diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index e83c9d366..b22ec82fc 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -1661,6 +1661,62 @@ function add_filter($tag, $function_to_add) {
return true;
}
+/* Highlighting code c/o Ryan Boren */
+function get_search_query_terms($engine = 'google') {
+ $referer = urldecode($_SERVER[HTTP_REFERER]);
+ $query_array = array();
+ switch ($engine) {
+ case 'google':
+ // Google query parsing code adapted from Dean Allen's
+ // Google Hilite 0.3. http://textism.com
+ $query_terms = preg_replace('/^.*q=([^&]+)&?.*$/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]);
+
+ if ( ! $engine ) {
+ return 0;
+ }
+
+ switch ($engine) {
+ case 'google':
+ if (preg_match('|^http://(www)?\.?google\.*|i',$referer)) {
+ return 1;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+function hilite($text) {
+ $search_engines = array('google');
+
+ foreach ($search_engines as $engine) {
+ if ( is_referer_search_engine($engine) ) {
+ $query_terms = get_search_query_terms($engine);
+ foreach ($query_terms as $term) {
+ if (!preg_match('/<.+>/',$text)) {
+ $text = preg_replace('/(\b'.$term.'\b)/i','$1',$text);
+ } else {
+ $text = preg_replace('/(?<=>)([^<]+)?(\b'.$term.'\b)/i','$1$2',$text);
+ }
+ }
+ break;
+ }
+ }
+
+ return $text;
+}
+
+
// Check for hacks file if the option is enabled
if (get_settings('hack_file')) {
if (file_exists(ABSPATH . '/my-hacks.php'))