webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: taxonomy.pages.inc,v 1.9 2008/01/18 16:23:57 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * @file |
webmaster@1
|
6 * Page callbacks for the taxonomy module. |
webmaster@1
|
7 */ |
webmaster@1
|
8 |
webmaster@1
|
9 /** |
webmaster@1
|
10 * Menu callback; displays all nodes associated with a term. |
webmaster@1
|
11 */ |
webmaster@1
|
12 function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { |
webmaster@1
|
13 $terms = taxonomy_terms_parse_string($str_tids); |
webmaster@1
|
14 if ($terms['operator'] != 'and' && $terms['operator'] != 'or') { |
webmaster@1
|
15 drupal_not_found(); |
webmaster@1
|
16 } |
webmaster@1
|
17 |
webmaster@1
|
18 if ($terms['tids']) { |
webmaster@1
|
19 $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. db_placeholders($terms['tids']) .')', 't', 'tid'), $terms['tids']); |
webmaster@1
|
20 $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. |
webmaster@1
|
21 $names = array(); |
webmaster@1
|
22 while ($term = db_fetch_object($result)) { |
webmaster@1
|
23 $tids[] = $term->tid; |
webmaster@1
|
24 $names[] = $term->name; |
webmaster@1
|
25 } |
webmaster@1
|
26 |
webmaster@1
|
27 if ($names) { |
webmaster@1
|
28 $title = check_plain(implode(', ', $names)); |
webmaster@1
|
29 drupal_set_title($title); |
webmaster@1
|
30 |
webmaster@1
|
31 switch ($op) { |
webmaster@1
|
32 case 'page': |
webmaster@1
|
33 // Build breadcrumb based on first hierarchy of first term: |
webmaster@1
|
34 $current->tid = $tids[0]; |
webmaster@1
|
35 $breadcrumb = array(); |
webmaster@1
|
36 while ($parents = taxonomy_get_parents($current->tid)) { |
webmaster@1
|
37 $current = array_shift($parents); |
webmaster@1
|
38 $breadcrumb[] = l($current->name, 'taxonomy/term/'. $current->tid); |
webmaster@1
|
39 } |
webmaster@1
|
40 $breadcrumb[] = l(t('Home'), NULL); |
webmaster@1
|
41 $breadcrumb = array_reverse($breadcrumb); |
webmaster@1
|
42 drupal_set_breadcrumb($breadcrumb); |
webmaster@1
|
43 |
webmaster@1
|
44 $output = theme('taxonomy_term_page', $tids, taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE)); |
webmaster@1
|
45 drupal_add_feed(url('taxonomy/term/'. $str_tids .'/'. $depth .'/feed'), 'RSS - '. $title); |
webmaster@1
|
46 return $output; |
webmaster@1
|
47 break; |
webmaster@1
|
48 |
webmaster@1
|
49 case 'feed': |
webmaster@1
|
50 $channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE)); |
webmaster@1
|
51 $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title; |
webmaster@1
|
52 // Only display the description if we have a single term, to avoid clutter and confusion. |
webmaster@1
|
53 if (count($tids) == 1) { |
webmaster@1
|
54 $term = taxonomy_get_term($tids[0]); |
webmaster@1
|
55 // HTML will be removed from feed description, so no need to filter here. |
webmaster@1
|
56 $channel['description'] = $term->description; |
webmaster@1
|
57 } |
webmaster@1
|
58 |
webmaster@1
|
59 $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE); |
webmaster@1
|
60 $items = array(); |
webmaster@1
|
61 while ($row = db_fetch_object($result)) { |
webmaster@1
|
62 $items[] = $row->nid; |
webmaster@1
|
63 } |
webmaster@1
|
64 |
webmaster@1
|
65 node_feed($items, $channel); |
webmaster@1
|
66 break; |
webmaster@1
|
67 |
webmaster@1
|
68 default: |
webmaster@1
|
69 drupal_not_found(); |
webmaster@1
|
70 } |
webmaster@1
|
71 } |
webmaster@1
|
72 else { |
webmaster@1
|
73 drupal_not_found(); |
webmaster@1
|
74 } |
webmaster@1
|
75 } |
webmaster@1
|
76 } |
webmaster@1
|
77 |
webmaster@1
|
78 /** |
webmaster@1
|
79 * Render a taxonomy term page HTML output. |
webmaster@1
|
80 * |
webmaster@1
|
81 * @param $tids |
webmaster@1
|
82 * An array of term ids. |
webmaster@1
|
83 * @param $result |
webmaster@1
|
84 * A pager_query() result, such as that performed by taxonomy_select_nodes(). |
webmaster@1
|
85 * |
webmaster@1
|
86 * @ingroup themeable |
webmaster@1
|
87 */ |
webmaster@1
|
88 function theme_taxonomy_term_page($tids, $result) { |
webmaster@1
|
89 drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css'); |
webmaster@1
|
90 |
webmaster@1
|
91 $output = ''; |
webmaster@1
|
92 |
webmaster@1
|
93 // Only display the description if we have a single term, to avoid clutter and confusion. |
webmaster@1
|
94 if (count($tids) == 1) { |
webmaster@1
|
95 $term = taxonomy_get_term($tids[0]); |
webmaster@1
|
96 $description = $term->description; |
webmaster@1
|
97 |
webmaster@1
|
98 // Check that a description is set. |
webmaster@1
|
99 if (!empty($description)) { |
webmaster@1
|
100 $output .= '<div class="taxonomy-term-description">'; |
webmaster@1
|
101 $output .= filter_xss_admin($description); |
webmaster@1
|
102 $output .= '</div>'; |
webmaster@1
|
103 } |
webmaster@1
|
104 } |
webmaster@1
|
105 |
webmaster@1
|
106 $output .= taxonomy_render_nodes($result); |
webmaster@1
|
107 |
webmaster@1
|
108 return $output; |
webmaster@1
|
109 } |
webmaster@1
|
110 |
webmaster@1
|
111 /** |
webmaster@1
|
112 * Helper function for autocompletion |
webmaster@1
|
113 */ |
webmaster@1
|
114 function taxonomy_autocomplete($vid, $string = '') { |
webmaster@1
|
115 // The user enters a comma-separated list of tags. We only autocomplete the last tag. |
webmaster@1
|
116 $array = drupal_explode_tags($string); |
webmaster@1
|
117 |
webmaster@1
|
118 // Fetch last tag |
webmaster@1
|
119 $last_string = trim(array_pop($array)); |
webmaster@1
|
120 $matches = array(); |
webmaster@1
|
121 if ($last_string != '') { |
webmaster@1
|
122 $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); |
webmaster@1
|
123 |
webmaster@1
|
124 $prefix = count($array) ? implode(', ', $array) .', ' : ''; |
webmaster@1
|
125 |
webmaster@1
|
126 while ($tag = db_fetch_object($result)) { |
webmaster@1
|
127 $n = $tag->name; |
webmaster@1
|
128 // Commas and quotes in terms are special cases, so encode 'em. |
webmaster@1
|
129 if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) { |
webmaster@1
|
130 $n = '"'. str_replace('"', '""', $tag->name) .'"'; |
webmaster@1
|
131 } |
webmaster@1
|
132 $matches[$prefix . $n] = check_plain($tag->name); |
webmaster@1
|
133 } |
webmaster@1
|
134 } |
webmaster@1
|
135 |
webmaster@1
|
136 drupal_json($matches); |
webmaster@1
|
137 } |