You are here

function sbp_nodes_sbp_details in Search by Page 6

Same name and namespace in other branches
  1. 7 sbp_nodes.module \sbp_nodes_sbp_details()

Implementation of Search by Page hook_sbp_details().

Returns details for a particular node ID, for particular search keys.

File

./sbp_nodes.module, line 120
Module file for Search by Page Nodes, a sub-module for Search by Page.

Code

function sbp_nodes_sbp_details($id, $environment, $keys = NULL) {
  $id = intval($id);
  if (!$id) {
    return NULL;
  }
  $node = node_load($id, NULL, TRUE);
  if (!$node->title) {
    return NULL;
  }

  // Get basic node info
  $ret = array(
    'type' => check_plain(node_get_types('name', $node)),
    'title' => search_by_page_strip_tags($node->title, $environment),
    'user' => theme('username', $node),
    'date' => $node->changed,
  );
  if (!$keys) {
    return $ret;
  }

  // See if we want to display an excerpt or a teaser
  if (search_by_page_setting_get('sbp_nodes_display_type', $environment, 'excerpts') == 'excerpts') {

    // Render this node, to get snippet, if excerpt is requested
    if ($keys) {
      $content = menu_execute_active_handler('node/' . $id);
      if (!is_int($content)) {
        $ret['snippet'] = search_by_page_excerpt($keys, search_by_page_strip_tags($content, $environment));
      }
    }
  }
  else {

    // We want a teaser
    $ret['snippet'] = search_by_page_strip_tags(node_view($node, TRUE, FALSE, FALSE), $environment);
  }
  return $ret;
}