| 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; |
| 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>'; |
| 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) |
| 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 |
|
|
| 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 |
|
|