diff -rup directory/directory.module directory_new/directory.module --- directory/directory.module 2008-07-16 16:08:25.000000000 +1000 +++ directory.module 2011-01-21 14:13:51.000000000 +1100 @@ -237,17 +237,68 @@ function directory_theme($existing, $typ 'arguments' => array('limit' => NULL, 'element' => 0, 'format' => '%d through %d of %d.'), ), 'directory_home_vocabulary' => array( - 'arguments' => array('vid' => NULL, 'collapse' => TRUE), + 'arguments' => array('vid' => NULL, 'collapse' => TRUE, 'display_title' => TRUE), ), 'directory_resource' => array( 'arguments' => array('tid' => NULL, 'filter' => NULL, 'fid' => NULL), ), 'directory_taxonomy_subterms' => array( - 'arguments' => array('tid' => NULL), + 'arguments' => array('tid' => NULL, 'display_title' => TRUE), ), ); } +/** + * Implemenation of hook_block(). + */ +function directory_block($op = 'list', $delta = 0, $edit = array()) { + if ($op == 'list') { + // Make a directory block for each vocabulary. + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies AS $vid => $vocabulary) { + $blocks['vocab_dir_' . $vocabulary->vid] = array( + 'info' => t('Directory: Vocabulary directory: @vocab', array('@vocab' => $vocabulary->name)), + 'cache' => BLOCK_NO_CACHE, + ); + } + + $blocks['subterms'] = array( + 'info' => t('Directory: Taxonomy subterms'), + 'cache' => BLOCK_CACHE_PER_PAGE, + ); + + return $blocks; + } + else if ($op == 'view') { + // We only want to do a generic vocab delta instead of one for each vocab. + $delta_check = (substr($delta, 0, 10) == 'vocab_dir_') ? substr($delta, 0, 10) : $delta; + + switch ($delta_check) { + case 'vocab_dir_': + $block = array(); + $vid = substr($delta, 10); + $vocab = taxonomy_vocabulary_load($vid); + if ($vocab) { + $block = array( + 'subject' => t('Directory for @vocab', array('@vocab' => $vocab->name)), + 'content' => theme_directory_home_vocabulary($vocab->vid, FALSE, FALSE), + ); + } + break; + case 'subterms': + $block = array(); + if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2)) { + $block = array( + 'subject' => t('Subterms'), + 'content' => theme('directory_taxonomy_subterms', arg(2), FALSE), + ); + } + break; + } + return $block; + } +} + /******************************************************************** * Module Specific :: Public Functions * ******************************************************************/ @@ -298,6 +349,8 @@ function directory_page() { * * @param $vid * integer: the vocabulary ID. + * @param $display_title + * Boolean for whether or not to add a title to the list. * * @param $collapse * boolean: say if the vocabulary should follow the collapsed setting. @@ -307,7 +360,7 @@ function directory_page() { * @return $output * formatted html. */ -function theme_directory_home_vocabulary($vid, $collapse = TRUE) { +function theme_directory_home_vocabulary($vid, $collapse = TRUE, $display_title = TRUE) { static $js_added; $vocabulary = taxonomy_vocabulary_load($vid); $terms = taxonomy_get_children(0, $vid); @@ -330,8 +383,8 @@ function theme_directory_home_vocabulary } $output = '
'; - $output .= theme('directory_list_terms', $terms, t('By !vocabulary-name', - array('!vocabulary-name' => l($vocabulary->name, 'directory/vocabulary/'. $vocabulary->vid)))); + $title = $display_title ? t('By !vocabulary-name', array('!vocabulary-name' => l($vocabulary->name, 'directory/vocabulary/'. $vocabulary->vid))) : ''; + $output .= theme('directory_list_terms', $terms, $title); $output .= '
'; return $output; @@ -692,8 +745,10 @@ function directory_vocabulary_page($vid) * * @param $tid integer * the ID of the term whose children to display + * @param $display_title + * Boolean for whether or not to add a title to the list. */ -function theme_directory_taxonomy_subterms($tids) { +function theme_directory_taxonomy_subterms($tids, $display_title = TRUE) { $tids = explode(' ', $tids); // assuming $tid1+$tid2. if (1 == count($tids)) { $tids = explode(',', $tids[0]); // looking for $tid1,$tid2 instead. @@ -707,15 +762,18 @@ function theme_directory_taxonomy_subter } foreach ($tids AS $tid) { + $title = NULL; $term = taxonomy_get_term($tid); if ($children = taxonomy_get_children($tid)) { $output .= '
'; $items = theme('directory_list_subterms', $children); - if ($add_link) { - $title = t('Subterms for !term', array('!term' => l($term->name, 'taxonomy/term/' . $term->tid))); - } - else { - $title = t('Subterms'); + if ($display_title) { + if ($add_link) { + $title = t('Subterms for !term', array('!term' => l($term->name, 'taxonomy/term/' . $term->tid))); + } + else { + $title = t('Subterms'); + } } $output .= theme('item_list', $items, $title); $output .= '
';