diff --git a/app/Core/Func.php b/app/Core/Func.php index ea5986c22924e82adf168ec56e33a2b85dff3090..206a94d6269d46c159c42c102235ac216bf31167 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 a8be11d05d25293584b5567d35f4017bff513814..0dee763592029641c904864a2dfe9a24c01ed7db 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 0119f481993411acc4fb94e34f4450529905157a..ad68df939158712c320f0c580780eea7361aab5b 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 00f5ba7f3d5a402353866c8cb1285343fb0c6155..ca80244e53b5ff8c35039196e810a07d3584d971 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'];