Revision 1441
Added by Dietmar over 13 years ago
- recoded /modules/admin.php info_banner, now compare with modify in pages
- security fixes remove defined WB_PATH for backend templates
- fixed class.admin.php missing $TEXT declaration, add get_section_details
search_modext.php | ||
---|---|---|
5 | 5 |
* @package search |
6 | 6 |
* @author WebsiteBaker Project |
7 | 7 |
* @copyright 2004-2009, Ryan Djurovich |
8 |
* @copyright 2009-2011, Website Baker Org. e.V.
|
|
8 |
* @copyright 2009-2010, Website Baker Org. e.V.
|
|
9 | 9 |
* @link http://www.websitebaker2.org/ |
10 | 10 |
* @license http://www.gnu.org/licenses/gpl.html |
11 | 11 |
* @platform WebsiteBaker 2.8.x |
12 |
* @requirements PHP 5.2.2 and higher
|
|
12 |
* @requirements PHP 4.3.4 and higher
|
|
13 | 13 |
* @version $Id$ |
14 | 14 |
* @filesource $HeadURL$ |
15 | 15 |
* @lastmodified $Date$ |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 |
// Must include code to stop this file being access directly |
|
20 |
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); } |
|
21 |
|
|
22 | 19 |
// make the url-string for highlighting |
23 |
function make_url_searchstring($search_match, $search_url_array) |
|
24 |
{ |
|
20 |
function make_url_searchstring($search_match, $search_url_array) { |
|
25 | 21 |
$link = ""; |
26 |
if ($search_match != 'exact') |
|
27 |
{ |
|
22 |
if ($search_match != 'exact') { |
|
28 | 23 |
$str = implode(" ", $search_url_array); |
29 | 24 |
$link = "?searchresult=1&sstring=".urlencode($str); |
30 | 25 |
} else { |
... | ... | |
35 | 30 |
} |
36 | 31 |
|
37 | 32 |
// make date and time for "last modified by... on ..."-string |
38 |
function get_page_modified($page_modified_when) |
|
39 |
{ |
|
33 |
function get_page_modified($page_modified_when) { |
|
40 | 34 |
global $TEXT; |
41 |
if($page_modified_when > 0) |
|
42 |
{ |
|
35 |
if($page_modified_when > 0) { |
|
43 | 36 |
$date = gmdate(DATE_FORMAT, $page_modified_when+TIMEZONE); |
44 | 37 |
$time = gmdate(TIME_FORMAT, $page_modified_when+TIMEZONE); |
45 | 38 |
} else { |
... | ... | |
50 | 43 |
} |
51 | 44 |
|
52 | 45 |
// make username and displayname for "last modified by... on ..."-string |
53 |
function get_page_modified_by($page_modified_by, $users) |
|
54 |
{ |
|
46 |
function get_page_modified_by($page_modified_by, $users) { |
|
55 | 47 |
global $TEXT; |
56 |
// check for existing user-id |
|
57 |
if(!isset($users[$page_modified_by])) |
|
58 |
{ |
|
59 |
$page_modified_by = 0; |
|
60 |
} |
|
61 |
|
|
62 |
$username = $users[$page_modified_by]['username']; |
|
63 |
$displayname = $users[$page_modified_by]['display_name']; |
|
48 |
if($page_modified_by>0) { |
|
49 |
$username = $users[$page_modified_by]['username']; |
|
50 |
$displayname = $users[$page_modified_by]['display_name']; |
|
51 |
} else { |
|
52 |
$username = ""; |
|
53 |
$displayname = $TEXT['UNKNOWN']; |
|
54 |
} |
|
64 | 55 |
return array($username, $displayname); |
65 | 56 |
} |
66 | 57 |
|
67 | 58 |
// checks if _all_ searchwords matches |
68 |
function is_all_matched($text, $search_words) |
|
69 |
{ |
|
59 |
function is_all_matched($text, $search_words) { |
|
70 | 60 |
$all_matched = true; |
71 |
foreach ($search_words AS $word) |
|
72 |
{ |
|
73 |
if(!preg_match('/'.$word.'/ui', $text)) |
|
74 |
{ |
|
61 |
foreach ($search_words AS $word) { |
|
62 |
if(!preg_match('/'.$word.'/i', $text)) { |
|
75 | 63 |
$all_matched = false; |
76 | 64 |
break; |
77 | 65 |
} |
... | ... | |
80 | 68 |
} |
81 | 69 |
|
82 | 70 |
// checks if _any_ of the searchwords matches |
83 |
function is_any_matched($text, $search_words) |
|
84 |
{ |
|
71 |
function is_any_matched($text, $search_words) { |
|
85 | 72 |
$any_matched = false; |
86 | 73 |
$word = '('.implode('|', $search_words).')'; |
87 |
if(preg_match('/'.$word.'/ui', $text)) |
|
88 |
{ |
|
74 |
if(preg_match('/'.$word.'/i', $text)) { |
|
89 | 75 |
$any_matched = true; |
90 | 76 |
} |
91 | 77 |
return $any_matched; |
92 | 78 |
} |
93 | 79 |
|
94 | 80 |
// collects the matches from text in excerpt_array |
95 |
function get_excerpts($text, $search_words, $max_excerpt_num) |
|
96 |
{ |
|
97 |
$match_array = array(); |
|
98 |
$excerpt_array = array(); |
|
81 |
function get_excerpts($text, $search_words, $max_excerpt_num) { |
|
82 |
$excerpt_array = FALSE; |
|
99 | 83 |
$word = '('.implode('|', $search_words).')'; |
100 |
|
|
101 |
//Filter droplets from the page data |
|
102 |
preg_match_all('~\[\[(.*?)\]\]~', $text, $matches); |
|
103 |
foreach ($matches[1] as $match) |
|
104 |
{ |
|
105 |
$text = str_replace('[['.$match.']]', '', $text); |
|
106 |
} |
|
107 |
|
|
108 |
// Build the regex-string |
|
109 |
if(strpos(strtoupper(PHP_OS), 'WIN')===0) // windows -> see below |
|
110 |
{ |
|
111 |
$str1=".!?;"; |
|
112 |
$str2=".!?;"; |
|
113 |
} else { // linux & Co. |
|
114 |
// start-sign: .!?; + INVERTED EXCLAMATION MARK - INVERTED QUESTION MARK - DOUBLE EXCLAMATION MARK - INTERROBANG - EXCLAMATION QUESTION MARK - QUESTION EXCLAMATION MARK - DOUBLE QUESTION MARK - HALFWIDTH IDEOGRAPHIC FULL STOP - IDEOGRAPHIC FULL STOP - IDEOGRAPHIC COMMA |
|
115 |
$str1=".!?;"."\xC2\xA1"."\xC2\xBF"."\xE2\x80\xBC"."\xE2\x80\xBD"."\xE2\x81\x89"."\xE2\x81\x88"."\xE2\x81\x87"."\xEF\xBD\xA1"."\xE3\x80\x82"."\xE3\x80\x81"; |
|
116 |
// stop-sign: .!?; + DOUBLE EXCLAMATION MARK - INTERROBANG - EXCLAMATION QUESTION MARK - QUESTION EXCLAMATION MARK - DOUBLE QUESTION MARK - HALFWIDTH IDEOGRAPHIC FULL STOP - IDEOGRAPHIC FULL STOP - IDEOGRAPHIC COMMA |
|
117 |
$str2=".!?;"."\xE2\x80\xBC"."\xE2\x80\xBD"."\xE2\x81\x89"."\xE2\x81\x88"."\xE2\x81\x87"."\xEF\xBD\xA1"."\xE3\x80\x82"."\xE3\x80\x81"; |
|
118 |
} |
|
119 |
$regex='/(?:^|\b|['.$str1.'])([^'.$str1.']{0,200}?'.$word.'[^'.$str2.']{0,200}(?:['.$str2.']|\b|$))/uis'; |
|
120 |
if(version_compare(PHP_VERSION, '4.3.3', '>=') && |
|
121 |
strpos(strtoupper(PHP_OS), 'WIN')!==0 |
|
122 |
) { // this may crash windows server, so skip if on windows |
|
123 |
// jump from match to match, get excerpt, stop if $max_excerpt_num is reached |
|
124 |
$last_end = 0; $offset = 0; |
|
125 |
while(preg_match('/'.$word.'/uis', $text, $match_array, PREG_OFFSET_CAPTURE, $last_end)) |
|
126 |
{ |
|
127 |
$offset = ($match_array[0][1]-206 < $last_end)?$last_end:$match_array[0][1]-206; |
|
128 |
if(preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE, $offset)) |
|
129 |
{ |
|
130 |
$last_end = $matches[1][1]+strlen($matches[1][0])-1; |
|
131 |
if(!preg_match('/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\./', $matches[1][0])) // skip excerpts with email-addresses |
|
132 |
{ |
|
133 |
$excerpt_array[] = trim($matches[1][0]); |
|
134 |
} |
|
135 |
if(count($excerpt_array)>=$max_excerpt_num) |
|
136 |
{ |
|
137 |
$excerpt_array = array_unique($excerpt_array); |
|
138 |
if(count($excerpt_array) >= $max_excerpt_num) { break; } |
|
139 |
} |
|
140 |
} else { // problem: preg_match failed - can't find a start- or stop-sign |
|
141 |
$last_end += 201; // jump forward and try again |
|
142 |
} |
|
84 |
// start-sign: .!?; + INVERTED EXCLAMATION MARK - INVERTED QUESTION MARK - DOUBLE EXCLAMATION MARK - INTERROBANG - EXCLAMATION QUESTION MARK - QUESTION EXCLAMATION MARK - DOUBLE QUESTION MARK - HALFWIDTH IDEOGRAPHIC FULL STOP - IDEOGRAPHIC FULL STOP - IDEOGRAPHIC COMMA |
|
85 |
$p_start=".!?;"."\xC2\xA1"."\xC2\xBF"."\xE2\x80\xBC"."\xE2\x80\xBD"."\xE2\x81\x89"."\xE2\x81\x88"."\xE2\x81\x87"."\xEF\xBD\xA1"."\xE3\x80\x82"."\xE3\x80\x81"; |
|
86 |
// stop-sign: .!?; + DOUBLE EXCLAMATION MARK - INTERROBANG - EXCLAMATION QUESTION MARK - QUESTION EXCLAMATION MARK - DOUBLE QUESTION MARK - HALFWIDTH IDEOGRAPHIC FULL STOP - IDEOGRAPHIC FULL STOP - IDEOGRAPHIC COMMA |
|
87 |
$p_stop=".!?;"."\xE2\x80\xBC"."\xE2\x80\xBD"."\xE2\x81\x89"."\xE2\x81\x88"."\xE2\x81\x87"."\xEF\xBD\xA1"."\xE3\x80\x82"."\xE3\x80\x81"; |
|
88 |
// jump from match to match, get excerpt, stop if $max_excerpt_num is reached |
|
89 |
$match_array = $matches = array(); |
|
90 |
$startpos = $wordpos = $endpos = 0; // although preg_match with u-switch handles unicode correctly, the ...pos-variables will count bytes (not chars) |
|
91 |
while(preg_match("/$word/i", $text, $match_array, PREG_OFFSET_CAPTURE, $startpos)) { |
|
92 |
$wordpos = $match_array[0][1]; |
|
93 |
$startpos = ($wordpos-200 < $endpos)?$endpos:$wordpos-200; |
|
94 |
$endpos = $wordpos+200; |
|
95 |
// look for better start position |
|
96 |
if(preg_match_all("/[$p_start]/u", substr($text, $startpos, $wordpos-$startpos), $matches, PREG_OFFSET_CAPTURE)) |
|
97 |
$startpos += $matches[0][count($matches[0])-1][1]; // set startpos at last punctuation before word |
|
98 |
// look for better end position |
|
99 |
if(preg_match_all("/[$p_stop]/u", substr($text, $wordpos, $endpos-$wordpos), $matches, PREG_OFFSET_CAPTURE)) |
|
100 |
$endpos = $wordpos+$matches[0][0][1]; // set endpos at first punctuation after word |
|
101 |
$match = substr($text, $startpos+1, $endpos-$startpos); |
|
102 |
if(!preg_match('/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\./', $match)) // skip excerpts with email-addresses |
|
103 |
$excerpt_array[] = trim($match); |
|
104 |
if(count($excerpt_array)>=$max_excerpt_num) { |
|
105 |
$excerpt_array = array_unique($excerpt_array); |
|
106 |
if(count($excerpt_array) >= $max_excerpt_num) |
|
107 |
break; |
|
143 | 108 |
} |
144 |
} else { // compatible, but may be very slow with large pages |
|
145 |
if(preg_match_all($regex, $text, $match_array)) |
|
146 |
{ |
|
147 |
foreach($match_array[1] AS $string) |
|
148 |
{ |
|
149 |
if(!preg_match('/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\./', $string)) // skip excerpts with email-addresses |
|
150 |
{ |
|
151 |
$excerpt_array[] = trim($string); |
|
152 |
} |
|
153 |
|
|
154 |
} |
|
155 |
} |
|
109 |
// restart at last endpos |
|
110 |
$startpos = $endpos; |
|
156 | 111 |
} |
157 | 112 |
return $excerpt_array; |
158 | 113 |
} |
159 | 114 |
|
160 | 115 |
// makes excerpt_array a string ready to print out |
161 |
function prepare_excerpts($excerpt_array, $search_words, $max_excerpt_num) |
|
162 |
{ |
|
116 |
function prepare_excerpts($excerpt_array, $search_words, $max_excerpt_num) { |
|
163 | 117 |
// excerpts: text before and after a single excerpt, html-tag for markup |
164 | 118 |
$EXCERPT_BEFORE = '... '; |
165 | 119 |
$EXCERPT_AFTER = ' ...<br />'; |
... | ... | |
168 | 122 |
// remove duplicate matches from $excerpt_array, if any. |
169 | 123 |
$excerpt_array = array_unique($excerpt_array); |
170 | 124 |
// use the first $max_excerpt_num excerpts only |
171 |
if(count($excerpt_array) > $max_excerpt_num) |
|
172 |
{ |
|
125 |
if(count($excerpt_array) > $max_excerpt_num) { |
|
173 | 126 |
$excerpt_array = array_slice($excerpt_array, 0, $max_excerpt_num); |
174 | 127 |
} |
175 | 128 |
// prepare search-string |
... | ... | |
177 | 130 |
// we want markup on search-results page, |
178 | 131 |
// but we need some 'magic' to prevent <br />, <b>... from being highlighted |
179 | 132 |
$excerpt = ''; |
180 |
foreach($excerpt_array as $str) |
|
181 |
{ |
|
182 |
$excerpt .= '#,,#'.preg_replace("/($string)/iu","#,,,,#$1#,,,,,#",$str).'#,,,#'; |
|
133 |
foreach($excerpt_array as $str) { |
|
134 |
$excerpt .= '#,,#'.preg_replace("/($string)/i","#,,,,#$1#,,,,,#",$str).'#,,,#'; |
|
183 | 135 |
} |
184 |
$excerpt = str_replace(array('&','<','>','"','\'',"\xC2\xA0"), array('&','<','>','"',''',' '), $excerpt);
|
|
136 |
$excerpt = str_replace(array('&','<','>','"','\'',"\xC2\xA0"), array('&','<','>','"',''',' '), $excerpt);
|
|
185 | 137 |
$excerpt = str_replace(array('#,,,,#','#,,,,,#'), array($EXCERPT_MARKUP_START,$EXCERPT_MARKUP_END), $excerpt); |
186 | 138 |
$excerpt = str_replace(array('#,,#','#,,,#'), array($EXCERPT_BEFORE,$EXCERPT_AFTER), $excerpt); |
187 | 139 |
// prepare to write out |
188 |
if(DEFAULT_CHARSET != 'utf-8') |
|
189 |
{ |
|
140 |
if(DEFAULT_CHARSET != 'utf-8') { |
|
190 | 141 |
$excerpt = umlauts_to_entities($excerpt, 'UTF-8'); |
191 | 142 |
} |
192 | 143 |
return $excerpt; |
193 | 144 |
} |
194 | 145 |
|
195 | 146 |
// work out what the link-anchor should be |
196 |
function make_url_target($page_link_target, $text, $search_words) |
|
197 |
{ |
|
147 |
function make_url_target($page_link_target, $text, $search_words) { |
|
198 | 148 |
// 1. e.g. $page_link_target=="&monthno=5&year=2007" - module-dependent target. Do nothing. |
199 | 149 |
// 2. $page_link_target=="#!wb_section_..." - the user wants the section-target, so do nothing. |
200 | 150 |
// 3. $page_link_target=="#wb_section_..." - try to find a better target, use the section-target as fallback. |
201 | 151 |
// 4. $page_link_target=="" - do nothing |
202 |
if(version_compare(PHP_VERSION, '4.3.3', ">=") && substr($page_link_target,0,12)=='#wb_section_') |
|
203 |
{ |
|
152 |
if(version_compare(PHP_VERSION, '4.3.3', ">=") && substr($page_link_target,0,12)=='#wb_section_') { |
|
204 | 153 |
$word = '('.implode('|', $search_words).')'; |
205 |
preg_match('/'.$word.'/ui', $text, $match, PREG_OFFSET_CAPTURE); |
|
206 |
if($match && is_array($match[0])) |
|
207 |
{ |
|
154 |
preg_match('/'.$word.'/i', $text, $match, PREG_OFFSET_CAPTURE); |
|
155 |
if($match && is_array($match[0])) { |
|
208 | 156 |
$x=$match[0][1]; // position of first match |
209 | 157 |
// is there an anchor nearby? |
210 |
if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iU', substr($text,0,$x), $match, PREG_OFFSET_CAPTURE)) |
|
211 |
{ |
|
212 |
$anchor=''; |
|
213 |
foreach($match[1] AS $array) |
|
214 |
{ |
|
215 |
if($array[1] > $x) |
|
216 |
{ |
|
217 |
break; |
|
218 |
} |
|
219 |
$anchor = $array[0]; |
|
220 |
} |
|
221 |
if($anchor != '') |
|
222 |
{ |
|
223 |
$page_link_target = '#'.$anchor; |
|
224 |
} |
|
158 |
if(preg_match_all('/<\s*(?:a[^>]+?name|[^>]+?id)\s*=\s*"([^"]+)"/i', substr($text,0,$x), $match)) { |
|
159 |
$page_link_target = '#'.$match[1][count($match[1])-1]; |
|
225 | 160 |
} |
226 | 161 |
} |
227 |
} elseif(substr($page_link_target,0,13)=='#!wb_section_') { |
|
162 |
} |
|
163 |
elseif(substr($page_link_target,0,13)=='#!wb_section_') { |
|
228 | 164 |
$page_link_target = '#'.substr($page_link_target, 2); |
229 | 165 |
} |
230 | 166 |
|
231 | 167 |
// since wb 2.7.1 the section-anchor is configurable - SEC_ANCHOR holds the anchor name |
232 |
if(substr($page_link_target,0,12)=='#wb_section_') |
|
233 |
{ |
|
234 |
if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') |
|
235 |
{ |
|
168 |
if(substr($page_link_target,0,12)=='#wb_section_') { |
|
169 |
if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') { |
|
236 | 170 |
$sec_id = substr($page_link_target, 12); |
237 | 171 |
$page_link_target = '#'.SEC_ANCHOR.$sec_id; |
238 | 172 |
} else { // section-anchors are disabled |
... | ... | |
244 | 178 |
} |
245 | 179 |
|
246 | 180 |
// wrapper for compatibility with old print_excerpt() |
247 |
function print_excerpt($page_link, $page_link_target, $page_title, $page_description, $page_modified_when, $page_modified_by, $text, $max_excerpt_num, $func_vars, $pic_link="") |
|
248 |
{ |
|
181 |
function print_excerpt($page_link, $page_link_target, $page_title, $page_description, $page_modified_when, $page_modified_by, $text, $max_excerpt_num, $func_vars, $pic_link="") { |
|
249 | 182 |
$mod_vars = array( |
250 | 183 |
'page_link' => $page_link, |
251 | 184 |
'page_link_target' => $page_link_target, |
... | ... | |
267 | 200 |
* list_files_dirs() - lists all files and dirs below a given directory |
268 | 201 |
* clear_filelist() - keeps only wanted or removes unwanted entries in file-list. |
269 | 202 |
*/ |
270 |
|
|
203 |
|
|
271 | 204 |
// prints the excerpts for one section |
272 |
function print_excerpt2($mod_vars, $func_vars) |
|
273 |
{ |
|
205 |
function print_excerpt2($mod_vars, $func_vars) { |
|
274 | 206 |
extract($func_vars, EXTR_PREFIX_ALL, 'func'); |
275 | 207 |
extract($mod_vars, EXTR_PREFIX_ALL, 'mod'); |
276 | 208 |
global $TEXT; |
277 | 209 |
// check $mod_...vars |
278 |
if(!isset($mod_page_link)) { $mod_page_link = $func_page_link; } |
|
279 |
if(!isset($mod_page_link_target)) { $mod_page_link_target = ''; } |
|
280 |
if(!isset($mod_page_title)) { $mod_page_title = $func_page_title; } |
|
281 |
if(!isset($mod_page_description)) { $mod_page_description = $func_page_description; } |
|
282 |
if(!isset($mod_page_modified_when)) { $mod_page_modified_when = $func_page_modified_when; } |
|
283 |
if(!isset($mod_page_modified_by)) { $mod_page_modified_by = $func_page_modified_by; } |
|
284 |
if(!isset($mod_text)) { $mod_text = ''; } |
|
285 |
if(!isset($mod_max_excerpt_num)) { $mod_max_excerpt_num = $func_default_max_excerpt; } |
|
286 |
if(!isset($mod_pic_link)) { $mod_pic_link = ''; } |
|
287 |
if(!isset($mod_no_highlight)) { $mod_no_highlight = false; } |
|
288 |
if(!isset($func_enable_flush)) { $func_enable_flush = false; } // set this in db: wb_search.cfg_enable_flush [READ THE DOC BEFORE] |
|
289 |
if(isset($mod_ext_charset)) |
|
290 |
{ |
|
291 |
$mod_ext_charset = strtolower($mod_ext_charset); |
|
292 |
} else { |
|
293 |
$mod_ext_charset = ''; |
|
294 |
} |
|
210 |
if(!isset($mod_page_link)) $mod_page_link = $func_page_link; |
|
211 |
if(!isset($mod_page_link_target)) $mod_page_link_target = ""; |
|
212 |
if(!isset($mod_page_title)) $mod_page_title = $func_page_title; |
|
213 |
if(!isset($mod_page_description)) $mod_page_description = $func_page_description; |
|
214 |
if(!isset($mod_page_modified_when)) $mod_page_modified_when = $func_page_modified_when; |
|
215 |
if(!isset($mod_page_modified_by)) $mod_page_modified_by = $func_page_modified_by; |
|
216 |
if(!isset($mod_text)) $mod_text = ""; |
|
217 |
if(!isset($mod_max_excerpt_num)) $mod_max_excerpt_num = $func_default_max_excerpt; |
|
218 |
if(!isset($mod_pic_link)) $mod_pic_link = ""; |
|
219 |
if(!isset($mod_no_highlight)) $mod_no_highlight = false; |
|
220 |
if(!isset($func_enable_flush)) $func_enable_flush = false; // set this in db: wb_search.cfg_enable_flush [READ THE DOC BEFORE] |
|
221 |
if(isset($mod_ext_charset)) $mod_ext_charset = strtolower($mod_ext_charset); |
|
222 |
else $mod_ext_charset = ''; |
|
295 | 223 |
|
296 | 224 |
if($mod_text == "") // nothing to do |
297 | 225 |
{ return false; } |
... | ... | |
299 | 227 |
if($mod_no_highlight) // no highlighting |
300 | 228 |
{ $mod_page_link_target = "&nohighlight=1".$mod_page_link_target; } |
301 | 229 |
// clean the text: |
230 |
$mod_text = preg_replace('#<(br|dt|/dd|/?(?:h[1-6]|tr|table|p|li|ul|pre|code|div|hr))[^>]*>#i', '.', $mod_text); |
|
302 | 231 |
$mod_text = preg_replace('#<(!--.*--|style.*</style|script.*</script)>#iU', ' ', $mod_text); |
303 |
$mod_text = preg_replace('#<(br( /)?|dt|/dd|/?(h[1-6]|tr|table|p|li|ul|pre|code|div|hr))[^>]*>#i', '.', $mod_text); |
|
304 |
// $mod_text = preg_replace('/(\v\s?|\s\s)+/', ' ', $mod_text); |
|
305 |
$mod_text = preg_replace('/\s\./', '.', $mod_text); |
|
232 |
$mod_text = preg_replace('#\[\[.*?\]\]#', '', $mod_text); //Filter droplets from the page data |
|
233 |
// strip_tags() is called below |
|
306 | 234 |
if($mod_ext_charset!='') { // data from external database may have a different charset |
307 | 235 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
308 | 236 |
switch($mod_ext_charset) { |
... | ... | |
333 | 261 |
$mod_text = charset_to_utf8($mod_text, 'UTF-8'); |
334 | 262 |
} |
335 | 263 |
} else { |
336 |
$mod_text = entities_to_umlauts($mod_text, 'UTF-8'); |
|
264 |
$mod_text = entities_to_umlauts($mod_text, 'UTF-8');
|
|
337 | 265 |
} |
338 | 266 |
$anchor_text = $mod_text; // make an copy containing html-tags |
339 | 267 |
$mod_text = strip_tags($mod_text); |
340 |
$mod_text = str_replace(array('>','<','&','"',''',''',' '), array('>','<','&','"','\'','\'',"\xC2\xA0"), $mod_text);
|
|
268 |
$mod_text = str_replace(array('>','<','&','"',''',''',' '), array('>','<','&','"','\'','\'',' '), $mod_text);
|
|
341 | 269 |
$mod_text = '.'.trim($mod_text).'.'; |
342 |
// Do a fast scan over $mod_text first. This will speedup things a lot.
|
|
270 |
// Do a fast scan over $mod_text first. This may speedup things a lot.
|
|
343 | 271 |
if($func_search_match == 'all') { |
344 | 272 |
if(!is_all_matched($mod_text, $func_search_words)) |
345 | 273 |
return false; |
... | ... | |
349 | 277 |
} |
350 | 278 |
// search for an better anchor - this have to be done before strip_tags() (may fail if search-string contains <, &, amp, gt, lt, ...) |
351 | 279 |
$anchor = make_url_target($mod_page_link_target, $anchor_text, $func_search_words); |
352 |
|
|
353 | 280 |
// make the link from $mod_page_link, add anchor |
354 | 281 |
$link = ""; |
355 | 282 |
$link = page_link($mod_page_link); |
... | ... | |
366 | 293 |
} |
367 | 294 |
$excerpt = prepare_excerpts($excerpt_array, $func_search_words, $mod_max_excerpt_num); |
368 | 295 |
} |
369 |
|
|
370 | 296 |
// handle thumbs - to deactivate this look in the module's search.php: $show_thumb (or maybe in the module's settings-page) |
371 | 297 |
if($mod_pic_link != "") { |
372 |
$excerpt = '<table class="excerpt_thumb" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="110" valign="top"><a href="'.$link.'"><img src="'.WB_URL.'/'.MEDIA_DIRECTORY.$mod_pic_link.'" alt="" /></a></td><td>'.$excerpt.'</td></tr></tbody></table>'; |
|
298 |
if(isset($mod_special) && $mod_special=='lightbox2_plus') |
|
299 |
$excerpt = '<table class="excerpt_thumb" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="110" valign="top">'.$mod_special_piclink.'<img src="'.WB_URL.'/'.MEDIA_DIRECTORY.$mod_pic_link.'" alt="" /></a></td><td>'.$excerpt.'</td></tr></tbody></table>'; |
|
300 |
else |
|
301 |
$excerpt = '<table class="excerpt_thumb" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="110" valign="top"><a href="'.$link.'"><img src="'.WB_URL.'/'.MEDIA_DIRECTORY.$mod_pic_link.'" alt="" /></a></td><td>'.$excerpt.'</td></tr></tbody></table>'; |
|
373 | 302 |
} |
374 | 303 |
|
375 | 304 |
// print-out the excerpt |
... | ... | |
377 | 306 |
$values = array(); |
378 | 307 |
list($date, $time) = get_page_modified($mod_page_modified_when); |
379 | 308 |
list($username, $displayname) = get_page_modified_by($mod_page_modified_by, $func_users); |
380 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]','[EXCERPT]'); |
|
309 |
$vars = array('[LINK]', '[TITLE]','[PAGE_TITLE]' ,'[MENU_TITLE]' , '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]','[EXCERPT]');
|
|
381 | 310 |
$values = array( |
382 | 311 |
$link, |
383 | 312 |
$mod_page_title, |
313 |
$func_page_title, |
|
314 |
$func_page_menu_title, |
|
384 | 315 |
$mod_page_description, |
385 | 316 |
$username, |
386 | 317 |
$displayname, |
... | ... | |
423 | 354 |
} |
424 | 355 |
|
425 | 356 |
// keeps only wanted entries in array $files. $str have to be an eregi()-compatible regex |
426 |
/* |
|
427 |
function clear_filelist($files, $str, $keep=true) |
|
428 |
{ |
|
357 |
function clear_filelist($files, $str, $keep=true) { |
|
429 | 358 |
// options: $keep = true : remove all non-matching entries |
430 | 359 |
// $keep = false : remove all matching entries |
431 | 360 |
$c_filelist = array(); |
432 | 361 |
if($str == '') |
433 | 362 |
return $files; |
434 |
foreach($files as $file) |
|
435 |
{ |
|
436 |
if($keep) |
|
437 |
{ |
|
438 |
if(eregi($str, $file)) |
|
439 |
{ |
|
363 |
foreach($files as $file) { |
|
364 |
if($keep) { |
|
365 |
if(eregi($str, $file)) { |
|
440 | 366 |
$c_filelist[] = $file; |
441 | 367 |
} |
442 | 368 |
} else { |
443 |
if(!eregi($str, $file)) |
|
444 |
{ |
|
369 |
if(!eregi($str, $file)) { |
|
445 | 370 |
$c_filelist[] = $file; |
446 | 371 |
} |
447 | 372 |
} |
448 | 373 |
} |
449 | 374 |
return($c_filelist); |
450 | 375 |
} |
451 |
*/ |
|
452 |
?> |
|
376 |
|
|
377 |
function search_make_sql_part($words, $match, $columns) { |
|
378 |
// $words are utf-8 encoded, will be converted to DEFAULT_CHARSET below |
|
379 |
if(empty($words) || empty($columns)) return('(1=1)'); |
|
380 |
global $database; |
|
381 |
|
|
382 |
// check if we can use SQL'S "LIKE" |
|
383 |
// work-around for WB'S missing-SET-NAMES-problem |
|
384 |
static $checked = FALSE; |
|
385 |
if($checked===FALSE) { |
|
386 |
$checked = TRUE; |
|
387 |
$lowers = array('utf8'=>"\xc3\xa1", 'iso'=>"\xe1"); |
|
388 |
$uppers = array('utf8'=>"\xc3\x81", 'iso'=>"\xc1"); |
|
389 |
switch(DEFAULT_CHARSET) { |
|
390 |
case 'utf-8': |
|
391 |
$lo = $lowers['utf8']; |
|
392 |
$up = $uppers['utf8']; |
|
393 |
break; |
|
394 |
case 'iso-8859-1': |
|
395 |
case 'iso-8859-2': |
|
396 |
case 'iso-8859-3': |
|
397 |
case 'iso-8859-4': |
|
398 |
case 'iso-8859-5': |
|
399 |
case 'iso-8859-7': |
|
400 |
case 'iso-8859-9': |
|
401 |
case 'iso-8859-10': |
|
402 |
$lo = $lowers['iso']; |
|
403 |
$up = $uppers['iso']; |
|
404 |
break; |
|
405 |
default: |
|
406 |
$checked = 'check failed'; // we can't handle arabic,hebrew,thai |
|
407 |
} |
|
408 |
if($checked===TRUE && $query = $database->query("SELECT UPPER('$lo')='$up'")) { |
|
409 |
$res = $query->fetchRow(); |
|
410 |
if($res[0]==0) { |
|
411 |
$checked = 'check failed'; |
|
412 |
} |
|
413 |
} else |
|
414 |
$checked = 'check failed'; |
|
415 |
} |
|
416 |
|
|
417 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
|
418 |
global $search_table_sql_local; |
|
419 |
$altnum = count($search_table_sql_local); |
|
420 |
|
|
421 |
if($match=='all') $op = 'AND'; |
|
422 |
else $op = ' OR'; // keep the leading space! |
|
423 |
|
|
424 |
// create sql-template |
|
425 |
$sql = ''; |
|
426 |
$i = 0; |
|
427 |
foreach($words as $w) { |
|
428 |
if(empty($w)) continue; |
|
429 |
$w_alts = $e_alts = array(); |
|
430 |
if($altnum) { |
|
431 |
for($x=0;$x<$altnum;$x++) |
|
432 |
$w_alts[$x] = strtr($w, $search_table_sql_local[$x]); |
|
433 |
} else { |
|
434 |
$w_alts[0] = $w; |
|
435 |
} |
|
436 |
$w_alts = array_unique($w_alts); |
|
437 |
foreach($w_alts as $a) { |
|
438 |
$tmp = htmlentities($a, ENT_COMPAT, 'UTF-8'); |
|
439 |
// if the missing-SET-NAMES-issue appears and $tmp contains non-ascii characters: exit and use the normal (slow) search-function instead |
|
440 |
if($checked!==TRUE && preg_match('/[\x80-\xFF]/', $tmp)) return('(1=1)'); // missing-SET-NAMES-issue |
|
441 |
$e_alts[] = $tmp; |
|
442 |
} |
|
443 |
$sql .= ""; |
|
444 |
foreach($w_alts as $a) |
|
445 |
$sql .= "{{COL}} LIKE '%".addslashes(utf8_to_charset($a))."%' OR "; |
|
446 |
if(isset($e_alts[$i]) && $e_alts[$i]!=$w) |
|
447 |
$sql .= " {{COL}} LIKE '%".addslashes($e_alts[$i])."%'"; |
|
448 |
else { |
|
449 |
$sql = substr($sql, 0, strlen($sql)-4); |
|
450 |
$sql .= ''; |
|
451 |
} |
|
452 |
$sql .= " $op "; |
|
453 |
$i++; |
|
454 |
} |
|
455 |
$sql = substr($sql, 0, strlen($sql)-5); |
|
456 |
$sql_template = $sql; |
|
457 |
|
|
458 |
// create SQL-string from template |
|
459 |
$sql = '('; |
|
460 |
foreach($columns as $c) { |
|
461 |
$sql .= '('; |
|
462 |
$sql .= str_replace('{{COL}}', $c, $sql_template); |
|
463 |
$sql .= ") OR "; |
|
464 |
} |
|
465 |
$sql = substr($sql, 0, strlen($sql)-4); |
|
466 |
$sql .= ')'; |
|
467 |
|
|
468 |
return($sql); |
|
469 |
} |
Also available in: Unified diff