--- taxonomy.module.my 2005-05-22 10:55:44.678309928 +0200
+++ taxonomy.module 2005-05-24 12:14:10.805627400 +0200
@@ -919,21 +919,35 @@ function _taxonomy_prepare_insert($data,
* A resource identifier pointing to the query results.
*/
function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE) {
+ echo "taxonomy_select_nodes: tids = "; var_dump($tids); echo "operator = $operator, depth = $depth.\n
";
if (count($tids) > 0) {
// For each term ID, generate an array of descendant term IDs to the right depth.
$descendant_tids = array();
+ $descendant_not_tids = array();
if ($depth === 'all') {
$depth = NULL;
}
foreach ($tids as $index => $tid) {
- $term = taxonomy_get_term($tid);
- $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
- $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
+ $bare_tid = ltrim($tid, '!');
+ $term = taxonomy_get_term($bare_tid);
+ $tree = taxonomy_get_tree($term->vid, $bare_tid, -1, $depth);
+ if ($bare_tid != $tid) // there was a "!"
+ $descendant_not_tids[$index] = array_merge(array($bare_tid), array_map('_taxonomy_get_tid_from_term', $tree));
+ else
+ $descendant_tids[$index] = array_merge(array($bare_tid), array_map('_taxonomy_get_tid_from_term', $tree));
}
if ($operator == 'or') {
- $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
- $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
+ if ($descendant_tids)
+ $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
+ if ($descendant_not_tids)
+ $str_not_tids = implode(',', call_user_func_array('array_merge', $descendant_not_tids));
+ $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE 1=1 ';
+ if ($descendant_tids)
+ $sql .= 'AND tn.tid IN ('. $str_tids .') ';
+ if ($descendant_tids)
+ $sql .= 'AND tn.tid NOT IN ('. $str_not_tids .') ';
+ $sql .= 'AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1';
}
else {
@@ -943,9 +957,15 @@ function taxonomy_select_nodes($tids = a
$joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';
$wheres .= ' AND tn'. $index .'.tid IN ('. implode(',', $tids) .')';
}
- $sql = 'SELECT n.nid, n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres .' ORDER BY n.sticky DESC, n.created DESC';
+ foreach ($descendant_not_tids as $index => $tids) {
+ $joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';
+ $wheres .= ' AND tn'. $index .'.tid NOT IN ('. implode(',', $tids) .')';
+ }
+
+ $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres .' ORDER BY n.sticky DESC, n.created DESC';
$sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE n.status = 1 ' . $wheres;
}
+ echo "taxonomy_select_nodes: sql = $sql\n
";
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
@@ -1000,12 +1020,12 @@ function taxonomy_nodeapi($node, $op, $a
* Menu callback; displays all nodes associated with a term.
*/
function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
- if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)) {
+ if (preg_match('/^(!?[0-9]+[+ ])+!?[0-9]+$/', $str_tids)) {
$operator = 'or';
// The '+' character in a query string may be parsed as ' '.
$tids = preg_split('/[+ ]/', $str_tids);
}
- else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)) {
+ else if (preg_match('/^(!?[0-9]+,)*!?[0-9]+$/', $str_tids)) {
$operator = 'and';
$tids = explode(',', $str_tids);
}
@@ -1034,7 +1054,7 @@ function taxonomy_term_page($str_tids =
if ($tids) {
// Build title:
- $result = db_query('SELECT name FROM {term_data} WHERE tid IN (%s)', implode(',', $tids));
+ $result = db_query('SELECT name FROM {term_data} WHERE tid IN (%s)', str_replace("!", "", implode(',', $tids)));
$names = array();
while ($term = db_fetch_object($result)) {
$names[] = $term->name;