You are here

function search404_get_keys in Search 404 6

Same name and namespace in other branches
  1. 5 search404.module \search404_get_keys()
  2. 7 search404.page.inc \search404_get_keys()

Replacement for search_get_keys This function can potentially return dangerous potential SQL inject/XSS data. Return must be sanatized before use.

1 call to search404_get_keys()
search404_page in ./search404.module
Main search function. Started with: http://drupal.org/node/12668 Updated to be more similar to search_view

File

./search404.module, line 40

Code

function search404_get_keys() {
  global $language;
  $keys = $_REQUEST['destination'] ? $_REQUEST['destination'] : $_REQUEST['q'];

  // Abort query on certain extensions, e.g: gif jpg jpeg png
  $extensions = explode(' ', variable_get('search404_ignore_query', 'gif jpg jpeg bmp png'));
  $extensions = trim(implode('|', $extensions));
  if (!empty($extensions) && preg_match("/\\.({$extensions})\$/i", $keys)) {
    return FALSE;
  }

  //Remove the Language Prefix Appended to Search String (http://drupal.org/node/560426)
  if (LANGUAGE_NEGOTIATION_PATH_DEFAULT && $language->language) {
    $keys = preg_replace("/^" . $language->language . "\\//i", '', $keys);
  }
  $regex_filter = variable_get('search404_regex', '');
  $keys_array[] = $keys;
  if (!empty($regex_filter)) {
    $keys = preg_replace("/" . $regex_filter . "/i", '', $keys);
  }

  // Ignore certain extensions from query.
  $extensions = explode(' ', variable_get('search404_ignore_extensions', 'htm html php'));
  $extensions = trim(implode('|', $extensions));
  if (!empty($extensions)) {
    $keys = preg_replace("/\\.({$extensions})\$/i", '', $keys);
  }
  $keys = preg_split('/[' . PREG_CLASS_SEARCH_EXCLUDE . ']+/u', $keys);

  // Ignore certain words (use case insensitive search).
  $keys = array_udiff($keys, explode(' ', variable_get('search404_ignore', t('and or the'))), 'strcasecmp');

  //Sanitize the keys
  foreach ($keys as $a => $b) {
    $keys[$a] = check_plain($b);
  }
  $modifier = variable_get('search404_use_or', FALSE) ? ' OR ' : ' ';
  $keys = trim(implode($modifier, $keys));
  return $keys;
}