Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8_en/decode deprecation #714

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/libraries/joomlatools/library/filter/ascii.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sanitize($value)

if ($result === null)
{
$result = htmlentities(utf8_decode($value), ENT_SUBSTITUTE);
$result = htmlentities(mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8'));
$result = preg_replace(
array('/ß/','/&(..)lig;/', '/&([aouAOU])uml;/','/&(.)[^;]*;/'),
array('ss',"$1","$1".'e',"$1"),
Expand Down
28 changes: 25 additions & 3 deletions code/libraries/joomlatools/library/legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
function mb_strlen($str)
{
return strlen(utf8_decode($str));
return strlen(mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8'));
}
}

Expand Down Expand Up @@ -61,7 +61,7 @@ function mb_substr($str, $offset, $length = NULL)
if ($offset < 0) {

// see notes
$strlen = strlen(utf8_decode($str));
$strlen = strlen(mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8'));
$offset = $strlen + $offset;
if ($offset < 0) $offset = 0;

Expand Down Expand Up @@ -100,7 +100,7 @@ function mb_substr($str, $offset, $length = NULL)

if (!isset($strlen)) {
// see notes
$strlen = strlen(utf8_decode($str));
$strlen = strlen(mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8'));
}

// another trivial case
Expand Down Expand Up @@ -401,3 +401,25 @@ function str_contains($haystack, $needle) {
}
}

/**
* utf8 encoding/decoding compatibility
*
* @link https://www.php.net/manual/en/function.utf8-decode.php
*/

if (!function_exists('utf8_decode'))
{
function utf8_decode($string)
{
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
}
}

if (!function_exists('utf8_encode'))
{
function utf8_encode($string)
{
return mb_convert_encoding($string, 'UTF-8', mb_detect_encoding($string));
}
}

Loading