function theme_similar_content in Similar Entries 5
Same name and namespace in other branches
- 6 similar.module \theme_similar_content()
- 7 similar.module \theme_similar_content()
Queries the database for similar entries and puts them in a HTML list
Parameters
object $node:
Return value
string
1 theme call to theme_similar_content()
- similar_block in ./
similar.module - Implementation of hook_block().
File
- ./
similar.module, line 370 - Module that shows a block listing similar entries. NOTE: Uses MySQL's FULLTEXT indexing for MyISAM tables.
Code
function theme_similar_content($node) {
$items = array();
$text = $node->title . ' ' . $node->body;
$teaser = variable_get('similar_teaser_enabled', 0);
$types = _similar_published_node_types();
$types = variable_get('similar_node_types', $types);
array_walk($types, '_similar_content_type_escape');
if (sizeof($types) > 1) {
$types = implode("','", $types);
}
else {
list(, $types) = each($types);
}
$types = "'{$types}'";
if (module_exists('taxonomy') && (variable_get('similar_taxonomy_filter', 0) == 2 && ($taxonomy_tids = variable_get('similar_taxonomy_tids', array()))) || variable_get('similar_taxonomy_filter', 0) == 1 && ($taxonomy_tids = _similar_taxonomy_membership($node->nid))) {
array_walk($taxonomy_tids, '_similar_force_int');
if (sizeof($taxonomy_tids) > 1) {
$taxonomy_tids = implode(',', $taxonomy_tids);
}
else {
list(, $taxonomy_tids) = each($taxonomy_tids);
$taxonomy_tids = (int) $taxonomy_tids;
}
$query = "SELECT r.nid, MATCH(r.body, r.title) AGAINST ('%s') AS score FROM {node_revisions} r INNER JOIN {node} n ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {term_node} t ON n.nid = t.nid AND t.tid IN ({$taxonomy_tids}) WHERE MATCH(r.body, r.title) AGAINST ('%s') AND n.status <> 0 AND r.nid <> %d AND n.type IN ({$types}) GROUP BY n.nid ORDER BY score DESC, r.vid DESC";
}
else {
$query = "SELECT r.nid, MATCH(r.body, r.title) AGAINST ('%s') AS score FROM {node_revisions} r INNER JOIN {node} n ON r.nid = n.nid AND r.vid = n.vid WHERE MATCH(r.body, r.title) AGAINST ('%s') AND n.status <> 0 AND r.nid <> %d AND n.type IN ({$types}) GROUP BY n.nid ORDER BY score DESC, r.vid DESC";
}
$query = db_rewrite_sql($query, 'n', 'nid');
$result = db_query_range($query, $text, $text, $node->nid, 0, variable_get('similar_num_display', 5));
while ($node = db_fetch_object($result)) {
$content = node_load($node->nid);
if ($teaser) {
$items[] = '<div class="similar-title">' . l($content->title, 'node/' . $node->nid, variable_get('similar_rel_nofollow', 0) ? array(
'rel' => 'nofollow',
) : NULL, NULL, NULL, NULL, TRUE) . '</div><div class="similar-teaser">' . check_markup($content->teaser, $content->format, FALSE) . '</div>';
}
else {
$items[] = l($content->title, 'node/' . $node->nid, variable_get('similar_rel_nofollow', 0) ? array(
'rel' => 'nofollow',
) : NULL);
}
}
return sizeof($items) > 0 ? theme('item_list', $items) : '';
}