You are here

function date_real_url in Date 6.2

Same name and namespace in other branches
  1. 7 date_views/date_views.module \date_real_url()

Figure out the URL of the date view we're currently looking at, adapted to various date types or specific date arguments.

Parameters

$date_type:

  • if not empty, return the url of a specific date type.

$date_arg:

  • if not empty, return the url for a view with a specific date argument.

$force_view_url:

  • always use the view url, even if embedded.

Return value

return the requested view url.

2 calls to date_real_url()
template_preprocess_date_navigation in theme/theme.inc
Preprocessor to construct back and next navigation from the date argument.
theme_date_nav_title in theme/theme.inc
Theme the calendar title

File

./date_api.module, line 2415
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_real_url($view, $date_type = NULL, $date_arg = NULL, $force_view_url = FALSE) {
  $args = $view->args;
  $pos = $view->date_info->date_arg_pos;

  // The View arguments array is indexed numerically but is not necessarily
  // in numerical order. Sort the arguments to ensure the correct order.
  ksort($args);

  // If there are empty arguments before the date argument,
  // pad them with the wildcard so the date argument will be in
  // the right position.
  if (count($args) < $pos) {
    foreach ($view->argument as $name => $argument) {
      if ($argument->position == $pos) {
        break;
      }
      $args[] = $argument->options['wildcard'];
    }
  }
  if (!empty($date_type)) {
    switch ($date_type) {
      case 'year':
        $args[$pos] = date_pad($view->date_info->year, 4);
        break;
      case 'week':
        $args[$pos] = date_pad($view->date_info->year, 4) . '-W' . date_pad($view->date_info->week);
        break;
      case 'day':
        $args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month) . '-' . date_pad($view->date_info->day);
        break;
      default:
        $args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month);
        break;
    }
  }
  elseif (!empty($date_arg)) {
    $args[$pos] = $date_arg;
  }
  else {
    $args = $view->args;
  }

  // Is this an embedded or a block view?
  if (!$force_view_url && (!empty($view->preview) || !empty($view->date_info->block_identifier))) {
    $url = $view
      ->get_url($args);
    $key = date_block_identifier($view);
    if (!empty($key)) {
      return url($_GET['q'], array(
        'query' => date_querystring($view, array(
          $key => $url,
        )),
        'absolute' => TRUE,
      ));
    }
  }

  // Normal views may need querystrings appended to them
  // if they use exposed filters.
  return url($view
    ->get_url($args), array(
    'query' => date_querystring($view),
    'absolute' => TRUE,
  ));
}