Index: nice_menus.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nice_menus/nice_menus.module,v
retrieving revision 1.37
diff -u -p -r1.37 nice_menus.module
--- nice_menus.module	14 Jan 2008 01:29:54 -0000	1.37
+++ nice_menus.module	17 Jan 2008 14:05:48 -0000
@@ -1,22 +1,21 @@
 <?php
-// $Id: nice_menus.module,v 1.37 2008/01/14 01:29:54 add1sun Exp $
+// $Id: nice_menus.module,v 1.16.2.15 2007/12/20 14:16:09 add1sun Exp $
 /*
-  Module to enable CSS dropdown and flyout menus.
-  Maintainer: Addison Berry (add1sun)
-  Originally written by Jake Gordon (jakeg)
+  By Jake Gordon (jakeg)
+  Module to enable CSS dropdoen and flyout menus.
+  Modifications and help by Simon Rawson, Addison Berry and Chad Phillips.
  */
 
 /**
  * Implementation of hook_help().
  */
-function nice_menus_help($path, $arg) {
-  $output = '';
-  switch ($path) {
+function nice_menus_help($section) {
+  switch ($section) {
     case 'admin/settings/modules#description':
-      $output .= t('Make drop down css/javascript menus for site navigation and admin menus.');
+      $output = t('Make drop down css/javascript menus for site navigation and admin menus.');
       break;
     case 'admin/settings/nice_menus':
-      $output .= t('<p>This is a simple module that enables the site to have drop down css/javascript menus for site navigation and admin navigation.</p><p>Remember to activate and configure the menus in !link</p>', array('!link' => l('admin/build/block', 'admin/build/block')));
+      $output = t('<p>This is a simple module that enables the site to have drop down css/javascript menus for site navigation and admin navigation.</p><p>Remember to activate and configure the menus in !link</p>', array('!link' => l('admin/build/block', 'admin/build/block')));
       break;
   }
   return $output;
@@ -25,7 +24,7 @@ function nice_menus_help($path, $arg) {
 /**
  * Implementation of hook_form_alter().
  */
-function nice_menus_form_alter(&$form, $form_state, $form_id) {
+function nice_menus_form_alter($form_id, &$form) {
   switch ($form_id) {
     case 'system_theme_settings':
 
@@ -37,7 +36,7 @@ function nice_menus_form_alter(&$form, $
 
       // Have to add a custom submit handler since this form doesn't use 
       // the standard system submit handler.
-      $form['#submit'][] = 'nice_menus_system_theme_settings_submit';
+      $form['#submit'] += array('nice_menus_system_theme_settings_submit' => array());
 
       // Add global theme setting for a custom CSS file.
       $form['nice_menus_custom_css'] = array(
@@ -55,22 +54,46 @@ function nice_menus_form_alter(&$form, $
 /**
  * Records the nice menu custom CSS file per theme.
  */
-function nice_menus_system_theme_settings_submit($form, &$form_state) {
-  variable_set('nice_menus_custom_css', $form_state['values']['nice_menus_custom_css']);
+function nice_menus_system_theme_settings_submit($form_id, $form_values) {
+  variable_set('nice_menus_custom_css', $form_values['nice_menus_custom_css']);
 }
 
 /**
  * Implemention of hook_menu().
  */
-function nice_menus_menu() {
-  $items['admin/settings/nice_menus'] = array(
-    'title' => 'Nice Menus',
-    'description' => 'Configure Nice Menus.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('nice_menus_admin_settings'),
-    'access arguments' => array('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM,
-  );
+function nice_menus_menu($may_cache) {
+  if (!$may_cache) {
+    // We only want to include the JS for IE and not browsers 
+    // capable of doing everything in css.  We have to put all the JS
+    // in drupal_set_html_head so they get called in the right order.
+    drupal_set_html_head('<!--[if IE]>
+    <script type="text/javascript" src="'. check_url(base_path() .'misc/jquery.js') .'"></script>
+    <script type="text/javascript" src="'. check_url(base_path() .'misc/drupal.js') .'"></script>
+    <script type="text/javascript" src="'. check_url(base_path() . drupal_get_path('module', 'nice_menus') .'/nice_menus.js') .'"></script>
+    <![endif]-->');
+
+    // Add main CSS functionality.
+    drupal_add_css(drupal_get_path('module', 'nice_menus') .'/nice_menus.css');
+    // Add custom CSS layout if specified.
+    if ($custom = variable_get('nice_menus_custom_css', '')) {
+      drupal_add_css($custom);
+    }
+    // Fall back to default layout.
+    else {
+      drupal_add_css(drupal_get_path('module', 'nice_menus') .'/nice_menus_default.css');
+    }
+  }
+  else {
+    $items[] = array(
+      'path' => 'admin/settings/nice_menus',
+      'title' => t('Nice Menus'),
+      'description' => t('Configure Nice Menus.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('nice_menus_admin_settings'),
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
+    );
+  }
 
   return $items;
 }
@@ -100,7 +123,7 @@ function nice_menus_block($op = 'list', 
 
   switch ($op) {
     case 'list':
-      for ($i = 1; $i <= variable_get('nice_menus_number', '2'); $i++) {
+      for ($i=1; $i <= variable_get('nice_menus_number', '2'); $i++) {
         $blocks[$i]['info'] = variable_get('nice_menus_name_'. $i, 'Nice Menu '. $i) .' (Nice Menu)';
       }
       return $blocks;
@@ -116,8 +139,8 @@ function nice_menus_block($op = 'list', 
         '#type' => 'select',
         '#title' => t('Source Menu Tree'),
         '#description' => t('The menu tree from which to show a nice menu.'),
-        '#default_value' => variable_get('nice_menus_menu_'. $delta, 'navigation:0'),
-        '#options' => menu_parent_options(menu_get_menus(), 0),
+        '#default_value' => variable_get('nice_menus_menu_'. $delta, '1'),
+        '#options' => menu_parent_options(0, 0),
       );
       $form['nice_menus_type_'. $delta] = array(
         '#type' => 'select',
@@ -126,6 +149,13 @@ function nice_menus_block($op = 'list', 
         '#default_value' => variable_get('nice_menus_type_'. $delta, 'right'),
         '#options' => drupal_map_assoc(array('right', 'left', 'down')),
       );
+      $form['nice_menus_depth_'. $delta] = array(
+        '#type' => 'select', 
+        '#title' => t('Maximum Depth'), 
+        '#description' => t('the depth of the menu, starting with the parent selected above to be displayed.  this allows primary/secondary links functionality.  if unsure, just leave this at -1 which will show all items.'),
+        '#default_value' => variable_get('nice_menus_depth_'. $delta, -1),
+        '#options' => drupal_map_assoc(range(-1,5))
+      );
       return $form;
     break;
 
@@ -133,13 +163,15 @@ function nice_menus_block($op = 'list', 
       variable_set('nice_menus_name_'. $delta, $edit['nice_menus_name_'. $delta]);
       variable_set('nice_menus_menu_'. $delta, $edit['nice_menus_menu_'. $delta]);
       variable_set('nice_menus_type_'. $delta, $edit['nice_menus_type_'. $delta]);
+			variable_set('nice_menus_depth_'. $delta, $edit['nice_menus_depth_'.$delta]);
     break;
 
     case 'view':
       // Build the nice menu for the block.
-      list($menu_name, $mlid) = explode(':', variable_get('nice_menus_menu_'. $delta, 'navigation:0'));
+      $pid = variable_get('nice_menus_menu_'. $delta, '1');
       $direction = variable_get('nice_menus_type_'. $delta, 'right');
-      if ($output = theme('nice_menu', $delta, $menu_name, $mlid, $direction)) {
+			$depth = variable_get('nice_menus_depth_'.$delta, '-1');
+      if ($output = theme('nice_menu', $delta, $depth, $pid, $direction)) {
         $block['content'] = $output['content'];
         if (variable_get('nice_menus_type_'. $delta, 'right') == 'down') {
           $class = 'nice-menu-hide-title';
@@ -160,163 +192,85 @@ function nice_menus_block($op = 'list', 
       else {
         $block['content'] = false;
       }
-      //$block['content'] = print_r($mlid);
+
       return $block;
     break;
   }
 }
 
 /**
- * Implmentation of hook_theme().
- **/
-function nice_menus_theme() {
-  return array(
-    'nice_menu_tree' => array(
-      'arguments' => array('pid' => 1, 'menu' => NULL),
-    ),
-    'nice_menu_build' => array(
-      'arguments' => array('menu' => NULL, 'id' => NULL),
-    ),
-    'nice_menu' => array('id' => NULL, 'pid' => NULL, 'direction' => 'right', 'menu' => NULL),
-    'nice_menu_primary_links' => array('direction' => 'down', 'menu' => NULL),
-  );
-}
-
-/**
- * Builds the final nice menu.
+ * Builds the inner portion of a nice menu.
  *
- * @param $menu_name
- *   The top-level menu name that contains the menu to use (e.g. navigation 
- *   or primary-links) for Drupal menus. For custom $menus this is just the 
- *   name for menu display.
- * @param $mlid
- *   The menu ID from which to start building the items, i.e. the parent
- *   of the displayed menu.
+ * @param $pid
+ *   The parent menu ID from which to build the items.
  * @param $menu
- *   Optional. A custom menu array to use for theming -- it should have
- *   the same structure as that returned by menu_tree_all_data().
+ *   Optional. A custom menu array to use for theming --
+ *   it should have the same structure as that returned by menu_get_menu().
  * @return
  *   An HTML string of properly nested nice menu lists.
  */
-function theme_nice_menu_tree($menu_name, $mlid = NULL, $menu = NULL) {
-  // Load the full menu array.
-  $menu = isset($menu) ? $menu : menu_tree_all_data($menu_name);
-  
-  // For custom $menus and menus built all the way from the top-level we
-  // don't need to "create" the specific sub-menu and we need to get the title
-  // from the $menu_name since there is no "parent item" array.
-   
-  // Create the specific menu if we have a mlid.
-  if (!empty($mlid)) {
-    // Load the parent menu item.
-    $item = menu_link_load($mlid);
-    $title = $item['title'];
-    // Narrow down the full menu to the specific sub-tree we need.
-    for ($p = 1; $p < 10; $p++) {
-      if ($sub_mlid = $item["p$p"]) {
-        $subitem = menu_link_load($sub_mlid);
-        // Menu sets these ghetto-ass keys in _menu_tree_check_access().
-        $menu = $menu[(50000 + $subitem['weight']) .' '. $subitem['title'] .' '. $subitem['mlid']]['below'];
-      }
-    }
-  }
-  // Otherwise just set a title and move on.
-  else {
-    $title = $menu_name;
-  }
-  
+function theme_nice_menu_tree($pid = 1, $depth = -1, $deep = 0, $menu = NULL) {
+  $menu = isset($menu) ? $menu : menu_get_menu();
   $output['content'] = '';
-  $output['subject'] = $title;
-
-  if ($menu) {
-    $output['content'] .= theme('nice_menu_build', $menu);
-  }
-
-  return $output;
-}
-
-/**
- * Helper function that builds the nested lists of a nice menu.
- *
- * @param $menu
- *   Menu array from which to build the nested lists. 
- */
-function theme_nice_menu_build($menu) {
-  $output = '';  
-
-  foreach ($menu as $menu_item) {
-    $mlid = $menu_item['link']['mlid'];
-    // Check to see if it is a visible menu item.
-    if ($menu_item['link']['hidden'] == 0) {
-      // Build class name based on menu path 
-      // e.g. to give each menu item individual style.
-      // Strip funny symbols.
-      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
-      // Convert slashes to dashes.
+	
+  $output['subject'] = $menu['items'][$pid]['title'];
+	
+  if ($menu['visible'][$pid]['children']) {
+    // Build class name based on menu path 
+    // e.g. to give each menu item individual style.
+		$i = 0;
+    foreach ($menu['visible'][$pid]['children'] as $mid) {
+      // Strip funny symbols
+      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu['items'][$mid]['path']);
+      // Convert slashes to dashes
       $clean_path = str_replace('/', '-', $clean_path);
       $path_class = 'menu-path-'. $clean_path;
-      // If it has children build a nice little tree under it.
-      if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
-        // Keep passing children into the function 'til we get them all.
-        $children = theme('nice_menu_build', $menu_item['below']);
-        // Build the child UL.
-        $output .= '<li id="menu-'. $mlid .'" class="menuparent '. $path_class .'">'. l($menu_item['link']['title'], $menu_item['link']['href']);
-        $output .= '<ul><!--[if lt IE 7]><iframe src="javascript:false;"></iframe><![endif]-->';
-        $output .= $children;                     
-        $output .= "</ul>\n";
-        $output .= "</li>\n";
+      if (count($menu['visible'][$mid]['children']) > 0 && $depth != 0) {
+			  if ($deep < $depth || $depth == -1) {
+	        $output['content'] .= '<li id="menu-'. $mid .'" class="menuparent '. $path_class .'">'. menu_item_link($mid);
+  	      $output['content'] .= '<ul><!--[if lt IE 7]><iframe src="javascript:false;"></iframe><![endif]-->';
+    	    $tmp = theme('nice_menu_tree', $mid, $depth, $i);
+      	  $output['content'] .= $tmp['content'];
+        	$output['content'] .= "</ul>\n";
+	        $output['content'] .= "</li>\n";
+				}
+			  else {
+        $output['content'] .= '<li id="menu-'. $mid .'" class="'. $path_class .'">'. menu_item_link($mid) .'</li>'."\n";
+				}
+				$i += 1;
       }
       else {
-        $output .= '<li id="menu-'. $mlid .'" class="'. $path_class .'">'. l($menu_item['link']['title'], $menu_item['link']['href']) .'</li>'."\n";
+        $output['content'] .= '<li id="menu-'. $mid .'" class="'. $path_class .'">'. menu_item_link($mid) .'</li>'."\n";
       }
     }
   }
   return $output;
 }
 
+
 /**
  * General theming function to allow any menu tree to be themed 
  * as a nice menu.
  *
  * @param $id
  *   The nice menu ID.
- * @param $menu_name
- *   The top parent menu name from which to build the full menu.
- * @param $mlid
- *   The menu ID from which to build the displayed menu.
+ * @param $pid
+ *   The parent menu ID from which to build the nice menu
  * @param $direction
  *   Optional. The direction the menu expands. Default is 'right'.
+ * @param $depth
+ *   Optional. The direction the menu expands. Default is 'right'.
  * @param $menu
  *   Optional. A custom menu array to use for theming --
- *   it should have the same structure as that returned
- *  by menu_tree_all_data(). Default is the standard menu tree.
+ *   it should have the same structure
+ *   as that returned by menu_get_menu(). Default is the standard menu tree.
  * @return
  *   An HTML string of nice menu links.
  */
-function theme_nice_menu($id, $menu_name, $mlid, $direction = 'right', $menu = NULL) {
-  // We only want to include the JS for IE and not browsers 
-  // capable of doing everything in css.  We have to put all the JS
-  // in drupal_set_html_head so they get called in the right order. ;-(
-  drupal_set_html_head('<!--[if IE]>
-  <script type="text/javascript" src="'. check_url(base_path() .'misc/jquery.js') .'"></script>
-  <script type="text/javascript" src="'. check_url(base_path() .'misc/drupal.js') .'"></script>
-  <script type="text/javascript" src="'. check_url(base_path() . drupal_get_path('module', 'nice_menus') .'/nice_menus.js') .'"></script>
-  <![endif]-->');
-
-  // Add main CSS functionality.
-  drupal_add_css(drupal_get_path('module', 'nice_menus') .'/nice_menus.css');
-  // Add custom CSS layout if specified.
-  if ($custom = variable_get('nice_menus_custom_css', '')) {
-    drupal_add_css($custom);
-  }
-  // Fall back to default layout.
-  else {
-    drupal_add_css(drupal_get_path('module', 'nice_menus') .'/nice_menus_default.css');
-  }
-  
+function theme_nice_menu($id, $depth = -1, $pid, $direction = 'right', $menu = NULL) {
   $output = array();
 
-  if ($menu_tree = theme('nice_menu_tree', $menu_name, $mlid, $menu)) {
+  if ($menu_tree = theme('nice_menu_tree', $pid, $depth, $menu)) {
     if ($menu_tree['content']) {
       $output['content'] = '<ul class="nice-menu nice-menu-'. $direction .'" id="nice-menu-'. $id .'">'. $menu_tree['content'] .'</ul>'."\n";
       $output['subject'] = $menu_tree['subject'];
@@ -332,12 +286,13 @@ function theme_nice_menu($id, $menu_name
  *   Optional. The direction the menu expands. Default is 'down'.
  * @param $menu
  *   Optional. A custom menu array to use for theming --
- *   it should have the same structure as that returned
- *   by menu_tree_all_data(). Default is the standard menu tree.
+ *   it should have the same structure
+ *   as that returned by menu_get_menu(). Default is the standard menu tree.
  * @return
  *   An HTML string of nice menu primary links.
  */
 function theme_nice_menu_primary_links($direction = 'down', $menu = NULL) {
-  $output = theme('nice_menu', 0, 'primary-links', 0, $direction, $menu);
+  $pid = variable_get('menu_primary_menu', 0);
+  $output = theme('nice_menu', 'primary', $pid, $direction, $menu);
   return $output['content'];
 }
