Stripping CVS keywords
[project/helpers.git] / helpers_taxonomy.module
CommitLineData
68f870a4 1<?php
68f870a4
K
2
3/**
4 * @file
5 * This is a library of useful taxonomy functions and methods.
6 * please insert the link if you have a patch for core to introduce a function from this lib to core.
7 */
8
9/**
10 * Taxonomy REST API: Build a path to a taxonomy listing page
11 * Patch pending at http://drupal.org/node/64664
12 *
13 * @param $terms
14 * a single numeric term id, or a single $term object
15 * or an array of numeric term ids or $term objects
16 * @param $op
17 * a string "AND" or "OR"
18 * @param $depth
19 * depth of the taxonomy tree that is to be returned. 0 equals the entire tree
20 * @param $feed
21 * TRUE for RSS feed, FALSE for page
22 */
23function taxonomy_get_path($terms, $op = 'AND', $depth = 0, $feed = FALSE) {
24 // prepare $tids associative array $tid => $term accounting for the possibility
25 // that $terms is either a tid, a $term, an array of tids, or an array of $term objects
26 if (is_array($terms) && count($array) > 0) {
27 foreach ($terms as $term) {
28 if (is_numeric($term)) {
29 $term = taxonomy_get_term($term);
30 }
31 if (is_object($term)) {
32 $tids[$term->tid] = $term;
33 }
34 }
35 }
36 else {
37 if (is_numeric($terms)) {
38 $tids[$terms] = taxonomy_get_term($terms);
39 }
40 elseif (is_object($terms)) {
41 $tids[$terms->tid] = $terms;
42 }
43 }
44
45 // build the $path
46 $path = 'taxonomy/term';
47 $op = strtolower($op);
48 switch ($op) {
49 case 'and':
50 $path .= '/'. implode(',', array_keys($tids));
51 break;
52
53 case 'or':
54 $path .= '/'. implode('+', array_keys($tids));
55 break;
56 }
57
58 if ($depth > 0) {
59 $path .= "/$depth";
60 }
61
62 if ($feed) {
63 if ($depth > 0) {
64 $path .= '/feed';
65 }
66 else {
67 $path .= '0/feed';
68 }
69 }
70 return $path;
71}