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

Diff of /contributions/modules/menutree/menutree.module

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

revision 1.3, Wed Jan 9 05:20:03 2008 UTC revision 1.4, Tue Jan 22 02:56:59 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  //$Id: menutree.module,v 1.2.2.8 2008/01/09 04:45:59 crell Exp $  //$Id: menutree.module,v 1.3 2008/01/09 05:20:03 crell Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 10  Line 10 
10   *   *
11   */   */
12    
13    /**
14     * Implementation of hook_theme()
15     */
16    function menutree_theme() {
17      return array(
18        'menutree_page' => array('arguments' => array('output' => NULL)),
19        'menutree_tree' => array('arguments' => array('menu_name' => NULL)),
20      );
21    }
22    
23  /**  /**
24   * Implementation of hook_perm().   * Implementation of hook_perm().
# Line 21  function menutree_perm() { Line 30  function menutree_perm() {
30  /**  /**
31   * Implementation of hook_menu().   * Implementation of hook_menu().
32   */   */
33  function menutree_menu($may_cache) {  function menutree_menu() {
34    $items = array();    $items = array();
35      $items['menutree'] = array(
36    if ($may_cache) {      'title' => 'Sitemap',
37      $items[] = array(      'page callback' => 'menutree_display',
38        'path' => 'menutree',      'page arguments' => array(menu_load('primary-links')),
39        'title' => t('Sitemap'),      'access callback' => 'user_access',
40        'access' => user_access('view site tree'),      'access arguments' => array('view site tree'),
41        'callback' => 'menutree_display',      'type' => MENU_CALLBACK,
42        'type' => MENU_CALLBACK,    );
43      );    $items['menutree/%menu'] = array(
44      $items[] = array(      'title' => 'Sitemap',
45        'path' => 'admin/build/menutree',      'page arguments' => array(1),
46        'title' => t('Menu trees'),      'type' => MENU_CALLBACK,
47        'description' => t('Configure page titles and intro text for menu tree pages.'),    );
48        'access' => user_access('administer menu tree'),    $items['admin/build/menutree'] = array(
49        'callback' => 'drupal_get_form',      'title' => 'Menu trees',
50        'callback arguments' => 'menutree_settings',      'page callback' => 'drupal_get_form',
51      );      'page arguments' => array('menutree_settings'),
52    }      'description' => 'Configure page titles and intro text for menu tree pages.',
53        'access callback' => 'user_access',
54        'access arguments' => array('administer menu tree'),
55        'file' => 'menutree.admin.inc',
56      );
57    return $items;    return $items;
58  }  }
59    
60  /**  /**
  * Form builder; Display menutree settings form.  
  */  
 function menutree_settings() {  
   $form = array();  
   
   $form['menutree'] = array('#tree' => FALSE);  
   
   $menus = menu_get_root_menus();  
   foreach ($menus as $mid => $menu) {  
     $open = trim(variable_get('menutree_title_'. $mid, '') . variable_get('menutree_intro_text_'. $mid, ''));  
   
     $form['menutree'][$mid] = array(  
       '#type' => 'fieldset',  
       '#title' => $menu,  
       '#collapsible' => TRUE,  
       '#collapsed' => ($open ? FALSE : TRUE),  
       '#description' => t('The path <a href="@link">@path</a> will provide a complete tree of all menu items in this menu.  If you wish to set a custom title or header text, do so here.', array(  
         '@link' => url('menutree/'. $mid),  
         '@path' => 'menutree/'. $mid,  
       )),  
     );  
     $form['menutree'][$mid]['menutree_title_'. $mid] = array(  
       '#type' => 'textfield',  
       '#title' => t('Page title'),  
       '#default_value' => variable_get('menutree_title_'. $mid, ''),  
       '#description' => t('A page title that is displayed instead of the root menu item title.'),  
     );  
     $form['menutree'][$mid]['menutree_intro_text_'. $mid] = array(  
       '#type' => 'textarea',  
       '#title' => t('Intro text'),  
       '#default_value' => variable_get('menutree_intro_text_'. $mid, ''),  
       '#resizable' => TRUE,  
       '#description' => t('An intro text that is displayed below the page title.'),  
     );  
   }  
   
   return system_settings_form($form);  
 }  
   
 /**  
61   * Display a fully-expanded version of the menu specified on the path   * Display a fully-expanded version of the menu specified on the path
62   *   *
63   * @param int $pid   * @param $menu
64   *  The menu to display.  If none is specified, we default to the Primary Links menu   *  The menu to display.
65   */   */
66  function menutree_display($pid = 0) {  function menutree_display($menu) {
67    $output = '';    $output = '';
68    
69    // Default to the Primary Links menu    $title = variable_get('menutree_title_'. $menu['menu_name'], '');
70    if (!$pid) {    drupal_set_title(check_plain(!empty($title) ? $title : $menu['title']));
     $pid = variable_get('menu_primary_menu', 0);  
   }  
   
   $menu = menu_get_item($pid);  
   if (empty($menu)) {  
     drupal_not_found();  
   }  
   
   $title = variable_get('menutree_title_'. $pid, '');  
   drupal_set_title(check_plain($title ? $title : $menu['title']));  
   $intro = variable_get('menutree_intro_text_'. $pid, '');  
71    
72    // Output custom intro text.    // Output custom intro text.
73      $intro = variable_get('menutree_intro_text_'. $menu['menu_name'], '');
74    if (!empty($intro)) {    if (!empty($intro)) {
75      $output .= check_markup($intro, FILTER_FORMAT_DEFAULT, FALSE);      $output .= check_markup($intro, FILTER_FORMAT_DEFAULT, FALSE);
76    }    }
77    
78    $tree = theme('menutree_tree', $pid);    $tree = menu_tree_output(menu_tree_all_data($menu['menu_name']));
79    $output .= theme('menutree_page', $tree);    $output .= theme('menutree_page', $tree);
   
   return $output;  
 }  
   
 /**  
  * Generate the HTML for a menu tree.  
  *  
  * @param $pid  
  *   The parent id of the menu.  
  *  
  * @ingroup themeable  
  */  
 function theme_menutree_tree($pid = 1) {  
   if ($tree = menutree_tree($pid)) {  
     return "\n<ul class=\"menu\">\n". $tree ."\n</ul>\n";  
   }  
 }  
   
 /**  
  * Returns a rendered menu tree.  
  *  
  * This is a near-direct copy of menu_tree() from menu.inc.  
  * The only difference is that we always call theme(menutree_tree) on the item  
  * rather than only if it's in the breadcrumb  
  *  
  * @param $pid  
  *   The parent id of the menu.  
  */  
 function menutree_tree($pid = 1) {  
   $menu = menu_get_menu();  
   $output = '';  
   
   if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {  
     foreach ($menu['visible'][$pid]['children'] as $mid) {  
       $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;  
       $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;  
       $output .= theme('menu_item', $mid, theme('menutree_tree', $mid), count($children) == 0);  
     }  
   }  
80    
81    return $output;    return $output;
82  }  }
# Line 165  function menutree_tree($pid = 1) { Line 88  function menutree_tree($pid = 1) {
88   *   *
89   * @param string $output   * @param string $output
90   *  The menutree, pre-rendered   *  The menutree, pre-rendered
91     *
92   * @ingroup themeable   * @ingroup themeable
93   */   */
94  function theme_menutree_page($output) {  function theme_menutree_page($output) {
95      return '<div class="menutree-page">'. $output ."</div>\n";
   return '<div class="menutree-page">' . $output . "</div>\n";  
   
96  }  }
97    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2