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

Diff of /contributions/modules/taxonomy_browser/taxonomy_browser.module

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

revision 1.19, Thu Feb 1 18:52:00 2007 UTC revision 1.19.2.27, Mon Jun 16 19:09:14 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_browser.module,v 1.18 2007/02/01 18:43:57 weitzman Exp $  // $Id: taxonomy_browser.module,v 1.19.2.26 2008/06/11 18:20:50 nancyw Exp $
3  // Original by Moshe Weitzman (weitzmna@tejasa.com)  // Original by Moshe Weitzman (weitzmna@tejasa.com)
4    
5  /**  /**
6   * @file   * @file
7   * Enables users to construct their own view of content from terms across   *   Enables users to construct their own view of content from terms across
8   * multiple vocabularies.   *   multiple vocabularies.
9   */   */
10    
11  /********************************************************************  //*******************************************************************
12   * Drupal Hooks :: General Overview  //* Drupal Hooks : General Overview
13   ********************************************************************/  //*******************************************************************
14    
15  /**  /**
16   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 19  function taxonomy_browser_menu($may_cach Line 19  function taxonomy_browser_menu($may_cach
19    $items = array();    $items = array();
20    
21    if ($may_cache) {    if ($may_cache) {
22      $items[] = array('path' => 'taxonomy_browser', 'title' => t('category browser'),      $items[] = array(
23        'access' => user_access('access content'),        '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        $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',        'callback' => 'taxonomy_browser_page',
37        'weight' => 7,        'description' => t('Find content on your own terms.'),
38        'type' => MENU_NORMAL_ITEM);        'type' => MENU_NORMAL_ITEM,
39          );
40    
41        drupal_add_css(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.css');
42    }    }
43    
44    return $items;    return $items;
# Line 37  function taxonomy_browser_help($section Line 52  function taxonomy_browser_help($section
52      case 'admin/modules#description':      case 'admin/modules#description':
53        return t('An interface for viewing content grouped by arbitrary taxonomy terms.');        return t('An interface for viewing content grouped by arbitrary taxonomy terms.');
54      case 'taxonomy_browser':      case 'taxonomy_browser':
55        return variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default());        $output = check_markup(variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()));
56          if (user_access('administer site configuration')) {
57            $output .= '<p class="links">'. l(t('Go to Taxonomy Browser settings'), 'admin/settings/taxonomy-browser', array(), drupal_get_destination()) .'</p>';
58          }
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    }    }
73  }  }
74    
75  /********************************************************************  //********************************************************************
76   * Drupal Hooks :: Core  //* Drupal Hooks : Core
77   ********************************************************************/  //********************************************************************
78    
79    /**
80     * 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          switch ($delta) {
91            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   * Implementation of hook_settings().   * Implementation of hook_form().
107   */   */
108  function taxonomy_browser_settings() {  function taxonomy_browser_admin_settings() {
109    if (!module_exist('node_type_filter') && !drupal_set_message()) {    if (!module_exists('node_type_filter') && !drupal_set_message()) {
110      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.'));      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    }    }
112    
113      drupal_add_js(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.js', 'module');
114    
115    $form['taxonomy_browser_guidelines'] = array(    $form['taxonomy_browser_guidelines'] = array(
116      '#title' => t('Guidelines'),      '#title' => t('Guidelines'),
117      '#type' => 'textarea',      '#type' => 'textarea',
118      '#default_value' => variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()),      '#default_value' => variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()),
119      '#rows' => 6,      '#rows' => 2,
120      '#description' => t('Instructions which should appear at top of the category browser main page'),      '#description' => t('Instructions which should appear at top of the category browser main page'),
121    );      );
122    
123      $form['taxonomy_browser_select_type'] = array(
124        '#title' => t('Selection type'),
125        '#type' => 'radios',
126        '#default_value' => variable_get('taxonomy_browser_select_type', 1),
127        '#options' => array(t('Selection box'), t('Check boxes')),
128        '#description' => t('This option determines whether the user will see a selection list or check boxes.'),
129        '#prefix' => '<div class="taxonomy_browser_radios">',
130        '#suffix' => '</div>',
131        );
132    
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    
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        );
149    
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        '#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        );
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    
164      $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      $select = array();
172    $vocabularies = taxonomy_get_vocabularies();    $vocabularies = taxonomy_get_vocabularies();
173    foreach ($vocabularies as $vocabulary) {    foreach ($vocabularies as $vocabulary) {
174      $select[$vocabulary->vid] = $vocabulary->name;      $select[$vocabulary->vid] = $vocabulary->name;
175    }    }
176    
177    $form['taxonomy_browser_vocabularies'] = array(    $form['taxonomy_browser_vocabularies'] = array(
178      '#title' => t('Included Vocabularies'),      '#title' => t('Included Vocabularies'),
179      '#type' => 'select',      '#type' => 'checkboxes',
180      '#default_value' => variable_get('taxonomy_browser_vocabularies', array()),      '#default_value' => variable_get('taxonomy_browser_vocabularies', array()),
181      '#options' => $select,      '#options' => $select,
182      '#description' => t('Select the vocabularies the user can select from on the category browser page'),      '#description' => t('Select the vocabularies the user can select from on the category browser page.'),
183      '#multiple' => TRUE,      '#prefix' => '<div class="taxonomy_browser_checkboxes">',
184      '#size' => 6,      '#suffix' => '</div>',
185    );      );
186    
187    return $form;    if (module_exists('node_type_filter')) {
188        $filter_options = node_get_types('names');
189        $form['taxonomy_browser_omit'] = array(
190          '#type' => 'checkboxes',
191          '#title' => t('Omit content types'),
192          '#options' => $filter_options,
193          '#default_value' => variable_get('taxonomy_browser_omit', array('')),
194          '#description' => t('If any of these types is selected, it will be omitted from the list on the "Category Browser" page.'),
195          '#prefix' => '<div class="taxonomy_browser_checkboxes">',
196          '#suffix' => '</div>',
197          );
198      }
199    
200      return system_settings_form($form);
201    }
202    
203    function taxonomy_browser_admin_settings_validate($form_id, &$form_values) {
204      if ($form_values['taxonomy_browser_count_nodes'] == false
205        && $form_values['taxonomy_browser_show_unused'] == true) {
206        form_set_error('taxonomy_browser_show_unused', t('"Show unused" requires "count nodes."'));
207      }
208  }  }
209    
210  /********************************************************************  //********************************************************************
211   * Module Functions :: Public  //* Module Functions : Public
212   ********************************************************************/  //********************************************************************
213    
214  /**  /**
215   * Menu callback: the query building interface for nodes selected based on   * Menu callback: the query building interface for nodes selected based on
216   * taxonomy terms.   * taxonomy terms.
217   */   */
218  function taxonomy_browser_page() {  function taxonomy_browser_page() {
219      $output .= drupal_get_form('taxonomy_browser_form');
220      return $output;
221    }
222    
223    function taxonomy_browser_form() {
224    $form = array();    $form = array();
225      $selection_types = array('select', 'checkboxes');
226      $select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)];
227      $count_nodes = variable_get('taxonomy_browser_count_nodes', false);
228      $show_unused = variable_get('taxonomy_browser_show_unused', false);
229      $allow_children = variable_get('taxonomy_browser_allow_children', false);
230      $node_types = node_get_types('names');
231    
232    $form['scope'] = array(    $form['scope'] = array(
233      '#type' => 'fieldset',      '#type' => 'fieldset',
234      '#title' => t('Scope'),      '#title' => t('Scope'),
235      '#collapsible' => FALSE,      '#collapsible' => true,
236    );      '#collapsed' => false,
237        '#attributes' => array('class' => 'taxonomy_browser_scope'),
238    if (module_exist('node_type_filter')) {      );
239      $filter_options['all'] = t('all');  
240      foreach (node_get_types() as $type => $name) {    if (module_exists('node_type_filter')) {
241        $filter_options[$type] = $name;      if ($count_nodes) {
242          $total_count = 0;
243          $result = db_query('SELECT DISTINCT(type), COUNT(nid) AS count FROM {node} WHERE status=1 GROUP BY type ORDER BY type');
244          while ($counter = db_fetch_array($result)) {
245            // Check if we know about this type - a disabled module could have orphans.
246            if (isset($node_types[$counter['type']])) {
247              $node_types[$counter['type']] .= ' ('. $counter['count'] .')';
248            }
249            else {
250              $node_types['unknown'] .= '<em>'. $counter['type'];
251              $node_types['unknown'] .= '</em>??? ('. $counter['count'] .') ';
252              watchdog('Taxonomy Browser', 'Unknown content type found: @type', array('@type' => $counter['type']), WATCHDOG_WARNING);
253            }
254            $total_count += $counter['count'];
255          }
256        }
257    
258        $omit = array_filter(variable_get('taxonomy_browser_omit', array()));
259        if (!empty($omit)) {
260          foreach ($omit as $omit_type) {
261            unset($node_types[$omit_type]);
262          }
263        }
264        $desc = t('Not selecting any type is the same as selecting all types.');
265        if ($count_nodes) {
266          $desc .= ' '. t('The total count of all types is !count.', array('!count' => $total_count));
267      }      }
268      $form['scope']['node_filter'] = array(      $form['scope']['node_filter'] = array(
269        '#type' => 'radios',  //      '#type' => 'checkboxes',
270          '#type' => $select_type,
271        '#title' => t('Restrict search by content type'),        '#title' => t('Restrict search by content type'),
272        '#options' => $filter_options,        '#options' => $node_types,
273        '#default_value' => 'all',        '#multiple' => true,
274      );        '#prefix' => '<div class="taxonomy_browser_checkboxes">',
275          '#suffix' => '</div>',
276          '#description' => $desc,
277          );
278    }    }
279      else {
280        $form['scope']['node_filter'] = array(
281          '#type' => value,
282          '#value' => array(),
283          );
284      }
285    
286    $form['scope']['operator'] = array(    $form['scope']['operator'] = array(
287      '#type' => 'radios',      '#type' => 'radios',
288      '#title' => t('Items containing'),      '#title' => t('Items containing'),
289      '#options' => array(t('<strong>all</strong> terms'), t('<strong>any</strong> terms')),      '#options' => array(t('<strong>all</strong> terms'), t('<strong>any</strong> terms')),
290      '#default_value' => 0,      '#default_value' => variable_get('taxonomy_browser_default_op', 0),
291    );      '#prefix' => '<div class="taxonomy_browser_radios">',
292        '#suffix' => '</div>',
293        );
294    
295    $vocabularies = variable_get('taxonomy_browser_vocabularies', array());    $vocabularies = array_filter(variable_get('taxonomy_browser_vocabularies', array()));
296    //  drupal_set_message('variable: '. print_r($vocabularies, true));
297      // Has the admin selected any vocabs?
298      if (count($vocabularies) == 0) {
299        $vocabs = taxonomy_get_vocabularies();
300        foreach ($vocabs as $vocabulary) {
301          $vocabularies[$vocabulary->vid] = 1;
302        }
303    //  drupal_set_message('all: '. print_r($vocabularies, true));
304      }
305    
306      if ($allow_children) {
307        $form['children'] = array(
308          '#type' => 'fieldset',
309          '#title' => t('Include Children'),
310          '#collapsible' => true,
311          '#collapsed' => false,
312          );
313        $form['children']['include_children'] = array(
314          '#type' => 'checkbox',
315          '#title' => t('Automatically include children (sub-terms)'),
316          '#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."'),
317          );
318      }
319      else {
320        $form['include_children'] = array(
321          '#type' => 'value',
322          '#value' => false,
323          );
324      }
325    
326    $form['taxonomy'] = array(    $form['taxonomy'] = array(
327      '#type' => 'fieldset',      '#type' => 'fieldset',
328      '#title' => t('Categories'),      '#title' => t('Categories'),
329        '#collapsible' => true,
330        '#collapsed' => false,
331      '#tree' => TRUE,      '#tree' => TRUE,
332    );    );
333    
334      $selection_types = array('select', 'checkboxes');
335    $i = 0;    $i = 0;
336    foreach ($vocabularies as $v) {    foreach ($vocabularies as $v => $sel) {
337      $form['taxonomy'][$v] = taxonomy_form($v);      $voc = taxonomy_get_vocabulary($v);
338      $form['taxonomy'][$v]['#weight'] = $i;  
339      $i++;      $voc_node_types = array();
340        foreach ($voc->nodes as $key => $type) {
341          $voc_node_types[] = $node_types[$type];
342        }
343        $count_types = count($voc_node_types);
344        if (count($voc_node_types) == 1) {
345          $node_type_list = $voc_node_types[0];
346        }
347        else {
348          $node_type_list = implode(', ', $voc_node_types);
349        }
350    
351        $tree = taxonomy_get_tree($v);
352        $term_opts = array();
353    
354        if ($tree) {
355          foreach ($tree as $term) {
356            $opt_string = null;
357            if ($count_nodes) {
358    //          $count = db_result(db_query('SELECT COUNT(nid) FROM {term_node} WHERE tid=%d', $term->tid));
359              $count = taxonomy_term_count_nodes($term->tid);
360              if ($count > 0 || $show_unused) {
361                $opt_string = htmlspecialchars_decode(check_plain($term->name), ENT_QUOTES) .' ('. $count .')';
362              }
363            }
364            else {
365              $opt_string = htmlspecialchars_decode(check_plain($term->name), ENT_QUOTES);
366            }
367            if ($opt_string) {
368              $term_opts[$term->tid] = str_repeat('-', $term->depth) . $opt_string;
369            }
370          }
371        }
372    
373        $vocname = filter_xss($voc->name);
374        if (!empty($term_opts)) {
375          $form['taxonomy'][$v] = array(
376            '#type' => $select_type,
377            '#title' => $vocname,
378            '#options' => $term_opts,
379            '#multiple' => true,
380            '#description' => $voc->description
381               .' &nbsp;'. t('"!name" is used for: !types.', array('!name' => '<strong>'. $vocname .'</strong>', '!types' => $node_type_list)),
382            '#size' => min(10, count($term_opts)),
383            '#prefix' => '<div class="taxonomy_browser_'. $select_type .'">',
384            '#suffix' => '</div>',
385            '#field_suffix' => $node_type_list,
386            '#weight' => $i,
387            );
388          ++$i;
389        }
390    }    }
391    
392    $form['submit'] = array(    $form['submit'] = array(
393      '#type' => 'submit',      '#type' => 'submit',
394      '#value' => t('Search'),      '#value' => t('Search'),
395    );      '#submit' => TRUE,
396        );
397    return drupal_get_form('taxonomy_browser_page', $form);  
398      return $form;
399  }  }
400    
401  /**  /**
# Line 146  function theme_taxonomy_browser_page($fo Line 406  function theme_taxonomy_browser_page($fo
406    
407    $vocabularies = variable_get('taxonomy_browser_vocabularies', array());    $vocabularies = variable_get('taxonomy_browser_vocabularies', array());
408    if (empty($vocabularies)) {    if (empty($vocabularies)) {
409      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'))));      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'))));
410      return ' ';      return ' ';
411    }    }
412    
413    $output .= form_render($form);    $output .= drupal_render($form);
414    return $output;    return $output;
415  }  }
416    
417  /**  /**
418   * Implementation of hook_form_validate().   * Implementation of hook_form_validate().
419   */   */
420  function taxonomy_browser_page_validate($form_id, $form_values) {  function taxonomy_browser_form_validate($form_id, &$form_values) {
421    $tids = _taxonomy_browser_get_tid_list($form_values['taxonomy']);  
422      $include_children = $form_values['include_children'];
423      $tids = _taxonomy_browser_get_tid_list($form_values['taxonomy'], $include_children);
424    
425      $operator = $form_values['operator'] ? 'or' : 'and';
426    
427      if ($operator == 'and' && $include_children == true) {
428        form_set_error('operator', t('You must use "Items containing <strong>any</strong>" to include child terms.'));
429      }
430    
431    if (empty($tids)) {    if (empty($tids)) {
432      form_set_error('taxonomy', t('You must select at least one category in your search.'));      form_set_error('taxonomy', t('You must select at least one category in your search.'));
433    }    }
434    else {    else {
435      $operator = $form_values['operator'] ? 'or' : 'and';  //    $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;
436      $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;      $node_type = str_replace(',0', '', implode(',', $form_values['node_filter']));
437    
438      if (!taxonomy_browser_count_nodes($tids, $operator, 0, $node_type)) {      if (!taxonomy_browser_count_nodes($tids, $operator, 0, $node_type)) {
439        form_set_error('taxonomy', t('No posts match your criteria.'));        form_set_error('taxonomy', t('No posts match your criteria.'));
440      }      }
# Line 175  function taxonomy_browser_page_validate( Line 444  function taxonomy_browser_page_validate(
444  /**  /**
445   * Implementation of hook_form_submit().   * Implementation of hook_form_submit().
446   */   */
447  function taxonomy_browser_page_submit($form_id, $form_values) {  function taxonomy_browser_form_submit($form_id, &$form_values) {
448    $tids = _taxonomy_browser_get_tid_list();    $tids = _taxonomy_browser_get_tid_list();
449    
450    $operator = $form_values['operator'] ? 'or' : 'and';    $operator = $form_values['operator'] ? 'or' : 'and';
451    $str_tids = ($operator == 'and') ? implode(',', $tids) : implode('+', $tids);    $str_tids = ($operator == 'and') ? implode(',', $tids) : implode('+', $tids);
   $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;  
452    
453    return array('taxonomy/term/'. $str_tids, (isset($node_type) ? 'type='. $node_type : ''));    $types = array_filter($form_values['node_filter']);
454      $node_type = str_replace(',0', '', implode(',', $types));
455    
456      if ($types) {
457        return array('taxonomy/term/'. $str_tids, 'type='. $node_type);
458      }
459      else {
460        return 'taxonomy/term/'. $str_tids;
461      }
462    
463  }  }
464    
465  /********************************************************************  //********************************************************************
466   * Module Functions :: Private  //* Module Functions : Private
467   ********************************************************************/  //********************************************************************
468    
469    /**
470     * Get the output to be displayed by the block.
471     *
472     * @param
473     *   $delta - integer for the block number.
474     *
475     * @return
476     *   array containing the title ("subject") and content of the block.
477     */
478    function _taxonomy_browser_block_view($delta) {
479      $block = array();
480      switch ($delta) {
481        case 0:
482          $block = array(
483            'content' => drupal_get_form('taxonomy_browser_form'),
484            );
485          break;
486      }
487      return $block;
488    }
489    
490  /**  /**
491   * Private function to count the number of nodes found by the user's query.   * Private function to count the number of nodes found by the user's query.
# Line 204  function taxonomy_browser_count_nodes($t Line 503  function taxonomy_browser_count_nodes($t
503        $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));        $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
504      }      }
505    
506      $type_where = $nodetype ? "n.type = '". db_escape_string($nodetype). "'" : 1;      $type_where = null;
507        if ($nodetype) {
508    //      $type_where = "n.type = '". db_escape_string($nodetype) ."'";
509          $type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')";
510        }
511    
512      if ($operator == 'or') {      if ($operator == 'or') {
513        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
514          $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";
       $sql_count = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE $type_where AND tn.tid IN ($str_tids) ORDER BY n.sticky DESC, n.title ASC";  
515      }      }
516      else {      else {
517        $joins = '';        $joins = '';
518        $wheres = array();        $wheres = array();
519        $wheres[] = $type_where;        if ($type_where) {
520            $wheres[] = $type_where;
521          }
522        foreach ($descendant_tids as $index => $tids) {        foreach ($descendant_tids as $index => $tids) {
523          $joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';          $joins .= 'INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid ';
524          $wheres[] = 'tn'. $index .'.tid IN ('. implode(',', $tids) .')';          $wheres[] = 'tn'. $index .'.tid IN ('. implode(',', $tids) .')';
525        }        }
526        $sql_count = "SELECT COUNT(n.nid) FROM {node} n $joins WHERE ". implode(' AND ', $wheres);        $sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE '. implode(' AND ', $wheres);
527      }      }
528    
529    //    drupal_set_message('Count query: '. $sql_count);
530      return db_result(db_query(db_rewrite_sql($sql_count)));      return db_result(db_query(db_rewrite_sql($sql_count)));
531    }    }
532    
# Line 231  function taxonomy_browser_count_nodes($t Line 537  function taxonomy_browser_count_nodes($t
537   * Transforms an unpredictably and irregularly nested set of tids (as returned   * Transforms an unpredictably and irregularly nested set of tids (as returned
538   * from a taxonomy form) into a linear array of tids.   * from a taxonomy form) into a linear array of tids.
539   */   */
540  function _taxonomy_browser_get_tid_list($tids = NULL) {  function _taxonomy_browser_get_tid_list($tids = null, $include_children = false) {
541    static $tid_list;    static $tid_list;
542    
543    if (isset($tids) && is_array($tids)) {    if (isset($tids) && is_array($tids)) {
544      $tid_list = array();      $tid_list = array();
545      foreach ($tids as $key => $tid) {      foreach ($tids as $key => $tid) {
# Line 241  function _taxonomy_browser_get_tid_list( Line 547  function _taxonomy_browser_get_tid_list(
547          if (is_array($tid)) {          if (is_array($tid)) {
548            foreach ($tid as $key2 => $tid2) {            foreach ($tid as $key2 => $tid2) {
549              if (!empty($tid2)) {              if (!empty($tid2)) {
550                $tid_list[] = $tid2;                $tid_list[$tid2] = $tid2;
551              }              }
552            }            }
553          }          }
554          else {          else {
555            $tid_list[] = $tid;            $tid_list[$tid] = $tid;
556          }          }
557        }        } /* end !empty */
558      }      } /* end foreach */
559    }    }
560    
561      if ($include_children) {
562        foreach ($tid_list as $tid) {
563          _taxonomy_browser_get_kids($tid_list, $tid);
564        }
565      }
566    
567    return $tid_list;    return $tid_list;
568  }  }
569    
570    function _taxonomy_browser_get_kids(&$tid_list, $tid) {
571      $children = taxonomy_get_children($tid);
572      if ($children) {
573        foreach ($children as $child_tid => $child_term) {
574          _taxonomy_browser_get_kids($tid_list, $child_tid);
575        }
576      }
577      else {
578        $tid_list[$tid] = $tid;
579      }
580    }
581    
582  /**  /**
583   * Provides default guideline text.   * Provides default guideline text.
584   */   */
585  function _taxonomy_browser_guidelines_default() {  function _taxonomy_browser_guidelines_default() {
586    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>');    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>');
587  }  }
   
 ?>  

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.19.2.27

  ViewVC Help
Powered by ViewVC 1.1.2