diff options
author | Sem <sembrestels@riseup.net> | 2011-12-31 20:14:45 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2011-12-31 20:14:45 +0100 |
commit | 9f4da6d87f2c520b975f968cedbcde4f3dce1a25 (patch) | |
tree | fee953cf498b6083faf56c61042d3bee07110331 /mod/search | |
parent | a22660e997611fe2afb97689ea23774578ee80db (diff) | |
parent | e49df853b2cc3a6a9bc2dd527a64951050142eb9 (diff) | |
download | elgg-9f4da6d87f2c520b975f968cedbcde4f3dce1a25.tar.gz elgg-9f4da6d87f2c520b975f968cedbcde4f3dce1a25.tar.bz2 |
Merge git://github.com/Elgg/Elgg
Diffstat (limited to 'mod/search')
-rw-r--r-- | mod/search/pages/search/index.php | 7 | ||||
-rw-r--r-- | mod/search/start.php | 5 | ||||
-rw-r--r-- | mod/search/views/default/search/search_box.php | 7 |
3 files changed, 17 insertions, 2 deletions
diff --git a/mod/search/pages/search/index.php b/mod/search/pages/search/index.php index c4e8d2219..efa3ec037 100644 --- a/mod/search/pages/search/index.php +++ b/mod/search/pages/search/index.php @@ -19,7 +19,12 @@ $query = stripslashes(get_input('q', get_input('tag', ''))); // @todo - create function for sanitization of strings for display in 1.8 // encode <,>,&, quotes and characters above 127 -$display_query = mb_convert_encoding($query, 'HTML-ENTITIES', 'UTF-8'); +if (function_exists('mb_convert_encoding')) { + $display_query = mb_convert_encoding($query, 'HTML-ENTITIES', 'UTF-8'); +} else { + // if no mbstring extension, we just strip characters + $display_query = preg_replace("/[^\x01-\x7F]/", "", $query); +} $display_query = htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); // check that we have an actual query diff --git a/mod/search/start.php b/mod/search/start.php index 73a96dc0a..bb8531e9c 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -107,6 +107,7 @@ function search_get_highlighted_relevant_substrings($haystack, $query, $min_matc $word = elgg_strtolower($word); $count = elgg_substr_count($haystack_lc, $word); $word_len = elgg_strlen($word); + $haystack_len = elgg_strlen($haystack_lc); // find the start positions for the words if ($count > 1) { @@ -117,6 +118,10 @@ function search_get_highlighted_relevant_substrings($haystack, $query, $min_matc $stop = $pos + $word_len + $min_match_context; $lengths[] = $stop - $start; $offset += $pos + $word_len; + + if ($offset >= $haystack_len) { + break; + } } } else { $pos = elgg_strpos($haystack_lc, $word); diff --git a/mod/search/views/default/search/search_box.php b/mod/search/views/default/search/search_box.php index 9440dd1de..87d59519c 100644 --- a/mod/search/views/default/search/search_box.php +++ b/mod/search/views/default/search/search_box.php @@ -24,7 +24,12 @@ $value = stripslashes($value); // @todo - create function for sanitization of strings for display in 1.8 // encode <,>,&, quotes and characters above 127 -$display_query = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); +if (function_exists('mb_convert_encoding')) { + $display_query = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); +} else { + // if no mbstring extension, we just strip characters + $display_query = preg_replace("/[^\x01-\x7F]/", "", $value); +} $display_query = htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); |