/[drupal]/contributions/modules/simplemenu/simplemenu.module
ViewVC logotype

Diff of /contributions/modules/simplemenu/simplemenu.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.10, Fri Dec 12 06:24:18 2008 UTC revision 1.10.2.1, Wed Apr 1 01:39:51 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: simplemenu.module,v 1.9.2.11.2.6 2008/12/12 05:25:07 rz Exp $  // $Id: simplemenu.module,v 1.10 2008/12/12 06:24:18 rz Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 63  function simplemenu_init() { Line 63  function simplemenu_init() {
63        'detectPopup' => variable_get('simplemenu_detect_popop', 1),        'detectPopup' => variable_get('simplemenu_detect_popop', 1),
64      );      );
65    
66      drupal_add_js(array('simplemenu' => $settings), 'setting');      drupal_add_js(array('simplemenu' => $settings), 'setting');
67      drupal_add_js($path .'/simplemenu.js');  
     drupal_add_js($path .'/superfish.js');  
   }  
 }  
   
 /**  
  * Implementation of hook_footer().  
  *  
  * This has been broken off of simplemenu_init() because simplemenu_get_menu()  
  * calls simplemenu_menu_tree() which calls menu_tree_output() which has several  
  * calls to theme().  This initializes the theme system too early causing hard  
  * to track bugs.  
  *  
  * @see http://drupal.org/node/219910  
  */  
 function simplemenu_footer() {  
   if(simplemenu_enabled()) {  
68      $simplemenu = drupal_to_js(simplemenu_get_menu());      $simplemenu = drupal_to_js(simplemenu_get_menu());
     $path = base_path() . drupal_get_path('module', 'simplemenu');  
   
     $output = "<script type=\"text/javascript\">var simplemenu = $simplemenu;</script>\n";  
69    
70      return $output;      drupal_add_js('var simplemenu = '. drupal_to_js(simplemenu_get_menu()) .';', 'inline');
71        drupal_add_js($path .'/simplemenu.js');
72        drupal_add_js($path .'/superfish.js');
73    }    }
74  }  }
75    
# Line 227  function simplemenu_get_menu() { Line 210  function simplemenu_get_menu() {
210    // if a user turned off menu module but SimpleMenu was previously set    // if a user turned off menu module but SimpleMenu was previously set
211    // reset variable so a menu appears    // reset variable so a menu appears
212    $menu_name = module_exists('menu') ? variable_get('simplemenu_menu', 'navigation:0') : 'navigation:0';    $menu_name = module_exists('menu') ? variable_get('simplemenu_menu', 'navigation:0') : 'navigation:0';
213    $menu = simplemenu_menu_tree($menu_name);    $tree = simplemenu_menu_tree($menu_name);
214    
215    if (!$menu) {    // allow other modules to alter the tree
216      $menu = '<li><a href="'. url('admin/settings/simplemenu') .'">'. t('No menu items found. Try a different menu as the default.') .'</a></li>';    drupal_alter('simplemenu_tree', $tree);
217    }  
218      // if the tree is still empty, display a link to the settings.
219    // This is ugly, I know, but it is the only way I can see to get the additional    if (!$tree) {
220    // links inside the <ul> tags      $tree[] = l(t('No menu items found. Try a different menu as the default.'), 'admin/settings/simplemenu');
   if($devel = simplemenu_get_devel()) {  
     $pos = strpos($menu, '>') + 1;  
     $menu = substr($menu, 0, $pos) . $devel .substr($menu, $pos);  
221    }    }
222    
223    $output .= $menu;    // render for output
224      $output = simplemenu_tree_output($tree);
225    
226    return $output;    return $output;
227  }  }
# Line 249  function simplemenu_get_menu() { Line 230  function simplemenu_get_menu() {
230   * Custom implementation of menu_tree().   * Custom implementation of menu_tree().
231   * We want to retrieve the entire menu structure for a given menu,   * We want to retrieve the entire menu structure for a given menu,
232   * regardless of whether or not the menu item is expanded or not.   * regardless of whether or not the menu item is expanded or not.
233     *
234     * @param $menu_name
235     *   The name of the menu.
236     * @return
237     *   A tree array ready for simplemenu_tree_output().
238   */   */
   
239  function simplemenu_menu_tree($menu_name = 'navigation:0') {  function simplemenu_menu_tree($menu_name = 'navigation:0') {
240    static $menu_output = array();    static $menu_output = array();
241    
242    if (!isset($menu_output[$menu_name])) {    if (!isset($menu_output[$menu_name])) {
243      $tree = simplemenu_tree_all_data($menu_name);      $tree = simplemenu_tree_all_data($menu_name);
244      $menu_output[$menu_name] = menu_tree_output($tree);      $menu_output[$menu_name] = simplemenu_compact_menu_tree($tree);
245    }    }
246    
247    return $menu_output[$menu_name];    return $menu_output[$menu_name];
248  }  }
249    
250  /**  /**
251     * Recursive function to compact the menu tree into our item_list style tree
252     *
253     * @param $tree
254     *   A menu tree array as returned from menu_tree_all_data().
255     * @return
256     *   A tree array ready for simplemenu_tree_output().
257     */
258    function simplemenu_compact_menu_tree($tree) {
259      $items = array();
260      foreach($tree as $data) {
261        if(!$data['link']['hidden']) {
262          $link = $data['link'];
263          if (empty($link['localized_options'])) {
264            $link['localized_options'] = array();
265          }
266    
267          $link = l($link['title'], $link['href'], $link['localized_options']);
268          if($data['below']) {
269            $items[] = array(
270              'data' => $link,
271              'children' => simplemenu_compact_menu_tree($data['below']),
272            );
273          }
274          else {
275            $items[] = $link;
276          }
277        }
278      }
279      return $items;
280    }
281    
282    /**
283     * Render the necessary markup from the tree array. This is largely based on
284     * theme_item_list(), without the extra markup.
285     *
286     * @param $tree
287     *   Array of items as expected in theme_item_list().
288     */
289    function simplemenu_tree_output($items, $attributes = array()) {
290      if (!empty($items)) {
291        $output .= '<ul'. drupal_attributes($attributes) .'>';
292        $num_items = count($items);
293        foreach ($items as $i => $item) {
294          $attributes = array();
295          $children = array();
296          if (is_array($item)) {
297            foreach ($item as $key => $value) {
298              if ($key == 'data') {
299                $data = $value;
300              }
301              elseif ($key == 'children') {
302                $children = $value;
303              }
304              else {
305                $attributes[$key] = $value;
306              }
307            }
308          }
309          else {
310            $data = $item;
311          }
312          if (count($children) > 0) {
313            $data .= simplemenu_tree_output($children); // Render nested list
314            $attributes['class'] = empty($attributes['class']) ? 'expanded' : ($attributes['class'] .' expanded');
315          }
316          $output .= '<li'. drupal_attributes($attributes) .'>'. $data ."</li>\n";
317        }
318        $output .= "</ul>\n";
319      }
320      return $output;
321    }
322    
323    /**
324   * Modified menu_tree_all_data(), providing the complete menu tree below $root_menu   * Modified menu_tree_all_data(), providing the complete menu tree below $root_menu
325   * (which can be *any* menu item, not just the root of a custom menu).   * (which can be *any* menu item, not just the root of a custom menu).
326   *   *
# Line 323  function simplemenu_tree_all_data($root_ Line 382  function simplemenu_tree_all_data($root_
382  }  }
383    
384  /**  /**
385   * Return a list of devel module links if the module is enabled   * Implementation of hook_simplemenu_tree_alter().
  * and the user has access to this module.  
386   */   */
387  function simplemenu_get_devel() {  function simplemenu_simplemenu_tree_alter(&$tree) {
388    $output = '';    if (variable_get('simplemenu_devel', 0) && module_exists('devel') && user_access('access devel information')) {
389        $devel = array(
390          'data' => l(t('Devel module'), 'admin/settings/devel'),
391          'children' => simplemenu_menu_tree('devel:0'),
392        );
393    
394    if (variable_get('simplemenu_devel', 0) && module_exists('devel')) {      array_unshift($tree, $devel);
     if (user_access('access devel information')) {  
       $output = '<li class="expanded"><a href="'. url('admin/settings/devel') .'">'. t('Devel module') .'</a>';  
       $output .= simplemenu_menu_tree('devel');  
       $output .= '</li>';  
     }  
395    }    }
   
   return $output;  
396  }  }
397    
398  /**  /**

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.10.2.1

  ViewVC Help
Powered by ViewVC 1.1.2