| 1 |
<?php |
<?php |
| 2 |
//$Id: menutree.module,v 1.1 2007/01/06 23:05:45 crell Exp $ |
//$Id: menutree.module,v 1.2.2.8 2008/01/09 04:45:59 crell Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 13 |
|
|
| 14 |
/** |
/** |
| 15 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
|
* |
|
|
* Since we are limiting the ability to create new nodes to certain users, |
|
|
* we need to define what those permissions are here. We also define a permission |
|
|
* to allow users to edit the nodes they created. |
|
| 16 |
*/ |
*/ |
| 17 |
function menutree_perm() { |
function menutree_perm() { |
| 18 |
return array('view site tree'); |
return array('view site tree', 'administer menu tree'); |
| 19 |
} |
} |
| 20 |
|
|
| 21 |
/** |
/** |
| 22 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
|
* |
|
|
* In order for users to be able to add nodes of their own, we need to |
|
|
* give them a link to the node composition form here. |
|
| 23 |
*/ |
*/ |
| 24 |
function menutree_menu($may_cache) { |
function menutree_menu($may_cache) { |
| 25 |
$items = array(); |
$items = array(); |
| 27 |
if ($may_cache) { |
if ($may_cache) { |
| 28 |
$items[] = array( |
$items[] = array( |
| 29 |
'path' => 'menutree', |
'path' => 'menutree', |
| 30 |
'title' => t('sitemap'), |
'title' => t('Sitemap'), |
| 31 |
'access' => TRUE, |
'access' => user_access('view site tree'), |
| 32 |
'callback' => 'menutree_display', |
'callback' => 'menutree_display', |
| 33 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 34 |
); |
); |
| 35 |
|
$items[] = array( |
| 36 |
|
'path' => 'admin/build/menutree', |
| 37 |
|
'title' => t('Menu trees'), |
| 38 |
|
'description' => t('Configure page titles and intro text for menu tree pages.'), |
| 39 |
|
'access' => user_access('administer menu tree'), |
| 40 |
|
'callback' => 'drupal_get_form', |
| 41 |
|
'callback arguments' => 'menutree_settings', |
| 42 |
|
); |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
return $items; |
return $items; |
| 46 |
} |
} |
| 47 |
|
|
| 48 |
/** |
/** |
| 49 |
|
* Form builder; Display menutree settings form. |
| 50 |
|
*/ |
| 51 |
|
function menutree_settings() { |
| 52 |
|
$form = array(); |
| 53 |
|
|
| 54 |
|
$form['menutree'] = array('#tree' => FALSE); |
| 55 |
|
|
| 56 |
|
$menus = menu_get_root_menus(); |
| 57 |
|
foreach ($menus as $mid => $menu) { |
| 58 |
|
$open = trim(variable_get('menutree_title_'. $mid, '') . variable_get('menutree_intro_text_'. $mid, '')); |
| 59 |
|
|
| 60 |
|
$form['menutree'][$mid] = array( |
| 61 |
|
'#type' => 'fieldset', |
| 62 |
|
'#title' => $menu, |
| 63 |
|
'#collapsible' => TRUE, |
| 64 |
|
'#collapsed' => ($open ? FALSE : TRUE), |
| 65 |
|
'#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( |
| 66 |
|
'@link' => url('menutree/'. $mid), |
| 67 |
|
'@path' => 'menutree/'. $mid, |
| 68 |
|
)), |
| 69 |
|
); |
| 70 |
|
$form['menutree'][$mid]['menutree_title_'. $mid] = array( |
| 71 |
|
'#type' => 'textfield', |
| 72 |
|
'#title' => t('Page title'), |
| 73 |
|
'#default_value' => variable_get('menutree_title_'. $mid, ''), |
| 74 |
|
'#description' => t('A page title that is displayed instead of the root menu item title.'), |
| 75 |
|
); |
| 76 |
|
$form['menutree'][$mid]['menutree_intro_text_'. $mid] = array( |
| 77 |
|
'#type' => 'textarea', |
| 78 |
|
'#title' => t('Intro text'), |
| 79 |
|
'#default_value' => variable_get('menutree_intro_text_'. $mid, ''), |
| 80 |
|
'#resizable' => TRUE, |
| 81 |
|
'#description' => t('An intro text that is displayed below the page title.'), |
| 82 |
|
); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
return system_settings_form($form); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
/** |
| 89 |
* Display a fully-expanded version of the menu specified on the path |
* Display a fully-expanded version of the menu specified on the path |
| 90 |
* |
* |
| 91 |
* @param int $pid |
* @param int $pid |
| 92 |
* The menu to display. If none is specified, we default to the Primary Links menu |
* The menu to display. If none is specified, we default to the Primary Links menu |
| 93 |
*/ |
*/ |
| 94 |
function menutree_display($pid=0) { |
function menutree_display($pid = 0) { |
|
|
|
| 95 |
$output = ''; |
$output = ''; |
| 96 |
|
|
| 97 |
// Default to the Primary Links menu |
// Default to the Primary Links menu |
| 99 |
$pid = variable_get('menu_primary_menu', 0); |
$pid = variable_get('menu_primary_menu', 0); |
| 100 |
} |
} |
| 101 |
|
|
| 102 |
// This is a near-direct copy of menu_tree() from meu.inc. |
$menu = menu_get_item($pid); |
| 103 |
// The only difference is that we always call theme(menu_tree) on the item |
if (empty($menu)) { |
| 104 |
// rather than only if it's in the breadcrumb |
drupal_not_found(); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
$title = variable_get('menutree_title_'. $pid, ''); |
| 108 |
|
drupal_set_title(check_plain($title ? $title : $menu['title'])); |
| 109 |
|
$intro = variable_get('menutree_intro_text_'. $pid, ''); |
| 110 |
|
|
| 111 |
|
// Output custom intro text. |
| 112 |
|
if (!empty($intro)) { |
| 113 |
|
$output .= check_markup($intro, FILTER_FORMAT_DEFAULT, FALSE); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
$tree = theme('menutree_tree', $pid); |
| 117 |
|
$output .= theme('menutree_page', $tree); |
| 118 |
|
|
| 119 |
|
return $output; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
/** |
| 123 |
|
* Generate the HTML for a menu tree. |
| 124 |
|
* |
| 125 |
|
* @param $pid |
| 126 |
|
* The parent id of the menu. |
| 127 |
|
* |
| 128 |
|
* @ingroup themeable |
| 129 |
|
*/ |
| 130 |
|
function theme_menutree_tree($pid = 1) { |
| 131 |
|
if ($tree = menutree_tree($pid)) { |
| 132 |
|
return "\n<ul class=\"menu\">\n". $tree ."\n</ul>\n"; |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
/** |
| 137 |
|
* Returns a rendered menu tree. |
| 138 |
|
* |
| 139 |
|
* This is a near-direct copy of menu_tree() from menu.inc. |
| 140 |
|
* The only difference is that we always call theme(menutree_tree) on the item |
| 141 |
|
* rather than only if it's in the breadcrumb |
| 142 |
|
* |
| 143 |
|
* @param $pid |
| 144 |
|
* The parent id of the menu. |
| 145 |
|
*/ |
| 146 |
|
function menutree_tree($pid = 1) { |
| 147 |
$menu = menu_get_menu(); |
$menu = menu_get_menu(); |
| 148 |
|
$output = ''; |
| 149 |
|
|
| 150 |
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { |
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { |
| 151 |
foreach ($menu['visible'][$pid]['children'] as $mid) { |
foreach ($menu['visible'][$pid]['children'] as $mid) { |
| 152 |
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL; |
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL; |
| 153 |
$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL; |
$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL; |
| 154 |
$output .= theme('menu_item', $mid, theme('menu_tree', $mid), count($children) == 0); |
$output .= theme('menu_item', $mid, theme('menutree_tree', $mid), count($children) == 0); |
| 155 |
} |
} |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
return theme('menutree_page', '<ul class="menutree">' . $output . '</ul>'); |
return $output; |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
/** |
/** |
| 165 |
* |
* |
| 166 |
* @param string $output |
* @param string $output |
| 167 |
* The menutree, pre-rendered |
* The menutree, pre-rendered |
| 168 |
|
* @ingroup themeable |
| 169 |
*/ |
*/ |
| 170 |
function theme_menutree_page($output) { |
function theme_menutree_page($output) { |
| 171 |
|
|
| 172 |
return '<div class="menutree-page">' . $output . "</div>\n"; |
return '<div class="menutree-page">' . $output . "</div>\n"; |
| 173 |
|
|
| 174 |
} |
} |
| 175 |
|
|