You are here

function _site_map_taxonomy_tree in Site map 6.2

Same name and namespace in other branches
  1. 5 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

numeric $vid: Vocabulary id.

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

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

Return value

string 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 349
site_map.module

Code

function _site_map_taxonomy_tree($vid, $name = NULL, $description = NULL) {
  $output = '';
  $class = '';
  if ($vid == variable_get('forum_nav_vocabulary', '')) {
    $title = l($name, 'forum');
    $threshold = variable_get('site_map_forum_threshold', -1);
    $forum_link = TRUE;
  }
  else {
    $title = $name ? check_plain(t($name)) : '';
    $threshold = variable_get('site_map_term_threshold', 0);
    $forum_link = FALSE;
  }
  $title .= module_exists('commentrss') && variable_get('commentrss_term', FALSE) ? ' ' . theme('site_map_feed_icon', "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 .= !empty($description) ? '<div class="taxonomy-term-description">' . filter_xss_admin($description) . "</div>\n" : '';

  // taxonomy_get_tree() honors access controls.
  $tree = taxonomy_get_tree($vid);
  foreach ($tree as $term) {
    $term->count = taxonomy_term_count_nodes($term->tid);
    if ($term->count <= $threshold) {
      continue;
    }
    if (module_exists('i18ntaxonomy')) {
      $term->name = tt("taxonomy:term:{$term->tid}:name", $term->name);
    }

    // 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 .= "\n<ul>";
      }
    }
    elseif ($term->depth == $last_depth) {
      $output .= '</li>';
    }
    elseif ($term->depth < $last_depth) {
      for ($i = 0; $i < $last_depth - $term->depth; $i++) {
        $output .= "</li>\n</ul>\n</li>";
      }
    }

    // Display the $term.
    $output .= "\n<li>";
    $term_item = '';
    if ($forum_link) {
      $term_item .= l($term->name, 'forum/' . $term->tid, array(
        'attributes' => array(
          'title' => $term->description,
        ),
      ));
    }
    elseif ($term->count) {
      $term_item .= l($term->name, $cat_depth <= 0 ? taxonomy_term_path($term) : "taxonomy/term/{$term->tid}/{$cat_depth}", array(
        'attributes' => array(
          'title' => $term->description,
        ),
      ));
    }
    else {
      $term_item .= check_plain($term->name);
    }
    if (variable_get('site_map_show_count', 1)) {
      $term_item .= " ({$term->count})";
    }
    if (variable_get('site_map_show_rss_links', 1) != 0) {
      $rss_link = theme('site_map_feed_icon', "taxonomy/term/{$term->tid}/{$rss_depth}/feed");
      if (module_exists('commentrss') && variable_get('commentrss_term', FALSE)) {
        $rss_link .= ' ' . theme('site_map_feed_icon', "crss/term/{$term->tid}", 'comment');
      }
      if (variable_get('site_map_show_rss_links', 1) == 1) {
        $term_item .= ' ' . $rss_link;
      }
      else {
        $class = ' site-map-rss-left';
        $term_item = $rss_link . ' ' . $term_item;
      }
    }
    $output .= $term_item;

    // 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 .= "</li>\n</ul>\n";
    }
  }
  $output = theme('site_map_box', $title, $output, 'site-map-terms-box site-map-terms-box-' . $vid . $class);
  return $output;
}