1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00
Daniel 2021-10-13 10:18:26 -03:00
parent e9c180457a
commit 865a7a4d91
14 changed files with 113 additions and 70 deletions

View file

@ -320,7 +320,7 @@ class Layout extends PluginAbstract {
}else{
$selectedJsonIcon = '';
}
$code = "<script>function getLangSelectformatStateResult (state) {
$code = "<script>/*selected={$selected}*/function getLangSelectformatStateResult (state) {
if (!state.id) {
return state.text;
}

View file

@ -40,6 +40,10 @@ class User_Location extends PluginAbstract {
public function getEmptyDataObject() {
$obj = new stdClass();
$obj->autoChangeLanguage = true;
$o = new stdClass();
$o->type = array('browser'=>__("Detect language from Browser"), 'ip'=>__("Detect language from IP"));
$o->value = 'browser';
$obj->useLanguageFrom = $o;
return $obj;
}
@ -72,23 +76,61 @@ class User_Location extends PluginAbstract {
return IP2Location::getLocation($ip);
}
static function getLanguageFromBrowser() {
if(empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
return false;
}
$parts = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
return str_replace('-', '_', $parts[0]);
}
static function setLanguage($lang) {
global $global;
$file = "{$global['systemRootPath']}locale/{$lang}.php";
_session_start();
if(file_exists($file)){
$_SESSION['language'] = $lang;
include_once $file;
return true;
}else{
$lang = strtolower($lang);
$file = "{$global['systemRootPath']}locale/{$lang}.php";
if(file_exists($file)){
$_SESSION['language'] = $lang;
include_once $file;
return true;
}
}
return false;
}
static function setLanguageFromBrowser() {
return self::setLanguage(self::getLanguageFromBrowser());
}
static function setLanguageFromIP() {
$User_Location = self::getThisUserLocation();
return self::setLanguage($User_Location['country_code']);
}
public function getStart() {
global $global, $config;
$obj = $this->getDataObject();
$User_Location = self::getThisUserLocation();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if($obj->autoChangeLanguage){
$location = self::getSessionLocation();
if(empty($location) && !empty($User_Location['country_code'])){
$_SESSION['language'] = strtolower($User_Location['country_code']);
$file = "{$global['systemRootPath']}locale/{$_SESSION['language']}.php";
if(file_exists($file)){
include_once $file;
}else{
$_SESSION['language'] = $config->getLanguage();
if($obj->useLanguageFrom->value=='browser'){
$changed = self::setLanguageFromBrowser();
if(!$changed){
$changed = self::setLanguageFromIP();
}
}else{
$changed = self::setLanguageFromIP();
if(!$changed){
$changed = self::setLanguageFromBrowser();
}
}
if(!$changed){
$_SESSION['language'] = $config->getLanguage();
}
}
$global['User_Location'] = $User_Location;

View file

@ -2298,7 +2298,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"time": "2021-03-05T17:36:06+00:00",
"type": "library",
@ -3490,7 +3490,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"psr/log": "^1|^2|^3",
"symfony/deprecation-contracts": "^2.1",
"symfony/http-client-contracts": "^2.4",
@ -3580,7 +3580,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"suggest": {
"symfony/http-client-implementation": ""
@ -3661,7 +3661,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-mbstring": "~1.1",
"symfony/polyfill-php80": "^1.16"
@ -3737,7 +3737,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php73": "~1.0",
"symfony/polyfill-php80": "^1.16"
@ -4316,7 +4316,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.16"
},
@ -4409,7 +4409,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"psr/container": "^1.1"
},
"suggest": {
@ -4491,7 +4491,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16",
@ -4589,7 +4589,7 @@
"shasum": ""
},
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"suggest": {
"symfony/translation-implementation": ""

View file

@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"autoload": {
"psr-4": {

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"suggest": {
"symfony/http-client-implementation": ""

View file

@ -21,7 +21,7 @@
"symfony/http-client-implementation": "2.4"
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"psr/log": "^1|^2|^3",
"symfony/deprecation-contracts": "^2.1",
"symfony/http-client-contracts": "^2.4",

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-mbstring": "~1.1",
"symfony/polyfill-php80": "^1.16"

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php73": "~1.0",
"symfony/polyfill-php80": "^1.16"

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.16"
},

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"psr/container": "^1.1"
},
"suggest": {

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.3"
},
"suggest": {
"symfony/translation-implementation": ""

View file

@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=7.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16",

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View file

@ -546,6 +546,7 @@ if (!User::isLogged() && !empty($advancedCustomUser->userMustBeLoggedIn) && !emp
$lang = 'en_US';
}
echo Layout::getLangsSelect('navBarFlag', $lang, 'navBarFlag', '', true);
//var_dump($lang);exit;
?>
</div>