event_page

Versions
5 – 6
event_page($year = NULL, $month = NULL, $day = NULL, $view = NULL, $types = NULL, $tids = NULL, $duration = NULL)

Displays a page containing event information. The page layout defaults to a graphical calendar.

Return value

the content for the event page.

Related topics

Code

contrib/event/event.module, line 395

<?php
function event_page($year = NULL, $month = NULL, $day = NULL, $view = NULL, $types = NULL, $tids = NULL, $duration = NULL) {
  event_include_files();

  // get local date value
  $now = _event_user_date();

  // date values
  $year = (isset($year) && is_numeric($year)) ? $year : $now['year'];
  $month = (isset($month) && is_numeric($month)) ? $month : $now['month'];
  $day = (isset($day) && is_numeric($day)) ? $day : $now['day'];

  $date = $now;
  $date['year'] = $year;
  $date['month'] = $month;
  $date['day'] = $day;
  $date['second'] = '00';
  $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 .'/'. check_plain($duration));
  }

  if (isset($_POST['event_term_select'])) {
    drupal_goto('event/'. $year .'/'. $month .'/'. $day .'/'. $view .'/'. ($types ? $types : 'all') .'/'. check_plain($_POST['event_term_select']) .'/'. check_plain($duration));
  }

  $breadcrumbs[] = l(t('Home'), NULL);
  $breadcrumbs[] = l(t('Events'), 'event');
  $links = array();
  $filter = array();

  if (!empty($types)) {
    // The '+' character in a query string may be parsed as ' '.
    $types = preg_split('/[+ ]/', $types);
    foreach ($types as $type) {
      if ($name = node_get_types('name', $type)) {
        $x = module_invoke($type, 'node_name', $node);
        $temp[$x] = $type;
        $filter[] = module_invoke($type, 'node_name', $node);
      }
    }

    if (!empty($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;
      $title = '';
    }
  }

  $terms = null;
  if (!empty($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)) {
      // The '+' character in a query string may be parsed as ' '.
      $terms = preg_split('/[+ ]/', $tids);
    }
    else if (preg_match('/^([0-9]+,)*[0-9]+$/', $tids)) {
      $terms = explode(',', $tids);
    }
  }

  $output = '';

  // add taxonomy filter controls to top of calendar
  if (variable_get('event_taxonomy_control', 'all') == 'all' || (variable_get('event_taxonomy_control', 'all') == 'request' && isset($terms))) {
    $output .= _event_get_taxonomy_control($terms);
  }
  // add content type filter controls to top of calendar
  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':
      // day view
      $caption = event_format_date($date, 'custom', t('l F d, Y'));
      list($thead, $tbody) = event_calendar_day('page', $date, $types, $terms);
      $ical_date = $date;
      $duration = 1;
      break;
    case 'week':
      // week view
      // setup calendar table header
      $dow = _event_day_of_week($date);
      $start_date = event_date_later($date, -1 * $dow);
      $temp = event_format_date($start_date, 'custom', 'F-j-Y');
      $temp = explode('-', $temp);
      $caption = t('Week of !month !day, !year', array('!month' => $temp[0], '!day' => $temp[1], '!year' => $temp[2]));
      $colspan = 5;
      list($thead, $tbody) = event_calendar_week('page', $date, $types, $terms);
      $ical_date = $start_date;
      $ical_date['hour'] = '00';
      $ical_date['minute'] = '00';
      $ical_date['second'] = '00';
      $ical_duration = 7;
      break;
    case 'month':
      // month view
      $caption = event_format_date($date, 'custom', t('F Y'));
      $colspan = 5;
      list($thead, $tbody) = event_calendar_month('page', $date, $types, $terms);
      $ical_date = $date;
      $ical_date['day'] = '01';
      $ical_date['hour'] = '00';
      $ical_date['minute'] = '00';
      $ical_date['second'] = '00';
      $ical_duration = date('t', mktime(0, 0, 0, $date['month'], 1, $date['year']));
      break;
    case 'table':
      // table view
      // next 30 day view, $duration can be set for different ranges
      // but set a maximum $duration of 1 year.
      $duration = $duration && $duration <= 366 ? $duration : variable_get('event_table_duration', '30');
      $end_date = event_date_later($date, $duration);
      $caption = event_format_date($date, 'custom', t('F d Y')) .' - '. event_format_date($end_date, 'custom', t('F d Y'));
      list($thead, $tbody) = event_calendar_table('page', $date, $end_date, $types, $terms);
      $ical_date = $date;
      $ical_duration = $duration;
      $ical_date['hour'] = '00';
      $ical_date['minute'] = '00';
      $ical_date['second'] = '00';
      break;
    case 'list':
      // list view
      // next 30 day view, $duration can be set for different ranges
      // but set a maximum $duration of 1 year.
      $duration = $duration && $duration <= 366 ? $duration : variable_get('event_table_duration', '30');
      $end_date = event_date_later($date, $duration);
      $caption = event_format_date($date, 'custom', t('F d Y')) .' - '. event_format_date($end_date, 'custom', t('F d Y'));
      $tbody = event_calendar_list('page', $date, $end_date, $types, $terms);
      $ical_date = $date;
      $ical_duration = $duration;
      $ical_date['hour'] = '00';
      $ical_date['minute'] = '00';
      $ical_date['second'] = '00';
      break;
    case 'feed':
      // rss feed
      drupal_set_header('Content-Type: text/xml; charset=utf-8');
      $duration = $duration ? $duration : variable_get('event_table_duration', '30');
      print event_calendar_rss($date, $duration, $types, $terms, $title);
      break;
    case 'ical':
      // ical feed
      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($date, $duration, $types, $terms, $title);
      break;
    case 'block':
      // block update
      $date = _event_user_date();
      if (arg(0) == 'event' && is_numeric(arg(1))) {
        // follow event calendar
        $date['year'] = (arg(1) ? arg(1) : $time['year']);
        $date['month'] = (arg(2) ? arg(2) : $time['month']);
        $date['day'] = (arg(3) ? arg(3) : $time['day']);
      }
      print event_calendar_month('block', $date);
      break;
  }

  if ($view != 'feed' && $view != 'ical' && $view != 'block') {
    // build header navigation
    $prev = _event_nav($date, 'prev', $view, $types, $terms, $duration);
    $next = _event_nav($date, 'next', $view, $types, $terms, $duration);

    // setup calendar table header
    $caption = $prev .' '. $caption .' '. $next;
    $node->event = array();
    $node->event['start_exploded'] = array('year' => $year, 'month' => $month, 'day' => $day);
    $node->event['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', (!empty($thead) ? $thead : array()), $tbody, array(), $caption);
    $output .= theme('event_ical_link', 'event/'. (isset($ical_date) ? _event_format_url($ical_date) : _event_format_url($date)) .'/ical/'. $node->event['filter'] . (isset($ical_duration) ? "/$ical_duration" :''));

    // Add RSS feed and icon to events page
    drupal_add_feed(url('event/feed', array('absolute' => TRUE)), t('Events at %site', array('%site' => variable_get('site_name', 'drupal'))));

    drupal_set_title(t('Events') . (!empty($title) ? ' - '. $title : ''));
    drupal_set_breadcrumb($breadcrumbs);
    return $output;
  }
}
?>