View source
<?php
define('EVENT_PATH', drupal_get_path('module', 'event'));
include EVENT_PATH . '/event.theme';
include EVENT_PATH . '/ical.inc';
function event_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node') {
if (event_enabled_state($node->type) == 'all') {
$links['event_calendar'] = array(
'title' => t('Calendar'),
'href' => 'event/' . format_date($node->event_start, 'custom', 'Y/m/d'),
);
}
elseif (event_enabled_state($node->type) == 'solo') {
$links['event_calendar'] = array(
'title' => t('Calendar'),
'href' => 'event/' . format_date($node->event_start, 'custom', 'Y/m/d') . '/month/' . $node->type,
);
}
}
elseif (user_access('access content')) {
$base = "event/{$node->year}/{$node->month}/{$node->day}/";
$links['event_month'] = array(
'title' => t('Month'),
'href' => $base . 'month/' . $node->filter,
'attributes' => array(
'title' => t('Month view'),
),
);
$links['event_week'] = array(
'title' => t('Week'),
'href' => $base . 'week/' . $node->filter,
'attributes' => array(
'title' => t('Week view'),
),
);
$links['event_day'] = array(
'title' => t('Day'),
'href' => $base . 'day/' . $node->filter,
'attributes' => array(
'title' => t('Day view'),
),
);
$links['event_table'] = array(
'title' => t('Table'),
'href' => $base . 'table/' . $node->filter,
'attributes' => array(
'title' => t('Table view'),
),
);
$links['event_list'] = array(
'title' => t('List'),
'href' => $base . 'list/' . $node->filter,
'attributes' => array(
'title' => t('List view'),
),
);
switch ($type) {
case 'event_month':
unset($links['event_month']);
break;
case 'event_week':
unset($links['event_week']);
break;
case 'event_day':
unset($links['event_day']);
break;
case 'event_table':
unset($links['event_table']);
break;
case 'event_list':
unset($links['event_list']);
break;
default:
$links = array();
}
}
return $links;
}
function event_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'event',
'title' => t('Events'),
'callback' => 'event_page',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'event/type',
'title' => t('Filter by content type'),
'callback' => 'event_type',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'event/term',
'title' => t('Filter by taxonomy'),
'callback' => 'event_term',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'event/feed',
'title' => t('Event rss feed'),
'callback' => 'event_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'event/dst',
'title' => t('Event dst view'),
'callback' => 'event_dst',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'event/ical',
'title' => t('Event ical feed'),
'callback' => 'event_ical',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/settings/event',
'title' => t('Events'),
'callback' => 'system_admin_menu_block_page',
'description' => t('Set up how your site handles events.'),
'access' => user_access('administer site configuration'),
);
$items[] = array(
'path' => 'admin/settings/event/timezone',
'title' => t('Timezone handling'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'event_admin_timezone_settings',
),
'description' => t('Change how timezone information is saved and displayed.'),
'access' => user_access('administer site configuration'),
);
$items[] = array(
'path' => 'admin/settings/event/overview',
'title' => t('Event overview'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'event_admin_overview_settings',
),
'description' => t('Change how event summary information is displayed.'),
'access' => user_access('administer site configuration'),
);
}
else {
drupal_add_css(EVENT_PATH . '/event.css');
if (arg(0) == 'node' && is_numeric(arg(1))) {
$type = db_result(db_query("SELECT type FROM {node} WHERE nid=%d", arg(1)));
if (event_is_enabled($type)) {
$items[] = array(
'path' => 'node/' . arg(1) . '/ical',
'title' => t('Event ical'),
'callback' => 'event_node_ical',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
}
}
}
return $items;
}
function event_admin_timezone_settings() {
if (variable_get('configurable_timezones', 0)) {
$form['event_timezone_input'] = array(
'#type' => 'radios',
'#title' => t('Event time zone input'),
'#default_value' => variable_get('event_timezone_input', 'site'),
'#options' => array(
'site' => t('Use the sitewide time zone'),
'user' => t('Use the time zone of the user editing or creating the event'),
'input' => t('Allow users to set event time zones'),
),
'#description' => t('Events are saved with a time zone value. This setting allows you to determine how the time zone is determined when creating or editing an event.'),
'#required' => TRUE,
);
$form['event_timezone_display'] = array(
'#type' => 'radios',
'#title' => t('Event time zone display'),
'#default_value' => variable_get('event_timezone_display', 'event'),
'#options' => array(
'event' => t("Use the event's time zone"),
'user' => t("Use the user's time zone"),
'site' => t('Use the sitewide time zone'),
),
'#description' => t("Events are saved with a time zone value. This setting allows you to determine if the event's time zone, the sitewide time zone, or the user's personal time zone setting is used to display the time for an event."),
'#required' => TRUE,
);
}
else {
if (variable_get('event_timezone_input', 'site') == 'user') {
variable_set('event_timezone_input', 'site');
}
variable_set('event_timezone_display', 'event');
$form['event_timezone_input'] = array(
'#type' => 'radios',
'#title' => t('Event time zone input'),
'#default_value' => variable_get('event_timezone_input', 'site'),
'#options' => array(
'site' => t('Use the sitewide time zone'),
'user' => t('Use the time zone of the user editing or creating the event'),
'input' => t('Allow users to set event time zones'),
),
'#description' => t("Events are saved with a time zone value. This setting allows you to determine how the time zone is determined when creating or editing an event. You must have 'Configurable time zones' enabled in the !url before you can enable user's time zones for this feature.", array(
'!url' => l(t('date/time settings'), 'admin/settings/date-time'),
)),
'#required' => TRUE,
);
$form['event_timezone_display'] = array(
'#type' => 'radios',
'#title' => t('Event time zone display'),
'#default_value' => variable_get('event_timezone_display', 'event'),
'#options' => array(
'event' => t("Use the event's time zone"),
'site' => t('Use the sitewide time zone'),
),
'#description' => t("Events are saved with a time zone value. This setting allows you to determine if the event's time zone, the sitewide time zone, or the user's personal time zone setting is used to display the time for an event. You must have 'Configurable time zones' enabled in the !url before you can enable user's time zones for this feature.", array(
'!url' => l(t('date/time settings'), 'admin/settings/date-time'),
)),
'#required' => TRUE,
);
}
$form['event_ampm'] = array(
'#type' => 'radios',
'#title' => t('Time notation preference'),
'#default_value' => variable_get('event_ampm', '0'),
'#options' => array(
'0' => t('24h'),
'1' => t('12h'),
),
'#description' => t('The time notation system used for entering event times.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
function event_admin_overview_settings() {
$form['event_upcoming_limit'] = array(
'#type' => 'textfield',
'#title' => t('Upcoming event block limit'),
'#default_value' => variable_get('event_upcoming_limit', '6'),
'#maxlength' => 5,
'#size' => 2,
'#description' => t('Limit the amount of events displayed in the upcoming events block by this amount.'),
);
$form['event_overview'] = array(
'#type' => 'radios',
'#title' => t('Default overview'),
'#default_value' => variable_get('event_overview', 'month'),
'#options' => array(
'day' => t('Day'),
'week' => t('Week'),
'month' => t('Month'),
'table' => t('Table'),
'list' => t('List'),
),
'#description' => t('The default event view to display when no format is specifically requested. This is also the view that will be displayed from the block calendar links.'),
);
$form['event_table_duration'] = array(
'#type' => 'textfield',
'#title' => t('Table view default period'),
'#default_value' => variable_get('event_table_duration', '30'),
'#maxlength' => 5,
'#size' => 3,
'#description' => t('The default number of days to display in the table view. You can specify a different number of days in the url. More info on the event url format !link', array(
'!link' => l(t('here'), 'admin/help/event#url-format'),
)),
);
if (module_exists('taxonomy')) {
$form['event_taxonomy_control'] = array(
'#type' => 'radios',
'#title' => t('Taxonomy filter controls'),
'#default_value' => variable_get('event_taxonomy_control', 'all'),
'#options' => array(
'all' => t('Show taxonomy filter control on calendar views'),
'request' => t('Only show taxonomy filter control when taxonomy filter view is requested'),
'never' => t('Never show taxonomy filter control'),
),
);
}
$form['event_type_control'] = array(
'#type' => 'radios',
'#title' => t('Content type filter controls'),
'#default_value' => variable_get('event_type_control', 'all'),
'#options' => array(
'all' => t('Show content type filter control on calendar views'),
'request' => t('Only show content type filter control when content type filter view is requested'),
'never' => t('Never show content type filter control'),
),
);
return system_settings_form($form);
}
function event_page($year = NULL, $month = NULL, $day = NULL, $view = NULL, $types = NULL, $tids = NULL, $duration = NULL) {
$now = _event_user_time();
$stamp = gmmktime(0, 0, 0, $month ? $month : gmdate('m', $now), $day ? $day : gmdate('d', $now), $year ? $year : gmdate('Y', $now));
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$day = gmdate('d', $stamp);
$view = $view ? $view : variable_get('event_overview', 'month');
if (isset($_POST['event_type_select'])) {
drupal_goto('event/' . $year . '/' . $month . '/' . $day . '/' . $view . '/' . check_plain($_POST['event_type_select']) . '/' . $tids);
}
if (isset($_POST['event_term_select'])) {
drupal_goto('event/' . $year . '/' . $month . '/' . $day . '/' . $view . '/' . ($types ? $types : 'all') . '/' . check_plain($_POST['event_term_select']));
}
$breadcrumbs[] = l(t('Home'), NULL);
$breadcrumbs[] = l(t('Events'), 'event');
$links = array();
if ($types) {
$types = preg_split('/[+ ]/', $types);
foreach ($types as $type) {
if (is_numeric($type)) {
$ctype = module_invoke('flexinode', 'load_content_type', $type);
if ($ctype->name) {
$temp[$ctype->name] = 'flexinode-' . $type;
$filter[] = $ctype->name;
}
}
elseif (substr($type, 0, 10) == 'flexinode-') {
$ctype = module_invoke('flexinode', 'load_content_type', substr($type, 10));
if ($ctype->name) {
$temp[$ctype->name] = $type;
$filter[] = $ctype->name;
}
}
elseif ($name = node_get_types('name', $type)) {
$x = module_invoke($type, 'node_name', $node);
$temp[$x] = $type;
$filter[] = module_invoke($type, 'node_name', $node);
}
}
if (is_array($filter)) {
$links['event_all'] = array(
'title' => t('View all'),
'href' => 'event/' . $year . '/' . $month . '/' . $day . '/' . $view . '/',
);
$title = t('Filter') . ': ' . implode(', ', $filter);
$types = $temp;
}
else {
$types = null;
}
}
$terms = null;
if ($tids && $tids != 'all') {
$links['event_all'] = array(
'title' => t('View all'),
'href' => 'event/' . $year . '/' . $month . '/' . $day . '/day',
);
if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $tids)) {
$terms = preg_split('/[+ ]/', $tids);
}
else {
if (preg_match('/^([0-9]+,)*[0-9]+$/', $tids)) {
$terms = explode(',', $tids);
}
}
}
if (variable_get('event_taxonomy_control', 'all') == 'all' || variable_get('event_taxonomy_control', 'all') == 'request' && isset($terms)) {
$output .= _event_get_taxonomy_control($terms);
}
if (variable_get('event_type_control', 'all') == 'all' || variable_get('event_type_control', 'all') == 'request' && isset($types)) {
$output .= _event_get_type_control($types);
}
switch ($view) {
case 'day':
$caption = t('!weekday !month !day, !year', array(
'!weekday' => t(gmdate('l', $stamp)),
'!month' => t(gmdate('F', $stamp)),
'!day' => $day,
'!year' => $year,
));
list($thead, $tbody) = event_calendar_day('page', $stamp, $types, $terms);
break;
case 'week':
$temp = $stamp - _event_day_of_week($stamp) * 86400;
$caption = t('Week of !month !day, !year', array(
'!month' => t(gmdate('F', $temp)),
'!day' => gmdate('d', $temp),
'!year' => $year,
));
$colspan = 5;
list($thead, $tbody) = event_calendar_week('page', $stamp, $types, $terms);
break;
case 'month':
$caption = t('!month !year', array(
'!month' => t(gmdate('F', $stamp)),
'!year' => $year,
));
$colspan = 5;
list($thead, $tbody) = event_calendar_month('page', $stamp, $types, $terms);
break;
case 'table':
$duration = $duration && $duration <= 366 ? $duration : variable_get('event_table_duration', '30');
$endstamp = $stamp + $duration * 86400;
$caption = t('!startmonth !startdate, !startyear - !endmonth !enddate, !endyear', array(
'!startmonth' => t(gmdate('F', $stamp)),
'!startdate' => gmdate('d', $stamp),
'!startyear' => gmdate('Y', $stamp),
'!endmonth' => t(gmdate('F', $endstamp)),
'!enddate' => gmdate('d', $endstamp),
'!endyear' => gmdate('Y', $endstamp),
));
list($thead, $tbody) = event_calendar_table('page', $stamp, $endstamp, $types, $terms);
break;
case 'list':
$duration = $duration && $duration <= 366 ? $duration : variable_get('event_table_duration', '30');
$endstamp = $stamp + $duration * 86400;
$caption = t('!startmonth !startdate, !startyear - !endmonth !enddate, !endyear', array(
'!startmonth' => t(gmdate('F', $stamp)),
'!startdate' => gmdate('d', $stamp),
'!startyear' => gmdate('Y', $stamp),
'!endmonth' => t(gmdate('F', $endstamp)),
'!enddate' => gmdate('d', $endstamp),
'!endyear' => gmdate('Y', $endstamp),
));
$tbody = event_calendar_list('page', $stamp, $endstamp, $types, $terms);
break;
case 'feed':
drupal_set_header('Content-Type: text/xml; charset=utf-8');
$duration = $duration ? $duration : variable_get('event_table_duration', '30');
print event_calendar_rss($stamp, $duration, $types, $terms, $title);
break;
case 'ical':
drupal_set_header('Content-Type: text/calendar; charset=utf-8');
drupal_set_header('Content-Disposition: attachment; filename="calendar.ics"; ');
$duration = $duration ? $duration : variable_get('event_table_duration', '30');
print event_calendar_ical($stamp, $duration, $types, $terms, $title);
break;
case 'block':
$time = _event_user_date();
if (arg(0) == 'event' && is_numeric(arg(1))) {
$year = arg(1) ? arg(1) : gmdate('Y', $time);
$month = arg(2) ? arg(2) : gmdate('m', $time);
$day = arg(3) ? arg(3) : gmdate('d', $time);
$stamp = gmmktime(0, 0, 0, $month, $day, $year);
}
else {
$stamp = _event_user_date();
}
print event_calendar_month('block', $stamp);
break;
}
if ($view != 'feed' && $view != 'ical' && $view != 'block') {
$prev = _event_nav($stamp, 'prev', $view, $types, $terms, $duration);
$next = _event_nav($stamp, 'next', $view, $types, $terms, $duration);
$caption = $prev . ' ' . $caption . ' ' . $next;
$node->day = $day;
$node->month = $month;
$node->year = $year;
$node->filter = ($types ? implode('+', $types) : 'all') . '/' . ($terms ? implode('+', $terms) : 'all');
$output .= theme('event_links', array_merge(module_invoke_all('link', 'event_' . $view, $node, FALSE), $links), $view);
$output .= theme('event_calendar_' . $view, 'page', $thead, $tbody, array(), $caption);
$output .= theme('event_ical_link', 'event/ical/' . $node->filter);
drupal_add_feed(url('event/feed', NULL, NULL, TRUE), t('Events at %site', array(
'%site' => variable_get('site_name', 'drupal'),
)));
drupal_set_title(t('Events') . ($title ? ' - ' . $title : ''));
drupal_set_breadcrumb($breadcrumbs);
return $output;
}
}
function event_type($types = NULL, $view = NULL, $terms = NULL) {
drupal_goto('event/' . format_date(_event_user_time(), 'custom', 'Y/m/d') . '/' . ($view ? $view : variable_get('event_overview', 'month')) . '/' . $types);
}
function event_term($filter = NULL, $view = NULL) {
drupal_goto('event/' . format_date(_event_user_time(), 'custom', 'Y/m/d') . '/' . ($view ? $view : variable_get('event_overview', 'month')) . '/all/' . $filter);
}
function event_feed($types = 'all', $terms = 'all', $duration = NULL) {
drupal_goto('event/' . format_date(_event_user_time(), 'custom', 'Y/m/d') . '/feed/' . $types . '/' . $terms . '/' . $duration);
}
function event_ical($types = 'all', $terms = 'all', $duration = NULL) {
drupal_goto('event/' . format_date(_event_user_time(), 'custom', 'Y/m/d') . '/ical/' . $types . '/' . $terms . '/' . $duration);
drupal_set_title(t('iCal support not enabled'));
return $output;
}
function event_calendar_month($op, $stamp, $types = NULL, $terms = NULL) {
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$day = gmdate('d', $stamp);
switch ($op) {
case 'page':
$callback = 'event_render_day';
$view = 'month';
break;
case 'block':
$caption = _event_nav($stamp, 'prev', 'block', $types, $terms) . ' ' . l(t(gmdate('F', $stamp)) . ' ' . $year, 'event/' . $year . '/' . $month . '/' . $day . '/month') . ' ' . _event_nav($stamp, 'next', 'block', $types, $terms);
$callback = 'event_render_day_single';
$view = 'block';
break;
}
$weekdays = event_week_days();
$thead = event_week_header();
$tbody = array();
$today = _event_user_date();
$month_name = t(gmdate('F', $stamp));
$month_name_abbrev = t(gmdate('M', $stamp));
$curstamp = gmmktime(0, 0, 0, $month, 01, $year);
$lastday = gmmktime(0, 0, 0, $month, gmdate('t', $stamp), $year);
$row = array_fill(0, 6, array(
'class' => 'pad',
));
$start = $offset = _event_day_of_week($curstamp);
while ($curstamp <= $lastday) {
for ($x = $start; $x < 7; $x++) {
$cur_day = $week * 7 + ($x + 1) - $offset;
$row[$x] = array(
'class' => strtolower($weekdays[$x]['day']) . " day-{$cur_day}" . ($curstamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : ''),
'data' => $callback($year, $month, $cur_day, $view, $types, $terms),
);
$curstamp += 86400;
if ($curstamp > $lastday) {
$x = 8;
}
}
$week++;
$start = 0;
$tbody[] = array_pad($row, 7, array(
'class' => 'pad',
));
$row = array();
}
switch ($op) {
case 'page':
return array(
$thead,
$tbody,
);
break;
case 'block':
return theme('event_calendar_month', $op, $thead, $tbody, $attributes = array(
'class' => 'event-block ' . strtolower($month_name),
), $caption);
break;
}
}
function event_calendar_week($op, $stamp, $types = NULL, $terms = NULL) {
$weekdays = event_week_days();
$thead = event_week_header();
$today = _event_user_date();
$stamp -= _event_day_of_week($stamp) * 86400;
for ($x = 0; $x < 7; $x++) {
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$cur_day = gmdate('j', $stamp);
$month_name = gmdate('M', $stamp);
$row[$x] = array(
'class' => strtolower("{$month_name} " . $weekdays[$x]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : '')),
'id' => strtolower($month_name . $cur_day),
'data' => event_render_day($year, $month, $cur_day, 'week', $types, $terms),
);
$stamp += 86400;
}
$tbody[] = $row;
return array(
$thead,
$tbody,
);
}
function event_calendar_day($op, $stamp, $types = NULL, $terms = NULL) {
$today = _event_user_date();
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$day = gmdate('j', $stamp);
$dow = _event_day_of_week($stamp);
$month_name = gmdate('M', $stamp);
$weekdays = event_week_days();
$thead[] = array(
'data' => t(gmdate('D', $stamp)),
);
$tbody[][] = array(
'class' => strtolower("{$month_name} " . $weekdays[$dow]['day'] . ($stamp == $today ? ' today' : '')),
'id' => strtolower($month_name . $day),
'data' => event_render_day($year, $month, $day, 'day', $types, $terms),
'colspan' => 3,
);
return array(
$thead,
$tbody,
);
}
function event_calendar_table($op, $stamp, $endstamp, $types = NULL, $terms = NULL) {
$today = _event_user_date();
$thead[] = array(
'data' => ' ',
);
while ($stamp <= $endstamp) {
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$cur_day = gmdate('j', $stamp);
$month_name = gmdate('M', $stamp);
$dow = _event_day_of_week($stamp);
$weekdays = event_week_days();
$tbody[][] = array(
'colspan' => 3,
'class' => strtolower("{$month_name} " . $weekdays[$dow]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : '')),
'id' => strtolower($month_name . $cur_day),
'data' => event_render_day($year, $month, $cur_day, 'table', $types, $terms),
);
$stamp += 86400;
}
return array(
$thead,
$tbody,
);
}
function event_calendar_list($op, $stamp, $endstamp, $types = NULL, $terms = NULL) {
$today = _event_user_date();
$rows = '';
while ($stamp <= $endstamp) {
$year = gmdate('Y', $stamp);
$month = gmdate('m', $stamp);
$cur_day = gmdate('j', $stamp);
$month_name = gmdate('M', $stamp);
$dow = _event_day_of_week($stamp);
$weekdays = event_week_days();
$rows .= event_render_day($year, $month, $cur_day, 'list', $types, $terms);
$stamp += 86400;
}
return $rows;
}
function event_calendar_rss($stamp, $duration, $types = NULL, $terms = NULL, $title = NULL) {
global $base_url, $locale;
$endstamp = $stamp + $duration * 86400;
$headertitle = t('!startmonth !startdate, !startyear - !endmonth !enddate, !endyear', array(
'!startmonth' => t(gmdate('F', $stamp)),
'!startdate' => gmdate('d', $stamp),
'!startyear' => gmdate('Y', $stamp),
'!endmonth' => t(gmdate('F', $endstamp)),
'!enddate' => gmdate('d', $endstamp),
'!endyear' => gmdate('Y', $endstamp),
));
$result = db_query(db_rewrite_sql('SELECT n.nid, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND ((e.event_start > %d AND e.event_start < %d) OR (e.event_end > %d AND e.event_end < %d) OR (e.event_start < %d AND e.event_end > %d)) ORDER BY event_start '), $stamp, $endstamp, $stamp, $endstamp, $stamp, $endstamp);
$nodes = array();
while ($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
$nodes[] = $node;
}
$filtered = event_filter_nodes($nodes, $types, $terms);
foreach ($filtered as $node) {
$body = '<div class="start">' . t('Start') . ': ' . $node->start_format . '</div>' . "\n";
$body .= '<div class="end">' . t('End') . ': ' . $node->end_format . '</div>' . "\n";
$body .= check_markup($node->teaser);
$link = url("node/{$node->nid}", NULL, NULL, 1);
$extra = node_invoke_nodeapi($node, 'rss item');
$extra = array_merge($extra, array(
array(
'key' => 'pubDate',
'value' => date('r', $node->changed),
),
));
$items .= format_rss_item($node->title, $link, $body, $extra);
}
$description = $headertitle . ($title ? ' | ' . $title : '');
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
if (module_exists('location')) {
$output .= "<rss version=\"2.0\" xmlns:geo=\"http://www.w3.org/2003/01/geo/wgs84_pos#\" xmlns:geourl=\"http://geourl.org/rss/module/\" xmlns:icbm=\"http://postneo.com/icbm\" xml:base=\"" . $base_url . "\">\n";
}
else {
$output .= "<rss version=\"2.0\" xml:base=\"" . $base_url . "\">\n";
}
$output .= format_rss_channel(variable_get('site_name', 'drupal') . t(' - Events Feed'), url('event/feed', NULL, NULL, TRUE), $description, $items, $locale);
$output .= "</rss>\n";
return $output;
}
function event_calendar_ical($stamp, $duration, $types = NULL, $terms = NULL, $title = NULL) {
global $base_url, $locale;
$endstamp = $stamp + $duration * 86400;
$headertitle = t('!startmonth !startdate, !startyear - !endmonth !enddate, !endyear', array(
'!startmonth' => t(gmdate('F', $stamp)),
'!startdate' => gmdate('d', $stamp),
'!startyear' => gmdate('Y', $stamp),
'!endmonth' => t(gmdate('F', $endstamp)),
'!enddate' => gmdate('d', $endstamp),
'!endyear' => gmdate('Y', $endstamp),
));
$result = db_query(db_rewrite_sql('SELECT n.nid, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND ((e.event_start > %d AND e.event_start < %d) OR (e.event_end > %d AND e.event_end < %d) OR (e.event_start < %d AND e.event_end > %d)) ORDER BY event_start '), $stamp, $endstamp, $stamp, $endstamp, $stamp, $endstamp);
$events = array();
while ($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
if (event_filter_node($node, $types, $terms)) {
$events[] = _event_node_ical($node);
}
}
$description = $headertitle . ($title ? ' | ' . $title : '');
return ical_export($events, $description);
}
function event_node_ical() {
$node = node_load(arg(1));
$event = _event_node_ical($node);
drupal_set_header('Content-Type: text/calendar; charset=utf-8');
drupal_set_header('Content-Disposition: attachment; filename="calendar.ics"; ');
print ical_export(array(
$event,
), $event['summary']);
}
function _event_node_ical($node) {
$event = array();
node_invoke_nodeapi($node, 'ical item');
$event['start'] = $node->event_start;
$event['end'] = $node->event_end;
$event['location'] = $node->event_location;
$event['summary'] = $node->title;
$event['description'] = check_markup($node->teaser ? $node->teaser : $node->body);
$event['uid'] = url("node/{$node->nid}", NULL, NULL, 1);
$event['url'] = url("node/{$node->nid}", NULL, NULL, 1);
return $event;
}
function event_get_calendar($view, $nodes, $module, $title = NULL) {
$today = _event_user_date();
foreach ($nodes as $node) {
$event = new stdClass();
$node->event_links = module_invoke_all('link', 'event_node_' . $view, $node, FALSE);
$nodes[$node->nid] = $node;
$event->nid = $node->nid;
$node_start = gmmktime(0, 0, 0, _event_date('m', $node->event_start, $node->start_offset), _event_date('d', $node->event_start, $node->start_offset), _event_date('Y', $node->event_start, $node->start_offset));
if ($node->event_end) {
$node_end = gmmktime(0, 0, 0, _event_date('m', $node->event_end, $node->end_offset), _event_date('d', $node->event_end, $node->end_offset), _event_date('Y', $node->event_end, $node->end_offset));
}
else {
$node_end = $node_start;
}
if ($node_start == $node_end) {
$event->event_state = 'singleday';
$event->stamp = $node_start;
$data[gmdate('Y', $node_start)][gmdate('m', $node_start)][gmdate('j', $node_start)][] = $event;
}
else {
for ($x = $node_start; $x <= $node_end; $x += 86400) {
if ($x == $node_end) {
$event->event_state = 'end';
$event->stamp = $x;
$data[gmdate('Y', $x)][gmdate('m', $x)][gmdate('j', $x)][] = $event;
}
elseif ($x == $node_start) {
$event->event_state = 'start';
$event->stamp = $x;
$data[gmdate('Y', $x)][gmdate('m', $x)][gmdate('j', $x)][] = $event;
}
else {
$event->event_state = 'ongoing';
$event->stamp = $x;
$data[gmdate('Y', $x)][gmdate('m', $x)][gmdate('j', $x)][] = $event;
}
}
}
}
ksort($data, SORT_NUMERIC);
foreach ($data as $year => $months) {
ksort($data[$year], SORT_NUMERIC);
foreach ($data[$year] as $month => $days) {
ksort($data[$year][$month], SORT_NUMERIC);
}
}
$weekdays = event_week_days();
switch ($view) {
case 'day':
case 'table':
foreach ($data as $year => $months) {
if (count($data) > 1) {
$rows[][] = array(
'class' => 'heading year',
'id' => 'year' . $year,
'data' => $year,
);
}
foreach ($months as $month => $days) {
foreach ($days as $day => $events) {
$content = theme('event_calendar_date_box', $year, $month, $day, 'table');
foreach ($events as $event) {
if (!$month_name) {
$month_name = gmdate('M', $event->stamp);
$dow = _event_day_of_week($event->stamp);
}
$node = $nodes[$event->nid];
$node->event_state = $event->event_state;
if ($output = module_invoke($module, 'event_node_' . $view, $node)) {
$content .= $output;
}
else {
$content .= theme('event_node_' . $view, $node);
}
}
$rows[][] = array(
'class' => strtolower("{$month_name} " . $weekdays[$dow]['day'] . ($event->stamp == $today ? ' today' : '')),
'id' => strtolower($month_name . $day),
'data' => $content,
);
$month_name = NULL;
}
}
}
break;
case 'week':
case 'month':
$colspan = '7';
foreach ($data as $year => $months) {
if (count($data) > 1) {
$rows[][] = array(
'class' => 'heading year',
'id' => 'year' . $year,
'data' => $year,
'colspan' => $colspan,
);
}
foreach ($months as $month => $days) {
$curstamp = gmmktime(0, 0, 0, $month, 1, $year);
$lastday = gmmktime(0, 0, 0, $month, gmdate('t', $curstamp), $year);
$row = array_fill(0, 6, '');
$start = $offset = _event_day_of_week($curstamp);
$month_name = gmdate('M', $curstamp);
$week = 0;
$rows[][] = array(
'class' => 'heading month',
'id' => 'month' . $month,
'data' => $month_name,
'colspan' => $colspan,
);
$rows[] = event_week_header();
while ($curstamp <= $lastday) {
for ($x = $start; $x < 7; $x++) {
$cur_day = $week * 7 + ($x + 1) - $offset;
$content = theme('event_calendar_date_box', $year, $month, $cur_day, $view);
if (is_array($days[$cur_day])) {
foreach ($days[$cur_day] as $event) {
$node = $nodes[$event->nid];
$node->event_state = $event->event_state;
if ($output = module_invoke($module, 'event_node_' . $view, $node)) {
$content .= $output;
}
else {
$content .= theme('event_node_' . $view, $node);
}
}
}
$row[$x] = array(
'class' => strtolower("{$month_name} " . $weekdays[$x]['day'] . ($curstamp == $today ? ' today' : '')),
'id' => strtolower($month_name . $day),
'data' => $content,
);
$curstamp += 86400;
if ($curstamp > $lastday) {
$x = 8;
}
}
$week++;
$start = 0;
$rows[] = array_pad($row, 7, ' ');
$row = array();
}
}
}
break;
}
$header[] = $title ? array(
'class' => 'heading',
'data' => $title,
'colspan' => $colspan,
) : array();
return theme('event_calendar_' . $view, 'page', $header, $rows);
}
function event_calendar_data($year, $month, $day, $view = NULL, $types = NULL, $terms = NULL) {
static $data;
global $user;
$day_start = _event_mktime(0, 0, 0, $month, $day, $year);
if (!is_array($data[$year][$month])) {
$data[$year][$month] = array();
module_invoke_all('event_load', $year, $month, $day, $view, $types, $terms);
$first = _event_mktime(0, 0, 0, $month, 1, $year);
$last = _event_mktime(23, 59, 59, $month + 1, 0, $year);
$result = db_query(db_rewrite_sql('SELECT n.nid, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND ((e.event_start >= %d AND e.event_start <= %d) OR (e.event_end >= %d AND e.event_end <= %d) OR (e.event_start <= %d AND e.event_end >= %d)) ORDER BY event_start '), $first, $last, $first, $last, $first, $last);
while ($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
$node->event_links = module_invoke_all('link', 'event_node_' . $view, $node, FALSE);
$data[$year][$month]['nodes'][$nid->nid] = $node;
$node_start = gmmktime(0, 0, 0, _event_date('m', $node->event_start, $node->start_offset), _event_date('d', $node->event_start, $node->start_offset), _event_date('Y', $node->event_start, $node->start_offset));
$node_end = gmmktime(0, 0, 0, _event_date('m', $node->event_end, $node->end_offset), _event_date('d', $node->event_end, $node->end_offset), _event_date('Y', $node->event_end, $node->end_offset));
if ($node_start == $node_end && gmdate('m', $node_start) == $month) {
$nid->event_state = 'singleday';
$data[$year][$month][gmdate('j', $node_start)][] = $nid;
}
else {
$first -= $first % 86400;
for ($x = $first > $node_start ? $first : $node_start; $x < $last; $x += 86400) {
if (gmdate('m', $x) == $month) {
if ($x == $node_end) {
$nid->event_state = 'end';
$data[$year][$month][gmdate('j', $x)][] = drupal_clone($nid);
$x = $last + 1;
}
elseif ($x == $node_start) {
$nid->event_state = 'start';
$data[$year][$month][gmdate('j', $x)][] = drupal_clone($nid);
}
else {
$nid->event_state = 'ongoing';
$data[$year][$month][gmdate('j', $x)][] = drupal_clone($nid);
}
}
}
}
}
}
$nodes = array();
$event_types = event_get_types();
if ($data[$year][$month][$day]) {
if (isset($types)) {
if (isset($terms)) {
foreach ($data[$year][$month][$day] as $nid) {
$node = $data[$year][$month]['nodes'][$nid->nid];
if (in_array($node->type, $types) && event_taxonomy_filter($node, $terms)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
elseif (in_array($node->type, $event_types['all'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
}
}
}
else {
foreach ($data[$year][$month][$day] as $nid) {
$node = $data[$year][$month]['nodes'][$nid->nid];
if (in_array($node->type, $types)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
elseif (in_array($node->type, $event_types['all'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
}
}
}
}
elseif (isset($terms)) {
foreach ($data[$year][$month][$day] as $nid) {
$node = $data[$year][$month]['nodes'][$nid->nid];
if (event_taxonomy_filter($node, $terms) && in_array($node->type, $event_types['all'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
}
}
else {
foreach ($data[$year][$month][$day] as $nid) {
$node = $data[$year][$month]['nodes'][$nid->nid];
if (in_array($node->type, $event_types['all'])) {
$node->event_current_date = $day_start;
$node->event_state = $nid->event_state;
$nodes[] = $node;
}
}
}
}
return $nodes;
}
function event_filter_node($node, $types, $terms) {
$event_types = event_get_types();
if (isset($types)) {
if (isset($terms)) {
if (in_array($node->type, $types) && event_taxonomy_filter($node, $terms)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
return TRUE;
}
elseif (in_array($node->type, $event_types['all'])) {
return TRUE;
}
}
}
else {
if (in_array($node->type, $types)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
return TRUE;
}
elseif (in_array($node->type, $event_types['all'])) {
return TRUE;
}
}
}
}
elseif (isset($terms)) {
if (event_taxonomy_filter($node, $terms) && in_array($node->type, $event_types['all'])) {
return TRUE;
}
}
else {
if (in_array($node->type, $event_types['all'])) {
return TRUE;
}
}
return FALSE;
}
function event_filter_nodes($nodes, $types, $terms) {
$event_types = event_get_types();
$results = array();
if (isset($types)) {
if (isset($terms)) {
foreach ($nodes as $node) {
if (in_array($node->type, $types) && event_taxonomy_filter($node, $terms)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
$results[] = $node;
}
elseif (in_array($node->type, $event_types['all'])) {
$results[] = $node;
}
}
}
}
else {
foreach ($nodes as $node) {
if (in_array($node->type, $types)) {
if (count($types) == 1 && in_array($node->type, $event_types['solo'])) {
$results[] = $node;
}
elseif (in_array($node->type, $event_types['all'])) {
$results[] = $node;
}
}
}
}
}
elseif (isset($terms)) {
foreach ($nodes as $node) {
if (event_taxonomy_filter($node, $terms) && in_array($node->type, $event_types['all'])) {
$results[] = $node;
}
}
}
else {
foreach ($nodes as $node) {
if (in_array($node->type, $event_types['all'])) {
return $nodes;
}
}
}
return $results;
}
function event_taxonomy_filter($node, $terms) {
if ($tids = taxonomy_node_get_terms($node->nid)) {
foreach ($tids as $tid => $term) {
if (in_array($tid, $terms)) {
return TRUE;
}
}
}
return FALSE;
}
function event_render_day_single($year, $month, $day, $view, $types, $terms) {
return count(event_calendar_data($year, $month, $day, $view, $types, $terms)) ? l($day, "event/{$year}/{$month}/{$day}/day") : $day;
}
function event_render_day($year, $month, $day, $view, $types, $terms) {
$nodes = event_calendar_data($year, $month, $day, $view, $types, $terms);
if (count($nodes)) {
$output = theme('event_calendar_date_box', $year, $month, $day, $view);
foreach ($nodes as $node) {
$output .= theme('event_node_' . $view, $node);
}
}
else {
$output .= theme('event_empty_day', $year, $month, $day, $view);
}
return $output;
}
function event_week_days() {
static $weekdays;
if (!$weekdays) {
if (variable_get('date_first_day', 1)) {
$weekdays = array(
array(
'day' => 'Mon',
't' => t('Mon'),
),
array(
'day' => 'Tue',
't' => t('Tue'),
),
array(
'day' => 'Wed',
't' => t('Wed'),
),
array(
'day' => 'Thu',
't' => t('Thu'),
),
array(
'day' => 'Fri',
't' => t('Fri'),
),
array(
'day' => 'Sat',
't' => t('Sat'),
),
array(
'day' => 'Sun',
't' => t('Sun'),
),
);
}
else {
$weekdays = array(
array(
'day' => 'Sun',
't' => t('Sun'),
),
array(
'day' => 'Mon',
't' => t('Mon'),
),
array(
'day' => 'Tue',
't' => t('Tue'),
),
array(
'day' => 'Wed',
't' => t('Wed'),
),
array(
'day' => 'Thu',
't' => t('Thu'),
),
array(
'day' => 'Fri',
't' => t('Fri'),
),
array(
'day' => 'Sat',
't' => t('Sat'),
),
);
}
}
return $weekdays;
}
function event_week_header() {
$days = event_week_days();
foreach ($days as $day) {
$row[] = array(
'class' => strtolower($day['day']),
'data' => $day['t'],
);
}
return $row;
}
function _event_date($format, $timestamp, $offset = null) {
global $user;
if (isset($offset)) {
$timestamp += $offset;
}
elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
$timestamp += $user->timezone;
}
else {
$timestamp += variable_get('date_default_timezone', 0);
}
if ($format == 'w') {
$result = _event_day_of_week($timestamp);
}
else {
$result = gmdate($format, $timestamp);
}
return $result;
}
function _event_day_of_week($stamp) {
$dow = gmdate('w', $stamp);
$dow = variable_get('date_first_day', 1) ? $dow == 0 ? 6 : --$dow : $dow;
return $dow;
}
function _event_mktime($hour, $minute, $second, $month, $day, $year, $offset = NULL) {
global $user;
$timestamp = gmmktime($hour, $minute, $second, $month, $day, $year);
if (isset($offset)) {
return $timestamp - $offset;
}
elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone) && variable_get('event_timezone_display', 'event') == 'user') {
return $timestamp - $user->timezone;
}
else {
return $timestamp - variable_get('date_default_timezone', 0);
}
}
function _event_user_time() {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
return time() - date("Z") + $user->timezone;
}
else {
return time() - date("Z") + variable_get('date_default_timezone', 0);
}
}
function _event_user_date() {
static $date;
if (!$date) {
$now = _event_user_time();
$date = gmmktime(0, 0, 0, gmdate('m', $now), gmdate('j', $now), gmdate('Y', $now));
}
return $date;
}
function event_form_date($timestamp, $prefix = 'start', $offset) {
$months = array(
1 => t('January'),
t('February'),
t('March'),
t('April'),
t('May'),
t('June'),
t('July'),
t('August'),
t('September'),
t('October'),
t('November'),
t('December'),
);
if (variable_get('event_ampm', '0')) {
$hour_format = t('g');
for ($i = 1; $i <= 12; $i++) {
$hours[$i] = $i < 10 ? "0{$i}" : $i;
}
$am_pms = array(
'am' => t('am'),
'pm' => t('pm'),
);
}
else {
$hour_format = t('H');
for ($i = 0; $i <= 23; $i++) {
$hours[$i] = $i < 10 ? "0{$i}" : $i;
}
}
for ($i = 0; $i <= 59; $i++) {
$minutes[$i] = $i < 10 ? "0{$i}" : $i;
}
$form[$prefix . '_day'] = array(
'#prefix' => '<div class="container-inline"><div class="day">',
'#type' => 'textfield',
'#default_value' => _event_date('d', $timestamp, $offset),
'#maxlength' => 2,
'#size' => 2,
'#required' => TRUE,
);
$form[$prefix . '_month'] = array(
'#type' => 'select',
'#default_value' => (int) _event_date('n', $timestamp, $offset),
'#options' => $months,
'#required' => TRUE,
);
$form[$prefix . '_year'] = array(
'#type' => 'textfield',
'#default_value' => (int) _event_date('Y', $timestamp, $offset),
'#maxlength' => 4,
'#size' => 4,
'#required' => TRUE,
);
$form[$prefix . '_hour'] = array(
'#prefix' => '</div><div class="time">—',
'#type' => 'select',
'#default_value' => _event_date($hour_format, $timestamp, $offset),
'#options' => $hours,
'#required' => TRUE,
);
$form[$prefix . '_minute'] = array(
'#prefix' => ':',
'#type' => 'select',
'#default_value' => _event_date('i', $timestamp, $offset),
'#options' => $minutes,
'#required' => TRUE,
);
if (isset($am_pms)) {
$form[$prefix . '_ampm'] = array(
'#type' => 'radios',
'#default_value' => _event_date('a', $timestamp, $offset),
'#options' => $am_pms,
'#required' => TRUE,
);
}
$form[$prefix . '_close'] = array(
'#type' => 'markup',
'#value' => '</div></div>',
);
return $form;
}
function event_validate_form_date(&$node, $date) {
$prefix = $date . '_';
if (module_exists('jscalendar')) {
$get = $prefix . 'date';
$this_date = $node->{$get};
$timestamp = mktime(substr($this_date, 11, 2), substr($this_date, 14, 2), substr($this_date, 17, 2), substr($this_date, 5, 2), substr($this_date, 8, 2), substr($this_date, 0, 4));
$node->{$prefix . 'year'} = date('Y', $timestamp);
$node->{$prefix . 'month'} = date('n', $timestamp);
$node->{$prefix . 'day'} = date('d', $timestamp);
if (variable_get('event_ampm', '0')) {
$node->{$prefix . 'ampm'} = substr($this_date, 11, 2) >= 12 ? 'pm' : 'am';
}
$node->{$prefix . 'hour'} = variable_get('event_ampm', '0') ? date('g', $timestamp) : date('H', $timestamp);
$node->{$prefix . 'minute'} = date('i', $timestamp);
}
if (isset($node->{$prefix . 'year'}) && isset($node->{$prefix . 'month'}) && isset($node->{$prefix . 'day'}) && isset($node->{$prefix . 'hour'}) && isset($node->{$prefix . 'minute'})) {
$hour = $node->{$prefix . 'hour'};
if (variable_get('event_ampm', '0')) {
if ($node->{$prefix . 'ampm'} == 'pm' && $hour != 12) {
$hour += 12;
}
elseif ($node->{$prefix . 'ampm'} == 'am' && $hour == 12) {
$hour -= 12;
}
}
$offset = event_get_offset($node->timezone, gmmktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}));
$node->{'event_' . $date} = _event_mktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}, $offset);
}
elseif (!$node->{$date}) {
$now = _event_user_time();
$node->{$date} = $now - $now % (60 * 60);
}
}
function _event_nav($date, $dir, $view, $types, $terms, $duration = NULL) {
$range = variable_get('event_range_' . $dir, -1);
if ($range == -1) {
event_set_range();
$range = variable_get('event_range_' . $dir, $date);
}
if ($dir == 'prev' && $range < $date || $dir == 'next' && $range > $date) {
$inc = $dir == 'prev' ? -1 : 1;
$duration = $duration ? $duration : 1;
if ($view == 'block') {
$view = 'month';
$attributes = array(
'class' => 'updateblock',
);
}
switch ($view) {
case 'day':
case 'table':
$date += $inc * ($duration * 86400);
break;
case 'week':
$date += $inc * ($duration * (86400 * 7));
break;
case 'month':
$date = gmmktime(0, 0, 0, gmdate('m', $date) + $duration * $inc, 1, gmdate('Y', $date));
break;
}
$url[] = 'event';
$url[] = gmdate('Y', $date);
$url[] = gmdate('m', $date);
$url[] = gmdate('d', $date);
$url[] = $view;
$url[] = $types ? implode('+', $types) : 'all';
$url[] = $terms ? implode('+', $terms) : 'all';
$url[] = $duration;
return theme('event_nav_' . $dir, implode('/', $url), $attributes);
}
}
function _event_get_taxonomy_control($curterm = NULL, $autosubmit = TRUE) {
if (module_exists('taxonomy')) {
$form = drupal_get_form('event_taxonomy_filter_form', $curterm, $autosubmit);
return theme('event_filter_control', $form);
}
}
function event_taxonomy_filter_form($curterm, $autosubmit) {
$types = event_get_types();
$vs = array();
foreach ($types['all'] as $type) {
$results = taxonomy_get_vocabularies($type);
foreach ($results as $vocab) {
$vs[$vocab->vid] = $vocab;
}
}
$results = null;
foreach ($types['solo'] as $type) {
$results = taxonomy_get_vocabularies($type);
foreach ($results as $vocab) {
$vs[$vocab->vid] = $vocab;
}
}
$items['all'] = t('(all)');
foreach ($vs as $vid => $vocab) {
$tree = taxonomy_get_tree($vid);
foreach ($tree as $term) {
$items[$term->tid] = $vocab->name . ' - ' . $term->name;
}
}
$form['event_term_select'] = array(
'#type' => 'select',
'#default_value' => $curterm,
'#options' => $items,
'#description' => t('Select event terms to filter by'),
);
if ($autosubmit) {
$form['event_term_select']['#attributes'] = array(
'onChange' => 'this.form.submit()',
);
}
return $form;
}
function _event_get_type_control($curtype = NULL, $autosubmit = TRUE) {
if (module_exists('taxonomy')) {
$form = drupal_get_form('event_type_filter_form', $curtype, $autosubmit);
return theme('event_filter_control', $form);
}
}
function event_type_filter_form($curtype, $autosubmit) {
$results = event_get_types('all');
$items['all'] = t('(all)');
foreach ($results as $type) {
if ($name = node_get_types('name', $type)) {
$items[$type] = $name;
}
}
$form['event_type_select'] = array(
'#type' => 'select',
'#default_value' => $curtype,
'#options' => $items,
'#description' => t('Select event type to filter by'),
);
if ($autosubmit) {
$form['event_type_select']['#attributes'] = array(
'onChange' => 'this.form.submit()',
);
}
return $form;
}
function event_block($op = 'list', $delta = 0) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Calendar to browse events.');
$blocks[1]['info'] = t('List of upcoming events.');
return $blocks;
break;
case 'view':
if (user_access('access content')) {
switch ($delta) {
case 0:
drupal_add_js(drupal_get_path('module', 'event') . '/eventblock.js');
drupal_add_js('misc/progress.js');
$time = _event_user_date();
if (arg(0) == 'event' && is_numeric(arg(1))) {
$year = arg(1) ? arg(1) : gmdate('Y', $time);
$month = arg(2) ? arg(2) : gmdate('m', $time);
$day = arg(3) ? arg(3) : gmdate('d', $time);
$stamp = gmmktime(0, 0, 0, $month, $day, $year);
}
else {
$stamp = _event_user_date();
}
$block['subject'] = t('Events');
$block['content'] = event_calendar_month('block', $stamp);
return $block;
case 1:
$block['subject'] = t('Upcoming events');
$block['content'] = event_block_upcoming(variable_get('event_upcoming_limit', '6'));
return $block;
}
}
if (event_is_enabled($node->type)) {
$length = strlen(ical_export(_event_node_ical($node), $node->title));
return array(
array(
'key' => 'enclosure',
'attributes' => array(
'url' => url('node/' . $node->nid . '/ical', NULL, NULL, TRUE),
'length' => $length,
'type' => 'text/calendar',
),
),
);
}
break;
}
}
function event_block_upcoming($limit = 6) {
global $user;
$time = time();
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.type, n.status, n.changed, e.event_start, e.event_end FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND (((e.event_start != e.event_end) AND (%d >= e.event_start AND %d < e.event_end)) OR ((e.event_start = e.event_end) AND (%d <= e.event_start + %d )) OR e.event_start >= %d) ORDER BY event_start LIMIT %d"), $time, $time, $time, 60 * 60 * 2, $time, $limit);
while ($node = db_fetch_object($result)) {
foreach (module_implements('event_edit_upcoming') as $module) {
$function = $module . '_event_edit_upcoming';
$function($node);
}
if ($node->status) {
if ($node->event_start >= $time) {
$minutesleft = floor(($node->event_start - $time) / 60);
if ($minutesleft >= 0 && $minutesleft < 60) {
$timeleft = format_plural($minutesleft, '1 minute', '@count minutes');
}
else {
if ($minutesleft >= 60 && $minutesleft < 24 * 60) {
$timeleft = format_plural(floor($minutesleft / 60), '1 hour', '@count hours');
}
else {
if ($minutesleft >= 24 * 60) {
$days = floor($minutesleft / (24 * 60));
$hours = $minutesleft % (24 * 60) / 60;
$hours_left = 24 - date('G', time());
if ($hours > $hours_left) {
$days++;
}
$timeleft = format_plural($days, '1 day', '@count days');
}
}
}
}
else {
$timeleft = t('Now');
}
$node->timeleft = $timeleft;
$node->typename = node_get_types('name', $node);
$items[] = theme('event_upcoming_item', $node);
}
}
if (!count($items)) {
$items[] = t('No upcoming events available');
}
$output = theme('event_upcoming_block', $items);
$output .= theme('event_ical_link', 'event/ical');
$output .= theme('event_more_link', 'event');
return $output;
}
function event_form_alter($form_id, &$form) {
global $user;
$node = isset($form['#node']) ? $form['#node'] : NULL;
switch ($form_id) {
case 'node_type_form':
$type = isset($form['old_type']) && isset($form['old_type']['#value']) ? $form['old_type']['#value'] : NULL;
$form['workflow']['event_nodeapi'] = array(
'#type' => 'radios',
'#title' => t('Show in event calendar'),
'#default_value' => variable_get('event_nodeapi_' . $type, 'never'),
'#options' => array(
'all' => t('All views'),
'solo' => t('Only in views for this type'),
'never' => t('Never'),
),
'#description' => t('All views: This content type will be available for display on all calendar views, including with other events.<br />Only in views for this type: This content type will only appear in calendar views specific to this type and never with other events.<br />Never: This content type will not be associated with the events calendar.'),
);
break;
case $form['type']['#value'] . '_node_form':
if (variable_get('event_nodeapi_' . $form['type']['#value'], 'never') != 'never') {
include_once EVENT_PATH . '/event_timezones.inc';
if (module_exists('jscalendar')) {
$form['start_date'] = array(
'#title' => t('Start Date'),
'#type' => 'textfield',
'#default_value' => _event_date('Y-m-d H:i', $node->event_start ? $node->event_start : _event_user_time(), $node->start_offset),
'#attributes' => array(
'class' => 'jscalendar',
),
'#jscalendar_ifFormat' => '%Y-%m-%d %H:%M',
'#jscalendar_showsTime' => 'true',
'#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12',
'#size' => 19,
'#maxlength' => 19,
'#weight' => -15,
'#description' => t('YYYY-MM-DD HH:MM'),
);
$form['end_date'] = array(
'#title' => t('End Date'),
'#type' => 'textfield',
'#default_value' => _event_date('Y-m-d H:i', $node->event_end ? $node->event_end : _event_user_time(), $node->end_offset),
'#attributes' => array(
'class' => 'jscalendar',
),
'#jscalendar_ifFormat' => '%Y-%m-%d %H:%M',
'#jscalendar_showsTime' => 'true',
'#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12',
'#size' => 19,
'#maxlength' => 19,
'#weight' => -14,
'#description' => t('YYYY-MM-DD HH:MM'),
);
}
else {
$form['event_start'] = array(
'#type' => 'fieldset',
'#title' => t('Start date'),
'#weight' => -15,
);
$form['event_start']['date'] = event_form_date($node->event_start ? $node->event_start : _event_user_time(), 'start', $node->start_offset);
$form['event_end'] = array(
'#type' => 'fieldset',
'#title' => t('End date'),
'#weight' => -14,
);
$form['event_end']['date'] = event_form_date($node->event_end ? $node->event_end : _event_user_time(), 'end', $node->end_offset);
}
if (variable_get('event_timezone_input', 'site') == 'input') {
$form['timezone'] = array(
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => $node->timezone ? $node->timezone : event_timezone_map(variable_get('date_default_timezone', 0)),
'#options' => event_zonelist(),
'#description' => t('Select the time zone this event occurs in.'),
'#weight' => -13,
);
}
elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone) && variable_get('event_timezone_input', 'site') == 'user') {
$form['timezone'] = array(
'#type' => 'hidden',
'#value' => event_timezone_map($user->timezone),
);
}
else {
$form['timezone'] = array(
'#type' => 'hidden',
'#value' => event_timezone_map(variable_get('date_default_timezone', 0)),
);
}
}
break;
}
}
function event_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if (variable_get('event_nodeapi_' . $node->type, 'never') != 'never') {
switch ($op) {
case 'validate':
case 'submit':
event_validate_form_date($node, 'start');
event_validate_form_date($node, 'end');
if ($node->event_end < $node->event_start) {
$node->event_end = $node->event_start;
}
switch (variable_get('event_timezone_display', 'event')) {
case 'event':
$node->start_offset = event_get_offset($node->timezone, $node->event_start);
$node->end_offset = event_get_offset($node->timezone, $node->event_end);
break;
case 'user':
global $user;
$node->start_offset = $node->end_offset = $user->timezone;
break;
case 'site':
$node->start_offset = $node->end_offset = variable_get('date_default_timezone', 0);
break;
}
$node->start_format = format_date($node->event_start, 'small', '', $node->start_offset);
$node->end_format = format_date($node->event_end, 'small', '', $node->end_offset);
break;
case 'insert':
db_query('INSERT INTO {event} (nid, event_start, event_end, timezone) VALUES (%d, %d, %d, %d)', $node->nid, $node->event_start, $node->event_end, $node->timezone);
event_set_range();
break;
case 'update':
db_query('DELETE FROM {event} WHERE nid = %d', $node->nid);
db_query('INSERT INTO {event} (nid, event_start, event_end, timezone) VALUES (%d, %d, %d, %d)', $node->nid, $node->event_start, $node->event_end, $node->timezone);
event_set_range();
break;
case 'delete':
db_query('DELETE FROM {event} WHERE nid = %d', $node->nid);
event_set_range();
break;
case 'load':
$object = db_fetch_object(db_query('SELECT event_start, event_end, timezone FROM {event} WHERE nid = %d', $node->nid));
switch (variable_get('event_timezone_display', 'event')) {
case 'event':
include_once EVENT_PATH . '/event_timezones.inc';
$start_offset = event_get_offset($object->timezone, $object->event_start);
$end_offset = event_get_offset($object->timezone, $object->event_end);
break;
case 'user':
global $user;
$start_offset = $end_offset = $user->timezone;
break;
case 'site':
$start_offset = $end_offset = variable_get('date_default_timezone', 0);
break;
}
$ctype = module_invoke('flexinode', 'load_content_type', $node->ctype_id);
return array(
'event_start' => $object->event_start,
'event_end' => $object->event_end,
'timezone' => $object->timezone,
'start_offset' => $start_offset,
'start_format' => format_date($object->event_start, 'small', '', $start_offset),
'start_time_format' => format_date($object->event_start, 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i', $start_offset),
'end_offset' => $end_offset,
'end_format' => format_date($object->event_end, 'small', '', $end_offset),
'end_time_format' => format_date($object->event_end, 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i', $end_offset),
'event_node_title' => $ctype->name ? $ctype->name : $node->type,
);
break;
case 'ical item':
break;
case 'view':
$node->content['event'] = array(
'#value' => theme('event_nodeapi', $node),
'#weight' => -10,
);
break;
case 'rss item':
$node->body = theme('event_nodeapi', $node) . $node->body;
$node->teaser = theme('event_nodeapi', $node) . $node->teaser;
break;
}
}
}
function event_get_types($state = NULL) {
static $types;
if (!is_array($types)) {
$types['all'] = array();
$types['solo'] = array();
$types['never'] = array();
$result = db_query("SELECT * FROM {variable} WHERE name like 'event_nodeapi_%'");
while ($type = db_fetch_object($result)) {
$types[unserialize($type->value)][] = substr($type->name, 14);
}
}
switch ($state) {
case 'all':
return $types['all'];
break;
case 'solo':
return $types['solo'];
break;
case 'never':
return $types['never'];
break;
default:
return $types;
break;
}
}
function event_enabled_state($type) {
$states = event_get_types();
foreach ($states as $key => $state) {
if (in_array($type, $state)) {
return $key;
}
}
}
function event_is_enabled($type) {
$states = event_get_types();
return in_array($type, $states['all']);
}
function event_set_range() {
$range = db_fetch_object(db_query('select MIN(e.event_start) AS event_start, MAX(e.event_end) AS event_end FROM {event} e'));
variable_set('event_range_prev', $range->event_start);
variable_set('event_range_next', $range->event_end);
}
function event_dst() {
include_once EVENT_PATH . '/event_timezones.inc';
$timestamp = time();
$zones = event_get_timezones();
foreach ($zones as $key => $zone) {
if ($zone['dst_region']) {
$list[$zone['dst_region']][] = $zone['timezone'] . ', ' . (event_is_dst($zone['dst_region'], $timestamp) ? 'In DST' : 'Not in DST') . ': ' . event_get_offset($key, $timestamp);
}
else {
$list[$zone['dst_region']][] = $zone['timezone'] . ': ' . event_get_offset($key, $timestamp);
}
}
$regions = event_get_dst_regions();
foreach ($list as $key => $region) {
$output .= theme('box', $regions[$key], theme('item_list', $region));
}
drupal_set_title(t('Daylight Savings Regions | Current GMT: !date', array(
'!date' => gmdate('m-d-Y, H:i', $timestamp),
)));
return $output;
}
function event_help($section) {
switch ($section) {
case 'admin/help#event':
$output = '<p>' . t('The event module allows for any type of content to be event enabled, meaning content can have a start and end time, and appear in calendars. The ability to event enable any content type combined with the ability to create new types of content make it possible to create unlimited types of calendars. The ability to broadly event enable content will allow for creative applications combining information and real world events.') . '</p>';
$output .= '<p>' . t('The administrator can decide which content types should be events for their site. In content type configuration, administrators can select the calendar view options: never, all views, or only views for this type. For example, this makes it possible to have a general calendar which shows all meetups and house parties in the same calendar, and have a separate calendar for rallies which only contains the rallies content type. Calendars can be customized to view a specific content type or a category of content, using taxonomies.') . '</p>';
$output .= '<p>' . t('Administrators can also set two types of options for events; general event options, and event overview options. General event options are for timezone configuration, time notation formats, and event block configuration. Event overview options allow calendar and table event default views. Administrators can also set general filter controls for content types and categories, via the event taxonomy controls.') . '</p>';
$output .= t('<p>You can</p>
<ul>
<li>enable content types to be event enabled at <a href="!admin-node-configure-types" title="content type configuration">administer >> content >> content types </a> then click configure for a content type.</li>
<li>administer general event options <a href="!admin-settings-event" title="administer events">administer >> settings >> events</a>.</li>
<li><a href="!node-add" title="list of content types that can be created">create content</a> and set a start and end time, if the administrator has set that content type to be event enabled.</li>
<li>use <a href="!external-http-drupal-org-handbook-modules-rsvp">RSVP</a> or <a href="!external-http-drupal-org-handbook-modules-signup">signup</a> module to invite users to events.</li>
', array(
'!admin-node-configure-types' => url('admin/content/types'),
'!admin-settings-event' => url('admin/event/event'),
'!node-add' => url('node/add'),
'!external-http-drupal-org-handbook-modules-signup' => 'http://drupal.org/project/signup',
'!external-http-drupal-org-handbook-modules-rsvp' => 'http://drupal.org/project/rsvp',
)) . '</ul>';
$output .= '<p>' . t('For more information please read the configuration and customization handbook <a href="!event">Event page</a>.', array(
'!event' => 'http://www.drupal.org/handbook/modules/event/',
)) . '</p>';
return $output;
case 'event/dst':
return t('This is a listing of all the event system\'s time zones, sorted by daylight savings time regions, and their respective offsets from GMT in seconds. Time zones in the \'None\' region do not observe daylight savings time. If you believe there is an error, please first search for the locale on !timeanddate and confirm it. If there is indeed an error please submit a !bugreport on drupal.org so we can fix it.', array(
'!timeanddate' => l('http://timeanddate.com/worldclock/search.html', 'http://timeanddate.com/worldclock/search.html'),
'!bugreport' => l('bug report', 'http://drupal.org/node/add/project-issue/event'),
));
}
}