? .project
Index: site_map.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/site_map/site_map.module,v
retrieving revision 1.39.2.17.2.8
diff -u -p -r1.39.2.17.2.8 site_map.module
--- site_map.module 22 May 2010 07:42:48 -0000 1.39.2.17.2.8
+++ site_map.module 23 May 2010 18:36:34 -0000
@@ -311,10 +311,14 @@ function _site_map_taxonomys() {
/**
* Render taxonomy tree
*
- * @param $tree The results of taxonomy_get_tree() with optional 'count' fields.
- * @param $name An optional name for the tree. (Default: NULL)
- * @param $description An optional description of the tree. (Default: NULL)
- * @return A string representing a rendered tree.
+ * @param $vid
+ * A vocabulary ID.
+ * @param $name
+ * An optional name for the tree.
+ * @param $description
+ * An optional description of the tree.
+ * @return
+ * A string representing a rendered tree.
*/
function _site_map_taxonomy_tree($vid, $name = NULL, $description = NULL) {
$output = '';
@@ -344,76 +348,165 @@ function _site_map_taxonomy_tree($vid, $
$output .= !empty($description) ? '
'. filter_xss_admin($description) ."
\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 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";
+ $tree = taxonomy_get_tree($vid, 0, -1, ($cat_depth == 'all' || $cat_depth == -1) ? NULL : ($cat_depth + 1));
+ $max_depth = 0;
+ if (count($tree > 0)) {
+ foreach ($tree as $term) {
+ $term->count = taxonomy_term_count_nodes($term->tid);
+ if ($term->count > $threshold) {
+ $terms[$term->tid] = $term;
+ }
+ if ($term->depth > $max_depth) {
+ $max_depth = $term->depth;
}
}
- elseif ($term->depth == $last_depth) {
- $output .= '';
- }
- elseif ($term->depth < $last_depth) {
- for ($i = 0; $i < ($last_depth - $term->depth); $i++) {
- $output .= "\n
\n";
+ if (count($terms > 0)) {
+ $options = array(
+ 'show_count' => variable_get('site_map_show_count', 1),
+ 'show_rss_links' => variable_get('site_map_show_rss_links', 1),
+ 'commentrss_term' => variable_get('commentrss_term', FALSE),
+ 'forum_link' => $forum_link,
+ 'rss_depth' => $rss_depth,
+ 'cat_depth' => ($cat_depth == 'all' || $cat_depth === -1) ? 'all' : $cat_depth,
+ );
+ foreach ($terms as $term) {
+ $term->link = _site_map_taxonomy_link($term, $vid, $options);
+ }
+ if ($cat_depth == -1 || $cat_depth === 0) {
+ $output .= "\n\n";
+ $count = 1;
+ $total = count($terms);
+ foreach ($terms as $term) {
+ $class = array();
+ if ($count == 1) {
+ $class[] = 'first';
+ }
+ if ($count == $total) {
+ $class[] = 'last';
+ }
+ $class = (count($class) > 0) ? ' class="'. implode(' ', $class) .'"' : '';
+ $output .= '- '. $term->link ."
\n";
+ $count++;
+ }
+ $output .= "
\n";
+ }
+ else {
+ $output .= _site_map_taxonomy_list($terms, $max_depth);
}
}
- // Display the $term.
- $output .= "\n- ";
- $term_item = '';
- if ($forum_link) {
- $term_item .= l($term->name, 'forum/'. $term->tid, array('attributes' => array('title' => $term->description)));
+ }
+ $output = theme('site_map_box', $title, $output, 'site-map-terms-box site-map-terms-box-'. $vid . $class);
+ return $output;
+}
+
+/**
+ * Helper function to build the taxonomy term link.
+ *
+ * @param $term
+ * A taxonomy term to build the link for.
+ * @param $vid
+ * A vocabulary ID.
+ * @param $options
+ * An array of options used to build the link.
+ * @return
+ * A link for the taxonomy term.
+ */
+function _site_map_taxonomy_link($term, $vid, $options) {
+ if (module_exists('i18ntaxonomy')) {
+ $term->name = tt("taxonomy:term:$term->tid:name", $term->name);
+ }
+ if ($options['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/". $options['cat_depth'], array('attributes' => array('title' => $term->description)));
+ }
+ else {
+ $term_item .= check_plain($term->name);
+ }
+ if ($options['show_count']) {
+ $term_item .= " ($term->count)";
+ }
+
+ if ($options['show_rss_links'] != 0) {
+ $rss_link = theme('site_map_feed_icon', "taxonomy/term/$term->tid/". $options['rss_depth'] ."/feed");
+ if (module_exists('commentrss') && $options['commentrss_term']) {
+ $rss_link .= ' '. theme('site_map_feed_icon', "crss/term/$term->tid", 'comment');
}
- 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)));
+ if ($options['show_rss_links'] == 1) {
+ $term_item .= ' '. $rss_link;
}
else {
- $term_item .= check_plain($term->name);
- }
- if (variable_get('site_map_show_count', 1)) {
- $term_item .= " ($term->count)";
+ $class = ' site-map-rss-left';
+ $term_item = $rss_link .' '. $term_item;
}
+ }
+ return $term_item;
+}
- 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');
+/**
+ * Helper function to build the vocabulary list of terms.
+ *
+ * @param $terms
+ * An array of terms.
+ * @param $depth
+ * The maximum depth of a term.
+ * @return
+ * Return an HTML string of the nested list.
+ */
+function _site_map_taxonomy_list($terms, $depth) {
+ $spacing = '';
+ for ($i = 0; $i < $depth; $i++) {
+ $spacing .= ' ';
+ }
+ if ($depth === 0) {
+ $count = 1;
+ $total = count($terms);
+ foreach ($terms as $tid => $term) {
+ $class = array();
+ if ($count == 1) {
+ $class[] = 'first';
}
- 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;
+ if ($count == $total) {
+ $class[] = 'last';
}
+ $class = (count($class) > 0) ? ' class="'. implode(' ', $class) .'"' : '';
+ $list .= '
- '. $term->link . (($term->children) ? $term->children ."
\n" : "\n");
+ $count++;
}
-
- $output .= $term_item;
-
- // Reset $last_depth in preparation for the next $term.
- $last_depth = $term->depth;
+ $output .= ($list) ? "\n\n" : '';
}
-
- // Bring the depth back to where it began, -1.
- if ($last_depth > -1) {
- for ($i = 0; $i < ($last_depth + 1); $i++) {
- $output .= "\n
\n";
+ else {
+ foreach ($terms as $tid => $term) {
+ if ($term->depth === $depth) {
+ foreach ($term->parents as $parent) {
+ $terms[$parent]->childrens[] = $term->link . $term->children;
+ }
+ unset($terms[$term->tid]);
+ }
+ }
+ foreach ($terms as $tid => $term) {
+ if ($term->childrens) {
+ $term->children = "\n$spacing\n";
+ $count = 1;
+ $total = count($term->childrens);
+ foreach ($term->childrens as $children) {
+ $class = array();
+ if ($count == 1) {
+ $class[] = 'first';
+ }
+ if ($count == $total) {
+ $class[] = 'last';
+ }
+ $class = (count($class) > 0) ? ' class="'. implode(' ', $class) .'"' : '';
+ $term->children .= $spacing .' - '. $children ."
\n";
+ $count++;
+ }
+ $term->children .= "$spacing
\n";
+ }
}
+ $output .= _site_map_taxonomy_list($terms, ($depth - 1));
}
- $output = theme('site_map_box', $title, $output, 'site-map-terms-box site-map-terms-box-'. $vid . $class);
-
return $output;
}