You are here

function theme_similar_content in Similar Entries 6

Same name and namespace in other branches
  1. 5 similar.module \theme_similar_content()
  2. 7 similar.module \theme_similar_content()

Queries the database for similar entries and puts them in a HTML list.

Parameters

$node: The current node being viewed.

Return value

A themed item list of related links.

1 theme call to theme_similar_content()
similar_block in ./similar.module
Implements hook_block().

File

./similar.module, line 222
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 (%s) WHERE n.status <> 0 AND r.nid <> %d AND n.type IN ({$types}) GROUP BY n.nid HAVING score > 0 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 n.status <> 0 AND r.nid <> %d AND n.type IN ({$types}) GROUP BY n.nid HAVING score > 0 ORDER BY score DESC, r.vid DESC";
  }
  $query = db_rewrite_sql($query, 'n', 'nid');
  $result = db_query_range($query, strip_tags($text), $node->nid, 0, variable_get('similar_num_display', 5));
  while ($node = db_fetch_object($result)) {
    $content = node_load($node->nid);
    $no_follow = variable_get('similar_rel_nofollow', 0) ? array(
      'rel' => 'nofollow',
    ) : array();
    if ($teaser) {
      $items[] = '<div class="similar-title">' . l($content->title, 'node/' . $node->nid, array(
        'attributes' => array(
          'title' => $content->title,
        ) + $no_follow,
        'absolute' => TRUE,
      )) . '</div><div class="similar-teaser">' . check_markup($content->teaser, $content->format, FALSE) . '</div>';
    }
    else {
      $items[] = l($content->title, 'node/' . $node->nid, array(
        'attributes' => array(
          'title' => $content->title,
        ) + $no_follow,
      ));
    }
  }
  return sizeof($items) > 0 ? theme('item_list', $items) : '';
}