| 1 |
<?php |
<?php |
| 2 |
//$Id: menutree.module,v 1.2.2.7 2008/01/09 04:41:46 crell Exp $ |
//$Id: menutree.module,v 1.2.2.8 2008/01/09 04:45:59 crell Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 10 |
* |
* |
| 11 |
*/ |
*/ |
| 12 |
|
|
| 13 |
|
/** |
| 14 |
|
* Page title handling option constant definitions. |
| 15 |
|
*/ |
| 16 |
|
|
| 17 |
|
/** |
| 18 |
|
* Display the menu title as the page title. |
| 19 |
|
*/ |
| 20 |
|
define('MENUTREE_TITLE_PAGE', 0x0001); |
| 21 |
|
|
| 22 |
|
/** |
| 23 |
|
* Display the menu title inline in the body of the page. |
| 24 |
|
*/ |
| 25 |
|
define('MENUTREE_TITLE_BODY', 0x0002); |
| 26 |
|
|
| 27 |
|
|
| 28 |
/** |
/** |
| 29 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 43 |
'path' => 'menutree', |
'path' => 'menutree', |
| 44 |
'title' => t('Sitemap'), |
'title' => t('Sitemap'), |
| 45 |
'access' => user_access('view site tree'), |
'access' => user_access('view site tree'), |
| 46 |
'callback' => 'menutree_display', |
'callback' => 'menutree_display_page', |
| 47 |
|
'type' => MENU_CALLBACK, |
| 48 |
|
); |
| 49 |
|
$items[] = array( |
| 50 |
|
'path' => 'menutree/all', |
| 51 |
|
'title' => t('Sitemap'), |
| 52 |
|
'access' => user_access('view site tree'), |
| 53 |
|
'callback' => 'menutree_display_all', |
| 54 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 55 |
); |
); |
| 56 |
$items[] = array( |
$items[] = array( |
| 74 |
|
|
| 75 |
$form['menutree'] = array('#tree' => FALSE); |
$form['menutree'] = array('#tree' => FALSE); |
| 76 |
|
|
| 77 |
|
// This really should be array_combine, but that's not PHP 4 compatible. |
| 78 |
|
$items = array_merge(array('<none>'), range(-10, 10)); |
| 79 |
|
$weights = array(); |
| 80 |
|
foreach ($items as $item) { |
| 81 |
|
$weights[$item] = $item; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
$menus = menu_get_root_menus(); |
$menus = menu_get_root_menus(); |
| 85 |
foreach ($menus as $mid => $menu) { |
foreach ($menus as $mid => $menu) { |
| 86 |
$open = trim(variable_get('menutree_title_'. $mid, '') . variable_get('menutree_intro_text_'. $mid, '')); |
$open = trim(variable_get('menutree_title_'. $mid, '') . variable_get('menutree_intro_text_'. $mid, '')); |
| 108 |
'#resizable' => TRUE, |
'#resizable' => TRUE, |
| 109 |
'#description' => t('An intro text that is displayed below the page title.'), |
'#description' => t('An intro text that is displayed below the page title.'), |
| 110 |
); |
); |
| 111 |
|
$form['menutree'][$mid]['menutree_all_weight_'. $mid] = array( |
| 112 |
|
'#type' => 'select', |
| 113 |
|
'#title' => t('Order in main index'), |
| 114 |
|
'#options' => $weights, |
| 115 |
|
'#default_value' => variable_get('menutree_all_weight_'. $mid, '<none>'), |
| 116 |
|
'#description' => t('The path <a href="@link">@path</a> will provide multiple menu trees on a single page. You can specify which and in what order here. Set the weight to "<none>" to exclude this menu.', array( |
| 117 |
|
'@link' => url('menutree/all'), |
| 118 |
|
'@path' => 'menutree/all', |
| 119 |
|
)), |
| 120 |
|
); |
| 121 |
} |
} |
| 122 |
|
|
| 123 |
return system_settings_form($form); |
return system_settings_form($form); |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
/** |
/** |
| 127 |
|
* Menu callback; Display a fully-expanded version of all flagged menus. |
| 128 |
|
* |
| 129 |
|
*/ |
| 130 |
|
function menutree_display_all() { |
| 131 |
|
|
| 132 |
|
$trees = array(); |
| 133 |
|
|
| 134 |
|
$roots = menu_get_root_menus(); |
| 135 |
|
foreach (array_keys($roots) as $pid) { |
| 136 |
|
if (($weight = variable_get('menutree_all_weight_'. $pid, '<none>')) !== '<none>') { |
| 137 |
|
$trees[$weight] = menutree_display($pid, MENUTREE_TITLE_BODY); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
ksort($trees); |
| 142 |
|
|
| 143 |
|
return implode($trees); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
/** |
| 147 |
|
* Menu callback; Display a menu tree for a single specified menu. |
| 148 |
|
* |
| 149 |
|
* @param $pid |
| 150 |
|
* The menu to display. If none is specified, we default to the Primary Links menu. |
| 151 |
|
*/ |
| 152 |
|
function menutree_display_page($pid = 0) { |
| 153 |
|
return menutree_display($pid, MENUTREE_TITLE_PAGE); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
/** |
| 157 |
* Display a fully-expanded version of the menu specified on the path |
* Display a fully-expanded version of the menu specified on the path |
| 158 |
* |
* |
| 159 |
* @param int $pid |
* @param $pid |
| 160 |
* 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. |
| 161 |
|
* @param $title_display |
| 162 |
|
* How to handle the display of the title. This is a bitmask that can take |
| 163 |
|
* multiple values. |
| 164 |
|
* - MENUTREE_TITLE_PAGE: Set the title of this menu as the page title. |
| 165 |
|
* - MENUTREE_TITLE_BODY: Include the title of the menu in the body of the page. |
| 166 |
*/ |
*/ |
| 167 |
function menutree_display($pid = 0) { |
function menutree_display($pid = 0, $title_display = MENUTREE_TITLE_PAGE) { |
| 168 |
$output = ''; |
$output = ''; |
| 169 |
|
|
| 170 |
// Default to the Primary Links menu |
// Default to the Primary Links menu |
| 177 |
drupal_not_found(); |
drupal_not_found(); |
| 178 |
} |
} |
| 179 |
|
|
| 180 |
$title = variable_get('menutree_title_'. $pid, ''); |
$title = variable_get('menutree_title_'. $pid, $menu['title']); |
| 181 |
drupal_set_title(check_plain($title ? $title : $menu['title'])); |
$title = check_plain($title); |
| 182 |
$intro = variable_get('menutree_intro_text_'. $pid, ''); |
|
| 183 |
|
if ($title_display & MENUTREE_TITLE_PAGE) { |
| 184 |
|
drupal_set_title($title); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
$tree_title = ''; |
| 188 |
|
if ($title_display & MENUTREE_TITLE_BODY) { |
| 189 |
|
$tree_title = $title; |
| 190 |
|
} |
| 191 |
|
|
| 192 |
// Output custom intro text. |
// Output custom intro text. |
| 193 |
|
$intro = variable_get('menutree_intro_text_'. $pid, ''); |
| 194 |
|
$description = ''; |
| 195 |
if (!empty($intro)) { |
if (!empty($intro)) { |
| 196 |
$output .= check_markup($intro, FILTER_FORMAT_DEFAULT, FALSE); |
$description = check_markup($intro, FILTER_FORMAT_DEFAULT, FALSE); |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
$tree = theme('menutree_tree', $pid); |
$tree = theme('menutree_tree', $pid); |
|
$output .= theme('menutree_page', $tree); |
|
| 200 |
|
|
| 201 |
return $output; |
return theme('menutree_page', $tree_title, $description, $tree); |
| 202 |
} |
} |
| 203 |
|
|
| 204 |
/** |
/** |
| 241 |
} |
} |
| 242 |
|
|
| 243 |
/** |
/** |
| 244 |
* Theme the menutree |
* Theme the menutree. |
| 245 |
* |
* |
| 246 |
* In practice this is already themed into lists, so this just wraps it in a div |
* @param string $title |
| 247 |
* |
* The title of this tree, if any. |
| 248 |
* @param string $output |
* @param $description |
| 249 |
* The menutree, pre-rendered |
* The descriptive intro text for this tree, if any. |
| 250 |
|
* @param $tree |
| 251 |
|
* The pre-rendered menu tree itself. |
| 252 |
* @ingroup themeable |
* @ingroup themeable |
| 253 |
*/ |
*/ |
| 254 |
function theme_menutree_page($output) { |
function theme_menutree_page($title, $description, $tree) { |
| 255 |
|
|
| 256 |
|
$output = ''; |
| 257 |
|
|
| 258 |
|
if ($title) { |
| 259 |
|
$output .= '<h3>'. $title ."</h3>\n"; |
| 260 |
|
} |
| 261 |
|
if ($description) { |
| 262 |
|
$output .= '<div class="menutree-description">'. $description ."</div>\n"; |
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
$output .= $tree; |
| 266 |
|
|
|
return '<div class="menutree-page">' . $output . "</div>\n"; |
|
| 267 |
|
|
| 268 |
|
return '<div class="menutree-page">' . $output . "</div>\n"; |
| 269 |
} |
} |
| 270 |
|
|