[geeklog-cvs] geeklog-1.3/public_html article.php,1.44,1.45 lib-common.php,1.327,1.328

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Sun May 30 12:33:05 EDT 2004


Update of /var/cvs/geeklog-1.3/public_html
In directory www:/tmp/cvs-serv27993/public_html

Modified Files:
	article.php lib-common.php 
Log Message:
Escape all PCRE special characters in the code to highlight search query words (bug #200).


Index: lib-common.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.327
retrieving revision 1.328
diff -C2 -d -r1.327 -r1.328
*** lib-common.php	29 May 2004 15:46:56 -0000	1.327
--- lib-common.php	30 May 2004 16:33:02 -0000	1.328
***************
*** 3024,3036 ****
          if( !empty( $query ))
          {
!             $mywords = explode( ' ', $query );
!             foreach( $mywords as $searchword )
!             {
!                 $searchword = str_replace( '*', '\*', $searchword );
!                 $A['comment'] = preg_replace( "/(\>(((?>[^><]+)|(?R))*)\<)/ie", "preg_replace('/(?>$searchword+)/i','<span class=\"highlight\">$searchword</span>','\\0')", "<x>" . $A['comment'] . "<x>" );
!             }
          }
  
!         $A['comment'] = str_replace( '$', '$', $A['comment'] );
          $A['comment'] = str_replace( '{', '{', $A['comment'] );
          $A['comment'] = str_replace( '}', '}', $A['comment'] );
--- 3024,3031 ----
          if( !empty( $query ))
          {
!             $A['comment'] = COM_highlightQuery( $A['comment'], $query );
          }
  
!         $A['comment'] = str_replace( '$', '$',  $A['comment'] );
          $A['comment'] = str_replace( '{', '{', $A['comment'] );
          $A['comment'] = str_replace( '}', '}', $A['comment'] );
***************
*** 5632,5635 ****
--- 5627,5664 ----
  }
  
+ /**
+ * Highlight the words from a search query in a given text string.
+ *
+ * @param    string  $text   the text
+ * @param    string  $query  the search query
+ * @return   string          the text with highlighted search words
+ *
+ */
+ function COM_highlightQuery( $text, $query )
+ {
+     $query = str_replace( '+', ' ', $query );
+ 
+     // escape all the other PCRE special characters
+     $query = str_replace( '\\', '\\\\', $query );
+     $query = str_replace( '.', '\.', $query ); 
+     $query = str_replace( '*', '\*', $query );
+     $query = str_replace( '?', '\?', $query );
+     $query = str_replace( '^', '\^', $query );
+     $query = str_replace( '$', '\$', $query );
+     $query = str_replace( '(', '\(', $query );
+     $query = str_replace( ')', '\)', $query );
+     $query = str_replace( ']', '\]', $query );
+     $query = str_replace( '{', '\{', $query );
+     $query = str_replace( '}', '\}', $query );
+ 
+     $mywords = explode( ' ', $query );
+     foreach( $mywords as $searchword )
+     {
+         $text = preg_replace( '/(\>(((?>[^><]+)|(?R))*)\<)/ie', "preg_replace('/(?>$searchword+)/i','<span class=\"highlight\">$searchword</span>','\\0')", '<x>' . $text . '<x>' );
+     }
+ 
+     return $text;
+ }
+ 
  
  // Now include all plugin functions

Index: article.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/article.php,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** article.php	20 May 2004 18:57:45 -0000	1.44
--- article.php	30 May 2004 16:33:02 -0000	1.45
***************
*** 146,156 ****
              DB_query ("UPDATE {$_TABLES['stories']} SET hits = hits + 1 WHERE sid = '$story'");
  
!             if ($query) {
!                 $mywords = explode (" ", $query);
!                 foreach ($mywords as $searchword) {
!                     $searchword = str_replace ('*', '\*', $searchword);
!                     $A['introtext'] = preg_replace ("/(\>(((?>[^><]+)|(?R))*)\<)/ie", "preg_replace('/(?>$searchword+)/i','<span class=\"highlight\">$searchword</span>','\\0')", "<x>" . $A['introtext'] . "<x>");
!                     $A['bodytext'] = preg_replace ("/(\>(((?>[^><]+)|(?R))*)\<)/ie", "preg_replace('/(?>$searchword+)/i','<span class=\"highlight\">$searchword</span>','\\0')" ,"<x>" . $A['bodytext'] . "<x>");
!                 }
              }
  
--- 146,152 ----
              DB_query ("UPDATE {$_TABLES['stories']} SET hits = hits + 1 WHERE sid = '$story'");
  
!             if (!empty ($query)) {
!                 $A['introtext'] = COM_highlightQuery ($A['introtext'], $query);
!                 $A['bodytext'] = COM_highlightQuery ($A['bodytext'], $query);
              }
  




More information about the geeklog-cvs mailing list