function holidayspotter_date_nav_title($params)
{
    $granularity = $params['granularity'];
    $view = $params['view'];
    $date_info = $view->date_info;
    $link = !empty($params['link']) ? $params['link'] : FALSE;
    $format = !empty($params['format']) ? $params['format'] : NULL;
    switch ($granularity) {
        case 'year':
            $title = $date_info->year;
            $date_arg = $date_info->year;
            break;
        case 'month':
            $format = !empty($format) ? $format : (empty($date_info->mini) ? 'F Y' : 'F Y');
            $title = date_format_date($date_info->min_date, 'custom', $format);
            $date_arg = $date_info->year . '-' . date_pad($date_info->month);
            break;
        case 'day':
            $format = !empty($format) ? $format : (empty($date_info->mini) ? 'l, F j Y' : 'l, F j');
            $title = date_format_date($date_info->min_date, 'custom', $format);
            $date_arg = $date_info->year . '-' . date_pad($date_info->month) . '-' . date_pad($date_info->day);
            break;
        case 'week':
            $format = !empty($format) ? $format : (empty($date_info->mini) ? 'F j Y' : 'F j');
            $title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
            $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
            break;
    }
    if (!empty($date_info->mini) || $link) {
        // Month navigation titles are used as links in the mini view.
        $attributes = array('title' => t('View full page month'));
        $url = date_pager_url($view, $granularity, $date_arg, TRUE);
        return l($title, $url, array('attributes' => $attributes));
    } else {
        return $title;
    }
}
Beispiel #2
0
/**
 * Theme the calendar title
 *
 * Copied and modified from date_views module theme.inc
 */
function az_gov_date_nav_title($params)
{
    $granularity = $params['granularity'];
    $view = $params['view'];
    $date_info = $view->date_info;
    $link = !empty($params['link']) ? $params['link'] : FALSE;
    $format = !empty($params['format']) ? $params['format'] : NULL;
    $format_with_year = variable_get('date_views_' . $granularity . 'format_with_year', 'l, F j, Y');
    $format_without_year = variable_get('date_views_' . $granularity . 'format_without_year', 'l, F j');
    switch ($granularity) {
        case 'year':
            $title = $date_info->year;
            $date_arg = $date_info->year;
            break;
        case 'month':
            //customized format for month display
            //$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
            $format = 'F Y';
            $title = date_format_date($date_info->min_date, 'custom', $format);
            $date_arg = $date_info->year . '-' . date_pad($date_info->month);
            break;
        case 'day':
            $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
            $title = date_format_date($date_info->min_date, 'custom', $format);
            $date_arg = $date_info->year . '-' . date_pad($date_info->month) . '-' . date_pad($date_info->day);
            break;
        case 'week':
            $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
            $title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
            $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
            break;
    }
    if (!empty($date_info->mini) || $link) {
        // Month navigation titles are used as links in the mini view.
        $attributes = array('title' => t('View full page month'));
        $url = date_pager_url($view, $granularity, $date_arg, TRUE);
        return l($title, $url, array('attributes' => $attributes));
    } else {
        return $title;
    }
}
/**
 * Preprocess function for Date pager template.
 */
function rfht2_preprocess_date_views_pager(&$vars)
{
    ctools_add_css('date_views', 'date_views');
    $plugin = $vars['plugin'];
    $input = $vars['input'];
    $view = $plugin->view;
    $vars['nav_title'] = '';
    $vars['next_url'] = '';
    $vars['prev_url'] = '';
    if (empty($view->date_info) || empty($view->date_info->min_date)) {
        return;
    }
    $date_info = $view->date_info;
    // Make sure we have some sort of granularity.
    $granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
    $pos = $date_info->date_arg_pos;
    if (!empty($input)) {
        $id = $plugin->options['date_id'];
        if (array_key_exists($id, $input) && !empty($input[$id])) {
            $view->args[$pos] = $input[$id];
        }
    }
    $next_args = $view->args;
    $prev_args = $view->args;
    $min_date = $date_info->min_date;
    $max_date = $date_info->max_date;
    // Set up the pager link format. Setting the block identifier
    // will force pager style links.
    if (isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean' || !empty($date_info->mini)) {
        if (empty($date_info->block_identifier)) {
            $date_info->block_identifier = $date_info->pager_id;
        }
    }
    if (empty($date_info->hide_nav)) {
        $prev_date = clone $min_date;
        date_modify($prev_date, '-1 ' . $granularity);
        $next_date = clone $min_date;
        date_modify($next_date, '+1 ' . $granularity);
        $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d');
        switch ($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') . date_pad($next_week);
                $prev_arg = date_format($prev_date, 'Y-\\W') . date_pad($prev_week);
                break;
            default:
                $next_arg = date_format($next_date, $format[$granularity]);
                $prev_arg = date_format($prev_date, $format[$granularity]);
        }
        $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
        $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
        $next_args[$pos] = $next_arg;
        $prev_args[$pos] = $prev_arg;
        $vars['next_url'] = date_pager_url($view, NULL, $next_arg);
        $vars['prev_url'] = date_pager_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') > $date_info->limit[1]) {
        $vars['next_url'] = '';
    }
    if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
        $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 ($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');
    // Need this so we can use '&laquo;' or images in the links.
    $vars['prev_options'] += array('html' => TRUE);
    $vars['next_options'] += array('html' => TRUE);
    $link = FALSE;
    // Month navigation titles are used as links in the block view.
    if (!empty($date_info->mini) && $granularity == 'month') {
        $link = TRUE;
    }
    $params = array('granularity' => $granularity, 'view' => $view, 'link' => $link);
    $nav_title = theme('date_nav_title', $params);
    $vars['nav_title'] = $nav_title;
    $vars['mini'] = !empty($date_info->mini);
    // Get the date information from the view.
    $date_info = $view->date_info;
    // Choose the dislpay format of the month name.
    $format = 'F';
    // Get the previous month.
    $dateString = $date_info->min_date;
    $prev_month = new DateTime($dateString);
    $prev_month->modify('-1 month');
    $prev_pager_title = format_date($prev_month->getTimestamp(), 'custom', $format);
    $vars['prev_title'] = $prev_pager_title;
    // Get the next month.
    $next_month = new DateTime($dateString);
    $next_month->modify('+1 month');
    $next_pager_title = format_date($next_month->getTimestamp(), 'custom', $format);
    $vars['next_title'] = $next_pager_title;
}
/**
 * Overriding alendar links above the pager.
 */
function glossy_preprocess_date_views_pager(&$vars) {
  $view = $vars['plugin']->view;
  if ($view->plugin_name != 'calendar_style') {
    return;
  }
  $options = $view->style_options;

  // If we're not on a view with a path (a page), no links are needed.
  $current_path = !empty($view->display_handler->options['path']) ? $view->display_handler->options['path'] : '';
  if (empty($current_path)) {
    return;
  }
  // Find all the displays in this view that use the calendar style and have a path and create links to each.
  $calendar_links = array();
  $base = array('attributes' => array('rel' => 'nofollow'));
  foreach($view->display as $id => $display) {

    if ($display->display_options['style_plugin'] == 'calendar_style' && !empty($display->display_options['path'])) {
      $path = $display->display_options['path'];
      $title = $display->display_title;
      // @TODO Why is this sometimes empty for a style that uses the default value?
      $type = !empty($display->display_options['style_options']['calendar_type']) ? $display->display_options['style_options']['calendar_type'] : 'month';

      // Make sure the links to other calendar displays use the right path for that display.
      // Get rid of pager links when swapping between displays to force the base argument 
      // to be structured correctly for the type of display. This means you can't use
      // these links in a block or panel.
      $href = str_replace($current_path, $path, date_pager_url($view, $type, NULL, TRUE));

      // Once we have a path for the links to other displays, add it to our links array.
      $calendar_links['calendar calendar-'. $type] = array('title' => $title, 'href' => $href);
    }
  }

  // If an 'Add new ... link is provided, add it here.
  // the query will bring the user back here after adding the node.
  if (!empty($view->date_info->calendar_date_link) 
  && (user_access("administer nodes") || user_access('create '. $view->date_info->calendar_date_link .' content'))) {
    $name = node_type_get_name($view->date_info->calendar_date_link);
    $href = 'node/add/' . str_replace('_', '-', $view->date_info->calendar_date_link);
    $query = drupal_get_query_parameters(array('destination' => $view->date_info->url));    
    $calendar_links['calendar calendar-add'] = $base + array(
      'title' => t('Add+'), 
      'href' => $href, 
      'query' => $query,
      );
  }

  // Append the calendar links above the pager.
	$type = arg(1);
	$type = isset($type) && in_array($type, array('day', 'week', 'month', 'year')) ? $type : '';
  $links = array(
    'links' => $calendar_links, 
    'attributes' => array('class' => array('calendar-links', 'item-list', $type, 'clearfix')),
  );
  $vars['pager_prefix'] = theme('links', $links);
}