improved utf8 conversion
This commit is contained in:
parent
130b5351f8
commit
83aa2246c7
@ -6,6 +6,7 @@ use ManiaControl\Callbacks\Callbacks;
|
|||||||
use ManiaControl\Files\FileUtil;
|
use ManiaControl\Files\FileUtil;
|
||||||
use ManiaControl\Plugins\PluginManager;
|
use ManiaControl\Plugins\PluginManager;
|
||||||
use ManiaControl\Update\UpdateManager;
|
use ManiaControl\Update\UpdateManager;
|
||||||
|
use ManiaControl\Utils\Formatter;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +112,7 @@ class ErrorHandler {
|
|||||||
// Report error
|
// Report error
|
||||||
$report = array();
|
$report = array();
|
||||||
$report['Type'] = 'Error';
|
$report['Type'] = 'Error';
|
||||||
$report['Message'] = $message;
|
$report['Message'] = Formatter::utf8($message);
|
||||||
if ($fileLine) {
|
if ($fileLine) {
|
||||||
$report['FileLine'] = $fileLine;
|
$report['FileLine'] = $fileLine;
|
||||||
}
|
}
|
||||||
@ -266,7 +267,7 @@ class ErrorHandler {
|
|||||||
$type = gettype($arg);
|
$type = gettype($arg);
|
||||||
$string .= $type . '(';
|
$string .= $type . '(';
|
||||||
if (is_string($arg)) {
|
if (is_string($arg)) {
|
||||||
$param = iconv('UTF-8', 'UTF-8//IGNORE', $arg);
|
$param = Formatter::utf8($arg);
|
||||||
if (strlen($param) > 20) {
|
if (strlen($param) > 20) {
|
||||||
$param = substr($param, 0, 20) . '..';
|
$param = substr($param, 0, 20) . '..';
|
||||||
}
|
}
|
||||||
|
@ -171,4 +171,23 @@ abstract class Formatter {
|
|||||||
$bool = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
$bool = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||||
return $bool;
|
return $bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure the given Text is encoded in UTF-8
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function utf8($text) {
|
||||||
|
if (!$text) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
$value = @iconv('UTF-8', 'UTF-8//IGNORE', $text);
|
||||||
|
if (!$value) {
|
||||||
|
// Prevent bugged iconv() of some systems
|
||||||
|
$text = preg_replace('/[^[:print:]]/', '', $text);
|
||||||
|
$value = iconv('UTF-8', 'UTF-8//IGNORE', $text);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user