修订版 | f8c393a4ea847f3dc85d5695554c85fe3396de70 (tree) |
---|---|
时间 | 2017-11-01 05:18:53 |
作者 | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2452 Remove 'create_function' function for stability
Note that 'create_function' will be deprecated in PHP 7.2 .
@@ -230,6 +230,13 @@ function auto_template($page) | ||
230 | 230 | return $body; |
231 | 231 | } |
232 | 232 | |
233 | +function _mb_convert_kana__enable($str, $option) { | |
234 | + return mb_convert_kana($str, $option, SOURCE_ENCODING); | |
235 | +} | |
236 | +function _mb_convert_kana__none($str, $option) { | |
237 | + return $str; | |
238 | +} | |
239 | + | |
233 | 240 | // Expand all search-words to regexes and push them into an array |
234 | 241 | function get_search_words($words = array(), $do_escape = FALSE) |
235 | 242 | { |
@@ -238,11 +245,9 @@ function get_search_words($words = array(), $do_escape = FALSE) | ||
238 | 245 | if (! isset($init)) { |
239 | 246 | // function: mb_convert_kana() is for Japanese code only |
240 | 247 | if (LANG == 'ja' && function_exists('mb_convert_kana')) { |
241 | - $mb_convert_kana = create_function('$str, $option', | |
242 | - 'return mb_convert_kana($str, $option, SOURCE_ENCODING);'); | |
248 | + $mb_convert_kana = '_mb_convert_kana__enable'; | |
243 | 249 | } else { |
244 | - $mb_convert_kana = create_function('$str, $option', | |
245 | - 'return $str;'); | |
250 | + $mb_convert_kana = '_mb_convert_kana__none'; | |
246 | 251 | } |
247 | 252 | if (SOURCE_ENCODING == 'EUC-JP') { |
248 | 253 | // Perl memo - Correct pattern-matching with EUC-JP |
@@ -166,28 +166,24 @@ function catbody($title, $page, $body) | ||
166 | 166 | arsort($keys, SORT_NUMERIC); |
167 | 167 | $keys = get_search_words(array_keys($keys), TRUE); |
168 | 168 | $id = 0; |
169 | + $patterns = ''; | |
169 | 170 | foreach ($keys as $key=>$pattern) { |
170 | - $s_key = htmlsc($key); | |
171 | - $pattern = '/' . | |
171 | + if (strlen($patterns) > 0) { | |
172 | + $patterns .= '|'; | |
173 | + } | |
174 | + $patterns .= '(' . $pattern . ')'; | |
175 | + } | |
176 | + if ($pattern) { | |
177 | + $whole_pattern = '/' . | |
172 | 178 | '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas |
173 | 179 | '|' . '<[^>]*>' . // Ignore tags |
174 | 180 | '|' . '&[^;]+;' . // Ignore entities |
175 | - '|' . '(' . $pattern . ')' . // $matches[1]: Regex for a search word | |
181 | + '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word | |
176 | 182 | '/sS'; |
177 | - $decorate_Nth_word = create_function( | |
178 | - '$matches', | |
179 | - 'return (isset($matches[1])) ? ' . | |
180 | - '\'<strong class="word' . | |
181 | - $id . | |
182 | - '">\' . $matches[1] . \'</strong>\' : ' . | |
183 | - '$matches[0];' | |
184 | - ); | |
185 | - $body = preg_replace_callback($pattern, $decorate_Nth_word, $body); | |
186 | - $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes); | |
187 | - ++$id; | |
183 | + $body = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $body); | |
184 | + $notes = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $notes); | |
188 | 185 | } |
189 | 186 | } |
190 | - | |
191 | 187 | // Embed Scripting data |
192 | 188 | $html_scripting_data = get_html_scripting_data(); |
193 | 189 |
@@ -197,6 +193,26 @@ function catbody($title, $page, $body) | ||
197 | 193 | require(SKIN_FILE); |
198 | 194 | } |
199 | 195 | |
196 | +function _decorate_Nth_word($matches) | |
197 | +{ | |
198 | + // $matches[0]: including both words to skip and to decorate | |
199 | + // $matches[1]: word to decorate | |
200 | + // $matches[2+]: indicates which keyword to decorate | |
201 | + $index = -1; | |
202 | + for ($i = 2; $i < count($matches); $i++) { | |
203 | + if (isset($matches[$i]) && $matches[$i]) { | |
204 | + $index = $i - 2; | |
205 | + break; | |
206 | + } | |
207 | + } | |
208 | + if (isset($matches[1])) { | |
209 | + // wordN highlight class: N=0...n | |
210 | + return '<strong class="word' . $index . '">' . | |
211 | + $matches[0] . '</strong>'; | |
212 | + } | |
213 | + return $matches[0]; | |
214 | +} | |
215 | + | |
200 | 216 | /** |
201 | 217 | * Get data used by JavaScript modules |
202 | 218 | */ |
@@ -264,7 +280,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE) | ||
264 | 280 | if ($digest === FALSE) $digest = md5(join('', get_source($page))); |
265 | 281 | |
266 | 282 | $refer = $template = ''; |
267 | - | |
283 | + | |
268 | 284 | // Add plugin |
269 | 285 | $addtag = $add_top = ''; |
270 | 286 | if(isset($vars['add'])) { |
@@ -441,6 +457,11 @@ function make_related($page, $tag = '') | ||
441 | 457 | return $retval; |
442 | 458 | } |
443 | 459 | |
460 | +function _convert_line_rule_to_regex($a) | |
461 | +{ | |
462 | + return '/' . $a . '/'; | |
463 | +} | |
464 | + | |
444 | 465 | // User-defined rules (convert without replacing source) |
445 | 466 | function make_line_rules($str) |
446 | 467 | { |
@@ -448,8 +469,7 @@ function make_line_rules($str) | ||
448 | 469 | static $pattern, $replace; |
449 | 470 | |
450 | 471 | if (! isset($pattern)) { |
451 | - $pattern = array_map(create_function('$a', | |
452 | - 'return \'/\' . $a . \'/\';'), array_keys($line_rules)); | |
472 | + $pattern = array_map('_convert_line_rule_to_regex', array_keys($line_rules)); | |
453 | 473 | $replace = array_values($line_rules); |
454 | 474 | unset($line_rules); |
455 | 475 | } |
@@ -30,16 +30,18 @@ class InlineConverter | ||
30 | 30 | var $result; |
31 | 31 | |
32 | 32 | function get_clone($obj) { |
33 | - static $clone_func; | |
34 | - | |
35 | - if (! isset($clone_func)) { | |
33 | + static $clone_exists; | |
34 | + if (! isset($clone_exists)) { | |
36 | 35 | if (version_compare(PHP_VERSION, '5.0.0', '<')) { |
37 | - $clone_func = create_function('$a', 'return $a;'); | |
36 | + $clone_exists = false; | |
38 | 37 | } else { |
39 | - $clone_func = create_function('$a', 'return clone $a;'); | |
38 | + $clone_exists = true; | |
40 | 39 | } |
41 | 40 | } |
42 | - return $clone_func($obj); | |
41 | + if ($clone_exists) { | |
42 | + return clone ($obj); | |
43 | + } | |
44 | + return $obj; | |
43 | 45 | } |
44 | 46 | |
45 | 47 | function __clone() { |
@@ -402,6 +402,7 @@ class Tracker_field_textarea extends Tracker_field | ||
402 | 402 | return $str; |
403 | 403 | } |
404 | 404 | } |
405 | + | |
405 | 406 | class Tracker_field_format extends Tracker_field |
406 | 407 | { |
407 | 408 | var $sort_type = SORT_STRING; |
@@ -419,7 +420,7 @@ class Tracker_field_format extends Tracker_field | ||
419 | 420 | |
420 | 421 | foreach ($this->config->get($this->name) as $option) |
421 | 422 | { |
422 | - list($key,$style,$format) = array_pad(array_map(create_function('$a','return trim($a);'),$option),3,''); | |
423 | + list($key,$style,$format) = array_pad(array_map('trim',$option),3,''); | |
423 | 424 | if ($style != '') |
424 | 425 | { |
425 | 426 | $this->styles[$key] = $style; |
@@ -511,7 +512,8 @@ class Tracker_field_radio extends Tracker_field_format | ||
511 | 512 | static $options = array(); |
512 | 513 | if (!array_key_exists($this->name,$options)) |
513 | 514 | { |
514 | - $options[$this->name] = array_flip(array_map(create_function('$arr','return $arr[0];'),$this->config->get($this->name))); | |
515 | + // 'reset' means function($arr) { return $arr[0]; } | |
516 | + $options[$this->name] = array_flip(array_map('reset',$this->config->get($this->name))); | |
515 | 517 | } |
516 | 518 | return array_key_exists($value,$options[$this->name]) ? $options[$this->name][$value] : $value; |
517 | 519 | } |