Skip to content

Commit

Permalink
Remove check and conversions to utf8, as non-utf is not supported
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Sep 29, 2023
1 parent b5eb8c9 commit 2763f43
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/Application/Controller/MediaLangJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function init()

/** @var Utils $oUtils */
$oUtils = Registry::getUtils();
$sJson = $oUtils->encodeJson($languages->getLanguageStringsArray());
$sJson = json_encode($languages->getLanguageStringsArray());
$oUtils->showMessageAndExit(";( function(g){ g.i18n = " . $sJson . "; })(window);");
}
}
59 changes: 1 addition & 58 deletions src/Core/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,6 @@ class Utils extends Utils_parent
public function showJsonAndExit($mMsg = null)
{
header('Content-Type: application/json');
$this->showMessageAndExit($this->encodeJson($mMsg));
}


public function encodeJson($mMsg = null)
{
if (is_string($mMsg)) {
if (!$this->isUtfString($mMsg)) {
$mMsg = utf8_encode($mMsg);
}
} else {
// Typecast for Objects
if (is_object($mMsg)) {
$mMsg = (array)$mMsg;
}

$mMsg = $this->encodeUtf8Array($mMsg);
}

return json_encode($mMsg);
}


public function isUtfString($sString = '')
{
if (
is_string($sString)
&& (function_exists('mb_detect_encoding')
&& mb_detect_encoding($sString, 'UTF-8', true) !== false)
) {
return true;
}

return false;
}


protected function encodeUtf8Array($aArray)
{
$aRet = [];

foreach ($aArray as $sKey => $mValue) {
if (!$this->isUtfString($mValue)) {
$sKey = utf8_encode($sKey);
}

if (is_string($mValue)) {
if (!$this->isUtfString($mValue)) {
$mValue = utf8_encode($mValue);
}
} elseif (is_array($mValue)) {
$mValue = $this->encodeUtf8Array($mValue);
}

$aRet[$sKey] = $mValue;
}

return $aRet;
$this->showMessageAndExit(json_encode($mMsg));
}
}

0 comments on commit 2763f43

Please sign in to comment.