Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 436)
+++ trunk/CHANGELOG	(revision 437)
@@ -36,6 +36,11 @@
 27-Dec-2006 Matthias Gallas
 #	Fixed form modul stores empty records
 ------------------------------------- 2.6.6 -------------------------------------
+03-Mar-2007 Matthias Gallas
++	Added new function for highlighting search results in the content area
+	(Special thanks to "thorn" and "Funky_MF")
+#	Fixed some issues in search with special chars
+	(Special thanks to "thorn" and "Funky_MF")
 22-Feb-2007 Christian Sommer
 #	Fixed bug in changeset 428 (page files were not deleted in /pages folder due to a typo in wb/framework/function.php)
 16-Feb-2007 Christian Sommer
Index: trunk/wb/search/search.php
===================================================================
--- trunk/wb/search/search.php	(revision 436)
+++ trunk/wb/search/search.php	(revision 437)
@@ -39,9 +39,9 @@
 
 	// Get the search type
 	$match = 'all';
-    if(isset($_REQUEST['match'])) {
-        $match = $_REQUEST['match'];
-    }
+	if(isset($_REQUEST['match'])) {
+		$match = $_REQUEST['match'];
+	}
 
 	// Get search string
 	if(isset($_REQUEST['string'])) {
@@ -54,8 +54,15 @@
 		$original_string=$wb->strip_slashes($string);
 		// Double backslashes (mySQL needs doubly escaped backslashes in LIKE comparisons)
 		$string = addslashes($wb->escape_backslashes($original_string));
-		// then escape for mySQL query
-		$search_string = htmlspecialchars($original_string,ENT_QUOTES);
+		// convert a copy of $string to HTML-ENTITIES
+		$string_entities=mb_convert_encoding($string, 'UTF-8', 'HTML-ENTITIES');
+		$string_entities=htmlspecialchars($string_entities,ENT_QUOTES);
+		$string_entities=mb_convert_encoding($string_entities, 'HTML-ENTITIES', 'UTF-8');
+		// and do some convertion to both
+		require(WB_PATH.'/search/search_convert.php');
+		$string=strtr($string,$string_conv);
+		$string_entities=strtr($string_entities,$string_entities_conv);
+		$search_string = $string_entities;
 	} else {
 		$string = '';
 		$search_string = '';
@@ -75,6 +82,15 @@
 				$string[] = $each_exploded_string;
 			}
 		}
+		// Split $string_entities, too
+		$exploded_string = explode(' ', $string_entities);
+		// Make sure there is no blank values in the array
+		$string_entities = array();
+		foreach($exploded_string AS $each_exploded_string) {
+			if($each_exploded_string != '') {
+				$string_entities[] = $each_exploded_string;
+			}
+		}
 		if ($match == 'any') {
 			$any_checked = ' checked="checked"';
 			$logical_operator = ' OR';
@@ -87,6 +103,9 @@
 		$exact_string=$string;
 		$string=array();
 		$string[]=$exact_string;
+		$exact_string=$string_entities;
+		$string_entities=array();
+		$string_entities[]=$exact_string;
 	}	
 	// Get list of usernames and display names
 	$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
@@ -131,22 +150,38 @@
 		// Show search results_header
 		echo $search_results_header;
 		// Search page details only, such as description, keywords, etc.
-			$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE ";
-			$count = 0;
-			foreach($string AS $each_string) {
-				if($count != 0) { $query_pages .= $logical_operator; }
-				$query_pages .= " visibility != 'none' AND page_title LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND menu_title LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND description LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND keywords LIKE '%$each_string%' AND searching = '1'";
-				$count = $count+1;
+		$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE ";
+		$count = 0;
+		foreach($string AS $each_string) {
+			if($count != 0) { 
+				$query_pages .= $logical_operator;
 			}
-			$query_pages = $database->query($query_pages);
+			$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'".
+			" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')";
+			$count = $count+1;
+		}
+		$count = 0;
+		$query_pages .= ' OR';
+		foreach($string_entities AS $each_string) {
+			if($count != 0) { 
+				$query_pages .= $logical_operator;
+			}
+			$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'".
+			" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')";
+			$count = $count+1;
+		}
+		$query_pages = $database->query($query_pages);
 		// Loop through pages
 		if($query_pages->numRows() > 0) {
 			while($page = $query_pages->fetchRow()) {
 				// Get page link
 				$link = page_link($page['link']);
+				
+				//Add search string for highlighting
+				$sstring = implode(" ", array_merge($string,$string_entities));
+				//$link = $link."?searchresult=1&amp;sstring=".$sstring;
+				$link = $link."?searchresult=1&amp;sstring=".urlencode($sstring);
+				
 				// Set vars to be replaced by values
 				$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
 				if($page['modified_when'] > 0) {
@@ -201,11 +236,24 @@
 							$prepared_query = $query_start;
 							$count = 0;
 							foreach($string AS $each_string) {
-								if($count != 0) { $prepared_query .= $logical_operator; }
+								if($count != 0) {
+									$prepared_query .= $logical_operator;
+								}
 								$prepared_query .= str_replace('[STRING]', $each_string, $query_body);
 								$count = $count+1;
 							}
+							$count=0;
+							$prepared_query .= ' OR ';
+							foreach($string_entities AS $each_string) {
+								if($count != 0) {
+									$prepared_query .= $logical_operator;
+								}
+								$prepared_query .= str_replace('[STRING]', $each_string, $query_body);
+								$count = $count+1;
+							}
+							
 							$prepared_query .= $query_end;
+							
 							// Execute query
 							$query = $database->query($prepared_query);
 							// Loop though queried items
@@ -215,6 +263,12 @@
 									if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) {
 										// Get page link
 										$link = page_link($page[$fields['link']]);
+										
+										//Add search string for highlighting
+										$sstring = implode(" ", array_merge($string,$string_entities));
+										//$link = $link."?searchresult=1&amp;sstring=".$sstring;
+										$link = $link."?searchresult=1&amp;sstring=".urlencode($sstring);
+										
 										// Set vars to be replaced by values
 										$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
 										if($page[$fields['modified_when']] > 0) {
@@ -236,7 +290,6 @@
 									}
 								}
 							}
-						
 						}
 					}
 				}
@@ -247,10 +300,10 @@
 			
 		}
 	
-	// Say no items found if we should
-	if($pages_listed == array() AND $items_listed == array()) {
-		echo $fetch_no_results['value'];
-	}
+		// Say no items found if we should
+		if($pages_listed == array() AND $items_listed == array()) {
+			echo $fetch_no_results['value'];
+		}
 		
 	}
 	
Index: trunk/wb/search/search_convert.php
===================================================================
--- trunk/wb/search/search_convert.php	(nonexistent)
+++ trunk/wb/search/search_convert.php	(revision 437)
@@ -0,0 +1,76 @@
+<?php
+
+// $Id$
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2007, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+/*
+Character Conversion file
+Some special translations
+*/
+if(!defined('WB_URL')) {
+	header('Location: ../index.php');
+	exit(0);
+}
+
+//for Xinha, (htmlarea)
+$string_conv=array(
+	"Š"=>"&Scaron;","š"=>"&scaron;","Œ"=>"&OElig;","œ"=>"&oelig;","Ÿ"=>"&Yuml;",
+	">"=>"&gt;","<"=>"&lt;",
+	"„"=>"&bdquo;","•"=>"&bull;","ˆ"=>"&circ;","&#925;"=>"&Nu;","&#957;"=>"&nu;",
+	"&#931;"=>"&Sigma;","&#933;"=>"&Upsilon;","&#965;"=>"&upsilon;",
+	"&#918;"=>"&Zeta;","&#950;"=>"&zeta;","&#958;"=>"&xi;","&#914;"=>"&Beta;","&#946;"=>"&beta;",
+	"&#8734;"=>"&infin;","&#8596;"=>"&harr;","&#8260;"=>"&frasl;","&#919;"=>"&Eta;","&#951;"=>"&eta;",
+	"&#935;"=>"&Chi;","&#8745;"=>"&cap;","&and;"=>"&#8743;","&#913;"=>"&Alpha;","&#945;"=>"&alpha;",
+	"&#8776;"=>"&asymp;","™"=>"&trade;","˜"=>"&tilde;","&#8804;"=>"&le;",
+	"&#916;"=>"&Delta;","&#948;"=>"&delta;","€"=>"&euro;","ƒ"=>"&fnof;",
+	"&#915;"=>"&Gamma;","&#947;"=>"&gamma;","&#8805;"=>"&ge;","&#9829;"=>"&hearts;",
+	"…"=>"&hellip;","&#8747;"=>"&int;","&#921;"=>"&Iota;","&#953;"=>"&iota;",
+	"&#922;"=>"&Kappa;","&#954;"=>"&kappa;","&#923;"=>"&Lambda;","&#955;"=>"&lambda;",
+	"&#8592;"=>"&larr;","“"=>"&ldquo;","&#9674;"=>"&loz;",
+	"‹"=>"&lsaquo;","‘"=>"&lsquo;","—"=>"&mdash;","&#8800;"=>"&ne;",
+	"&#8722;"=>"&minus;","&#924;"=>"&Mu;","&#956;"=>"&mu;","–"=>"&ndash;",
+	"&#8254;"=>"&oline;","&#937;"=>"&Omega;","&#969;"=>"&omega;","&#959;"=>"&omicron;",
+	"&#934;"=>"&Phi;","&#966;"=>"&phi;","&#928;"=>"&Pi;","&#960;"=>"&pi;","&#8706;"=>"&part;",
+	"‰"=>"&permil;","&#8243;"=>"&Prime;","&#8242;"=>"&prime;","&#8719;"=>"&prod;",
+	"&#936;"=>"&Psi;","&#8730;"=>"&radic;","&#8658;"=>"&rArr;","&#8594;"=>"&rarr;",
+	"”"=>"&rdquo;","&#929;"=>"&Rho;","&#961;"=>"&rho;",
+	"›"=>"&rsaquo;","’"=>"&rsquo;","‚"=>"&sbquo;",
+	"&#963;"=>"&sigma;","&#962;"=>"&sigmaf;","&#9824;"=>"&spades;","&#8721;"=>"&sum;",
+	"&#932;"=>"&Tau;","&#964;"=>"&tau;","&#920;"=>"&Theta;","&#952;"=>"&theta;",
+	"&#8593;"=>"&uarr;","&#926;"=>"&Xi;"
+);
+
+//for fckeditor, (tiny_mce)
+$string_entities_conv=array(
+	"&#140;"=>"&OElig;","&#156;"=>"&oelig;","&#138;"=>"&Scaron;","&#154;"=>"&scaron;",
+	"&#159;"=>"&Yuml;",
+	"&#152;"=>"&tilde;","&upsih;"=>"&#978;","&#149;"=>"&bull;","&#153;"=>"&trade;",
+	"&#132;"=>"&bdquo;","&#136;"=>"&circ;","&#128;"=>"&euro;","&#131;"=>"&fnof;",
+	"&#133;"=>"&hellip;","&lang;"=>"&#9001;","&lceil;"=>"&#8968;","&#147;"=>"&ldquo;",
+	"&lfloor;"=>"&#8970;","&#150;"=>"&ndash;","&#151;"=>"&mdash;",
+	"&#139;"=>"&lsaquo;","&#145;"=>"&lsquo;","&rfloor;"=>"&#8971;","&#148;"=>"&rdquo;",
+	"&rceil;"=>"&#8969;","&rang;"=>"&#9002;","&piv;"=>"&#982;","&#137;"=>"&permil;",
+	"&#155;"=>"&rsaquo;","&#146;"=>"&rsquo;","&#130;"=>"&sbquo;","&thetasym;"=>"&#977"
+);
+
+?>
\ No newline at end of file

Property changes on: trunk/wb/search/search_convert.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: trunk/wb/framework/frontend.functions.php
===================================================================
--- trunk/wb/framework/frontend.functions.php	(revision 436)
+++ trunk/wb/framework/frontend.functions.php	(revision 437)
@@ -66,6 +66,26 @@
 	}
 }
 
+//function to highlight search results
+function search_highlight($foo='', $arr_string=array()) {
+	foreach($arr_string as $string) {
+		$string=str_replace('\\','\\\\',$string); 
+		$string=str_replace('/','\/',$string); 
+		$string=str_replace('*','\*',$string); 
+		$string=str_replace('.','\.',$string); 
+    
+		$foo=preg_replace('/(>[^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo); 
+		$foo=preg_replace('/^([^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo);
+    
+		$foo=preg_replace('/(>[^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo); 
+		$foo=preg_replace('/^([^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo);
+    
+		$foo=preg_replace('/(>[^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo); 
+		$foo=preg_replace('/^([^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo);
+	}
+	return $foo;
+}  
+
 // Old menu call invokes new menu function
 if (!function_exists('page_menu')) {
 	function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a] [menu_title] [/a]</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
@@ -166,7 +186,19 @@
 			while($section = $query_sections->fetchRow()) {
 				$section_id = $section['section_id'];
 				$module = $section['module'];
-				require(WB_PATH.'/modules/'.$module.'/view.php');
+				// highlights searchresults
+				if (isset($_GET['searchresult']) AND is_numeric($_GET['searchresult']) ) {
+					if (isset($_GET['sstring']) AND !empty($_GET['sstring']) ){
+						$arr_string = explode(" ", $_GET['sstring']);
+						ob_start(); //start output buffer
+						require(WB_PATH.'/modules/'.$module.'/view.php');
+						$foo = ob_get_contents();    // put outputbuffer in $foo
+						ob_end_clean();             // clear outputbuffer
+						echo search_highlight($foo, $arr_string);
+					}
+				} else {
+					require(WB_PATH.'/modules/'.$module.'/view.php');
+				}
 			}
 		} else {
 			require(PAGE_CONTENT);
@@ -239,6 +271,7 @@
 		}
 	}
 }
+
 // Function for page header
 if (!function_exists('page_header')) {
 	function page_header($date_format = 'Y') {
