Project

General

Profile

« Previous | Next » 

Revision 437

Added by Matthias over 17 years ago

Added new function for highlighting search results in the content area; Fixed some issues in search with special chars; (Special thanks to "thorn" and "Funky_MF")

View differences:

frontend.functions.php
66 66
	}
67 67
}
68 68

  
69
//function to highlight search results
70
function search_highlight($foo='', $arr_string=array()) {
71
	foreach($arr_string as $string) {
72
		$string=str_replace('\\','\\\\',$string); 
73
		$string=str_replace('/','\/',$string); 
74
		$string=str_replace('*','\*',$string); 
75
		$string=str_replace('.','\.',$string); 
76
    
77
		$foo=preg_replace('/(>[^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo); 
78
		$foo=preg_replace('/^([^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo);
79
    
80
		$foo=preg_replace('/(>[^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo); 
81
		$foo=preg_replace('/^([^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo);
82
    
83
		$foo=preg_replace('/(>[^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo); 
84
		$foo=preg_replace('/^([^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo);
85
	}
86
	return $foo;
87
}  
88

  
69 89
// Old menu call invokes new menu function
70 90
if (!function_exists('page_menu')) {
71 91
	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 186
			while($section = $query_sections->fetchRow()) {
167 187
				$section_id = $section['section_id'];
168 188
				$module = $section['module'];
169
				require(WB_PATH.'/modules/'.$module.'/view.php');
189
				// highlights searchresults
190
				if (isset($_GET['searchresult']) AND is_numeric($_GET['searchresult']) ) {
191
					if (isset($_GET['sstring']) AND !empty($_GET['sstring']) ){
192
						$arr_string = explode(" ", $_GET['sstring']);
193
						ob_start(); //start output buffer
194
						require(WB_PATH.'/modules/'.$module.'/view.php');
195
						$foo = ob_get_contents();    // put outputbuffer in $foo
196
						ob_end_clean();             // clear outputbuffer
197
						echo search_highlight($foo, $arr_string);
198
					}
199
				} else {
200
					require(WB_PATH.'/modules/'.$module.'/view.php');
201
				}
170 202
			}
171 203
		} else {
172 204
			require(PAGE_CONTENT);
......
239 271
		}
240 272
	}
241 273
}
274

  
242 275
// Function for page header
243 276
if (!function_exists('page_header')) {
244 277
	function page_header($date_format = 'Y') {

Also available in: Unified diff