prevent possible errors if language files are broken

This commit is contained in:
Max Pozdeev 2022-04-15 21:29:59 +03:00
parent 2dc8a2213f
commit 82318c6df0
2 changed files with 11 additions and 2 deletions

View file

@ -60,6 +60,9 @@ class Lang
{
$this->code = $code;
$json = json_decode($jsonString, true);
if ($json === null) {
$json = array();
}
//load default language
if ( $code != $this->default ) {
@ -78,6 +81,9 @@ class Lang
}
$defStr = file_get_contents($this->langDir(). "{$this->default}.json");
$this->strings = json_decode($defStr, true);
if ($this->strings === null) {
die("Invalid JSON in default language file (". htmlspecialchars($this->default). ".json)");
}
}
function get($key)

View file

@ -114,6 +114,9 @@ function selectOptionsA($a, $key, $default=null)
$s = '';
if($default !== null && !isset($a[$key])) $key = $default;
foreach($a as $k=>$v) {
if (!is_array($v)) {
$v = array('name' => $k);
}
$s .= '<option value="'.htmlspecialchars($k).'" '.($k===$key?'selected="selected"':'').
(isset($v['title']) ? ' title="'.htmlspecialchars($v['title']).'"' : '').
'>'.htmlspecialchars($v['name']).'</option>';
@ -141,7 +144,7 @@ header('Content-type:text/html; charset=utf-8');
if (isset($_GET['json'])) {
$j = Config::requestDefaultDomain();
if ($j['password'] != '') $j['password'] = "<not empty>";
$j = json_encode($j, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
$j = json_encode($j, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE);
?>
<div class="mtt-settings-table">
<div class="tr">
@ -269,4 +272,4 @@ header('Content-type:text/html; charset=utf-8');
</div>
</form>
</form>