You are here

function template_preprocess_date_navigation in Date 7

Same name and namespace in other branches
  1. 6.2 theme/theme.inc \template_preprocess_date_navigation()
  2. 6 theme/theme.inc \template_preprocess_date_navigation()

Preprocessor to construct back and next navigation from the date argument.

File

date_views/theme/theme.inc, line 11
Theme files for Date API.

Code

function template_preprocess_date_navigation(&$vars) {
  $view = $vars['view'];
  $next_args = $view->args;
  $prev_args = $view->args;
  $pos = $view->date_info->date_arg_pos;
  $min_date = is_object($view->date_info->min_date) ? $view->date_info->min_date : date_now();
  $max_date = is_object($view->date_info->max_date) ? $view->date_info->max_date : date_now();
  if (empty($view->date_info->hide_nav)) {
    $prev_date = clone $min_date;
    date_modify($prev_date, '-1 ' . $view->date_info->granularity);
    $next_date = clone $min_date;
    date_modify($next_date, '+1 ' . $view->date_info->granularity);
    $format = array(
      'year' => 'Y',
      'month' => 'Y-m',
      'day' => 'Y-m-d',
    );
    switch ($view->date_info->granularity) {
      case 'week':
        $next_week = date_week(date_format($next_date, 'Y-m-d'));
        $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
        $next_arg = date_format($next_date, 'Y-\\W') . $next_week;
        $prev_arg = date_format($prev_date, 'Y-\\W') . $prev_week;
        break;
      default:
        $next_arg = date_format($next_date, $format[$view->date_info->granularity]);
        $prev_arg = date_format($prev_date, $format[$view->date_info->granularity]);
    }
    $next_path = str_replace($view->date_info->date_arg, $next_arg, $view->date_info->url);
    $prev_path = str_replace($view->date_info->date_arg, $prev_arg, $view->date_info->url);
    $next_args[$pos] = $next_arg;
    $prev_args[$pos] = $prev_arg;
    $vars['next_url'] = date_real_url($view, NULL, $next_arg);
    $vars['prev_url'] = date_real_url($view, NULL, $prev_arg);
    $vars['next_options'] = $vars['prev_options'] = array();
  }
  else {
    $next_path = '';
    $prev_path = '';
    $vars['next_url'] = '';
    $vars['prev_url'] = '';
    $vars['next_options'] = $vars['prev_options'] = array();
  }

  // Check whether navigation links would point to
  // a date outside the allowed range.
  if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $view->date_info->max_allowed_year) {
    $vars['next_url'] = '';
  }
  if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $view->date_info->min_allowed_year) {
    $vars['prev_url'] = '';
  }
  $vars['prev_options'] += array(
    'attributes' => array(),
  );
  $vars['next_options'] += array(
    'attributes' => array(),
  );
  $prev_title = '';
  $next_title = '';

  // Build next/prev link titles.
  switch ($view->date_info->granularity) {
    case 'year':
      $prev_title = t('Navigate to previous year');
      $next_title = t('Navigate to next year');
      break;
    case 'month':
      $prev_title = t('Navigate to previous month');
      $next_title = t('Navigate to next month');
      break;
    case 'week':
      $prev_title = t('Navigate to previous week');
      $next_title = t('Navigate to next week');
      break;
    case 'day':
      $prev_title = t('Navigate to previous day');
      $next_title = t('Navigate to next day');
      break;
  }
  $vars['prev_options']['attributes'] += array(
    'title' => $prev_title,
  );
  $vars['next_options']['attributes'] += array(
    'title' => $next_title,
  );

  // Add nofollow for next/prev links.
  $vars['prev_options']['attributes'] += array(
    'rel' => 'nofollow',
  );
  $vars['next_options']['attributes'] += array(
    'rel' => 'nofollow',
  );
  $link = FALSE;

  // Month navigation titles are used as links in the block view.
  if (!empty($view->date_info->block) && $view->date_info->granularity == 'month') {
    $link = TRUE;
  }
  $params = array(
    'granularity' => $view->date_info->granularity,
    'view' => $view,
    'link' => $link,
  );
  $nav_title = theme('date_nav_title', $params);
  $vars['nav_title'] = $nav_title;
  $vars['block'] = !empty($view->date_info->block);
}