/[drupal]/contributions/modules/taxonomy_block/taxonomy_block.module
ViewVC logotype

Contents of /contributions/modules/taxonomy_block/taxonomy_block.module

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


Revision 1.25 - (show annotations) (download) (as text)
Fri Aug 14 02:56:43 2009 UTC (3 months, 1 week ago) by thenicespider
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA2
Changes since 1.24: +21 -7 lines
File MIME type: text/x-php
6.x-1.0-BETA2:  New: able to set maksimum term to display
1 <?php
2 // $Id: taxonomy_block.module,v 1.24 2009/06/26 09:02:02 thenicespider Exp $
3
4 /**
5 * @file
6 * The taxonomy_block module used for displaying Site Counter.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function taxonomy_block_help($section) {
13 switch ($section) {
14 case 'admin/help#taxonomy_block':
15 $output = "The taxonomy_block module used for displaying taxonomy in a block with i18n/multi-languages support";
16 return $output;
17 case 'admin/modules#description':
18 return 'The taxonomy_block module used for displaying taxonomy in a block with i18n/multi-languages support';
19 }
20 }
21
22 /**
23 * Implementation of hook_perm
24 */
25 function taxonomy_block_perm() {
26 return array('access taxonomy_block', 'administer taxonomy_block');
27 }
28
29 /**
30 * Menu callback. Prints a listing of active nodes on the site.
31 */
32
33 function taxonomy_block_menu() {
34 $items = array();
35
36 $items['admin/settings/taxonomy_block'] = array(
37 'title' => 'Taxonomy Block',
38 'description' => 'Show taxonomy in a block with i18n support',
39 'access arguments' => array('administer taxonomy_block'),
40 'page callback' => 'drupal_get_form',
41 'page arguments' => array('taxonomy_block_admin_settings'),
42 'type' => MENU_NORMAL_ITEM,
43 'file' => 'taxonomy_block.settings.inc',
44 );
45
46 return $items;
47 }
48
49 /**
50 * Implementation of hook_block().
51 *
52 */
53 function taxonomy_block_block($op = 'list', $delta = 0) {
54 if ($op == 'list')
55 {
56 $blocks[0]['info'] = 'Taxonomy Block';
57 return $blocks;
58 }
59
60 if ($op == 'view')
61 {
62 $vid = variable_get('taxonomy_block_settings_vid',1);
63 $node_count = variable_get('taxonomy_block_settings_node_count',0);
64 $num_term = variable_get('taxonomy_block_settings_max_term',0);
65
66 switch($delta) {
67 case 0:
68 $block['subject'] = 'Taxonomy Block';
69
70 $output = '';
71
72
73 //Check database
74
75 if ($num_term == 0) {
76 $sql = " SELECT td.tid, td.name, th.parent from {term_data} td "
77 ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
78 ." WHERE vid='%d' AND th.parent=0 ORDER BY name ASC";
79 } else {
80 $sql = " SELECT td.tid, td.name, th.parent from {term_data} td "
81 ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
82 ." WHERE vid='%d' AND th.parent=0 ORDER BY name ASC LIMIT %d";
83 }
84
85 $term_parents = db_query($sql, $vid, $num_term );
86
87
88 $output .= '<ul class="menu">';
89 while ($term_parent = db_fetch_object($term_parents)) {
90 $tid_parent = $term_parent->tid;
91 $name_parent= $term_parent->name;
92
93 $output .= '<li>';
94 if (module_exists("i18n")) {
95 $output .= l(tt("taxonomy:term:$tid_parent:name", $name_parent), "taxonomy/term/$tid_parent");
96 } else {
97 $output .= l(t($name_parent), "taxonomy/term/$tid_parent");
98 }
99 if ($node_count) {
100 $total_parent = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_parent));
101 $output .= " ($total_parent)";
102 }
103 $output .= "</li>";
104
105 $sql_count_childs = " SELECT count(td.tid) from {term_data} td "
106 ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
107 ." WHERE td.vid='%d' AND th.parent='%d'";
108 $count_childs = db_query($sql_count_childs, $vid, $tid_parent);
109 $count_child = db_result($count_childs);
110
111 if ($count_child) {
112 if ($num_term == 0) {
113 $sql_term_childs = " SELECT td.tid, td.name from {term_data} td "
114 ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
115 ." WHERE vid='%d' AND th.parent='%d' ORDER BY name ASC";
116 } else {
117 $sql_term_childs = " SELECT td.tid, td.name from {term_data} td "
118 ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
119 ." WHERE vid='%d' AND th.parent='%d' ORDER BY name ASC LIMIT %d";
120 }
121
122 $term_childs = db_query($sql_term_childs, $vid, $tid_parent, $num_term );
123 $output .= '<ul>';
124 while ($term_child = db_fetch_object($term_childs)) {
125 $tid_child = $term_child->tid;
126 $name_child = $term_child->name;
127
128 $output .= '<li>';
129 if (module_exists("i18n")) {
130 $output .= l(tt("taxonomy:term:$tid_child:name", $name_child), "taxonomy/term/$tid_child");
131 } else {
132 $output .= l(t($name_child), "taxonomy/term/$tid_child");
133 }
134 if ($node_count) {
135 $total_child = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_child));
136 $output .= " ($total_child)";
137 }
138 $output .= "</li>";
139 }
140 $output .= "</ul>";
141 }
142 }
143
144 $output .= "</ul>";
145
146 //if(count($items)) {
147 // return theme('item_list',$items);
148 //}
149
150 $block['content'] = $output;
151
152 break;
153 }
154
155 return $block;
156 }
157
158 }
159
160 ?>

  ViewVC Help
Powered by ViewVC 1.1.2