You are here

function sbp_paths_sbp_details in Search by Page 7

Same name and namespace in other branches
  1. 6 sbp_paths.module \sbp_paths_sbp_details()

Implements Search by Page hook_sbp_details().

Reads details information stored in the database, extracts snippet if necessary, and returns it.

File

./sbp_paths.module, line 91
Module file for Search by Page Paths, a sub-module for Search by Page.

Code

function sbp_paths_sbp_details($id, $environment, $keys = NULL) {

  // Get info from DB
  $item = db_query('SELECT p.pid, p.title, p.page_path, p.page_type, p.snippet FROM {sbpp_path} p WHERE p.pid = :pid', array(
    ':pid' => $id,
  ))
    ->fetchObject();
  if (!$item->pid) {
    return NULL;
  }

  // Translate if necessary
  if (module_exists('i18n_string')) {
    $code = 'sbp_paths:path:' . $item->pid . ':';
    $item->title = i18n_string_translate($code . 'title', $item->title);
    $item->page_type = i18n_string_translate($code . 'type', $item->page_type);
    $snip = drupal_strtolower($item->snippet);
    if ($snip != 'yes' && $snip != 'no' && $keys) {
      $item->snippet = i18n_string_translate($code . 'snippet', $item->snippet);
    }
  }

  // Basic page info
  $ret = array(
    'type' => $item->page_type,
    'title' => search_by_page_strip_tags($item->title, $environment),
  );

  // Snippet -- DB either stores "yes", "no", or a custom snippet to use
  $code = drupal_strtolower($item->snippet);
  if ($code == 'yes' && $keys) {
    $content = search_by_page_stored_page_content('sbp_paths', $id, $environment);
    if ($content) {
      $ret['snippet'] = search_by_page_excerpt($keys, $content);
    }
  }
  elseif ($code != 'no' && $keys) {

    // User-supplied custom snippet
    $ret['snippet'] = search_by_page_strip_tags($item->snippet, $environment);
  }
  return $ret;
}