mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
This commit is contained in:
parent
58f6bf7da9
commit
b1a80a3edd
1 changed files with 53 additions and 36 deletions
|
@ -7,13 +7,15 @@ 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()) {
|
||||
|
@ -36,7 +38,8 @@ function __($str, $allowHTML = false) {
|
|||
return str_replace(["'", '"', "<", '>'], [''', '"', '<', '>'], $return);
|
||||
}
|
||||
|
||||
function printJSString($str, $return = false) {
|
||||
function printJSString($str, $return = false)
|
||||
{
|
||||
$text = json_encode(__($str), JSON_UNESCAPED_UNICODE);
|
||||
if ($return) {
|
||||
return $text;
|
||||
|
@ -45,12 +48,14 @@ 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 = [];
|
||||
|
@ -71,7 +76,8 @@ function getAllFlags() {
|
|||
* @global array $global
|
||||
* @return array
|
||||
*/
|
||||
function getEnabledLangs() {
|
||||
function getEnabledLangs()
|
||||
{
|
||||
global $global;
|
||||
$dir = "{$global['systemRootPath']}locale";
|
||||
$flags = [];
|
||||
|
@ -90,7 +96,8 @@ function getEnabledLangs() {
|
|||
return $flags;
|
||||
}
|
||||
|
||||
function textToLink($string, $targetBlank = false) {
|
||||
function textToLink($string, $targetBlank = false)
|
||||
{
|
||||
$target = "";
|
||||
if ($targetBlank) {
|
||||
$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);
|
||||
}
|
||||
|
||||
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])) {
|
||||
|
@ -112,35 +121,40 @@ function flag2Lang($flagCode) {
|
|||
return $flagCode;
|
||||
}
|
||||
|
||||
function setSiteLang() {
|
||||
function setSiteLang()
|
||||
{
|
||||
global $config, $global;
|
||||
|
||||
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'])) {
|
||||
if (empty($global['systemRootPath'])) {
|
||||
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);
|
||||
if (empty($lang)) {
|
||||
return false;
|
||||
|
@ -181,18 +195,21 @@ 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]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue