You are here

function sbp_nodes_sbp_paths in Search by Page 7

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

Implements Search by Page hook_sbp_paths().

Returns a list of all the nodes that should be indexed.

File

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

Code

function sbp_nodes_sbp_paths($environment) {

  // What node types do they want to index?
  $typelist = search_by_page_setting_get('sbp_nodes_types_indexed', $environment, array());
  if (!is_array($typelist) || !count($typelist)) {
    return array();
  }

  // This variable comes from a checkbox array form element. So it
  // gives us an array like 'page' => 'page', 'story' => 0
  // meaning page should be indexed, but not story
  // so pick out the ones to actually index
  $toindex = array();
  foreach ($typelist as $key => $item) {
    if ($item) {
      $toindex[] = $key;
    }
  }
  if (!count($toindex)) {
    return array();
  }

  // Find all published nodes of those types, and build array of paths
  // Note that we don't want to check for access permissions here! We
  // want to index everything, independent of access rights. Access
  // permission checking is done during the search step -- see
  // hook_sbp_query_modify() implementation below. This is the same
  // procedure followed in node_search(), which performs searching for
  // the core Search module, and node_update_index(), which indexes
  // everything for Search without access checks.
  $res = db_query('SELECT n.nid, n.language FROM {node} n WHERE n.status=1 AND n.type IN (:toindex)', array(
    ':toindex' => $toindex,
  ))
    ->fetchAll();
  $role = search_by_page_setting_get('sbp_nodes_role', $environment, DRUPAL_ANONYMOUS_RID);
  $min_time = search_by_page_setting_get('sbp_nodes_min_time', $environment, 1);
  $max_time = search_by_page_setting_get('sbp_nodes_max_time', $environment, 0);
  $langs = language_list();
  $langs = array_keys($langs);
  $ret = array();
  foreach ($res as $item) {
    $stuff = array(
      'id' => $item->nid,
      'role' => $role,
      'min_time' => $min_time,
      'max_time' => $max_time,
    );
    if ($item->language && $item->language != LANGUAGE_NONE) {
      $stuff['languages'] = array(
        $item->language,
      );
    }
    else {

      // language-neutral - index in all languages
      $stuff['languages'] = $langs;
    }
    $ret['node/' . $item->nid] = $stuff;
  }
  return $ret;
}