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

Contents of /contributions/modules/site_map/site_map.module

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


Revision 1.39 - (show annotations) (download) (as text)
Tue May 27 19:41:00 2008 UTC (18 months ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.38: +2 -2 lines
File MIME type: text/x-php
Added missing argument to theme_feed_icon(), thanks dmoore. See issue #177918
1 <?php
2 // $Id: site_map.module,v 1.38 2008/01/08 11:21:48 frjo Exp $
3
4 /**
5 * @file
6 * Original author: Nic Ivy
7 * Now maintained by by Fredrik Jonsson fredrik at combonet dot se
8 */
9
10 /**
11 * Implementation of hook_help().
12 */
13 function site_map_help($path, $arg) {
14 switch ($path) {
15 case 'sitemap':
16 $output = variable_get('site_map_message', '');
17 return $output ? '<p>'. $output .'</p>' : '';
18 }
19 }
20
21 /**
22 * Implementation of hook_perm().
23 */
24 function site_map_perm() {
25 return array('access site map');
26 }
27
28 /**
29 * Implementation of hook_theme().
30 */
31 function site_map_theme() {
32 return array(
33 'site_map_display' => array(
34 'arguments' => array(),
35 ),
36 'site_map_feed_icon' => array(
37 'arguments' => array('url' => NULL, 'type' => 'node'),
38 ),
39 );
40 }
41
42 /**
43 * Implementation of hook_menu().
44 */
45 function site_map_menu() {
46 $items['admin/settings/sitemap'] = array(
47 'title' => 'Site map',
48 'description' => 'Control what should be displayed on the site map.',
49 'page callback' => 'drupal_get_form',
50 'page arguments' => array('site_map_admin_settings'),
51 'access arguments' => array('administer site configuration'),
52 'file' => 'site_map.admin.inc',
53 'type' => MENU_NORMAL_ITEM,
54 );
55 $items['sitemap'] = array(
56 'title' => 'Site map',
57 'description' => 'Display a site map with RSS feeds.',
58 'page callback' => 'site_map_page',
59 'access arguments' => array('access site map'),
60 'type' => MENU_SUGGESTED_ITEM,
61 );
62
63 return $items;
64 }
65
66 /**
67 * Implementation of hook_block().
68 */
69 function site_map_block($op = 'list', $delta = 0) {
70 if ($op == 'list') {
71 $blocks[0]['info'] = t('Syndicate (site map)');
72 return $blocks;
73 }
74 else if ($op == 'view') {
75 if (user_access('access content')) {
76 $block['subject'] = t('Syndicate');
77 if (arg(0) == 'blog') {
78 $uid = arg(1);
79 $feedurl = is_numeric($uid) ? "blog/$uid/feed" : 'blog/feed';
80 }
81 else {
82 $feedurl = 'rss.xml';
83 }
84 $block['content'] = theme('feed_icon', url($feedurl), t('Syndicate'));
85 $block['content'] .= '<div class="more-link">'. l(t('more'), 'sitemap', array('title' => t('View the site map to see more RSS feeds.'))) ."</div>\n";
86
87 return $block;
88 }
89 }
90 }
91
92 /**
93 * Menu callback for the site map.
94 */
95 function site_map_page() {
96 // Set breadcrumbs
97 $breadcrumb = array(array('path' => 'sitemap'));
98 //menu_set_location($breadcrumb);
99
100 return theme('site_map_display');
101 }
102
103 function theme_site_map_display() {
104 $output = '';
105
106 if (variable_get('site_map_show_rss_links', 1)) {
107 $output .= '<p><span class="rss">'. theme('site_map_feed_icon', NULL) .'</span> '. t('This is a link to a content RSS feed');
108 if (module_exists('commentrss')) {
109 $output .= '<br /><span class="rss">'. theme('site_map_feed_icon', NULL, 'comment') .'</span> '. t('This is a link to a comment RSS feed');
110 }
111 $output .= '</p>';
112 }
113
114 if (variable_get('site_map_show_front', 1)) {
115 $output .= _site_map_front_page();
116 }
117
118 if (variable_get('site_map_show_blogs', 1)) {
119 $output .= _site_map_blogs();
120 }
121
122 /* $output .= _site_map_audio(); */
123
124 /* $output .= _site_map_video(); */
125
126 // Compile the books trees.
127 $output .= _site_map_books();
128
129 // Compile the menu trees.
130 $output .= _site_map_menus();
131
132 if (variable_get('site_map_show_faq', 1)) {
133 $output .= _site_map_faq();
134 }
135
136 // Compile the vocabulary trees.
137 $output .= _site_map_taxonomys();
138
139 // Invoke all custom modules and get themed HTML to be integrated into the site map.
140 $additional = module_invoke_all('site_map');
141 foreach ($additional as $themed_site_map_code) {
142 $output .= $themed_site_map_code;
143 }
144
145 $output = '<div class="site-map">'. $output .'</div>';
146
147 return $output;
148 }
149
150 function theme_site_map_feed_icon($url, $type = 'node') {
151 $output = '';
152
153 switch ($type) {
154 case 'node':
155 $output = theme('image', (drupal_get_path('module', 'site_map') .'/feed-small.png'), t('Syndicate content'), t('Syndicate content'));
156 if ($url) {
157 $output = '<a href="'. check_url($url) .'" class="feed-link">'. $output .'</a>';
158 }
159 break;
160 case 'comment':
161 $output = theme('image', (drupal_get_path('module', 'site_map') .'/feed-small-comment.png'), t('Syndicate comments'), t('Syndicate comments'));
162 if ($url) {
163 $output = '<a href="'. check_url($url) .'" class="feed-link">'. $output .'</a>';
164 }
165 break;
166 }
167
168 return $output;
169 }
170
171 function _site_map_front_page() {
172 $title = t('Front page');
173 $output = l(t("Front page of %sn", array("%sn" => variable_get('site_name', 'Drupal'))), '<front>', array('html' => TRUE)) . (variable_get('site_map_show_rss_links', 1) ? ' '. theme('site_map_feed_icon', url('rss.xml')) . (module_exists('commentrss') ? ' '. theme('site_map_feed_icon', url('crss'), 'comment') : '') : '');
174 $output = theme('box', $title, $output);
175
176 return $output;
177 }
178
179 /**
180 * Render the latest blog authors
181 */
182 function _site_map_blogs() {
183 $output = '';
184 if (module_exists('blog')) {
185 $title = t('Blogs');
186 $output = '<div class="description">'. t("Community blog and recent blog authors at %sn.", array("%sn" => variable_get('site_name', 'Drupal'))) .'</div>';
187
188 $blogs = array();
189 $blogs[] .= l(t('All blogs'), 'blog') . (variable_get('site_map_show_rss_links', 1) ? ' '. theme('site_map_feed_icon', url('blog/feed')) : '');
190 $result = db_query_range("SELECT DISTINCT u.uid, u.name
191 FROM {users} u
192 INNER JOIN {node} n ON u.uid = n.uid
193 WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC", 0, 10);
194 while ($account = db_fetch_object($result)) {
195 $blogs[] = l(t("!s's blog", array("!s" => $account->name)), "blog/$account->uid") . (variable_get('site_map_show_rss_links', 1) ? ' '. theme('site_map_feed_icon', url("blog/$account->uid/feed")) : '');
196 }
197 $output .= theme('item_list', $blogs);
198 $output = theme('box', $title, $output);
199 }
200
201 return $output;
202 }
203
204 function _site_map_audio() {
205 $output = '';
206 if (module_exists('audio')) {
207 $title = t('Audio');
208 $output = l(t('Audio content'), 'audio') . (variable_get('site_map_show_rss_links', 1) ? ' '. theme('site_map_feed_icon', url('audio/feed')) : '');
209 $output = theme('box', $title, $output);
210 }
211
212 return $output;
213 }
214
215 function _site_map_video() {
216 $output = '';
217 if (module_exists('video')) {
218 $title = t('Video');
219 $output = l(t('Video content'), 'video') . (variable_get('site_map_show_rss_links', 1) ? ' '. theme('site_map_feed_icon', url('video/feed')) : '');
220 $output = theme('box', $title, $output);
221 }
222
223 return $output;
224 }
225
226 /**
227 * Render books
228 */
229 function _site_map_books() {
230 $output = '';
231 if (module_exists('book') && ($nids = variable_get('site_map_show_books', array()))) {
232 $title = t('Books');
233 $description = '<div class="description">'. t("Books at %sn.", array("%sn" => variable_get('site_name', 'Drupal'))) .'</div>';
234
235 $book_menus = array();
236 foreach ($nids as $nid) {
237 $node = node_load($nid);
238 $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
239 $data = array_shift($tree);
240 $output .= theme('book_title_link', $data['link']);
241 $output .= ($data['below']) ? menu_tree_output($data['below']) : '';
242 }
243
244 if ($output) {
245 $output = theme('box', $title, $description . $output);
246 }
247 }
248
249 return $output;
250 }
251
252 /**
253 * Render menus
254 */
255 function _site_map_menus() {
256 $output = '';
257 if ($mids = variable_get('site_map_show_menus', array())) {
258 foreach ($mids as $mid) {
259 $menu = menu_load($mid);
260 $menu_display = menu_tree($mid);
261 if (!empty($menu_display)) {
262 $title = $menu['title'];
263 $output .= theme('box', $title, $menu_display);
264 }
265 }
266 }
267
268 return $output;
269 }
270
271 function _site_map_faq() {
272 $output = '';
273 if (module_exists('faq')) {
274 $title = variable_get('faq_title', t('Frequently Asked Questions'));
275 $output = faq_get_faq_list();
276 $output = theme('box', $title, $output);
277 }
278
279 return $output;
280 }
281
282 /**
283 * This function can be called from blocks or pages as desired.
284 */
285 function _site_map_taxonomys() {
286 $output = '';
287 if (module_exists('taxonomy') && $vids = variable_get('site_map_show_vocabularies', array())) {
288 $result = db_query('SELECT vid, name, description FROM {vocabulary} WHERE vid IN ('. db_placeholders($vids, 'int') .') ORDER BY weight ASC, name');
289 while ($t = db_fetch_object($result)) {
290 $output .= _site_map_taxonomy_tree($t->vid, $t->name, $t->description);
291 }
292 }
293
294 return $output;
295 }
296
297 /**
298 * Render taxonomy tree
299 *
300 * @param $tree The results of taxonomy_get_tree() with optional 'count' fields.
301 * @param $name An optional name for the tree. (Default: NULL)
302 * @param $description An optional description of the tree. (Default: NULL)
303 * @return A string representing a rendered tree.
304 */
305 function _site_map_taxonomy_tree($vid, $name = NULL, $description = NULL) {
306 if ($vid == variable_get('forum_nav_vocabulary', '')) {
307 $title = l($name, 'forum');
308 }
309 else {
310 $title = $name ? check_plain($name) : '';
311 }
312 $title .= (module_exists('commentrss') ? ' '. theme('site_map_feed_icon', url("crss/vocab/$vid"), 'comment') : '');
313
314 $last_depth = -1;
315 $rss_depth = variable_get('site_map_rss_depth', 'all');
316 if (!is_numeric($rss_depth) || $rss_depth < 0) {
317 $rss_depth = 'all';
318 }
319 $cat_depth = variable_get('site_map_categories_depth', 'all');
320 if (!is_numeric($cat_depth)) {
321 $cat_depth = 'all';
322 }
323
324 $output = $description ? '<div class="description">'. check_plain($description) .'</div>' : '';
325
326 $output .= '<div class="tree">';
327 // taxonomy_get_tree() honors access controls
328 $tree = taxonomy_get_tree($vid);
329 foreach ($tree as $term) {
330 // Adjust the depth of the <ul> based on the change
331 // in $term->depth since the $last_depth.
332 if ($term->depth > $last_depth) {
333 for ($i = 0; $i < ($term->depth - $last_depth); $i++) {
334 $output .= '<ul>';
335 }
336 }
337 else if ($term->depth < $last_depth) {
338 for ($i = 0; $i < ($last_depth - $term->depth); $i++) {
339 $output .= '</ul>';
340 }
341 }
342 // Display the $term.
343 $output .= '<li>';
344 $term->count = taxonomy_term_count_nodes($term->tid);
345 if ($term->count) {
346 if ($cat_depth < 0) {
347 $output .= l($term->name, taxonomy_term_path($term), array('attributes' => array('title' => $term->description)));
348 }
349 else {
350 $output .= l($term->name, "taxonomy/term/$term->tid/$cat_depth", array('attributes' => array('title' => $term->description)));
351 }
352 }
353 else {
354 $output .= check_plain($term->name);
355 }
356 if (variable_get('site_map_show_count', 1)) {
357 $output .= " ($term->count)";
358 }
359 if (variable_get('site_map_show_rss_links', 1)) {
360 $output .= ' '. theme('site_map_feed_icon', url("taxonomy/term/$term->tid/$rss_depth/feed"));
361 $output .= (module_exists('commentrss') ? ' '. theme('site_map_feed_icon', url("crss/term/$term->tid"), 'comment') : '');
362 }
363
364
365
366 $output .= "</li>\n";
367 // Reset $last_depth in preparation for the next $term.
368 $last_depth = $term->depth;
369 }
370
371 // Bring the depth back to where it began, -1.
372 if ($last_depth > -1) {
373 for ($i = 0; $i < ($last_depth + 1); $i++) {
374 $output .= '</ul>';
375 }
376 }
377 $output .= "</div>\n";
378 $output = theme('box', $title, $output);
379
380 return $output;
381 }

  ViewVC Help
Powered by ViewVC 1.1.2