aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@socioambiental.org>2009-10-16 11:22:28 -0300
committerSilvio <silvio@socioambiental.org>2009-10-16 11:22:28 -0300
commitcf7ff05265920cc11df3fb27848903de7b6651ef (patch)
tree5d0a702527285d2a854c09e34d7045d4d03fda72
parent92a55ddd433cf36665444cb130ce300442cf9a7a (diff)
downloadjquery_drawer-cf7ff05265920cc11df3fb27848903de7b6651ef.tar.gz
jquery_drawer-cf7ff05265920cc11df3fb27848903de7b6651ef.tar.bz2
More integration with taxonomy_node_tree
-rw-r--r--jquery_drawer.module76
1 files changed, 8 insertions, 68 deletions
diff --git a/jquery_drawer.module b/jquery_drawer.module
index 76e0856..dd73f27 100644
--- a/jquery_drawer.module
+++ b/jquery_drawer.module
@@ -49,8 +49,10 @@ function jquery_drawer_block($op = 'list', $delta = 0, $edit = array()) {
break;
case 'view':
- $menu = explode(':', variable_get('jquery_drawer', '1'));
- $block['content'] = theme('jquery_drawer', $menu[0], $menu[1]);
+ // Get all terms from a given vocabulary
+ $vid = variable_get('jquery_drawer', '1');
+ $menu = taxonomy_node_tree_parents($vid);
+ $block['content'] = theme('jquery_drawer', $menu);
return $block;
}
}
@@ -77,7 +79,6 @@ function jquery_drawer_theme() {
'jquery_drawer' => array(
'arguments' => array(
'menu' => NULL,
- 'parent' => NULL,
),
),
'jquery_drawer_javascript' => array(
@@ -94,33 +95,12 @@ function jquery_drawer_theme() {
/**
* Drawer logic.
- */
-function theme_jquery_drawer() {
- // Get all terms from a given vocabulary
- $vocabulary = variable_get('jquery_drawer', '1');
- $terms = jquery_drawer_taxonomy_get_tree($vocabulary);
-
- foreach ($terms as $term) {
- // Just show parent terms
- if (taxonomy_get_parents($term->tid) == array()) {
- $menu[] = $term;
- }
- }
-
- // Build the drawer
- $output = jquery_drawer_build($menu);
- return $output;
-}
-
-/**
- * Drawer rendering.
- *
* @ingroup themeable
*/
-function jquery_drawer_build($menu) {
+function theme_jquery_drawer($menu) {
$output = '<ul id="drw_tabs">';
- $output .= implode((array) module_invoke_all('jquery_drawer_build'));
+ $output .= implode((array) module_invoke_all('jquery_drawer'));
foreach ($menu as $item) {
$link['title'] = $item->name;
@@ -153,7 +133,7 @@ function jquery_drawer_page($tid = null) {
// Then render all nodes whose terms are children of $term
$vocabulary = variable_get('jquery_drawer', '1');
- $terms = jquery_drawer_taxonomy_get_tree($vocabulary, $tid);
+ $terms = taxonomy_node_tree_taxonomy_get_tree($vocabulary, $tid);
foreach ($terms as $term) {
$filter[] = $term->tid;
@@ -208,7 +188,7 @@ function jquery_drawer_menu_build($term) {
$output .= '<ul id="jquery_drawer[ul][' . $jquery_drawer_id . ']" class="hidden">';
foreach ($term->nodes as $node) {
$output .= '<li>';
- $output .= '<a href="' . $GLOBALS['base_url'] . '/sitio/' . $node->nid . '">' . $node->title . '</a>';
+ $output .= '<a href="' . $GLOBALS['base_url'] . '/node/' . $node->nid . '">' . $node->title . '</a>';
}
$output .= '</ul>';
$output .= '</li>';
@@ -257,43 +237,3 @@ function theme_jquery_drawer_link($link) {
return $output;
}
-
-/**
- * Version of taxonomy_get_tree() without caching.
- */
-function jquery_drawer_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $cache = FALSE) {
- static $children, $parents, $terms;
-
- $depth++;
-
- // We can cache trees, so it's not CPU-intensive to call get_tree() on a term
- // and its children, too.
- if (!$cache && !isset($children[$vid])) {
- $children[$vid] = array();
-
- $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid);
- while ($term = db_fetch_object($result)) {
- $children[$vid][$term->parent][] = $term->tid;
- $parents[$vid][$term->tid][] = $term->parent;
- $terms[$vid][$term->tid] = $term;
- }
- }
-
- $max_depth = (is_null($max_depth)) ? count($children[$vid]) : $max_depth;
- $tree = array();
- if ($max_depth > $depth && !empty($children[$vid][$parent])) {
- foreach ($children[$vid][$parent] as $child) {
- $term = drupal_clone($terms[$vid][$child]);
- $term->depth = $depth;
- // The "parent" attribute is not useful, as it would show one parent only.
- unset($term->parent);
- $term->parents = $parents[$vid][$child];
- $tree[] = $term;
- if (!empty($children[$vid][$child])) {
- $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $depth, $max_depth));
- }
- }
- }
-
- return $tree;
-}