You are here

function theme_calendar_links in Calendar 5.2

Same name and namespace in other branches
  1. 5 calendar.theme \theme_calendar_links()

Links at the top of the calendar.

Parameters

links: TRUE/FALSE, should links be shown.

view: The current view being rendered

4 theme calls to theme_calendar_links()
calendar_build_calendar in ./calendar.inc
Build calendar
theme_calendar_view_list in ./calendar.theme
Display the nodes of a view as a list.
theme_calendar_view_nodes in ./calendar.theme
Display the nodes of a view as plain nodes.
theme_calendar_view_table in ./calendar.theme
Display the nodes of a view as a table.

File

./calendar.theme, line 365

Code

function theme_calendar_links($view, $links = FALSE) {
  $now = date_now();

  // add links to the top of the calendar to switch from one view to another
  if ($links) {
    $view->month = $view->month && $view->month != CALENDAR_EMPTY_ARG ? $view->month : date_format($now, 'm');
    $view->day = $view->day && $view->day != CALENDAR_EMPTY_ARG ? $view->day : date_format($now, 'j');
    if (empty($view->week) || $view->week == CALENDAR_EMPTY_ARG) {
      $view->week = date_week($view->year . '-' . date_pad($view->month) . '-' . date_pad($view->day));
    }
    $formats = calendar_get_formats($view);

    // For "page" views, add the arguments to the path.
    if ($view->build_type == 'page') {
      $query_string = calendar_querystring($view, !empty($_GET['view']) ? array(
        'view' => $_GET['view'],
      ) : array());
      $base = array(
        'attributes' => array(
          'rel' => 'nofollow',
        ),
      );
      if (!empty($formats['year'])) {
        $calendar_links[] = $base + array(
          'title' => t('Year'),
          'href' => $view->real_url . '/' . $view->year,
          'query' => $query_string,
        );
      }
      if (!empty($formats['month'])) {
        $calendar_links[] = array(
          'title' => t('Month'),
          'href' => $view->real_url . '/' . $view->year . '/' . $view->month,
          'query' => $query_string,
        );
      }
      if (!empty($formats['week'])) {
        $calendar_links[] = array(
          'title' => t('Week'),
          'href' => $view->real_url . '/' . $view->year . '/W' . $view->week,
          'query' => $query_string,
        );
      }
      if (!empty($formats['day'])) {
        $calendar_links[] = array(
          'title' => t('Day'),
          'href' => $view->real_url . '/' . $view->year . '/' . $view->month . '/' . $view->day,
          'query' => $query_string,
        );
      }
    }
    else {
      $block_identifier = isset($view->block_identifier) ? $view->block_identifier : 'mini';
      $base = array(
        'href' => $view->page_url,
        'attributes' => array(
          'rel' => 'nofollow',
        ),
      );
      if (!empty($_GET['view'])) {
        $query_params['view'] = $_GET['view'];
      }
      if (!empty($formats['year'])) {
        $query_params[$block_identifier] = $view->real_url . '/' . $view->year;
        $calendar_links[] = $base + array(
          'title' => t('Year'),
          'query' => calendar_querystring($view, $query_params),
        );
      }
      if (!empty($formats['month'])) {
        $query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/' . $view->month;
        $calendar_links[] = $base + array(
          'title' => t('Month'),
          'query' => calendar_querystring($view, $query_params),
        );
      }
      if (!empty($formats['week'])) {
        $query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/W' . $view->week;
        $calendar_links[] = $base + array(
          'title' => t('Week'),
          'query' => calendar_querystring($view, $query_params),
        );
      }
      if (!empty($formats['day'])) {
        $query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/' . $view->month . '/' . $view->day;
        $calendar_links[] = $base + array(
          'title' => t('Day'),
          'query' => calendar_querystring($view, $query_params),
        );
      }
    }

    // If this is a page, add a popup date selector.
    if ($view->build_type == 'page' && variable_get('calendar_popup_' . $view->name, 0)) {
      $output = '<div class="clear-block">' . calendar_date_select($view) . '</div>';
    }
    $output .= theme('links', $calendar_links);
    return $output;
  }
}