| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_browser.module,v 1.19.2.29 2008/06/26 16:30:54 nancyw Exp $ |
// $Id: taxonomy_browser.module,v 1.19.2.30 2008/07/22 00:47:13 nancyw Exp $ |
| 3 |
// Original by Moshe Weitzman (weitzmna@tejasa.com) |
// Original by Moshe Weitzman (weitzmna@tejasa.com) |
| 4 |
|
|
| 5 |
/** |
/** |
| 32 |
$items[] = array( |
$items[] = array( |
| 33 |
'path' => 'taxonomy_browser', |
'path' => 'taxonomy_browser', |
| 34 |
'title' => t('Category Browser'), |
'title' => t('Category Browser'), |
| 35 |
'access' => user_access(variable_get('taxonomy_browser_need_perm', false) ? 'access taxonomy browser' : 'access content'), |
'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 |
'description' => t('Find content on your own terms.'), |
'description' => t('Find content on your own terms.'), |
| 38 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 64 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 65 |
*/ |
*/ |
| 66 |
function taxonomy_browser_perm() { |
function taxonomy_browser_perm() { |
| 67 |
if (variable_get('taxonomy_browser_need_perm', false)) { |
if (variable_get('taxonomy_browser_need_perm', FALSE)) { |
| 68 |
return array('access taxonomy browser'); |
return array('access taxonomy browser'); |
| 69 |
} |
} |
| 70 |
else { |
else { |
| 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', |
| 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?'), |
'#description' => t('Do you want to require permission to see the browser page?'), |
| 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) { |
| 219 |
} |
} |
| 220 |
|
|
| 221 |
function taxonomy_browser_admin_settings_validate($form_id, &$form_values) { |
function taxonomy_browser_admin_settings_validate($form_id, &$form_values) { |
| 222 |
if ($form_values['taxonomy_browser_count_nodes'] == false |
if ($form_values['taxonomy_browser_count_nodes'] == FALSE |
| 223 |
&& $form_values['taxonomy_browser_show_unused'] == true) { |
&& $form_values['taxonomy_browser_show_unused'] == TRUE) { |
| 224 |
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."')); |
| 225 |
} |
} |
| 226 |
} |
} |
| 242 |
$form = array(); |
$form = array(); |
| 243 |
$selection_types = array('select', 'checkboxes'); |
$selection_types = array('select', 'checkboxes'); |
| 244 |
$select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)]; |
$select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)]; |
| 245 |
$count_nodes = variable_get('taxonomy_browser_count_nodes', false); |
$collapsible = variable_get('taxonomy_browser_collapse', FALSE) && ($select_type == 'checkboxes'); |
| 246 |
$show_unused = variable_get('taxonomy_browser_show_unused', false); |
$count_nodes = variable_get('taxonomy_browser_count_nodes', FALSE); |
| 247 |
$allow_children = variable_get('taxonomy_browser_allow_children', false); |
$show_unused = variable_get('taxonomy_browser_show_unused', FALSE); |
| 248 |
|
$allow_children = variable_get('taxonomy_browser_allow_children', FALSE); |
| 249 |
$node_types = node_get_types('names'); |
$node_types = node_get_types('names'); |
| 250 |
|
|
| 251 |
$form['scope'] = array( |
$form['scope'] = array( |
| 252 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 253 |
'#title' => t('Scope'), |
'#title' => t('Scope'), |
| 254 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 255 |
'#collapsed' => false, |
'#collapsed' => FALSE, |
| 256 |
'#attributes' => array('class' => 'taxonomy_browser_scope'), |
'#attributes' => array('class' => 'taxonomy_browser_scope'), |
| 257 |
); |
); |
| 258 |
|
|
| 266 |
$node_types[$counter['type']] .= ' ('. $counter['count'] .')'; |
$node_types[$counter['type']] .= ' ('. $counter['count'] .')'; |
| 267 |
} |
} |
| 268 |
else { |
else { |
| 269 |
$node_types['unknown'] .= '<em>'. $counter['type']; |
$node_types['unknown'] .= $counter['type'] .' ??? ('. $counter['count'] .') '; |
|
$node_types['unknown'] .= '</em>??? ('. $counter['count'] .') '; |
|
| 270 |
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); |
| 271 |
} |
} |
| 272 |
$total_count += $counter['count']; |
$total_count += $counter['count']; |
| 288 |
'#type' => $select_type, |
'#type' => $select_type, |
| 289 |
'#title' => t('Restrict search by content type'), |
'#title' => t('Restrict search by content type'), |
| 290 |
'#options' => $node_types, |
'#options' => $node_types, |
| 291 |
'#multiple' => true, |
'#multiple' => TRUE, |
| 292 |
'#prefix' => '<div class="taxonomy_browser_checkboxes">', |
'#prefix' => '<div class="taxonomy_browser_checkboxes">', |
| 293 |
'#suffix' => '</div>', |
'#suffix' => '</div>', |
| 294 |
'#description' => $desc, |
'#description' => $desc, |
| 326 |
$form['children'] = array( |
$form['children'] = array( |
| 327 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 328 |
'#title' => t('Include Children'), |
'#title' => t('Include Children'), |
| 329 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 330 |
'#collapsed' => false, |
'#collapsed' => FALSE, |
| 331 |
); |
); |
| 332 |
$form['children']['include_children'] = array( |
$form['children']['include_children'] = array( |
| 333 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 338 |
else { |
else { |
| 339 |
$form['include_children'] = array( |
$form['include_children'] = array( |
| 340 |
'#type' => 'value', |
'#type' => 'value', |
| 341 |
'#value' => false, |
'#value' => FALSE, |
| 342 |
); |
); |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
$form['taxonomy'] = array( |
$form['taxonomy'] = array( |
| 346 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 347 |
'#title' => t('Categories'), |
'#title' => t('Categories'), |
| 348 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 349 |
'#collapsed' => false, |
'#collapsed' => FALSE, |
| 350 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 351 |
); |
); |
| 352 |
|
|
| 373 |
|
|
| 374 |
if ($tree) { |
if ($tree) { |
| 375 |
foreach ($tree as $term) { |
foreach ($tree as $term) { |
| 376 |
$opt_string = null; |
$opt_string = NULL; |
| 377 |
if ($count_nodes) { |
if ($count_nodes) { |
| 378 |
// $count = db_result(db_query('SELECT COUNT(nid) FROM {term_node} WHERE tid=%d', $term->tid)); |
// $count = db_result(db_query('SELECT COUNT(nid) FROM {term_node} WHERE tid=%d', $term->tid)); |
| 379 |
$count = taxonomy_term_count_nodes($term->tid); |
$count = taxonomy_term_count_nodes($term->tid); |
| 391 |
} |
} |
| 392 |
|
|
| 393 |
$vocname = check_plain($voc->name); |
$vocname = check_plain($voc->name); |
| 394 |
$description = $voc->description ? decode_entities(check_markup($voc->description)) : null; |
$description = $voc->description ? decode_entities(check_markup($voc->description)) : NULL; |
| 395 |
$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)) { |
| 396 |
|
$description .= t('"!name" is used for: !types.', array('!name' => '<strong>'. $vocname .'</strong>', '!types' => (empty($node_type_list) ? '<em>'. t('nothing') .'</em>' : $node_type_list))); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
if (!empty($term_opts)) { |
if (!empty($term_opts)) { |
| 400 |
$form['taxonomy'][$v] = array( |
$voc_element = array( |
| 401 |
'#type' => $select_type, |
'#type' => $select_type, |
| 402 |
'#title' => $vocname, |
'#title' => $vocname, |
| 403 |
'#options' => $term_opts, |
'#options' => $term_opts, |
| 404 |
'#multiple' => true, |
'#multiple' => TRUE, |
| 405 |
'#description' => $description, |
'#description' => $description, |
|
'#size' => min(10, count($term_opts)), |
|
| 406 |
'#prefix' => '<div class="taxonomy_browser_'. $select_type .'">', |
'#prefix' => '<div class="taxonomy_browser_'. $select_type .'">', |
| 407 |
'#suffix' => '</div>', |
'#suffix' => '</div>', |
| 408 |
'#field_suffix' => $node_type_list, |
'#field_suffix' => $node_type_list, |
| 409 |
'#weight' => $i, |
'#weight' => $i, |
| 410 |
); |
); |
| 411 |
|
|
| 412 |
|
if ($collapsible) { |
| 413 |
|
$fld_set = 'set'. $voc->vid; |
| 414 |
|
$form['taxonomy'][$fld_set] = array( |
| 415 |
|
'#type' => 'fieldset', |
| 416 |
|
'#title' => $vocname, |
| 417 |
|
'#collapsible' => TRUE, |
| 418 |
|
'#collapsed' => TRUE, |
| 419 |
|
); |
| 420 |
|
$form['taxonomy'][$fld_set][$v] = $voc_element; |
| 421 |
|
} |
| 422 |
|
else { |
| 423 |
|
$form['taxonomy'][$v] = $voc_element; |
| 424 |
|
} |
| 425 |
++$i; |
++$i; |
| 426 |
} |
} |
| 427 |
} |
} |
| 461 |
|
|
| 462 |
$operator = $form_values['operator'] ? 'or' : 'and'; |
$operator = $form_values['operator'] ? 'or' : 'and'; |
| 463 |
|
|
| 464 |
if ($operator == 'and' && $include_children == true) { |
if ($operator == 'and' && $include_children == TRUE) { |
| 465 |
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.')); |
| 466 |
} |
} |
| 467 |
|
|
| 540 |
$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)); |
| 541 |
} |
} |
| 542 |
|
|
| 543 |
$type_where = null; |
$type_where = NULL; |
| 544 |
if ($nodetype) { |
if ($nodetype) { |
| 545 |
// $type_where = "n.type = '". db_escape_string($nodetype) ."'"; |
// $type_where = "n.type = '". db_escape_string($nodetype) ."'"; |
| 546 |
$type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')"; |
$type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')"; |
| 548 |
|
|
| 549 |
if ($operator == 'or') { |
if ($operator == 'or') { |
| 550 |
$str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids)); |
$str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids)); |
| 551 |
$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"; |
| 552 |
} |
} |
| 553 |
else { |
else { |
| 554 |
$joins = ''; |
$joins = ''; |
| 574 |
* Transforms an unpredictably and irregularly nested set of tids (as returned |
* Transforms an unpredictably and irregularly nested set of tids (as returned |
| 575 |
* from a taxonomy form) into a linear array of tids. |
* from a taxonomy form) into a linear array of tids. |
| 576 |
*/ |
*/ |
| 577 |
function _taxonomy_browser_get_tid_list($tids = null, $include_children = false) { |
function _taxonomy_browser_get_tid_list($tids = NULL, $include_children = FALSE) { |
| 578 |
static $tid_list; |
static $tid_list; |
| 579 |
|
|
| 580 |
if (isset($tids) && is_array($tids)) { |
if (isset($tids) && is_array($tids)) { |