Search hilite changes from Ryan Boren
git-svn-id: http://svn.automattic.com/wordpress/trunk@754 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6bf26558ba
commit
d6ec36fed7
|
@ -1663,6 +1663,7 @@ function add_filter($tag, $function_to_add) {
|
|||
|
||||
/* Highlighting code c/o Ryan Boren */
|
||||
function get_search_query_terms($engine = 'google') {
|
||||
global $s, $s_array;
|
||||
$referer = urldecode($_SERVER[HTTP_REFERER]);
|
||||
$query_array = array();
|
||||
switch ($engine) {
|
||||
|
@ -1673,21 +1674,71 @@ function get_search_query_terms($engine = 'google') {
|
|||
$query_terms = preg_replace('/\'|"/', '', $query_terms);
|
||||
$query_array = preg_split ("/[\s,\+\.]+/", $query_terms);
|
||||
break;
|
||||
|
||||
case 'lycos':
|
||||
$query_terms = preg_replace('/^.*query=([^&]+)&?.*$/i','$1', $referer);
|
||||
$query_terms = preg_replace('/\'|"/', '', $query_terms);
|
||||
$query_array = preg_split ("/[\s,\+\.]+/", $query_terms);
|
||||
break;
|
||||
|
||||
case 'yahoo':
|
||||
$query_terms = preg_replace('/^.*p=([^&]+)&?.*$/i','$1', $referer);
|
||||
$query_terms = preg_replace('/\'|"/', '', $query_terms);
|
||||
$query_array = preg_split ("/[\s,\+\.]+/", $query_terms);
|
||||
break;
|
||||
|
||||
case 'wordpress':
|
||||
// Check the search form vars if the search terms
|
||||
// aren't in the referer.
|
||||
if ( ! preg_match('/^.*s=/i', $referer)) {
|
||||
if (isset($s_array)) {
|
||||
$query_array = $s_array;
|
||||
} else if (isset($s)) {
|
||||
$query_array = array($s);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$query_terms = preg_replace('/^.*s=([^&]+)&?.*$/i','$1', $referer);
|
||||
$query_terms = preg_replace('/\'|"/', '', $query_terms);
|
||||
$query_array = preg_split ("/[\s,\+\.]+/", $query_terms);
|
||||
break;
|
||||
}
|
||||
|
||||
return $query_array;
|
||||
}
|
||||
|
||||
function is_referer_search_engine($engine = 'google') {
|
||||
$referer = urldecode($_SERVER[HTTP_REFERER]);
|
||||
global $siteurl;
|
||||
|
||||
$referer = urldecode($_SERVER[HTTP_REFERER]);
|
||||
//echo "referer is: $referer<br />";
|
||||
if ( ! $engine ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch ($engine) {
|
||||
case 'google':
|
||||
if (preg_match('|^http://(www)?\.?google\.*|i',$referer)) {
|
||||
if (preg_match('/^http:\/\/w?w?w?\.?google.*/i', $referer)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'lycos':
|
||||
if (preg_match('/^http:\/\/search\.lycos.*/i', $referer)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'yahoo':
|
||||
if (preg_match('/^http:\/\/search\.yahoo.*/i', $referer)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'wordpress':
|
||||
if (preg_match("#^$siteurl#i", $referer)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1697,7 +1748,7 @@ function is_referer_search_engine($engine = 'google') {
|
|||
}
|
||||
|
||||
function hilite($text) {
|
||||
$search_engines = array('google');
|
||||
$search_engines = array('wordpress', 'google', 'lycos', 'yahoo');
|
||||
|
||||
foreach ($search_engines as $engine) {
|
||||
if ( is_referer_search_engine($engine) ) {
|
||||
|
|
Loading…
Reference in New Issue