Customizing SMF > SMF Coding Discussion
Calendar events in news topic
(1/1)
Springer:
Is there any way to make calendar events become the news topic the day of the event?
Jack.R.Abbit™:
yes. I don't know if this is the best way but it works so here it goes. This is mostly code adapted from other parts of the sources.
search for this line in Subs.php:
--- Code: --- $context['news_lines'] = explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))));
--- End code ---
Add this after:
--- Code: --- require_once($sourcedir . '/Calendar.php');
$low_date = strftime('%Y-%m-%d', forum_time(false) - 24 * 3600);
$high_date = strftime('%Y-%m-%d', forum_time(false));
$events = calendarEventArray($low_date, $high_date, false);
$day = (int) strftime('%d', forum_time());
$duplicates = array();
if (isset($events[$day]))
foreach ($events[$day] as $ev => $event)
{
if (count(array_intersect($user_info['groups'], $event['allowed_groups'])) != 0 || allowedTo('admin_forum'))
{
$this_event = &$events[$day][$ev];
$this_event['href'] = $scripturl . '?topic=' . $this_event['topic'] . '.0';
if (isset($duplicates[$this_event['topic']]) && $duplicates[$this_event['topic']] == $this_event['title'])
unset($events[$i][$ev]);
$duplicates[$this_event['topic']] = $this_event['title'];
}
else
unset($events[$day][$ev]);
if (isset($this_event))
$context['news_lines'][] = '[url=' . $this_event['href'] . ']' . $this_event['title'] . '[/url]';
}
--- End code ---
You will also need to add "$sourcedir" to the list of globals for the function we are modifying here... setupThemeContext()
EDIT: I've just added this feature to my Calendar Pack (still not released until SMF 1.0 Final)
Navigation
[0] Message Index
Go to full version