00001 <?php
00002
00003
00012 function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
00013 $terms = taxonomy_terms_parse_string($str_tids);
00014 if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
00015 drupal_not_found();
00016 }
00017
00018 if ($terms['tids']) {
00019 $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']);
00020 $tids = array();
00021 $names = array();
00022 while ($term = db_fetch_object($result)) {
00023 $tids[] = $term->tid;
00024 $names[] = $term->name;
00025 }
00026
00027 if ($names) {
00028 $title = check_plain(implode(', ', $names));
00029 drupal_set_title($title);
00030
00031 switch ($op) {
00032 case 'page':
00033
00034 $current->tid = $tids[0];
00035 $breadcrumb = array();
00036 while ($parents = taxonomy_get_parents($current->tid)) {
00037 $current = array_shift($parents);
00038 $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
00039 }
00040 $breadcrumb[] = l(t('Home'), NULL);
00041 $breadcrumb = array_reverse($breadcrumb);
00042 drupal_set_breadcrumb($breadcrumb);
00043
00044 $output = theme('taxonomy_term_page', $tids, taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));
00045 drupal_add_feed(url('taxonomy/term/' . $str_tids . '/' . $depth . '/feed'), 'RSS - ' . $title);
00046 return $output;
00047 break;
00048
00049 case 'feed':
00050 $channel['link'] = url('taxonomy/term/' . $str_tids . '/' . $depth, array('absolute' => TRUE));
00051 $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $title;
00052
00053 if (count($tids) == 1) {
00054 $term = taxonomy_get_term($tids[0]);
00055
00056 $channel['description'] = $term->description;
00057 }
00058
00059 $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE);
00060 $items = array();
00061 while ($row = db_fetch_object($result)) {
00062 $items[] = $row->nid;
00063 }
00064
00065 node_feed($items, $channel);
00066 break;
00067
00068 default:
00069 drupal_not_found();
00070 }
00071 }
00072 else {
00073 drupal_not_found();
00074 }
00075 }
00076 }
00077
00088 function theme_taxonomy_term_page($tids, $result) {
00089 drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
00090
00091 $output = '';
00092
00093
00094 if (count($tids) == 1) {
00095 $term = taxonomy_get_term($tids[0]);
00096 $description = $term->description;
00097
00098
00099 if (!empty($description)) {
00100 $output .= '<div class="taxonomy-term-description">';
00101 $output .= filter_xss_admin($description);
00102 $output .= '</div>';
00103 }
00104 }
00105
00106 $output .= taxonomy_render_nodes($result);
00107
00108 return $output;
00109 }
00110
00114 function taxonomy_autocomplete($vid, $string = '') {
00115
00116 $array = drupal_explode_tags($string);
00117
00118
00119 $last_string = trim(array_pop($array));
00120 $matches = array();
00121 if ($last_string != '') {
00122 $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);
00123
00124 $prefix = count($array) ? implode(', ', $array) . ', ' : '';
00125
00126 while ($tag = db_fetch_object($result)) {
00127 $n = $tag->name;
00128
00129 if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
00130 $n = '"' . str_replace('"', '""', $tag->name) . '"';
00131 }
00132 $matches[$prefix . $n] = check_plain($tag->name);
00133 }
00134 }
00135
00136 drupal_json($matches);
00137 }