function boost_boost_menu_router in Boost 7
Same name and namespace in other branches
- 6 boost.module \boost_boost_menu_router()
Implements hook_boost_menu_router().
TODO Better support for arguments.
Parameters
$parts: info about this request
Return value
$parts
File
- ./
boost.module, line 904 - Caches generated output as a static file to be served directly from the webserver.
Code
function boost_boost_menu_router($parts) {
// Handle nodes.
if ($parts['args'][0] === 'node' && is_numeric($parts['args'][1])) {
$node = node_load($parts['args'][1]);
$parts['menu_item']['page_callback'] = 'node';
$parts['menu_item']['page_id'] = $parts['args'][1];
if ($node) {
$parts['menu_item']['page_type'] = $node->type;
}
return $parts;
}
// Handle taxonomy.
if ($parts['args'][0] === 'taxonomy' && is_numeric($parts['args'][2])) {
$term = taxonomy_term_load($parts['args'][2]);
$parts['menu_item']['page_callback'] = 'taxonomy';
$parts['menu_item']['page_id'] = $parts['args'][2];
if ($term) {
$vocab = taxonomy_vocabulary_load($term->vid);
$parts['menu_item']['page_type'] = $vocab->name;
}
return $parts;
}
// Handle users.
if ($parts['args'][0] === 'user' && is_numeric($parts['args'][1])) {
$user = user_load($parts['args'][1]);
$parts['menu_item']['page_callback'] = 'user';
$parts['menu_item']['page_id'] = $parts['args'][1];
if ($user !== FALSE) {
$parts['menu_item']['page_type'] = implode(', ', $user->roles);
}
return $parts;
}
// Handle views.
if (isset($parts['menu_item']['page_callback']) && $parts['menu_item']['page_callback'] === 'views_page') {
$page_arguments = $parts['menu_item']['page_arguments'];
// Issue #1364090 : views with access control have serialized page arguments
if (!is_array($page_arguments)) {
$page_arguments = unserialize($page_arguments);
}
$parts['menu_item']['page_callback'] = 'view';
$parts['menu_item']['page_type'] = array_shift($page_arguments);
$parts['menu_item']['page_id'] = array_shift($page_arguments);
// See http://drupal.org/node/651798 for the reason why this if is needed
if (is_array($parts['menu_item']['page_id'])) {
$parts['menu_item']['page_id'] = array_shift($parts['menu_item']['page_id']);
}
return $parts;
}
// Handle panels.
if (isset($parts['menu_item']['page_callback']) && $parts['menu_item']['page_callback'] === 'page_manager_page_execute') {
$page_arguments = $parts['menu_item']['page_arguments'];
// Issue #1653206 : panels with access control have serialized page arguments
if (!is_array($page_arguments)) {
$page_arguments = unserialize($page_arguments);
}
$subtask_id = array_shift($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')) {
$parts['menu_item']['page_callback'] = $function;
}
$parts['menu_item']['page_type'] = $page->task;
$parts['menu_item']['page_id'] = $page->name;
return $parts;
}
elseif (isset($parts['menu_item']['page_arguments']) && is_array($parts['menu_item']['page_arguments'])) {
foreach ($parts['menu_item']['page_arguments'] as $string) {
if (is_string($string) && empty($parts['menu_item']['page_type'])) {
$parts['menu_item']['page_type'] = $string;
}
elseif (is_string($string)) {
$parts['menu_item']['page_id'] .= $string;
}
}
}
// If router doesn't hold the the arguments, get them from the URL.
if (empty($parts['menu_item']['page_type'])) {
$parts['menu_item']['page_type'] = $parts['menu_item']['extra_arguments'];
}
elseif (empty($parts['menu_item']['page_id'])) {
$parts['menu_item']['page_id'] = $parts['menu_item']['extra_arguments'];
}
// Try populating with the query string.
if (empty($parts['menu_item']['page_type']) && !empty($parts['query_extra'])) {
$parts['menu_item']['page_type'] = $parts['query_extra'];
}
elseif (empty($parts['menu_item']['page_id']) && !empty($parts['query_extra'])) {
$parts['menu_item']['page_id'] = $parts['query_extra'];
}
return $parts;
}