From 5328c92edf2fabbfa71ed2c3eadfe66f12efab8d Mon Sep 17 00:00:00 2001 From: Sama34 Date: Thu, 13 Jun 2024 00:14:42 -0700 Subject: [PATCH] Fix several PHP8 deprecated issues --- boards/bbpress.php | 2 +- boards/ipb3/polls.php | 2 +- boards/vbulletin3/privatemessages.php | 6 ++++-- boards/vbulletin4/privatemessages.php | 6 ++++-- boards/vbulletin5/privatemessages.php | 6 ++++-- loginconvert.php | 12 ++++++++++-- resources/functions.php | 12 ++++++++---- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/boards/bbpress.php b/boards/bbpress.php index 8fc9de3..56cbcdf 100644 --- a/boards/bbpress.php +++ b/boards/bbpress.php @@ -97,7 +97,7 @@ class BBPRESS_Converter extends Converter * @param string $gids A serialized list of original roles * @return string group id(s) */ - function get_group_id($gids) + function get_group_id($gids, $remove=array()) { // bbPress saves roles as ["name" => true] $roles = array_keys(unserialize($gids)); diff --git a/boards/ipb3/polls.php b/boards/ipb3/polls.php index 633d8f7..7c81e39 100644 --- a/boards/ipb3/polls.php +++ b/boards/ipb3/polls.php @@ -44,7 +44,7 @@ function convert_data($data) $insert_data['import_tid'] = $data['tid']; $insert_data['import_pid'] = $data['pid']; $insert_data['tid'] = $this->get_import->tid($data['tid']); - $choices = unserialize(utf8_decode($data['choices'])); + $choices = unserialize(mb_convert_encoding($data['choices'], 'ISO-8859-1', 'UTF-8')); $choices = $choices[1]; $seperator = ''; diff --git a/boards/vbulletin3/privatemessages.php b/boards/vbulletin3/privatemessages.php index fad704c..ff897f6 100644 --- a/boards/vbulletin3/privatemessages.php +++ b/boards/vbulletin3/privatemessages.php @@ -60,8 +60,10 @@ function convert_data($data) // However afterwards we need to properly encode all elements again, otherwise we'd get other issues again if(!is_array($touserarray)) { - $touserarray = unserialize(utf8_decode($data['touserarray'])); - array_walk_recursive($touserarray, create_function('&$value, $key', '$value = utf8_encode($value);')); + $touserarray = unserialize(mb_convert_encoding($data['touserarray'], 'ISO-8859-1', 'UTF-8')); + array_walk_recursive($touserarray, function (&$value, &$key) { + $value = mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1'); + }); } // This is the original check in vB diff --git a/boards/vbulletin4/privatemessages.php b/boards/vbulletin4/privatemessages.php index c48e90b..2ff214d 100644 --- a/boards/vbulletin4/privatemessages.php +++ b/boards/vbulletin4/privatemessages.php @@ -60,8 +60,10 @@ function convert_data($data) // However afterwards we need to properly encode all elements again, otherwise we'd get other issues again if(!is_array($touserarray)) { - $touserarray = unserialize(utf8_decode($data['touserarray'])); - array_walk_recursive($touserarray, create_function('&$value, $key', '$value = utf8_encode($value);')); + $touserarray = unserialize(mb_convert_encoding($data['touserarray'], 'ISO-8859-1', 'UTF-8')); + array_walk_recursive($touserarray, function (&$value, &$key) { + $value = mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1'); + }); } // This is the original check in vB diff --git a/boards/vbulletin5/privatemessages.php b/boards/vbulletin5/privatemessages.php index 6757aa5..5a22ddb 100644 --- a/boards/vbulletin5/privatemessages.php +++ b/boards/vbulletin5/privatemessages.php @@ -60,8 +60,10 @@ function convert_data($data) // However afterwards we need to properly encode all elements again, otherwise we'd get other issues again if(!is_array($touserarray)) { - $touserarray = unserialize(utf8_decode($data['touserarray'])); - array_walk_recursive($touserarray, create_function('&$value, $key', '$value = utf8_encode($value);')); + $touserarray = unserialize(mb_convert_encoding($data['touserarray'], 'ISO-8859-1', 'UTF-8')); + array_walk_recursive($touserarray, function (&$value, &$key) { + $value = mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1'); + }); } // This is the original check in vB diff --git a/loginconvert.php b/loginconvert.php index aa58bdb..40994e8 100644 --- a/loginconvert.php +++ b/loginconvert.php @@ -160,9 +160,12 @@ function loginconvert_convert(&$login) $check = $function($login->data['password'], $user); // If the password was wrong, an utf8 password and we want to check utf8 passwords we call the function again - if(!$check && in_array($login_type, $utf8_recheck) && utf8_decode($login->data['password']) != $login->data['password']) + if(!$check && in_array($login_type, $utf8_recheck) && mb_convert_encoding( + $login->data['password'], + 'ISO-8859-1', + 'UTF-8') !== $login->data['password']) { - $check = $function(utf8_decode($login->data['password']), $user); + $check = $function(mb_convert_encoding($login->data['password'], 'ISO-8859-1', 'UTF-8'), $user); } if(!$check) @@ -331,6 +334,11 @@ function check_punbb($password, $user) { return true; } + elseif(function_exists('hash') && $is_sha1 && (hash('sha1', $password) === $user['passwordconvert'] || hash('sha1', $user['passwordconvertsalt'].hash('sha1', $password)) === $user['passwordconvert'])) + { + return true; + } + // mhash() is deprecated as of PHP8.1 elseif(function_exists('mhash') && $is_sha1 && (bin2hex(mhash(MHASH_SHA1, $password)) == $user['passwordconvert'] || bin2hex(mhash(MHASH_SHA1, $user['passwordconvertsalt'].bin2hex(mhash(MHASH_SHA1, $password)))) == $user['passwordconvert'])) { return true; diff --git a/resources/functions.php b/resources/functions.php index 6a3a83c..a7b805e 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -459,12 +459,12 @@ function encode_to_utf8($text, $old_table_name, $new_table_name) { if(!function_exists('iconv')) { - if(fetch_iconv_encoding($import_session['table_charset_old'][$old_table_name]) != 'iso-8859-1' || !function_exists("utf8_encode")) + if(fetch_iconv_encoding($import_session['table_charset_old'][$old_table_name]) != 'iso-8859-1' || !function_exists("mb_convert_encoding")) { return $text; } - return utf8_encode($text); + return mb_convert_encoding($text, 'UTF-8', 'ISO-8859-1'); } $converted_str = iconv(fetch_iconv_encoding($import_session['table_charset_old'][$old_table_name]), fetch_iconv_encoding($import_session['table_charset_new'][$new_table_name]).'//TRANSLIT', $text); @@ -781,8 +781,12 @@ function htmlspecialchars_decode($text) function utf8_unhtmlentities($string) { // Replace numeric entities - $string = preg_replace_callback('~&#x([0-9a-f]+);~i', create_function('$matches', 'return unichr(hexdec($matches[1]));'), $string); - $string = preg_replace_callback('~&#([0-9]+);~', create_function('$matches', 'return unichr($matches[1]);'), $string); + $string = preg_replace_callback('~&#x([0-9a-f]+);~i', function($matches) { + return unichr(hexdec($matches[1])); + }, $string); + $string = preg_replace_callback('~&#([0-9]+);~', function($matches) { + return unichr($matches[1]); + }, $string); // Replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES);