You are here

function boost_boost_menu_router in Boost 6

Same name and namespace in other branches
  1. 7 boost.module \boost_boost_menu_router()

Implementation of hook_boost_menu_router().

TODO Better support for arguments.

Parameters

$router_item: info about this request

Return value

array return the $router_item array with 'page_callback', 'page_type', 'page_id' set return NULL if you didn't get a match

File

./boost.module, line 5070
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function boost_boost_menu_router($router_item) {

  // Handle nodes
  if ($router_item['args'][0] == 'node' && is_numeric($router_item['args'][1])) {
    $node = boost_node_get_basics($router_item['args'][1]);
    $router_item['page_callback'] = 'node';
    $router_item['page_id'] = $router_item['args'][1];
    if ($node) {
      $router_item['page_type'] = $node->type;
    }
    return $router_item;
  }

  // Handle taxonomy
  if ($router_item['args'][0] == 'taxonomy' && is_numeric($router_item['args'][2])) {
    $term = taxonomy_get_term($router_item['args'][2]);
    $router_item['page_callback'] = 'taxonomy';
    $router_item['page_id'] = $router_item['args'][2];
    if ($term) {
      $vocab = taxonomy_vocabulary_load($term->vid);
      $router_item['page_type'] = $vocab->name;
    }
    return $router_item;
  }

  // Handle users
  if ($router_item['args'][0] == 'user' && is_numeric($router_item['args'][1])) {
    $user = user_load($router_item['args'][1]);
    $router_item['page_callback'] = 'user';
    $router_item['page_id'] = $router_item['args'][1];
    if ($user !== FALSE) {
      $router_item['page_type'] = implode(', ', $user->roles);
    }
    return $router_item;
  }

  // Handle views
  if ($router_item['page_callback'] == 'views_page') {
    $router_item['page_callback'] = 'view';
    $router_item['page_type'] = array_shift($router_item['page_arguments']);
    $router_item['page_id'] = array_shift($router_item['page_arguments']);

    // See http://drupal.org/node/651798 for the reason why this if is needed
    if (is_array($router_item['page_id'])) {
      $router_item['page_id'] = array_shift($router_item['page_id']);
    }
    return $router_item;
  }

  // Handle panels
  if ($router_item['page_callback'] == 'page_manager_page_execute') {
    $subtask_id = array_shift($router_item['page_arguments']);
    $page = page_manager_page_load($subtask_id);
    $task = page_manager_get_task($page->task);
    if ($function = ctools_plugin_get_function($task, 'page callback')) {
      $router_item['page_callback'] = $function;
    }
    $router_item['page_type'] = $page->task;
    $router_item['page_id'] = $page->name;
    return $router_item;
  }
  elseif (is_array($router_item['page_arguments'])) {
    foreach ($router_item['page_arguments'] as $string) {
      if (is_string($string) && empty($router_item['page_type'])) {
        $router_item['page_type'] = $string;
      }
      elseif (is_string($string)) {
        $router_item['page_id'] .= $string;
      }
    }
  }

  // If router doesn't hold the the arguments, get them from the URL.
  if (empty($router_item['page_type'])) {
    $router_item['page_type'] = $router_item['extra_arguments'];
  }
  elseif (empty($router_item['page_id'])) {
    $router_item['page_id'] = $router_item['extra_arguments'];
  }

  // Try populating with the query string
  if (empty($router_item['page_type'])) {
    $router_item['page_type'] = $router_item['query'];
  }
  elseif (empty($router_item['page_id'])) {
    $router_item['page_id'] = $router_item['query'];
  }
  return $router_item;
}