/[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.2.11.2.20, Tue Jul 22 00:47:02 2008 UTC revision 1.19.2.11.2.21, Thu Aug 14 14:27:30 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_browser.module,v 1.19.2.11.2.19 2008/06/20 04:07:50 nancyw Exp $  // $Id: taxonomy_browser.module,v 1.19.2.11.2.20 2008/07/22 00:47:02 nancyw Exp $
3  // Original by Moshe Weitzman (weitzmna@tejasa.com)  // Original by Moshe Weitzman (weitzmna@tejasa.com)
4    
5  /**  /**
# Line 63  function taxonomy_browser_help($path, $a Line 63  function taxonomy_browser_help($path, $a
63   * Implementation of hook_perm().   * Implementation of hook_perm().
64   */   */
65  function taxonomy_browser_perm() {  function taxonomy_browser_perm() {
66    if (variable_get('taxonomy_browser_need_perm', false)) {    if (variable_get('taxonomy_browser_need_perm', FALSE)) {
67      return array('access taxonomy browser');      return array('access taxonomy browser');
68    }    }
69    else {    else {
# Line 75  function taxonomy_browser_perm() { Line 75  function taxonomy_browser_perm() {
75   * Implementation of hook_menu_alter().   * Implementation of hook_menu_alter().
76   */   */
77  function taxonomy_browser_menu_alter(&$callbacks) {  function taxonomy_browser_menu_alter(&$callbacks) {
78    $callbacks['taxonomy_browser']['access arguments'] = array(variable_get('taxonomy_browser_need_perm', false) ? 'access taxonomy browser' : 'access content');    $callbacks['taxonomy_browser']['access arguments'] = array(variable_get('taxonomy_browser_need_perm', FALSE) ? 'access taxonomy browser' : 'access content');
79  }  }
80    
81  //********************************************************************  //********************************************************************
# Line 130  function taxonomy_browser_admin_settings Line 130  function taxonomy_browser_admin_settings
130      '#suffix' => '</div>',      '#suffix' => '</div>',
131      );      );
132    
133      $form['taxonomy_browser_collapse'] = array(
134        '#title' => t('Make vocabularies collapsible'),
135        '#type' => 'checkbox',
136        '#default_value' => variable_get('taxonomy_browser_collapse', FALSE),
137        '#description' => t('Do you want to display of the terms within a vocabulary to be collapsible? Requires "Check boxes" above.'),
138        );
139    
140    $form['taxonomy_browser_default_op'] = array(    $form['taxonomy_browser_default_op'] = array(
141      '#title' => t('"Items containing" default'),      '#title' => t('"Items containing" default'),
142      '#type' => 'radios',      '#type' => 'radios',
# Line 143  function taxonomy_browser_admin_settings Line 150  function taxonomy_browser_admin_settings
150    $form['taxonomy_browser_count_nodes'] = array(    $form['taxonomy_browser_count_nodes'] = array(
151      '#title' => t('Show node count'),      '#title' => t('Show node count'),
152      '#type' => 'checkbox',      '#type' => 'checkbox',
153      '#default_value' => variable_get('taxonomy_browser_count_nodes', false),      '#default_value' => variable_get('taxonomy_browser_count_nodes', FALSE),
154      '#description' => t('Do you want to display the count of nodes tagged with each term? This can be SQL-intensive.'),      '#description' => t('Do you want to display the count of nodes tagged with each term? This can be SQL-intensive.'),
155      );      );
156    
157    $form['taxonomy_browser_show_unused'] = array(    $form['taxonomy_browser_show_unused'] = array(
158      '#title' => t('Show unused terms'),      '#title' => t('Show unused terms'),
159      '#type' => 'checkbox',      '#type' => 'checkbox',
160      '#default_value' => variable_get('taxonomy_browser_show_unused', false),      '#default_value' => variable_get('taxonomy_browser_show_unused', FALSE),
161      '#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.'),      '#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.'),
162      );      );
163    
164    $form['taxonomy_browser_allow_children'] = array(    $form['taxonomy_browser_allow_children'] = array(
165      '#title' => t('Allow child terms to be included'),      '#title' => t('Allow child terms to be included'),
166      '#type' => 'checkbox',      '#type' => 'checkbox',
167      '#default_value' => variable_get('taxonomy_browser_allow_children', false),      '#default_value' => variable_get('taxonomy_browser_allow_children', FALSE),
168      '#description' => t('Do you want the user to see a check box to include child terms (sub-terms)?'),      '#description' => t('Do you want the user to see a check box to include child terms (sub-terms)?'),
169      );      );
170    
171    $form['taxonomy_browser_need_perm'] = array(    $form['taxonomy_browser_need_perm'] = array(
172      '#title' => t('Requires permission'),      '#title' => t('Requires permission'),
173      '#type' => 'checkbox',      '#type' => 'checkbox',
174      '#default_value' => variable_get('taxonomy_browser_need_perm', false),      '#default_value' => variable_get('taxonomy_browser_need_perm', FALSE),
175      '#description' => t('Do you want to require permission to see the browser page? If you change this you need to clear the menu cache, such as at <a href="!clear">the Performance page</a>.', array('!clear' => url('admin/settings/performance'))),      '#description' => t('Do you want to require permission to see the browser page? If you change this you need to clear the menu cache, such as at <a href="!clear">the Performance page</a>.', array('!clear' => url('admin/settings/performance'))),
176      );      );
177    
178      $form['taxonomy_browser_show_types'] = array(
179        '#title' => t('Show content types with vocabulary'),
180        '#type' => 'checkbox',
181        '#default_value' => variable_get('taxonomy_browser_show_types', FALSE),
182        '#description' => t('If checked, this option displays a list of the content types for which this vocabulary may be used.'),
183        );
184    
185    $select = array();    $select = array();
186    $vocabularies = taxonomy_get_vocabularies();    $vocabularies = taxonomy_get_vocabularies();
187    foreach ($vocabularies as $vocabulary) {    foreach ($vocabularies as $vocabulary) {
# Line 201  function taxonomy_browser_admin_settings Line 215  function taxonomy_browser_admin_settings
215  }  }
216    
217  function taxonomy_browser_admin_settings_validate($form, &$form_state) {  function taxonomy_browser_admin_settings_validate($form, &$form_state) {
218    if ($form_state['values']['taxonomy_browser_count_nodes'] == false    if ($form_state['values']['taxonomy_browser_count_nodes'] == FALSE
219      && $form_state['values']['taxonomy_browser_show_unused'] == true) {      && $form_state['values']['taxonomy_browser_show_unused'] == TRUE) {
220      form_set_error('taxonomy_browser_show_unused', t('"Show unused" requires "count nodes."'));      form_set_error('taxonomy_browser_show_unused', t('"Show unused" requires "count nodes."'));
221    }    }
222  }  }
# Line 224  function taxonomy_browser_form() { Line 238  function taxonomy_browser_form() {
238    $form = array();    $form = array();
239    $selection_types = array('select', 'checkboxes');    $selection_types = array('select', 'checkboxes');
240    $select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)];    $select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)];
241    $count_nodes = variable_get('taxonomy_browser_count_nodes', false);    $collapsible = variable_get('taxonomy_browser_collapse', FALSE) && ($select_type == 'checkboxes');
242    $show_unused = variable_get('taxonomy_browser_show_unused', false);    $count_nodes = variable_get('taxonomy_browser_count_nodes', FALSE);
243    $allow_children = variable_get('taxonomy_browser_allow_children', false);    $show_unused = variable_get('taxonomy_browser_show_unused', FALSE);
244      $allow_children = variable_get('taxonomy_browser_allow_children', FALSE);
245    $node_types = node_get_types('names');    $node_types = node_get_types('names');
246    
247    $form['scope'] = array(    $form['scope'] = array(
248      '#type' => 'fieldset',      '#type' => 'fieldset',
249      '#title' => t('Scope'),      '#title' => t('Scope'),
250      '#collapsible' => true,      '#collapsible' => TRUE,
251      '#collapsed' => false,      '#collapsed' => FALSE,
252      '#attributes' => array('class' => 'taxonomy_browser_scope'),      '#attributes' => array('class' => 'taxonomy_browser_scope'),
253      );      );
254    
# Line 247  function taxonomy_browser_form() { Line 262  function taxonomy_browser_form() {
262            $node_types[$counter['type']] .= ' ('. $counter['count'] .')';            $node_types[$counter['type']] .= ' ('. $counter['count'] .')';
263          }          }
264          else {          else {
265            $node_types['unknown'] .= '<em>'. $counter['type'];            $node_types['unknown'] .= $counter['type'] .' ??? ('. $counter['count'] .') ';
           $node_types['unknown'] .= '</em>??? ('. $counter['count'] .') ';  
266            watchdog('Taxonomy Browser', 'Unknown content type found: @type', array('@type' => $counter['type']), WATCHDOG_WARNING);            watchdog('Taxonomy Browser', 'Unknown content type found: @type', array('@type' => $counter['type']), WATCHDOG_WARNING);
267          }          }
268          $total_count += $counter['count'];          $total_count += $counter['count'];
# Line 269  function taxonomy_browser_form() { Line 283  function taxonomy_browser_form() {
283        '#type' => $select_type,        '#type' => $select_type,
284        '#title' => t('Restrict search by content type'),        '#title' => t('Restrict search by content type'),
285        '#options' => $node_types,        '#options' => $node_types,
286        '#multiple' => true,        '#multiple' => TRUE,
287        '#prefix' => '<div class="taxonomy_browser_checkboxes">',        '#prefix' => '<div class="taxonomy_browser_checkboxes">',
288        '#suffix' => '</div>',        '#suffix' => '</div>',
289        '#description' => $desc,        '#description' => $desc,
# Line 304  function taxonomy_browser_form() { Line 318  function taxonomy_browser_form() {
318      $form['children'] = array(      $form['children'] = array(
319        '#type' => 'fieldset',        '#type' => 'fieldset',
320        '#title' => t('Include Children'),        '#title' => t('Include Children'),
321        '#collapsible' => true,        '#collapsible' => TRUE,
322        '#collapsed' => false,        '#collapsed' => FALSE,
323        );        );
324      $form['children']['include_children'] = array(      $form['children']['include_children'] = array(
325        '#type' => 'checkbox',        '#type' => 'checkbox',
# Line 316  function taxonomy_browser_form() { Line 330  function taxonomy_browser_form() {
330    else {    else {
331      $form['include_children'] = array(      $form['include_children'] = array(
332        '#type' => 'value',        '#type' => 'value',
333        '#value' => false,        '#value' => FALSE,
334        );        );
335    }    }
336    
337    $form['taxonomy'] = array(    $form['taxonomy'] = array(
338      '#type' => 'fieldset',      '#type' => 'fieldset',
339      '#title' => t('Categories'),      '#title' => t('Categories'),
340      '#collapsible' => true,      '#collapsible' => TRUE,
341      '#collapsed' => false,      '#collapsed' => FALSE,
342      '#tree' => TRUE,      '#tree' => TRUE,
343    );    );
344    
# Line 356  function taxonomy_browser_form() { Line 370  function taxonomy_browser_form() {
370    
371      if ($tree) {      if ($tree) {
372        foreach ($tree as $term) {        foreach ($tree as $term) {
373          $opt_string = null;          $opt_string = NULL;
374          if ($count_nodes) {          if ($count_nodes) {
375            $count = taxonomy_term_count_nodes($term->tid);            $count = taxonomy_term_count_nodes($term->tid);
376            if ($count > 0 || $show_unused) {            if ($count > 0 || $show_unused) {
# Line 373  function taxonomy_browser_form() { Line 387  function taxonomy_browser_form() {
387      }      }
388    
389      $vocname = check_plain($voc->name);      $vocname = check_plain($voc->name);
390      $description = $voc->description ? decode_entities(check_markup($voc->description)) : null;      $description = $voc->description ? decode_entities(check_markup($voc->description)) : NULL;
391      $description .= t('"!name" is used for: !types.', array('!name' => '<strong>'. $vocname .'</strong>', '!types' => (empty($node_type_list) ? '<em>'. t('nothing') .'</em>' : $node_type_list)));      if (variable_get('taxonomy_browser_show_types', FALSE)) {
392          $description .= t('"!name" is used for: !types.', array('!name' => '<strong>'. $vocname .'</strong>', '!types' => (empty($node_type_list) ? '<em>'. t('nothing') .'</em>' : $node_type_list)));
393        }
394    
395      if (!empty($term_opts)) {      if (!empty($term_opts)) {
396        $form['taxonomy'][$v] = array(        $voc_element = array(
397          '#type' => $select_type,          '#type' => $select_type,
398          '#title' => $vocname,          '#title' => $vocname,
399          '#options' => $term_opts,          '#options' => $term_opts,
400          '#multiple' => true,          '#multiple' => TRUE,
401          '#description' => $description,          '#description' => $description,
         '#size' => min(10, count($term_opts)),  
402          '#prefix' => '<div class="taxonomy_browser_'. $select_type .'">',          '#prefix' => '<div class="taxonomy_browser_'. $select_type .'">',
403          '#suffix' => '</div>',          '#suffix' => '</div>',
404          '#field_suffix' => $node_type_list,          '#field_suffix' => $node_type_list,
405          '#weight' => $i,          '#weight' => $i,
406          );          );
407    
408          if ($collapsible) {
409            $fld_set = 'set'. $voc->vid;
410            $form['taxonomy'][$fld_set] = array(
411              '#type' => 'fieldset',
412              '#title' => $vocname,
413              '#collapsible' => TRUE,
414              '#collapsed' => TRUE,
415              );
416            $form['taxonomy'][$fld_set][$v] = $voc_element;
417          }
418          else {
419            $form['taxonomy'][$v] = $voc_element;
420          }
421        ++$i;        ++$i;
422      }      }
423    }    }
# Line 438  function taxonomy_browser_form_validate( Line 468  function taxonomy_browser_form_validate(
468    
469    $operator = $form_state['values']['operator'] ? 'or' : 'and';    $operator = $form_state['values']['operator'] ? 'or' : 'and';
470    
471    if ($operator == 'and' && $include_children == true) {    if ($operator == 'and' && $include_children == TRUE) {
472      form_set_error('operator', t('You must use "Items containing <strong>any</strong>" to include child terms.'));      form_set_error('operator', t('You must use "Items containing <strong>any</strong>" to include child terms.'));
473    }    }
474    
# Line 518  function taxonomy_browser_count_nodes($t Line 548  function taxonomy_browser_count_nodes($t
548        $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));
549      }      }
550    
551      $type_where = null;      $type_where = NULL;
552      if ($nodetype) {      if ($nodetype) {
553  //      $type_where = "n.type = '". db_escape_string($nodetype) ."'";  //      $type_where = "n.type = '". db_escape_string($nodetype) ."'";
554        $type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')";        $type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')";
# Line 527  function taxonomy_browser_count_nodes($t Line 557  function taxonomy_browser_count_nodes($t
557      if ($operator == 'or') {      if ($operator == 'or') {
558        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
559    
560        $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 USING(nid) WHERE '. ($type_where ? $type_where .' AND ' : NULL) ."tn.tid IN ($str_tids) ORDER BY n.sticky DESC, n.title ASC";
561      }      }
562      else {      else {
563        $joins = '';        $joins = '';
# Line 552  function taxonomy_browser_count_nodes($t Line 582  function taxonomy_browser_count_nodes($t
582   * Transforms an unpredictably and irregularly nested set of tids (as returned   * Transforms an unpredictably and irregularly nested set of tids (as returned
583   * from a taxonomy form) into a linear array of tids.   * from a taxonomy form) into a linear array of tids.
584   */   */
585  function _taxonomy_browser_get_tid_list($tids = null, $include_children = false) {  function _taxonomy_browser_get_tid_list($tids = NULL, $include_children = FALSE) {
586    static $tid_list;    static $tid_list;
587    
588    if (isset($tids) && is_array($tids)) {    if (isset($tids) && is_array($tids)) {

Legend:
Removed from v.1.19.2.11.2.20  
changed lines
  Added in v.1.19.2.11.2.21

  ViewVC Help
Powered by ViewVC 1.1.2