diff -rup ../directory/directory.module ./directory.module --- ../directory/directory.module 2008-07-16 16:08:25.000000000 +1000 +++ ./directory.module 2011-03-18 05:20:34.000000000 +1100 @@ -21,7 +21,9 @@ */ function directory_help($path, $arg) { if ('taxonomy/term/%' == $path) { - return theme('directory_taxonomy_subterms', arg(2)); + if (variable_get('directory_subterm_help_enabled', TRUE)) { + return theme('directory_taxonomy_subterms', arg(2)); + } } } @@ -196,6 +198,13 @@ function directory_admin_settings() { '#rows' => 5, '#description' => t('This text will be displayed at the top of each directory term page. It is useful for helping or instructing your users.'), ); + + $form['directory_subterm_help_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Show subterms in help on taxonomy term pages'), + '#default_value' => variable_get('directory_subterm_help_enabled', TRUE), + '#description' => t('If enabled, a list of subterms will be displayed in the help text area on taxonomy/term/% pages.'), + ); $form['directory_support_websites'] = array( @@ -237,17 +246,99 @@ 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 == 'configure') { + if ($delta == 'subterms') { + $options = array(0 => '-- All --'); + $vocabs = taxonomy_get_vocabularies(); + foreach ($vocabs as $vocab) { + $options[$vocab->vid] = $vocab->name; + } + $form['vocabs'] = array( + '#type' => 'select', + '#title' => t('Vocabularies'), + '#description' => t('Select which vocabularies to display the subterms block for.'), + '#default_value' => variable_get('directory_subterms_block_vocabs', array(0)), + '#options' => $options, + '#multiple' => TRUE, + ); + return $form; + } + } + else if ($op == 'save') { + if ($delta == 'subterms') { + variable_set('directory_subterms_block_vocabs', $edit['vocabs']); + } + } + 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' && is_numeric(arg(2))) { + $vocabs = variable_get('directory_subterms_block_vocabs', array(0)); + // Don't waste resources loading the term if all vocabs is selected. + $term = in_array(0, $vocabs) ? NULL : taxonomy_get_term(arg(2)); + + // Only display if all vocabs is selected or the term is in one of + // the selected vocabs. + if (in_array(0, $vocabs) || (!empty($term) && in_array($term->vid, $vocabs))) { + $block = array( + 'subject' => t('Subterms'), + 'content' => theme('directory_taxonomy_subterms', arg(2), FALSE), + ); + } + } + break; + } + return $block; + } +} + /******************************************************************** * Module Specific :: Public Functions * ******************************************************************/ @@ -298,6 +389,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 +400,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 +423,8 @@ function theme_directory_home_vocabulary } $output = '