/[drupal]/contributions/modules/taxonomy_vtn/taxonomy_vtn.pages.inc
ViewVC logotype

Contents of /contributions/modules/taxonomy_vtn/taxonomy_vtn.pages.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Apr 17 18:37:34 2008 UTC (19 months, 1 week ago) by tomaszx
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of taxonomy_vtn module.
1 <?php
2 // $Id$
3
4 /**
5 * Implementation of taxonomy_vtn_show_vocabularies().
6 */
7 function taxonomy_vtn_show_vocabularies() {
8
9 $vocs = taxonomy_get_vocabularies();
10
11 if ( (count($vocs) == 1) && (variable_get('taxonomy_vtn_vocabularies_goto_terms_if_one', 0) == 1) ) {
12 drupal_goto('taxonomy_vtn/voc/'. key($vocs));
13 }
14
15 //Check if the page hasn't already been cached. If not, create and cache it.
16 $cache_data = cache_get('taxonomy_vtn_show_vocs')->data;
17 if ($cache_data && variable_get('taxonomy_vtn_caching', FALSE)) {
18 $output = $cache_data;
19 //print 'z cache';
20 return $output;
21 }
22 else {
23
24 if ($vocs) {
25
26 $show_empty_vocs = variable_get('taxonomy_vtn_vocabularies_show_empty_vocs', 1);
27 $show_count_terms = variable_get('taxonomy_vtn_vocabularies_show_count_terms', 1);
28 $show_voc_desc = variable_get('taxonomy_vtn_vocabularies_show_voc_desc', 1);
29 $count_group_vocabularies = variable_get('taxonomy_vtn_vocabularies_count_group_vocabularies', 1);
30 $count_column_vocs = variable_get('taxonomy_vtn_vocabularies_count_column_vocs', 2);
31 $arr = array();
32
33 foreach ( $vocs as $vid => $voc_obj ) {
34 $terms = taxonomy_get_tree($vid);
35 $tcount = count($terms);
36
37 if ($show_count_terms) {
38 $count_terms = ' ('. $tcount .')';
39 }
40
41 if ($show_voc_desc) {
42 $voc_desc = '<br /><span class="description">'. $voc_obj->description .'</span>';
43 }
44
45 if ($tcount || $show_empty_vocs) {
46 $index = strtoupper(substr($voc_obj->name, 0, $count_group_vocabularies));
47 $arr[$index][] = l($voc_obj->name, 'taxonomy_vtn/voc/'. $voc_obj->vid) . $count_terms . $voc_desc;
48 }
49 }
50
51 $xlanguage = language_default();
52 // change locale to sort
53 //if ( setlocale(LC_ALL, $xlanguage->language.'_'.strtoupper($xlanguage->language).'.UTF8') ){
54 if (variable_get('taxonomy_vtn_use_setlocale', 1) == 1 && variable_get('taxonomy_vtn_server_support_setlocale', 0) ) {
55 setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');
56 ksort($arr, SORT_LOCALE_STRING);
57 // set locale back to default
58 setlocale(LC_ALL, NULL); // without this count($arr) not work properly
59 }
60 else {
61 ksort($arr); //--- this not support locales
62 }
63
64
65 $cnt = ceil(count($arr)/$count_column_vocs);
66 $k = 0; $col = 0;
67 foreach ($arr as $i => $t) {
68 if ($k == 0 || ($k%$cnt) == 0 || $k == $cnt) {
69 $cell = 'cell'. ++$col;
70 }
71 $$cell .= theme('item_list', $t, $i, 'ul');
72 ++$k;
73 }
74
75 if ($k) {
76 // prepare cells and they width
77 ($col < $count_column_vocs ) ? $ile = $col : $ile = $count_column_vocs;
78 for ($num=1; $num <= $ile; ++$num) {
79 $xcell = 'cell'. $num;
80 $xcells[] = array('data' => $$xcell, 'style' => 'width:'. (100/$ile) .'%');
81 }
82 $row[] = $xcells;
83
84
85 if ($show_voc_desc) {
86 $output .= '<a href="javascript:taxonomy_vtn_show_hide_desc(\'vocabularies\');">'. t('Show / Hide descriptions') .'</a>';
87 }
88
89 $output .= theme('table', array(), $row, array('class' => 'taxonomy_vtn_vocabularies', 'id' => 'taxonomy_vtn_vocabularies'));
90
91 //Cache the fully rendered page in case of aggressive caching
92 if (variable_get('taxonomy_vtn_caching', FALSE)) {
93 cache_set('taxonomy_vtn_show_vocs', $output);
94 }
95
96 return $output;
97 }
98 else {
99
100 $output = t('No data to display. Probably you have set option to not show empty vocabularies.');
101
102 //Cache the fully rendered page in case of aggressive caching
103 if (variable_get('taxonomy_vtn_caching', FALSE)) {
104 cache_set('taxonomy_vtn_show_vocs', $output);
105 }
106 return $output;
107 }
108 }
109 else {
110 $output = t('No data to display. Probably you not have any vocabularies');
111
112 //Cache the fully rendered page in case of aggressive caching
113 if (variable_get('taxonomy_vtn_caching', FALSE)) {
114 cache_set('taxonomy_vtn_show_vocs', $output);
115 }
116
117 return $output;
118 }
119 } // end cache
120 }
121
122 /**
123 * Implementation of taxonomy_vtn_show_terms().
124 */
125 function taxonomy_vtn_show_terms($arg = '') {
126
127 if (is_numeric($arg)) {
128 $own_vid = (int)$arg;
129 if ($voc_obj = taxonomy_vocabulary_load($own_vid)) {
130 drupal_set_title(t('Terms in %vocabulary', array('%vocabulary' => $voc_obj->name)));
131 $output = '<div class="description">'. $voc_obj->description .'</div>';
132 }
133 else {
134 drupal_set_title(t('Bad vocabulary id'));
135 $output = '<p>'. t('No data to display. Probably you not have a vocabulary with vid = !voc_id', array('!voc_id' => $own_vid)) .'</p>';
136 $output .= '<div>'. l('<< '. t('Back to vocabularies'), 'taxonomy_vtn') .'</div>';
137 return $output;
138 }
139 }
140 else {
141 drupal_set_message(t('Please select a vocabulary first'));
142 drupal_goto('taxonomy_vtn');
143 }
144
145
146 //Check if the page hasn't already been cached. If not, create and cache it.
147 $cache_data = cache_get('taxonomy_vtn_show_terms_'. $own_vid)->data;
148 if ($cache_data && variable_get('taxonomy_vtn_caching', FALSE)) {
149 $output = $cache_data;
150 //print 'z cache';
151 return $output;
152 }
153 else {
154
155 // vocabulary vid is ok, lets do it
156
157 $show_empty_terms = variable_get('taxonomy_vtn_terms_show_empty_terms', 1);
158 $show_count_nodes = variable_get('taxonomy_vtn_terms_show_count_nodes', 1);
159 $show_term_desc = variable_get('taxonomy_vtn_terms_show_term_desc', 1);
160 $show_synonyms = variable_get('taxonomy_vtn_terms_show_synonyms', 1);
161 $count_group_terms = variable_get('taxonomy_vtn_terms_count_group_terms', 1);
162 $count_column_terms = variable_get('taxonomy_vtn_terms_count_column_terms', 2);
163
164
165 if ( $terms = taxonomy_get_tree($own_vid) ) {
166 $arr = array();
167 $arr_terms = array();
168 $row = array();
169 $count_nodes = '';
170
171 /// prepare own full structure with terms and synonyms and link to them
172 foreach ($terms as $term) {
173 //$cnt_nodes[$term->tid] = taxonomy_term_count_nodes($term->tid);
174
175 $tcount = taxonomy_term_count_nodes($term->tid);
176 // real count or total count with relations terms
177 // real ...//$tcount = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));
178
179 if ($show_count_nodes) {
180 $count_nodes = ' ('. $tcount .')';
181 }
182
183 $term_desc = '';
184 if ($show_term_desc && $term->description) {
185 $term_desc = '<br /><span class="description">'. $term->description .'</span>';
186 }
187
188 if ($tcount || $show_empty_terms) {
189 $arr_terms[$term->name]['term'][] = l($term->name, 'taxonomy_vtn/term/'. $term->tid) . $count_nodes . $term_desc ;
190 // if is not empty term or we show empty terms
191 // and we will show synonyms then get for this
192 if ($show_synonyms) {
193 $synonyms = taxonomy_get_synonyms($term->tid);
194 foreach ($synonyms as $synonym_name) {
195 // $synonym_term = taxonomy_get_synonym_root($synonym_name);
196 // all synonyms have a target - this term
197 $arr_terms[$synonym_name]['synonym'][] = l($term->name, 'taxonomy_vtn/term/'. $term->tid);
198 }
199 }
200 }
201 } // end foreach terms as term prepare
202
203
204 // Now we make index with links to proper terms for synonyms
205 foreach ($arr_terms as $name => $types) {
206 $index = drupal_strtoupper(drupal_substr($name, 0, $count_group_terms));
207 foreach ($types as $type => $links) {
208 if ($type == 'term') {
209 foreach ($links as $link) { // maybe is more than one
210 $arr[$index][] = $link;
211 }
212 }
213 else { // is a synonym then look for terms
214 $x_links = array();
215 foreach ($links as $link) { // propably is more than one
216 $x_links[] = $link;
217 }
218 //$arr[$index][] = $name .'<br /> <small> ( '. t('Look at') .' : '. implode(', ', $x_links) . ' )</small>';
219 $arr[$index][] = $name .'<br /> <small>'. t('Synonyms') .': '. implode(', ', $x_links) .'</small>';
220 }
221 }
222 } // end foreach arr_terms
223
224
225 // sort array key (index like A B C .. etc.)
226 $xlanguage = language_default();
227 // change locale to sort
228 //if ( setlocale(LC_ALL, $xlanguage->language.'_'.strtoupper($xlanguage->language).'.UTF8') ){
229 if (variable_get('taxonomy_vtn_use_setlocale', 1) == 1 && variable_get('taxonomy_vtn_server_support_setlocale', 0) ) {
230 setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');
231 ksort($arr, SORT_LOCALE_STRING);
232 // set locale back to default
233 setlocale(LC_ALL, NULL); // without this count($arr) not work properly
234 }
235 else {
236 ksort($arr); //--- this not support languages
237 }
238
239 $cnt = ceil(count($arr)/$count_column_terms);
240 $k = 0; $col = 0;
241 foreach ($arr as $i => $t) {
242 if ($k == 0 || ($k%$cnt) == 0 || $k == $cnt) {
243 $cell = 'cell'. ++$col;
244 }
245 $$cell .= theme('item_list', $t, $i, 'ul');
246 ++$k;
247 }
248
249 if ($k) {
250 // prepare cells and they width
251 ($col < $count_column_terms ) ? $ile = $col : $ile = $count_column_terms;
252 for ($num=1; $num <= $ile; ++$num) {
253 $xcell = 'cell'. $num;
254 $xcells[] = array('data' => $$xcell, 'style' => 'width:'. (100/$ile) .'%');
255 }
256 $row[] = $xcells;
257
258 $term_js = '';
259 if ($show_term_desc) {
260 $term_js = ' &nbsp; | &nbsp; <a href="javascript:taxonomy_vtn_show_hide_desc(\'terms\');">'. t('Show / Hide descriptions') .'</a>';
261 }
262 $output .= '<div>'. l('<< '. t('Back to vocabularies'), 'taxonomy_vtn') . $term_js .'</div>';
263
264 $output .= theme('table', array(), $row, array('class' => 'taxonomy_vtn_terms', 'id' => 'taxonomy_vtn_terms'));
265
266 //Cache the fully rendered page in case of aggressive caching
267 if (variable_get('taxonomy_vtn_caching', FALSE)) {
268 cache_set('taxonomy_vtn_show_terms_'. $own_vid, $output);
269 }
270
271 return $output;
272 }
273 else {
274 $output .= '<p>'. t('No data to display. Probably you have set option to not show empty terms.') .'</p>';
275 $output .= '<div>'. l('<< '. t('Back to vocabularies'), 'taxonomy_vtn') .'</div>';
276
277 //Cache the fully rendered page in case of aggressive caching
278 if (variable_get('taxonomy_vtn_caching', FALSE)) {
279 cache_set('taxonomy_vtn_show_terms_'. $own_vid, $output);
280 }
281
282 return $output;
283 }
284 }// end if terms
285 else {
286 $output .= '<p>'. t('No data to display. Probably this vocabulary is empty.') .'</p>';
287 $output .= '<div>'. l('<< '. t('Back to vocabularies'), 'taxonomy_vtn') .'</div>';
288
289 //Cache the fully rendered page in case of aggressive caching
290 if (variable_get('taxonomy_vtn_caching', FALSE)) {
291 cache_set('taxonomy_vtn_show_terms_'. $own_vid, $output);
292 }
293
294 return $output;
295 }
296
297 } // end else if cache
298
299 }
300
301
302 /**
303 * Implementation of taxonomy_vtn_show_nodes().
304 */
305 function taxonomy_vtn_show_nodes($arg = '') {
306
307 if (is_numeric($arg)) {
308 $own_tid = (int)$arg;
309 if ($term_obj = taxonomy_get_term($own_tid)) {
310 drupal_set_title(t('Nodes of term @term_name', array('@term_name' => $term_obj->name)));
311 }
312 else {
313 drupal_set_title(t('Bad term id'));
314 $output = '<p>'. t('No data to display. Probably you not have a term with tid = !term_id', array('!term_id' => $own_tid)) .'</p>';
315 $output .= '<div>'. l('<< '. t('Back to vocabularies'), 'taxonomy_vtn') .'</div>';
316 return $output;
317 }
318 }
319 else {
320 drupal_set_message(t('Please select a vocabulary first'));
321 drupal_goto('taxonomy_vtn');
322 }
323
324 //Check if the page hasn't already been cached. If not, create and cache it.
325 $cache_data = cache_get('taxonomy_vtn_show_nodes_'. $own_tid)->data;
326 if ($cache_data && variable_get('taxonomy_vtn_caching', FALSE)) {
327 $output = $cache_data;
328 //print 'z cache';
329 return $output;
330 }
331 else {
332
333 // TODO: settings for depth
334 require_once('taxonomy_vtn_overwrites.inc.php');
335 $nodes = taxonomy_vtn_select_nodes(array($own_tid), $operator = 'or', $depth = 'all', $pager = FALSE, $order = 'n.sticky DESC', 0);
336
337 $show_count_comments = variable_get('taxonomy_vtn_nodes_show_count_comments', 1);
338 $count_column_nodes = variable_get('taxonomy_vtn_nodes_count_column_nodes', 2);
339 $show_empty_count_comments = variable_get('taxonomy_vtn_nodes_show_empty_count_comments', 0);
340 $show_nodes_index = variable_get('taxonomy_vtn_nodes_show_nodes_index', 0);
341
342 $count_comments = '';
343
344 while ($node = db_fetch_object($nodes)) {
345 $node = node_load($node->nid);
346 // TODO: cut special chars
347 $index = strtoupper(substr($node->title, 0, 1));
348 //print_r($node);
349 if ($show_count_comments) {
350 if ( $node->comment_count || $show_empty_count_comments) {
351 $count_comments = ' ('. format_plural($node->comment_count, '1 comment', '@count comments') .')';
352 }
353 }
354 $arr[$index][] = l($node->title, 'node/'. $node->nid) . $count_comments;
355 // for <li> style .... $arr[$index][] = array('data' => l($node->title,'node/'.$node->nid) . $count_comments, 'style' => '');
356 }
357
358 if ( count($arr) > 0 ) {
359
360 $xlanguage = language_default();
361 // change locale to sort
362 //if ( setlocale(LC_ALL, $xlanguage->language.'_'.strtoupper($xlanguage->language).'.UTF8') ){
363 if (variable_get('taxonomy_vtn_use_setlocale', 1) == 1 && variable_get('taxonomy_vtn_server_support_setlocale', 0) ) {
364 setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');
365 ksort($arr, SORT_LOCALE_STRING);
366 // set locale back to default
367 setlocale(LC_ALL, NULL); // without this count($arr) not work properly
368 }
369 else {
370 ksort($arr); //--- this not support locales
371 }
372
373 // if more columns always show index
374 if ($count_column_nodes > 1) {
375 $show_nodes_index = 1;
376 $attr = array();
377 }
378
379 $cnt = ceil(count($arr)/$count_column_nodes);
380 $k = 0; $col = 0;
381 foreach ($arr as $i => $t) {
382 if ($k == 0 || ($k%$cnt) == 0 || $k == $cnt) {
383 $cell = 'cell'. ++$col;
384 }
385 if ($show_nodes_index == 0) {
386 $i = NULL;
387 $attr = array('class' => 'simple-list');
388 }
389 $$cell .= theme('item_list', $t, $i, 'ul', $attr);
390 ++$k;
391 }
392
393 // prepare cells and they width
394 ($col < $count_column_nodes ) ? $ile = $col : $ile = $count_column_nodes;
395 for ($num=1; $num <= $ile; ++$num) {
396 $xcell = 'cell'. $num;
397 $xcells[] = array('data' => $$xcell, 'style' => 'width:'. (100/$ile) .'%');
398 }
399 $row[] = $xcells;
400
401 $output .= '<div class="description">'. $term_obj->description .'</div>';
402 $output .= '<div>'. l('<< '. t('Back to terms'), 'taxonomy_vtn/voc/'. $term_obj->vid) .'</div>';
403 $output .= theme('table', array(), $row, array('class' => 'taxonomy_vtn_nodes', 'id' => 'taxonomy_vtn_nodes'));
404
405 //Cache the fully rendered page in case of aggressive caching
406 if (variable_get('taxonomy_vtn_caching', FALSE)) {
407 cache_set('taxonomy_vtn_show_nodes_'. $own_tid, $output);
408 }
409
410 return $output;
411 }
412 else {
413 $output = '<p>'. t('No data to display. Probably this term is empty.') .'</p>';
414 $output .= '<div>'. l('<< '. t('Back to terms'), 'taxonomy_vtn/voc/'. $term_obj->vid) .'</div>';
415
416 //Cache the fully rendered page in case of aggressive caching
417 if (variable_get('taxonomy_vtn_caching', FALSE)) {
418 cache_set('taxonomy_vtn_show_nodes_'. $own_tid, $output);
419 }
420
421 return $output;
422 }
423 } // end if cache
424 }
425

  ViewVC Help
Powered by ViewVC 1.1.2