View source
<?php
function admin_menu_get_menu() {
global $_menu;
$admin_items = array();
$mid_admin = $_menu['path index']['admin'];
foreach ($_menu['items'][$mid_admin]['children'] as $key => $parent) {
if ($_menu['items'][$parent]['access'] != false || !isset($_menu['items'][$parent]['children'])) {
continue;
}
$is_accessible = false;
foreach ($_menu['items'][$parent]['children'] as $key => $child) {
if ($_menu['items'][$child]['access'] == true) {
$is_accessible = true;
}
}
if ($is_accessible) {
$_menu['items'][$parent]['access'] = true;
}
}
$admin_items[$mid_admin] = $_menu['items'][$mid_admin];
_admin_menu_get_children($admin_items, $admin_items[$mid_admin]);
admin_menu_adjust_items($admin_items);
$parent_id = $_menu['items'][$mid_admin]['pid'];
$child_key = array_search($mid_admin, $_menu['visible'][$parent_id]['children']);
unset($_menu['visible'][$parent_id]['children'][$child_key]);
return theme('admin_menu_tree', $admin_items, $mid_admin);
}
function _admin_menu_get_children(&$admin_items, &$item) {
global $_menu;
if (isset($item['children'])) {
foreach ($item['children'] as $child) {
if (!variable_get('admin_menu_show_all', 0)) {
$item_is_accessible = !isset($_menu['items'][$child]['access']) || isset($_menu['items'][$child]['access']) && $_menu['items'][$child]['access'];
}
else {
$item_is_accessible = true;
}
$item_is_visible = $_menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_IS_LOCAL_TASK);
if ($item_is_accessible && $item_is_visible) {
$admin_items[$child] = $_menu['items'][$child];
if (isset($_menu['items'][$child]['children'])) {
_admin_menu_get_children($admin_items, $admin_items[$child]);
}
unset($_menu['visible'][$child]);
}
else {
$parent_id = $_menu['items'][$child]['pid'];
if (isset($_menu['items'][$parent_id]['children']) && is_array($_menu['items'][$parent_id]['children'])) {
$child_key = array_search($child, $_menu['items'][$parent_id]['children']);
if ($child_key !== false) {
unset($admin_items[$parent_id]['children'][$child_key]);
}
}
}
}
usort($item['children'], '_menu_sort');
}
}
function admin_menu_adjust_items(&$admin_items) {
global $_menu;
if (user_access('administer site configuration')) {
admin_menu_move_item($admin_items, 'admin/by-module', 'admin/settings');
}
else {
admin_menu_remove_item($admin_items, 'admin/by-module');
}
admin_menu_remove_item($admin_items, 'admin/by-task');
$mid_logout = $_menu['path index']['logout'];
$admin_items[$mid_logout] = $_menu['items'][$mid_logout];
$admin_items[$mid_logout]['class'] = 'admin_menu-action';
$mid_admin = $_menu['path index']['admin'];
$admin_items[$mid_logout]['pid'] = $mid_admin;
array_unshift($admin_items[$mid_admin]['children'], $mid_logout);
$mid_node_add = $_menu['path index']['node/add'];
$mid_content = $_menu['path index']['admin/content/node'];
admin_menu_copy_items($admin_items, $mid_node_add, $mid_content, t('Add !title'));
}
function admin_menu_copy_items(&$admin_items, $source_pid, $target_pid, $title = NULL, $tree = TRUE) {
global $_menu;
if (isset($admin_items[$target_pid]) && isset($_menu['items'][$source_pid]['children'])) {
foreach ($_menu['items'][$source_pid]['children'] as $mid) {
$admin_items[$mid] = $_menu['items'][$mid];
if (isset($title)) {
$admin_items[$mid]['title'] = check_plain(strtr($title, array(
'!title' => $admin_items[$mid]['title'],
)));
}
$admin_items[$mid]['pid'] = $target_pid;
if (!in_array($mid, $admin_items[$target_pid]['children'])) {
$admin_items[$target_pid]['children'][] = $mid;
}
if (isset($_menu['items'][$mid]['children']) && count($_menu['items'][$mid]['children'])) {
if ($tree) {
admin_menu_copy_items($admin_items, $mid, $mid, $title);
}
else {
admin_menu_copy_items($admin_items, $mid, $target_pid, $title, FALSE);
unset($admin_items[$mid]['children']);
}
}
}
usort($admin_items[$target_pid]['children'], '_menu_sort');
}
}
function admin_menu_move_item(&$admin_items, $path, $parent_path) {
global $_menu;
$mid = $_menu['path index'][$path];
$new_pid = $_menu['path index'][$parent_path];
if (isset($admin_items[$mid]) && isset($admin_items[$new_pid])) {
admin_menu_remove_item($admin_items, $path);
$admin_items[$mid]['pid'] = $new_pid;
array_unshift($admin_items[$new_pid]['children'], $mid);
return true;
}
else {
return false;
}
}
function admin_menu_remove_item(&$admin_items, $path) {
global $_menu;
$mid = $_menu['path index'][$path];
if (isset($admin_items[$mid])) {
$pid = $admin_items[$mid]['pid'];
$child_key = array_search($mid, $admin_items[$pid]['children']);
if ($child_key !== false) {
unset($admin_items[$pid]['children'][$child_key]);
return true;
}
else {
return false;
}
}
return false;
}
function admin_menu_item_link(&$admin_items, $mid) {
$item = $admin_items[$mid];
$link_item = $item;
while ($link_item['type'] & MENU_LINKS_TO_PARENT) {
$link_item = menu_get_item($link_item['pid']);
}
if (variable_get('admin_menu_show_item_ids', 0)) {
$item['title'] = $item['title'] . ' (' . $mid . ')';
}
unset($item['description']);
return theme('menu_item_link', $item, $link_item);
}
function theme_admin_menu_tree(&$menu, $pid = 1) {
$output = '';
if (isset($menu[$pid]) && $menu[$pid]['children']) {
foreach ($menu[$pid]['children'] as $mid) {
$type = isset($menu[$mid]['type']) ? $menu[$mid]['type'] : null;
$children = isset($menu[$mid]['children']) ? $menu[$mid]['children'] : null;
$output .= theme('admin_menu_item', $menu, $mid, theme('admin_menu_tree', $menu, $mid), count($children) == 0);
}
}
return $output ? "<ul>" . $output . "</ul>" : '';
}
function theme_admin_menu_item(&$admin_items, $mid, $children = '', $leaf = true) {
$class = array();
if (!$leaf) {
$class[] = 'expandable';
}
if (isset($admin_items[$mid]['class'])) {
$class[] = $admin_items[$mid]['class'];
}
$output = '<li' . (!empty($class) ? ' class="' . implode(' ', $class) . '"' : '') . '>';
$output .= admin_menu_item_link($admin_items, $mid) . $children . '</li>';
return $output;
}