[geeklog-cvs] geeklog: Check if the text and query are empty before attempting...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Jan 30 10:28:27 EST 2011
changeset 8089:c1f500666c73
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/c1f500666c73
user: Dirk Haun <dirk at haun-online.de>
date: Sun Jan 30 16:28:00 2011 +0100
description:
Check if the text and query are empty before attempting to highlight a query (cf. patch #0001204)
diffstat:
public_html/lib-common.php | 49 +++++++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 22 deletions(-)
diffs (61 lines):
diff -r 70336a86d147 -r c1f500666c73 public_html/lib-common.php
--- a/public_html/lib-common.php Sun Jan 30 13:13:35 2011 +0100
+++ b/public_html/lib-common.php Sun Jan 30 16:28:00 2011 +0100
@@ -6005,30 +6005,35 @@
* @return string the text with highlighted search words
*
*/
-function COM_highlightQuery( $text, $query, $class = 'highlight' )
+function COM_highlightQuery($text, $query, $class = 'highlight')
{
- // escape PCRE special characters
- $query = preg_quote($query, '/');
-
- $mywords = explode(' ', $query);
- foreach ($mywords as $searchword)
- {
- if (!empty($searchword))
- {
- $before = "/(?!(?:[^<]+>|[^>]+<\/a>))\b";
- $after = "\b/i";
- if ($searchword <> utf8_encode($searchword)) {
- if (@preg_match('/^\pL$/u', urldecode('%C3%B1'))) { // Unicode property support
- $before = "/(?<!\p{L})";
- $after = "(?!\p{L})/u";
- } else {
- $before = "/";
- $after = "/u";
- }
+ if (!empty($text) && !empty($query)) {
+
+ // escape PCRE special characters
+ $query = preg_quote($query, '/');
+
+ $mywords = explode(' ', $query);
+ foreach ($mywords as $searchword) {
+ if (!empty($searchword)) {
+ $before = "/(?!(?:[^<]+>|[^>]+<\/a>))\b";
+ $after = "\b/i";
+ if ($searchword <> utf8_encode($searchword)) {
+ if (@preg_match('/^\pL$/u', urldecode('%C3%B1'))) {
+ // Unicode property support
+ $before = "/(?<!\p{L})";
+ $after = "(?!\p{L})/u";
+ } else {
+ $before = "/";
+ $after = "/u";
+ }
+ }
+ $text = preg_replace($before . $searchword . $after,
+ "<span class=\"$class\">\\0</span>",
+ '<!-- x -->' . $text . '<!-- x -->');
}
- $text = preg_replace($before . $searchword . $after, "<span class=\"$class\">\\0</span>", '<!-- x -->' . $text . '<!-- x -->' );
- }
- }
+ }
+ }
+
return $text;
}
More information about the geeklog-cvs
mailing list