| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: admin_menu.module,v 1.43.2.18 2009/06/21 18:58:04 sun Exp $ 3 4 /** 5 * @file 6 * Renders a menu tree for administrative purposes as a dropdown menu at the top 7 * of the window. 8 */ 9 10 /** 11 * Implementation of hook_help(). 12 */ 13 function admin_menu_help($path, $arg) { 14 switch ($path) { 15 case 'admin/settings/admin_menu': 16 return 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.'); 17 18 case 'admin/help#admin_menu': 19 $output = ''; 20 $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>'; 21 $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/settings/admin_menu'))) . '</p>'; 22 $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>'; 23 return $output; 24 } 25 } 26 27 /** 28 * Implementation of hook_perm(). 29 */ 30 function admin_menu_perm() { 31 return array('access administration menu', 'display drupal links'); 32 } 33 34 /** 35 * Implementation of hook_theme(). 36 */ 37 function admin_menu_theme() { 38 return array( 39 'admin_menu_icon' => array( 40 'arguments' => array(), 41 ), 42 ); 43 } 44 45 /** 46 * Implementation of hook_menu(). 47 */ 48 function admin_menu_menu() { 49 $items = array(); 50 $items['admin/settings/admin_menu'] = array( 51 'title' => 'Administration menu', 52 'description' => 'Adjust administration menu settings.', 53 'page callback' => 'drupal_get_form', 54 'page arguments' => array('admin_menu_theme_settings'), 55 'access arguments' => array('administer site configuration'), 56 'file' => 'admin_menu.inc', 57 ); 58 $items['admin_menu/toggle-modules'] = array( 59 'page callback' => 'admin_menu_toggle_modules', 60 'access arguments' => array('administer site configuration'), 61 'type' => MENU_CALLBACK, 62 'file' => 'admin_menu.inc', 63 ); 64 $items['admin_menu/flush-cache'] = array( 65 'page callback' => 'admin_menu_flush_cache', 66 'access arguments' => array('administer site configuration'), 67 'type' => MENU_CALLBACK, 68 'file' => 'admin_menu.inc', 69 ); 70 return $items; 71 } 72 73 /** 74 * Implementation of hook_init(). 75 * 76 * We can't move this into admin_menu_footer(), because PHP-only based themes 77 * like chameleon load and output scripts and stylesheets in front of 78 * theme_closure(), so we ensure Admin menu's styles and scripts are loaded on 79 * all pages via hook_init(). 80 */ 81 function admin_menu_init() { 82 if (user_access('access administration menu')) { 83 $path = drupal_get_path('module', 'admin_menu'); 84 drupal_add_css($path .'/admin_menu.css', 'module', 'all', FALSE); 85 // Performance: Defer execution. 86 drupal_add_js($path .'/admin_menu.js', 'module', 'header', TRUE); 87 88 if ($setting = variable_get('admin_menu_margin_top', 1)) { 89 drupal_add_js(array('admin_menu' => array('margin_top' => $setting)), 'setting'); 90 } 91 if ($setting = variable_get('admin_menu_position_fixed', 0)) { 92 drupal_add_js(array('admin_menu' => array('position_fixed' => $setting)), 'setting'); 93 } 94 if ($setting = variable_get('admin_menu_tweak_tabs', 0)) { 95 drupal_add_js(array('admin_menu' => array('tweak_tabs' => $setting)), 'setting'); 96 } 97 if ($_GET['q'] == 'admin/build/modules' || strpos($_GET['q'], 'admin/build/modules/list') === 0) { 98 drupal_add_js(array('admin_menu' => array('tweak_modules' => variable_get('admin_menu_tweak_modules', 0))), 'setting'); 99 } 100 } 101 } 102 103 /** 104 * Suppress display of administration menu. 105 * 106 * This function should be called from within another module's page callback 107 * (preferably using module_invoke()) when the menu should not be displayed. 108 * This is useful for modules that implement popup pages or other special 109 * pages where the menu would be distracting or break the layout. 110 * 111 * @param $set 112 * Defaults to TRUE. If called before hook_footer, the menu will not be 113 * displayed. Calling with FALSE returns the suppression state. 114 */ 115 function admin_menu_suppress($set = TRUE) { 116 static $suppress = FALSE; 117 if (!empty($set)) { 118 $suppress = TRUE; 119 } 120 return $suppress; 121 } 122 123 /** 124 * Implementation of hook_footer(). 125 * 126 * Admin menu was previously output via hook_block(), but suffered from 127 * theme-specific stylesheets that may be applied to layout blocks. We now 128 * output Admin menu in the footer to circumvent this. 129 * 130 * @todo Since admin_menu is rebuilt in the same request, we should be able 131 * to use a helper function instead of a variable to remind us to rebuild 132 * (variable_set() is slow). 133 */ 134 function admin_menu_footer($main = 0) { 135 if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) { 136 return; 137 } 138 139 // Check for the flag indicating that we need to rebuild. 140 if (variable_get('admin_menu_rebuild_links', FALSE)) { 141 module_load_include('inc', 'admin_menu'); 142 _admin_menu_rebuild_links(); 143 variable_del('admin_menu_rebuild_links'); 144 } 145 146 $content = '<div id="admin-menu">'; 147 $content .= admin_menu_tree_output(menu_tree_all_data('admin_menu')); 148 $content .= '</div>'; 149 return $content; 150 } 151 152 /** 153 * Returns a rendered menu tree. 154 * 155 * @param $tree 156 * A data structure representing the tree as returned from menu_tree_data. 157 * 158 * @return string 159 * The complete, rendered administration menu. 160 */ 161 function admin_menu_tree_output($tree) { 162 $output = ''; 163 164 foreach ($tree as $data) { 165 $extra_class = isset($data['link']['localized_options']['extra class']) ? $data['link']['localized_options']['extra class'] : NULL; 166 $link = admin_menu_item_link($data['link']); 167 168 if ($data['below']) { 169 $output .= theme_admin_menu_item($link, $data['link']['has_children'], admin_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class); 170 } 171 else { 172 $output .= theme_admin_menu_item($link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class); 173 } 174 } 175 return $output ? "\n<ul>". $output .'</ul>' : ''; 176 } 177 178 /** 179 * High-performance implementation of theme_menu_item_link(). 180 * 181 * This saves us a theme() call and does only the absolute minimum to get 182 * the admin menu links rendered. 183 */ 184 function admin_menu_item_link($link) { 185 // Omit alias lookups. 186 $link['localized_options']['alias'] = TRUE; 187 return '<a href="'. check_url(url($link['href'], $link['localized_options'])) .'">'. (!empty($link['localized_options']['html']) ? $link['title'] : check_plain($link['title'])) .'</a>'; 188 } 189 190 /** 191 * Generate the HTML output for a single menu item and submenu. 192 * 193 * @param string $link 194 * A rendered menu item link. 195 * @param bool $has_children 196 * Whether this item has children. 197 * @param string $menu 198 * A string containing any rendered children of this item. 199 * @param bool $in_active_trail 200 * Whether this item is in the active menu trail. 201 * @param string $extra_class 202 * An additional CSS class to set for this item. 203 * 204 * @see theme_menu_item() 205 * @ingroup themeable 206 */ 207 function theme_admin_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) { 208 $class = ($menu || $has_children ? 'expandable' : ''); 209 if (!empty($extra_class)) { 210 $class .= ' '. $extra_class; 211 } 212 if ($in_active_trail) { 213 $class .= ' active-trail'; 214 } 215 return '<li'. (!empty($class) ? ' class="'. $class .'"' : '') .'>'. $link . $menu .'</li>'; 216 } 217 218 /** 219 * Implementation of hook_form_[form_id]_alter(). 220 * 221 * Extends Devel module with Administration Menu developer settings. 222 */ 223 function admin_menu_form_devel_admin_settings_alter(&$form, $form_state) { 224 module_load_include('inc', 'admin_menu'); 225 _admin_menu_devel_settings_form_alter($form, $form_state); 226 } 227 228 /** 229 * Implementation of hook_enable(). 230 */ 231 function admin_menu_enable() { 232 variable_set('admin_menu_rebuild_links', TRUE); 233 } 234 235 /** 236 * Implementation of hook_menu_alter(). 237 */ 238 function admin_menu_menu_alter() { 239 variable_set('admin_menu_rebuild_links', TRUE); 240 } 241 242 /** 243 * Implementation of hook_translated_menu_link_alter(). 244 * 245 * Here is where we make changes to links that need dynamic information such 246 * as the current page path or the number of users. 247 */ 248 function admin_menu_translated_menu_link_alter(&$item, $map) { 249 global $user, $base_url; 250 static $access_all; 251 252 if (!isset($access_all)) { 253 // We only ever do this for development 254 $access_all = variable_get('admin_menu_show_all', 0) && module_exists('devel'); 255 } 256 if ($item['menu_name'] != 'admin_menu') { 257 return; 258 } 259 if ($access_all && !$item['access']) { 260 $item['access'] = TRUE; 261 // Prepare for http://drupal.org/node/266596 262 if (!isset($item['localized_options'])) { 263 _menu_item_localize($item, $map, TRUE); 264 } 265 } 266 // We defined 'Run updates' as external link; apply proper base path now. 267 if ($item['link_path'] == 'update.php') { 268 $item['title'] = $item['link_title']; 269 $item['access'] = ($user->uid == 1 || !empty($GLOBALS['update_free_access'])); 270 $item['href'] = base_path() . $item['href']; 271 _menu_item_localize($item, $map, TRUE); 272 return; 273 } 274 // Don't waste cycles altering items that are not visible 275 if (!$item['access']) { 276 return; 277 } 278 if ($item['link_path'] == 'http://drupal.org' && !user_access('display drupal links')) { 279 $item['access'] = FALSE; 280 return; 281 } 282 // Fix destination query strings 283 if (isset($item['localized_options']['query'])) { 284 if ($item['localized_options']['query'] == 'destination') { 285 $item['localized_options']['query'] = drupal_get_destination(); 286 } 287 } 288 if ($extra = variable_get('admin_menu_display', 0)) { 289 $item['title'] .= ' '. $extra[0] .': '. $item[$extra]; 290 } 291 // Handle items that need dynamic localization/replacement. 292 if (isset($item['options']['t'])) { 293 $item['title'] = t($item['title'], $item['options']['t'] + array('@username' => $user->name)); 294 } 295 if ($item['title'] == 'icon_users') { 296 // Add count of active anonymous/authenticated users. 297 // @see user_block(), user.module 298 $interval = time() - variable_get('user_block_seconds_online', 900); 299 $count_anon = sess_count($interval); 300 $count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval)); 301 $icon_users = '<img src="'. base_path() . drupal_get_path('module', 'admin_menu') .'/images/icon_users.png" width="16" height="15" alt="@title" title="@title" />'; 302 303 $title = array('@title' => t('Current anonymous / authenticated users')); 304 $icon_users = strtr($icon_users, $title); 305 $item['title'] = t('@count-anon / @count-auth !icon', array('@count-anon' => $count_anon, '@count-auth' => $count_auth, '!icon' => $icon_users)); 306 if (user_access('administer users')) { 307 $item['href'] = 'admin/user/user'; 308 } 309 } 310 } 311 312 /** 313 * Render an icon to display in the Administration Menu. 314 * 315 * @ingroup themeable 316 */ 317 function theme_admin_menu_icon() { 318 return '<img class="admin-menu-icon" src="'. (theme_get_setting('toggle_favicon') ? theme_get_setting('favicon') : base_path() .'misc/favicon.ico') .'" width="16" height="16" alt="'. t('Home') .'" />'; 319 } 320
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |