Labels |
Added:
No Code Attached Yet
|
The issue also affects the POST method
Incriminated code (damn modifications to language router, each time problems):
`public function parseRule(&$router, &$uri)
{
// Are we in SEF mode or not?
if ($this->mode_sef) {
$path = $uri->getPath();
$parts = explode('/', $path);
$sef = StringHelper::strtolower($parts[0]);
$lang = $uri->getVar('lang');
if (isset($this->sefs[$sef])) {
// We found a matching language to the lang code
$uri->setVar('lang', $this->sefs[$sef]->lang_code);
array_shift($parts);
$uri->setPath(implode('/', $parts));
// We were called with the default language code and want to redirect
if ($this->params->get('remove_default_prefix', 0) && $uri->getVar('lang') == $this->default_lang) {
$router->setTainted();
}
} elseif ($this->params->get('remove_default_prefix', 0)) {
// We don't have a prefix for the default language
$uri->setVar('lang', $this->default_lang);
} else {
// No language is set, so we want to redirect to the right language
$router->setTainted();
}
// The language was set both per SEF path and per query parameter. Query parameter takes precedence
if ($lang) {
$uri->setVar('lang', $lang);
$router->setTainted();
}
} elseif ($uri->hasVar('lang')) {
// We are not in SEF mode. Do we have a language set?
$lang_code = $uri->getVar('lang');
if (isset($this->sefs[$lang_code])) {
// We found a matching language to the lang code
$uri->setVar('lang', $this->sefs[$lang_code]->lang_code);
} else {
// The language is not installed on our site
$uri->delVar('lang');
}
}
}
/**
* Parse rule to set the applications language state.
* This rule is removed after being executed the first time, since
* it does redirects and thus disallows parsing more than one URL per page call
*
* @param Router &$router Router object.
* @param Uri &$uri Uri object.
*
* @return void
*
* @since 6.0.0
*/
public function setLanguageApplicationState(&$router, &$uri)
{
// We check if the parseRule is still attached to keep this b/c
if (!\in_array([$this, 'parseRule'], $router->getRules()['parsepreprocess'])) {
$router->detachRule('parse', [$this, 'setLanguageApplicationState'], $router::PROCESS_BEFORE);
return;
}
$lang_code = false;
// Our parse rule discovered a language
if ($uri->hasVar('lang')) {
$lang_code = $uri->getVar('lang');
} else {
/**
* We don't know the language yet and want to discover it.
* If we remove the default prefix, call by POST or have nolangfilter set,
* we simply take the default language.
*/
if (
$this->params->get('remove_default_prefix', 0)
|| $this->getApplication()->getInput()->getMethod() === 'POST'
|| $this->getApplication()->getInput()->get('nolangfilter', 0) == 1
|| \count($this->getApplication()->getInput()->post) > 0
|| \count($this->getApplication()->getInput()->files) > 0
) {
$lang_code = $this->default_lang;
} else {
$lang_code = $this->getLanguageCookie();
// No language code. Try using browser settings or default site language
if (!$lang_code && $this->params->get('detect_browser', 0) == 1) {
$lang_code = LanguageHelper::detectLanguage();
}
if (!$lang_code) {
$lang_code = $this->default_lang;
}
if (!$this->params->get('remove_default_prefix', 0) && $uri->getPath() == '') {
if ($this->mode_sef) {
$path = $this->lang_codes[$lang_code]->sef . '/' . $uri->getPath();
if (!$this->getApplication()->get('sef_rewrite')) {
$path = 'index.php/' . $path;
}
$uri->setPath($path);
} else {
$uri->setPath('index.php');
$uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
}
$redirectHttpCode = 301;
$redirectUri = $uri->base() . $uri->toString(['path', 'query', 'fragment']);
// We cannot cache this redirect in browser. 301 is cacheable by default so we need to force to not cache it in browsers.
$this->getApplication()->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
$this->getApplication()->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
$this->getApplication()->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate', false);
$this->getApplication()->sendHeaders();
// Redirect to language.
$this->getApplication()->redirect($redirectUri, $redirectHttpCode);
}
}
}
// We have found our language and now need to set the cookie and the language value in our system
$this->current_lang = $lang_code;
// Set the request var.
$app = $this->getApplication();
$app->getInput()->set('language', $lang_code);
$app->set('language', $lang_code);
$language = $app->getLanguage();
if ($language->getTag() !== $lang_code) {
$language_new = $this->languageFactory->createLanguage($lang_code, (bool) $app->get('debug_lang'));
foreach ($language->getPaths() as $extension => $files) {
if (str_starts_with($extension, 'plg_system')) {
$extension_name = substr($extension, 11);
$language_new->load($extension, JPATH_ADMINISTRATOR)
|| $language_new->load($extension, JPATH_PLUGINS . '/system/' . $extension_name);
continue;
}
$language_new->load($extension);
}
Factory::$language = $language_new;
$app->loadLanguage($language_new);
}
// Create a cookie.
$this->setLanguageCookie($lang_code);
$router->detachRule('parse', [$this, 'setLanguageApplicationState'], $router::PROCESS_BEFORE);
}`
It's no longer possible to have a working URL like:
http://joomla60dev/index.php?option=com_mycomponent&view=myview&lang=de
This one is 404:
http://joomla60dev/de/index.php?option=com_mycomponent&view=myview
This one only works:
http://joomla60dev/de/?option=com_mycomponent&view=myview