Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit dd3f87897a099b10c353e92117b6a00f60b2a81d @klaftertief committed Mar 24, 2010
Showing with 121 additions and 0 deletions.
  1. +27 −0 LICENCE.txt
  2. +1 −0 README.md
  3. +69 −0 events/event.language_redirect.php
  4. +24 −0 extension.driver.php
@@ -0,0 +1,27 @@
+All source code included in the "Language Redirect" Symphony Extension
+archive is, unless otherwise specified, released under the MIT licence as
+follows:
+
+----- begin license block -----
+
+Copyright 2010 Jonas Coch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+----- end license block -----
@@ -0,0 +1 @@
+# Language Redirect
@@ -0,0 +1,69 @@
+<?php
+
+ if(!defined('__IN_SYMPHONY__')) die('<h2>Error</h2><p>You cannot directly access this file</p>');
+
+ require_once(TOOLKIT . '/class.event.php');
+
+ Class eventlanguage_redirect extends Event{
+
+ const ROOTELEMENT = 'language-redirect';
+
+ public static function about(){
+
+ $description = new XMLElement('p', 'This event redirects users to a language version of the page depending on browser settings or cookies.');
+
+ return array(
+ 'name' => 'Language Redirect',
+ 'author' => array('name' => 'Jonas Coch',
+ 'website' => 'http://klaftertief.de',
+ 'email' => 'jonas@klaftertief.de'),
+ 'version' => '1.0',
+ 'release-date' => '2010-03-19',
+ 'trigger-condition' => '');
+ }
+
+ public function load(){
+ return $this->__trigger();
+ }
+
+ public static function documentation(){
+ return 'This event redirects users to a language version of the page depending on browser settings or cookies.';
+ }
+
+ protected function __trigger(){
+ $current_language = $_REQUEST['language'];
+ $supported_languages = array('en','de');
+
+ // TODO: check for unsupported languages
+ if (isset($current_language)) { // no redirect, set current language in cookie
+ setcookie(__SYM_COOKIE_PREFIX__ . 'language', $current_language, time()+TWO_WEEKS, __SYM_COOKIE_PATH__);
+ }
+ else { // redirect to language depending in cookie or browser settings
+ $current_path = $this->_env['param']['current-path'];
+ $browser_languages = Lang::getBrowserLanguages();
+ foreach ($browser_languages as $language) {
+ $language = substr($language,0,2);
+ if (in_array($language, $supported_languages)) {
+ $in_browser_languages = true;
+ $browser_language = $language;
+ break;
+ };
+ }
+ if (isset($_COOKIE[__SYM_COOKIE_PREFIX__ . 'language'])) {
+ $language = $_COOKIE[__SYM_COOKIE_PREFIX__ . 'language'];
+ }
+ elseif ($in_browser_languages) {
+ $language = $browser_language;
+ }
+ else {
+ $language = $supported_languages[0];
+ }
+
+ header ('Location: '.$this->_env['param']['root'].'/'.$language.$current_path);
+ die();
+ }
+
+ return false;
+
+ }
+ }
@@ -0,0 +1,24 @@
+<?php
+
+ Class extension_language_redirect extends Extension{
+
+ public function about(){
+ return array(
+ 'name' => 'Language Redirect',
+ 'version' => '1.0beta',
+ 'release-date' => '2010-03-24',
+ 'author' => array(
+ 'name' => 'Jonas Coch',
+ 'website' => 'http://klaftertief.de',
+ 'email' => 'jonas@klaftertief.de'
+ )
+ );
+ }
+
+ public function getSubscribedDelegates(){
+ return array(
+ );
+ }
+
+ }
+

0 comments on commit dd3f878

Please sign in to comment.