| 1 |
<?php |
<?php |
| 2 |
|
// $Id: taxonomy_hide.module,v 1.7 2007/08/03 16:29:37 davidlesieur Exp $ |
| 3 |
|
|
| 4 |
/* $Id$ */ |
/** |
| 5 |
|
* Implementation of hook_menu(). |
| 6 |
|
*/ |
| 7 |
function taxonomy_hide_menu($may_cache) { |
function taxonomy_hide_menu($may_cache) { |
| 8 |
$items = array(); |
$items = array(); |
| 9 |
if ($may_cache) { |
if ($may_cache) { |
| 20 |
return $items; |
return $items; |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
|
/** |
| 24 |
|
* Implementation of hook_help(). |
| 25 |
|
*/ |
| 26 |
function taxonomy_hide_help($section) { |
function taxonomy_hide_help($section) { |
| 27 |
$output = ''; |
$output = ''; |
| 28 |
switch ($section) { |
switch ($section) { |
| 45 |
return $output; |
return $output; |
| 46 |
} |
} |
| 47 |
|
|
| 48 |
|
/** |
| 49 |
|
* Menu callback for administration settings. |
| 50 |
|
*/ |
| 51 |
function taxonomy_hide_admin_settings() { |
function taxonomy_hide_admin_settings() { |
| 52 |
$form = array(); |
$form = array(); |
| 53 |
$form['taxonomy_hide'] = array( |
$form['taxonomy_hide'] = array( |
| 63 |
'#weight' => -1, |
'#weight' => -1, |
| 64 |
); |
); |
| 65 |
|
|
| 66 |
# Note that the settings will be saved as an array whose keys are |
// Note that the settings will be saved as an array whose keys are the |
| 67 |
# the vocabulary ids ($vid) and whose values are 0 (disabled) or |
// vocabulary ids ($vid) and whose values are 0 (disabled) or $vid (enabled). |
| 68 |
# $vid (enabled). |
// |
| 69 |
# The default_value should be an array whose values are the enabled |
// The default_value should be an array whose values are the enabled |
| 70 |
# vocabulary ids. |
// vocabulary ids. |
| 71 |
# The options should be an array whose keys are the vocabulary ids, |
// |
| 72 |
# and whose values are the names of the vocabularies. |
// The options should be an array whose keys are the vocabulary ids, and whose |
| 73 |
|
// values are the names of the vocabularies. |
| 74 |
$select = array(); |
$select = array(); |
| 75 |
$vocabularies = taxonomy_get_vocabularies(); |
$vocabularies = taxonomy_get_vocabularies(); |
| 76 |
foreach ($vocabularies as $vocabulary) { |
foreach ($vocabularies as $vocabulary) { |
| 89 |
return system_settings_form($form); |
return system_settings_form($form); |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
|
/** |
| 93 |
|
* Implementation of hook_nodeapi(). |
| 94 |
|
*/ |
| 95 |
function taxonomy_hide_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) { |
function taxonomy_hide_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) { |
| 96 |
switch ($op) { |
switch ($op) { |
| 97 |
case 'view': |
case 'view': |
| 98 |
# Get all hidden vocabularies; keys of $hidden are the vocabulary ids. |
// Get all hidden vocabularies; keys of $hidden are the vocabulary ids. |
| 99 |
$hidden = array_filter(variable_get('taxonomy_hide_vocabularies', array())); |
$hidden = array_filter(variable_get('taxonomy_hide_vocabularies', array())); |
| 100 |
if (count($hidden) && !empty($node->taxonomy)) { |
if (count($hidden) && !empty($node->taxonomy)) { |
| 101 |
# Hide terms by removing them from the taxonomy field |
// Hide terms by removing them from the taxonomy field |
| 102 |
foreach ($node->taxonomy as $key => $value) { |
foreach ($node->taxonomy as $key => $value) { |
| 103 |
if (array_key_exists($value->vid, $hidden)) { |
if (array_key_exists($value->vid, $hidden)) { |
| 104 |
unset($node->taxonomy[$key]); |
unset($node->taxonomy[$key]); |
| 106 |
} |
} |
| 107 |
} |
} |
| 108 |
if (variable_get('taxonomy_hide_group_by_vocabulary', 0)) { |
if (variable_get('taxonomy_hide_group_by_vocabulary', 0)) { |
| 109 |
# Sort terms by sorting the taxonomy field |
// Sort terms by sorting the taxonomy field |
| 110 |
usort($node->taxonomy, "_taxonomy_hide_sort"); |
usort($node->taxonomy, "_taxonomy_hide_sort"); |
| 111 |
} |
} |
| 112 |
break; |
break; |
| 114 |
return; |
return; |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
# Comparison function for the usort of vocabulary terms. |
/** |
| 118 |
|
* Comparison function for the usort of vocabulary terms. |
| 119 |
|
*/ |
| 120 |
function _taxonomy_hide_sort($a, $b) { |
function _taxonomy_hide_sort($a, $b) { |
| 121 |
# Cache the extra vocabulary information (we need the vocabulary weight) |
// Cache the extra vocabulary information (we need the vocabulary weight) |
| 122 |
static $vocs = array(); |
static $vocs = array(); |
| 123 |
if (!array_key_exists($a->vid, $vocs)) { |
if (!array_key_exists($a->vid, $vocs)) { |
| 124 |
$vocs[$a->vid] = taxonomy_get_vocabulary($a->vid); |
$vocs[$a->vid] = taxonomy_get_vocabulary($a->vid); |
| 127 |
$vocs[$b->vid] = taxonomy_get_vocabulary($b->vid); |
$vocs[$b->vid] = taxonomy_get_vocabulary($b->vid); |
| 128 |
} |
} |
| 129 |
|
|
| 130 |
# Compare first by vocabulary weight, next by vocabulary id, next by |
// Compare first by vocabulary weight, next by vocabulary id, next by term |
| 131 |
# term weight, next by term name, and finally by term id. |
// weight, next by term name, and finally by term id. This is the same order |
| 132 |
# This is the same order as used by taxonomy_node_get_terms, except that |
// as used by taxonomy_node_get_terms, except that we group by vocabulary too. |
|
# we group by vocabulary too. |
|
| 133 |
if ($vocs[$a->vid]->weight < $vocs[$b->vid]->weight) { |
if ($vocs[$a->vid]->weight < $vocs[$b->vid]->weight) { |
| 134 |
return -1; |
return -1; |
| 135 |
} |
} |