? example.patch
Index: refine_by_taxo.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/refine_by_taxo/refine_by_taxo.info,v
retrieving revision 1.3
diff -u -p -r1.3 refine_by_taxo.info
--- refine_by_taxo.info 4 Mar 2008 20:26:21 -0000 1.3
+++ refine_by_taxo.info 22 Feb 2009 12:17:15 -0000
@@ -1,3 +1,6 @@
-; $Id: refine_by_taxo.info,v 1.3 2008/03/04 20:26:21 ber Exp $
+; $Id: refine_by_taxo.info,v 1.0.0.0 2008/08/26 23:07:00 dww Exp $
name = Refine by taxonomy
description = "Provides blocks that enable you to refine a taxonomy view. Some features only work when tagadelic is installed."
+version = "6x-1.x-dev"
+project = "refine_by_taxo"
+core = 6.x
\ No newline at end of file
Index: refine_by_taxo.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/refine_by_taxo/refine_by_taxo.module,v
retrieving revision 1.13
diff -u -p -r1.13 refine_by_taxo.module
--- refine_by_taxo.module 1 May 2008 14:35:06 -0000 1.13
+++ refine_by_taxo.module 22 Feb 2009 12:17:16 -0000
@@ -1,5 +1,5 @@
'textfield',
'#title' => t('Block title'),
@@ -78,7 +78,7 @@ function refine_by_taxo_save_blocks($del
*/
function refine_by_taxo_view_blocks($delta) {
list($op, $type) = explode('_', variable_get('refine_by_taxo_type_'. $delta, 'and_node'));
- $voc = taxonomy_get_vocabulary($delta);
+ $voc = taxonomy_vocabulary_load($delta);
$terms = array();
//Input sanitizing
@@ -124,9 +124,9 @@ function refine_by_taxo_build_body($term
$content = '';
foreach ($terms as $term) {
- // BAH Drupal encodes the paths, what a crap.
+ // BAH Drupal encodes teh paths, what a crap.
// $items[] = l($term->name, refine_by_taxo_build_url($term->tid, $op));
- $items[] = ''. check_plain($term->name) .'';
+ $items[] = ''. $term->name .'';
}
if (count($items) > 0) {
@@ -168,7 +168,7 @@ function refine_by_taxo_build_url($refin
$replacement = '$0' . $splitter . $refine_tid;
$path = preg_replace($pattern, $replacement, $_GET['q']);
- return url($path, NULL, NULL, FALSE, FALSE);
+ return url($path, array());
}
/**
@@ -192,7 +192,7 @@ function refine_by_taxo_find_related_ter
if ($conditions) {
$sql = db_escape_string('SELECT DISTINCT tn.tid FROM {term_node} tn INNER JOIN {term_data} td ON td.tid = tn.tid WHERE' . $conditions);
- $result = db_query(db_rewrite_sql($sql, 'tn', 'tid'));
+ $result = db_query(db_rewrite_sql($sql));
while ($i <= variable_get('refine_by_taxo_block_tags_'. $delta, 12) && ($tid = db_fetch_object($result))) {
$terms[$tid->tid] = taxonomy_get_term($tid->tid);
$i++;
@@ -251,7 +251,7 @@ function refine_by_taxo_current_nids() {
$tids = refine_by_taxo_current_terms(FALSE);
$op = refine_by_taxo_get_leading_op();
- $result = taxonomy_select_nodes($tids, $op, 0, FALSE);
+ $result = refine_by_taxo_select_nodes($tids, $op);
while ($row = db_fetch_object($result)) {
$nids[] = $row->nid;
@@ -317,3 +317,50 @@ function _refine_by_taxo_options() {
'and_hierarchy' => t('Refine tags with AND, interconnected through hierarchy'),
);
}
+
+
+
+/** PATCH included from http://drupal.org/node/120271 -- on Sept 7 2007 to add more filters based on more content
+ * Finds all nodes that match selected taxonomy conditions.
+ * Based on taxonomy_select_nodes of taxonomy.module and modified a bit
+ * to always return all the nodes (no just the first 10 or so) and to
+ * not sort the nodes list (for performance reasons).
+ * Also removed some default parameters ($depth) and some superfluous
+ * code ($sql_count).
+ *
+ * @param $tids
+ * An array of term IDs to match.
+ * @param $operator
+ * How to interpret multiple IDs in the array. Can be "or" or "and".
+ * @return
+ * A resource identifier pointing to the query results.
+ */
+function refine_by_taxo_select_nodes($tids = array(), $operator = 'or') {
+ if (count($tids) > 0) {
+ // For each term ID, generate an array of descendant term IDs to the right depth.
+ $descendant_tids = array();
+ foreach ($tids as $index => $tid) {
+ $term = taxonomy_get_term($tid);
+ $tree = taxonomy_get_tree($term->vid, $tid, -1, 0);
+ $descendant_tids[] = array_merge(array($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 AND n.moderate = 0';
+ }
+ else {
+ $joins = '';
+ $wheres = '';
+ foreach ($descendant_tids as $index => $tids) {
+ $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.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 AND n.moderate = 0 '. $wheres;
+ }
+ $sql = db_rewrite_sql($sql);
+ $result = db_query($sql);
+ }
+
+ return $result;
+}
\ No newline at end of file