/[drupal]/contributions/modules/taxonomy_hide/taxonomy_hide.inc
ViewVC logotype

Diff of /contributions/modules/taxonomy_hide/taxonomy_hide.inc

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

revision 1.1, Sun May 11 04:38:51 2008 UTC revision 1.1.2.1, Sun May 11 04:38:51 2008 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: $
3    
4    /**
5     * Helper function to taxonomy_hide_nodeapi() when its time
6     * to display the node
7     */
8    function _taxonomy_hide_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {
9      // This module only cares with nodes that have taxonomy terms
10      // assigned to them.
11      if (!empty($node->taxonomy)) {
12    
13        // Get all hidden vocabularies; keys of $hidden are the vocabulary ids.
14        // Apply either the node type filter or the global filter, not both
15        // First, apply filter for current node type, if it exists, else apply global filter
16        // In this way, the setting for the node type overrides the global setting
17        // If a filter for this type is not set, the global filter will be used.
18        if ($hidden = array_filter(variable_get('taxonomy_hide_vocabularies_'. $node->type, array())) or
19            $hidden = array_filter(variable_get('taxonomy_hide_vocabularies', array()))) {
20    
21          // Hide terms by removing them from the taxonomy field
22          foreach ($node->taxonomy as $key => $value) {
23            if (isset($hidden[$value->vid])) {
24              unset($node->taxonomy[$key]);
25            }
26          }
27        }
28    
29        // Sort terms by sorting the taxonomy field
30        if (!empty($node->taxonomy) and variable_get('taxonomy_hide_group_by_vocabulary', 0)) {
31          usort($node->taxonomy, "_taxonomy_hide_sort");
32        }
33      }
34    }
35    
36    /**
37     * Comparison function for the usort of vocabulary terms.
38     */
39    function _taxonomy_hide_sort($a, $b) {
40      // Cache the extra vocabulary information (we need the vocabulary weight)
41      static $vocs = array();
42      if (!array_key_exists($a->vid, $vocs)) {
43        $vocs[$a->vid] = taxonomy_get_vocabulary($a->vid);
44      }
45      if (!array_key_exists($b->vid, $vocs)) {
46        $vocs[$b->vid] = taxonomy_get_vocabulary($b->vid);
47      }
48    
49      // Compare first by vocabulary weight, next by vocabulary id, next by term
50      // weight, next by term name, and finally by term id. This is the same order
51      // as used by taxonomy_node_get_terms, except that we group by vocabulary too.
52      if ($vocs[$a->vid]->weight < $vocs[$b->vid]->weight) {
53        return -1;
54      }
55      elseif ($vocs[$a->vid]->weight > $vocs[$b->vid]->weight) {
56        return 1;
57      }
58      elseif ($a->vid < $b->vid) {
59        return -1;
60      }
61      elseif ($a->vid > $b->vid) {
62        return 1;
63      }
64      elseif ($a->weight < $b->weight) {
65        return -1;
66      }
67      elseif ($a->weight > $b->weight) {
68        return 1;
69      }
70      elseif (strcasecmp($a->name, $b->name)) {
71        return strcasecmp($a->name, $b->name);
72      }
73      elseif ($a->tid < $b->tid) {
74        return -1;
75      }
76      elseif ($a->tid > $b->tid) {
77        return 1;
78      }
79      else {
80        return 0;
81      }
82    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2