OSDN Git Service

BugTrack/2452 Remove 'create_function' function for stability
authorumorigu <umorigu@gmail.com>
Tue, 31 Oct 2017 20:18:53 +0000 (05:18 +0900)
committerumorigu <umorigu@gmail.com>
Tue, 31 Oct 2017 20:18:53 +0000 (05:18 +0900)
Note that 'create_function' will be deprecated in PHP 7.2 .

lib/func.php
lib/html.php
lib/make_link.php
plugin/tracker.inc.php

index eecd2b9..fba35cf 100644 (file)
@@ -230,6 +230,13 @@ function auto_template($page)
        return $body;
 }
 
+function _mb_convert_kana__enable($str, $option) {
+       return mb_convert_kana($str, $option, SOURCE_ENCODING);
+}
+function _mb_convert_kana__none($str, $option) {
+       return $str;
+}
+
 // Expand all search-words to regexes and push them into an array
 function get_search_words($words = array(), $do_escape = FALSE)
 {
@@ -238,11 +245,9 @@ function get_search_words($words = array(), $do_escape = FALSE)
        if (! isset($init)) {
                // function: mb_convert_kana() is for Japanese code only
                if (LANG == 'ja' && function_exists('mb_convert_kana')) {
-                       $mb_convert_kana = create_function('$str, $option',
-                               'return mb_convert_kana($str, $option, SOURCE_ENCODING);');
+                       $mb_convert_kana = '_mb_convert_kana__enable';
                } else {
-                       $mb_convert_kana = create_function('$str, $option',
-                               'return $str;');
+                       $mb_convert_kana = '_mb_convert_kana__none';
                }
                if (SOURCE_ENCODING == 'EUC-JP') {
                        // Perl memo - Correct pattern-matching with EUC-JP
index 94fd070..1b3ae31 100644 (file)
@@ -166,28 +166,22 @@ function catbody($title, $page, $body)
                arsort($keys, SORT_NUMERIC);
                $keys = get_search_words(array_keys($keys), TRUE);
                $id = 0;
+               $patterns = '';
                foreach ($keys as $key=>$pattern) {
-                       $s_key    = htmlsc($key);
-                       $pattern  = '/' .
-                               '<textarea[^>]*>.*?<\/textarea>' .      // Ignore textareas
-                               '|' . '<[^>]*>' .                       // Ignore tags
-                               '|' . '&[^;]+;' .                       // Ignore entities
-                               '|' . '(' . $pattern . ')' .            // $matches[1]: Regex for a search word
-                               '/sS';
-                       $decorate_Nth_word = create_function(
-                               '$matches',
-                               'return (isset($matches[1])) ? ' .
-                                       '\'<strong class="word' .
-                                               $id .
-                                       '">\' . $matches[1] . \'</strong>\' : ' .
-                                       '$matches[0];'
-                       );
-                       $body  = preg_replace_callback($pattern, $decorate_Nth_word, $body);
-                       $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes);
-                       ++$id;
+                       if (strlen($patterns) > 0) {
+                               $patterns .= '|';
+                       }
+                       $patterns .= '(' . $pattern . ')';
                }
+               $whole_pattern  = '/' .
+                       '<textarea[^>]*>.*?<\/textarea>' .      // Ignore textareas
+                       '|' . '<[^>]*>' .                       // Ignore tags
+                       '|' . '&[^;]+;' .                       // Ignore entities
+                       '|' . '(' . $patterns . ')' .           // $matches[1]: Regex for a search word
+                       '/sS';
+               $body  = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $body);
+               $notes = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $notes);
        }
-
        // Embed Scripting data
        $html_scripting_data = get_html_scripting_data();
 
@@ -197,6 +191,26 @@ function catbody($title, $page, $body)
        require(SKIN_FILE);
 }
 
+function _decorate_Nth_word($matches)
+{
+       // $matches[0]: including both words to skip and to decorate
+       // $matches[1]: word to decorate
+       // $matches[2+]: indicates which keyword to decorate
+       $index = -1;
+       for ($i = 2; $i < count($matches); $i++) {
+               if (isset($matches[$i]) && $matches[$i]) {
+                       $index = $i - 2;
+                       break;
+               }
+       }
+       if (isset($matches[1])) {
+               // wordN highlight class: N=0...n
+               return '<strong class="word' . $index . '">' .
+                       $matches[0] . '</strong>';
+       }
+       return $matches[0];
+}
+
 /**
  * Get data used by JavaScript modules
  */
@@ -264,7 +278,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
        if ($digest === FALSE) $digest = md5(join('', get_source($page)));
 
        $refer = $template = '';
+
        // Add plugin
        $addtag = $add_top = '';
        if(isset($vars['add'])) {
@@ -441,6 +455,11 @@ function make_related($page, $tag = '')
        return $retval;
 }
 
+function _convert_line_rule_to_regex($a)
+{
+       return '/' . $a . '/';
+}
+
 // User-defined rules (convert without replacing source)
 function make_line_rules($str)
 {
@@ -448,8 +467,7 @@ function make_line_rules($str)
        static $pattern, $replace;
 
        if (! isset($pattern)) {
-               $pattern = array_map(create_function('$a',
-                       'return \'/\' . $a . \'/\';'), array_keys($line_rules));
+               $pattern = array_map('_convert_line_rule_to_regex', array_keys($line_rules));
                $replace = array_values($line_rules);
                unset($line_rules);
        }
index 5d07243..962a2ee 100644 (file)
@@ -30,16 +30,18 @@ class InlineConverter
        var $result;
 
        function get_clone($obj) {
-               static $clone_func;
-
-               if (! isset($clone_func)) {
+               static $clone_exists;
+               if (! isset($clone_exists)) {
                        if (version_compare(PHP_VERSION, '5.0.0', '<')) {
-                               $clone_func = create_function('$a', 'return $a;');
+                               $clone_exists = false;
                        } else {
-                               $clone_func = create_function('$a', 'return clone $a;');
+                               $clone_exists = true;
                        }
                }
-               return $clone_func($obj);
+               if ($clone_exists) {
+                       return clone ($obj);
+               }
+               return $obj;
        }
 
        function __clone() {
index 3c94911..bb9e34d 100644 (file)
@@ -402,6 +402,7 @@ class Tracker_field_textarea extends Tracker_field
                return $str;
        }
 }
+
 class Tracker_field_format extends Tracker_field
 {
        var $sort_type = SORT_STRING;
@@ -419,7 +420,7 @@ class Tracker_field_format extends Tracker_field
 
                foreach ($this->config->get($this->name) as $option)
                {
-                       list($key,$style,$format) = array_pad(array_map(create_function('$a','return trim($a);'),$option),3,'');
+                       list($key,$style,$format) = array_pad(array_map('trim',$option),3,'');
                        if ($style != '')
                        {
                                $this->styles[$key] = $style;
@@ -511,7 +512,8 @@ class Tracker_field_radio extends Tracker_field_format
                static $options = array();
                if (!array_key_exists($this->name,$options))
                {
-                       $options[$this->name] = array_flip(array_map(create_function('$arr','return $arr[0];'),$this->config->get($this->name)));
+                       // 'reset' means function($arr) { return $arr[0]; }
+                       $options[$this->name] = array_flip(array_map('reset',$this->config->get($this->name)));
                }
                return array_key_exists($value,$options[$this->name]) ? $options[$this->name][$value] : $value;
        }