1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
Daniel Neto 2023-03-29 13:47:59 -03:00
parent ee87ab472f
commit be59a90c9c

View file

@ -7,15 +7,13 @@ if (!empty($_GET['lang'])) {
includeLangFile();
function includeLangFile()
{
function includeLangFile() {
global $t;
setSiteLang();
@include_once "{$global['systemRootPath']}locale/{$_SESSION['language']}.php";
}
function __($str, $allowHTML = false)
{
function __($str, $allowHTML = false) {
global $t, $t_insensitive;
if (!isset($t_insensitive)) {
if (is_array($t) && function_exists('array_change_key_case') && !isCommandLineInterface()) {
@ -38,8 +36,7 @@ function __($str, $allowHTML = false)
return str_replace(["'", '"', "<", '>'], ['&apos;', '&quot;', '&lt;', '&gt;'], $return);
}
function printJSString($str, $return = false)
{
function printJSString($str, $return = false) {
$text = json_encode(__($str), JSON_UNESCAPED_UNICODE);
if ($return) {
return $text;
@ -48,14 +45,12 @@ function printJSString($str, $return = false)
}
}
function isRTL()
{
function isRTL() {
global $t_isRTL;
return !empty($t_isRTL) && $t_isRTL;
}
function getAllFlags()
{
function getAllFlags() {
global $global;
$dir = "{$global['systemRootPath']}view/css/flag-icon-css-master/flags/4x3";
$flags = [];
@ -76,8 +71,7 @@ function getAllFlags()
* @global array $global
* @return array
*/
function getEnabledLangs()
{
function getEnabledLangs() {
global $global;
$dir = "{$global['systemRootPath']}locale";
$flags = [];
@ -96,8 +90,7 @@ function getEnabledLangs()
return $flags;
}
function textToLink($string, $targetBlank = false)
{
function textToLink($string, $targetBlank = false) {
$target = "";
if ($targetBlank) {
$target = "target=\"_blank\"";
@ -105,14 +98,12 @@ function textToLink($string, $targetBlank = false)
return preg_replace('$(\s|^)(https?://[a-z0-9_./?=&-]+)(?![^<>]*>)$i', ' <a href="$2" ' . $target . '>$2</a> ', $string);
}
function br2nl($html)
{
function br2nl($html) {
$nl = preg_replace(['#<br\s*/?>#i', '#<p\s*/?>#i', '#</p\s*>#i'], ["\n", "\n", ''], $html);
return $nl;
}
function flag2Lang($flagCode)
{
function flag2Lang($flagCode) {
global $global;
$index = strtolower($flagCode);
if (!empty($global['flag2Lang'][$index])) {
@ -121,8 +112,7 @@ function flag2Lang($flagCode)
return $flagCode;
}
function setSiteLang()
{
function setSiteLang() {
global $config, $global;
if (empty($global['systemRootPath'])) {
setLanguage('en_US');
@ -139,12 +129,12 @@ function setSiteLang()
User_Location::changeLang();
}
try {
if (empty($config) || !is_object($config)) {
require_once $global['systemRootPath'] . 'objects/configuration.php';
$config = new Configuration();
}
if (empty($config) || !is_object($config)) {
require_once $global['systemRootPath'] . 'objects/configuration.php';
$config = new Configuration();
}
} catch (Exception $exc) {
_error_log("setSiteLang systemRootPath=[{$global['systemRootPath']}] ".$exc->getMessage().' '. json_encode(debug_backtrace()));
_error_log("setSiteLang systemRootPath=[{$global['systemRootPath']}] " . $exc->getMessage() . ' ' . json_encode(debug_backtrace()));
}
if (empty($_SESSION['language']) && is_object($config)) {
@ -156,8 +146,7 @@ function setSiteLang()
}
}
function setLanguage($lang)
{
function setLanguage($lang) {
$lang = strip_tags($lang);
if (empty($lang)) {
return false;
@ -198,21 +187,18 @@ function setLanguage($lang)
return false;
}
function getLanguage()
{
function getLanguage() {
if (empty($_SESSION['language'])) {
return 'en_US';
}
return fixLangString($_SESSION['language']);
}
function fixLangString($lang)
{
function fixLangString($lang) {
return strtolower(str_replace('_', '-', $lang));
}
function revertLangString($lang)
{
function revertLangString($lang) {
$parts = explode('-', $lang);
$lang = strtolower($parts[0]);