Skip to content

Commit

Permalink
Fix several PHP8 deprecated issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sama34 committed Jun 13, 2024
1 parent cff261e commit 5328c92
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion boards/bbpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion boards/ipb3/polls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
6 changes: 4 additions & 2 deletions boards/vbulletin3/privatemessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions boards/vbulletin4/privatemessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions boards/vbulletin5/privatemessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions loginconvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5328c92

Please sign in to comment.