• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版f8c393a4ea847f3dc85d5695554c85fe3396de70 (tree)
时间2017-11-01 05:18:53
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2452 Remove 'create_function' function for stability

Note that 'create_function' will be deprecated in PHP 7.2 .

更改概述

差异

--- a/lib/func.php
+++ b/lib/func.php
@@ -230,6 +230,13 @@ function auto_template($page)
230230 return $body;
231231 }
232232
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+
233240 // Expand all search-words to regexes and push them into an array
234241 function get_search_words($words = array(), $do_escape = FALSE)
235242 {
@@ -238,11 +245,9 @@ function get_search_words($words = array(), $do_escape = FALSE)
238245 if (! isset($init)) {
239246 // function: mb_convert_kana() is for Japanese code only
240247 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';
243249 } else {
244- $mb_convert_kana = create_function('$str, $option',
245- 'return $str;');
250+ $mb_convert_kana = '_mb_convert_kana__none';
246251 }
247252 if (SOURCE_ENCODING == 'EUC-JP') {
248253 // Perl memo - Correct pattern-matching with EUC-JP
--- a/lib/html.php
+++ b/lib/html.php
@@ -166,28 +166,24 @@ function catbody($title, $page, $body)
166166 arsort($keys, SORT_NUMERIC);
167167 $keys = get_search_words(array_keys($keys), TRUE);
168168 $id = 0;
169+ $patterns = '';
169170 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 = '/' .
172178 '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas
173179 '|' . '<[^>]*>' . // Ignore tags
174180 '|' . '&[^;]+;' . // Ignore entities
175- '|' . '(' . $pattern . ')' . // $matches[1]: Regex for a search word
181+ '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word
176182 '/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);
188185 }
189186 }
190-
191187 // Embed Scripting data
192188 $html_scripting_data = get_html_scripting_data();
193189
@@ -197,6 +193,26 @@ function catbody($title, $page, $body)
197193 require(SKIN_FILE);
198194 }
199195
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+
200216 /**
201217 * Get data used by JavaScript modules
202218 */
@@ -264,7 +280,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
264280 if ($digest === FALSE) $digest = md5(join('', get_source($page)));
265281
266282 $refer = $template = '';
267-
283+
268284 // Add plugin
269285 $addtag = $add_top = '';
270286 if(isset($vars['add'])) {
@@ -441,6 +457,11 @@ function make_related($page, $tag = '')
441457 return $retval;
442458 }
443459
460+function _convert_line_rule_to_regex($a)
461+{
462+ return '/' . $a . '/';
463+}
464+
444465 // User-defined rules (convert without replacing source)
445466 function make_line_rules($str)
446467 {
@@ -448,8 +469,7 @@ function make_line_rules($str)
448469 static $pattern, $replace;
449470
450471 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));
453473 $replace = array_values($line_rules);
454474 unset($line_rules);
455475 }
--- a/lib/make_link.php
+++ b/lib/make_link.php
@@ -30,16 +30,18 @@ class InlineConverter
3030 var $result;
3131
3232 function get_clone($obj) {
33- static $clone_func;
34-
35- if (! isset($clone_func)) {
33+ static $clone_exists;
34+ if (! isset($clone_exists)) {
3635 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
37- $clone_func = create_function('$a', 'return $a;');
36+ $clone_exists = false;
3837 } else {
39- $clone_func = create_function('$a', 'return clone $a;');
38+ $clone_exists = true;
4039 }
4140 }
42- return $clone_func($obj);
41+ if ($clone_exists) {
42+ return clone ($obj);
43+ }
44+ return $obj;
4345 }
4446
4547 function __clone() {
--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -402,6 +402,7 @@ class Tracker_field_textarea extends Tracker_field
402402 return $str;
403403 }
404404 }
405+
405406 class Tracker_field_format extends Tracker_field
406407 {
407408 var $sort_type = SORT_STRING;
@@ -419,7 +420,7 @@ class Tracker_field_format extends Tracker_field
419420
420421 foreach ($this->config->get($this->name) as $option)
421422 {
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,'');
423424 if ($style != '')
424425 {
425426 $this->styles[$key] = $style;
@@ -511,7 +512,8 @@ class Tracker_field_radio extends Tracker_field_format
511512 static $options = array();
512513 if (!array_key_exists($this->name,$options))
513514 {
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)));
515517 }
516518 return array_key_exists($value,$options[$this->name]) ? $options[$this->name][$value] : $value;
517519 }