View source
<?php
function _admin_menu_rebuild_links() {
$menu = NULL;
if (function_exists('_menu_router_cache')) {
$menu = _menu_router_cache();
}
else {
$menu = menu_router_build();
}
if (!$menu) {
return;
}
$menu_links = array();
foreach ($menu as $path => $item) {
if ($item['type'] != MENU_CALLBACK && ($item['_parts'][0] == 'admin' && count($item['_parts']) > 1 || strpos($path, 'node/add') === 0)) {
if (!strpos($path, '%')) {
$item = admin_menu_link_build($item);
$menu_links[$path] = $item;
$sort[$path] = $item['_number_parts'];
}
}
}
$deleted = admin_menu_adjust_items($menu_links, $sort);
if ($menu_links) {
array_multisort($sort, SORT_NUMERIC, $menu_links);
foreach ($menu_links as $item) {
admin_menu_link_save($item);
}
}
$links = array();
foreach (module_implements('admin_menu') as $module) {
$function = $module . '_admin_menu';
$links = array_merge_recursive($links, $function($deleted));
}
foreach ($links as $item) {
admin_menu_link_save($item);
}
}
function admin_menu_link_build($item) {
$item['module'] = 'admin_menu';
$item['menu_name'] = 'admin_menu';
$item += array(
'link_title' => isset($item['title']) ? $item['title'] : '',
'link_path' => isset($item['path']) ? $item['path'] : '',
'hidden' => 0,
'options' => array(),
);
$item['options']['alter'] = TRUE;
if (!empty($item['query'])) {
$item['options']['query'] = $item['query'];
}
return $item;
}
function admin_menu_link_save($item) {
$item = admin_menu_link_build($item);
$existing_item = db_fetch_array(db_query("SELECT mlid, plid, has_children FROM {menu_links} WHERE link_path = '%s' AND menu_name = '%s'", $item['link_path'], 'admin_menu'));
if ($existing_item) {
$item['mlid'] = $existing_item['mlid'];
$item['plid'] = $existing_item['plid'];
$item['has_children'] = $existing_item['has_children'];
}
if (isset($item['parent_path'])) {
if ($item['parent_path'] == '<root>') {
$item['plid'] = 0;
}
else {
$plid = db_result(db_query("SELECT mlid from {menu_links} WHERE link_path = '%s' AND menu_name = '%s'", $item['parent_path'], 'admin_menu'));
if ($plid) {
$item['plid'] = $plid;
}
}
}
menu_link_save($item);
}
function admin_menu_admin_menu(&$deleted) {
$links = array();
$icon_path = '<front>';
$links[] = array(
'title' => 'Run cron',
'path' => 'admin/reports/status/run-cron',
'weight' => 50,
'parent_path' => $icon_path,
);
$links[] = array(
'title' => 'Run updates',
'path' => 'update.php',
'weight' => 50,
'parent_path' => $icon_path,
'options' => array(
'external' => TRUE,
),
);
if (isset($deleted['admin/by-module'])) {
$deleted['admin/by-module']['parent_path'] = 'admin/settings';
$deleted['admin/by-module']['weight'] = -10;
$links[] = $deleted['admin/by-module'];
unset($deleted['admin/by-module']);
}
$links[] = array(
'title' => 'Drupal.org',
'path' => 'http://drupal.org',
'weight' => 100,
'parent_path' => $icon_path,
);
$links[] = array(
'title' => 'Drupal issue queue',
'path' => 'http://drupal.org/project/issues/drupal',
'weight' => -10,
'parent_path' => 'http://drupal.org',
);
$projects = array();
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
$info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
if (!isset($info['project']) || isset($info['project']) && ($info['project'] == 'drupal' || isset($projects[$info['project']]))) {
continue;
}
$projects[$info['project']] = 1;
$url = 'http://drupal.org/project/issues/' . $info['project'];
$links[] = array(
'title' => check_plain($info['name']) . ' issue queue',
'path' => $url,
'parent_path' => 'http://drupal.org',
);
}
if (isset($deleted['node/add'])) {
$deleted['node/add']['parent_path'] = 'admin/content';
$deleted['node/add']['weight'] = 0;
$links[] = $deleted['node/add'];
unset($deleted['node/add']);
}
foreach ($deleted as $path => $item) {
if (strpos($path, 'node/add') !== FALSE) {
$links[] = $deleted[$path];
unset($deleted[$path]);
}
}
ksort($deleted);
foreach (node_get_types('types', NULL, TRUE) as $type) {
$type_url_str = str_replace('_', '-', $type->type);
$type_path = 'admin/content/node-type/' . $type_url_str;
$links[$type_path] = array(
'title' => 'Edit !content-type',
'path' => $type_path,
'parent_path' => 'admin/content/types',
'options' => array(
't' => array(
'!content-type' => $type->name,
),
),
);
unset($deleted[$type_path . '/edit']);
foreach ($deleted as $path => $item) {
if ($path === $type_path || strpos($path, $type_path . '/') === 0) {
$i = $item['_number_parts'] - 1;
do {
$parent_path = implode('/', array_slice($item['_parts'], 0, $i));
--$i;
} while (!isset($links[$parent_path]) && $i);
$item['parent_path'] = $parent_path;
$links[$path] = $item;
unset($deleted[$path]);
}
}
}
$links[] = array(
'title' => 'Flush all caches',
'path' => 'admin_menu/flush-cache',
'query' => 'destination',
'weight' => 20,
'parent_path' => $icon_path,
);
$caches = array(
'admin_menu' => 'Administration menu',
'cache' => 'Cache tables',
'menu' => 'Menu',
'requisites' => 'Page requisites',
'theme' => 'Theme registry',
);
foreach ($caches as $name => $title) {
$links[] = array(
'title' => $title,
'path' => 'admin_menu/flush-cache/' . $name,
'query' => 'destination',
'parent_path' => 'admin_menu/flush-cache',
);
}
if (module_exists('devel')) {
$links[] = array(
'title' => 'Variable editor',
'path' => 'devel/variable',
'weight' => 20,
'parent_path' => $icon_path,
);
if ($devel_user_links = module_invoke('devel', 'switch_user_list')) {
foreach ($devel_user_links as $link) {
if (is_array($link)) {
$links[] = array(
'title' => $link['title'],
'description' => $link['attributes']['title'],
'path' => $link['href'],
'options' => array(
'query' => $link['query'],
'html' => !empty($link['html']),
),
'parent_path' => 'logout',
);
}
elseif (preg_match('!href="' . base_path() . '([^\\?]+)\\?([^"]+)" title="([^"]+)">((<em>)?[^<]+(</em>)?)!', $link, $match)) {
$links[] = array(
'title' => $match[4],
'description' => $match[3],
'path' => urldecode($match[1]),
'weight' => 20,
'query' => 'destination',
'parent_path' => 'logout',
'options' => array(
'html' => TRUE,
),
);
}
}
}
}
$saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
$links[] = array(
'title' => isset($saved_state) ? t('Enable developer modules') : t('Disable developer modules'),
'path' => 'admin_menu/toggle-modules',
'weight' => 88,
'parent_path' => $icon_path,
'options' => array(
'query' => 'destination',
),
);
return $links;
}
function admin_menu_adjust_items(&$menu_links, &$sort) {
global $user;
$links = array();
$deleted = array();
$deleted['admin/by-module'] = $menu_links['admin/by-module'];
unset($menu_links['admin/by-module'], $sort['admin/by-module']);
$deleted['admin/by-task'] = $menu_links['admin/by-task'];
unset($menu_links['admin/by-task'], $sort['admin/by-task']);
foreach ($menu_links as $path => $link) {
if (strpos($path, 'admin/content/node-type/') !== FALSE || strpos($path, 'node/add') !== FALSE) {
$deleted[$path] = $link;
unset($menu_links[$path], $sort[$path]);
}
}
$links[] = array(
'title' => theme('admin_menu_icon'),
'path' => '<front>',
'weight' => -100,
'parent_path' => '<root>',
'options' => array(
'extra class' => 'admin-menu-icon',
'html' => TRUE,
),
);
$links[] = array(
'title' => 'icon_users',
'path' => 'user',
'weight' => -90,
'parent_path' => '<root>',
'options' => array(
'extra class' => 'admin-menu-action admin-menu-icon admin-menu-users',
'html' => TRUE,
),
);
$links[] = array(
'title' => 'Log out @username',
'path' => 'logout',
'weight' => -100,
'parent_path' => '<root>',
'options' => array(
'extra class' => 'admin-menu-action admin-menu-logout',
't' => array(),
),
);
foreach ($links as $item) {
$path = $item['path'];
$item = admin_menu_link_build($item);
$menu_links[$path] = $item;
$sort[$path] = 1;
}
return $deleted;
}
function admin_menu_theme_settings() {
$form['admin_menu_margin_top'] = array(
'#type' => 'checkbox',
'#title' => t('Adjust top margin'),
'#default_value' => variable_get('admin_menu_margin_top', 1),
'#description' => t('If enabled, the site output is shifted down approximately 20 pixels from the top of the viewport to display the administration menu. If disabled, some absolute- or fixed-positioned page elements may be covered by the administration menu.'),
);
$form['admin_menu_position_fixed'] = array(
'#type' => 'checkbox',
'#title' => t('Keep menu at top of page'),
'#default_value' => variable_get('admin_menu_position_fixed', 0),
'#description' => t('If enabled, the administration menu is always displayed at the top of the browser viewport (even after the page is scrolled). <strong>Note: In some browsers, this setting results in a malformed page, an invisible cursor, non-selectable elements in forms, or other issues. Disable this option if these issues occur.</strong>'),
);
$form['tweaks'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
);
$form['tweaks']['admin_menu_tweak_modules'] = array(
'#type' => 'checkbox',
'#title' => t('Collapse fieldsets on modules page'),
'#default_value' => variable_get('admin_menu_tweak_modules', 0),
'#description' => t('If enabled, fieldsets on the <a href="!modules-url">modules</a> page are automatically collapsed when loading the page.', array(
'!modules-url' => url('admin/build/modules'),
)),
);
if (module_exists('util')) {
$form['tweaks']['admin_menu_tweak_modules']['#description'] .= '<br /><strong>' . t('If the Utility module was installed for this purpose, it can be safely disabled and uninstalled.') . '</strong>';
}
$form['tweaks']['admin_menu_tweak_tabs'] = array(
'#type' => 'checkbox',
'#title' => t('Move local tasks into menu'),
'#default_value' => variable_get('admin_menu_tweak_tabs', 0),
'#description' => t('If enabled, the tabs on the current page are moved into the administration menu. This feature is only available in themes that use the CSS classes <code>tabs primary</code> and <code>tabs secondary</code> for tabs.'),
);
$form = system_settings_form($form);
$form['wipe description'] = array(
'#type' => 'item',
'#value' => t('If the administration menu displays duplicate menu items, you may need to rebuild your menu items using the <em>Wipe and rebuild</em> button.'),
);
$form['wipe'] = array(
'#type' => 'submit',
'#value' => t('Wipe and rebuild'),
'#submit' => array(
'admin_menu_wipe',
),
);
return $form;
}
function admin_menu_wipe() {
db_query("DELETE FROM {menu_links} WHERE menu_name = 'admin_menu'");
menu_cache_clear('admin_menu');
menu_rebuild();
}
function _admin_menu_devel_settings_form_alter(&$form, $form_state) {
$weight = isset($form['buttons']['#weight']) ? $form['buttons']['#weight'] : 0;
$form['buttons']['#weight'] = $weight + 1;
$form['admin_menu'] = array(
'#type' => 'fieldset',
'#title' => t('Administration menu settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$display_options = array(
'mid',
'weight',
'pid',
);
$display_options = array(
0 => t('None'),
'mlid' => t('Menu link ID'),
'weight' => t('Weight'),
'plid' => t('Parent link ID'),
);
$form['admin_menu']['admin_menu_display'] = array(
'#type' => 'radios',
'#title' => t('Display additional data for each menu item'),
'#default_value' => variable_get('admin_menu_display', 0),
'#options' => $display_options,
'#description' => t('Display the selected items next to each menu item link.'),
);
$form['admin_menu']['admin_menu_show_all'] = array(
'#type' => 'checkbox',
'#title' => t('Display all menu items'),
'#default_value' => variable_get('admin_menu_show_all', 0),
'#description' => t('If enabled, all menu items are displayed regardless of your site permissions. <em>Note: Do not enable on a production site.</em>'),
);
}
function admin_menu_toggle_modules() {
if (!isset($_GET['token']) || $_GET['token'] !== drupal_get_token($_GET['q'])) {
return MENU_ACCESS_DENIED;
}
$rebuild = FALSE;
$saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
if (isset($saved_state)) {
module_enable($saved_state);
variable_del('admin_menu_devel_modules_enabled');
drupal_set_message(t('Enabled these modules: !module-list.', array(
'!module-list' => implode(', ', $saved_state),
)));
$rebuild = TRUE;
}
else {
$devel_modules = variable_get('admin_menu_devel_modules', array(
'cache_disable',
'coder',
'content_copy',
'debug',
'delete_all',
'demo',
'devel',
'devel_node_access',
'devel_themer',
'macro',
'form_controller',
'imagecache_ui',
'journal',
'trace',
'upgrade_status',
'user_display_ui',
'util',
'views_ui',
'views_theme_wizard',
));
$devel_modules = array_intersect(module_list(FALSE, FALSE), $devel_modules);
if (!empty($devel_modules)) {
variable_set('admin_menu_devel_modules_enabled', $devel_modules);
module_disable($devel_modules);
drupal_set_message(t('Disabled these modules: !module-list.', array(
'!module-list' => implode(', ', $devel_modules),
)));
$rebuild = TRUE;
}
else {
drupal_set_message(t('No developer modules are enabled.'));
}
}
if ($rebuild) {
drupal_rebuild_theme_registry();
menu_rebuild();
cache_clear_all('schema', 'cache');
cache_clear_all();
drupal_clear_css_cache();
drupal_clear_js_cache();
actions_synchronize();
}
drupal_goto('');
}
function admin_menu_flush_cache($name = NULL) {
if (!isset($_GET['token']) || $_GET['token'] !== drupal_get_token($_GET['q'])) {
return MENU_ACCESS_DENIED;
}
switch ($name) {
case 'admin_menu':
admin_menu_wipe();
break;
case 'cache':
$core = array(
'cache',
'cache_block',
'cache_filter',
'cache_page',
);
$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);
}
break;
case 'menu':
menu_rebuild();
break;
case 'requisites':
_drupal_flush_css_js();
drupal_clear_css_cache();
drupal_clear_js_cache();
break;
case 'theme':
module_invoke('system', 'theme_data');
drupal_rebuild_theme_registry();
break;
default:
module_load_include('inc', 'system', 'system.admin');
$form = $form_state = array();
system_clear_cache_submit($form, $form_state);
break;
}
drupal_goto();
}