You are here

function sbp_paths_sbp_query_modify in Search by Page 6

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

Implementation of Search by Page hook_sbp_query_modify().

Adds an access permission check to the search query.

File

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

Code

function sbp_paths_sbp_query_modify($environment) {

  // Unfortunately, we don't have a wholesale way to check access permissions.
  // So we have to go through all the paths in our table, and check whether the
  // user has permission to see each one, by querying the menu system.
  // Hopefully, there aren't too many! We store them in a temporary table.
  // Create temporary table
  $table = 'sbptt' . rand();
  db_query_temporary('SELECT p.pid, 1 as perm FROM {sbpp_path} p WHERE p.environment=%d', $environment, $table);

  // Check permissions on each path, store in temporary table
  $res = db_query('SELECT p.pid, p.page_path FROM {sbpp_path} p WHERE p.environment=%d', $environment);
  while ($item = db_fetch_object($res)) {
    $parts = search_by_page_path_parts($item->page_path);
    $mitem = menu_get_item($parts[0]);
    db_query("UPDATE {$table} SET perm=%d WHERE pid=%d", $mitem['access'], $item->pid);
  }

  // Join to our temporary table
  return array(
    'join' => 'LEFT JOIN ' . $table . ' sbpp ON sbpp.pid = sp.modid',
    'where' => 'sbpp.perm = 1',
    'arguments' => array(),
  );
}