OSDN Git Service

BugTrack/2514 Support PHP 8
authorumorigu <umorigu@gmail.com>
Sat, 13 Mar 2021 06:14:30 +0000 (15:14 +0900)
committerumorigu <umorigu@gmail.com>
Sat, 13 Mar 2021 06:14:30 +0000 (15:14 +0900)
PHP8 - Backward Incompatible Changes

* Support for deprecated curly braces for offset access has been removed
* Fatal error: Inheritance errors due to incompatible method signatures
* get_magic_quotes_gpc() have been removed
* Fatal error: Undefined constant ( `is_page` )
* Nested ternaries now require explicit parentheses

lib/config.php
lib/convert_html.php
lib/file.php
lib/func.php
lib/make_link.php
lib/plugin.php
lib/proxy.php
plugin/dump.inc.php
plugin/tracker.inc.php

index b3eeb1a..ec6dc7c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
 // config.php
-// Copyright 2003-2016 PukiWiki Development Team
+// Copyright 2003-2021 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // Parse a PukiWiki page as a configuration page
@@ -49,7 +49,7 @@ class Config
                foreach (get_source($this->page) as $line) {
                        if ($line == '') continue;
 
-                       $head  = $line{0};      // The first letter
+                       $head  = $line[0];      // The first letter
                        $level = strspn($line, $head);
 
                        if ($level > 3) {
index 0f4c42b..1690251 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone
 // convert_html.php
 // Copyright
-//   2002-2016 PukiWiki Development Team
+//   2002-2021 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -64,7 +64,7 @@ class Element
                return $this->last = & $obj->last;
        }
 
-       function canContain($obj)
+       function canContain($obj)
        {
                return TRUE;
        }
@@ -186,7 +186,7 @@ class Inline extends Element
                return $this;
        }
 
-       function canContain($obj)
+       function canContain($obj)
        {
                return is_a($obj, 'Inline');
        }
@@ -226,7 +226,7 @@ class Paragraph extends Element
                $this->insert(Factory_Inline($text));
        }
 
-       function canContain($obj)
+       function canContain($obj)
        {
                return is_a($obj, 'Inline');
        }
@@ -531,7 +531,7 @@ class TableCell extends Element
                                $name = $matches[2] ? 'background-color' : 'color';
                                $this->style[$name] = $name . ':' . htmlsc($matches[3]) . ';';
                                $text = $matches[5];
-                       } else if ($matches[4]) {
+                       } else if (isset($matches[4])) {
                                $this->style['size'] = 'font-size:' . htmlsc($matches[4]) . 'px;';
                                $text = $matches[5];
                        }
@@ -548,7 +548,7 @@ class TableCell extends Element
                        $text      = substr($text, 1);
                }
 
-               if ($text != '' && $text{0} == '#') {
+               if ($text != '' && $text[0] == '#') {
                        // Try using Div class for this $text
                        $obj = & Factory_Div($this, $text);
                        if (is_a($obj, 'Paragraph'))
@@ -788,7 +788,7 @@ class Pre extends Element
                global $preformat_ltrim;
                parent::__construct();
                $this->elements[] = htmlsc(
-                       (! $preformat_ltrim || $text == '' || $text{0} != ' ') ? $text : substr($text, 1));
+                       (! $preformat_ltrim || $text == '' || $text[0] != ' ') ? $text : substr($text, 1));
        }
 
        function canContain(& $obj)
@@ -941,7 +941,7 @@ class Body extends Element
                        }
 
                        // The first character
-                       $head = $line{0};
+                       $head = $line[0];
 
                        // Heading
                        if ($head == '*') {
index 9d9a29e..9600cd6 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // file.php
 // Copyright
-//   2002-2020 PukiWiki Development Team
+//   2002-2021 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -160,7 +160,7 @@ function make_str_rules($source)
                $line = & $lines[$i]; // Modify directly
 
                // Ignore null string and preformatted texts
-               if ($line == '' || $line{0} == ' ' || $line{0} == "\t") continue;
+               if ($line == '' || $line[0] == ' ' || $line[0] == "\t") continue;
 
                // Modify this line?
                if ($modify) {
index 333e32c..22c7c75 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // func.php
 // Copyright
-//   2002-2020 PukiWiki Development Team
+//   2002-2021 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -1039,9 +1039,14 @@ function guess_script_absolute_uri()
 function input_filter($param)
 {
        static $magic_quotes_gpc = NULL;
-       if ($magic_quotes_gpc === NULL)
-           $magic_quotes_gpc = get_magic_quotes_gpc();
-
+       if ($magic_quotes_gpc === NULL) {
+               if (function_exists('get_magic_quotes_gpc')) {
+                       // No 'get_magic_quotes_gpc' function in PHP8
+                       $magic_quotes_gpc = get_magic_quotes_gpc();
+               } else {
+                       $magic_quotes_gpc = 0;
+               }
+       }
        if (is_array($param)) {
                return array_map('input_filter', $param);
        } else {
@@ -1068,7 +1073,7 @@ function csv_explode($separator, $string)
 
        foreach ($matches[1] as $str) {
                $len = strlen($str);
-               if ($len > 1 && $str{0} == '"' && $str{$len - 1} == '"')
+               if ($len > 1 && $str[0] == '"' && $str[$len - 1] == '"')
                        $str = str_replace('""', '"', substr($str, 1, -1));
                $retval[] = $str;
        }
@@ -1078,7 +1083,7 @@ function csv_explode($separator, $string)
 // Implode an array with CSV data format (escape double quotes)
 function csv_implode($glue, $pieces)
 {
-       $_glue = ($glue != '') ? '\\' . $glue{0} : '';
+       $_glue = ($glue != '') ? '\\' . $glue[0] : '';
        $arr = array();
        foreach ($pieces as $str) {
                if (preg_match('/[' . '"' . "\n\r" . $_glue . ']/', $str))
index 73ade5f..d8bf67f 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // make_link.php
 // Copyright
-//   2003-2020 PukiWiki Development Team
+//   2003-2021 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -851,8 +851,9 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
 
        $page_filetime = fast_get_filetime($page);
        $is_page = $page_filetime !== 0;
-       if (! isset($related[$page]) && $page !== $vars['page'] && is_page)
+       if (! isset($related[$page]) && $page !== $vars['page'] && $is_page) {
                $related[$page] = $page_filetime;
+       }
 
        if ($isautolink || $is_page) {
                // Hyperlink to the page
@@ -905,7 +906,7 @@ function get_fullname($name, $refer)
        if ($name == '' || $name == './') return $refer;
 
        // Absolute path
-       if ($name{0} == '/') {
+       if ($name[0] == '/') {
                $name = substr($name, 1);
                return ($name == '') ? $defaultpage : $name;
        }
@@ -1024,7 +1025,7 @@ function get_ticketlink_jira_projects()
                } else if (preg_match('/^--\s*([A-Z][A-Z0-9]{1,10}(?:_[A-Z0-9]{1,10}){0,2})(\s+(.+?))?\s*$/', $line, $m)) {
                        if ($active_jira_base_url) {
                                $project_key = $m[1];
-                               $title = $m[2];
+                               $title = isset($m[2]) ? $m[2] : '';
                                array_push($jira_projects, array(
                                        'key' => $m[1],
                                        'title' => $title,
index 2980438..1bfcc3d 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // plugin.php
 // Copyright
-//   2002-2016 PukiWiki Development Team
+//   2002-2021 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -51,20 +51,35 @@ function exist_plugin($name)
 
 // Check if plugin API 'action' exists
 function exist_plugin_action($name) {
-       return  function_exists('plugin_' . $name . '_action') ? TRUE : exist_plugin($name) ?
-               function_exists('plugin_' . $name . '_action') : FALSE;
+       if (function_exists('plugin_' . $name . '_action')) {
+               return TRUE;
+       }
+       if (exist_plugin($name)) {
+               return function_exists('plugin_' . $name . '_action');
+       }
+       return FALSE;
 }
 
 // Check if plugin API 'convert' exists
 function exist_plugin_convert($name) {
-       return  function_exists('plugin_' . $name . '_convert') ? TRUE : exist_plugin($name) ?
-               function_exists('plugin_' . $name . '_convert') : FALSE;
+       if (function_exists('plugin_' . $name . '_convert')) {
+               return TRUE;
+       }
+       if (exist_plugin($name)) {
+               return function_exists('plugin_' . $name . '_convert');
+       }
+       return FALSE;
 }
 
 // Check if plugin API 'inline' exists
 function exist_plugin_inline($name) {
-       return  function_exists('plugin_' . $name . '_inline') ? TRUE : exist_plugin($name) ?
-               function_exists('plugin_' . $name . '_inline') : FALSE;
+       if (function_exists('plugin_' . $name . '_inline')) {
+               return TRUE;
+       }
+       if (exist_plugin($name)) {
+               return function_exists('plugin_' . $name . '_inline');
+       }
+       return FALSE;
 }
 
 // Call 'init' function for the plugin
index 94cfdd2..d090aa3 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
 // proxy.php
-// Copyright: 2003-2017 PukiWiki Development Team
+// Copyright: 2003-2021 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // HTTP-Proxy related functions
@@ -130,7 +130,7 @@ function pkwk_http_request($url, $method = 'GET', $headers = '', $post = array()
                        $url = trim($matches[1]);
                        if (! preg_match('/^https?:\//', $url)) {
                                // Relative path to Absolute
-                               if ($url{0} != '/')
+                               if ($url[0] != '/')
                                        $url = substr($url_path, 0, strrpos($url_path, '/')) . '/' . $url;
                                $url = $url_base . $url; // Add sheme, host
                        }
index 946fca8..46c4f37 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone
 // dump.inc.php
 // Copyright
-//   2004-2017 PukiWiki Development Team
+//   2004-2021 PukiWiki Development Team
 //   2004      teanan / Interfair Laboratory
 // License: GPL v2 or (at your option) any later version
 //
@@ -488,7 +488,7 @@ class tarlib
                // ファイル名を保存
                for($i = 0; $i < strlen($filename); $i++ ) {
                        if ($i < TARLIB_HDR_NAME_LEN) {
-                               $tar_data[$i + TARLIB_HDR_NAME_OFFSET] = $filename{$i};
+                               $tar_data[$i + TARLIB_HDR_NAME_OFFSET] = $filename[$i];
                        } else {
                                break;  // ファイル名が長すぎ
                        }
@@ -497,32 +497,32 @@ class tarlib
                // mode
                $modeid = TARLIB_DATA_MODE;
                for($i = 0; $i < strlen($modeid); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_MODE_OFFSET] = $modeid{$i};
+                       $tar_data[$i + TARLIB_HDR_MODE_OFFSET] = $modeid[$i];
                }
 
                // uid / gid
                $ugid = TARLIB_DATA_UGID;
                for($i = 0; $i < strlen($ugid); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_UID_OFFSET] = $ugid{$i};
-                       $tar_data[$i + TARLIB_HDR_GID_OFFSET] = $ugid{$i};
+                       $tar_data[$i + TARLIB_HDR_UID_OFFSET] = $ugid[$i];
+                       $tar_data[$i + TARLIB_HDR_GID_OFFSET] = $ugid[$i];
                }
 
                // サイズ
                $strsize = sprintf('%11o', $size);
                for($i = 0; $i < strlen($strsize); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_SIZE_OFFSET] = $strsize{$i};
+                       $tar_data[$i + TARLIB_HDR_SIZE_OFFSET] = $strsize[$i];
                }
 
                // 最終更新時刻
                $strmtime = sprintf('%o', $mtime);
                for($i = 0; $i < strlen($strmtime); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_MTIME_OFFSET] = $strmtime{$i};
+                       $tar_data[$i + TARLIB_HDR_MTIME_OFFSET] = $strmtime[$i];
                }
 
                // チェックサム計算用のブランクを設定
                $chkblanks = TARLIB_DATA_CHKBLANKS;
                for($i = 0; $i < strlen($chkblanks); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_CHKSUM_OFFSET] = $chkblanks{$i};
+                       $tar_data[$i + TARLIB_HDR_CHKSUM_OFFSET] = $chkblanks[$i];
                }
 
                // タイプフラグ
@@ -535,7 +535,7 @@ class tarlib
                }
                $strchksum = sprintf('%7o',$sum);
                for($i = 0; $i < strlen($strchksum); $i++ ) {
-                       $tar_data[$i + TARLIB_HDR_CHKSUM_OFFSET] = $strchksum{$i};
+                       $tar_data[$i + TARLIB_HDR_CHKSUM_OFFSET] = $strchksum[$i];
                }
 
                return $tar_data;
@@ -615,8 +615,8 @@ class tarlib
                                $longname = '';
                        } else {
                                for ($i = 0; $i < TARLIB_HDR_NAME_LEN; $i++ ) {
-                                       if ($buff{$i + TARLIB_HDR_NAME_OFFSET} != "\0") {
-                                               $name .= $buff{$i + TARLIB_HDR_NAME_OFFSET};
+                                       if ($buff[$i + TARLIB_HDR_NAME_OFFSET] != "\0") {
+                                               $name .= $buff[$i + TARLIB_HDR_NAME_OFFSET];
                                        } else {
                                                break;
                                        }
@@ -630,22 +630,22 @@ class tarlib
                        $checksum = '';
                        $chkblanks = TARLIB_DATA_CHKBLANKS;
                        for ($i = 0; $i < TARLIB_HDR_CHKSUM_LEN; $i++ ) {
-                               $checksum .= $buff{$i + TARLIB_HDR_CHKSUM_OFFSET};
-                               $buff{$i + TARLIB_HDR_CHKSUM_OFFSET} = $chkblanks{$i};
+                               $checksum .= $buff[$i + TARLIB_HDR_CHKSUM_OFFSET];
+                               $buff[$i + TARLIB_HDR_CHKSUM_OFFSET] = $chkblanks[$i];
                        }
                        list($checksum) = sscanf('0' . trim($checksum), '%i');
 
                        // Compute checksum
                        $sum = 0;
                        for($i = 0; $i < TARLIB_BLK_LEN; $i++ ) {
-                               $sum += 0xff & ord($buff{$i});
+                               $sum += 0xff & ord($buff[$i]);
                        }
                        if ($sum != $checksum) break; // Error
                                
                        // Size
                        $size = '';
                        for ($i = 0; $i < TARLIB_HDR_SIZE_LEN; $i++ ) {
-                               $size .= $buff{$i + TARLIB_HDR_SIZE_OFFSET};
+                               $size .= $buff[$i + TARLIB_HDR_SIZE_OFFSET];
                        }
                        list($size) = sscanf('0' . trim($size), '%i');
 
@@ -656,12 +656,12 @@ class tarlib
                        // 最終更新時刻
                        $strmtime = '';
                        for ($i = 0; $i < TARLIB_HDR_MTIME_LEN; $i++ ) {
-                               $strmtime .= $buff{$i + TARLIB_HDR_MTIME_OFFSET};
+                               $strmtime .= $buff[$i + TARLIB_HDR_MTIME_OFFSET];
                        }
                        list($mtime) = sscanf('0' . trim($strmtime), '%i');
 
                        // タイプフラグ
-//                      $type = $buff{TARLIB_HDR_TYPE_OFFSET};
+//                      $type = $buff[TARLIB_HDR_TYPE_OFFSET];
 
                        if ($name == TARLIB_DATA_LONGLINK) {
                                // LongLink
index ff67599..9b1cd10 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
 // tracker.inc.php
-// Copyright 2003-2020 PukiWiki Development Team
+// Copyright 2003-2021 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // Issue tracker plugin (See Also bugtrack plugin)
@@ -1236,7 +1236,7 @@ class Tracker_list
                                        // Ignore empty line
                                        continue;
                                }
-                               $this->pipe = ($line{0} == '|' or $line{0} == ':');
+                               $this->pipe = ($line[0] == '|' or $line[0] == ':');
                                $source .= preg_replace_callback('/\[([^\[\]]+)\]/',array(&$this,'replace_item'),$line);
                        }
                }