Revert "Multi-language support"

This reverts commit 83d4a10d2b.
This commit is contained in:
bergware
2020-05-15 12:41:12 +02:00
parent 83d4a10d2b
commit 761009df70

View File

@@ -15,38 +15,32 @@ session_start();
session_write_close();
function _($text) {
// PHP translation function _
global $language;
if (!$text) return '';
$a = '/\&amp;|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"\']|<.+?\/?>/';
$b = '/^(null|yes|no|true|false|on|off|none)$/i';
$c = '/ +/';
$data = $language[preg_replace([$a,$b,$c],['','$1.',' '],$text)] ?? $text;
$data = $language[preg_replace(['/\&amp;|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"\']|<.+?\/?>/','/^(null|yes|no|true|false|on|off|none)$/i','/ +/'],['','$1.',' '],$text)] ?? $text;
return strpos($data,'*')===false ? $data : preg_replace(['/\*\*(.+?)\*\*/','/\*(.+?)\*/'],['<b>$1</b>','<i>$1</i>'],$data);
}
function parse_lang_file($file) {
$a = '/^(null|yes|no|true|false|on|off|none)=/mi';
$b = '/^([^>].*)=(.*)$/m';
$c = '/^:(.+_(help|plug)):$/m';
$d = '/^:end$/m';
return shield(parse_ini_string(preg_replace([$a,$b,$c,$d],['$1.=','$1="$2"','_$1_="','"'],escapeQuotes(file_get_contents($file)))));
// parser for translation files, includes some trickery to handle PHP quirks.
return array_filter(parse_ini_string(preg_replace(['/^(null|yes|no|true|false|on|off|none)=/mi','/^([^>].*)=(.*)$/m','/^:(.+_(help|plug)):$/m','/^:end$/m'],['$1.=','$1="$2"','_$1_="','"'],str_replace(["\"\n",'"'],["\" \n",'\"'],file_get_contents($file)))),'secured',ARRAY_FILTER_USE_BOTH);
}
function parse_help_file($file) {
$a = '/^$/m';
$b = '/^([^:;].+)$/m';
$c = '/^:(.+_help):$/m';
$d = '/^:end$/m';
return shield(parse_ini_string(preg_replace([$a,$b,$c,$d],['>','>$1','_$1_="','"'],escapeQuotes(file_get_contents($file)))));
// parser for help text files (multi-line sections), includes some trickery to handle PHP quirks.
return parse_ini_string(preg_replace(['/^$/m','/^([^:;].+)$/m','/^:(.+_help):$/m','/^:end$/m'],['>','>$1','_$1_="','"'],str_replace(["\"\n",'"'],["\" \n",'\"'],file_get_contents($file))));
}
function parse_text($text) {
$a = "/^:(.+_help):$/m";
$b = "/^:(.+_plug):$/m";
$c = "/^:end$/m";
$d = '/_\((.+?)\)_/m';
return preg_replace_callback($d,function($m){return _($m[1]);},preg_replace([$a,$b,$c],["<?translate(\"_$1_\");?>","<?if (translate(\"_$1_\")):?>","<?endif;?>"],$text));
// inline text parser
return preg_replace_callback('/_\((.+?)\)_/m',function($m){return _($m[1]);},preg_replace(["/^:(.+_help):$/m","/^:(.+_plug):$/m","/^:end$/m"],["<?translate(\"_$1_\");?>","<?if (translate(\"_$1_\")):?>","<?endif;?>"],$text));
}
function parse_file($file,$markdown=true) {
// replacement of PHP include function
return $markdown ? Markdown(parse_text(file_get_contents($file))) : parse_text(file_get_contents($file));
}
function parse_array($text,&$array) {
// multi keyword parser
parse_str(str_replace([' ',':'],['&','='],$text),$array);
}
function my_lang($text,$do=0) {
global $language;
switch ($do) {
@@ -72,24 +66,16 @@ function my_lang($text,$do=0) {
}
return $text;
}
// internal helper functions
function parse_array($text,&$array) {
parse_str(str_replace([' ',':'],['&','='],$text),$array);
}
function escapeQuotes($text) {
return str_replace(["\"\n",'"'],["\" \n",'\"'],$text);
}
function shield($array) {
$shield = '#<(script|iframe)(.*?)>(.+?)</(script|iframe)>|<(link|meta)\s(.+?)/?>#is';
return array_filter($array,function($v,$k){return strlen($v) && !preg_match($shield,html_entity_decode($v));},ARRAY_FILTER_USE_BOTH);
function secured($v,$k) {
// remove potential dangerous tags
return strlen($v) && !preg_match('#<(script|iframe)(.*?)>(.+?)</(script|iframe)>|<(link|meta)\s(.+?)/?>#is',html_entity_decode($v));
}
function translate($key) {
// replaces multi-line sections
global $language;
if ($plug = isset($language[$key])) eval('?>'.Markdown($language[$key]));
return !$plug;
}
// main
$language = [];
$locale = $_SESSION['locale'];
$return = "function _(t){return t;}";