Exemplo n.º 1
0
 /**
  * @return string Parsed path info without lang prefix.
  */
 public function getPathInfo()
 {
     $langCode = null;
     $pathInfo = parent::getPathInfo();
     if ($this->_pathInfo === null) {
         $pathInfo = parent::getPathInfo();
         $parts = explode('/', $pathInfo);
         /*
         			if (in_array($parts[0], Yii::app()->languageManager->getCodes()))
         			{
         				// Valid language code detected.
         				// Remove it from url path to make route work and activate lang
         				$langCode = $parts[0];
         
         				// If language code are is equal default show 404 page
         				if($langCode === Yii::app()->languageManager->default->code)
         					throw new CHttpException(404, Yii::t('core', 'Страница не найдена.'));
         
         				unset($parts[0]);
         				$pathInfo = implode($parts, '/');
         			}
         */
         $this->_pathInfo = $pathInfo;
     }
     // Activate language by code
     //Yii::app()->languageManager->setActive($langCode);
     return $pathInfo;
 }
Exemplo n.º 2
0
 /**
  * Parses the user request.
  * @param CHttpRequest $request The request application component.
  * @return string The route (controllerID/actionID) and perhaps GET parameters in path format.
  */
 public function parseUrl($request)
 {
     $route = $request->getQuery('r');
     if (is_null($route)) {
         $route = $request->getPathInfo();
     }
     $app = Yii::app()->getModule('herbie')->application;
     try {
         $path = $app['urlMatcher']->match($route);
     } catch (Exception $ex) {
         // Don't catch exception
     }
     if (!empty($path)) {
         return 'herbie/page';
     }
     return parent::parseUrl($request);
 }
Exemplo n.º 3
0
 /**
  * @return string
  * @throws CHttpException
  * @return string Parsed path info without lang prefix.
  */
 public function getPathInfo()
 {
     $langCode = null;
     $pathInfo = parent::getPathInfo();
     if (null === $this->_pathInfo) {
         $pathInfo = parent::getPathInfo();
         $parts = explode('/', $pathInfo);
         if (in_array($parts[0], Yii::app()->languageManager->getCodes())) {
             // Valid language code detected.
             // Remove it from url path to make route work and activate lang
             $langCode = $parts[0];
             // If language code is equal default - show 404 page
             if ($langCode === Yii::app()->languageManager->default->code) {
                 throw new CHttpException(404, Yii::t('error', '404'));
             }
             unset($parts[0]);
             $pathInfo = implode($parts, '/');
         }
         $this->_pathInfo = $pathInfo;
         // Activate language by code
         Yii::app()->languageManager->setActive($langCode);
     }
     return $pathInfo;
 }
Exemplo n.º 4
0
 /**
  * Parses the user request.
  * @param CHttpRequest $request the request application component
  * @return string the route (controllerID/actionID) and perhaps GET parameters in path format.
  */
 public function parseUrl($request)
 {
     if ($this->getUrlFormat() === self::PATH_FORMAT) {
         $rawPathInfo = $request->getPathInfo();
         $pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
         foreach ($this->_rules as $i => $rule) {
             if (is_array($rule)) {
                 $this->_rules[$i] = $rule = Gateway::createComponent($rule);
             }
             if (($r = $rule->parseUrl($this, $request, $pathInfo, $rawPathInfo)) !== false) {
                 return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;
             }
         }
         if ($this->useStrictParsing) {
             throw new THoughtException("Unable to resolve the request '.{$pathInfo},').");
         } else {
             return $pathInfo;
         }
     } elseif (isset($_GET[$this->routeVar])) {
         return $_GET[$this->routeVar];
     } elseif (isset($_POST[$this->routeVar])) {
         return $_POST[$this->routeVar];
     } else {
         return '';
     }
 }
Exemplo n.º 5
0
 /**
  * Parses the user request.
  * @param CHttpRequest $request the request application component
  * @return string the route (controllerID/actionID) and perhaps GET parameters in path format.
  */
 public function parseUrl($request)
 {
     if ($this->getUrlFormat() === self::PATH_FORMAT) {
         $rawPathInfo = $request->getPathInfo();
         $pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
         foreach ($this->_rules as $i => $rule) {
             if (is_array($rule)) {
                 $this->_rules[$i] = $rule = Yii::createComponent($rule);
             }
             if (($r = $rule->parseUrl($this, $request, $pathInfo, $rawPathInfo)) !== false) {
                 return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;
             }
         }
         if ($this->useStrictParsing) {
             throw new CHttpException(404, Yii::t('yii', 'Unable to resolve the request "{route}".', array('{route}' => $pathInfo)));
         } else {
             return $pathInfo;
         }
     } elseif (isset($_GET[$this->routeVar])) {
         return $_GET[$this->routeVar];
     } elseif (isset($_POST[$this->routeVar])) {
         return $_POST[$this->routeVar];
     } else {
         return '';
     }
 }
Exemplo n.º 6
0
 public function getPathInfo()
 {
     if ($this->_cleanPathInfo === null) {
         $this->_cleanPathInfo = parent::getPathInfo();
         $languages = array();
         foreach ($this->languages as $k => $v) {
             $languages[] = is_string($k) ? $k : $v;
         }
         $pattern = implode('|', $languages);
         if (preg_match("#^({$pattern})\\b(/?)#", $this->_cleanPathInfo, $m)) {
             $this->_cleanPathInfo = substr($this->_cleanPathInfo, strlen($m[1] . $m[2]));
             $language = isset($this->languages[$m[1]]) ? $this->languages[$m[1]] : $m[1];
             Yii::app()->language = $language;
             YII_DEBUG && Yii::trace("Detected language '{$language}'", 'ext.localeurls');
             if ($this->persistLanguage) {
                 Yii::app()->user->setState(self::LANGUAGE_KEY, $language);
                 $cookies = $this->cookies;
                 if ($this->languageCookieLifetime) {
                     $cookie = new CHttpCookie(self::LANGUAGE_KEY, $language);
                     $cookie->expire = time() + $this->languageCookieLifetime;
                     $cookies->add(self::LANGUAGE_KEY, $cookie);
                 }
             }
             if (!$this->redirectDefault && $language === $this->getDefaultLanguage()) {
                 $url = $this->getBaseUrl() . '/' . $this->_cleanPathInfo;
                 $queryString = $this->getQueryString();
                 if (!empty($queryString)) {
                     $url .= '?' . $queryString;
                 }
                 $this->redirect($url);
             }
         } else {
             $language = null;
             if ($this->persistLanguage) {
                 $language = Yii::app()->user->getState(self::LANGUAGE_KEY);
                 if ($language === null) {
                     $language = $this->getCookies()->itemAt(self::LANGUAGE_KEY);
                 }
             }
             if ($language === null && $this->detectLanguage) {
                 foreach ($this->preferredLanguages as $preferred) {
                     if (in_array($preferred, $this->languages)) {
                         $language = $preferred;
                         break;
                     }
                 }
             }
             if ($language === null || $language === $this->_defaultLanguage) {
                 if (!$this->redirectDefault) {
                     return $this->_cleanPathInfo;
                 } else {
                     $language = $this->_defaultLanguage;
                 }
             }
             $key = array_search($language, $this->languages);
             if ($key && is_string($key)) {
                 $language = $key;
             }
             if (($baseUrl = $this->getBaseUrl()) === '') {
                 $this->redirect('/' . $language . $this->getRequestUri());
             } else {
                 $this->redirect(strtr($this->getRequestUri(), array($baseUrl => $baseUrl . '/' . $language)));
             }
         }
     }
     return $this->_cleanPathInfo;
 }