1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00
Daniel Neto 2023-03-24 10:48:06 -03:00
parent 58f6bf7da9
commit b1a80a3edd

View file

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