コード例 #1
0
ファイル: AweUrlManager.php プロジェクト: awecode/awecms
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     $route = trim($route, '/');
     //for admin and admin/*
     $parts = explode('/', $route);
     //do not mess with gii
     if ($parts[0] == 'gii') {
         return parent::createUrl($route, $params, $ampersand);
     }
     //        ignore defaultController
     if (Yii::app()->hasModule($parts[0]) && isset($parts[1]) && $parts[1] == Yii::app()->getModule($parts[0])->defaultController) {
         unset($parts[1]);
         $route = implode('/', $parts);
     }
     if (substr(Yii::app()->getRequest()->pathInfo, 0, 6) == 'admin/' || Yii::app()->getRequest()->pathInfo == 'admin') {
         $route = 'admin/' . trim($route, '/');
     }
     $url = parent::createUrl($route, $params, $ampersand);
     if (Settings::get('SEO', 'slugs_enabled')) {
         //handle slugs here
         if ($slug = Slug::getSlug(preg_replace('/' . trim(Yii::app()->baseUrl, '/') . '/', '', $url, 1))) {
             //if (Settings::get('SEO','externalSlug')
             $url = $slug;
             $url = Yii::app()->baseUrl . '/' . $url;
         }
     }
     return $url;
 }
コード例 #2
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if (empty($params['language']) && Yii::app()->language !== 'ru') {
         $params['language'] = Yii::app()->language;
     }
     if (!isset(Yii::app()->controller->module->id)) {
         if (!strstr($route, 'register')) {
             if (isset($_POST['city'])) {
                 $cookie = new CHttpCookie('city', $_POST['city']);
                 Yii::app()->request->cookies['city'] = $cookie;
                 $cookie->expire = time() + 3600;
                 $c = City::model()->localized('ru')->findByPk($_POST['city'])->name;
                 $params['city'] = Settings::toLatin($c);
             } elseif (isset(Yii::app()->request->cookies['city'])) {
                 $c = City::model()->localized('ru')->findByPk(Yii::app()->request->cookies['city']->value)->name;
                 $params['city'] = Settings::toLatin($c);
             } else {
                 unset($params['city']);
             }
         } else {
             unset($params['city']);
         }
     }
     /*if (!strstr($route,'/')) {
           $route = '/cat/'.$route;
       }*/
     return Yii::app()->request->hostInfo . parent::createUrl($route, $params, $ampersand);
 }
コード例 #3
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if (isset($params[$this->languageParam])) {
         $language = $params[$this->languageParam];
         $forceLanguage = true;
         unset($params[$this->languageParam]);
     } else {
         $language = Yii::app()->language;
         $forceLanguage = false;
     }
     $url = parent::createUrl($route, $params, $ampersand);
     $request = Yii::app()->request;
     if (!$forceLanguage && !$request->redirectDefault && $language === $request->getDefaultLanguage()) {
         return $url;
     }
     $key = array_search($language, $request->languages);
     if (is_string($key)) {
         $language = $key;
     }
     if (($baseUrl = $this->getBaseUrl()) === '') {
         return '/' . $language . $url;
     } else {
         return strtr($url, array($baseUrl => $baseUrl . '/' . $language));
     }
 }
コード例 #4
0
ファイル: VerbUrlManager.php プロジェクト: aer123456/yougou
 protected function processRules()
 {
     $rules = array();
     $method = strtolower(Yii::app()->getRequest()->getRequestType());
     //transform method's rules keys to lowercase
     $this->rules = array_combine(array_map(array($this, '__atToLowerCase'), array_keys($this->rules)), array_values($this->rules));
     //check if it has an index the same as the request type and if it does add its rules
     if (key_exists("@{$method}", $this->rules)) {
         $rules = $this->rules["@{$method}"];
     }
     //add the default rules
     if (is_array($rules)) {
         foreach ($this->rules as $k => $rule) {
             if (substr($k, 0, 1) !== '@') {
                 $rules[$k] = $rule;
             }
         }
     } elseif (is_string($rules)) {
         $rules = array("." => $rules);
     }
     //override the existing rules with only those that matche with the request type
     $this->rules = $rules;
     //disable cache that causes it to load wrong rules
     //cant use it as its defined as a constant and not able to change to use method's specific cache
     $this->cacheID = false;
     parent::processRules();
 }
コード例 #5
0
ファイル: XUrlManager.php プロジェクト: mryuhancai/newphemu
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if (!isset($params['language'])) {
         $params['language'] = Yii::app()->language;
     }
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #6
0
 public function createLangUrl($language, $ampersand = '&')
 {
     $route = Yii::app()->controller->route;
     $params = $_GET;
     unset($params[$this->routeVar]);
     $params[$this->langParam] = $language;
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #7
0
 public function parseUrl($request)
 {
     $route = parent::parseUrl($request);
     if (substr_count($route, '-') > 0) {
         $route = lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
     }
     return $route;
 }
コード例 #8
0
ファイル: BackendUrlManager.php プロジェクト: kot-ezhva/ygin
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     $url = parent::createUrl($route, $params, $ampersand);
     if ($this->getFrontendMode()) {
         $baseUrl = $this->getBaseUrl();
         return mb_substr($url, mb_strlen($baseUrl));
     }
     return $url;
 }
コード例 #9
0
 /**
  * Build the rules from the DB
  */
 protected function processRules()
 {
     if (($this->rules = Yii::app()->cache->get('customurlrules')) === false) {
         // Site Rules
         $this->rules = array('project/<id:\\d+>/<alias>' => 'site/projects/viewproject', 'issue/<id:\\d+>/<alias>' => 'site/tickets/viewticket', 'issues/<type:(priority|version|fixedin|type|status|category|project|milestone)>/<id:\\d+>/<alias>' => 'site/tickets/filterissues', 'issues/<type:(priority|version|fixedin|type|status|category|project|milestone)>/<id:\\d+>/<alias>/<rss:\\w+>' => 'site/tickets/filterissues', 'issues/tag/<tag>' => 'site/tickets/filterissuesbytag', 'wiki/<id:\\d+>/<alias>' => 'site/wiki/viewpage', 'wiki/<id:\\d+>/<alias>/<revisionid:\\d+>' => 'site/wiki/viewpagerevision', '' => 'site/index/index', '<_c:([a-zA-z0-9-]+)>' => 'site/<_c>/index', '<_c:([a-zA-z0-9-]+)>/<_a:([a-zA-z0-9-]+)>' => 'site/<_c>/<_a>', '<_c:([a-zA-z0-9-]+)>/<_a:([a-zA-z0-9-]+)>//*' => 'site/<_c>/<_a>/');
         Yii::app()->cache->set('customurlrules', $this->rules);
     }
     // Run parent
     parent::processRules();
 }
コード例 #10
0
ファイル: UrlManager.php プロジェクト: schiz/teff
 public function createUrl($route,$params=array(),$ampersand='&')
 {
     if (!isset($params['language'])) {
         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;
         $params['language']=Yii::app()->language;
     }
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #11
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if ($route != 'min/serve' && $route != 'site/uploadimage') {
         $langs = Lang::getActiveLangs();
         $countLangs = count($langs);
         if (!isFree() && empty($params['lang']) && ($countLangs > 1 || $countLangs == 1 && param('useLangPrefixIfOneLang'))) {
             $params['lang'] = Yii::app()->language;
         }
     }
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #12
0
ファイル: CManagerUrl.php プロジェクト: buildshop/bs-common
 /**
  * Create url based on current language.
  * @param mixed $route
  * @param array $params
  * @param string $ampersand
  * @param boolean $respectLang
  * @access public
  * @return string
  */
 public function createUrl($route, $params = array(), $ampersand = '&', $respectLang = true)
 {
     $result = parent::createUrl($route, $params, $ampersand);
     if ($respectLang === true) {
         $langPrefix = Yii::app()->languageManager->getUrlPrefix();
         if ($langPrefix) {
             $result = '/' . $langPrefix . $result;
         }
     }
     return $result;
 }
コード例 #13
0
ファイル: UrlManager.php プロジェクト: codemix/restyii
 /**
  * @inheritDoc
  */
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     $oldUrlSuffix = $this->urlSuffix;
     if (isset($params['_ext'])) {
         $this->urlSuffix = '.' . $params['_ext'];
         unset($params['_ext']);
     }
     $url = parent::createUrl($route, $params, $ampersand);
     $this->urlSuffix = $oldUrlSuffix;
     return $url;
 }
コード例 #14
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);
 }
コード例 #15
0
 /**
  * @return null
  */
 public function init()
 {
     parent::init();
     // Set this to false so extra query string parameters don't get the path treatment
     $this->appendParams = false;
     // makes more sense to set in HttpRequest
     if (craft()->config->usePathInfo()) {
         $this->setUrlFormat(static::PATH_FORMAT);
     } else {
         $this->setUrlFormat(static::GET_FORMAT);
     }
     $this->_routeVariables = array();
 }
コード例 #16
0
 /**
  *
  * @see CUrlManager 
  *
  * Constructs a URL.
  * @param string the controller and the action (e.g. article/read)
  * @param array list of GET parameters (name=>value). Both the name and value will be URL-encoded.
  * If the name is '#', the corresponding value will be treated as an anchor
  * and will be appended at the end of the URL. This anchor feature has been available since version 1.0.1.
  * @param string the token separating name-value pairs in the URL. Defaults to '&'.
  * @return string the constructed URL
  */
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     // We added this by default to all links to show
     // Content based on language - Add only when not excplicity set
     if (!isset($params['lang'])) {
         $params['lang'] = Yii::app()->language;
     }
     if (isset($params['lang']) && $params['lang'] === false) {
         unset($params['lang']);
     }
     // Use parent to finish url construction
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #17
0
ファイル: CiiURLManager.php プロジェクト: fandikurnia/CiiMS
 /**
  * Overrides processRules, allowing us to inject our own ruleset into the URL Manager
  * Takes no parameters
  **/
 protected function processRules()
 {
     $this->addBasicRules();
     $this->cacheRules('content', $this->contentUrlRulesId);
     $this->cacheRules('categories', $this->categoriesUrlRulesId);
     // Allow Sphinx Search settings to be dynamically via CiiSettings
     if (Cii::getConfig('sphinx_enabled')) {
         $this->rules['/search/<page:\\d+>'] = '/site/search';
         $this->rules['/search'] = '/site/search';
     }
     // Append our cache rules BEFORE we run the defaults
     $this->rules['<controller:\\w+>/<action:\\w+>/<id:\\d+>'] = '<controller>/<action>';
     $this->rules['<controller:\\w+>/<action:\\w+>'] = '<controller>/<action>';
     return parent::processRules();
 }
コード例 #18
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))));
 }
コード例 #19
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;
 }
コード例 #20
0
ファイル: TsUrlManager.php プロジェクト: nilojan/yii-cms
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if ($route !== 'tstranslation') {
         if ($this->showLangInUrl) {
             if (empty($params['_lang'])) {
                 $params['_lang'] = Yii::app()->language;
             }
         } else {
             if (isset($params['_lang'])) {
                 unset($params['_lang']);
             }
         }
     } else {
         $params = array();
     }
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #21
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);
 }
コード例 #22
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;
 }
コード例 #23
0
 /**
  * Overrides processRules, allowing us to inject our own ruleset into the URL Manager
  * Takes no parameters
  **/
 protected function processRules()
 {
     $this->cache = !YII_DEBUG;
     // Generate the clientRules
     $this->rules = $this->cache ? Yii::app()->cache->get('CiiMS::Routes') : array();
     if ($this->rules == false || empty($this->rules)) {
         $this->rules = array();
         $this->rules = $this->generateClientRules();
         $this->rules = CMap::mergearray($this->addRssRules(), $this->rules);
         $this->rules = CMap::mergeArray($this->addModuleRules(), $this->rules);
         Yii::app()->cache->set('CiiMS::Routes', $this->rules);
     }
     // Append our cache rules BEFORE we run the defaults
     $this->rules['<controller:\\w+>/<action:\\w+>/<id:\\d+>'] = '<controller>/<action>';
     $this->rules['<controller:\\w+>/<action:\\w+>'] = '<controller>/<action>';
     return parent::processRules();
 }
コード例 #24
0
ファイル: UrlManager.php プロジェクト: rosko/Tempo-CMS
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if (!isset($params['language'])) {
         if (Yii::app()->language != Yii::app()->settings->getValue('language')) {
             $params['language'] = Yii::app()->language;
         }
     } else {
         if ($params['language'] == Yii::app()->settings->getValue('language')) {
             unset($params['language']);
         }
     }
     if (isset($params['pageId']) && $params['pageId'] == 1) {
         $tmp = $params;
         unset($tmp['pageId'], $tmp['language'], $tmp['alias'], $tmp['url']);
         if (empty($tmp)) {
             return Yii::app()->homeUrl;
         } else {
             $params = $tmp;
         }
     }
     if (!isset($params['alias']) && isset($params['pageId'])) {
         $params['alias'] = '';
     }
     if ($this->getUrlFormat() == self::GET_FORMAT) {
         unset($params['alias']);
         unset($params['url']);
     }
     if (!empty($params['url'])) {
         if (substr($params['url'], 0, 1) == '/') {
             $params['url'] = substr($params['url'], 1);
         }
         $tmp = explode('/', $params['url']);
         if ($tmp[count($tmp) - 1] == '') {
             unset($params['url']);
         }
     }
     if ($this->fullUrl && !empty($params['url'])) {
         unset($params['alias']);
         unset($params['pageId']);
     } else {
         unset($params['url']);
     }
     $ret = parent::createUrl($route, $params, $ampersand);
     $ret = str_ireplace('%2F', '/', $ret);
     return $ret;
 }
コード例 #25
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if ($route == 'detail/index') {
         if ($params['cate_id'] == 20) {
             $route = 'review/index';
             $all_params['alias'] = $params['alias'];
         } else {
             $all_params['alias'] = $params['alias'];
         }
         $params = $all_params;
     }
     if ($route == 'category/index') {
         if ($params['alias'] == 'how-to') {
             return '/how-to.html';
         }
     }
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #26
0
 /**
  * Creates a URL based on default settings.
  *
  * @param string $route
  * @param array $params
  * @param string $ampersand
  * @return string
  */
 protected function createUrlDefault($route, $params, $ampersand)
 {
     if (!is_admin() || $this->getUrlFormat() === self::PATH_FORMAT) {
         return parent::createUrlDefault($route, $params, $ampersand);
     }
     $url = $this->getBaseUrl();
     if (isset($params['page'])) {
         unset($params['page']);
     }
     if ($route !== '') {
         $url .= '_' . str_replace('/', '_', $route);
         if (($query = $this->createPathInfo($params, '=', $ampersand)) !== '') {
             $url .= $ampersand . $query;
         }
     } elseif (($query = $this->createPathInfo($params, '=', $ampersand)) !== '') {
         $url .= '&' . $query;
     }
     return $url;
 }
コード例 #27
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;
 }
コード例 #28
0
ファイル: UrlManager.php プロジェクト: DarkAiR/test
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     // Формируем стандартный URL без языка
     $url = parent::createUrl($route, $params, $ampersand);
     $domains = explode('/', ltrim($url, '/'));
     if (in_array($domains[0], array_keys(Yii::app()->params['languages']))) {
         if ($domains[0] == Yii::app()->sourceLanguage) {
             // Вырезем из урла дефолтный язык
             array_shift($domains);
             $url = '/' . implode('/', $domains);
         } else {
             // В урле задан язык, отличный от дефолтного, ничего делать не надо
         }
     } else {
         if (Yii::app()->language != Yii::app()->sourceLanguage) {
             // Язык не задан в урле, добавляем его
             array_unshift($domains, Yii::app()->language);
             $url = '/' . implode('/', $domains);
         } else {
             // Язык не задан, но он дефолтный, ничего подставлять не надо
         }
     }
     return $url;
 }
コード例 #29
0
ファイル: ELangCUrlManager.php プロジェクト: bafio89/qea-u
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     /*if (!isset($params['lang']))
       $params['lang']=Yii::app()->GetLanguage();*/
     return parent::createUrl($route, $params, $ampersand);
 }
コード例 #30
0
 /**
  * Parses a URL based on this rule.
  * @param CUrlManager $manager the URL manager
  * @param CHttpRequest $request the request object
  * @param string $pathInfo path info part of the URL
  * @param string $rawPathInfo path info that contains the potential URL suffix
  * @return mixed the route that consists of the controller ID and action ID or false on error
  */
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     if ($this->verb !== null && !in_array($request->getRequestType(), $this->verb, true)) {
         return false;
     }
     if ($manager->caseSensitive && $this->caseSensitive === null || $this->caseSensitive) {
         $case = '';
     } else {
         $case = 'i';
     }
     if ($this->urlSuffix !== null) {
         $pathInfo = $manager->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
     }
     // URL suffix required, but not found in the requested URL
     if ($manager->useStrictParsing && $pathInfo === $rawPathInfo) {
         $urlSuffix = $this->urlSuffix === null ? $manager->urlSuffix : $this->urlSuffix;
         if ($urlSuffix != '' && $urlSuffix !== '/') {
             return false;
         }
     }
     if ($this->hasHostInfo) {
         $pathInfo = strtolower($request->getHostInfo()) . rtrim('/' . $pathInfo, '/');
     }
     $pathInfo .= '/';
     if (preg_match($this->pattern . $case, $pathInfo, $matches)) {
         foreach ($this->defaultParams as $name => $value) {
             if (!isset($_GET[$name])) {
                 $_REQUEST[$name] = $_GET[$name] = $value;
             }
         }
         $tr = array();
         foreach ($matches as $key => $value) {
             if (isset($this->references[$key])) {
                 $tr[$this->references[$key]] = $value;
             } elseif (isset($this->params[$key])) {
                 $_REQUEST[$key] = $_GET[$key] = $value;
             }
         }
         if ($pathInfo !== $matches[0]) {
             // there're additional GET params
             $manager->parsePathInfo(ltrim(substr($pathInfo, strlen($matches[0])), '/'));
         }
         if ($this->routePattern !== null) {
             return strtr($this->route, $tr);
         } else {
             return $this->route;
         }
     } else {
         return false;
     }
 }