diff -ur taxonomy_block/taxonomy_block.info localmods/taxonomy_block/taxonomy_block.info --- taxonomy_block/taxonomy_block.info 2011-06-08 13:36:58.000000000 -0400 +++ localmods/taxonomy_block/taxonomy_block.info 2011-08-11 14:13:54.624678619 -0400 @@ -1,5 +1,5 @@ -name = Taxonomy Block -description = Displays taxonomy hierarchy in a block. +name = Taxonomy Blocks +description = Displays taxonomy hierarchies in blocks. core = 7.x files[] = taxonomy_block.module dependencies[] = taxonomy diff -ur taxonomy_block/taxonomy_block.install localmods/taxonomy_block/taxonomy_block.install --- taxonomy_block/taxonomy_block.install 2011-06-08 13:36:50.000000000 -0400 +++ localmods/taxonomy_block/taxonomy_block.install 2011-08-11 14:13:54.624678619 -0400 @@ -8,6 +8,8 @@ * Implementation of hook_uninstall(); */ function taxonomy_block_uninstall() { - variable_del('taxonomy_block_vid'); - variable_del('taxonomy_block_node_count'); -} \ No newline at end of file + db_delete('variable') + ->condition('name', db_like('taxonomy_block__').'%', 'LIKE') + ->execute(); + variable_del('taxonomy_block__machine_names'); +} diff -ur taxonomy_block/taxonomy_block.module localmods/taxonomy_block/taxonomy_block.module --- taxonomy_block/taxonomy_block.module 2011-06-08 13:36:50.000000000 -0400 +++ localmods/taxonomy_block/taxonomy_block.module 2011-08-11 14:13:54.624678619 -0400 @@ -21,7 +21,7 @@ function taxonomy_block_help($section) { switch ($section) { case 'admin/help#taxonomy_block': - return '
'.t('Displays taxonomy hierarchy in a block.') . '
'; + return ''.t('Displays taxonomy hierarchy in blocks.') . '
'; case 'admin/modules#description': return 'Displays taxonomy hierarchy in a block.'; @@ -52,7 +52,7 @@ $items['admin/config/taxonomy_block'] = array( 'title' => 'Taxonomy Block', - 'description' => 'Displays taxonomy hierarchy', + 'description' => 'Configure which vocabularies to display in Taxonomy Block', 'access arguments' => array(TAXONOMY_BLOCK_PERM_ADMIN), 'page callback' => 'drupal_get_form', 'page arguments' => array('taxonomy_block_admin_settings'), @@ -67,12 +67,73 @@ * Implementation of hook_block_info(); */ function taxonomy_block_block_info() { - $blocks['taxonomy_block'] = array( - 'info' => t('Taxonomy Block'), - 'cache' => DRUPAL_NO_CACHE, + $vocabs = taxonomy_vocabulary_get_names(); + $blocks = array(); + foreach (variable_get('taxonomy_block__machine_names', array()) as $machine_name) { + if (!empty($vocabs[$machine_name])) { + $blocks[$machine_name] = array( + 'info' => t('Taxonomy Blok: @name', array('@name'=>$vocabs[$machine_name]->name)), + 'cache' => DRUPAL_CACHE_GLOBAL, + ); + } + } + return $blocks; +} + +/** + * Implementation of hook_block_configure(); + */ +function taxonomy_block_block_configure($delta = '') { + $form = array(); + $default = drupal_parse_url('taxonomy/term/%taxonomy_term'); + $url = variable_get('taxonomy_block__url_'.$delta, $default); + if (!is_array($url)) + $url = $default; + /* construct $path similar to menu.module */ + $path = $url['path']; + if (!empty($url['query'])) { + $path .= '?' . drupal_http_build_query($url['query']); + } + if (!empty($url['fragment'])) { + $path .= '#' . $url['fragment']; + } + $form['taxonomy_block__url_'.$delta] = array( + '#type' => 'textfield', + '#title' => t('URL'), + '#size' => 60, + '#description' => t('The base drupal path to use for in the term links. Insert %taxonomy_term where you want the term id to be placed. Default: taxonomy/term/%taxonomy_term'), + '#default_value' => str_replace('%25taxonomy_term', '%taxonomy_term', $path), + ); + $form['taxonomy_block__node_count_'.$delta] = array( + '#type' => 'checkbox', + '#title' => t('Show node count'), + '#default_value' => variable_get('taxonomy_block__node_count_'.$delta, 1) ); + return $form; +} - return $blocks; +/** + * Implements hook_block_save(). + */ +function taxonomy_block_block_save($delta = '', $edit = array()) { + if (!empty($edit['taxonomy_block__url_'.$delta])) { + $valid = false; + if (is_array($url = drupal_parse_url($edit['taxonomy_block__url_'.$delta]))) { + $path = str_replace('%taxonomy_term', '%', drupal_get_normal_path($url['path'])); + if (drupal_valid_path($path) || _menu_find_router_path($path) == $path) { + variable_set('taxonomy_block__url_'.$delta, $url); + $valid = true; + } + } + if (!$valid) + form_set_error('taxonomy_block__url_'.$delta, t('Please provide a valid internal drupal path for the URL.')); + } + else + variable_del('taxonomy_block__url_'.$delta); + if (!empty($edit['taxonomy_block__node_count_'.$delta])) + variable_set('taxonomy_block__node_count_'.$delta, $edit['taxonomy_block__node_count_'.$delta]); + else + variable_del('taxonomy_block__node_count_'.$delta); } /** @@ -80,17 +141,16 @@ */ function taxonomy_block_block_view($delta = '') { $block = array(); - - switch ($delta) { - case 'taxonomy_block': - if ($vid = variable_get('taxonomy_block_vid', 0)) { - $block['subject'] = taxonomy_vocabulary_load($vid)->name; - $block['content'] = taxonomy_block_generate_list(taxonomy_block_build_taxonomy_tree($vid, 0), (bool) variable_get('taxonomy_block_node_count', 0)); - } - - break; + if ($vocab = taxonomy_vocabulary_machine_name_load($delta)) { + $block['subject'] = t('Browse by @name', array('@name' => $vocab->name)); + $block['content'] = theme('item_list', array( + 'items' => taxonomy_block_generate_list( + taxonomy_block_build_taxonomy_tree($vocab->vid), + variable_get('taxonomy_block__url_'.$delta, drupal_parse_url('taxonomy/term/%taxonomy_term')), + (bool) variable_get('taxonomy_block__node_count_'.$delta, 1) + ) + )); } - return $block; } @@ -109,7 +169,7 @@ static $results; $args = func_get_args(); - $hash = md5(implode('-', $args)); + $hash = implode('-', $args); if (!isset($results[$hash])) { $terms = array(); @@ -135,8 +195,8 @@ * @param object $terms * @param object $parent */ -function taxonomy_block_nest_taxonomy_terms($terms, $parent) { - foreach ($terms as $term) { +function taxonomy_block_nest_taxonomy_terms(&$terms, $parent) { + foreach ($terms as &$term) { $parent_tid = isset($term->parents[0]) ? $term->parents[0] : 0; if ($parent_tid) { @@ -180,26 +240,33 @@ * @param array $hierarchy * @param bool $show_counts[optional] */ -function taxonomy_block_generate_list($hierarchy, $show_counts = FALSE) { +function taxonomy_block_generate_list($hierarchy, $url, $show_counts = FALSE) { $items = array(); foreach ($hierarchy as $term) { + $item = array(); $title = $term->name; + $base_url = $url; if ($show_counts) { - $title .= t(' (@count)', array('@count' => taxonomy_block_count_nodes_term($term->tid))); + $title .= ' ('.taxonomy_block_count_nodes_term($term->tid).')'; } - $item = l($title, 'taxonomy/term/' . $term->tid); + if (!empty($base_url['query'])) { + foreach ($base_url['query'] as $key => $val) + $base_url['query'][$key] = str_replace('%taxonomy_term', $term->tid, $val); + } + + $item['data'] = l($title, str_replace('%taxonomy_term', $term->tid, $base_url['path']), array_merge(array('html'=>true), $base_url)); if (!empty($term->children)) { - $item .= taxonomy_block_generate_list($term->children, $show_counts); + $item['children'] = taxonomy_block_generate_list($term->children, $url, $show_counts); } $items[] = $item; } - return theme('item_list', array('items' => $items)); + return $items; } /** @@ -213,4 +280,4 @@ ->countQuery() ->execute() ->fetchField(); -} \ No newline at end of file +} diff -ur taxonomy_block/taxonomy_block.settings.inc localmods/taxonomy_block/taxonomy_block.settings.inc --- taxonomy_block/taxonomy_block.settings.inc 2011-06-08 13:36:50.000000000 -0400 +++ localmods/taxonomy_block/taxonomy_block.settings.inc 2011-08-11 14:13:54.624678619 -0400 @@ -10,24 +10,21 @@ function taxonomy_block_admin_settings() { $form = array(); - $vocabs = array(); - foreach(taxonomy_vocabulary_get_names() as $vocab) { - $vocabs[$vocab->vid] = $vocab->name; + $vocabs = taxonomy_vocabulary_get_names(); + ksort($vocabs); + $options= array(); + foreach($vocabs as $machine_name => $vocab) { + $options[$machine_name] = $vocab->name; } - $form['taxonomy_block_vid'] = array( - '#type' => 'select', - '#title' => t('Select a Vocabulary'), - '#default_value' => variable_get('taxonomy_block_vid', 0), - '#description' => t('Select Vocabulary for used by taxonomy block.'), - '#options' => $vocabs + $form['taxonomy_block__machine_names'] = array( + '#type' => 'checkboxes', + '#title' => t('Select Vocabularies'), + '#default_value' => variable_get('taxonomy_block__machine_names', ''), + '#description' => t('Select Vocabularies to be used by taxonomy block.'), + '#multiple' => true, + '#options' => $options ); - $form['taxonomy_block_node_count'] = array( - '#type' => 'checkbox', - '#title' => t('Show node count'), - '#default_value' => variable_get('taxonomy_block_node_count', 0) - ); - return system_settings_form($form); -} \ No newline at end of file +}