From 740dc97b5ff8bd73ed8390b6dd66a5bbe5500517 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Tue, 14 Feb 2006 21:12:09 +0000 Subject: - #35073: Admin/node category filter not working --- modules/node.module | 124 +++++++++++++++++++++++++++++------------------ modules/node/node.module | 124 +++++++++++++++++++++++++++++------------------ 2 files changed, 156 insertions(+), 92 deletions(-) (limited to 'modules') diff --git a/modules/node.module b/modules/node.module index 4cf89859d..0bc004aca 100644 --- a/modules/node.module +++ b/modules/node.module @@ -744,7 +744,7 @@ function node_search($op = 'search', $keys = null) { $form['advanced']['keywords']['negative'] = array('#type' => 'textfield', '#title' => t('Containing none of the words'), '#size' => 30, '#maxlength' => 255); // Taxonomy box - if ($taxonomy = module_invoke('taxonomy', 'form_all')) { + if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { $form['advanced']['category'] = array('#type' => 'select', '#title' => t('Only in the category'), '#prefix' => '
', '#suffix' => '
', '#options' => $taxonomy, '#extra' => 'size="10"', '#multiple' => true); } @@ -938,9 +938,9 @@ function node_last_changed($nid) { return ($node->changed); } -/* -** Node operations -*/ +/** + * List node administration operations that can be performed. + */ function node_operations() { $operations = array( 'approve' => array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'), @@ -953,70 +953,82 @@ function node_operations() { return $operations; } -/* -** Filters -*/ +/** + * List node administration filters that can be applied. + */ function node_filters() { // Regular filters - $filters = array( - 'status' => array('title' => t('status'), - 'options' => array('status-1' => t('published'), 'status-0' => t('not published'), - 'moderate-1' => t('in moderation'), 'moderate-0' => t('not in moderation'), - 'promote-1' => t('promoted'), 'promote-0' => t('not promoted'), - 'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))), - 'type' => array('title' => t('type'), 'where' => "n.type = '%s'", - 'options' => node_get_types())); - // Merge all vocabularies into one for retrieving $value below - if ($taxonomy = module_invoke('taxonomy', 'form_all')) { - $terms = array(); - foreach ($taxonomy as $value) { - $terms = $terms + $value; - } - $filters['category'] = array('title' => t('category'), 'where' => 'tn.tid = %d', - 'options' => $terms, 'join' => 'INNER JOIN {term_node} tn ON n.nid = tn.nid'); - } - if (isset($filters['category'])) { - $filters['category']['options'] = $taxonomy; + $filters['status'] = array('title' => t('status'), + 'options' => array('status-1' => t('published'), 'status-0' => t('not published'), + 'moderate-1' => t('in moderation'), 'moderate-0' => t('not in moderation'), + 'promote-1' => t('promoted'), 'promote-0' => t('not promoted'), + 'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))); + $filters['type'] = array('title' => t('type'), 'options' => node_get_types()); + // The taxonomy filter + if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { + $filters['category'] = array('title' => t('category'), 'options' => $taxonomy); } return $filters; } +/** + * Build query for node administration filters based on session. + */ function node_build_filter_query() { $filters = node_filters(); // Build query $where = $args = array(); $join = ''; - foreach ($_SESSION['node_overview_filter'] as $filter) { + foreach ($_SESSION['node_overview_filter'] as $index => $filter) { list($key, $value) = $filter; - if ($key == 'status') { - // Note: no exploit hole as $value has already been checked - list($key, $value) = explode('-', $value, 2); - $where[] = 'n.'. $key .' = %d'; - } - else { - $where[] = $filters[$key]['where']; + switch($key) { + case 'status': + // Note: no exploitable hole as $key/$value have already been checked when submitted + list($key, $value) = explode('-', $value, 2); + $where[] = 'n.'. $key .' = %d'; + break; + case 'category': + $table = "tn$index"; + $where[] = "$table.tid = %d"; + $join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid "; + break; + case 'type': + $where[] = "n.type = '%s'"; } $args[] = $value; - $join .= $filters[$key]['join']; } $where = count($where) ? 'WHERE '. implode(' AND ', $where) : ''; return array('where' => $where, 'join' => $join, 'args' => $args); } +/** + * Return form for node administration filters. + */ function node_filter_form() { $session = &$_SESSION['node_overview_filter']; $session = is_array($session) ? $session : array(); $filters = node_filters(); $i = 0; - $form['filters'] = array('#type' => 'fieldset', '#title' => t('Show only items where'), '#theme' => 'node_filters'); + $form['filters'] = array('#type' => 'fieldset', + '#title' => t('Show only items where'), + '#theme' => 'node_filters', + ); foreach ($session as $filter) { list($type, $value) = $filter; + if ($type == 'category') { + // Load term name from DB rather than search and parse options array. + $value = module_invoke('taxonomy', 'get_term', $value); + $value = $value->name; + } + else { + $value = $filters[$type]['options'][$value]; + } $string = ($i++ ? 'and where %a is %b' : '%a is %b'); - $form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $filters[$type]['options'][$value]))); + $form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $value))); } foreach ($filters as $key => $filter) { @@ -1034,6 +1046,9 @@ function node_filter_form() { return drupal_get_form('node_filter_form', $form); } +/** + * Theme node administration filter form. + */ function theme_node_filter_form(&$form) { $output .= '
'; $output .= form_render($form['filters']); @@ -1042,6 +1057,9 @@ function theme_node_filter_form(&$form) { return $output; } +/** + * Theme node administraton filter selector. + */ function theme_node_filters(&$form) { $output .= '