| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: site_map.module,v 1.39.2.17.2.10 2010/07/11 17:49:10 frjo Exp $ 3 4 /** 5 * @file site_map.module 6 * 7 * Original author: Nic Ivy 8 * Now maintained by Fredrik Jonsson fredrik at combonet dot se 9 */ 10 11 /** 12 * Implementation of hook_perm(). 13 */ 14 function site_map_perm() { 15 return array('access site map'); 16 } 17 18 /** 19 * Implementation of hook_theme(). 20 */ 21 function site_map_theme() { 22 return array( 23 'site_map' => array( 24 'arguments' => array(), 25 'template' => 'site-map', 26 'file' => 'site_map.theme.inc', 27 ), 28 'site_map_box' => array( 29 'arguments' => array('title' => NULL, 'content' => NULL, 'class' => NULL), 30 'file' => 'site_map.theme.inc', 31 ), 32 'site_map_feed_icon' => array( 33 'arguments' => array('url' => NULL, 'type' => 'node'), 34 'file' => 'site_map.theme.inc', 35 ), 36 'site_map_menu_tree' => array( 37 'arguments' => array('tree' => NULL), 38 'file' => 'site_map.theme.inc', 39 ), 40 'site_map_menu_item' => array( 41 'arguments' => array('link' => NULL, 'has_children' => NULL, 'menu' => NULL), 42 'file' => 'site_map.theme.inc', 43 ), 44 'site_map_rss_legend' => array( 45 'arguments' => array(), 46 'file' => 'site_map.theme.inc', 47 ), 48 ); 49 } 50 51 /** 52 * Implementation of hook_menu(). 53 */ 54 function site_map_menu() { 55 $items['admin/settings/sitemap'] = array( 56 'title' => 'Site map', 57 'description' => 'Control what should be displayed on the site map.', 58 'page callback' => 'drupal_get_form', 59 'page arguments' => array('site_map_admin_settings'), 60 'access arguments' => array('administer site configuration'), 61 'file' => 'site_map.admin.inc', 62 'type' => MENU_NORMAL_ITEM, 63 ); 64 $items['sitemap'] = array( 65 'title' => 'Site map', 66 'description' => 'Display a site map with RSS feeds.', 67 'page callback' => 'site_map_page', 68 'access arguments' => array('access site map'), 69 'type' => MENU_SUGGESTED_ITEM, 70 ); 71 72 return $items; 73 } 74 75 /** 76 * Implementation of hook_block(). 77 */ 78 function site_map_block($op = 'list', $delta = 0) { 79 if ($op == 'list') { 80 $blocks[0]['info'] = t('Syndicate (site map)'); 81 return $blocks; 82 } 83 elseif ($op == 'view') { 84 if (user_access('access content')) { 85 $block['subject'] = t('Syndicate'); 86 if (arg(0) == 'blog') { 87 $uid = arg(1); 88 $feedurl = is_numeric($uid) ? "blog/$uid/feed" : 'blog/feed'; 89 } 90 else { 91 $feedurl = variable_get('site_map_rss_front', 'rss.xml'); 92 } 93 $block['content'] = theme('feed_icon', url($feedurl), t('Syndicate')); 94 $block['content'] .= '<div class="more-link">'. l(t('more'), 'sitemap', array('title' => t('View the site map to see more RSS feeds.'))) ."</div>\n"; 95 96 return $block; 97 } 98 } 99 } 100 101 /** 102 * Menu callback for the site map. 103 */ 104 function site_map_page() { 105 drupal_set_title(check_plain(variable_get('site_map_page_title', t('Site map')))); 106 107 if (variable_get('site_map_css', 0) != 1) { 108 drupal_add_css(drupal_get_path('module', 'site_map') .'/site_map.css'); 109 } 110 111 return theme('site_map'); 112 } 113 114 function _site_map_front_page() { 115 $output = ''; 116 $class = ''; 117 $title = t('Front page'); 118 $output = l(t("Front page of %sn", array("%sn" => variable_get('site_name', 'Drupal'))), '<front>', array('html' => TRUE)); 119 120 if (variable_get('site_map_show_rss_links', 1) != 0) { 121 $rss_link = theme('site_map_feed_icon', variable_get('site_map_rss_front', 'rss.xml')); 122 if (module_exists('commentrss') && variable_get('commentrss_site', COMMENTRSS_SITE_FRONT_PAGE)) { 123 $rss_link .= ' '. theme('site_map_feed_icon', 'crss', 'comment'); 124 } 125 if (variable_get('site_map_show_rss_links', 1) == 1) { 126 $output .= ' '. $rss_link; 127 } 128 else { 129 $class = ' site-map-rss-left'; 130 $output = $rss_link .' '. $output; 131 } 132 } 133 134 return theme('site_map_box', $title, $output, 'site-map-front-box'. $class); 135 } 136 137 /** 138 * Render the latest blog authors 139 */ 140 function _site_map_blogs() { 141 $output = ''; 142 $class = ''; 143 if (module_exists('blog')) { 144 $title = t('Blogs'); 145 $output = '<div class="description">'. t("Community blog and recent blog authors at %sn.", array("%sn" => variable_get('site_name', 'Drupal'))) .'</div>'; 146 147 $blog_link = l(t('All blogs'), 'blog'); 148 if (variable_get('site_map_show_rss_links', 1) != 0) { 149 $rss_link = theme('site_map_feed_icon', 'blog/feed'); 150 if (variable_get('site_map_show_rss_links', 1) == 1) { 151 $blog_link .= ' '. $rss_link; 152 } 153 else { 154 $class = ' site-map-rss-left'; 155 $blog_link = $rss_link .' '. $blog_link; 156 } 157 } 158 $blogs = array(); 159 $blogs[] = $blog_link; 160 161 $sql = "SELECT DISTINCT u.uid, u.name, count(u.uid) AS numitems 162 FROM {node} n 163 INNER JOIN {users} u ON u.uid = n.uid 164 WHERE n.type = 'blog' AND n.status = 1 165 GROUP BY u.uid, u.name 166 ORDER BY numitems DESC, u.name"; 167 $result = db_query_range($sql, 0, 10); 168 while ($blog = db_fetch_object($result)) { 169 $blog_item = l(t("!s's blog", array("!s" => $blog->name)), "blog/$blog->uid") .' ('. $blog->numitems .')'; 170 if (variable_get('site_map_show_rss_links', 1) != 0) { 171 $rss_link = theme('site_map_feed_icon', "blog/$blog->uid/feed"); 172 if (variable_get('site_map_show_rss_links', 1) == 1) { 173 $blog_item .= ' '. $rss_link; 174 } 175 else { 176 $blog_item = $rss_link .' '. $blog_item; 177 } 178 } 179 $blogs[] = $blog_item; 180 } 181 $output .= theme('item_list', $blogs); 182 $output = theme('site_map_box', $title, $output, 'site-map-blog-box'. $class); 183 } 184 185 return $output; 186 } 187 188 function _site_map_audio() { 189 $output = ''; 190 $class = ''; 191 if (module_exists('audio')) { 192 $title = t('Audio'); 193 $output = l(t('Audio content'), 'audio'); 194 if (variable_get('site_map_show_rss_links', 1) != 0) { 195 $rss_link = theme('site_map_feed_icon', 'audio/feed'); 196 if (variable_get('site_map_show_rss_links', 1) == 1) { 197 $output .= ' '. $rss_link; 198 } 199 else { 200 $class = ' site-map-rss-left'; 201 $output = $rss_link .' '. $output; 202 } 203 } 204 $output = theme('site_map_box', $title, $output, 'site-map-audio-box'. $class); 205 } 206 207 return $output; 208 } 209 210 function _site_map_video() { 211 $output = ''; 212 $class = ''; 213 if (module_exists('video')) { 214 $title = t('Video'); 215 $output = l(t('Video content'), 'video'); 216 if (variable_get('site_map_show_rss_links', 1) != 0) { 217 $rss_link = theme('site_map_feed_icon', 'video/feed'); 218 if (variable_get('site_map_show_rss_links', 1) == 1) { 219 $output .= ' '. $rss_link; 220 } 221 else { 222 $class = ' site-map-rss-left'; 223 $output = $rss_link .' '. $output; 224 } 225 } 226 $output = theme('site_map_box', $title, $output, 'site-map-video-box'. $class); 227 } 228 229 return $output; 230 } 231 232 /** 233 * Render books 234 */ 235 function _site_map_books() { 236 $output = ''; 237 $nids = array_filter(variable_get('site_map_show_books', array())); 238 239 if (module_exists('book') && !empty($nids)) { 240 $title = t('Books'); 241 $description = '<div class="description">'. t("Books at %sn.", array("%sn" => variable_get('site_name', 'Drupal'))) .'</div>'; 242 243 $book_menus = array(); 244 foreach ($nids as $nid) { 245 $node = node_load($nid); 246 $tree = menu_tree_all_data($node->book['menu_name']); 247 $data = array_shift($tree); 248 $output .= theme('book_title_link', $data['link']); 249 $output .= ($data['below']) ? _site_map_menu_tree_output($data['below']) : ''; 250 } 251 252 if (!empty($output)) { 253 $output = theme('site_map_box', $title, $description . $output, 'site-map-book-box'); 254 } 255 } 256 257 return $output; 258 } 259 260 /** 261 * Render menus 262 */ 263 function _site_map_menus() { 264 $output = ''; 265 $mids = array_filter(variable_get('site_map_show_menus', array())); 266 267 if (!empty($mids)) { 268 foreach ($mids as $mid) { 269 $menu = menu_load($mid); 270 // Use menu_tree_all_data to retrieve the expanded tree. 271 $tree = menu_tree_all_data($mid); 272 if (module_exists('i18nmenu')) { 273 i18nmenu_localize_tree($tree); 274 } 275 $menu_display = _site_map_menu_tree_output($tree); 276 if (!empty($menu_display)) { 277 $title = $menu['title']; 278 $output .= theme('site_map_box', $title, $menu_display, 'site-map-menu-box'); 279 } 280 } 281 } 282 283 return $output; 284 } 285 286 function _site_map_faq() { 287 $output = ''; 288 if (module_exists('faq')) { 289 $title = variable_get('faq_title', t('Frequently Asked Questions')); 290 $output = faq_get_faq_list(); 291 $output = theme('site_map_box', $title, $output, 'site-map-faq-box'); 292 } 293 294 return $output; 295 } 296 297 /** 298 * This function can be called from blocks or pages as desired. 299 */ 300 function _site_map_taxonomys() { 301 $output = ''; 302 $vids = array_filter(variable_get('site_map_show_vocabularies', array())); 303 304 if (module_exists('taxonomy') && !empty($vids)) { 305 $result = db_query('SELECT vid, name, description FROM {vocabulary} WHERE vid IN ('. db_placeholders($vids, 'int') .') ORDER BY weight ASC, name', $vids); 306 while ($t = db_fetch_object($result)) { 307 if (module_exists('i18ntaxonomy')) { 308 $t->name = tt("taxonomy:vocabulary:$t->vid:name", $t->name); 309 } 310 $output .= _site_map_taxonomy_tree($t->vid, $t->name, $t->description); 311 } 312 } 313 314 return $output; 315 } 316 317 /** 318 * Render taxonomy tree 319 * 320 * @param $tree The results of taxonomy_get_tree() with optional 'count' fields. 321 * @param $name An optional name for the tree. (Default: NULL) 322 * @param $description An optional description of the tree. (Default: NULL) 323 * @return A string representing a rendered tree. 324 */ 325 function _site_map_taxonomy_tree($vid, $name = NULL, $description = NULL) { 326 $output = ''; 327 $class = ''; 328 if ($vid == variable_get('forum_nav_vocabulary', '')) { 329 $title = l($name, 'forum'); 330 $threshold = variable_get('site_map_forum_threshold', -1); 331 $forum_link = TRUE; 332 } 333 else { 334 $title = $name ? check_plain(t($name)) : ''; 335 $threshold = variable_get('site_map_term_threshold', 0); 336 $forum_link = FALSE; 337 } 338 $title .= (module_exists('commentrss') && variable_get('commentrss_term', FALSE) ? ' '. theme('site_map_feed_icon', "crss/vocab/$vid", 'comment') : ''); 339 340 $last_depth = -1; 341 $rss_depth = variable_get('site_map_rss_depth', 'all'); 342 if (!is_numeric($rss_depth) || $rss_depth < 0) { 343 $rss_depth = 'all'; 344 } 345 $cat_depth = variable_get('site_map_categories_depth', 'all'); 346 if (!is_numeric($cat_depth)) { 347 $cat_depth = 'all'; 348 } 349 350 $output .= !empty($description) ? '<div class="taxonomy-term-description">'. filter_xss_admin($description) ."</div>\n" : ''; 351 352 // taxonomy_get_tree() honors access controls 353 $tree = taxonomy_get_tree($vid); 354 foreach ($tree as $term) { 355 $term->count = taxonomy_term_count_nodes($term->tid); 356 if ($term->count <= $threshold) { 357 continue; 358 } 359 360 if (module_exists('i18ntaxonomy')) { 361 $term->name = tt("taxonomy:term:$term->tid:name", $term->name); 362 } 363 364 // Adjust the depth of the <ul> based on the change 365 // in $term->depth since the $last_depth. 366 if ($term->depth > $last_depth) { 367 for ($i = 0; $i < ($term->depth - $last_depth); $i++) { 368 $output .= "\n<ul>"; 369 } 370 } 371 elseif ($term->depth == $last_depth) { 372 $output .= '</li>'; 373 } 374 elseif ($term->depth < $last_depth) { 375 for ($i = 0; $i < ($last_depth - $term->depth); $i++) { 376 $output .= "</li>\n</ul>\n</li>"; 377 } 378 } 379 // Display the $term. 380 $output .= "\n<li>"; 381 $term_item = ''; 382 if ($forum_link) { 383 $term_item .= l($term->name, 'forum/'. $term->tid, array('attributes' => array('title' => $term->description))); 384 } 385 elseif ($term->count) { 386 $term_item .= l($term->name, ($cat_depth < 0) ? taxonomy_term_path($term) : "taxonomy/term/$term->tid/$cat_depth", array('attributes' => array('title' => $term->description))); 387 } 388 else { 389 $term_item .= check_plain($term->name); 390 } 391 if (variable_get('site_map_show_count', 1)) { 392 $term_item .= " ($term->count)"; 393 } 394 395 if (variable_get('site_map_show_rss_links', 1) != 0) { 396 $rss_link = theme('site_map_feed_icon', "taxonomy/term/$term->tid/$rss_depth/feed"); 397 if (module_exists('commentrss') && variable_get('commentrss_term', FALSE)) { 398 $rss_link .= ' '. theme('site_map_feed_icon', "crss/term/$term->tid", 'comment'); 399 } 400 if (variable_get('site_map_show_rss_links', 1) == 1) { 401 $term_item .= ' '. $rss_link; 402 } 403 else { 404 $class = ' site-map-rss-left'; 405 $term_item = $rss_link .' '. $term_item; 406 } 407 } 408 409 $output .= $term_item; 410 411 // Reset $last_depth in preparation for the next $term. 412 $last_depth = $term->depth; 413 } 414 415 // Bring the depth back to where it began, -1. 416 if ($last_depth > -1) { 417 for ($i = 0; $i < ($last_depth + 1); $i++) { 418 $output .= "</li>\n</ul>\n"; 419 } 420 } 421 $output = theme('site_map_box', $title, $output, 'site-map-terms-box site-map-terms-box-'. $vid . $class); 422 423 return $output; 424 } 425 426 /** 427 * This is a clone of the core menu_tree_output() function with the exception 428 * of theme('site_map_menu_tree') for theming override reasons. 429 * 430 * Returns a rendered menu tree. 431 * 432 * @param $tree 433 * A data structure representing the tree as returned from menu_tree_data. 434 * @return 435 * The rendered HTML of that data structure. 436 */ 437 function _site_map_menu_tree_output($tree) { 438 $output = ''; 439 $items = array(); 440 441 // Pull out just the menu items we are going to render so that we 442 // get an accurate count for the first/last classes. 443 foreach ($tree as $data) { 444 if (!$data['link']['hidden']) { 445 $items[] = $data; 446 } 447 } 448 449 $num_items = count($items); 450 foreach ($items as $i => $data) { 451 $extra_class = NULL; 452 if ($i == 0) { 453 $extra_class = 'first'; 454 } 455 if ($i == $num_items - 1) { 456 $extra_class = 'last'; 457 } 458 $link = theme('menu_item_link', $data['link']); 459 if ($data['below']) { 460 $output .= theme('site_map_menu_item', $link, $data['link']['has_children'], _site_map_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class); 461 } 462 else { 463 $output .= theme('site_map_menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class); 464 } 465 } 466 return $output ? theme('site_map_menu_tree', $output) : ''; 467 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |