Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.152 diff -u -r1.152 taxonomy.module --- modules/taxonomy.module 18 Oct 2004 17:46:19 -0000 1.152 +++ modules/taxonomy.module 25 Oct 2004 20:58:49 -0000 @@ -642,10 +642,10 @@ if (!isset($count[$type])) { // $type == 0 always evaluates true is $type is a string if (is_numeric($type)) { - $result = db_query('SELECT t.tid, COUNT(*) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid'); + $result = db_query('SELECT t.tid, COUNT(*) AS c FROM {term_node} t '. node_access_join_sql() .'INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND '. node_access_where_sql() .'GROUP BY t.tid'); } else { - $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid", $type); + $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t, {node} n ". node_access_join_sql() ." WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' AND ". node_access_where_sql() ." GROUP BY t.tid", $type); } while ($term = db_fetch_object($result)) { $count[$type][$term->tid] = $term->c; @@ -804,7 +804,11 @@ * @return * A resource identifier pointing to the query results. */ -function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE) { +function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $types = array()) { + // build type filter + $typefilter=''; + if (!empty($types)) $typefilter = " AND n.type IN ('". implode("', '", $types) ."')"; + if (count($tids) > 0) { // For each term ID, generate an array of descendant term IDs to the right depth. $descendant_tids = array(); @@ -819,8 +823,8 @@ if ($operator == 'or') { $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids)); - $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.created FROM {node} n '. node_access_join_sql() .' INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 AND '. node_access_where_sql() .' ORDER BY n.sticky DESC, n.created DESC'; - $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 AND '. node_access_where_sql(); + $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.created FROM {node} n '. node_access_join_sql() .' INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 AND '. node_access_where_sql() . $typefilter. ' ORDER BY n.sticky DESC, n.created DESC'; + $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 '.$typefilter.' AND '. node_access_where_sql(); } else { $joins = ''; @@ -829,8 +833,8 @@ $joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid'; $wheres .= ' AND tn'. $index .'.tid IN ('. implode(',', $tids) .')'; } - $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.created FROM {node} n '. node_access_join_sql() . $joins .' WHERE n.status = 1 AND '. node_access_where_sql() . $wheres .' ORDER BY n.sticky DESC, n.created DESC'; - $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() . $joins .' WHERE n.status = 1 AND '. node_access_where_sql() . $wheres; + $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.created FROM {node} n '. node_access_join_sql() . $joins .' WHERE n.status = 1 AND '. node_access_where_sql() . $wheres . $typefilter. ' ORDER BY n.sticky DESC, n.created DESC'; + $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() . $joins .' WHERE n.status = 1 ' . $typefilter . ' AND ' . node_access_where_sql() . $wheres; } if ($pager) { @@ -882,6 +886,16 @@ * Menu callback; displays all nodes associated with a term. */ function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { + // extract node types + list($str_tids,$tps) = split ('[()]', $str_tids); + // check every node type + if (!empty($tps)) { + $types=explode(',',$tps); + foreach ($types as $tp => $c) { + if (!in_array($c, node_list())) drupal_not_found(); + } + } + if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)) { $operator = 'or'; // The '+' character in a query string may be parsed as ' '. @@ -918,7 +932,7 @@ drupal_set_html_head(''); - $output = taxonomy_render_nodes(taxonomy_select_nodes($tids, $operator, $depth, TRUE)); + $output = taxonomy_render_nodes(taxonomy_select_nodes($tids, $operator, $depth, TRUE, $types)); print theme('page', $output, $title); break; @@ -928,7 +942,7 @@ $channel['title'] = variable_get('site_name', 'drupal') .' - '. $title; $channel['description'] = $term->description; - $result = taxonomy_select_nodes($tids, $operator, $depth, FALSE); + $result = taxonomy_select_nodes($tids, $operator, $depth, FALSE, $types); node_feed($result, $channel); break; default: