You are here

function top_searches_process_keys in Top Searches 6

Same name and namespace in other branches
  1. 7 top_searches.module \top_searches_process_keys()
1 call to top_searches_process_keys()
top_searches_top_searches in ./top_searches.module
Hook top_searches. Modules may use this hook to add their search queries. They can later theme the results, to alter the url of the search phrases, to point elsewhere than "search/node/*"

File

./top_searches.module, line 132

Code

function top_searches_process_keys($keys) {

  // Beautify the search phrase
  $keys = preg_replace("/[' ']{2,}/", ' ', ucwords(strtolower(trim($keys))));

  // Search the DB for existing keys:
  $results_qid = db_result(db_query("SELECT qid FROM {top_searches} WHERE q = '%s'", $keys));
  if ($results_qid) {
    db_query("UPDATE {top_searches} SET counter = (counter + 1) WHERE qid = %d", $results_qid);
  }
  else {
    db_query("INSERT INTO {top_searches} (q, counter) VALUES ('%s', %d)", $keys, 1);
  }
}