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

Contents of /contributions/modules/taxonomy_browser/taxonomy_browser.module

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


Revision 1.19.2.29 - (hide annotations) (download) (as text)
Thu Jun 26 16:30:54 2008 UTC (17 months ago) by nancyw
Branch: DRUPAL-5
Changes since 1.19.2.28: +9 -4 lines
File MIME type: text/x-php
#275329 by NancyDru - bypass 5.x forms api error when no checkboxes selected.
1 jaza 1.17 <?php
2 nancyw 1.19.2.29 // $Id: taxonomy_browser.module,v 1.19.2.28 2008/06/20 04:08:03 nancyw Exp $
3 jaza 1.17 // Original by Moshe Weitzman (weitzmna@tejasa.com)
4    
5     /**
6     * @file
7 nancyw 1.19.2.19 * Enables users to construct their own view of content from terms across
8     * multiple vocabularies.
9 jaza 1.17 */
10    
11 nancyw 1.19.2.13 //*******************************************************************
12 nancyw 1.19.2.21 //* Drupal Hooks : General Overview
13 nancyw 1.19.2.13 //*******************************************************************
14 jaza 1.17
15     /**
16     * Implementation of hook_menu().
17     */
18     function taxonomy_browser_menu($may_cache) {
19     $items = array();
20    
21     if ($may_cache) {
22 nancyw 1.19.2.14 $items[] = array(
23 nancyw 1.19.2.5 'path' => 'admin/settings/taxonomy-browser',
24     'title' => t('Taxonomy Browser'),
25     'description' => t('Set usage guidelines and included vocabularies.'),
26     'callback' => 'drupal_get_form',
27     'callback arguments' => 'taxonomy_browser_admin_settings',
28     'access' => user_access('administer site configuration'),
29     );
30     }
31     else {
32 nancyw 1.19.2.15 $items[] = array(
33     'path' => 'taxonomy_browser',
34     'title' => t('Category Browser'),
35     'access' => user_access(variable_get('taxonomy_browser_need_perm', false) ? 'access taxonomy browser' : 'access content'),
36     'callback' => 'taxonomy_browser_page',
37     'description' => t('Find content on your own terms.'),
38 nancyw 1.19.2.20 'type' => MENU_NORMAL_ITEM,
39     );
40    
41 nancyw 1.19.2.5 drupal_add_css(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.css');
42 jaza 1.17 }
43    
44     return $items;
45     }
46    
47     /**
48     * Implementation of hook_help().
49     */
50     function taxonomy_browser_help($section = '') {
51     switch ($section) {
52     case 'admin/modules#description':
53     return t('An interface for viewing content grouped by arbitrary taxonomy terms.');
54     case 'taxonomy_browser':
55 nancyw 1.19.2.15 $output = check_markup(variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()));
56     if (user_access('administer site configuration')) {
57 nancyw 1.19.2.23 $output .= '<p class="links">'. l(t('Go to Taxonomy Browser settings'), 'admin/settings/taxonomy-browser', array(), drupal_get_destination()) .'</p>';
58 nancyw 1.19.2.15 }
59     return $output;
60     }
61     }
62    
63     /**
64     * Implementation of hook_perm().
65     */
66     function taxonomy_browser_perm() {
67     if (variable_get('taxonomy_browser_need_perm', false)) {
68     return array('access taxonomy browser');
69     }
70     else {
71     return array();
72 jaza 1.17 }
73     }
74    
75 nancyw 1.19.2.13 //********************************************************************
76 nancyw 1.19.2.15 //* Drupal Hooks : Core
77 nancyw 1.19.2.13 //********************************************************************
78 jaza 1.17
79     /**
80 nancyw 1.19.2.21 * Implementation of hook_block().
81     */
82     function taxonomy_browser_block($op = 'list', $delta = 0, $edit = array()) {
83     $block = array();
84     switch ($op) {
85     case 'list':
86     $block[0]['info'] = t('Category browser');
87     return $block;
88    
89     case 'view':
90 nancyw 1.19.2.23 switch ($delta) {
91 nancyw 1.19.2.21 case 0:
92     $block = _taxonomy_browser_block_view($delta);
93     break;
94     }
95     return $block;
96     //
97     // case 'configure':
98     // return _taxonomy_browser_block_configure($delta);
99     //
100     // case 'save':
101     // _taxonomy_browser_block_save($delta, $edit);
102     }
103     }
104    
105     /**
106 nancyw 1.19.2.15 * Implementation of hook_form().
107 jaza 1.17 */
108 nancyw 1.19.2.1 function taxonomy_browser_admin_settings() {
109     if (!module_exists('node_type_filter') && !drupal_set_message()) {
110 nancyw 1.19.2.13 drupal_set_message(t('You do not have the node_type_filter module installed. This means that the "restrict search by content type" option will not be available on the category browser page.'), 'status');
111 jaza 1.17 }
112 nancyw 1.19.2.27
113     drupal_add_js(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.js', 'module');
114 jaza 1.17
115     $form['taxonomy_browser_guidelines'] = array(
116     '#title' => t('Guidelines'),
117     '#type' => 'textarea',
118     '#default_value' => variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()),
119 nancyw 1.19.2.15 '#rows' => 2,
120 jaza 1.17 '#description' => t('Instructions which should appear at top of the category browser main page'),
121 nancyw 1.19.2.13 );
122 jaza 1.17
123 nancyw 1.19.2.5 $form['taxonomy_browser_select_type'] = array(
124     '#title' => t('Selection type'),
125     '#type' => 'radios',
126 nancyw 1.19.2.23 '#default_value' => variable_get('taxonomy_browser_select_type', 1),
127 nancyw 1.19.2.7 '#options' => array(t('Selection box'), t('Check boxes')),
128 nancyw 1.19.2.9 '#description' => t('This option determines whether the user will see a selection list or check boxes.'),
129 nancyw 1.19.2.23 '#prefix' => '<div class="taxonomy_browser_radios">',
130     '#suffix' => '</div>',
131 nancyw 1.19.2.13 );
132 nancyw 1.19.2.16
133     $form['taxonomy_browser_default_op'] = array(
134     '#title' => t('"Items containing" default'),
135     '#type' => 'radios',
136     '#default_value' => variable_get('taxonomy_browser_default_op', 0),
137     '#options' => array(t('All'), t('Any')),
138     '#description' => t('This option determines which "Items containing" choice is the default.'),
139     '#prefix' => '<div class="taxonomy_browser_radios">',
140     '#suffix' => '</div>',
141     );
142 nancyw 1.19.2.10
143     $form['taxonomy_browser_count_nodes'] = array(
144     '#title' => t('Show node count'),
145     '#type' => 'checkbox',
146     '#default_value' => variable_get('taxonomy_browser_count_nodes', false),
147     '#description' => t('Do you want to display the count of nodes tagged with each term? This can be SQL-intensive.'),
148 nancyw 1.19.2.13 );
149 nancyw 1.19.2.10
150     $form['taxonomy_browser_show_unused'] = array(
151     '#title' => t('Show unused terms'),
152     '#type' => 'checkbox',
153     '#default_value' => variable_get('taxonomy_browser_show_unused', false),
154 nancyw 1.19.2.23 '#description' => t('Do you want to display the term if no nodes are tagged with that term? This requires "Show node count" to be selected; if it is not seleted, all terms will be shown.'),
155 nancyw 1.19.2.13 );
156    
157     $form['taxonomy_browser_allow_children'] = array(
158     '#title' => t('Allow child terms to be included'),
159     '#type' => 'checkbox',
160     '#default_value' => variable_get('taxonomy_browser_allow_children', false),
161     '#description' => t('Do you want the user to see a check box to include child terms (sub-terms)?'),
162     );
163 nancyw 1.19.2.5
164 nancyw 1.19.2.15 $form['taxonomy_browser_need_perm'] = array(
165     '#title' => t('Requires permission'),
166     '#type' => 'checkbox',
167     '#default_value' => variable_get('taxonomy_browser_need_perm', false),
168     '#description' => t('Do you want to require permission to see the browser page?'),
169     );
170    
171 nancyw 1.19.2.23 $select = array();
172 jaza 1.17 $vocabularies = taxonomy_get_vocabularies();
173     foreach ($vocabularies as $vocabulary) {
174     $select[$vocabulary->vid] = $vocabulary->name;
175     }
176 nancyw 1.19.2.13
177 nancyw 1.19.2.29 $current_vocabs = variable_get('taxonomy_browser_vocabularies', array());
178     // Occasionally we get a 0 vid in the array.
179     unset($current_vocabs[0]);
180    
181 jaza 1.17 $form['taxonomy_browser_vocabularies'] = array(
182     '#title' => t('Included Vocabularies'),
183 nancyw 1.19.2.23 '#type' => 'checkboxes',
184 nancyw 1.19.2.29 '#default_value' => $current_vocabs,
185 jaza 1.17 '#options' => $select,
186 nancyw 1.19.2.8 '#description' => t('Select the vocabularies the user can select from on the category browser page.'),
187 nancyw 1.19.2.23 '#prefix' => '<div class="taxonomy_browser_checkboxes">',
188     '#suffix' => '</div>',
189 nancyw 1.19.2.13 );
190 nancyw 1.19.2.18
191 nancyw 1.19.2.8 if (module_exists('node_type_filter')) {
192 nancyw 1.19.2.23 $filter_options = node_get_types('names');
193 nancyw 1.19.2.8 $form['taxonomy_browser_omit'] = array(
194 nancyw 1.19.2.23 '#type' => 'checkboxes',
195 nancyw 1.19.2.8 '#title' => t('Omit content types'),
196     '#options' => $filter_options,
197 nancyw 1.19.2.13 '#default_value' => variable_get('taxonomy_browser_omit', array('')),
198 nancyw 1.19.2.8 '#description' => t('If any of these types is selected, it will be omitted from the list on the "Category Browser" page.'),
199 nancyw 1.19.2.23 '#prefix' => '<div class="taxonomy_browser_checkboxes">',
200     '#suffix' => '</div>',
201 nancyw 1.19.2.13 );
202 nancyw 1.19.2.8 }
203 jaza 1.17
204 nancyw 1.19.2.12 return system_settings_form($form);
205 jaza 1.17 }
206    
207 nancyw 1.19.2.13 function taxonomy_browser_admin_settings_validate($form_id, &$form_values) {
208     if ($form_values['taxonomy_browser_count_nodes'] == false
209     && $form_values['taxonomy_browser_show_unused'] == true) {
210     form_set_error('taxonomy_browser_show_unused', t('"Show unused" requires "count nodes."'));
211     }
212     }
213    
214     //********************************************************************
215     //* Module Functions : Public
216     //********************************************************************
217 jaza 1.17
218     /**
219     * Menu callback: the query building interface for nodes selected based on
220     * taxonomy terms.
221     */
222     function taxonomy_browser_page() {
223 nancyw 1.19.2.1 $output .= drupal_get_form('taxonomy_browser_form');
224     return $output;
225     }
226    
227     function taxonomy_browser_form() {
228 jaza 1.17 $form = array();
229 nancyw 1.19.2.15 $selection_types = array('select', 'checkboxes');
230 nancyw 1.19.2.23 $select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)];
231 nancyw 1.19.2.10 $count_nodes = variable_get('taxonomy_browser_count_nodes', false);
232     $show_unused = variable_get('taxonomy_browser_show_unused', false);
233 nancyw 1.19.2.13 $allow_children = variable_get('taxonomy_browser_allow_children', false);
234 nancyw 1.19.2.14 $node_types = node_get_types('names');
235 jaza 1.17
236     $form['scope'] = array(
237     '#type' => 'fieldset',
238     '#title' => t('Scope'),
239 nancyw 1.19.2.14 '#collapsible' => true,
240     '#collapsed' => false,
241 nancyw 1.19.2.15 '#attributes' => array('class' => 'taxonomy_browser_scope'),
242     );
243 nancyw 1.19.2.13
244 nancyw 1.19.2.1 if (module_exists('node_type_filter')) {
245 nancyw 1.19.2.11 if ($count_nodes) {
246     $total_count = 0;
247 nancyw 1.19.2.20 $result = db_query('SELECT DISTINCT(type), COUNT(nid) AS count FROM {node} WHERE status=1 GROUP BY type ORDER BY type');
248 nancyw 1.19.2.11 while ($counter = db_fetch_array($result)) {
249 nancyw 1.19.2.14 // Check if we know about this type - a disabled module could have orphans.
250 nancyw 1.19.2.20 if (isset($node_types[$counter['type']])) {
251     $node_types[$counter['type']] .= ' ('. $counter['count'] .')';
252 nancyw 1.19.2.14 }
253     else {
254 nancyw 1.19.2.20 $node_types['unknown'] .= '<em>'. $counter['type'];
255     $node_types['unknown'] .= '</em>??? ('. $counter['count'] .') ';
256     watchdog('Taxonomy Browser', 'Unknown content type found: @type', array('@type' => $counter['type']), WATCHDOG_WARNING);
257 nancyw 1.19.2.14 }
258 nancyw 1.19.2.11 $total_count += $counter['count'];
259     }
260     }
261 nancyw 1.19.2.20
262 nancyw 1.19.2.24 $omit = array_filter(variable_get('taxonomy_browser_omit', array()));
263 nancyw 1.19.2.10 if (!empty($omit)) {
264 nancyw 1.19.2.13 foreach ($omit as $omit_type) {
265 nancyw 1.19.2.20 unset($node_types[$omit_type]);
266 nancyw 1.19.2.10 }
267     }
268 nancyw 1.19.2.22 $desc = t('Not selecting any type is the same as selecting all types.');
269     if ($count_nodes) {
270     $desc .= ' '. t('The total count of all types is !count.', array('!count' => $total_count));
271     }
272 jaza 1.17 $form['scope']['node_filter'] = array(
273 nancyw 1.19.2.6 // '#type' => 'checkboxes',
274 nancyw 1.19.2.15 '#type' => $select_type,
275 jaza 1.17 '#title' => t('Restrict search by content type'),
276 nancyw 1.19.2.15 '#options' => $node_types,
277     '#multiple' => true,
278     '#prefix' => '<div class="taxonomy_browser_checkboxes">',
279     '#suffix' => '</div>',
280 nancyw 1.19.2.22 '#description' => $desc,
281 nancyw 1.19.2.14 );
282 jaza 1.17 }
283 nancyw 1.19.2.17 else {
284     $form['scope']['node_filter'] = array(
285     '#type' => value,
286     '#value' => array(),
287     );
288     }
289    
290 jaza 1.17 $form['scope']['operator'] = array(
291     '#type' => 'radios',
292     '#title' => t('Items containing'),
293     '#options' => array(t('<strong>all</strong> terms'), t('<strong>any</strong> terms')),
294 nancyw 1.19.2.16 '#default_value' => variable_get('taxonomy_browser_default_op', 0),
295 nancyw 1.19.2.14 '#prefix' => '<div class="taxonomy_browser_radios">',
296 nancyw 1.19.2.15 '#suffix' => '</div>',
297 nancyw 1.19.2.14 );
298 jaza 1.17
299 nancyw 1.19.2.23 $vocabularies = array_filter(variable_get('taxonomy_browser_vocabularies', array()));
300 nancyw 1.19.2.29 // Occasionally we get a 0 vid in the array.
301     unset($vocabularies[0]);
302    
303 nancyw 1.19.2.18 // Has the admin selected any vocabs?
304     if (count($vocabularies) == 0) {
305 nancyw 1.19.2.23 $vocabs = taxonomy_get_vocabularies();
306     foreach ($vocabs as $vocabulary) {
307     $vocabularies[$vocabulary->vid] = 1;
308     }
309 nancyw 1.19.2.18 }
310 nancyw 1.19.2.17
311 nancyw 1.19.2.13 if ($allow_children) {
312     $form['children'] = array(
313     '#type' => 'fieldset',
314     '#title' => t('Include Children'),
315 nancyw 1.19.2.14 '#collapsible' => true,
316     '#collapsed' => false,
317 nancyw 1.19.2.13 );
318     $form['children']['include_children'] = array(
319     '#type' => 'checkbox',
320     '#title' => t('Automatically include children (sub-terms)'),
321     '#description' => t('If you select a term with children (sub-terms), do you want those child terms automatically included in the search? This requires that "Items containing" be "any."'),
322     );
323     }
324     else {
325 nancyw 1.19.2.14 $form['include_children'] = array(
326 nancyw 1.19.2.13 '#type' => 'value',
327     '#value' => false,
328     );
329     }
330 jaza 1.17
331     $form['taxonomy'] = array(
332     '#type' => 'fieldset',
333     '#title' => t('Categories'),
334 nancyw 1.19.2.5 '#collapsible' => true,
335     '#collapsed' => false,
336 jaza 1.17 '#tree' => TRUE,
337     );
338 weitzman 1.19
339 nancyw 1.19.2.13 $selection_types = array('select', 'checkboxes');
340 weitzman 1.19 $i = 0;
341 nancyw 1.19.2.23 foreach ($vocabularies as $v => $sel) {
342 nancyw 1.19.2.10 $voc = taxonomy_get_vocabulary($v);
343 nancyw 1.19.2.14
344     $voc_node_types = array();
345     foreach ($voc->nodes as $key => $type) {
346     $voc_node_types[] = $node_types[$type];
347     }
348     $count_types = count($voc_node_types);
349     if (count($voc_node_types) == 1) {
350     $node_type_list = $voc_node_types[0];
351     }
352     else {
353     $node_type_list = implode(', ', $voc_node_types);
354     }
355    
356 nancyw 1.19.2.5 $tree = taxonomy_get_tree($v);
357     $term_opts = array();
358    
359     if ($tree) {
360     foreach ($tree as $term) {
361 nancyw 1.19.2.13 $opt_string = null;
362 nancyw 1.19.2.10 if ($count_nodes) {
363 nancyw 1.19.2.25 // $count = db_result(db_query('SELECT COUNT(nid) FROM {term_node} WHERE tid=%d', $term->tid));
364     $count = taxonomy_term_count_nodes($term->tid);
365 nancyw 1.19.2.10 if ($count > 0 || $show_unused) {
366 nancyw 1.19.2.28 $opt_string = decode_entities(check_plain($term->name)) .' ('. $count .')';
367 nancyw 1.19.2.10 }
368     }
369     else {
370 nancyw 1.19.2.28 $opt_string = decode_entities(check_plain($term->name));
371 nancyw 1.19.2.13 }
372     if ($opt_string) {
373     $term_opts[$term->tid] = str_repeat('-', $term->depth) . $opt_string;
374 nancyw 1.19.2.10 }
375 nancyw 1.19.2.5 }
376     }
377    
378 nancyw 1.19.2.21 $vocname = filter_xss($voc->name);
379 nancyw 1.19.2.10 if (!empty($term_opts)) {
380 nancyw 1.19.2.13 $form['taxonomy'][$v] = array(
381     '#type' => $select_type,
382 nancyw 1.19.2.21 '#title' => $vocname,
383 nancyw 1.19.2.10 '#options' => $term_opts,
384     '#multiple' => true,
385 nancyw 1.19.2.15 '#description' => $voc->description
386 nancyw 1.19.2.21 .' &nbsp;'. t('"!name" is used for: !types.', array('!name' => '<strong>'. $vocname .'</strong>', '!types' => $node_type_list)),
387 nancyw 1.19.2.10 '#size' => min(10, count($term_opts)),
388 nancyw 1.19.2.13 '#prefix' => '<div class="taxonomy_browser_'. $select_type .'">',
389 nancyw 1.19.2.15 '#suffix' => '</div>',
390 nancyw 1.19.2.14 '#field_suffix' => $node_type_list,
391 nancyw 1.19.2.10 '#weight' => $i,
392     );
393 nancyw 1.19.2.14 ++$i;
394 nancyw 1.19.2.10 }
395 jaza 1.17 }
396    
397     $form['submit'] = array(
398     '#type' => 'submit',
399     '#value' => t('Search'),
400 nancyw 1.19.2.5 '#submit' => TRUE,
401 nancyw 1.19.2.14 );
402 nancyw 1.19.2.1
403     return $form;
404 jaza 1.17 }
405    
406     /**
407     * Themable form output for the category browser page.
408     */
409     function theme_taxonomy_browser_page($form) {
410     $output = '';
411    
412     $vocabularies = variable_get('taxonomy_browser_vocabularies', array());
413     if (empty($vocabularies)) {
414 nancyw 1.19.2.2 form_set_error('taxonomy_browser_page', t('You must select the vocabularies to display from the <a href="%link">taxonomy browser settings page</a>.', array('%link' => url('admin/settings/taxonomy_browser'))));
415 jaza 1.17 return ' ';
416     }
417    
418 nancyw 1.19.2.2 $output .= drupal_render($form);
419 jaza 1.17 return $output;
420     }
421    
422     /**
423     * Implementation of hook_form_validate().
424     */
425 nancyw 1.19.2.13 function taxonomy_browser_form_validate($form_id, &$form_values) {
426    
427     $include_children = $form_values['include_children'];
428     $tids = _taxonomy_browser_get_tid_list($form_values['taxonomy'], $include_children);
429    
430     $operator = $form_values['operator'] ? 'or' : 'and';
431    
432     if ($operator == 'and' && $include_children == true) {
433     form_set_error('operator', t('You must use "Items containing <strong>any</strong>" to include child terms.'));
434     }
435    
436 jaza 1.17 if (empty($tids)) {
437     form_set_error('taxonomy', t('You must select at least one category in your search.'));
438     }
439     else {
440 nancyw 1.19.2.15 // $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;
441     $node_type = str_replace(',0', '', implode(',', $form_values['node_filter']));
442 nancyw 1.19.2.18
443 jaza 1.17 if (!taxonomy_browser_count_nodes($tids, $operator, 0, $node_type)) {
444     form_set_error('taxonomy', t('No posts match your criteria.'));
445     }
446     }
447     }
448    
449     /**
450     * Implementation of hook_form_submit().
451     */
452 nancyw 1.19.2.13 function taxonomy_browser_form_submit($form_id, &$form_values) {
453 jaza 1.17 $tids = _taxonomy_browser_get_tid_list();
454 nancyw 1.19.2.1
455 jaza 1.17 $operator = $form_values['operator'] ? 'or' : 'and';
456     $str_tids = ($operator == 'and') ? implode(',', $tids) : implode('+', $tids);
457    
458 nancyw 1.19.2.15 $types = array_filter($form_values['node_filter']);
459     $node_type = str_replace(',0', '', implode(',', $types));
460    
461     if ($types) {
462     return array('taxonomy/term/'. $str_tids, 'type='. $node_type);
463     }
464     else {
465     return 'taxonomy/term/'. $str_tids;
466     }
467    
468 jaza 1.17 }
469    
470 nancyw 1.19.2.13 //********************************************************************
471 nancyw 1.19.2.21 //* Module Functions : Private
472 nancyw 1.19.2.13 //********************************************************************
473 jaza 1.17
474     /**
475 nancyw 1.19.2.21 * Get the output to be displayed by the block.
476     *
477     * @param
478     * $delta - integer for the block number.
479     *
480     * @return
481     * array containing the title ("subject") and content of the block.
482     */
483     function _taxonomy_browser_block_view($delta) {
484     $block = array();
485     switch ($delta) {
486     case 0:
487     $block = array(
488     'content' => drupal_get_form('taxonomy_browser_form'),
489     );
490     break;
491     }
492     return $block;
493     }
494    
495     /**
496 jaza 1.17 * Private function to count the number of nodes found by the user's query.
497     */
498     function taxonomy_browser_count_nodes($tids = array(), $operator = 'or', $depth = 0, $nodetype = NULL) {
499     if (count($tids) > 0) {
500     // For each term ID, generate an array of descendant term IDs to the right depth.
501     $descendant_tids = array();
502     if ($depth === 'all') {
503     $depth = NULL;
504     }
505     foreach ($tids as $index => $tid) {
506     $term = taxonomy_get_term($tid);
507     $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
508     $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
509     }
510    
511 nancyw 1.19.2.3 $type_where = null;
512     if ($nodetype) {
513 nancyw 1.19.2.15 // $type_where = "n.type = '". db_escape_string($nodetype) ."'";
514     $type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')";
515 nancyw 1.19.2.3 }
516 nancyw 1.19.2.15
517 jaza 1.17 if ($operator == 'or') {
518     $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
519 nancyw 1.19.2.3 $sql_count = 'SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn USING(nid) WHERE '. ($type_where ? $type_where .' AND ' : null) ."tn.tid IN ($str_tids) ORDER BY n.sticky DESC, n.title ASC";
520 jaza 1.17 }
521     else {
522     $joins = '';
523     $wheres = array();
524 nancyw 1.19.2.3 if ($type_where) {
525     $wheres[] = $type_where;
526     }
527 jaza 1.17 foreach ($descendant_tids as $index => $tids) {
528 nancyw 1.19.2.13 $joins .= 'INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid ';
529 jaza 1.17 $wheres[] = 'tn'. $index .'.tid IN ('. implode(',', $tids) .')';
530     }
531 nancyw 1.19.2.13 $sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE '. implode(' AND ', $wheres);
532 jaza 1.17 }
533    
534 nancyw 1.19.2.15 // drupal_set_message('Count query: '. $sql_count);
535 jaza 1.17 return db_result(db_query(db_rewrite_sql($sql_count)));
536     }
537    
538     return 0;
539     }
540    
541     /**
542     * Transforms an unpredictably and irregularly nested set of tids (as returned
543     * from a taxonomy form) into a linear array of tids.
544     */
545 nancyw 1.19.2.13 function _taxonomy_browser_get_tid_list($tids = null, $include_children = false) {
546 jaza 1.17 static $tid_list;
547 nancyw 1.19.2.13
548 jaza 1.17 if (isset($tids) && is_array($tids)) {
549     $tid_list = array();
550     foreach ($tids as $key => $tid) {
551     if (!empty($tid)) {
552     if (is_array($tid)) {
553     foreach ($tid as $key2 => $tid2) {
554     if (!empty($tid2)) {
555 nancyw 1.19.2.13 $tid_list[$tid2] = $tid2;
556 jaza 1.17 }
557     }
558     }
559     else {
560 nancyw 1.19.2.13 $tid_list[$tid] = $tid;
561 jaza 1.17 }
562 nancyw 1.19.2.13 } /* end !empty */
563     } /* end foreach */
564 jaza 1.17 }
565    
566 nancyw 1.19.2.13 if ($include_children) {
567     foreach ($tid_list as $tid) {
568     _taxonomy_browser_get_kids($tid_list, $tid);
569     }
570     }
571    
572 jaza 1.17 return $tid_list;
573     }
574    
575 nancyw 1.19.2.13 function _taxonomy_browser_get_kids(&$tid_list, $tid) {
576     $children = taxonomy_get_children($tid);
577     if ($children) {
578     foreach ($children as $child_tid => $child_term) {
579     _taxonomy_browser_get_kids($tid_list, $child_tid);
580     }
581     }
582     else {
583     $tid_list[$tid] = $tid;
584     }
585     }
586    
587 jaza 1.17 /**
588     * Provides default guideline text.
589     */
590     function _taxonomy_browser_guidelines_default() {
591     return t('<p>You may select multiple items from each list by holding down the <code>Ctrl</code> (Mac: <code>command</code>) key while left-clicking each item.</p>');
592     }

  ViewVC Help
Powered by ViewVC 1.1.2