? .svn ? 220328.patch ? 220354.patch ? taxonomy_menu_extend_views_support.patch ? po/.svn Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_menu/README.txt,v retrieving revision 1.1.4.4 diff -u -p -r1.1.4.4 README.txt --- README.txt 31 Jan 2008 16:23:34 -0000 1.1.4.4 +++ README.txt 13 Feb 2008 00:22:10 -0000 @@ -23,15 +23,7 @@ INSTALLATION INTEGRATE WITH VIEWS ==================== -1) Install Views module - -2) Enable Views and Views UI module - -3) Create a view normally. You can display your content on a table, - only the teaser, the full content; you decide. - -4) Yet on Views page, on Argument fieldset, include Vocabulary ID as - the first argument and Term ID as the second (both optional). - -5) On Taxonomy Menu Settings page, select the new Views that you - created. +1) Install and enable views module +2) Create a view with two arguments for Vocabulary ID and Term ID respectively. +3) Make sure nodes per page is set in page settings, even if page is disabled. +5) Select the new view on the taxonomy menu settings pages. Index: taxonomy_menu.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_menu/taxonomy_menu.inc,v retrieving revision 1.1.2.10 diff -u -p -r1.1.2.10 taxonomy_menu.inc --- taxonomy_menu.inc 31 Jan 2008 16:23:34 -0000 1.1.2.10 +++ taxonomy_menu.inc 13 Feb 2008 00:22:10 -0000 @@ -8,81 +8,50 @@ */ /** - * Admin area. Configure the module, setting which - * vocabularies will be converted into menus items + * Admin area. Configure the module. * * @return * Array. The form fields. */ function _taxonomy_menu_admin() { - $options = array( - TAXONOMY_MENU_NONE => t('No'), - TAXONOMY_MENU_NORMAL => t('Normal') - ); + $form = array(); + extract(_taxonomy_menu_admin_init_options()); - // If the Views module is enabled, add some special - // new features - if (module_exists('views')) { - // Add the Views file with more functions - require_once(drupal_get_path('module', 'views') .'/views_cache.inc'); + // Create some options for each of the vocabularies + $header = array(t('Vocabulary'), t('Status'), t('Operations')); - // Add a new options on Categories - $options[TAXONOMY_MENU_VIEW] = t('Views'); + $rows = array(); + foreach (taxonomy_get_vocabularies() as $vocab) { + $vid = $vocab->vid; + $edit_path = "admin/settings/taxonomy_menu/$vid"; + $show = variable_get("taxonomy_menu_show_$vid", TAXONOMY_MENU_NONE); - // Get the list of User generated views - $views = db_query("SELECT * FROM {view_view}"); - while ($view = db_fetch_array($views)) { - $views_list[$view['name']] = $view['page_title']; + if ($show != TAXONOMY_MENU_VIEW) { + $status = $options[$show]; } - - // Now get a list of default Views - foreach (_views_get_default_views() as $view => $viewdata) { - $views_list[$view] = $viewdata->name; + else { + $status = t('View: %view', array('%view' => variable_get("taxonomy_menu_show_view_$vid", ''))); } - } - - // Create some options for each of the vocabularies - foreach (taxonomy_get_vocabularies() as $vocab) { - $form[$vocab->vid] = array( - '#title' => $vocab->name, - '#tree' => FALSE, - '#type' => 'fieldset' - ); - $form[$vocab->vid]['taxonomy_menu_show_'. $vocab->vid] = array( - '#default_value' => variable_get('taxonomy_menu_show_'. $vocab->vid, TAXONOMY_MENU_NONE), - '#options' => $options, - '#title' => t('Show this category in menu'), - '#type' => 'radios' - ); - // In case of View options selected, select Views - if (module_exists('views')) { - $form[$vocab->vid]['taxonomy_menu_show_view_'. $vocab->vid] = array( - '#default_value' => variable_get('taxonomy_menu_show_view_'. $vocab->vid, ''), - '#options' => $views_list, - '#title' => t('Views available'), - '#type' => 'select' - ); - } + $rows[] = array(l($vocab->name, $edit_path), $status, l(t('Edit'), $edit_path)); } + + $form['taxonomy_menu_vocabs'] = array( + '#type' => 'markup', + '#value' => theme('table', $header, $rows), + ); // General options - $form['taxonomy_menu_display_page'] = array( - '#default_value' => variable_get('taxonomy_menu_display_page', 'category'), - '#description' => t('How should be the first item on the menu? Example: categories/1/2/3, technology/1/2/3'), - '#title' => t('Module page'), - '#type' => 'textfield', - ); $form['taxonomy_menu_display_num'] = array( '#default_value' => variable_get('taxonomy_menu_display_num', FALSE), '#description' => t('If checked, number of node per term will be displayed in the menu.'), - '#title' => t('Display number of nodes per terms'), + '#title' => t('Show number of nodes per terms'), '#type' => 'checkbox', ); $form['taxonomy_menu_hide_empty'] = array( - '#default_value' => variable_get('taxonomy_menu_hide_empty', FALSE), - '#description' => t('If checked, only taxonomy terms with members will be shown in the menu.'), - '#title' => t('Hide Empty Terms'), + '#default_value' => !variable_get('taxonomy_menu_hide_empty', FALSE), + '#description' => t('If checked, empty taxonomy terms will be shown in the menu.'), + '#title' => t('Show Empty Terms'), '#type' => 'checkbox', ); $form['taxonomy_menu_display_descendants'] = array( @@ -101,6 +70,99 @@ function _taxonomy_menu_admin() { } /** + * Configure each vocabulary + * + * @return + * Array. The form fields. + */ +function _taxonomy_menu_admin_vid($vid) { + $form = array('#redirect' => 'admin/settings/taxonomy_menu'); + extract(_taxonomy_menu_admin_init_options()); + $show = variable_get("taxonomy_menu_show_$vid", TAXONOMY_MENU_NONE); + + $form['vid'] = array( + '#type' => 'hidden', + '#value' => $vid, + ); + + $form["taxonomy_menu_own_menu_$vid"] = array( + '#default_value' => variable_get("taxonomy_menu_own_menu_$vid", FALSE), + '#description' => t('If checked, a new menu will be created for the vocabulary.'), + '#title' => t('New menu'), + '#type' => 'checkbox', + ); + + $form["taxonomy_menu_show_$vid"] = array( + '#default_value' => $show, + '#options' => $options, + '#title' => t('Show this category in menu'), + '#type' => 'radios', + ); + + // In case of View options selected, select Views + if (module_exists('views')) { + $form["taxonomy_menu_show_view_$vid"] = array( + '#default_value' => variable_get("taxonomy_menu_show_view_$vid", ''), + '#options' => $views_list, + '#title' => t('Views available'), + '#type' => 'select', + ); + } + + $form["taxonomy_menu_display_page_$vid"] = array( + '#default_value' => variable_get("taxonomy_menu_display_page_$vid", 'category'), + '#description' => t('How should be the first item on the menu? Example: categories/1/2/3, technology/1/2/3'), + '#title' => t('Module page'), + '#type' => 'textfield', + ); + + $form['submit'] = array( + '#value' => t('Submit'), + '#type' => 'submit', + ); + + return $form; +} + +/** + * Assembles and returns a list of options and views for admin forms. + * + * @return + * Array. + * options; A list of values and titles for vocabulary settings. + * views_list; A list of views that can be selected for vocabularies. + */ +function _taxonomy_menu_admin_init_options() { + $options = array( + TAXONOMY_MENU_NONE => t('No'), + TAXONOMY_MENU_NORMAL => t('Normal') + ); + + // If the Views module is enabled, add some special + // new features + if (module_exists('views')) { + // Add the Views file with more functions + require_once(drupal_get_path('module', 'views') .'/views_cache.inc'); + + // Add a new options on Categories + $options[TAXONOMY_MENU_VIEW] = t('Views'); + + // Get the list of User generated views + $views = db_query("SELECT * FROM {view_view}"); + while ($view = db_fetch_array($views)) { + $views_list[$view['name']] = $view['page_title']; + } + + // Now get a list of default Views + foreach (_views_get_default_views() as $view => $viewdata) { + $views_list[$view] = $viewdata->name; + } + } + + return compact('options', 'views_list'); +} + +/** * Implementation of hook_menu(). * * Its the main function for this module. @@ -110,30 +172,50 @@ function _taxonomy_menu_menu() { 'access' => user_access('administer site configuration'), 'callback' => 'drupal_get_form', 'callback arguments' => array('__taxonomy_menu_admin'), - 'file' => 'taxonomy_menu.inc', 'description' => t('Global configuration of taxonomy menu functionality.'), 'path' => 'admin/settings/taxonomy_menu', 'title' => t('Taxonomy Menu'), - 'type' => MENU_NORMAL_ITEM ); + // Create menu items to admin each vocabulary. + foreach (taxonomy_get_vocabularies() as $vocab) { + $vid = $vocab->vid; + $path = "admin/settings/taxonomy_menu/$vid"; + $t_vars = array('!vocab' => $vocab->name); + + $items[$path] = array( + 'access' => user_access('administer site configuration'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('__taxonomy_menu_admin_vid', $vid), + 'description' => t('Configuration of taxonomy menu functionality for the !vocab vocabulary.', $t_vars), + 'path' => $path, + 'title' => t('Taxonomy Menu: !vocab', $t_vars), + 'type' => MENU_CALLBACK, + ); + } + // This user access function will be used for // all menu items $access = user_access('access content'); + // Create menu items for each vocabulary and taxonomy term. foreach (taxonomy_get_vocabularies() as $vocabulary) { - if (variable_get('taxonomy_menu_show_'. $vocabulary->vid, TAXONOMY_MENU_NONE)) { - $path = variable_get('taxonomy_menu_display_page', 'category') .'/'. $vocabulary->vid; + $vid = $vocabulary->vid; + if (variable_get("taxonomy_menu_show_$vid", TAXONOMY_MENU_NONE)) { + $path = variable_get("taxonomy_menu_display_page_$vid", 'category') ."/$vid"; $items[$path] = array( 'access' => $access, 'callback' => '__taxonomy_menu_page', - 'file' => 'taxonomy_menu.inc', - 'page callback' => '__taxonomy_menu_page', 'path' => $path, 'title' => t($vocabulary->name), - 'weight' => $vocabulary->weight + 'weight' => $vocabulary->weight, ); + if (variable_get("taxonomy_menu_own_menu_$vid", FALSE)) { + $items[$path]['pid'] = 0; + $items[$path]['type'] = 310; + } + $tree = taxonomy_get_tree($vocabulary->vid); $old_depth = -1; $old_path = $path; @@ -150,12 +232,20 @@ function _taxonomy_menu_menu() { $old_path = $path; // Calculate the numbers of children nodes - $num = taxonomy_term_count_nodes($term->tid); + if (variable_get("taxonomy_menu_show_$vid", TAXONOMY_MENU_NORMAL) != TAXONOMY_MENU_VIEW) { + $num = taxonomy_term_count_nodes($term->tid); + } + else { + $arguments = array($vid, $term->tid); + $view = views_get_view(variable_get("taxonomy_menu_show_view_$vid", '')); + $view_queries = views_build_view('queries', $view, $arguments); + $num = db_result(db_query($view_queries['countquery'], $view_queries['args'])); + } // If the number of children nodes of this term is // zero and the Hide Empty Terms option is enabled, // dont create the menu item - if (variable_get('taxonomy_menu_hide_empty', FALSE) == FALSE or $num != 0) { + if (variable_get('taxonomy_menu_hide_empty', FALSE) == FALSE || $num > 0) { $name = t($term->name); if (variable_get('taxonomy_menu_display_num', FALSE) == TRUE) { $name .= ' ('. $num .')'; @@ -164,8 +254,6 @@ function _taxonomy_menu_menu() { 'access' => $access, 'callback' => '__taxonomy_menu_page', 'description' => t($term->description), - 'file' => 'taxonomy_menu.inc', - 'page callback' => '__taxonomy_menu_page', 'path' => $path, 'title' => $name, 'weight' => $term->weight @@ -174,6 +262,7 @@ function _taxonomy_menu_menu() { } } } + return $items; } @@ -190,7 +279,7 @@ function _taxonomy_menu_menu() { */ function _taxonomy_menu_node_view(&$node, &$vocabs) { foreach ($vocabs as $vid => $vocab) { - $path = variable_get('taxonomy_menu_display_page', 'category') .'/'. $vid; + $path = variable_get("taxonomy_menu_display_page_$vid", 'category') .'/'. $vid; $tree = taxonomy_get_tree($vid); $old_depth = -1; @@ -232,7 +321,7 @@ function _taxonomy_menu_page() { // Depending on what Output technique is used, // show the nodes' list - if (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_NORMAL) { + if (variable_get("taxonomy_menu_show_$vid", TAXONOMY_MENU_NORMAL) != TAXONOMY_MENU_VIEW) { if ($tid = arg(2)) { $tid = explode('/', $_GET['q']); $tid = db_escape_string(array_pop($tid)); @@ -265,7 +354,7 @@ function _taxonomy_menu_page() { // Render the selected nodes $output = taxonomy_render_nodes($result); } - elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_VIEW) { + else { // Get the last page argument $tid = explode('/', $_GET['q']); $tid = db_escape_string(array_pop($tid)); @@ -277,10 +366,12 @@ function _taxonomy_menu_page() { $arguments[] = $tid; } + // What page? Type check, since a malicious user can modify $_GET[*]. + $page = (int)max($_GET['page'], 0); + // Embed the views output into the page - $output = views_build_view('embed', - views_get_view(variable_get('taxonomy_menu_show_views_'. $vid, '')), - $arguments, FALSE, NULL); + $view = views_get_view(variable_get("taxonomy_menu_show_view_$vid", '')); + $output = views_build_view('embed', $view, $arguments, TRUE, $view->nodes_per_page, $page); } } Index: taxonomy_menu.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_menu/taxonomy_menu.module,v retrieving revision 1.17.2.1.2.12 diff -u -p -r1.17.2.1.2.12 taxonomy_menu.module --- taxonomy_menu.module 31 Jan 2008 16:23:34 -0000 1.17.2.1.2.12 +++ taxonomy_menu.module 13 Feb 2008 00:22:10 -0000 @@ -14,8 +14,7 @@ define('TAXONOMY_MENU_VIEW', 2); define('TAXONOMY_MENU_DEFAULT_TAX', 3); /** - * Admin area. Configure the module, setting which - * vocabularies will be converted into menus items + * Admin area. Configure the module. * * @return * Array. The form fields. @@ -26,22 +25,41 @@ function __taxonomy_menu_admin() { } /** - * Admin area. Configure the module, setting which - * vocabularies will be converted into menus items + * Admin area. Configure the module. */ function __taxonomy_menu_admin_submit(&$form_id, &$form) { // Save these options - variable_set('taxonomy_menu_display_page', $form['taxonomy_menu_display_page']); variable_set('taxonomy_menu_display_num', $form['taxonomy_menu_display_num']); - variable_set('taxonomy_menu_hide_empty', $form['taxonomy_menu_hide_empty']); + variable_set('taxonomy_menu_hide_empty', !$form['taxonomy_menu_hide_empty']); variable_set('taxonomy_menu_display_descendants', $form['taxonomy_menu_display_descendants']); - // Save which category should be displayed on menu - foreach (taxonomy_get_vocabularies() as $vocab) { - variable_set('taxonomy_menu_show_'. $vocab->vid, $form['taxonomy_menu_show_'. $vocab->vid]); - if (module_exists('views')) { - variable_set('taxonomy_menu_show_views_'. $vocab->vid, $form['taxonomy_menu_show_view_'. $vocab->vid]); - } + // Rebuild the menu to include these features + menu_rebuild(); +} + +/** + * Admin for each vocabulary. + * + * @return + * Array. The form fields. + */ +function __taxonomy_menu_admin_vid($vid) { + require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.inc'); + return _taxonomy_menu_admin_vid($vid); +} + +/** + * Admin for each vocabulary. + */ +function __taxonomy_menu_admin_vid_submit(&$form_id, &$form) { + $vid = $form['vid']; + + variable_set("taxonomy_menu_show_$vid", $form["taxonomy_menu_show_$vid"]); + variable_set("taxonomy_menu_display_page_$vid", $form["taxonomy_menu_display_page_$vid"]); + variable_set("taxonomy_menu_own_menu_$vid", $form["taxonomy_menu_own_menu_$vid"]); + + if (module_exists('views')) { + variable_set("taxonomy_menu_show_view_$vid", $form["taxonomy_menu_show_view_$vid"]); } // Rebuild the menu to include these features