You are here

function sbp_paths_sbp_details in Search by Page 6

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

Implementation of 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 87
Module file for Search by Page Paths, a sub-module for Search by Page.

Code

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

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

  // Translate if necessary
  if (module_exists('i18nstrings')) {
    $code = 'sbp_paths:path:' . $item->pid . ':';
    $item->title = i18nstrings($code . 'title', $item->title);
    $item->page_type = i18nstrings($code . 'type', $item->page_type);
    $snip = drupal_strtolower($item->snippet);
    if ($snip != 'yes' && $snip != 'no') {
      $item->snippet = i18nstrings($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) {

    // Get snippet from page content
    $parts = search_by_page_path_parts($item->page_path);
    $path = drupal_get_normal_path($parts[0]);
    if (isset($parts[1])) {
      $getstuff = array();
      parse_str($parts[1], $getstuff);
      $_GET += $getstuff;
    }
    $content = menu_execute_active_handler($path);
    $content = search_by_page_strip_tags($content, $environment);
    $tmp_get = $_GET;
    if (!is_int($content)) {
      $ret['snippet'] = search_by_page_excerpt($keys, $content);
    }
    $_GET = $tmp_get;
  }
  elseif ($code != 'no' && $keys) {

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