All pastes #499017 Raw Edit

chx

public text v1 · immutable
·published 2007-05-20 20:47 UTC
rendered paste body
=== modified file 'includes/menu.inc'
--- includes/menu.inc	2007-05-16 13:45:15 +0000
+++ includes/menu.inc	2007-05-20 20:45:55 +0000
@@ -583,7 +583,7 @@ function menu_tree_output($tree) {
  * field, see http://drupal.org/node/141866 for more.
  *
  * @param $menu_name
- *   The named menu links to return
+ *   Links will be returned from this menu.
  * @return
  *   An array of menu links, in the order they should be rendered. The array
  *   is a list of associative arrays -- these have two keys, link and below.
@@ -610,7 +610,7 @@ function menu_tree_data($menu_name = 'na
         $expanded = variable_get('menu_expanded', array());
         if (in_array($menu_name, $expanded)) {
           do {
-            $result = db_query("SELECT mlid FROM {menu_links} WHERE expanded != 0 AND AND has_children != 0 AND menu_name = '%s' AND plid IN (". $placeholders .') AND mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args));
+            $result = db_query("SELECT mlid FROM {menu_links} WHERE expanded != 0 AND has_children != 0 AND menu_name = '%s' AND plid IN (". $placeholders .') AND mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args));
             while ($item = db_fetch_array($result)) {
               $args[] = $item['mlid'];
             }
@@ -685,7 +685,7 @@ function _menu_tree_data($result = NULL,
         'below' => $below,
       );
       // We need to fall back one level.
-      if ($item->depth < $depth) {
+      if (!isset($item) || $item->depth < $depth) {
         ksort($tree);
         return array($item, $tree);
       }
@@ -776,23 +776,6 @@ function menu_get_active_help() {
   return $output;
 }

-/**
- * Build a list of named menus.
- */
-function menu_get_names($reset = FALSE) {
-  static $names;
-  // TODO - use cache system to save this
-
-  if ($reset || empty($names)) {
-    $names = array();
-    $result = db_query("SELECT DISTINCT(menu_name) FROM {menu_links} ORDER BY menu_name");
-    while ($name = db_fetch_array($result)) {
-      $names[] = $name['menu_name'];
-    }
-  }
-  return $names;
-}
-
 function menu_primary_links() {
   $tree = menu_tree_data('primary links');
   return array();
@@ -898,22 +881,6 @@ function menu_secondary_local_tasks() {
   return menu_local_tasks(1);
 }

-function menu_set_active_menu_name($menu_name = NULL) {
-  static $active;
-
-  if (isset($menu_name)) {
-    $active = $menu_name;
-  }
-  elseif (!isset($active)) {
-    $active = 'navigation';
-  }
-  return $active;
-}
-
-function menu_get_active_menu_name() {
-  return menu_set_active_menu_name();
-}
-
 function menu_set_active_item() {
 }

@@ -935,7 +902,8 @@ function menu_set_active_trail($new_trai
     else {
       $href = $item->href;
     }
-    $tree = menu_tree_data(menu_get_active_menu_name());
+    // TODO: enable trail for other menus, not just navigation.
+    $tree = menu_tree_data();
     $curr = array_shift($tree);

     while ($curr) {
@@ -998,7 +966,7 @@ function menu_get_active_title() {
  * @param $mlid
  *   The mlid of the menu item.
  * @return
- *   A menu object, with $item->access filled and link translated for
+ *   A menu array, with $item->access filled and link translated for
  *   rendering.
  */
 function menu_get_item_by_mlid($mlid) {
@@ -1039,10 +1007,9 @@ function menu_cache_clear($menu_name = '
 /**
  * This should be called any time broad changes might have been made to the
  * router items or menu links.
+ * TODO.
  */
 function menu_cache_clear_all() {
-  cache_clear_all('*', 'menu_links', TRUE);
-  cache_clear_all('*', 'menu_router', TRUE);
 }

 /**
@@ -1050,7 +1017,6 @@ function menu_cache_clear_all() {
  * and the navigation menu in the {menu_links} table.
  */
 function menu_rebuild() {
-  menu_cache_clear_all();
   $menu = menu_router_build(TRUE);
   _menu_navigation_links_rebuild($menu);
 }
@@ -1075,14 +1041,14 @@ function _menu_navigation_links_rebuild(
       $item['hidden'] = $item['type'];
     }
     $item += array(
-      'menu name' => 'navigation',
+      'menu_name' => 'navigation',
       'link_title' => $item['title'],
       'href' => $path,
       'module' => 'system',
       'hidden' => 0,
     );
     // We add nonexisting items.
-    if ($item['_visible'] && !db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $item['menu name'], $item['href']))) {
+    if ($item['_visible'] && !db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $item['menu_name'], $item['href']))) {
       $menu_links[$path] = $item;
       $sort[$path] = $item['_number_parts'];
     }
@@ -1106,7 +1072,7 @@ function _menu_navigation_links_rebuild(
  * @param $item
  *   An array representing a menu link item. The only mandatory keys are href
  *   and link_title. Possible keys are
- *     menu name   default is navigation
+ *     menu_name   default is navigation
  *     weight      default is 0
  *     expanded    whether the item is expanded.
  *     options     An array of options, @see l for more.
@@ -1130,7 +1096,7 @@ function menu_link_save(&$item, $_menu =
   $item['_external'] = menu_path_is_external($item['href']);
   // Load defaults.
   $item += array(
-    'menu name' => 'navigation',
+    'menu_name' => 'navigation',
     'weight' => 0,
     'link_title' => '',
     'hidden' => 0,
@@ -1143,14 +1109,14 @@ function menu_link_save(&$item, $_menu =
     $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $item['mlid']));
   }
   else {
-    $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $item['menu name'], $item['href']));
+    $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $item['menu_name'], $item['href']));
   }

   if (empty($existing_item)) {
     $item['mlid'] = db_next_id('{menu_links}_mlid');
   }

-  $menu_name = $item['menu name'];
+  $menu_name = $item['menu_name'];
   $new_path = !$existing_item || ($existing_item['href'] != $item['href']);

   // Find the parent.
@@ -1219,7 +1185,7 @@ function menu_link_save(&$item, $_menu =
       expanded = %d, weight = %d,  depth = %d,
       p1 = %d, p2 = %d, p3 = %d, p4 = %d, p5 = %d, p6 = %d,
       module = '%s', link_title = '%s', options = '%s' WHERE mlid = %d",
-      $item['menu name'], $item['plid'], $item['href'],
+      $item['menu_name'], $item['plid'], $item['href'],
       $item['router_path'], $item['hidden'], $item['_external'], $item['has_children'],
       $item['expanded'],$item['weight'],  $item['depth'],
       $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'],
@@ -1237,7 +1203,7 @@ function menu_link_save(&$item, $_menu =
       %d, %d, %d,
       %d, %d, %d, %d, %d, %d,
       '%s', '%s', '%s')",
-      $item['menu name'], $item['mlid'], $item['plid'], $item['href'],
+      $item['menu_name'], $item['mlid'], $item['plid'], $item['href'],
       $item['router_path'], $item['hidden'], $item['_external'], $item['has_children'],
       $item['expanded'],$item['weight'],  $item['depth'],
       $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'],