You are here

function _site_map_taxonomy_tree in Site map 5

Same name and namespace in other branches
  1. 6.2 site_map.module \_site_map_taxonomy_tree()
  2. 6 site_map.module \_site_map_taxonomy_tree()
  3. 7 site_map.module \_site_map_taxonomy_tree()

Render taxonomy tree

Parameters

$tree The results of taxonomy_get_tree() with optional 'count' fields.:

$name An optional name for the tree. (Default: NULL):

$description An optional description of the tree. (Default: NULL):

Return value

A string representing a rendered tree.

1 call to _site_map_taxonomy_tree()
_site_map_taxonomys in ./site_map.module
This function can be called from blocks or pages as desired.

File

./site_map.module, line 452
Original author: Nic Ivy Now maintained by by Fredrik Jonsson fredrik at combonet dot se

Code

function _site_map_taxonomy_tree($vid, $name = NULL, $description = NULL) {
  if ($vid == variable_get('forum_nav_vocabulary', '')) {
    $title = l($name, 'forum');
  }
  else {
    $title = $name ? check_plain(t($name)) : '';
  }
  $title .= module_exists('commentrss') ? ' ' . theme('site_map_feed_icon', url("crss/vocab/{$vid}"), 'comment') : '';
  $last_depth = -1;
  $rss_depth = variable_get('site_map_rss_depth', 'all');
  if (!is_numeric($rss_depth) || $rss_depth < 0) {
    $rss_depth = 'all';
  }
  $cat_depth = variable_get('site_map_categories_depth', 'all');
  if (!is_numeric($cat_depth)) {
    $cat_depth = 'all';
  }
  $output = $description ? '<div class="description">' . check_plain($description) . '</div>' : '';
  $output .= '<div class="tree">';

  // taxonomy_get_tree() honors access controls
  $tree = taxonomy_get_tree($vid);
  foreach ($tree as $term) {

    // Adjust the depth of the <ul> based on the change
    // in $term->depth since the $last_depth.
    if ($term->depth > $last_depth) {
      for ($i = 0; $i < $term->depth - $last_depth; $i++) {
        $output .= '<ul>';
      }
    }
    else {
      if ($term->depth < $last_depth) {
        for ($i = 0; $i < $last_depth - $term->depth; $i++) {
          $output .= '</ul>';
        }
      }
    }

    // Display the $term.
    $output .= '<li>';
    $term->count = taxonomy_term_count_nodes($term->tid);
    if ($term->count) {
      if ($cat_depth < 0) {
        $output .= l($term->name, taxonomy_term_path($term), array(
          'title' => $term->description,
        ));
      }
      else {
        $output .= l($term->name, "taxonomy/term/{$term->tid}/{$cat_depth}", array(
          'title' => $term->description,
        ));
      }
    }
    else {
      $output .= check_plain($term->name);
    }
    if (variable_get('site_map_show_count', 1)) {
      $output .= " ({$term->count})";
    }
    if (variable_get('site_map_show_rss_links', 1)) {
      $output .= ' ' . theme('site_map_feed_icon', url("taxonomy/term/{$term->tid}/{$rss_depth}/feed"));
      $output .= module_exists('commentrss') ? ' ' . theme('site_map_feed_icon', url("crss/term/{$term->tid}"), 'comment') : '';
    }
    $output .= "</li>\n";

    // Reset $last_depth in preparation for the next $term.
    $last_depth = $term->depth;
  }

  // Bring the depth back to where it began, -1.
  if ($last_depth > -1) {
    for ($i = 0; $i < $last_depth + 1; $i++) {
      $output .= '</ul>';
    }
  }
  $output .= "</div>\n";
  $output = theme('box', $title, $output);
  return $output;
}