/[drupal]/contributions/modules/related_nodes/related_nodes.module
ViewVC logotype

Diff of /contributions/modules/related_nodes/related_nodes.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3, Sat Dec 3 20:20:58 2005 UTC revision 1.4, Sat Dec 3 21:02:50 2005 UTC
# Line 61  function related_nodes_block($op = 'list Line 61  function related_nodes_block($op = 'list
61          '#title' => t('Vocabularies used to relate nodes (select none for unrestricted)'),          '#title' => t('Vocabularies used to relate nodes (select none for unrestricted)'),
62          '#multiple' => TRUE,          '#multiple' => TRUE,
63          '#default_value' => variable_get('related_nodes_vocabularies', array()),          '#default_value' => variable_get('related_nodes_vocabularies', array()),
64            '#return_value' => array(),
65          '#options' => _related_nodes_get_vocabularies(),          '#options' => _related_nodes_get_vocabularies(),
66        );        );
67        return $form;        return $form;
# Line 77  function related_nodes_block($op = 'list Line 78  function related_nodes_block($op = 'list
78            $content = '';            $content = '';
79            $numTags = variable_get('related_nodes_count', 5);            $numTags = variable_get('related_nodes_count', 5);
80    
81              $vocabularies = implode(',',variable_get('related_nodes_vocabularies', array()));
82    
83            if (is_numeric($numTags) && $numTags >= 1) {            if (is_numeric($numTags) && $numTags >= 1) {
84              $content .= '<ul>';              $content .= '<ul>';
85              $haveOne = FALSE;              $haveOne = FALSE;
86              $result = related_nodes_get_nodes($nid, $numTags, FALSE);              $result = related_nodes_get_nodes($nid, $numTags, $vocabularies, FALSE);
87             while ($rn = db_fetch_object($result)) {             while ($rn = db_fetch_object($result)) {
88                $haveOne = TRUE;                $haveOne = TRUE;
89                $content .= '<li>' . l(t($rn->title), 'node/' . $rn->nid) . '</li>';                $content .= '<li>' . l(t($rn->title), 'node/' . $rn->nid) . '</li>';
# Line 100  function related_nodes_block($op = 'list Line 103  function related_nodes_block($op = 'list
103    }    }
104  }  }
105    
106  function related_nodes_get_nodes($nid, $numNodes = 5, $usePager = FALSE, $from = 0) {  function related_nodes_get_nodes($nid, $numNodes = 5, $vocabularies = '', $usePager = FALSE, $from = 0) {
107    if (!is_numeric($nid))    if (!is_numeric($nid))
108      return FALSE;      return FALSE;
109    if ($nid <= 0)    if ($nid <= 0)
# Line 108  function related_nodes_get_nodes($nid, $ Line 111  function related_nodes_get_nodes($nid, $
111    if (!is_numeric($numNodes))    if (!is_numeric($numNodes))
112      $numNodes= variable_get('related_nodes_count', 5);      $numNodes= variable_get('related_nodes_count', 5);
113    
114      if ($vocabularies) {
115        $join = 'INNER JOIN {term_data} td ON tn.tid = td.tid ';
116        $where = ' AND td.vid IN ( ' . $vocabularies . ') ';
117      }
118    
119    $sql = 'SELECT n.nid AS nid, n.title, ' .    $sql = 'SELECT n.nid AS nid, n.title, ' .
120        'COUNT(tn3.tid) c FROM {term_node} tn ' .        'COUNT(tn3.tid) c FROM {term_node} tn ' .
121          $join .
122        'INNER JOIN {term_node} tn2 ON tn.tid = tn2.tid ' .        'INNER JOIN {term_node} tn2 ON tn.tid = tn2.tid ' .
123        'INNER JOIN {term_node} tn3 ON tn2.nid = tn3.nid ' .        'INNER JOIN {term_node} tn3 ON tn2.nid = tn3.nid ' .
124        'INNER JOIN {node} n ON tn3.nid = n.nid ' .        'INNER JOIN {node} n ON tn3.nid = n.nid ' .
125        'WHERE n.status = 1 AND tn.nid = ' . $nid . ' AND tn2.nid <> ' . $nid .        'WHERE n.status = 1 AND tn.nid = ' . $nid . ' AND tn2.nid <> ' . $nid .
126          $where .
127        ' AND tn.nid <> tn3.nid ' .        ' AND tn.nid <> tn3.nid ' .
128        ' GROUP BY n.nid ORDER BY c DESC';        ' GROUP BY n.nid ORDER BY c DESC';
129    
# Line 135  function related_nodes_get_nodes($nid, $ Line 145  function related_nodes_get_nodes($nid, $
145  function _related_nodes_get_vocabularies() {  function _related_nodes_get_vocabularies() {
146    $vocabularies = array();    $vocabularies = array();
147    foreach(taxonomy_get_vocabularies() as $vocab) {    foreach(taxonomy_get_vocabularies() as $vocab) {
148      $vocabularies[$vocab->vid] = $vocab->title;      $vocabularies[$vocab->vid] = $vocab->name;
149    }    }
150    return $vocabularies;    return $vocabularies;
151  }  }
152    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2