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