/[drupal]/contributions/modules/i18n/i18ntaxonomy/i18ntaxonomy.pages.inc
ViewVC logotype

Contents of /contributions/modules/i18n/i18ntaxonomy/i18ntaxonomy.pages.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Feb 21 20:14:23 2008 UTC (21 months, 1 week ago) by jareyero
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
- Added (Upgraded) i18ncontent, fully reworked, much cleaner now
- Improved i18nstrings, translation of strings without source, debug facility
- Replaced taxonomy term pages with localized version
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, i18n remake.
7 */
8
9 /**
10 * Menu callback; displays all nodes associated with a term.
11 */
12 function i18ntaxonomy_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 // We need vid here too
20 $result = db_query(db_rewrite_sql('SELECT t.vid, t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. db_placeholders($terms['tids']) .')', 't', 'tid'), $terms['tids']);
21 $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to.
22 $names = array();
23 while ($term = db_fetch_object($result)) {
24 $tids[] = $term->tid;
25 if (i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
26 $names[] = tt("taxonomy:term:$term->tid:name", $term->name);
27 } else {
28 $names[] = $term->name;
29 }
30 }
31
32 if ($names) {
33 $title = check_plain(implode(', ', $names));
34 drupal_set_title($title);
35
36 switch ($op) {
37 case 'page':
38 // Build breadcrumb based on first hierarchy of first term:
39 $current->tid = $tids[0];
40 $breadcrumb = array();
41 while ($parents = taxonomy_get_parents($current->tid)) {
42 $current = array_shift($parents);
43 $breadcrumb[] = l($current->name, 'taxonomy/term/'. $current->tid);
44 }
45 $breadcrumb[] = l(t('Home'), NULL);
46 $breadcrumb = array_reverse($breadcrumb);
47 drupal_set_breadcrumb($breadcrumb);
48
49 $output = theme('taxonomy_term_page', $tids, taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));
50 drupal_add_feed(url('taxonomy/term/'. $str_tids .'/'. $depth .'/feed'), 'RSS - '. $title);
51 return $output;
52 break;
53
54 case 'feed':
55 $channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE));
56 $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title;
57 // Only display the description if we have a single term, to avoid clutter and confusion.
58 if (count($tids) == 1) {
59 $term = taxonomy_get_term($tids[0]);
60 // HTML will be removed from feed description, so no need to filter here.
61 $channel['description'] = $term->description;
62 }
63
64 $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE);
65 $items = array();
66 while ($row = db_fetch_object($result)) {
67 $items[] = $row->nid;
68 }
69
70 node_feed($items, $channel);
71 break;
72
73 default:
74 drupal_not_found();
75 }
76 }
77 else {
78 drupal_not_found();
79 }
80 }
81 }
82
83 /**
84 * Render a taxonomy term page HTML output.
85 *
86 * @param $tids
87 * An array of term ids.
88 * @param $result
89 * A pager_query() result, such as that performed by taxonomy_select_nodes().
90 *
91 * @ingroup themeable
92 */
93 function theme_taxonomy_term_page($tids, $result) {
94 drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css');
95
96 $output = '';
97
98 // Only display the description if we have a single term, to avoid clutter and confusion.
99 if (count($tids) == 1) {
100 $term = taxonomy_get_term($tids[0]);
101 if (i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
102 $description = tt('taxonomy:term:'.$term->tid.':description', $term->description);
103 } else {
104 $description = $term->description;
105 }
106
107 // Check that a description is set.
108 if (!empty($description)) {
109 $output .= '<div class="taxonomy-term-description">';
110 $output .= filter_xss_admin($description);
111 $output .= '</div>';
112 }
113 }
114
115 $output .= taxonomy_render_nodes($result);
116
117 return $output;
118 }
119
120 /**
121 * Helper function for autocompletion
122 *
123 * @ TODO Optimized localization. We cannot just tt() huge lists of terms
124 */
125 function i18ntaxonomy_autocomplete($vid, $string = '') {
126 // The user enters a comma-separated list of tags. We only autocomplete the last tag.
127 $array = drupal_explode_tags($string);
128
129 // Is this vocabulary localizable ?
130 $localizable = i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE;
131
132 // Fetch last tag
133 $last_string = trim(array_pop($array));
134 $matches = array();
135 if ($last_string != '') {
136 $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);
137
138 $prefix = count($array) ? implode(', ', $array) .', ' : '';
139
140 while ($tag = db_fetch_object($result)) {
141 $n = $tag->name;
142 // Commas and quotes in terms are special cases, so encode 'em.
143 if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
144 $n = '"'. str_replace('"', '""', $tag->name) .'"';
145 }
146 $matches[$prefix . $n] = check_plain($tag->name);
147 }
148 }
149
150 drupal_json($matches);
151 }

  ViewVC Help
Powered by ViewVC 1.1.2