| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Implementation of hook_init().
|
| 5 |
*/
|
| 6 |
function admin_init() {
|
| 7 |
$path = drupal_get_path('module', 'admin');
|
| 8 |
drupal_add_js($path .'/toolbar/admin_toolbar.js');
|
| 9 |
drupal_add_css($path .'/toolbar/admin_toolbar.css');
|
| 10 |
|
| 11 |
// Initialize the "null" theme -- in effect, bypass the theme system
|
| 12 |
// entirely so we can load our own theme into place.
|
| 13 |
$item = menu_get_item();
|
| 14 |
if (variable_get('node_admin_theme', 0) && in_array($item['page_callback'], array('node_add', 'node_add_page', 'node_page_edit'))) {
|
| 15 |
module_load_include('inc', 'admin', 'admin.theme');
|
| 16 |
_admin_init_theme();
|
| 17 |
}
|
| 18 |
else if (arg(0) == 'admin' && (arg(1) .'/'. arg(2) != 'build/block') && variable_get('admin_theme', 'admin') == 'admin') {
|
| 19 |
module_load_include('inc', 'admin', 'admin.theme');
|
| 20 |
_admin_init_theme();
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_menu_alter().
|
| 26 |
*/
|
| 27 |
function admin_menu_alter(&$items) {
|
| 28 |
// Move admin theme settings to theme local task.
|
| 29 |
$items['admin/build/themes/admin'] = $items['admin/settings/admin'];
|
| 30 |
$items['admin/build/themes/admin']['type'] = MENU_LOCAL_TASK;
|
| 31 |
$items['admin/build/themes/admin']['weight'] = 10;
|
| 32 |
unset($items['admin/settings/admin']);
|
| 33 |
|
| 34 |
// Gather site settings under local tasks
|
| 35 |
$items['admin/settings/site'] =
|
| 36 |
$items['admin/settings/site/information'] =
|
| 37 |
$items['admin/settings/site-information'];
|
| 38 |
unset($items['admin/settings/site-information']);
|
| 39 |
|
| 40 |
$items['admin/settings/site']['title'] = 'Site settings';
|
| 41 |
$items['admin/settings/site/information']['title'] = 'Information';
|
| 42 |
$items['admin/settings/site/information']['type'] = MENU_DEFAULT_LOCAL_TASK;
|
| 43 |
|
| 44 |
$items['admin/settings/site/clean-urls'] = $items['admin/settings/clean-urls'];
|
| 45 |
$items['admin/settings/site/clean-urls']['type'] = MENU_LOCAL_TASK;
|
| 46 |
$items['admin/settings/site/clean-urls']['weight'] = 10;
|
| 47 |
unset($items['admin/settings/clean-urls']);
|
| 48 |
|
| 49 |
$items['admin/settings/site/error-reporting'] = $items['admin/settings/error-reporting'];
|
| 50 |
$items['admin/settings/site/error-reporting']['type'] = MENU_LOCAL_TASK;
|
| 51 |
$items['admin/settings/site/error-reporting']['weight'] = 10;
|
| 52 |
unset($items['admin/settings/error-reporting']);
|
| 53 |
|
| 54 |
$items['admin/settings/site/file-system'] = $items['admin/settings/file-system'];
|
| 55 |
$items['admin/settings/site/file-system']['type'] = MENU_LOCAL_TASK;
|
| 56 |
$items['admin/settings/site/file-system']['weight'] = 10;
|
| 57 |
unset($items['admin/settings/file-system']);
|
| 58 |
|
| 59 |
// Generate additional items for use in the menu
|
| 60 |
$items = array_merge($items, admin_menu_clone_items('node/add', 'admin/content/add', $items));
|
| 61 |
$items = array_merge($items, admin_menu_clone_items('admin/build/themes', 'admin/themes', $items));
|
| 62 |
$items = array_merge($items, admin_menu_clone_items('admin/build/modules', 'admin/modules', $items));
|
| 63 |
|
| 64 |
// Expose a small subset of the most usable core admin pages.
|
| 65 |
// Other pages can be exposed simply by adding ['options']['admin'] = TRUE
|
| 66 |
// to items in hook_menu().
|
| 67 |
$include = array(
|
| 68 |
'admin/content' => 'Content',
|
| 69 |
'admin/content/add' => 'Add',
|
| 70 |
'admin/content/node' => 'Edit',
|
| 71 |
|
| 72 |
'admin/build' => 'Structure',
|
| 73 |
'admin/build/views' => '',
|
| 74 |
'admin/build/block' => '',
|
| 75 |
'admin/build/menu' => '',
|
| 76 |
|
| 77 |
'admin/user' => 'People',
|
| 78 |
'admin/user/permissions' => '',
|
| 79 |
'admin/user/user' => '',
|
| 80 |
|
| 81 |
'admin/settings' => 'Configuration',
|
| 82 |
'admin/settings/date-time' => '',
|
| 83 |
'admin/settings/filters' => '',
|
| 84 |
'admin/settings/language' => '',
|
| 85 |
'admin/settings/performance' => '',
|
| 86 |
'admin/settings/site' => '',
|
| 87 |
|
| 88 |
'admin/themes' => 'Appearance',
|
| 89 |
'admin/modules' => '',
|
| 90 |
);
|
| 91 |
foreach ($include as $path => $title) {
|
| 92 |
if (!empty($items[$path])) {
|
| 93 |
$items[$path]['title'] = !empty($title) ? $title : $items[$path]['title'];
|
| 94 |
$items[$path]['options']['admin'] = TRUE;
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
| 98 |
// Apparently node/add has no description. Add one.
|
| 99 |
$items['admin/content/add']['description'] = 'Create new content on your site.';
|
| 100 |
$items['admin/content/add']['weight'] = -20;
|
| 101 |
$items['admin/content/node']['weight'] = -19;
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Helper to clone portions of the menu tree to a duplicate location.
|
| 106 |
*/
|
| 107 |
function admin_menu_clone_items($search, $replace, $items) {
|
| 108 |
$offset = count(explode('/', $replace)) - count(explode('/', $search));
|
| 109 |
|
| 110 |
$clone = array();
|
| 111 |
foreach ($items as $path => $item) {
|
| 112 |
if (strpos($path, $search) === 0) {
|
| 113 |
$clone_path = str_replace($search, $replace, $path);
|
| 114 |
|
| 115 |
// Adjust argument offsets if the search and replace paths have a
|
| 116 |
// different arg counts.
|
| 117 |
if ($offset != 0) {
|
| 118 |
foreach (array('page arguments', 'access arguments', 'load arguments', 'title arguments') as $arg_key) {
|
| 119 |
if (!empty($item[$arg_key])) {
|
| 120 |
foreach ($item[$arg_key] as $k => $v) {
|
| 121 |
if (is_numeric($v)) {
|
| 122 |
$item[$arg_key][$k] = $v + $offset;
|
| 123 |
}
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
$clone[$clone_path] = $item;
|
| 130 |
}
|
| 131 |
}
|
| 132 |
return $clone;
|
| 133 |
}
|
| 134 |
|
| 135 |
/**
|
| 136 |
* Implementation of hook_form_alter() for system_admin_theme_settings.
|
| 137 |
*/
|
| 138 |
function admin_form_system_admin_theme_settings_alter(&$form) {
|
| 139 |
// Add in our stealth theme as an option
|
| 140 |
$form['admin_theme']['#options']['admin'] = t('Admin');
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Implementation of hook_form_alter() for node_filter_form.
|
| 145 |
*/
|
| 146 |
function admin_form_node_admin_content_alter(&$form) {
|
| 147 |
// If the admin theme has been inited, do some additional work.
|
| 148 |
global $theme;
|
| 149 |
if ($theme == 'admin') {
|
| 150 |
unset($form['admin']['options']['#type']);
|
| 151 |
unset($form['admin']['options']['#prefix']);
|
| 152 |
unset($form['admin']['options']['#suffix']);
|
| 153 |
$form['admin']['options']['#theme'] = 'admin_manage_options';
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
| 157 |
function admin_form_user_admin_account_alter(&$form) {
|
| 158 |
// If the admin theme has been inited, do some additional work.
|
| 159 |
global $theme;
|
| 160 |
if ($theme == 'admin') {
|
| 161 |
unset($form['options']['#type']);
|
| 162 |
unset($form['options']['#prefix']);
|
| 163 |
unset($form['options']['#suffix']);
|
| 164 |
$form['options']['#theme'] = 'admin_manage_options';
|
| 165 |
}
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Implementation of hook_system_info_alter().
|
| 170 |
* Throw a flag that tells us we need to reinstantiate the admin theme.
|
| 171 |
*/
|
| 172 |
function admin_system_info_alter(&$info, &$theme) {
|
| 173 |
static $once;
|
| 174 |
if (!isset($once)) {
|
| 175 |
$once = TRUE;
|
| 176 |
variable_set('admin_theme_invalidated', TRUE);
|
| 177 |
}
|
| 178 |
}
|
| 179 |
|
| 180 |
/**
|
| 181 |
* Implementation of hook_perm().
|
| 182 |
*/
|
| 183 |
function admin_perm() {
|
| 184 |
return array('admin menu', 'admin inline');
|
| 185 |
}
|
| 186 |
|
| 187 |
/**
|
| 188 |
* Implementation of hook_theme().
|
| 189 |
*/
|
| 190 |
function admin_theme($cache, $type, $theme, $path) {
|
| 191 |
$items = array();
|
| 192 |
$items['admin_toolbar'] = array(
|
| 193 |
'arguments' => array('tree' => array()),
|
| 194 |
'template' => 'admin-toolbar',
|
| 195 |
'path' => drupal_get_path('module', 'admin') .'/toolbar',
|
| 196 |
'file' => 'theme.inc',
|
| 197 |
);
|
| 198 |
$items['admin_links'] = array(
|
| 199 |
'arguments' => array('links' => array()),
|
| 200 |
'template' => 'admin-links',
|
| 201 |
'path' => drupal_get_path('module', 'admin') .'/toolbar',
|
| 202 |
'file' => 'theme.inc',
|
| 203 |
);
|
| 204 |
$items['admin_manage_options'] = array(
|
| 205 |
'arguments' => array('form' => array()),
|
| 206 |
'path' => drupal_get_path('module', 'admin') .'/theme',
|
| 207 |
'file' => 'template.php',
|
| 208 |
);
|
| 209 |
return $items;
|
| 210 |
}
|
| 211 |
|
| 212 |
|
| 213 |
/**
|
| 214 |
* Set wrapper around admin_links_cache().
|
| 215 |
*/
|
| 216 |
function admin_links_set($type, $id, $link) {
|
| 217 |
admin_links_cache('set', $type, $id, $link);
|
| 218 |
}
|
| 219 |
|
| 220 |
/**
|
| 221 |
* Get wrapper around admin_links_cache().
|
| 222 |
*/
|
| 223 |
function admin_links_get($type, $id) {
|
| 224 |
return admin_links_cache('get', $type, $id);
|
| 225 |
}
|
| 226 |
|
| 227 |
/**
|
| 228 |
* Static cache function which allows different parts of the page load
|
| 229 |
* to add contextual admin links to different object types (nodes,
|
| 230 |
* blocks, etc). They are retrieved all at once at the final "rendering"
|
| 231 |
* stages.
|
| 232 |
*/
|
| 233 |
function admin_links_cache($op = 'set', $type, $id, $link = NULL) {
|
| 234 |
static $cache;
|
| 235 |
if (!isset($cache)) {
|
| 236 |
$cache = array();
|
| 237 |
}
|
| 238 |
switch ($op) {
|
| 239 |
case 'set':
|
| 240 |
if (!isset($cache[$type])) {
|
| 241 |
$cache[$type] = array();
|
| 242 |
}
|
| 243 |
if (!isset($cache[$type][$id])) {
|
| 244 |
$cache[$type][$id] = array();
|
| 245 |
}
|
| 246 |
if ($link) {
|
| 247 |
$cache[$type][$id][] = $link;
|
| 248 |
}
|
| 249 |
break;
|
| 250 |
case 'get':
|
| 251 |
if (isset($cache[$type][$id])) {
|
| 252 |
return $cache[$type][$id];
|
| 253 |
}
|
| 254 |
else {
|
| 255 |
return array();
|
| 256 |
}
|
| 257 |
break;
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
/**
|
| 262 |
* Helper function which centralizes link creation for different object
|
| 263 |
* types. Not actually sure if this is a good idea -- may split up.
|
| 264 |
*/
|
| 265 |
function admin_admin_link($hook, $params = array()) {
|
| 266 |
$options = array('query' => 'destination='. $_GET['q']);
|
| 267 |
switch ($hook) {
|
| 268 |
case 'node':
|
| 269 |
if (user_access('administer nodes')) {
|
| 270 |
$edit = $delete = $translate = $options;
|
| 271 |
|
| 272 |
$output = '';
|
| 273 |
if (isset($params['node']->translation)) {
|
| 274 |
$output .= l(t('Translate'), 'node/'. $params['node']->nid .'/translation', $options);
|
| 275 |
}
|
| 276 |
|
| 277 |
$edit['attributes'] = array('class' => 'icon-edit');
|
| 278 |
$output .= l(t('Edit'), "node/{$params['node']->nid}/edit", $edit);
|
| 279 |
|
| 280 |
$delete['attributes'] = array('class' => 'icon-delete');
|
| 281 |
$output .= l(t('Delete'), "node/{$params['node']->nid}/delete", $delete);
|
| 282 |
return $output;
|
| 283 |
}
|
| 284 |
break;
|
| 285 |
case 'block':
|
| 286 |
if (user_access('administer blocks')) {
|
| 287 |
$configure = $options;
|
| 288 |
$configure['attributes'] = array('class' => 'icon-configure');
|
| 289 |
return l(t('Configure'), "admin/build/block/configure/{$params['module']}/{$params['delta']}", $configure);
|
| 290 |
}
|
| 291 |
break;
|
| 292 |
case 'nodequeue':
|
| 293 |
if (user_access('manipulate queues')) {
|
| 294 |
return l(t("Manage queue"), "admin/content/nodequeue/". $params['qid'] ."/view", $options);
|
| 295 |
}
|
| 296 |
break;
|
| 297 |
case 'views':
|
| 298 |
if (user_access('administer views')) {
|
| 299 |
$edit['attributes'] = array('class' => 'icon-edit');
|
| 300 |
return l(t("Edit view"), "admin/build/views/edit/{$params['view']}", $edit);
|
| 301 |
}
|
| 302 |
break;
|
| 303 |
}
|
| 304 |
return '';
|
| 305 |
}
|
| 306 |
|
| 307 |
/**
|
| 308 |
* Implementation of hook_views_pre_view().
|
| 309 |
*/
|
| 310 |
function admin_views_pre_view(&$view, $display_id, $args) {
|
| 311 |
if (user_access('admin inline')) {
|
| 312 |
$links = array();
|
| 313 |
|
| 314 |
// Default view links (edit view)
|
| 315 |
$links[] = admin_admin_link('views', array('view' => $view->name));
|
| 316 |
|
| 317 |
// Helper nodequeue link for administrators
|
| 318 |
if (module_exists('nodequeue') && user_access("manipulate queues")) {
|
| 319 |
$display_id = $view->current_display;
|
| 320 |
$relationships = $view->display[$display_id]->handler->get_option('relationships');
|
| 321 |
if (isset($relationships['nodequeue_rel']) && isset($relationships['nodequeue_rel']['qids']) && count($relationships['nodequeue_rel']['qids'])) {
|
| 322 |
reset($relationships['nodequeue_rel']['qids']);
|
| 323 |
$qid = current($relationships['nodequeue_rel']['qids']);
|
| 324 |
$links[] = admin_admin_link('nodequeue', array('qid' => $qid));
|
| 325 |
}
|
| 326 |
}
|
| 327 |
|
| 328 |
$row_plugin = $view->display_handler->get_option('row_plugin');
|
| 329 |
|
| 330 |
// Bail on attachment views
|
| 331 |
if (get_class($view->display_handler) === 'views_plugin_display_attachment') {
|
| 332 |
return;
|
| 333 |
}
|
| 334 |
// If this is a block view, merge links into the respective block
|
| 335 |
else if (get_class($view->display_handler) === 'views_plugin_display_block') {
|
| 336 |
foreach ($links as $link) {
|
| 337 |
admin_links_set('block', "views-{$view->name}-{$view->current_display}", $link);
|
| 338 |
}
|
| 339 |
}
|
| 340 |
// Ensure the view popups and node popups don't collide
|
| 341 |
else if ($row_plugin != 'node') {
|
| 342 |
foreach ($links as $link) {
|
| 343 |
admin_links_set('views', $view->name .'-'. $view->current_display, $link);
|
| 344 |
}
|
| 345 |
}
|
| 346 |
}
|
| 347 |
}
|
| 348 |
|
| 349 |
/**
|
| 350 |
* Implementation of hook_theme_registry_alter().
|
| 351 |
*/
|
| 352 |
function admin_theme_registry_alter(&$theme_registry) {
|
| 353 |
$hooks = array(
|
| 354 |
'page',
|
| 355 |
'block',
|
| 356 |
'views_view',
|
| 357 |
'views_view_table',
|
| 358 |
'node',
|
| 359 |
);
|
| 360 |
foreach ($hooks as $hook) {
|
| 361 |
if (empty($theme_registry[$hook]['preprocess functions']) || !in_array('admin_preprocess_'. $hook, $theme_registry[$hook]['preprocess functions'])) {
|
| 362 |
$theme_registry[$hook]['preprocess functions'][] = 'admin_preprocess_'. $hook;
|
| 363 |
}
|
| 364 |
}
|
| 365 |
// If the admin theme has been inited, do some additional work.
|
| 366 |
global $theme;
|
| 367 |
if ($theme == 'admin') {
|
| 368 |
// Slap a preprocessor on at the very front of the stack for rebuilding the admin theme.
|
| 369 |
if (!in_array('admin_page_alter', $theme_registry['page']['preprocess functions'])) {
|
| 370 |
array_unshift($theme_registry['page']['preprocess functions'], 'admin_page_alter');
|
| 371 |
}
|
| 372 |
$overrides = array('fieldset', 'node_form', 'system_settings_form', 'admin_block_content');
|
| 373 |
foreach ($overrides as $hook) {
|
| 374 |
$theme_registry[$hook]['function'] = 'admin_'. $hook;
|
| 375 |
}
|
| 376 |
}
|
| 377 |
}
|
| 378 |
|
| 379 |
/**
|
| 380 |
* Page preprocessor that runs before any others (including template_preprocess_page()).
|
| 381 |
* Check the theme rebuild flag and do so if necessary.
|
| 382 |
*/
|
| 383 |
function admin_page_alter(&$vars) {
|
| 384 |
_admin_theme_rebuild();
|
| 385 |
}
|
| 386 |
|
| 387 |
/**
|
| 388 |
* Implementation of hook_preprocess_page().
|
| 389 |
*/
|
| 390 |
function admin_preprocess_page(&$vars) {
|
| 391 |
// @TODO: merge multiple menus rather than just using the first
|
| 392 |
if (user_access('admin menu')) {
|
| 393 |
$links = admin_menu_tree();
|
| 394 |
$links = theme('admin_toolbar', $links);
|
| 395 |
$vars['admin'] = $links;
|
| 396 |
}
|
| 397 |
else {
|
| 398 |
$vars['admin'] = '';
|
| 399 |
}
|
| 400 |
}
|
| 401 |
|
| 402 |
/**
|
| 403 |
* Implementation of hook_preprocess_views_view().
|
| 404 |
*/
|
| 405 |
function admin_preprocess_views_view(&$vars) {
|
| 406 |
if (user_access('admin inline')) {
|
| 407 |
// Retrieve link cache
|
| 408 |
$vid = $vars['view']->name .'-'. $vars['view']->current_display;
|
| 409 |
$links = admin_links_get('views', $vid);
|
| 410 |
|
| 411 |
if ($links) {
|
| 412 |
// Add admin links
|
| 413 |
$vars['pager'] .= theme('admin_links', $links);
|
| 414 |
}
|
| 415 |
$vars['admin_links'] = '';
|
| 416 |
$vars['admin_links_raw'] = '';
|
| 417 |
}
|
| 418 |
}
|
| 419 |
|
| 420 |
/**
|
| 421 |
* Implementation of hook_preprocess_block().
|
| 422 |
*/
|
| 423 |
function admin_preprocess_block(&$vars) {
|
| 424 |
if (user_access('admin inline')) {
|
| 425 |
if (!empty($vars['block']->module) && !empty($vars['block']->delta)) {
|
| 426 |
$bid = $vars['block']->module .'-'. $vars['block']->delta;
|
| 427 |
|
| 428 |
// If this is a custom block, we need to catch it here + add links!
|
| 429 |
switch ($vars['block']->module) {
|
| 430 |
case 'block':
|
| 431 |
$link = admin_admin_link('block', array('module' => 'block', 'delta' => $vars['block']->delta));
|
| 432 |
admin_links_set('block', $bid, $link);
|
| 433 |
break;
|
| 434 |
case 'menu':
|
| 435 |
$link = l(t('Edit menu'), "admin/build/menu-customize/{$vars['block']->delta}", array('query' => "destination={$_GET['q']}"));
|
| 436 |
admin_links_set('block', $bid, $link);
|
| 437 |
break;
|
| 438 |
}
|
| 439 |
|
| 440 |
// Retrieve link cache
|
| 441 |
$links = admin_links_get('block', $bid);
|
| 442 |
|
| 443 |
// Add admin links
|
| 444 |
$vars['block']->content .= theme('admin_links', $links);
|
| 445 |
}
|
| 446 |
}
|
| 447 |
}
|
| 448 |
|
| 449 |
/**
|
| 450 |
* Implementation of hook_preprocess_node().
|
| 451 |
*/
|
| 452 |
function admin_preprocess_node(&$vars) {
|
| 453 |
if (user_access('admin inline')) {
|
| 454 |
// Set link cache
|
| 455 |
$link = admin_admin_link('node', array('node' => $vars['node']));
|
| 456 |
admin_links_set('node', $vars['node']->nid, $link);
|
| 457 |
|
| 458 |
// Retrieve link cache
|
| 459 |
$links = admin_links_get('node', $vars['nid']);
|
| 460 |
$vars['content'] .= theme('admin_links', $links);
|
| 461 |
}
|
| 462 |
}
|
| 463 |
|
| 464 |
/**
|
| 465 |
* Retrieve a hierarchy of links representing select portions of the
|
| 466 |
* 'admin' branch of the navigation menu.
|
| 467 |
*/
|
| 468 |
function admin_menu_tree() {
|
| 469 |
$parents = array();
|
| 470 |
|
| 471 |
$trail = menu_get_active_trail();
|
| 472 |
foreach ($trail as $item) {
|
| 473 |
if (!empty($item['mlid'])) {
|
| 474 |
$parents[] = $item['mlid'];
|
| 475 |
}
|
| 476 |
}
|
| 477 |
|
| 478 |
$tree = menu_tree_data(db_query("
|
| 479 |
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
|
| 480 |
FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
|
| 481 |
WHERE ml.menu_name = '%s'
|
| 482 |
AND ml.link_path LIKE 'admin%'
|
| 483 |
AND ml.depth > 1
|
| 484 |
AND ml.depth < 4
|
| 485 |
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", 'navigation'), $parents);
|
| 486 |
// @TODO: Cache here!
|
| 487 |
|
| 488 |
menu_tree_check_access($tree);
|
| 489 |
|
| 490 |
$links = array();
|
| 491 |
admin_menu_tree_links($tree, $links);
|
| 492 |
|
| 493 |
// Add user-specific links
|
| 494 |
global $user;
|
| 495 |
$user_links = array();
|
| 496 |
$user_links[] = array(
|
| 497 |
'title' => t('Hello <strong>!username</strong>', array('!username' => $user->name)),
|
| 498 |
'href' => 'user',
|
| 499 |
'html' => TRUE
|
| 500 |
);
|
| 501 |
$user_links[] = array('title' => t('Logout'), 'href' => "logout");
|
| 502 |
$links[0]['user'] = $user_links;
|
| 503 |
|
| 504 |
return $links;
|
| 505 |
}
|
| 506 |
|
| 507 |
/**
|
| 508 |
* Generate a links array from a menu tree array.
|
| 509 |
*/
|
| 510 |
function admin_menu_navigation_links($tree, $admin_only = FALSE) {
|
| 511 |
$links = array();
|
| 512 |
foreach ($tree as $item) {
|
| 513 |
if (!$item['link']['hidden'] && (!$admin_only || !empty($item['link']['options']['admin']))) {
|
| 514 |
$class = '';
|
| 515 |
$id = str_replace('/', '-', $item['link']['href']);
|
| 516 |
|
| 517 |
$l = $item['link']['localized_options'];
|
| 518 |
$l['href'] = $item['link']['href'];
|
| 519 |
$l['title'] = "<span class='icon'></span>". $item['link']['title'];
|
| 520 |
$l['attributes'] = array('id' => 'admin-link-'. $id);
|
| 521 |
$l['html'] = TRUE;
|
| 522 |
|
| 523 |
$class = ' path-'. $id;
|
| 524 |
if ($item['link']['in_active_trail']) {
|
| 525 |
$class .= ' active-trail';
|
| 526 |
}
|
| 527 |
// Keyed with the unique mlid to generate classes in theme_links().
|
| 528 |
$links['menu-'. $item['link']['mlid'] . $class] = $l;
|
| 529 |
}
|
| 530 |
}
|
| 531 |
return $links;
|
| 532 |
}
|
| 533 |
|
| 534 |
/**
|
| 535 |
* Build a hierarchy of $links arrays suitable for theme_links() from a
|
| 536 |
* menu tree.
|
| 537 |
*/
|
| 538 |
function admin_menu_tree_links($tree, &$links, $parent = 'admin', $depth = 0) {
|
| 539 |
// Create a single level of links.
|
| 540 |
$links[$depth][$parent] = array();
|
| 541 |
$l = admin_menu_navigation_links($tree, TRUE);
|
| 542 |
if (!empty($l)) {
|
| 543 |
$links[$depth][$parent] = $l;
|
| 544 |
}
|
| 545 |
|
| 546 |
// Recurse
|
| 547 |
foreach ($tree as $item) {
|
| 548 |
if (!$item['link']['hidden'] && !empty($item['link']['options']['admin'])) {
|
| 549 |
if (!empty($item['below'])) {
|
| 550 |
admin_menu_tree_links($item['below'], $links, $item['link']['href'], $depth + 1);
|
| 551 |
}
|
| 552 |
}
|
| 553 |
}
|
| 554 |
}
|
| 555 |
|
| 556 |
/**
|
| 557 |
* Rebuild the admin theme entry in the database.
|
| 558 |
*/
|
| 559 |
function _admin_theme_rebuild($force = FALSE) {
|
| 560 |
if (arg(0) == 'admin') {
|
| 561 |
$exists = db_result(db_query("SELECT count(*) FROM {system} WHERE name = 'admin' AND type = 'theme'"));
|
| 562 |
$force = !$exists ? TRUE : $force;
|
| 563 |
}
|
| 564 |
if ($force || variable_get('admin_theme_invalidated', FALSE)) {
|
| 565 |
$path = drupal_get_path('module', 'admin') .'/theme';
|
| 566 |
|
| 567 |
$theme = new StdClass();
|
| 568 |
$theme->name = 'admin';
|
| 569 |
$theme->filename = "{$path}/admin.theme.info";
|
| 570 |
$theme->engine = 'phptemplate';
|
| 571 |
$theme->owner = drupal_get_path('theme_engine', 'phptemplate') .'/phptemplate.engine';
|
| 572 |
$theme->info = system_theme_default();
|
| 573 |
|
| 574 |
db_query("DELETE FROM {system} WHERE name = 'admin' AND type = 'theme'");
|
| 575 |
db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, isset($theme->status) ? $theme->status : 0, 0, 0);
|
| 576 |
|
| 577 |
variable_set('admin_theme_invalidated', FALSE);
|
| 578 |
}
|
| 579 |
}
|