'select', '#title' => t('Select the vocabulary to list'), '#default_value' => variable_get('jquery_drawer', '1'), // TODO: won't work with taxonomy_get_vocabularies() '#options' => menu_parent_options(taxonomy_get_vocabularies(), 0), ); return $form; case 'save': variable_set('jquery_drawer', $edit['jquery_drawer']); break; case 'view': $menu = explode(':', variable_get('jquery_drawer', '1')); $block['content'] = theme('jquery_drawer', $menu[0], $menu[1]); return $block; } } /** * Implementation of hook_menu(); */ function jquery_drawer_menu() { $items['jquery_drawer'] = array( 'title' => 'jQuery Drawer', 'description' => 'Displays content inside a jQuery Drawer.', 'page callback' => 'jquery_drawer_page', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_theme(); */ function jquery_drawer_theme() { return array( 'jquery_drawer' => array( 'arguments' => array( 'menu' => NULL, 'parent' => NULL, ), ), 'jquery_drawer_javascript' => array( 'arguments' => array(), ), 'jquery_drawer_css' => array( 'arguments' => array(), ), 'jquery_drawer_link' => array( 'arguments' => array(), ), ); } /** * Drawer logic. */ function theme_jquery_drawer($menu_name, $mlid) { // 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) { $output = ''; $output .= '
'; $output .= '
'; return $output; } /** * Menu callback. */ function jquery_drawer_page($tid = null) { // First render all nodes whose parent is $term $output = ''; $nodes = taxonomy_select_nodes(array($tid)); while ($node = db_fetch_object($nodes)) { $link['title'] = $node->title; $link['href'] = 'node/' . $node->nid; $output .= theme('jquery_drawer_link', $link); } // Then render all nodes whose terms are children of $term $vocabulary = variable_get('jquery_drawer', '1'); $terms = jquery_drawer_taxonomy_get_tree($vocabulary, $tid); foreach ($terms as $term) { $filter[] = $term->tid; } $query = 'SELECT node.nid, node.title, term_node.tid FROM {node} LEFT JOIN {term_node} ON term_node.nid = node.nid WHERE term_node.tid IN (%s) AND node.status = "1"'; $result = db_query(db_rewrite_sql($query), implode(',', $filter)); while ($node = db_fetch_object($result)) { foreach ($terms as $term) { // add nodes into the term if ($node->tid == $term->tid) { $term->nodes[] = $node; } // update an index of terms $tree[$term->tid] = $term; } } // add children relationship just for terms present in the tree foreach ($tree as $term) { if ($term->parents[0] != 0 && isset($tree[$term->parents[0]])) { $tree[$term->parents[0]]->children[] = $term->tid; } } // build menu with hierarchy foreach ($tree as $term) { jquery_drawer_build_tree($tree, $term); } // format output $output .= ''; // Display output echo($output); // We need to exit here to avoid themeable output exit(); } function jquery_drawer_build_tree(&$tree, $term) { if ($term->parents[0] != 0 && isset($tree[$term->parents[0]])) { // is child if (isset($term->children)) { // is also parent, so go down one level foreach($term->children as $child) { jquery_drawer_build_tree($tree, $tree[$child]); } } $tree[$term->parents[0]]->below[] = drupal_clone($term); unset($tree[$term->tid]); } } /** * Recursively build the menu. * * @ingroup themeable */ function jquery_drawer_menu_build($term) { global $jquery_drawer_id; if ($jquery_drawer_id == null) { $jquery_drawer_id = 0; } $jquery_drawer_id++; if (isset($term->tid)) { $output .= '
  • '; $output .= $term->name; if (isset($term->below)) { $output .= ''; } else if (isset($term->nodes)) { $output .= ''; $output .= '
  • '; } $output .= ''; } return $output; } /** * Build the Drawer. * * @TODO * @ingroup themeable */ /*function jquery_drawer_show_items($term) { $tree = array(); $terms = jquery_drawer_taxonomy_get_tree(JQUERY_DRAWER_VOC_ID); $query = 'SELECT node.nid, node.title, term_node.tid FROM {node} LEFT JOIN {term_node} ON term_node.nid = node.nid WHERE node.type = "story" AND term_node.tid = "%d" AND node.status = "1")'; $result = db_query(db_rewrite_sql($query), $term); while ($node = db_fetch_object($result)) { foreach ($terms as $term) { // add nodes into the term if ($node->tid == $term->tid) { $term->nodes[] = $node; } // update an index of terms $tree[$term->tid] = $term; } } // add children relationship foreach ($tree as $term) { if ($term->parents[0] != 0) { $tree[$term->parents[0]]->children[] = $term->tid; } } // build menu with hierarchy foreach ($tree as $term) { jquery_drawer_build_tree($tree, $term); } // format output $output = '
  • '. t('About') .'
  • '; $output .= '
  • '. t('Location'); $output .= '
  • '; return $output; } /** * Recursively build the menu. * * @ingroup themeable */ /*function jquery_drawer_show_items($menu) { global $_jquery_drawer_id; if ($_jquery_drawer_id == NULL) { $output = '