123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852 |
- <?php
- function admin_menu_help($path, $arg) {
- switch ($path) {
- case 'admin/config/administration/admin_menu':
- return '<p>' . t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Use the settings below to customize the appearance of the menu.') . '</p>';
- case 'admin/help#admin_menu':
- $output = '';
- $output .= '<p>' . t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Administration menu also displays the number of anonymous and authenticated users, and allows modules to add their own custom menu items. Integration with the menu varies from module to module; the contributed module <a href="@drupal">Devel</a>, for instance, makes strong use of the administration menu module to provide quick access to development tools.', array('@drupal' => 'http://drupal.org/project/devel')) . '</p>';
- $output .= '<p>' . t('The administration menu <a href="@settings">settings page</a> allows you to modify some elements of the menu\'s behavior and appearance. Since the appearance of the menu is dependent on your site theme, substantial customizations require modifications to your site\'s theme and CSS files. See the advanced module README.txt file for more information on theme and CSS customizations.', array('@settings' => url('admin/config/administration/admin_menu'))) . '</p>';
- $output .= '<p>' . t('The menu items displayed in the administration menu depend upon the actual permissions of the viewer. First, the administration menu is only displayed to users in roles with the <em>Access administration menu</em> (admin_menu module) permission. Second, a user must be a member of a role with the <em>Access administration pages</em> (system module) permission to view administrative links. And, third, only currently permitted links are displayed; for example, if a user is not a member of a role with the permissions <em>Administer permissions</em> (user module) and <em>Administer users</em> (user module), the <em>User management</em> menu item is not displayed.') . '</p>';
- return $output;
- }
- }
- function admin_menu_permission() {
- return array(
- 'access administration menu' => array(
- 'title' => t('Access administration menu'),
- 'description' => t('Display the administration menu at the top of each page.'),
- ),
- 'flush caches' => array(
- 'title' => t('Flush caches'),
- 'description' => t('Access links to flush caches in the administration menu.'),
- ),
- 'display drupal links' => array(
- 'title' => t('Display Drupal links'),
- 'description' => t('Provide Drupal.org links in the administration menu.'),
- ),
- );
- }
- function admin_menu_theme() {
- return array(
- 'admin_menu_links' => array(
- 'render element' => 'elements',
- ),
- 'admin_menu_icon' => array(
- 'variables' => array('src' => NULL, 'alt' => NULL),
- 'file' => 'admin_menu.inc',
- ),
- );
- }
- function admin_menu_menu() {
-
-
- $items['js/admin_menu/cache'] = array(
- 'page callback' => 'admin_menu_js_cache',
- 'delivery callback' => 'admin_menu_deliver',
- 'access arguments' => array('access administration menu'),
- 'type' => MENU_CALLBACK,
- );
-
- $items['admin/config/administration'] = array(
- 'title' => 'Administration',
- 'description' => 'Administration tools.',
- 'page callback' => 'system_admin_menu_block_page',
- 'access arguments' => array('access administration pages'),
- 'file' => 'system.admin.inc',
- 'file path' => drupal_get_path('module', 'system'),
- );
- $items['admin/config/administration/admin_menu'] = array(
- 'title' => 'Administration menu',
- 'description' => 'Adjust administration menu settings.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('admin_menu_theme_settings'),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'admin_menu.inc',
- );
-
- $items['admin_menu/flush-cache'] = array(
- 'page callback' => 'admin_menu_flush_cache',
- 'access arguments' => array('flush caches'),
- 'type' => MENU_CALLBACK,
- 'file' => 'admin_menu.inc',
- );
- return $items;
- }
- function admin_menu_menu_alter(&$items) {
-
- admin_menu_flush_caches();
- }
- function admin_menu_menu_link_insert($link) {
-
- admin_menu_flush_caches();
- }
- function admin_menu_menu_link_update($link) {
-
- admin_menu_flush_caches();
- }
- function admin_menu_menu_link_delete($link) {
-
- admin_menu_flush_caches();
- }
- function admin_menu_system_info_alter(&$info, $file, $type) {
- if ($type == 'theme') {
- $info['overlay_supplemental_regions'][] = 'page_bottom';
- }
- }
- function admin_menu_page_build(&$page) {
- if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
- return;
- }
-
- if (strpos($_GET['q'], 'js/') === 0) {
- return;
- }
- global $user, $language;
- $path = drupal_get_path('module', 'admin_menu');
- $page['page_bottom']['admin_menu'] = array(
- '#attached' => array(),
- );
- $attached = &$page['page_bottom']['admin_menu']['#attached'];
- $options = array('every_page' => TRUE);
- $attached['css'][$path . '/admin_menu.css'] = $options;
- if ($user->uid == 1) {
- $attached['css'][$path . '/admin_menu.uid1.css'] = $options;
- }
-
-
-
-
- $attached['js'][$path . '/admin_menu.js'] = $options;
-
- $settings['destination'] = drupal_http_build_query(drupal_get_destination());
-
- $complete = FALSE;
- if (current_path() == 'admin/config/administration/admin_menu' && $_SERVER['REQUEST_METHOD'] == 'GET') {
- $complete = TRUE;
- }
-
-
- $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language->language;
- if (!$complete && !empty($_COOKIE['has_js']) && ($hash = admin_menu_cache_get($cid))) {
- $settings['hash'] = $hash;
-
-
-
-
-
-
-
- $settings['basePath'] = url('admin_menu');
- }
-
- else {
- $page['page_bottom']['admin_menu']['#markup'] = admin_menu_output($complete);
- }
- $replacements = module_invoke_all('admin_menu_replacements', $complete);
- if (!empty($replacements)) {
- $settings['replacements'] = $replacements;
- }
- if ($setting = variable_get('admin_menu_margin_top', 1)) {
- $settings['margin_top'] = $setting;
-
-
-
-
- }
- if ($setting = variable_get('admin_menu_position_fixed', 1)) {
- $settings['position_fixed'] = $setting;
-
-
-
- $attached['js'][] = array(
- 'data' => array('tableHeaderOffset' => 'Drupal.admin.height'),
- 'type' => 'setting',
- );
- }
- if ($setting = variable_get('admin_menu_tweak_tabs', 0)) {
- $settings['tweak_tabs'] = $setting;
- }
- if ($_GET['q'] == 'admin/modules' || strpos($_GET['q'], 'admin/modules/list') === 0) {
- $settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
- }
- if ($_GET['q'] == 'admin/people/permissions' || $_GET['q'] == 'admin/people/permissions/list') {
- $settings['tweak_permissions'] = variable_get('admin_menu_tweak_permissions', 0);
- }
- $attached['js'][] = array(
- 'data' => array('admin_menu' => $settings),
- 'type' => 'setting',
- );
- }
- function admin_menu_suppress($set = TRUE) {
- static $suppress = FALSE;
-
- if (!empty($set) && $suppress === FALSE) {
- $suppress = TRUE;
- drupal_add_js(array('admin_menu' => array('suppress' => 1)), 'setting');
- }
- return $suppress;
- }
- function admin_menu_js() {
- return array(
- 'cache' => array(
- 'callback' => 'admin_menu_js_cache',
- 'includes' => array('common', 'theme', 'unicode'),
- 'dependencies' => array('devel', 'filter', 'user'),
- ),
- );
- }
- function admin_menu_cache_get($cid) {
- $cache = &drupal_static(__FUNCTION__, array());
- if (!variable_get('admin_menu_cache_client', TRUE)) {
- return FALSE;
- }
- if (!array_key_exists($cid, $cache)) {
- $cache[$cid] = cache_get($cid, 'cache_admin_menu');
- if ($cache[$cid] && isset($cache[$cid]->data)) {
- $cache[$cid] = $cache[$cid]->data;
- }
- }
- return $cache[$cid];
- }
- function admin_menu_cache_set($cid, $data) {
- if (variable_get('admin_menu_cache_client', TRUE)) {
- cache_set($cid, $data, 'cache_admin_menu');
- }
- }
- function admin_menu_js_cache() {
- global $conf;
-
- $GLOBALS['devel_shutdown'] = FALSE;
-
- $conf['cache'] = 1;
- drupal_page_is_cacheable(TRUE);
-
-
- $cache = drupal_page_get_cache();
- if (is_object($cache)) {
- header('X-Drupal-Cache: HIT');
-
- $_GET['q'] = $cache->data['path'];
- date_default_timezone_set(drupal_get_user_timezone());
- drupal_serve_page_from_cache($cache);
-
- exit;
- }
-
- header('X-Drupal-Cache: MISS');
-
-
-
-
- $max_age = 3600 * 24 * 365;
- drupal_add_http_header('Expires', gmdate(DATE_RFC1123, REQUEST_TIME + $max_age));
- drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age);
-
- return admin_menu_output();
- }
- function admin_menu_deliver($page_callback_result) {
- drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
-
- global $language;
- drupal_add_http_header('Content-Language', $language->language);
-
-
-
- print $page_callback_result;
-
- drupal_page_footer();
- }
- function admin_menu_admin_menu_replacements($complete) {
- $items = array();
-
-
- if (!$complete) {
-
- $components = variable_get('admin_menu_components', array());
- if (!empty($components['admin_menu.users']) && ($user_count = admin_menu_get_user_count())) {
-
- $items['.admin-menu-users a'] = $user_count;
- }
- }
- return $items;
- }
- function admin_menu_get_user_count() {
- $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
- $count_anon = admin_menu_session_count($interval, TRUE);
- $count_auth = admin_menu_session_count($interval, FALSE);
- return t('@count-anon / @count-auth', array('@count-anon' => $count_anon, '@count-auth' => $count_auth));
- }
- function admin_menu_session_count($timestamp = 0, $anonymous = TRUE) {
- $query = db_select('sessions');
- $query->addExpression('COUNT(sid)', 'count');
- $query->condition('timestamp', $timestamp, '>=');
- $query->condition('uid', 0, $anonymous ? '=' : '>');
- return $query->execute()->fetchField();
- }
- function admin_menu_output($complete = FALSE) {
- global $user, $language;
- $cache_server_enabled = !$complete && variable_get('admin_menu_cache_server', TRUE);
- $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language->language;
-
-
-
-
-
-
-
-
- if ($cache_server_enabled) {
- $cache = cache_get($cid, 'cache_menu');
- if ($cache && isset($cache->data)) {
- $content = $cache->data;
- }
- }
-
- if (!isset($content)) {
-
- $components = variable_get('admin_menu_components', array());
- $components += array(
- 'admin_menu.menu' => TRUE,
- 'admin_menu.icon' => TRUE,
- 'admin_menu.account' => TRUE,
- );
- $content['#components'] = $components;
- $content['#complete'] = $complete;
-
-
-
- $classes = 'admin-menu-site' . drupal_strtolower(preg_replace('/[^a-zA-Z0-9-]/', '-', $GLOBALS['cookie_domain']));
-
-
-
- if (module_exists('overlay')) {
- $classes .= ' overlay-displace-top';
- }
-
- $content['#prefix'] = '<div id="admin-menu" class="' . $classes . '"><div id="admin-menu-wrapper">';
- $content['#suffix'] = '</div></div>';
-
- module_load_include('inc', 'admin_menu');
-
-
-
- if (!empty($components['admin_menu.menu']) || $complete) {
- $content['menu'] = admin_menu_links_menu(admin_menu_tree('management'));
- $content['menu']['#theme'] = 'admin_menu_links';
- $content['menu']['#wrapper_attributes']['id'] = 'admin-menu-menu';
-
- $content['menu']['#weight'] = 0;
- }
-
- if (!empty($components['admin_menu.icon']) || $complete) {
- $content['icon'] = admin_menu_links_icon();
- }
- if (!empty($components['admin_menu.account']) || $complete) {
- $content['account'] = admin_menu_links_account();
- }
- if (!empty($components['admin_menu.users']) || $complete) {
- $content['users'] = admin_menu_links_users();
- }
- if (!empty($components['admin_menu.search']) || $complete) {
- $content['search'] = admin_menu_links_search();
- }
-
-
- foreach (module_implements('admin_menu_output_build') as $module) {
- $function = $module . '_admin_menu_output_build';
- $function($content);
- }
-
-
-
- drupal_alter('admin_menu_output', $content);
- $content = drupal_render($content);
-
- if ($cache_server_enabled) {
- cache_set($cid, $content, 'cache_menu');
- }
- }
-
- if (!empty($_COOKIE['has_js']) && !$complete) {
- admin_menu_cache_set($cid, md5($content));
- }
- return $content;
- }
- function admin_menu_admin_menu_output_build(&$content) {
- if (!isset($content['menu'])) {
- return;
- }
-
-
- if (isset($content['menu']['admin/config'])) {
- foreach (element_children($content['menu']['admin/config']) as $key) {
- $content['menu']['admin/config'][$key]['#weight_original'] = $content['menu']['admin/config'][$key]['#weight'];
- unset($content['menu']['admin/config'][$key]['#weight']);
- }
- }
-
- $link = db_query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")->fetchAssoc();
- $conditions = array();
- for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
- if (!empty($link["p$i"])) {
- $conditions["p$i"] = $link["p$i"];
- }
- }
- $tree = menu_build_tree($link['menu_name'], array(
- 'conditions' => $conditions,
- 'min_depth' => $link['depth'],
- ));
- $links = admin_menu_links_menu($tree);
- if (!empty($links)) {
-
-
- if (isset($content['menu']['admin/content'])) {
- $content['menu']['admin/content'] += $links;
- }
-
- else {
- $key = key($links);
- $links[$key]['#weight'] = -100;
- $content['menu'] += $links;
- }
- }
- }
- function admin_menu_admin_menu_output_alter(&$content) {
- foreach ($content['menu'] as $key => $link) {
-
- if ($key == 'admin/tasks' || $key == 'admin/index') {
- $content['icon']['icon'][$key] = $link;
- unset($content['menu'][$key]);
- }
- }
- }
- function theme_admin_menu_links($variables) {
- $destination = &drupal_static('admin_menu_destination');
- $elements = $variables['elements'];
- if (!isset($destination)) {
- $destination = drupal_get_destination();
- $destination = $destination['destination'];
- }
-
-
-
-
-
- uasort($elements, 'admin_menu_element_sort');
- $elements['#sorted'] = TRUE;
- $output = '';
- foreach (element_children($elements) as $path) {
-
- if (isset($elements[$path]['#access']) && !$elements[$path]['#access']) {
- continue;
- }
- $elements[$path] += array(
- '#attributes' => array(),
- '#options' => array(),
- );
-
- if (isset($elements[$path]['#type']) || isset($elements[$path]['#theme']) || isset($elements[$path]['#pre_render'])) {
- $elements[$path]['#children'] = drupal_render($elements[$path]);
- }
- else {
- $elements[$path]['#children'] = theme('admin_menu_links', array('elements' => $elements[$path]));
- if (!empty($elements[$path]['#children'])) {
- $elements[$path]['#attributes']['class'][] = 'expandable';
- }
- if (isset($elements[$path]['#attributes']['class'])) {
- $elements[$path]['#attributes']['class'] = $elements[$path]['#attributes']['class'];
- }
- }
- $link = '';
-
- if (isset($elements[$path]['#href'])) {
-
-
- if (isset($elements[$path]['#options']['query']['destination']) && $elements[$path]['#options']['query']['destination'] == $destination) {
- unset($elements[$path]['#options']['query']['destination']);
- $elements[$path]['#options']['attributes']['class'][] = 'admin-menu-destination';
- }
- $link = l($elements[$path]['#title'], $elements[$path]['#href'], $elements[$path]['#options']);
- }
-
- elseif (!isset($elements[$path]['#type']) && isset($elements[$path]['#title'])) {
- if (!empty($elements[$path]['#options']['html'])) {
- $title = $elements[$path]['#title'];
- }
- else {
- $title = check_plain($elements[$path]['#title']);
- }
- $attributes = '';
- if (isset($elements[$path]['#options']['attributes'])) {
- $attributes = drupal_attributes($elements[$path]['#options']['attributes']);
- }
- $link = '<span' . $attributes . '>' . $title . '</span>';
- }
- $output .= '<li' . drupal_attributes($elements[$path]['#attributes']) . '>';
- $output .= $link . $elements[$path]['#children'];
- $output .= '</li>';
- }
-
-
- if ($output) {
- $elements['#wrapper_attributes']['class'][] = 'dropdown';
- $attributes = drupal_attributes($elements['#wrapper_attributes']);
- $output = "\n" . '<ul' . $attributes . '>' . $output . '</ul>';
- }
- return $output;
- }
- function admin_menu_element_sort($a, $b) {
-
- $a_weight = isset($a['#weight']) ? $a['#weight'] : 0;
- $b_weight = isset($b['#weight']) ? $b['#weight'] : 0;
- if ($a_weight == $b_weight) {
-
- $a_title = isset($a['#title']) ? $a['#title'] : '';
- $b_title = isset($b['#title']) ? $b['#title'] : '';
- return strnatcasecmp($a_title, $b_title);
- }
- return ($a_weight < $b_weight) ? -1 : 1;
- }
- function admin_menu_translated_menu_link_alter(&$item, $map) {
- global $user, $base_url;
- static $access_all;
- if ($item['menu_name'] != 'admin_menu') {
- return;
- }
-
- if (!isset($access_all)) {
- $access_all = variable_get('admin_menu_show_all', 0) && module_exists('devel');
- }
-
- if ($access_all && !$item['access']) {
- $item['access'] = TRUE;
-
- if (!isset($item['localized_options'])) {
- _menu_item_localize($item, $map, TRUE);
- }
- }
-
- if (!$item['access']) {
- return;
- }
-
- if ($extra = variable_get('admin_menu_display', 0)) {
- $item['title'] .= ' ' . $extra[0] . ': ' . $item[$extra];
- }
- }
- function admin_menu_flush_caches($uid = NULL) {
-
-
-
-
-
-
-
-
- $was_flushed = &drupal_static(__FUNCTION__, array());
-
-
- if (isset($was_flushed[$uid])) {
- return;
- }
- $was_flushed[$uid] = TRUE;
- $cid = 'admin_menu:';
- if (isset($uid)) {
- $cid .= $uid . ':';
- }
-
- cache_clear_all($cid, 'cache_menu', TRUE);
-
- drupal_static_reset('admin_menu_cache_get');
-
- if (db_table_exists('cache_admin_menu')) {
- cache_clear_all(isset($uid) ? $cid : '*', 'cache_admin_menu', TRUE);
- }
- }
- function admin_menu_form_alter(&$form, &$form_state, $form_id) {
- $global_flush_ids = array(
- 'admin_menu_theme_settings' => 1,
-
- 'system_clean_url_settings' => 1,
-
- 'user_admin_permissions' => 1,
-
- 'user_admin_role_delete_confirm' => 1,
-
- 'user_profile_form' => 1,
- );
- if (isset($global_flush_ids[$form_id])) {
- $form['#submit'][] = 'admin_menu_form_alter_flush_cache_submit';
-
- $form_state['admin_menu_uid'] = NULL;
- if ($form_id == 'user_profile_form') {
- $form_state['admin_menu_uid'] = $form_state['user']->uid;
- }
- }
-
-
-
- if ($form_id == 'user_admin_permissions') {
- $form['#attached']['js'][] = drupal_get_path('module', 'admin_menu') . '/admin_menu.admin.js';
- }
- }
- function admin_menu_form_alter_flush_cache_submit($form, &$form_state) {
- admin_menu_flush_caches($form_state['admin_menu_uid']);
- }
- function admin_menu_form_devel_admin_settings_alter(&$form, &$form_state) {
- form_load_include($form_state, 'inc', 'admin_menu');
- _admin_menu_form_devel_admin_settings_alter($form, $form_state);
- }
|