Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover a missing language correctly via the cookie #6371

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ public function parseRule(&$router, &$uri)
// Lets find the default language for this user
if (!isset($lang_code) || !isset($this->lang_codes[$lang_code]))
{
$lang_code = false;
if ($this->params->get('detect_browser', 1))
// Either we detected the language via the browser or we got it from the cookie. In worst case
// we fall back to the application setting
$lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'), false);

if (!$lang_code && $this->params->get('detect_browser', 1))
{
$lang_code = JLanguageHelper::detectLanguage();
if (!isset($this->lang_codes[$lang_code]))
Expand All @@ -323,9 +326,6 @@ public function parseRule(&$router, &$uri)
{
$lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
}
// Either we detected the language via the browser or we got it from the cookie. In worst case
// we fall back to the application setting
$lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'), $lang_code);
}

if ($this->mode_sef)
Expand Down Expand Up @@ -377,7 +377,7 @@ public function parseRule(&$router, &$uri)
if ($this->app->input->cookie->getString(JApplicationHelper::getHash('language')) != $lang_code)
{
$cookie_domain = $this->app->get('cookie_domain');
$cookie_path = $this->app->get('cookie_path', $uri->base(true));
$cookie_path = $this->app->get('cookie_path', ($uri->base(true) == '' ? '/' : $uri->base(true)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to do this calculations for the cookie_path? In all other instances where we are setting a cookie within Joomla, we just default to /, which will work for the most sites anyway.
The only place it may not work is if you have www.example.com/one_joomla and www.example.com/another_joomla. But then the user can set the cookie_path in his global configuration to reflect that.
I would prefer to be consistent when setting the cookie.

By the way, you do it already this way here: https://github.com/Hackwar/joomla-cms/blob/patch-40/plugins/system/languagefilter/languagefilter.php#L459 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need it, it is maybe a 0.0001 % problem for the sites outside, but for our testing it is more a problem when someone installed more then one multi-language sites for testing a functionality.

$this->app->input->cookie->set(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
}

Expand Down