t('node neighbors'), 'path' => 'node_neighbors', 'callback' => 'node_neighbors_overview', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); } return $items; } /** * Display the last ten nodes of terms assigned to $nnid. */ function node_neighbors_overview($nnid) { drupal_set_title('Related Stories'); $node = node_load(array('nid' => $nnid)); $output = '
'.theme('node', $node); // get terms assigned to this node. we had to write this manually because // we wanted alphabetical terms, regardless of the weight applied to vids. $terms = node_neighbors_taxonomy_node_get_terms($nnid); foreach ($terms as $term) { // bah. kludgey. // skip NHPR Programs vocabulary. if ($term->vid == 3) { continue; } $cells = NULL; // we don't use nhpr_taxonomy_get_term_nodes here because that auto // loads the ENTIRE node. that's a huge amount of overhead for a big // list of roughly 50 nodes on one page. we'll do everything manually. $sql = "SELECT fd.nid FROM {flexinode_data} fd INNER JOIN {term_node} tn ". "ON tn.nid = fd.nid WHERE fd.field_id = 1 AND fd.numeric_data < ". "UNIX_TIMESTAMP(NOW()) AND tn.tid = %d ORDER BY fd.numeric_data DESC LIMIT %d"; $result = db_query($sql, $term->tid, 10); // check how many results there are too. $result_count = mysql_num_rows($result); // used later to determine a "read more..." $xml_icon = theme('xml_icon', url("taxonomy/term/$term->tid/0/feed")); $term_url = url("taxonomy/term/$term->tid"); $term_uc = ucwords($term->name); while ($nid = db_fetch_object($result)) { if ($nnid == $nid->nid) { continue; } // skip ourselves. $node = db_fetch_object(db_query('SELECT n.nid, n.title, numeric_data AS flexinode_1 FROM node n LEFT '. 'JOIN flexinode_data fd ON fd.nid = n.nid WHERE n.nid = %d AND fd.field_id = 1', $nid->nid)); $nurl = url("node/$node->nid"); $date = format_date($node->flexinode_1, 'custom', 'l, F j, Y'); $cells .= "$date"; // no times, no times! $cells .= "$node->title"; } if ($cells) { $output .= "

$xml_icon$term_uc

$cells
"; } if ($result_count == 10) { $output .= "see all matches for $term_uc >>"; } } return $output; } /** * Displays inline vertical or horizontal box on node content. */ function node_neighbors_box($nid, $vertical = 0) { $output = NULL; // start the header for our vertical or horizontal box thing. $output .= $vertical ? '
' : '
'; $terms = node_neighbors_taxonomy_node_get_terms($nid); $where = array(); foreach ($terms as $term) { if ($term->vid == 3) { continue; } // create a SQL WHERE clause $where[] = "tn1.tid = '$term->tid'"; // for this batch of terms. } $where = $where ? "(" . implode(' OR ', $where) . ")" : NULL; $except = " AND n.nid != '$nid' "; if (!$where) { return NULL; } // first up is three related news item, where the returned nodes // have to have "NHPR News" as one of their assigned terms. $output .= "

Related news:

"; $result = db_query("SELECT DISTINCT(n.nid), n.title, numeric_data AS flexinode_1 ". "FROM {node} n LEFT JOIN {flexinode_data} fd ON n.nid = fd.nid ". "LEFT JOIN {term_node} tn1 ON tn1.nid = n.nid LEFT JOIN {term_node} ". "tn2 ON tn1.nid = tn2.nid AND tn2.tid = 15002 WHERE $where $except AND ". "tn2.nid IS NOT NULL AND fd.field_id = 1 ORDER BY flexinode_1 DESC LIMIT 3"); while ($node = db_fetch_object($result)) { $url = url("node/$node->nid"); $date = format_date($node->flexinode_1, 'custom', 'l, F j, Y'); $output .= "

$date
"; $output .= "$node->title

"; } // any division for our horizontal box? $output .= $vertical ? NULL : '
'; // next are nodes that DO NOT have "NHPR News" as one of their terms. $output .= "

Related shows:

"; $result = db_query("SELECT DISTINCT(n.nid), n.title, numeric_data AS flexinode_1 ". "FROM {node} n LEFT JOIN {flexinode_data} fd ON n.nid = fd.nid ". "LEFT JOIN {term_node} tn1 ON tn1.nid = n.nid LEFT JOIN {term_node} ". "tn2 ON tn1.nid = tn2.nid AND tn2.tid = 15002 WHERE $where $except AND ". "tn2.nid IS NULL AND fd.field_id = 1 ORDER BY flexinode_1 DESC LIMIT 3"); while ($node = db_fetch_object($result)) { $url = url("node/$node->nid"); $date = format_date($node->flexinode_1, 'custom', 'l, F j, Y'); $output .= "

$date
"; $output .= "$node->title

"; } $see_more_url = url("node_neighbors/$nid"); // oh, but there's plenty more! $see_more .= ""; $output .= $vertical ? "$see_more" : "
$see_more
"; return $output; } /** * Same as taxonomy_node_get_terms, only without weights. */ function node_neighbors_taxonomy_node_get_terms($nid, $key = 'tid') { static $terms; if (!isset($terms[$nid])) { $result = db_query('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t '. 'ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = '. 'v.vid WHERE r.nid = %d ORDER BY t.name', $nid); $terms[$nid] = array(); while ($term = db_fetch_object($result)) { $terms[$nid][$term->$key] = $term; } } return $terms[$nid]; } ?>