[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/calendar/calendar_ical/ -> theme.inc (source)

   1  <?php
   2  // $Id: theme.inc,v 1.1.2.15 2010/11/21 11:00:56 karens Exp $
   3  /**
   4   * Preprocess an ical feed
   5   */
   6  function template_preprocess_calendar_view_ical(&$vars) {
   7    global $base_url;
   8    global $language;
   9   
  10    $view     = &$vars['view'];
  11    $options  = &$vars['options'];
  12    $items    = &$vars['rows'];
  13    
  14    $style    = &$view->style_plugin;
  15  
  16    // Figure out which display which has a path we're using for this feed. If there isn't
  17    // one, use the global $base_url
  18    $link_display = $view->display_handler->get_link_display();
  19  
  20    // Compare the link to the default home page; if it's the default home page, just use $base_url.
  21    if (empty($vars['link'])) {
  22      $vars['link'] = $base_url;
  23    }
  24  
  25    // Keep devel module from appending queries to ical export.
  26    $GLOBALS['devel_shutdown'] = FALSE;
  27    
  28    drupal_set_header('Content-Type: text/calendar; charset=utf-8');
  29    drupal_set_header('Content-Disposition: attachment; filename="calendar.ics"; ');
  30    require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_ical.inc');
  31    require_once('./'. drupal_get_path('module', 'date_api') .'/theme/theme.inc');
  32    require_once('./'. drupal_get_path('module', 'calendar') .'/includes/calendar.inc');
  33    
  34    $events = array();
  35    // Get the alias name for each of our data fields.
  36    foreach ($view->field as $name => $field) {
  37      // Some fields, like the node edit and delete links, have no alias.
  38      $field_alias = $field->field_alias != 'unknown' ? $field->field_alias : $name; 
  39      foreach (array('summary_field', 'description_field', 'location_field') as $data) {
  40        if ($field->field == $view->date_info->$data) {
  41          $$data = $field_alias;
  42        }
  43      }
  44    }
  45    // A summary field is required, default to the title.
  46    if (empty($summary_field) || $summary_field == 'node_title') {
  47      $summary_field = 'title';
  48    }
  49    foreach ($items as $node) {
  50      // We cannot process an event that is missing the summary info.
  51      if (empty($node->$summary_field)) {
  52        continue;
  53      }
  54      // Allow modules to affect item fields
  55      node_invoke_nodeapi($node, 'ical item');
  56      unset($node->view);
  57      $rrule_field = str_replace(array('_value2', '_value'), '_rrule', $node->datefield);
  58      $event = array();
  59      $event['summary'] = strip_tags($node->$summary_field);
  60      $event['start'] = $node->calendar_start_date;
  61      $event['end'] = $node->calendar_end_date;
  62      $event['description'] = !empty($description_field) && !empty($node->$description_field) ? $node->$description_field : '';
  63      $event['location'] = !empty($location_field) && !empty($node->$location_field) ? $node->$location_field : '';
  64      $event['url'] = !empty($node->url) ? $node->url : (is_numeric($node->nid) ? url("node/$node->nid", array('absolute' => TRUE)) : $node->nid);
  65      $event['uid'] = !empty($node->date_id) ? $node->date_id : $event['url'];
  66      $event['rrule'] = !empty($rrule_field) && !empty($node->$rrule_field) ? $node->$rrule_field : '';
  67      $events[$event['uid']] = $event;
  68  
  69      /* force UTC timezone */
  70      date_timezone_set($event['start'], timezone_open('UTC'));
  71      date_timezone_set($event['end'], timezone_open('UTC'));
  72    }
  73    
  74    $headertitle = filter_xss_admin($view->get_title());
  75    $title = variable_get('site_name', 'Drupal');
  76    $description = $headertitle . ($title ? ' | '. $title : '');
  77    
  78    $vars['calname'] = $description;
  79    $vars['events'] = $events;
  80    template_preprocess_date_vcalendar($vars);
  81  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7