You are here

function event_page in Event 5

Same name and namespace in other branches
  1. 5.2 event.module \event_page()

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

Return value

the content for the event page.

Related topics

1 string reference to 'event_page'
event_menu in ./event.module
Implementation of hook_menu()

File

./event.module, line 266

Code

function event_page($year = NULL, $month = NULL, $day = NULL, $view = NULL, $types = NULL, $tids = NULL, $duration = NULL) {

  // get local timestamp value
  $now = _event_user_time();

  // create request timestamp and date values
  $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) {

    // The '+' character in a query string may be parsed as ' '.
    $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)) {

      // 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);
      }
    }
  }

  // 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 = 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':

      // week view
      // setup calendar table header
      $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':

      // month view
      $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':

      // 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');
      $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':

      // 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');
      $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':

      // 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($stamp, $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($stamp, $duration, $types, $terms, $title);
      break;
    case 'block':

      // block update
      $time = _event_user_date();
      if (arg(0) == 'event' && is_numeric(arg(1))) {

        // follow event calendar
        $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') {

    // build header navigation
    $prev = _event_nav($stamp, 'prev', $view, $types, $terms, $duration);
    $next = _event_nav($stamp, 'next', $view, $types, $terms, $duration);

    // setup calendar table header
    $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);

    // Add RSS feed and icon to events page
    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;
  }
}