| 1 |
<?php
|
| 2 |
// $Id: series.module,v 1.1.2.2 2004/09/18 13:42:39 goba Exp $
|
| 3 |
|
| 4 |
// Integrate with the Drupal module selection page properly
|
| 5 |
function series_help($section){
|
| 6 |
if ($section == 'admin/modules#description') {
|
| 7 |
return t("Allows you to group nodes into series (using taxonomy).");
|
| 8 |
}
|
| 9 |
}
|
| 10 |
|
| 11 |
// Let admin select a taxonomy to hold series information
|
| 12 |
function series_settings() {
|
| 13 |
$vocs = array();
|
| 14 |
foreach (taxonomy_get_vocabularies() as $vid => $voc) {
|
| 15 |
$vocs[$vid] = $voc->name;
|
| 16 |
}
|
| 17 |
if (count($vocs)) {
|
| 18 |
$form = form_select(t("Series vocabulary"), "series_nav_vocabulary", variable_get("series_nav_vocabulary", ""), $vocs, t("The vocabulary used to contain series groups."));
|
| 19 |
}
|
| 20 |
else {
|
| 21 |
$form = form_item(t("Series vocabulary"), t("At least one <a href=\"%url\">vocabulary</a> should be set up, so it can contain the list of series available on the website.", array("%url" => url("admin/taxonomy"))));
|
| 22 |
}
|
| 23 |
return $form;
|
| 24 |
}
|
| 25 |
|
| 26 |
// Nodeapi hook to add node id for series filter (requires patched core!)
|
| 27 |
function series_nodeapi(&$node, $op, $a3, $a4) {
|
| 28 |
|
| 29 |
// Vocabulary needs to be set for this to work
|
| 30 |
if (($vid = variable_get("series_nav_vocabulary", "")) && ($op == 'view')) {
|
| 31 |
_series_filter($node, $a3, $a4, $vid);
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
// Add series block, if we are filtering a node and the node is in a serial
|
| 36 |
function _series_filter(&$node, $main, $page, $vid) {
|
| 37 |
|
| 38 |
// Filter the value of this property
|
| 39 |
$property = ($main ? 'teaser' : 'body');
|
| 40 |
|
| 41 |
// Try to find the place where the series block should go
|
| 42 |
if (preg_match("!\\[series-info:(left|right|center)\\]!", $node->$property, $match)) {
|
| 43 |
|
| 44 |
// Find out the one serial this node is in
|
| 45 |
$terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node->nid, $vid));
|
| 46 |
if (count($terms) == 1) {
|
| 47 |
$nodelist = _series_nodelist($terms[0]);
|
| 48 |
if (count($nodelist) > 1) {
|
| 49 |
$nodelinks = array();
|
| 50 |
foreach ($nodelist as $node_in_series) {
|
| 51 |
if ($node_in_series->nid == $node->nid) {
|
| 52 |
$nodelinks[] = $node_in_series->title;
|
| 53 |
}
|
| 54 |
else {
|
| 55 |
$nodelinks[] = l($node_in_series->title, 'node/' . $node_in_series->nid);
|
| 56 |
}
|
| 57 |
}
|
| 58 |
$node->$property = str_replace($match[0], theme("series_box", $nodelinks, $match[1]), $node->$property);
|
| 59 |
return;
|
| 60 |
}
|
| 61 |
}
|
| 62 |
|
| 63 |
// Remove series reference, since no matching series have been found
|
| 64 |
$node->$property = str_replace($match[0], "", $node->$property);
|
| 65 |
return;
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
function theme_series_box($nodelinks, $align) {
|
| 70 |
return "<div class=\"series-box series-$align\">" . theme("item_list", $nodelinks, t('Also published in this series')) . "</div>";
|
| 71 |
}
|
| 72 |
|
| 73 |
// Get the nodes from the same serial
|
| 74 |
function _series_nodelist($tid) {
|
| 75 |
$nodelist = array();
|
| 76 |
if ($result = db_query("SELECT n.nid, n.title FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND t.tid = %d ORDER BY n.created", $tid)) {
|
| 77 |
while ($node = db_fetch_object($result)) {
|
| 78 |
$nodelist[] = $node;
|
| 79 |
}
|
| 80 |
}
|
| 81 |
return $nodelist;
|
| 82 |
}
|
| 83 |
|
| 84 |
?>
|