vid] = $vocabulary->name; } $form['jquery_drawer'] = array( '#type' => 'select', '#title' => t('Select the vocabulary to list'), '#default_value' => variable_get('jquery_drawer', '1'), '#options' => $vocabularies, ); $form['jquery_drawer_drw'] = array( '#type' => 'checkbox', '#title' => t('Do not show drawer box.'), '#description' => t('Select this option if you plan to manually provide the drawer box.'), '#default_value' => variable_get('jquery_drawer_drw', '0'), ); $form['jquery_drawer_link'] = array( '#type' => 'textfield', '#title' => t('Base link path (useful for views).'), '#description' => t('Set the base link for nodes listed in drawer.'), '#default_value' => variable_get('jquery_drawer_link', 'node'), ); return $form; case 'save': variable_set('jquery_drawer', $edit['jquery_drawer']); variable_set('jquery_drawer_drw', $edit['jquery_drawer_drw']); variable_set('jquery_drawer_link', $edit['jquery_drawer_link']); break; case 'view': // Get all terms from a given vocabulary $vid = variable_get('jquery_drawer', '1'); $menu = taxonomy_node_tree_parents($vid); // Remove empty menus foreach ($menu as $key => $term) { if (jquery_drawer_check_empty($term->tid)) { unset($menu[$key]); } } $block['content'] = theme('jquery_drawer', $menu); return $block; } } /** * Check empty menus. */ function jquery_drawer_check_empty($tid) { $parents = array(); $nodes = jquery_drawer_select_nodes($tid); $children = jquery_drawer_get_children($tid); while ($node = db_fetch_object($nodes)) { $parents[] = $node; } if (empty($parents) && empty($children)) { return TRUE; } } /** * Static version of taxonomy_select_nodes(). */ function jquery_drawer_select_nodes($tid = NULL) { static $cache = array(); if ($tid == NULL) { return; } if (!isset($cache[$tid])) { $cache[$tid] = taxonomy_select_nodes(array($tid)); } return $cache[$tid]; } /** * 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, ), ), 'jquery_drawer_javascript' => array( 'arguments' => array(), ), 'jquery_drawer_css' => array( 'arguments' => array(), ), 'jquery_drawer_link' => array( 'arguments' => array(), ), ); } /** * Drawer logic. * * @ingroup themeable */ function theme_jquery_drawer($menu) { $output = ''; if (variable_get('jquery_drawer_drw', '0') == 0) { $output .= '
'; $output .= '
'; } return $output; } /** * Render all nodes whose terms are children of $tid. */ function jquery_drawer_get_children($tid = NULL) { static $cache = array(); if (isset($cache[$tid])) { return $cache[$tid]; } $vid = variable_get('jquery_drawer', '1'); $terms = taxonomy_node_tree_taxonomy_get_tree($vid, $tid); if (module_exists('i18n')) { $terms = i18ntaxonomy_localize_terms($terms); } foreach ($terms as $term) { $filter[] = $term->tid; } if (isset($filter) && !empty($filter)) { // Then render all nodes whose terms are children of $term $query = 'SELECT DISTINCT n.nid, n.title, term_node.tid FROM {node} n LEFT JOIN {term_node} ON term_node.nid = n.nid WHERE term_node.tid IN (%s) AND n.status = "1" ORDER BY term_node.weight_in_tid ASC'; //$query = db_rewrite_sql($query); $nodes = db_query(db_rewrite_sql($query), implode(',', $filter)); $tree = taxonomy_node_tree_build($nodes, $terms); $cache[$tid] = $tree; return $tree; } $cache[$tid] = NULL; } /** * Menu callback. */ function jquery_drawer_page($tid = NULL) { static $cache = array(); if (!isset($cache[$tid])) { $output = ''; $nodes = jquery_drawer_select_nodes($tid); $base = variable_get('jquery_drawer_link', 'node'); $tree = jquery_drawer_get_children($tid); $output .= ''; $cache[$tid] = $output; } // Display output echo($output); // We need to exit here to avoid themeable output exit(); } /** * jQuery Drawer Javascript theme function. * * @ingroup themeable */ function theme_jquery_drawer_javascript() { drupal_add_js(drupal_get_path('module', 'jquery_drawer') .'/jquery_drawer/drw/scripts.js'); } /** * jQuery Drawer CSS theme function. * * @ingroup themeable */ function theme_jquery_drawer_css() { drupal_add_css(drupal_get_path('module', 'jquery_drawer') .'/jquery_drawer/drw/styles.css'); drupal_add_css(drupal_get_path('module', 'jquery_drawer') .'/jquery_drawer.css'); } /** * jQuery Drawer Link theme function. * * @ingroup themeable */ function theme_jquery_drawer_link($link) { if (empty($link['localized_options'])) { $link['localized_options'] = array(); } $link['attributes']['rel'] = 'drw'; $output = '
  • '; $output .= l($link['title'], $link['href'], array('attributes' => array('rel' => 'drw'))); $output .= '
  • '; return $output; }