Permalink
Browse files

highlight queries from popular serch engines only FS#2448

  • Loading branch information...
splitbrain committed Jul 28, 2012
1 parent c4a2059 commit 079b3ac10d5d47b9d24320337a7b477f64f060af
Showing with 13 additions and 11 deletions.
  1. +13 −11 inc/common.php
View
@@ -1197,25 +1197,27 @@ function getGoogleQuery() {
}
$url = parse_url($_SERVER['HTTP_REFERER']);
$query = array();
// only handle common SEs
if(!preg_match('/(google|bing|yahoo|ask|duckduckgo|babylon|aol|yandex)/',$url['host'])) return '';
$query = array();
// temporary workaround against PHP bug #49733
// see http://bugs.php.net/bug.php?id=49733
if(UTF8_MBSTRING) $enc = mb_internal_encoding();
parse_str($url['query'], $query);
if(UTF8_MBSTRING) mb_internal_encoding($enc);
$q = '';
if(isset($query['q']))
$q = $query['q']; // google, live/msn, aol, ask, altavista, alltheweb, gigablast
elseif(isset($query['p']))
$q = $query['p']; // yahoo
elseif(isset($query['query']))
$q = $query['query']; // lycos, netscape, clusty, hotbot
elseif(preg_match("#a9\.com#i", $url['host'])) // a9
$q = urldecode(ltrim($url['path'], '/'));
if($q === '') return '';
if(isset($query['q'])){
$q = $query['q'];
}elseif(isset($query['p'])){
$q = $query['p'];
}elseif(isset($query['query'])){
$q = $query['query'];
}
$q = trim($q);
if(!$q) return '';
$q = preg_split('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/', $q, -1, PREG_SPLIT_NO_EMPTY);
return $q;
}

0 comments on commit 079b3ac

Please sign in to comment.