Revision 437
Added by Matthias over 17 years ago
trunk/CHANGELOG | ||
---|---|---|
36 | 36 |
27-Dec-2006 Matthias Gallas |
37 | 37 |
# Fixed form modul stores empty records |
38 | 38 |
------------------------------------- 2.6.6 ------------------------------------- |
39 |
03-Mar-2007 Matthias Gallas |
|
40 |
+ Added new function for highlighting search results in the content area |
|
41 |
(Special thanks to "thorn" and "Funky_MF") |
|
42 |
# Fixed some issues in search with special chars |
|
43 |
(Special thanks to "thorn" and "Funky_MF") |
|
39 | 44 |
22-Feb-2007 Christian Sommer |
40 | 45 |
# Fixed bug in changeset 428 (page files were not deleted in /pages folder due to a typo in wb/framework/function.php) |
41 | 46 |
16-Feb-2007 Christian Sommer |
trunk/wb/search/search.php | ||
---|---|---|
39 | 39 |
|
40 | 40 |
// Get the search type |
41 | 41 |
$match = 'all'; |
42 |
if(isset($_REQUEST['match'])) {
|
|
43 |
$match = $_REQUEST['match'];
|
|
44 |
}
|
|
42 |
if(isset($_REQUEST['match'])) {
|
|
43 |
$match = $_REQUEST['match'];
|
|
44 |
}
|
|
45 | 45 |
|
46 | 46 |
// Get search string |
47 | 47 |
if(isset($_REQUEST['string'])) { |
... | ... | |
54 | 54 |
$original_string=$wb->strip_slashes($string); |
55 | 55 |
// Double backslashes (mySQL needs doubly escaped backslashes in LIKE comparisons) |
56 | 56 |
$string = addslashes($wb->escape_backslashes($original_string)); |
57 |
// then escape for mySQL query |
|
58 |
$search_string = htmlspecialchars($original_string,ENT_QUOTES); |
|
57 |
// convert a copy of $string to HTML-ENTITIES |
|
58 |
$string_entities=mb_convert_encoding($string, 'UTF-8', 'HTML-ENTITIES'); |
|
59 |
$string_entities=htmlspecialchars($string_entities,ENT_QUOTES); |
|
60 |
$string_entities=mb_convert_encoding($string_entities, 'HTML-ENTITIES', 'UTF-8'); |
|
61 |
// and do some convertion to both |
|
62 |
require(WB_PATH.'/search/search_convert.php'); |
|
63 |
$string=strtr($string,$string_conv); |
|
64 |
$string_entities=strtr($string_entities,$string_entities_conv); |
|
65 |
$search_string = $string_entities; |
|
59 | 66 |
} else { |
60 | 67 |
$string = ''; |
61 | 68 |
$search_string = ''; |
... | ... | |
75 | 82 |
$string[] = $each_exploded_string; |
76 | 83 |
} |
77 | 84 |
} |
85 |
// Split $string_entities, too |
|
86 |
$exploded_string = explode(' ', $string_entities); |
|
87 |
// Make sure there is no blank values in the array |
|
88 |
$string_entities = array(); |
|
89 |
foreach($exploded_string AS $each_exploded_string) { |
|
90 |
if($each_exploded_string != '') { |
|
91 |
$string_entities[] = $each_exploded_string; |
|
92 |
} |
|
93 |
} |
|
78 | 94 |
if ($match == 'any') { |
79 | 95 |
$any_checked = ' checked="checked"'; |
80 | 96 |
$logical_operator = ' OR'; |
... | ... | |
87 | 103 |
$exact_string=$string; |
88 | 104 |
$string=array(); |
89 | 105 |
$string[]=$exact_string; |
106 |
$exact_string=$string_entities; |
|
107 |
$string_entities=array(); |
|
108 |
$string_entities[]=$exact_string; |
|
90 | 109 |
} |
91 | 110 |
// Get list of usernames and display names |
92 | 111 |
$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users"); |
... | ... | |
131 | 150 |
// Show search results_header |
132 | 151 |
echo $search_results_header; |
133 | 152 |
// Search page details only, such as description, keywords, etc. |
134 |
$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE "; |
|
135 |
$count = 0; |
|
136 |
foreach($string AS $each_string) { |
|
137 |
if($count != 0) { $query_pages .= $logical_operator; } |
|
138 |
$query_pages .= " visibility != 'none' AND page_title LIKE '%$each_string%' AND searching = '1'". |
|
139 |
" OR visibility != 'none' AND visibility != 'deleted' AND menu_title LIKE '%$each_string%' AND searching = '1'". |
|
140 |
" OR visibility != 'none' AND visibility != 'deleted' AND description LIKE '%$each_string%' AND searching = '1'". |
|
141 |
" OR visibility != 'none' AND visibility != 'deleted' AND keywords LIKE '%$each_string%' AND searching = '1'"; |
|
142 |
$count = $count+1; |
|
153 |
$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE "; |
|
154 |
$count = 0; |
|
155 |
foreach($string AS $each_string) { |
|
156 |
if($count != 0) { |
|
157 |
$query_pages .= $logical_operator; |
|
143 | 158 |
} |
144 |
$query_pages = $database->query($query_pages); |
|
159 |
$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'". |
|
160 |
" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')"; |
|
161 |
$count = $count+1; |
|
162 |
} |
|
163 |
$count = 0; |
|
164 |
$query_pages .= ' OR'; |
|
165 |
foreach($string_entities AS $each_string) { |
|
166 |
if($count != 0) { |
|
167 |
$query_pages .= $logical_operator; |
|
168 |
} |
|
169 |
$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'". |
|
170 |
" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')"; |
|
171 |
$count = $count+1; |
|
172 |
} |
|
173 |
$query_pages = $database->query($query_pages); |
|
145 | 174 |
// Loop through pages |
146 | 175 |
if($query_pages->numRows() > 0) { |
147 | 176 |
while($page = $query_pages->fetchRow()) { |
148 | 177 |
// Get page link |
149 | 178 |
$link = page_link($page['link']); |
179 |
|
|
180 |
//Add search string for highlighting |
|
181 |
$sstring = implode(" ", array_merge($string,$string_entities)); |
|
182 |
//$link = $link."?searchresult=1&sstring=".$sstring; |
|
183 |
$link = $link."?searchresult=1&sstring=".urlencode($sstring); |
|
184 |
|
|
150 | 185 |
// Set vars to be replaced by values |
151 | 186 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]'); |
152 | 187 |
if($page['modified_when'] > 0) { |
... | ... | |
201 | 236 |
$prepared_query = $query_start; |
202 | 237 |
$count = 0; |
203 | 238 |
foreach($string AS $each_string) { |
204 |
if($count != 0) { $prepared_query .= $logical_operator; } |
|
239 |
if($count != 0) { |
|
240 |
$prepared_query .= $logical_operator; |
|
241 |
} |
|
205 | 242 |
$prepared_query .= str_replace('[STRING]', $each_string, $query_body); |
206 | 243 |
$count = $count+1; |
207 | 244 |
} |
245 |
$count=0; |
|
246 |
$prepared_query .= ' OR '; |
|
247 |
foreach($string_entities AS $each_string) { |
|
248 |
if($count != 0) { |
|
249 |
$prepared_query .= $logical_operator; |
|
250 |
} |
|
251 |
$prepared_query .= str_replace('[STRING]', $each_string, $query_body); |
|
252 |
$count = $count+1; |
|
253 |
} |
|
254 |
|
|
208 | 255 |
$prepared_query .= $query_end; |
256 |
|
|
209 | 257 |
// Execute query |
210 | 258 |
$query = $database->query($prepared_query); |
211 | 259 |
// Loop though queried items |
... | ... | |
215 | 263 |
if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) { |
216 | 264 |
// Get page link |
217 | 265 |
$link = page_link($page[$fields['link']]); |
266 |
|
|
267 |
//Add search string for highlighting |
|
268 |
$sstring = implode(" ", array_merge($string,$string_entities)); |
|
269 |
//$link = $link."?searchresult=1&sstring=".$sstring; |
|
270 |
$link = $link."?searchresult=1&sstring=".urlencode($sstring); |
|
271 |
|
|
218 | 272 |
// Set vars to be replaced by values |
219 | 273 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]'); |
220 | 274 |
if($page[$fields['modified_when']] > 0) { |
... | ... | |
236 | 290 |
} |
237 | 291 |
} |
238 | 292 |
} |
239 |
|
|
240 | 293 |
} |
241 | 294 |
} |
242 | 295 |
} |
... | ... | |
247 | 300 |
|
248 | 301 |
} |
249 | 302 |
|
250 |
// Say no items found if we should |
|
251 |
if($pages_listed == array() AND $items_listed == array()) { |
|
252 |
echo $fetch_no_results['value']; |
|
253 |
} |
|
303 |
// Say no items found if we should
|
|
304 |
if($pages_listed == array() AND $items_listed == array()) {
|
|
305 |
echo $fetch_no_results['value'];
|
|
306 |
}
|
|
254 | 307 |
|
255 | 308 |
} |
256 | 309 |
|
trunk/wb/search/search_convert.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2007, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
25 |
|
|
26 |
/* |
|
27 |
Character Conversion file |
|
28 |
Some special translations |
|
29 |
*/ |
|
30 |
if(!defined('WB_URL')) { |
|
31 |
header('Location: ../index.php'); |
|
32 |
exit(0); |
|
33 |
} |
|
34 |
|
|
35 |
//for Xinha, (htmlarea) |
|
36 |
$string_conv=array( |
|
37 |
"?"=>"Š","?"=>"š","?"=>"Œ","?"=>"œ","?"=>"Ÿ", |
|
38 |
">"=>">","<"=>"<", |
|
39 |
"?"=>"„","?"=>"•","?"=>"ˆ","Ν"=>"Ν","ν"=>"ν", |
|
40 |
"Σ"=>"Σ","Υ"=>"Υ","υ"=>"υ", |
|
41 |
"Ζ"=>"Ζ","ζ"=>"ζ","ξ"=>"ξ","Β"=>"Β","β"=>"β", |
|
42 |
"∞"=>"∞","↔"=>"↔","⁄"=>"⁄","Η"=>"Η","η"=>"η", |
|
43 |
"Χ"=>"Χ","∩"=>"∩","∧"=>"∧","Α"=>"Α","α"=>"α", |
|
44 |
"≈"=>"≈","?"=>"™","?"=>"˜","≤"=>"≤", |
|
45 |
"Δ"=>"Δ","δ"=>"δ","?"=>"€","?"=>"ƒ", |
|
46 |
"Γ"=>"Γ","γ"=>"γ","≥"=>"≥","♥"=>"♥", |
|
47 |
"?"=>"…","∫"=>"∫","Ι"=>"Ι","ι"=>"ι", |
|
48 |
"Κ"=>"Κ","κ"=>"κ","Λ"=>"Λ","λ"=>"λ", |
|
49 |
"←"=>"←","?"=>"“","◊"=>"◊", |
|
50 |
"?"=>"‹","?"=>"‘","?"=>"—","≠"=>"≠", |
|
51 |
"−"=>"−","Μ"=>"Μ","μ"=>"μ","?"=>"–", |
|
52 |
"‾"=>"‾","Ω"=>"Ω","ω"=>"ω","ο"=>"ο", |
|
53 |
"Φ"=>"Φ","φ"=>"φ","Π"=>"Π","π"=>"π","∂"=>"∂", |
|
54 |
"?"=>"‰","″"=>"″","′"=>"′","∏"=>"∏", |
|
55 |
"Ψ"=>"Ψ","√"=>"√","⇒"=>"⇒","→"=>"→", |
|
56 |
"?"=>"”","Ρ"=>"Ρ","ρ"=>"ρ", |
|
57 |
"?"=>"›","?"=>"’","?"=>"‚", |
|
58 |
"σ"=>"σ","ς"=>"ς","♠"=>"♠","∑"=>"∑", |
|
59 |
"Τ"=>"Τ","τ"=>"τ","Θ"=>"Θ","θ"=>"θ", |
|
60 |
"↑"=>"↑","Ξ"=>"Ξ" |
|
61 |
); |
|
62 |
|
|
63 |
//for fckeditor, (tiny_mce) |
|
64 |
$string_entities_conv=array( |
|
65 |
"Œ"=>"Œ","œ"=>"œ","Š"=>"Š","š"=>"š", |
|
66 |
"Ÿ"=>"Ÿ", |
|
67 |
"˜"=>"˜","ϒ"=>"ϒ","•"=>"•","™"=>"™", |
|
68 |
"„"=>"„","ˆ"=>"ˆ","€"=>"€","ƒ"=>"ƒ", |
|
69 |
"…"=>"…","⟨"=>"〈","⌈"=>"⌈","“"=>"“", |
|
70 |
"⌊"=>"⌊","–"=>"–","—"=>"—", |
|
71 |
"‹"=>"‹","‘"=>"‘","⌋"=>"⌋","”"=>"”", |
|
72 |
"⌉"=>"⌉","⟩"=>"〉","ϖ"=>"ϖ","‰"=>"‰", |
|
73 |
"›"=>"›","’"=>"’","‚"=>"‚","ϑ"=>"ϑ" |
|
74 |
); |
|
75 |
|
|
76 |
?> |
|
0 | 77 |
trunk/wb/framework/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
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")