[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  /**
   3   *  Preprocessor to construct back and next navigation from the date argument.
   4   */
   5  function template_preprocess_date_navigation(&$vars) {
   6    $view = $vars['view'];
   7    $next_args = $view->args;
   8    $prev_args = $view->args;
   9    $pos = $view->date_info->date_arg_pos;
  10    $min_date = is_object($view->date_info->min_date) ? $view->date_info->min_date : date_now();
  11    $max_date = is_object($view->date_info->max_date) ? $view->date_info->max_date : date_now();
  12  
  13    if (empty($view->date_info->hide_nav)) {
  14      $prev_date = drupal_clone($min_date);
  15      date_modify($prev_date, '-1 '. $view->date_info->granularity);
  16      $next_date = drupal_clone($min_date);
  17      date_modify($next_date, '+1 '. $view->date_info->granularity);
  18      $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d');
  19      switch ($view->date_info->granularity) {
  20        case 'week':
  21          $next_week = date_week(date_format($next_date, 'Y-m-d'));
  22          $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
  23          $next_arg = date_format($next_date, 'Y-\W') . $next_week;
  24          $prev_arg = date_format($prev_date, 'Y-\W') . $prev_week;
  25          break;
  26        default:
  27          $next_arg = date_format($next_date, $format[$view->date_info->granularity]);
  28          $prev_arg = date_format($prev_date, $format[$view->date_info->granularity]);
  29      }
  30      $next_path = str_replace($view->date_info->date_arg, $next_arg, $view->date_info->url);
  31      $prev_path = str_replace($view->date_info->date_arg, $prev_arg, $view->date_info->url);
  32      $next_args[$pos] = $next_arg;
  33      $prev_args[$pos] = $prev_arg;
  34      $vars['next_url'] = date_real_url($view, NULL, $next_arg);
  35      $vars['prev_url'] = date_real_url($view, NULL, $prev_arg);
  36      $vars['next_options'] = $vars['prev_options'] = array();
  37    }
  38    else {
  39      $next_path = '';
  40      $prev_path = '';
  41      $vars['next_url'] = '';
  42      $vars['prev_url'] = '';
  43      $vars['next_options'] = $vars['prev_options'] = array();
  44    }
  45  
  46    // Check whether navigation links would point to 
  47    // a date outside the allowed range.
  48    if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $view->date_info->max_allowed_year) {
  49      $vars['next_url'] = '';    
  50    }
  51    if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $view->date_info->min_allowed_year) {
  52      $vars['prev_url'] = '';    
  53    }
  54  
  55    $vars['prev_options'] += array('attributes' => array());
  56    $vars['next_options'] += array('attributes' => array());
  57    $prev_title = '';
  58    $next_title = '';
  59  
  60    // Build next/prev link titles.
  61    switch($view->date_info->granularity) {
  62      case 'year':
  63        $prev_title = t('Navigate to previous year');
  64        $next_title = t('Navigate to next year');
  65        break;
  66      case 'month':
  67        $prev_title = t('Navigate to previous month');
  68        $next_title = t('Navigate to next month');
  69        break;
  70      case 'week':
  71        $prev_title = t('Navigate to previous week');
  72        $next_title = t('Navigate to next week');
  73        break;      
  74      case 'day':
  75        $prev_title = t('Navigate to previous day');
  76        $next_title = t('Navigate to next day');
  77        break;
  78    }
  79    $vars['prev_options']['attributes'] += array('title' => $prev_title);
  80    $vars['next_options']['attributes'] += array('title' => $next_title);
  81  
  82    // Add nofollow for next/prev links.
  83    $vars['prev_options']['attributes'] += array('rel' => 'nofollow');
  84    $vars['next_options']['attributes'] += array('rel' => 'nofollow');
  85  
  86    $link = FALSE;
  87    // Month navigation titles are used as links in the block view.
  88      if (!empty($view->date_info->block) && $view->date_info->granularity == 'month') {
  89        $link = TRUE;
  90    }
  91  
  92    $nav_title = theme('date_nav_title', $view->date_info->granularity, $view, $link);
  93    $vars['nav_title'] = $nav_title;
  94    $vars['block'] = !empty($view->date_info->block);
  95  }
  96  
  97  /**
  98   * Theme the calendar title
  99   */
 100  function theme_date_nav_title($granularity, $view, $link = FALSE, $format = NULL) {
 101    switch ($granularity) {
 102      case 'year':
 103        $title = $view->date_info->year;
 104        $date_arg = $view->date_info->year;
 105        break;
 106      case 'month':
 107        $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F Y' : 'F');
 108        $title = date_format_date($view->date_info->min_date, 'custom', $format);
 109        $date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month);
 110        break;
 111      case 'day':
 112        $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'l, F j Y' : 'l, F j');
 113        $title = date_format_date($view->date_info->min_date, 'custom', $format);
 114        $date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day);
 115        break;
 116      case 'week':
 117          $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F j Y' : 'F j');
 118        $title = t('Week of @date', array('@date' => date_format_date($view->date_info->min_date, 'custom', $format)));
 119          $date_arg = $view->date_info->year .'-W'. date_pad($view->date_info->week);
 120          break;
 121    }
 122    if (!empty($view->date_info->mini) || $link) {
 123        // Month navigation titles are used as links in the mini view.
 124      $attributes = array('title' => t('View full page month'));
 125        $url = date_real_url($view, $granularity, $date_arg, TRUE);
 126      return l($title, $url, array('attributes' => $attributes));
 127    }
 128    else {
 129      return $title;
 130    }  
 131  }
 132  
 133  /**
 134   *  Preprocessor to construct an ical vcalendar
 135   * 
 136   * @param $events
 137   *   An array of events where each event is an array keyed on the uid:
 138   *    'start'
 139   *      Start date object,
 140   *    'end'
 141   *      End date object, optional, omit for all day event.
 142   *    'summary'
 143   *      Title of event (Text)
 144   *    'description'
 145   *      Description of event (Text)
 146   *    'location'
 147   *      Location of event (Text or vvenue id)
 148   *    'uid'
 149   *      ID of the event for use by calendaring program, usually the url of the node
 150   *    'url'
 151   *      URL of event information
 152   * 
 153   *    'alarm'
 154   *      sub-array of alarm information for the event, including:
 155   *      - 'action' - the action to take, either 'DISPLAY' or 'EMAIL'
 156   *      - 'trigger' - the time period for the trigger, like -P2D.
 157   *      - 'repeat' - the number of times to repeat the alarm.
 158   *      - 'duration' - the time period between repeated alarms, like P1D.
 159   *      - 'description' - the description of the alarm.
 160   *      An email alarm should have two additional parts:
 161   *      - 'email' - a comma-separated list of email recipients.
 162   *      - 'summary' - the subject of the alarm email.
 163   *
 164   * @param $calname
 165   *   Name of the calendar.  Use site name if none is specified.
 166   * 
 167   */
 168  function template_preprocess_date_vcalendar(&$vars) {
 169  
 170    $vars['current_date'] = date_format(date_now(), DATE_FORMAT_ICAL);
 171    $vars['current_date_utc'] = date_format(date_now('UTC'), DATE_FORMAT_ICAL);
 172    $vars['site_timezone'] = date_default_timezone_name();
 173    $vars['calname'] = date_ical_escape_text(!empty($vars['calname']) ? $vars['calname'] : variable_get('site_name', ''));
 174  
 175    // Format the event results as iCal expects.
 176    $events_in = $vars['events'];
 177    $events = array();
 178    $rows = $vars['rows'];
 179    foreach ($events_in as $uid => $event) {
 180      $row = array_shift($rows);
 181      // Omit any items with empty dates.
 182      if (!empty($event['start'])) {
 183        $events[$uid] = $event;
 184        $timezone = timezone_name_get(date_timezone_get($event['start']));
 185        if (!empty($timezone)) {
 186          $events[$uid]['timezone'] = "TZID=$timezone;";
 187        }
 188        else {
 189          $events[$uid]['timezone'] = '';
 190        }
 191        $date_format = ($row->calendar_all_day == TRUE) ? DATE_FORMAT_ICAL_DATE : DATE_FORMAT_ICAL;
 192        $events[$uid]['start'] = date_format($event['start'], $date_format);
 193        if ($event['start'] && $event['end']) {
 194          $events[$uid]['end'] = date_format($event['end'], $date_format);
 195        }
 196        else {
 197          $events[$uid]['end'] = $events[$uid]['start'];
 198        }
 199        foreach ($event as $key => $value) {
 200          if (is_string($value)) {
 201            $event[trim($key)] = trim($value);
 202          }
 203        }
 204  
 205        // Escape text values.
 206        foreach ($event as $key => $value) {
 207          if ($key == 'alarm') {
 208            foreach ($value as $alarm_key => $alarm_value) {
 209              if (in_array($alarm_key, array('summary', 'description'))) {
 210                $events[$uid]['alarm'][$alarm_key] = date_ical_escape_text($alarm_value);
 211              }
 212            }
 213          }
 214          elseif (in_array($key, array('summary', 'description', 'location'))) {
 215            $events[$uid][$key] = date_ical_escape_text(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
 216          }
 217        }
 218      }
 219    }
 220  
 221    $vars['events'] = $events;  
 222  }
 223  
 224  /**
 225   * Preprocessor for Date Views filter form.
 226   */
 227  function template_preprocess_date_views_filter_form(&$vars) {
 228    $form = $vars['form'];
 229    $vars['date'] = drupal_render($form['valuedate']);
 230    $vars['mindate'] = drupal_render($form['mindate']);
 231    $vars['maxdate'] = drupal_render($form['maxdate']);
 232    $vars['adjustment'] = drupal_render($form['valueadjustment']);
 233    $vars['minadjustment'] = drupal_render($form['minadjustment']);
 234    $vars['maxadjustment'] = drupal_render($form['maxadjustment']);
 235    $vars['description'] = drupal_render($form['description']) . drupal_render($form);
 236  }
 237  
 238  /**
 239   * Format a date timezone element.
 240   *
 241   * @param $element
 242   *   An associative array containing the properties of the element.
 243   *   Properties used: title, value, options, description, required and attributes.
 244   * @return
 245   *   A themed HTML string representing the date selection boxes.
 246   */
 247  function theme_date_timezone($element) {
 248    return '<div class="date-clear">'. theme('form_element', $element, $element['#children']) .'</div>';
 249  }
 250  
 251  /**
 252   * Format a date selection element.
 253   *
 254   * @param $element
 255   *   An associative array containing the properties of the element.
 256   *   Properties used: title, value, options, description, required and attributes.
 257   * @return
 258   *   A themed HTML string representing the date selection boxes.
 259   */
 260  function theme_date_select($element) {
 261    $output = '';
 262    $class = 'container-inline-date';
 263    // Add #date_float to allow date parts to float together on the same line. 
 264    if (empty($element['#date_float'])) {
 265      $class .= ' date-clear-block';
 266    }
 267    if (isset($element['#children'])) {
 268      $output = $element['#children'];
 269    }
 270    return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>';
 271  }
 272  
 273  /**
 274   * Format a date text element.
 275   *
 276   * @param $element
 277   *   An associative array containing the properties of the element.
 278   *   Properties used: title, value, options, description, required and attributes.
 279   * @return
 280   *   A themed HTML string representing the date selection boxes.
 281   */
 282  function theme_date_text($element) {
 283    $output = '';
 284    $class = 'container-inline-date';
 285    // Add #date_float to allow date parts to float together on the same line. 
 286    if (empty($element['#date_float'])) {
 287      $class .= ' date-clear-block';
 288    }
 289    if (isset($element['#children'])) {
 290      $output = $element['#children'];
 291    }
 292    return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>';
 293  }
 294  
 295  /**
 296   *  Themes for date input form elements
 297   */
 298  function theme_date_select_element($element) {
 299    $part = array_pop($element['#parents']);
 300    return '<div class="date-'. $part .'">'. theme('select', $element) .'</div>';
 301  }
 302  
 303  function theme_date_textfield_element($element) {
 304    $part = array_pop($element['#parents']);
 305    return '<div class="date-'. $part .'">'. theme('textfield', $element) .'</div>';
 306  }
 307  
 308  /**
 309   * Functions to separate date parts in form.
 310   *
 311   * Separators float up to the title level for elements with titles,
 312   * so won't work if this element has titles above the element date parts.
 313   */
 314  function theme_date_part_hour_prefix($element) {
 315    if ($element['#date_label_position'] != 'above') {
 316      return '<span class="form-item date-spacer">&nbsp;-&nbsp;</span>';
 317    }
 318  }
 319  
 320  function theme_date_part_minsec_prefix($element) {
 321    if ($element['#date_label_position'] != 'above') {
 322      return '<span class="form-item date-spacer">:</span>';
 323    }
 324  }
 325  
 326  /**
 327   * Format labels for each date part in a date_select.
 328   *
 329   * @param $part_type
 330   *   the type of field used for this part, 'textfield' or 'select'
 331   * @param $element
 332   *   An associative array containing the properties of the element.
 333   *   Properties used: title, value, options, description, required and attributes.
 334   */
 335  function theme_date_part_label_year($part_type, $element) {
 336    return date_t('Year', 'datetime');
 337  }
 338  function theme_date_part_label_month($part_type, $element) {
 339    return date_t('Month', 'datetime');
 340  }
 341  function theme_date_part_label_day($part_type, $element) {
 342    return date_t('Day', 'datetime');
 343  }
 344  function theme_date_part_label_hour($part_type, $element) {
 345    return date_t('Hour', 'datetime');
 346  }
 347  function theme_date_part_label_minute($part_type, $element) {
 348    return date_t('Minute', 'datetime');
 349  }
 350  function theme_date_part_label_second($part_type, $element) {
 351    return date_t('Second', 'datetime');
 352  }
 353  function theme_date_part_label_ampm($part_type, $element) {
 354    return ' ';
 355  }
 356  function theme_date_part_label_timezone($part_type, $element) {
 357    return t('Timezone');
 358  }
 359  
 360  /**
 361   * Theme for a date block that looks like a mini calendar day.
 362   * Pass in a date object already set to the right timezone, 
 363   * format as a calendar page date. The calendar styling is created in css.
 364   */
 365  function theme_date_calendar_day($date) {
 366    if (empty($date)) {
 367      return NULL;
 368    }
 369    return '<div class="date-calendar-day">' .
 370      '<span class="month">' . date_format_date($date, 'custom', 'M') . '</span>' .
 371      '<span class="day">' . date_format_date($date, 'custom', 'j') . '</span>' .
 372      '<span class="year">' . date_format_date($date, 'custom', 'Y') . '</span>' .
 373    '</div>';
 374  }
 375  
 376  function theme_date_time_ago($start_date, $end_date, $interval = 2) {
 377    // If no date is sent, then return nothing
 378    if (empty($start_date) || empty($end_date)){
 379      return NULL;
 380    }
 381  
 382    // Time to compare dates to
 383    $now = date_format(date_now(), DATE_FORMAT_DATETIME);
 384    $start = date_format($start_date, DATE_FORMAT_DATETIME);
 385    $end = date_format($end_date, DATE_FORMAT_DATETIME);
 386  
 387    // 1) The date is entirely in the future
 388    if ($now < $start) {
 389      return t('!time from now', array('!time' => date_format_interval($start_date, $interval)));
 390    }
 391    // 2) Ongoing date
 392    elseif ($now > $start && $now <= $end) {
 393      //return t('Started !time ago', array('!time' => $dates['value']['interval']));
 394      return t('ongoing');
 395    }
 396    // 3) Date is in the past (format_interval added 'ago' to the value).
 397    else {
 398      return date_format_interval($start_date, $interval);
 399    }
 400  }


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