You are here

function sbp_nodes_sbp_details in Search by Page 7

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

Implements Search by Page hook_sbp_details().

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

File

./sbp_nodes.module, line 115
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;
  }
  $type = node_type_get_type($node);

  // Get basic node info
  $ret = array(
    'type' => check_plain($type->name),
    'title' => search_by_page_strip_tags($node->title, $environment),
    'user' => theme('username', array(
      'account' => $node,
    )),
    'date' => $node->changed,
    'object' => $node,
  );
  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') {
    $content = search_by_page_stored_page_content('sbp_nodes', $id, $environment);
    if ($content) {
      $ret['snippet'] = search_by_page_excerpt($keys, $content);
    }
  }
  else {

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