Advertisement
enkuso

Untitled

Jun 10th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Base actions for the nmcLanguageSwitcherPlugin language module.
  5.  *
  6.  * @package     nmcLanguageSwitcherPlugin
  7.  * @subpackage  language
  8.  * @author      NiMo Consulting LLC
  9.  * @version     1.0.0.
  10.  */
  11. abstract class BaselanguageActions extends sfActions
  12. {
  13.   public function executeChangeLanguage(sfWebRequest $request)
  14.   {
  15.     $new_lang = $request->getParameter('lang',false);
  16.     $old_lang = $this->getUser()->getCulture();
  17.     $this->forward404unless($new_lang);
  18.     $all_lang = sfConfig::get('app_available_languages',array('en'=>array('en', 'English')));
  19.     foreach($all_lang as $lang):
  20.       if($new_lang === $lang[0]) {
  21.         $this->getUser()->setCulture($new_lang);
  22.       }
  23.     endforeach;
  24.     $prev = $request->getReferer();
  25.     /* 2011 July 25 bug fix. Now work with ':sf_culture' in routing.*/
  26.         /* case: domain/foo/sf_culture/bar */
  27.         $pos = strpos($prev,'/'.$old_lang.'/');
  28.         if($pos !== false){$prev = str_replace('/'.$old_lang.'/','/'.$new_lang.'/',$prev);}
  29.         /* case: domain/foo/sf_culture */
  30.         $pos = strpos($prev,'/'.$old_lang);
  31.         if($pos !== false && strlen($prev) === ($pos + strlen('/'.$old_lang))) {
  32.           $prev = str_replace('/'.$old_lang, '/'.$new_lang, $prev);
  33.         }
  34.         /* Still have bug if route contains same string as '/sf_culture/'. example: 'domain/sf_culture/module/action/param' if (param == sf_culture) there will be bug. */
  35.     /* end of 2011 July 25 bug fix */
  36.     $this->redirect(($prev)?$prev:sfConfig::get('app_homepage'));
  37.     return sfView::HEADER_ONLY;
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement