コード例 #1
0
ファイル: CustomUrlManager.php プロジェクト: barricade86/raui
 public function parseUrl($request)
 {
     if (issetModule('seo') && $this->parseReady === false && oreInstall::isInstalled()) {
         if (preg_match('#^([\\w-]+)#i', $request->pathInfo, $matches)) {
             $activeLangs = Lang::getActiveLangs();
             $arr = array();
             foreach ($activeLangs as $lang) {
                 $arr[] = 'url_' . $lang . ' = :alias';
             }
             $condition = '(' . implode(' OR ', $arr) . ')';
             $seo = SeoFriendlyUrl::model()->find(array('condition' => 'direct_url = 1 AND ' . $condition, 'params' => array('alias' => $matches[1])));
             if ($seo !== null) {
                 foreach ($activeLangs as $lang) {
                     $field = 'url_' . $lang;
                     if ($seo->{$field} == $matches[1]) {
                         setLangCookie($lang);
                         Yii::app()->setLanguage($lang);
                         //$_GET['lang'] = $lang;
                     }
                 }
                 $_GET['url'] = $matches[1];
                 //$_GET['id'] = $seo->model_id;
                 //Yii::app()->controller->seo = $seo;
                 return 'infopages/main/view';
             }
         }
         $this->parseReady = true;
     }
     return parent::parseUrl($request);
 }
コード例 #2
0
 public function parseUrl($request)
 {
     $route = parent::parseUrl($request);
     if (substr_count($route, '-') > 0) {
         $route = lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
     }
     return $route;
 }
コード例 #3
0
ファイル: XUrlManager.php プロジェクト: mryuhancai/newphemu
 public function parseUrl($pathInfo)
 {
     $result = parent::parseUrl($pathInfo);
     $urlLanguage = Yii::app()->getRequest()->getParam('language');
     if ($urlLanguage && in_array($urlLanguage, $this->supportedLanguages)) {
         Yii::app()->setLanguage($urlLanguage);
     }
     return $result;
 }
コード例 #4
0
 public function parseUrl($request)
 {
     $searchPaths = array($request->pathInfo);
     // Also search for paths that end with the wildcard "*" (e.g. with news details)
     if ($lastPathSeparatorPos = strrpos($request->pathInfo, '/')) {
         $searchPaths[] = substr($request->pathInfo, 0, $lastPathSeparatorPos + 1) . '*';
     }
     $page = CmsPage::model()->findByAttributes(array('path' => $searchPaths));
     if ($page !== null) {
         return 'cms/page/default/id/' . $page->id;
     }
     return parent::parseUrl($request);
 }
コード例 #5
0
 public function parseUrl($request)
 {
     $route = parent::parseUrl($request);
     // Perform a 301 redirection if the current protocol
     // does not match the expected protocol
     $secureRoute = $this->isSecureRoute($route);
     $sslRequest = $request->isSecureConnection;
     if ($secureRoute !== $sslRequest) {
         $hostInfo = $secureRoute ? $this->secureHostInfo : $this->hostInfo;
         if (strpos($hostInfo, 'https') === 0 xor $sslRequest) {
             $request->redirect($hostInfo . $request->url, true, 301);
         }
     }
     return $route;
 }
コード例 #6
0
ファイル: SnapUrlManager.php プロジェクト: snapfrozen/snapcms
 public function parseUrl($request)
 {
     $path = '/' . $request->pathInfo;
     if (!empty($path)) {
         $Content = Content::model()->findByAttributes(array('path' => $path));
     }
     if ($Content && $Content->id) {
         $route = 'content/view/id/' . $Content->id;
         $_GET['path'] = $Content->path;
         //So that menu items become active
     } else {
         $route = parent::parseUrl($request);
     }
     return lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
 }
コード例 #7
0
ファイル: UrlManager.php プロジェクト: getherbie/yii-module
 /**
  * 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);
 }
コード例 #8
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)
 {
     $this->_currentUrl = parent::parseUrl($request);
     if (isset($_GET['language']) && in_array($_GET['language'], $this->languages)) {
         Yii::app()->language = $_GET['language'];
         Yii::app()->user->setState('language', $_GET['language']);
     } else {
         if (Yii::app()->user->hasState('language')) {
             Yii::app()->language = Yii::app()->user->getState('language');
         } else {
             if (isset(Yii::app()->request->cookies['language'])) {
                 Yii::app()->language = Yii::app()->request->cookies['language']->value;
             }
         }
     }
     return $this->_currentUrl;
 }
コード例 #9
0
 public function parseUrl($request)
 {
     $route = parent::parseUrl($request);
     // Set application language
     $urlLanguage = Yii::app()->getRequest()->getParam('language');
     if ($urlLanguage && in_array($urlLanguage, $this->supportedLanguages)) {
         Yii::app()->setLanguage($urlLanguage);
     }
     // Perform a 301 redirection if the current protocol
     // does not match the expected protocol
     $secureRoute = $this->isSecureRoute($route);
     $sslRequest = $request->isSecureConnection;
     if ($secureRoute !== $sslRequest) {
         $hostInfo = $secureRoute ? $this->secureHostInfo : $this->hostInfo;
         if (strpos($hostInfo, 'https') === 0 xor $sslRequest) {
             $request->redirect($hostInfo . $request->url, true, 301);
         }
     }
     return $route;
 }
コード例 #10
0
ファイル: UrlManager.php プロジェクト: codemix/restyii
 /**
  * Override the default implementation to return a routing object when passed a string instead of a request object.
  * @param \CHttpRequest|string $url the request or string to parse
  * @param string|null $verb the http verb to assume when parsing string urls
  *
  * @return array|bool|string false if the request or url could not be parsed, otherwise the route or routing object
  */
 public function parseUrl($url, $verb = 'GET')
 {
     if (!is_string($url)) {
         return parent::parseUrl($url);
     }
     $request = new Request();
     $request->setRequestType($verb);
     $request->setUrl($url);
     $oldGET = $_GET;
     $oldREQUEST = $_REQUEST;
     $_GET = array();
     $parsed = parent::parseUrl($request);
     $params = $_GET;
     $_GET = $oldGET;
     $_REQUEST = $oldREQUEST;
     if ($parsed === false) {
         return false;
     }
     array_unshift($params, $parsed);
     return $params;
 }
コード例 #11
0
ファイル: XUrlManager.php プロジェクト: hung5s/yap
 public function parseUrl($request)
 {
     if ($this->getUrlFormat() === self::PATH_FORMAT) {
         $rawPathInfo = urldecode($request->getPathInfo());
         $this->pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
         //            '<path:.*>.tpl' => ['Admin/default/template','.tpl'],
         //            '<route:.*>.js' => ['Admin/default/control','.js','passingOnly' => true],
         //            '<route:.*>' => 'Admin/default/index',
         $matches = [];
         if (preg_match('/(.*)app.js/', $this->pathInfo, $matches)) {
             $_GET['isNg'] = true;
             return $matches[1];
             //                return '/'.str_replace('.','/',$matches[1]);
         }
         return parent::parseUrl($request);
         /** Merge URLs between rules defined in config file and CMS page's rules */
         if (WORKFLOW_ID) {
             //when preview mode, we load cache urls of site
             //normal mode, we load cache urls of workflow
             $isPreview = isset($_GET['preview']);
             //check current page have enable AB testing
             //if yes, load urls cache file from <site_id>.php file
             if ($isPreview == false && app()->hasComponent('cmsManager')) {
                 $isPreview = Yii::app()->XService->run('Cms.PageUrl.isAbTesting', array('siteId' => app()->cmsManager->workflow['site_id'], 'url' => $pathInfo));
             }
             $this->_pageUrls = Yii::app()->XService->run('Cms.PageUrl.getCachedUrls', array('workflowId' => WORKFLOW_ID, 'preview' => $isPreview));
             $this->_workflowId = WORKFLOW_ID;
             $_pageUrls = array();
             if (is_array($this->_pageUrls)) {
                 //redirect to default url with code 301
                 app()->XService->run('Cms.PageUrl.redirectToDefault', array('url' => $pathInfo));
                 if (Yii::app()->hasComponent('localeManager')) {
                     $pathInfo = Yii::app()->localeManager->processPathInfo($pathInfo);
                 }
                 // can add code to modify url like mod_rewirte
                 // ...
                 // end of "mod_rewrite"
                 /**
                  * No rule in config file and in CMS page rules matched with requested URL
                  * As the CMS page rules are pull from cached file, we assume that the cache
                  * file is old so we will try to search against the rules in DB and rebuild
                  * the cache file
                  */
                 $notInKeys = array_keys($this->_pageUrls);
                 $workflow = app()->cmsManager->workflow;
                 $pageUrls = Yii::app()->XService->run('Cms.PageUrl.rebuildCacheUrls', array('workflow' => $workflow, 'ids' => $notInKeys));
                 $_pageUrls = $this->_pageUrls = CMap::mergeArray($this->_pageUrls, $pageUrls);
                 $event = new CmsUrlManagerEvent($this);
                 $event->rules =& $this->rules;
                 $event->workflowId = $this->_workflowId;
                 if ($this->hasEventHandler('onBeforeParseUrl')) {
                     $this->onBeforeParseUrl($event);
                 }
                 $_pageUrls = CMap::mergeArray($event->rules, $_pageUrls);
                 $matchedRoute = $this->parsePageUrlsToBaseUrl($_pageUrls, $request, $pathInfo, $rawPathInfo);
                 if (!empty($matchedRoute)) {
                     return $matchedRoute;
                 }
                 //$this->rules['/'] = 'Cms/default/index';
             } else {
                 //we should throw an error but unfortunately, we cannot do that within UrlManager init()
                 //so we have to wait till parseUrl();
                 $this->_noUrlCacheError = true;
             }
         } else {
             //we should throw an error but unfortunately, we cannot do that within UrlManager init()
             //so we have to wait till parseUrl();
             $this->_workflowLookupError = true;
         }
         // check and throw some error we supposed to throw on the init but cannot because of Yii
         if ($this->_workflowLookupError === true) {
             throw new CHttpException(404, 'This domain does not match with any configured domain(s).');
         }
         if ($this->_noUrlCacheError === true) {
             throw new Exception('Workflow for the requested URL is not defined yet.');
         }
         // end of checking and throwing error
         if ($this->useStrictParsing) {
             throw new CHttpException(404, Yii::t('yii', 'Unable to resolve the request "{route}".', array('{route}' => $pathInfo)));
         } else {
             return $pathInfo;
         }
     } else {
         if (isset($_GET[$this->routeVar])) {
             $route = $_GET[$this->routeVar];
         } else {
             if (isset($_POST[$this->routeVar])) {
                 $route = $_POST[$this->routeVar];
             } else {
                 $route = '';
             }
         }
     }
     return $route;
 }
コード例 #12
0
ファイル: CUrlManagerTest.php プロジェクト: avtograd/yii
 public function testParsingOnly()
 {
     $config = array('basePath' => dirname(__FILE__), 'components' => array('request' => array('class' => 'TestHttpRequest')));
     $rules = array('(articles|article)/<id:\\d+>' => array('article/read', 'parsingOnly' => true), 'article/<id:\\d+>' => array('article/read', 'verb' => 'GET'));
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $app = new TestApplication($config);
     $app->request->baseUrl = null;
     // reset so that it can be determined based on scriptUrl
     $app->request->scriptUrl = '/apps/index.php';
     $app->request->pathInfo = 'articles/123';
     $um = new CUrlManager();
     $um->urlFormat = 'path';
     $um->rules = $rules;
     $um->init($app);
     $route = $um->parseUrl($app->request);
     $this->assertEquals('article/read', $route);
     $url = $um->createUrl('article/read', array('id' => 345));
     $this->assertEquals('/apps/index.php/article/345', $url);
 }
コード例 #13
0
ファイル: UrlManager.php プロジェクト: annamoorjani/dental
 public function parseUrl($request)
 {
     $route = parent::parseUrl($request);
     return lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
 }
コード例 #14
0
 public function parseUrl($pathInfo)
 {
     $result = parent::parseUrl($pathInfo);
     return $result;
 }
コード例 #15
0
 public function testParseUrlWithGetFormat()
 {
     $config = array('basePath' => dirname(__FILE__), 'components' => array('request' => array('class' => 'TestHttpRequest', 'scriptUrl' => '/app/index.php')));
     $entries = array(array('route' => 'article/read', 'name' => 'value'));
     $app = new TestApplication($config);
     $request = $app->request;
     $um = new CUrlManager();
     $um->urlFormat = 'get';
     $um->routeVar = 'route';
     $um->init($app);
     foreach ($entries as $entry) {
         $_GET = $entry;
         $route = $um->parseUrl($request);
         $this->assertEquals($entry['route'], $route);
         $this->assertEquals($_GET, $entry);
     }
 }