Project

General

Profile

« Previous | Next » 

Revision 1301

Added by Dietmar over 14 years ago

Tickets #932 change deprecated eregi functions
Tickets #948 fixed Multiple use of same parametrised droplet - parameter handling
Upgrade Droplets to Version 1.0.3
update some headerinfos
non existing pages, will be created if clicking save in page settings

View differences:

search_modext.php
17 17
 */
18 18

  
19 19
// make the url-string for highlighting
20
function make_url_searchstring($search_match, $search_url_array) {
20
function make_url_searchstring($search_match, $search_url_array)
21
{
21 22
	$link = "";
22
	if ($search_match != 'exact') {
23
	if ($search_match != 'exact')
24
    {
23 25
		$str = implode(" ", $search_url_array);
24 26
		$link = "?searchresult=1&sstring=".urlencode($str);
25 27
	} else {
......
30 32
}
31 33

  
32 34
// make date and time for "last modified by... on ..."-string
33
function get_page_modified($page_modified_when) {
35
function get_page_modified($page_modified_when)
36
{
34 37
	global $TEXT;
35
	if($page_modified_when > 0) {
38
	if($page_modified_when > 0)
39
    {
36 40
		$date = gmdate(DATE_FORMAT, $page_modified_when+TIMEZONE);
37 41
		$time = gmdate(TIME_FORMAT, $page_modified_when+TIMEZONE);
38 42
	} else {
......
43 47
}
44 48

  
45 49
// make username and displayname for "last modified by... on ..."-string
46
function get_page_modified_by($page_modified_by, $users) {
50
function get_page_modified_by($page_modified_by, $users)
51
{
47 52
	global $TEXT;
48 53
	// check for existing user-id
49 54
	if(!isset($users[$page_modified_by]))
50
		$page_modified_by = 0;
51
	
55
    {
56
        $page_modified_by = 0;
57
    }
58

  
52 59
	$username = $users[$page_modified_by]['username'];
53 60
	$displayname = $users[$page_modified_by]['display_name'];
54 61
	return array($username, $displayname);
55 62
}
56 63

  
57 64
// checks if _all_ searchwords matches
58
function is_all_matched($text, $search_words) {
65
function is_all_matched($text, $search_words)
66
{
59 67
	$all_matched = true;
60
	foreach ($search_words AS $word) {
61
		if(!preg_match('/'.$word.'/ui', $text)) {
68
	foreach ($search_words AS $word)
69
    {
70
		if(!preg_match('/'.$word.'/ui', $text))
71
        {
62 72
			$all_matched = false;
63 73
			break;
64 74
		}
......
67 77
}
68 78

  
69 79
// checks if _any_ of the searchwords matches
70
function is_any_matched($text, $search_words) {
80
function is_any_matched($text, $search_words)
81
{
71 82
	$any_matched = false;
72 83
	$word = '('.implode('|', $search_words).')';
73
	if(preg_match('/'.$word.'/ui', $text)) {
84
	if(preg_match('/'.$word.'/ui', $text))
85
    {
74 86
		$any_matched = true;
75 87
	}
76 88
	return $any_matched;
77 89
}
78 90

  
79 91
// collects the matches from text in excerpt_array
80
function get_excerpts($text, $search_words, $max_excerpt_num) {
92
function get_excerpts($text, $search_words, $max_excerpt_num)
93
{
81 94
	$match_array = array();
82 95
	$excerpt_array = array();
83 96
	$word = '('.implode('|', $search_words).')';
84 97

  
85 98
	//Filter droplets from the page data
86 99
	preg_match_all('~\[\[(.*?)\]\]~', $text, $matches);
87
	foreach ($matches[1] as $match) {
100
	foreach ($matches[1] as $match)
101
    {
88 102
		$text = str_replace('[['.$match.']]', '', $text);					
89 103
	}
90 104

  
91 105
	// Build the regex-string
92
	if(strpos(strtoupper(PHP_OS), 'WIN')===0) { // windows -> see below
106
	if(strpos(strtoupper(PHP_OS), 'WIN')===0)  // windows -> see below
107
    {
93 108
		$str1=".!?;";
94 109
		$str2=".!?;";
95 110
	} else { // linux & Co.
......
104 119
	) { // this may crash windows server, so skip if on windows
105 120
		// jump from match to match, get excerpt, stop if $max_excerpt_num is reached
106 121
		$last_end = 0; $offset = 0;
107
		while(preg_match('/'.$word.'/uis', $text, $match_array, PREG_OFFSET_CAPTURE, $last_end)) {
122
		while(preg_match('/'.$word.'/uis', $text, $match_array, PREG_OFFSET_CAPTURE, $last_end))
123
        {
108 124
			$offset = ($match_array[0][1]-206 < $last_end)?$last_end:$match_array[0][1]-206;
109
			if(preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
125
			if(preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE, $offset))
126
            {
110 127
				$last_end = $matches[1][1]+strlen($matches[1][0])-1;
111 128
				if(!preg_match('/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\./', $matches[1][0])) // skip excerpts with email-addresses
112
					$excerpt_array[] = trim($matches[1][0]);
113
				if(count($excerpt_array)>=$max_excerpt_num) {
129
				{
130
				  $excerpt_array[] = trim($matches[1][0]);
131
                }
132
				if(count($excerpt_array)>=$max_excerpt_num)
133
                {
114 134
					$excerpt_array = array_unique($excerpt_array);
115
					if(count($excerpt_array) >= $max_excerpt_num)
116
						break;
135
					if(count($excerpt_array) >= $max_excerpt_num) { break; }
117 136
				}
118 137
			} else { // problem: preg_match failed - can't find a start- or stop-sign
119 138
				$last_end += 201; // jump forward and try again
120 139
			}
121 140
		}
122 141
	} else { // compatible, but may be very slow with large pages
123
		if(preg_match_all($regex, $text, $match_array)) {
124
			foreach($match_array[1] AS $string) {
142
		if(preg_match_all($regex, $text, $match_array))
143
        {
144
			foreach($match_array[1] AS $string)
145
            {
125 146
				if(!preg_match('/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\./', $string))  // skip excerpts with email-addresses
126
					$excerpt_array[] = trim($string);
127
				
147
				{
148
				  $excerpt_array[] = trim($string);
149
                }
150

  
128 151
			}
129 152
		}
130 153
	}
......
132 155
}
133 156

  
134 157
// makes excerpt_array a string ready to print out
135
function prepare_excerpts($excerpt_array, $search_words, $max_excerpt_num) {
158
function prepare_excerpts($excerpt_array, $search_words, $max_excerpt_num)
159
{
136 160
	// excerpts: text before and after a single excerpt, html-tag for markup
137 161
	$EXCERPT_BEFORE =       '...&nbsp;';
138 162
	$EXCERPT_AFTER =        '&nbsp;...<br />';
......
141 165
	// remove duplicate matches from $excerpt_array, if any.
142 166
	$excerpt_array = array_unique($excerpt_array);
143 167
	// use the first $max_excerpt_num excerpts only
144
	if(count($excerpt_array) > $max_excerpt_num) {
168
	if(count($excerpt_array) > $max_excerpt_num)
169
    {
145 170
		$excerpt_array = array_slice($excerpt_array, 0, $max_excerpt_num);
146 171
	}
147 172
	// prepare search-string
......
149 174
	// we want markup on search-results page,
150 175
	// but we need some 'magic' to prevent <br />, <b>... from being highlighted
151 176
	$excerpt = '';
152
	foreach($excerpt_array as $str) {
177
	foreach($excerpt_array as $str)
178
    {
153 179
		$excerpt .= '#,,#'.preg_replace("/($string)/iu","#,,,,#$1#,,,,,#",$str).'#,,,#';
154 180
	}
155 181
	$excerpt = str_replace(array('&','<','>','"','\'',"\xC2\xA0"), array('&amp;','&lt;','&gt;','&quot;','&#039;','&nbsp;'), $excerpt);
156 182
	$excerpt = str_replace(array('#,,,,#','#,,,,,#'), array($EXCERPT_MARKUP_START,$EXCERPT_MARKUP_END), $excerpt);
157 183
	$excerpt = str_replace(array('#,,#','#,,,#'), array($EXCERPT_BEFORE,$EXCERPT_AFTER), $excerpt);
158 184
	// prepare to write out
159
	if(DEFAULT_CHARSET != 'utf-8') {
185
	if(DEFAULT_CHARSET != 'utf-8')
186
    {
160 187
		$excerpt = umlauts_to_entities($excerpt, 'UTF-8');
161 188
	}
162 189
	return $excerpt;
163 190
}
164 191

  
165 192
// work out what the link-anchor should be
166
function make_url_target($page_link_target, $text, $search_words) {
193
function make_url_target($page_link_target, $text, $search_words)
194
{
167 195
	// 1. e.g. $page_link_target=="&monthno=5&year=2007" - module-dependent target. Do nothing.
168 196
	// 2. $page_link_target=="#!wb_section_..." - the user wants the section-target, so do nothing.
169 197
	// 3. $page_link_target=="#wb_section_..." - try to find a better target, use the section-target as fallback.
170 198
	// 4. $page_link_target=="" - do nothing
171
	if(version_compare(PHP_VERSION, '4.3.3', ">=") && substr($page_link_target,0,12)=='#wb_section_') {
199
	if(version_compare(PHP_VERSION, '4.3.3', ">=") && substr($page_link_target,0,12)=='#wb_section_')
200
    {
172 201
		$word = '('.implode('|', $search_words).')';
173 202
		preg_match('/'.$word.'/ui', $text, $match, PREG_OFFSET_CAPTURE);
174
		if($match && is_array($match[0])) {
203
		if($match && is_array($match[0]))
204
        {
175 205
			$x=$match[0][1]; // position of first match
176 206
			// is there an anchor nearby?
177
			if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iU', substr($text,0,$x), $match, PREG_OFFSET_CAPTURE)) {
207
			if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iU', substr($text,0,$x), $match, PREG_OFFSET_CAPTURE))
208
            {
178 209
				$anchor='';
179
				foreach($match[1] AS $array) {
180
					if($array[1] > $x) {
210
				foreach($match[1] AS $array)
211
                {
212
					if($array[1] > $x)
213
                    {
181 214
						break;
182 215
					}
183 216
					$anchor = $array[0];
184 217
				}
185
				if($anchor != '') {
218
				if($anchor != '')
219
                {
186 220
					$page_link_target = '#'.$anchor;
187 221
				}
188 222
			}
189 223
		}
190
	}
191
	elseif(substr($page_link_target,0,13)=='#!wb_section_') {
224
	} elseif(substr($page_link_target,0,13)=='#!wb_section_') {
192 225
		$page_link_target = '#'.substr($page_link_target, 2);
193 226
	}
194 227
	
195 228
	// since wb 2.7.1 the section-anchor is configurable - SEC_ANCHOR holds the anchor name
196
	if(substr($page_link_target,0,12)=='#wb_section_') {
197
		if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
229
	if(substr($page_link_target,0,12)=='#wb_section_')
230
    {
231
		if(defined('SEC_ANCHOR') && SEC_ANCHOR!='')
232
        {
198 233
			$sec_id = substr($page_link_target, 12);
199 234
			$page_link_target = '#'.SEC_ANCHOR.$sec_id;
200 235
		} else { // section-anchors are disabled
......
206 241
}
207 242

  
208 243
// wrapper for compatibility with old print_excerpt()
209
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="") {
244
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="")
245
{
210 246
	$mod_vars = array(
211 247
		'page_link' => $page_link,
212 248
		'page_link_target' => $page_link_target,
......
228 264
 * list_files_dirs() - lists all files and dirs below a given directory
229 265
 * clear_filelist() - keeps only wanted or removes unwanted entries in file-list.
230 266
 */
231
 
267

  
232 268
// prints the excerpts for one section
233
function print_excerpt2($mod_vars, $func_vars) {
269
function print_excerpt2($mod_vars, $func_vars)
270
{
234 271
	extract($func_vars, EXTR_PREFIX_ALL, 'func');
235 272
	extract($mod_vars, EXTR_PREFIX_ALL, 'mod');
236 273
	global $TEXT;
237 274
	// check $mod_...vars
238
	if(!isset($mod_page_link))          $mod_page_link = $func_page_link;
239
	if(!isset($mod_page_link_target))   $mod_page_link_target = "";
240
	if(!isset($mod_page_title))         $mod_page_title = $func_page_title;
241
	if(!isset($mod_page_description))   $mod_page_description = $func_page_description;
242
	if(!isset($mod_page_modified_when)) $mod_page_modified_when = $func_page_modified_when;
243
	if(!isset($mod_page_modified_by))   $mod_page_modified_by = $func_page_modified_by;
244
	if(!isset($mod_text))               $mod_text = "";
245
	if(!isset($mod_max_excerpt_num))    $mod_max_excerpt_num = $func_default_max_excerpt;
246
	if(!isset($mod_pic_link))           $mod_pic_link = "";
247
	if(!isset($mod_no_highlight))       $mod_no_highlight = false;
248
	if(!isset($func_enable_flush))      $func_enable_flush = false; // set this in db: wb_search.cfg_enable_flush [READ THE DOC BEFORE]
249
	if(isset($mod_ext_charset)) $mod_ext_charset = strtolower($mod_ext_charset);
250
	else $mod_ext_charset = '';
275
	if(!isset($mod_page_link))          { $mod_page_link = $func_page_link; }
276
	if(!isset($mod_page_link_target))   { $mod_page_link_target = ''; }
277
	if(!isset($mod_page_title))         { $mod_page_title = $func_page_title; }
278
	if(!isset($mod_page_description))   { $mod_page_description = $func_page_description; }
279
	if(!isset($mod_page_modified_when)) { $mod_page_modified_when = $func_page_modified_when; }
280
	if(!isset($mod_page_modified_by))   { $mod_page_modified_by = $func_page_modified_by; }
281
	if(!isset($mod_text))               { $mod_text = ''; }
282
	if(!isset($mod_max_excerpt_num))    { $mod_max_excerpt_num = $func_default_max_excerpt; }
283
	if(!isset($mod_pic_link))           { $mod_pic_link = ''; }
284
	if(!isset($mod_no_highlight))       { $mod_no_highlight = false; }
285
	if(!isset($func_enable_flush))      { $func_enable_flush = false; } // set this in db: wb_search.cfg_enable_flush [READ THE DOC BEFORE]
286
	if(isset($mod_ext_charset))
287
    {
288
      $mod_ext_charset = strtolower($mod_ext_charset);
289
    } else {
290
      $mod_ext_charset = '';
291
    }
251 292

  
252 293
	if($mod_text == "") // nothing to do
253 294
		{ return false; }
......
379 420
}
380 421

  
381 422
// keeps only wanted entries in array $files. $str have to be an eregi()-compatible regex
382
function clear_filelist($files, $str, $keep=true) {
423
/*
424
function clear_filelist($files, $str, $keep=true)
425
{
383 426
	// options: $keep = true  : remove all non-matching entries
384 427
	//          $keep = false : remove all matching entries
385 428
	$c_filelist = array();
386 429
	if($str == '')
387 430
		return $files;
388
	foreach($files as $file) {
389
		if($keep) {
390
			if(eregi($str, $file)) {
431
	foreach($files as $file)
432
    {
433
		if($keep)
434
        {
435
			if(eregi($str, $file))
436
            {
391 437
				$c_filelist[] = $file;
392 438
			}
393 439
		} else {
394
			if(!eregi($str, $file)) {
440
			if(!eregi($str, $file))
441
            {
395 442
				$c_filelist[] = $file;
396 443
			}
397 444
		}
398 445
	}
399 446
	return($c_filelist);
400 447
}
401

  
402
?>

448
*/
449
?>

Also available in: Unified diff