findByUrl() public static method

public static findByUrl ( $url )
 /**
  * Reverse route
  *
  * @param array $url Array of parameters to convert to a string.
  * @return mixed either false or a string URL.
  */
 public function match($url)
 {
     // フロント以外のURLの場合にマッチしない
     if (!empty($url['admin'])) {
         return false;
     }
     // プラグイン確定
     if (empty($url['plugin'])) {
         $plugin = 'Core';
     } else {
         $plugin = Inflector::camelize($url['plugin']);
     }
     // アクション確定
     if (!empty($url['action'])) {
         $action = $url['action'];
     } else {
         $action = 'index';
     }
     $params = $url;
     unset($params['plugin']);
     unset($params['controller']);
     unset($params['action']);
     unset($params['entityId']);
     // コンテンツタイプ確定、できなければスルー
     $type = $this->_getContentTypeByParams($url);
     if ($type) {
         unset($params['action']);
     } else {
         $type = $this->_getContentTypeByParams($url, false);
     }
     if (!$type) {
         return false;
     }
     // エンティティID確定
     $entityId = $contentId = null;
     if (isset($url['entityId'])) {
         $entityId = $url['entityId'];
     } else {
         $request = Router::getRequest(true);
         if (!empty($request->params['entityId'])) {
             $entityId = $request->params['entityId'];
         }
         if (!empty($request->params['Content']['alias_id'])) {
             $contentId = $request->params['Content']['id'];
         }
     }
     // コンテンツ確定、できなければスルー
     if ($type == 'Page') {
         $pass = [];
         foreach ($params as $key => $param) {
             if (!is_string($key)) {
                 $pass[] = $param;
                 unset($params[$key]);
             }
         }
         $strUrl = '/' . implode('/', $pass);
     } else {
         $Content = ClassRegistry::init('Content');
         if ($contentId) {
             $conditions = ['Content.id' => $contentId];
         } else {
             $conditions = ['Content.plugin' => $plugin, 'Content.type' => $type, 'Content.entity_id' => $entityId];
         }
         $strUrl = $Content->field('url', $conditions);
     }
     if (!$strUrl) {
         return false;
     }
     // URL生成
     $site = BcSite::findByUrl($strUrl);
     if ($site && $site->useSubDomain) {
         $strUrl = preg_replace('/^\\/' . preg_quote($site->alias, '/') . '\\//', '/', $strUrl);
     }
     $pass = [];
     $named = [];
     $setting = Configure::read('BcContents.items.' . $plugin . '.' . $type);
     if (!$params) {
         if (empty($setting['omitViewAction']) && $setting['routes']['view']['action'] != $action) {
             $strUrl .= '/' . $action;
         }
     } else {
         if (empty($setting['omitViewAction'])) {
             $strUrl .= '/' . $action;
         }
         foreach ($params as $key => $param) {
             if (!is_numeric($key)) {
                 if ($key == 'page' && !$param) {
                     $param = 1;
                 }
                 if (!is_array($param)) {
                     $named[] = $key . ':' . $param;
                 }
             } else {
                 $pass[] = $param;
             }
         }
     }
     if ($pass) {
         $strUrl .= '/' . implode('/', $pass);
     }
     if ($named) {
         $strUrl .= '/' . implode('/', $named);
     }
     return $strUrl;
 }
Beispiel #2
0
 /**
  * ページファイルのパスを取得する
  * 
  * @param array $data
  * @return string
  */
 public function getPageFilePath($data)
 {
     $path = APP . 'View' . DS . 'Pages' . DS;
     if (!is_dir($path)) {
         mkdir($path);
         chmod($path, 0777);
     }
     $url = $this->Content->createUrl($data['Content']['parent_id'], 'Core', 'ContentFolder');
     if ($url != '/') {
         if ($data['Content']['site_id'] != 0) {
             $site = BcSite::findByUrl($url);
             if ($site) {
                 $url = preg_replace('/^\\/' . preg_quote($site->alias, '/') . '\\//', '/' . $site->name . '/', $url);
             }
         }
         $urlAry = explode('/', preg_replace('/(^\\/|\\/$)/', '', $url));
         foreach ($urlAry as $value) {
             $path .= $value . DS;
             if (!is_dir($path)) {
                 mkdir($path, 0777);
                 chmod($path, 0777);
             }
         }
     }
     return $path . $data['Content']['name'] . Configure::read('BcApp.templateExt');
 }
Beispiel #3
0
 /**
  * URLを取得する
  *
  * @param $url
  * @param bool $useSubDomain
  * @return string
  */
 public function getUrl($url, $full = false, $useSubDomain = false)
 {
     if ($useSubDomain && !is_array($url)) {
         $subDomain = '';
         $site = BcSite::findByUrl($url);
         $originUrl = $url;
         if ($site) {
             $subDomain = $site->alias;
             $originUrl = preg_replace('/^\\/' . preg_quote($site->alias, '/') . '\\//', '/', $url);
         }
         if ($originUrl == '/') {
             $urlArray = [];
         } else {
             $urlArray = explode('/', preg_replace('/(^\\/|\\/$)/', '', $originUrl));
         }
         if (preg_match('/\\/$/', $url) && count($urlArray) > 0) {
             $originUrl .= '/';
         }
         if ($full) {
             $fullUrl = fullUrl($originUrl);
             if (BcUtil::isAdminSystem()) {
                 if ($site->domainType == 1) {
                     $fullUrlArray = explode('//', $fullUrl);
                     return $fullUrlArray[0] . '//' . $subDomain . '.' . $fullUrlArray[1];
                 } elseif ($site->domainType == 2) {
                     $fullUrlArray = explode('//', $fullUrl);
                     $urlArray = explode('/', $fullUrlArray[1]);
                     unset($urlArray[0]);
                     if ($site->sameMainUrl) {
                         $mainSite = BcSite::findById($site->mainSiteId);
                         $subDomain = $mainSite->alias;
                     }
                     return $fullUrlArray[0] . '//' . $subDomain . '/' . implode('/', $urlArray);
                 }
             } else {
                 return $fullUrl;
             }
         } else {
             return Router::url($originUrl);
         }
     } else {
         if (BC_INSTALLED) {
             if (!is_array($url)) {
                 $site = BcSite::findByUrl($url);
                 if ($site && $site->sameMainUrl) {
                     $mainSite = BcSite::findById($site->mainSiteId);
                     $alias = $mainSite->alias;
                     if ($alias) {
                         $alias = '/' . $alias;
                     }
                     $url = $alias . $site->getPureUrl($url);
                 }
             }
         }
         if ($full) {
             return fullUrl($url);
         } else {
             return Router::url($url);
         }
     }
 }
 /**
  * ビューを表示する
  *
  * @param mixed
  * @return void
  */
 public function display()
 {
     // CUSTOMIZE DELETE 2016/10/05 ryuring
     $path = func_get_args();
     // CUSTOMIZE ADD 2014/07/02 ryuring
     // >>>
     if ($this->request->params['Content']['alias_id']) {
         $urlTmp = $this->Content->field('url', ['Content.id' => $this->request->params['Content']['alias_id']]);
     } else {
         $urlTmp = $this->request->params['Content']['url'];
     }
     if ($this->request->params['Site']['alias']) {
         $site = BcSite::findByUrl($urlTmp);
         if ($site && $site->alias == $this->request->params['Site']['alias']) {
             $urlTmp = preg_replace('/^\\/' . preg_quote($site->alias, '/') . '\\//', '/' . $this->request->params['Site']['name'] . '/', $urlTmp);
         }
     }
     $urlTmp = preg_replace('/^\\//', '', $urlTmp);
     $path = explode('/', $urlTmp);
     $count = count($path);
     if (!$count) {
         $this->redirect('/');
     }
     $page = $subpage = $titleForLayout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $titleForLayout = Inflector::humanize($path[$count - 1]);
     }
     // <<<
     $this->set(array('page' => $page, 'subpage' => $subpage, 'title_for_layout' => $titleForLayout));
     // CUSTOMIZE ADD 2014/07/02 ryuring
     // >>>
     $previewCreated = false;
     if ($this->request->data) {
         if ($this->BcContents->preview == 'default') {
             $uuid = $this->_createPreviewTemplate($this->request->data);
             $this->set('previewTemplate', TMP . 'pages_preview_' . $uuid . $this->ext);
             $previewCreated = true;
         }
     }
     $page = $this->Page->find('first', ['conditions' => ['Page.id' => $this->request->params['Content']['entity_id']], 'recursive' => -1]);
     $template = $page['Page']['page_template'];
     $pagePath = implode('/', $path);
     if (!$template) {
         $ContentFolder = ClassRegistry::init('ContentFolder');
         $template = $ContentFolder->getParentTemplate($this->request->params['Content']['id'], 'page');
     }
     $this->set('pagePath', $pagePath);
     // <<<
     try {
         // CUSTOMIZE MODIFY 2014/07/02 ryuring
         // >>>
         //$this->render(implode('/', $path));
         // ---
         $this->render('templates/' . $template);
         if ($previewCreated) {
             @unlink(TMP . 'pages_preview_' . $uuid . $this->ext);
         }
         // <<<
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
 }