Index: admin_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/admin_menu/admin_menu.module,v
retrieving revision 1.9
diff -u -r1.9 admin_menu.module
--- admin_menu.module	4 Mar 2007 02:51:10 -0000	1.9
+++ admin_menu.module	10 Mar 2007 23:26:10 -0000
@@ -53,6 +53,24 @@
   global $_menu;
   $admin_items = array();
 
+  // Temporary permissions fix until #126621 has been committed to core.
+  $mid_content = $_menu['path index']['admin/content'];
+  if (isset($_menu['items'][$mid_content])) {
+    $_menu['items'][$mid_content]['access'] = user_access('access administration pages');
+  }
+  $mid_build = $_menu['path index']['admin/build'];
+  if (isset($_menu['items'][$mid_build])) {
+    $_menu['items'][$mid_build]['access'] = user_access('access administration pages');
+  }
+  $mid_user = $_menu['path index']['admin/user'];
+  if (isset($_menu['items'][$mid_user])) {
+    $_menu['items'][$mid_user]['access'] = user_access('administer users');
+  }
+  $mid_user_settings = $_menu['path index']['admin/user/settings'];
+  if (isset($_menu['items'][$mid_user_settings])) {
+    $_menu['items'][$mid_user_settings]['access'] = user_access('administer site configuration');
+  }
+  
   // get path id of /q=admin, which we suppose to be the root of admin menu
   $pid_admin = $_menu['path index']['admin'];
   $admin_items[$pid_admin] = $_menu['items'][$pid_admin];
@@ -66,7 +84,7 @@
   // remove administer menu item from parent's children list
   $parent_id = $_menu['items'][$pid_admin]['pid'];
   $child_key = array_search($pid_admin, $_menu['visible'][$parent_id]['children']);
-  unset( $_menu['visible'][$parent_id]['children'][$child_key] );
+  unset($_menu['visible'][$parent_id]['children'][$child_key]);
   
   return theme('admin_menu_tree', $admin_items, $pid_admin);
 }
@@ -74,29 +92,38 @@
 function _admin_menu_get_children(&$admin_items, &$item) {
   global $_menu;
   
-  if (isset( $item['children'] )) {
+  if (isset($item['children'])) {
     foreach ($item['children'] as $child) {
-      $is_visible_item = $_menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_IS_LOCAL_TASK);
+      // check access permissions
+      if (!variable_get('admin_menu_show_item_ids', 0)) {
+        $item_is_accessible = !isset($_menu['items'][$child]['access']) || (isset($_menu['items'][$child]['access']) && $_menu['items'][$child]['access']);
+      }
+      else {
+        $item_is_accessible = true;
+      }
+      // check type
+      $item_is_visible = $_menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_IS_LOCAL_TASK);
 
-      // create the child item if it's visible in navigation
-      // Hide items linking to parent: && !($_menu['items'][$child]['type'] & MENU_LINKS_TO_PARENT) 12/01/2007 sun
-      if ($is_visible_item) {
+      // create the child item if it is accessible and visible
+      // Additional if condition to hide items linking to parent:
+      //   && !($_menu['items'][$child]['type'] & MENU_LINKS_TO_PARENT)
+      if ($item_is_accessible && $item_is_visible) {
         $admin_items[$child] = $_menu['items'][$child];
 
         // recurse to child menu items
-        if (isset( $_menu['items'][$child]['children'] )) {
+        if (isset($_menu['items'][$child]['children'])) {
           _admin_menu_get_children($admin_items, $admin_items[$child]);
         }
 
-        // remove this child item if it's visible in navigation
-        unset( $_menu['visible'][$child] );
+        // remove this child item if it is visible in navigation
+        unset($_menu['visible'][$child]);
       }
       else {
         // remove child menu item from parent's children list
         $parent_id = $_menu['items'][$child]['pid'];
         $child_key = array_search($child, $_menu['items'][$parent_id]['children']);
-        if ($child_key !== FALSE) {
-          unset( $admin_items[$parent_id]['children'][$child_key] );
+        if ($child_key !== false) {
+          unset($admin_items[$parent_id]['children'][$child_key]);
         }
       }
     }
@@ -109,35 +136,20 @@
 function admin_menu_adjust_items(&$admin_items) {
   global $_menu;
   
-  // move 'By module' into Site configuration
-  $mid_bymodule = $_menu['path index']['admin/by-module'];
-  if (isset( $admin_items[$mid_bymodule] )) {
-    // remove child pointer from original location
-    $parent_id = $admin_items[$mid_bymodule]['pid'];
-    $child_key = array_search($mid_bymodule, $admin_items[$parent_id]['children']);
-    if ($child_key !== FALSE) {
-      unset( $admin_items[$parent_id]['children'][$child_key] );
-    }
-    // insert new child pointers
-    $pid_settings = $_menu['path index']['admin/settings'];
-    $admin_items[$mid_bymodule]['pid'] = $pid_settings;
-    array_unshift( $admin_items[$pid_settings]['children'], $mid_bymodule);
+  // move 'By module' into Site configuration or remove it
+  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');
   }
   
   // remove 'By task' menu item
-  $mid_bytask = $_menu['path index']['admin/by-task'];
-  if (isset( $admin_items[$mid_bytask] )) {
-    // remove child pointer
-    $parent_id = $admin_items[$mid_bytask]['pid'];
-    $child_key = array_search($mid_bytask, $admin_items[$parent_id]['children']);
-    if ($child_key !== FALSE) {
-      unset( $admin_items[$parent_id]['children'][$child_key] );
-    }
-  }
+  admin_menu_remove_item($admin_items, 'admin/by-task');
 
   // add create content_type items to Content management > Content
   $mid_content = $_menu['path index']['admin/content/node'];
-  if (isset( $admin_items[$mid_content] )) {
+  if (isset($admin_items[$mid_content])) {
     foreach ($_menu['items'][$_menu['path index']['node/add']]['children'] as $mid) {
       $admin_items[$mid] = $_menu['items'][$mid];
       $admin_items[$mid]['title'] = t('Add !content-type', array('!content-type' => $admin_items[$mid]['title']));
@@ -150,6 +162,62 @@
 }
 
 /**
+ * Moves the child pointer for a menu item to a new parent.
+ * 
+ * @param admin_items
+ *      The sliced administration menu.
+ * @param path
+ *      The menu path of the item to move.
+ * @param parent_path
+ *      The menu path of the new parent item.
+ */
+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])) {
+    // remove current child pointer
+    admin_menu_remove_item($admin_items, $path);
+    
+    // insert new child pointer
+    $admin_items[$mid]['pid'] = $new_pid;
+    array_unshift($admin_items[$new_pid]['children'], $mid);
+    
+    return true;
+  }
+  else {
+    return false;
+  }
+}
+
+/**
+ * Removes the child pointer for a menu item.
+ * 
+ * @param admin_items
+ *      The sliced administration menu.
+ * @param path
+ *      The menu path to remove.
+ */
+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;
+}
+
+/**
  * Returns the rendered link to a menu item.
  *
  * @param $mid
@@ -163,6 +231,11 @@
     $link_item = menu_get_item($link_item['pid']);
   }
 
+  // display menu item ids if enabled (devel)
+  if (variable_get('admin_menu_show_item_ids', 0)) {
+    $item['title'] = $item['title'] . ' (' . $mid . ')';
+  }
+  
   return theme('menu_item_link', $item, $link_item);
 }
 
@@ -179,15 +252,15 @@
   
   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;
+      $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) {
+function theme_admin_menu_item(&$admin_items, $mid, $children = '', $leaf = true) {
   $output = '<li' . (!$leaf ? ' class="expandable"' : '') . '>';
   $output.= admin_menu_item_link($admin_items, $mid) . $children . "</li>";
   return $output;
@@ -197,3 +270,28 @@
   $output = '<img id="admin_menu_icon" src="' . check_url(base_path() . 'misc/favicon.ico') . '" alt="" border="0" />';
   return $output;
 }
+
+/**
+ * Implementation of hook_form_alter() to extend devel.module.
+ */
+function admin_menu_form_alter($form_id, &$form) {
+  if ($form_id == 'devel_admin_settings') {
+    // shift system_settings_form buttons
+    $weight = $form['buttons']['#weight'];
+    $form['buttons']['#weight'] = $weight + 1;
+    
+    $form['admin_menu'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Administration Menu settings'),
+      '#collapsible' => true,
+      '#collapsed' => true,
+    );
+    $form['admin_menu']['admin_menu_show_item_ids'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display menu item IDs in Drupal Administration Menu'),
+      '#default_value' => variable_get('admin_menu_show_item_ids', 0),
+      '#description' => t('If enabled, the corresponding menu item id will appear next to each menu item link.'),
+    );
+  }
+}
+
