Skip to content

Instantly share code, notes, and snippets.

@elinw
Created April 27, 2013 21:40
Show Gist options
  • Save elinw/5474844 to your computer and use it in GitHub Desktop.
Save elinw/5474844 to your computer and use it in GitHub Desktop.
--- a/plugins/system/languagefilter/languagefilter.php
+++ b/plugins/system/languagefilter/languagefilter.php
@@ -30,6 +30,8 @@
public function __construct(&$subject, $config)
{
+ parent::__construct($subject, $config);
+
// Ensure that constructor is called one time
self::$cookie = SID == '';
if (!self::$default_lang) {
@@ -82,7 +84,7 @@
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
- setcookie(JApplication::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
+ setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
// set the request var
JRequest::setVar('language', $lang_code);
}
@@ -355,7 +357,7 @@
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
- setcookie(JApplication::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
+ setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
}
}
}
@@ -402,7 +404,7 @@
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
- setcookie(JApplication::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
+ setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
// Change the language code
JFactory::getLanguage()->setLanguage($lang_code);
@@ -507,4 +509,25 @@
}
}
}
+
+ /**
+ * Getting the Language Cookie settings
+ *
+ * @return string The cookie time.
+ *
+ * @since 3.0.4
+ */
+ private function getLangCookieTime()
+ {
+ if ($this->params->get('lang_cookie', 1) == 1)
+ {
+ $lang_cookie = time() + 365 * 86400;
+ }
+ else
+ {
+ $lang_cookie = 0;
+ }
+
+ return $lang_cookie;
+ }
}
diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml
index 36649f9..856de90 100644
--- a/plugins/system/languagefilter/languagefilter.xml
+++ b/plugins/system/languagefilter/languagefilter.xml
@@ -52,6 +52,15 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
+ <field name="lang_cookie" type="radio"
+ description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_DESC"
+ label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL"
+ default="1"
+ class="btn-group"
+ >
+ <option value="0">PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION</option>
+ <option value="1">PLG_SYSTEM_LANGUAGEFILTER_OPTION_YEAR</option>
+ </field>
<field name="alternate_meta" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment