diff --git a/app/Core/Func.php b/app/Core/Func.php index ea5986c2..206a94d6 100644 --- a/app/Core/Func.php +++ b/app/Core/Func.php @@ -173,7 +173,7 @@ class Func * * @return array */ - public function langParse($str) + public function langParse($str) { $result = []; @@ -196,7 +196,8 @@ class Func $result[$l] = $q; } + \arsort($result, \SORT_NUMERIC); - return \array_keys(\arsort($result, \SORT_NUMERIC)); + return \array_keys($result); } } diff --git a/app/Models/Pages/Install.php b/app/Models/Pages/Install.php index a8be11d0..0dee7635 100644 --- a/app/Models/Pages/Install.php +++ b/app/Models/Pages/Install.php @@ -896,8 +896,8 @@ class Install extends Page 'dst' => ['TINYINT(1)', false, 0], 'time_format' => ['TINYINT(1)', false, 0], 'date_format' => ['TINYINT(1)', false, 0], - 'language' => ['VARCHAR(25)', false, $v->defaultlang], - 'style' => ['VARCHAR(25)', false, $v->defaultstyle], + 'language' => ['VARCHAR(25)', false, ''], + 'style' => ['VARCHAR(25)', false, ''], 'num_posts' => ['INT(10) UNSIGNED', false, 0], 'last_post' => ['INT(10) UNSIGNED', true], 'last_search' => ['INT(10) UNSIGNED', true], diff --git a/app/Models/User/Current.php b/app/Models/User/Current.php index 0119f481..ad68df93 100644 --- a/app/Models/User/Current.php +++ b/app/Models/User/Current.php @@ -39,6 +39,7 @@ class Current extends Action $user->__dst = $this->c->config->o_default_dst; # $user->language = $this->c->config->o_default_lang; # $user->style = $this->c->config->o_default_style; + $user->__language = $this->getLangFromHTTP(); // быстрое переключение языка - Visman /* $language = $this->cookie->get('glang'); @@ -247,4 +248,27 @@ class Current extends Action } return $agent; } + + /** + * Возвращает имеющийся в наличии язык из HTTP_ACCEPT_LANGUAGE + * или язык по умолчанию + * + * @return string + */ + protected function getLangFromHTTP() + { + if (! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $langs = $this->c->Func->getLangs(); + foreach ($this->c->Func->langParse($_SERVER['HTTP_ACCEPT_LANGUAGE']) as $entry) { + $arr = \explode('-', $entry); + if (isset($arr[1])) { + $entry = $arr[0] . '_' . \strtoupper($arr[1]); + } + if (isset($langs[$entry])) { + return $langs[$entry]; + } + } + } + return $this->c->config->o_default_lang; + } } diff --git a/app/Models/User/Model.php b/app/Models/User/Model.php index 00f5ba7f..ca80244e 100644 --- a/app/Models/User/Model.php +++ b/app/Models/User/Model.php @@ -111,7 +111,7 @@ class Model extends DataModel { $langs = $this->c->Func->getLangs(); - $lang = $this->isGuest || empty($this->a['language']) || ! isset($langs[$this->a['language']]) + $lang = empty($this->a['language']) || ! isset($langs[$this->a['language']]) ? $this->c->config->o_default_lang : $this->a['language'];