Skip to content

Commit

Permalink
#$ [#25037] No option to remove the default language from the URL and
Browse files Browse the repository at this point in the history
links. Thanks Christophe.
  • Loading branch information
chdemko authored and infograf768 committed Nov 8, 2011
1 parent abec4bd commit ca5acfa
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
Expand Up @@ -14,3 +14,5 @@ PLG_SYSTEM_LANGUAGEFILTER_BROWSER_SETTINGS="Browser Settings"
PLG_SYSTEM_LANGUAGEFILTER_SITE_LANGUAGE="Site Language"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_MENU_ASSOCIATIONS_DESC="This option will allow menu associations when switching from one language to another"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_MENU_ASSOCIATIONS_LABEL="Menu associations"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_DESC="Remove the defined prefix for the default site language when Search Engine Friendly URLs is set to 'Yes'."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL="Remove default language prefix"
9 changes: 8 additions & 1 deletion includes/router.php
Expand Up @@ -99,7 +99,14 @@ public function build($url)

if ($app->getCfg('sef_rewrite')) {
//Transform the route
$route = str_replace('index.php/', '', $route);
if ($route == 'index.php')
{
$route = '';
}
else
{
$route = str_replace('index.php/', '', $route);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion installation/CHANGELOG
Expand Up @@ -28,7 +28,8 @@ $ -> Language fix or change
! -> Note

08-Nov-2011 Jean-Marie Simonet
# [#26980] Missing menu ordering in edit. Thanks Christophe.
#$ [#26980] Missing menu ordering in edit. Thanks Christophe and Elin.
#$ [#25037] No option to remove the default language from the URL and links. Thanks Christophe.

07-Nov-2011 Jean-Marie Simonet
#$ [#27007] *mod_articles_category missing option to sort by feature articles ordering system. Thanks Denise.
Expand Down
4 changes: 2 additions & 2 deletions modules/mod_languages/helper.php
Expand Up @@ -49,8 +49,8 @@ public static function getList(&$params)
unset($languages[$i]);
}
else {
$language->active = $language->lang_code == $lang->getTag();
if ($app->getLanguageFilter()) {
$language->active = $language->lang_code == $lang->getTag();
if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
$itemid = $associations[$language->lang_code];
if ($app->getCfg('sef')=='1') {
Expand All @@ -71,7 +71,7 @@ public static function getList(&$params)
}
}
else {
$language->link = 'index.php';
$language->link = JRoute::_('&Itemid='.$homes['*']->id);
}
}
}
Expand Down
72 changes: 60 additions & 12 deletions plugins/system/languagefilter/languagefilter.php
Expand Up @@ -158,7 +158,14 @@ public function buildRule(&$router, &$uri)

if (self::$mode_sef) {
$uri->delVar('lang');
$uri->setPath($uri->getPath().'/'.$sef.'/');
if ($this->params->get('remove_default_prefix', 0) == 0 || $sef != self::$default_sef || $sef != self::$lang_codes[self::$tag]->sef)
{
$uri->setPath($uri->getPath().'/'.$sef.'/');
}
else
{
$uri->setPath($uri->getPath());
}
}
else {
$uri->setVar('lang', $sef);
Expand All @@ -183,23 +190,64 @@ public function parseRule(&$router, &$uri)

$sef = $parts[0];

if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
$app = JFactory::getApplication();

$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0)
// Redirect only if not in post
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0)
{
if ($this->params->get('remove_default_prefix', 0) == 0)
{
$app = JFactory::getApplication();
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base().$uri->toString(array('path', 'query', 'fragment')));
// redirect if sef does not exists
if (!isset(self::$sefs[$sef]))
{
// Use the current language sef or the default one
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);

if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base().$uri->toString(array('path', 'query', 'fragment')));
}
else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base().'index.php'.($path ? ('/' . $path) : ''));
}
}
}
else
{
// redirect if sef does not exists and language is not the default one
if (!isset(self::$sefs[$sef]) && $lang_code != self::$default_lang)
{
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);

if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base().$uri->toString(array('path', 'query', 'fragment')));
}
else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base().'index.php'.($path ? ('/' . $path) : ''));
}
}
else {
$app->redirect($uri->base().'index.php/'.$uri->toString(array('path', 'query', 'fragment')));
// redirect if sef is the default one
elseif ($sef == self::$default_sef)
{
array_shift($parts);
$uri->setPath(implode('/' , $parts));

if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base().$uri->toString(array('path', 'query', 'fragment')));
}
else {
$path = $uri->toString(array('path', 'query', 'fragment'));
$app->redirect($uri->base().'index.php'.($path ? ('/' . $path) : ''));
}
}
}
}
$lang_code = self::$sefs[$sef]->lang_code;

$lang_code = isset(self::$sefs[$sef]) ? self::$sefs[$sef]->lang_code : '';
if ($lang_code && JLanguage::exists($lang_code)) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
Expand Down
8 changes: 8 additions & 0 deletions plugins/system/languagefilter/languagefilter.xml
Expand Up @@ -44,6 +44,14 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="remove_default_prefix" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</fields>
</config>
Expand Down

0 comments on commit ca5acfa

Please sign in to comment.