《注意》by ryuring
処理の内容にCakeRequest や、Router::parse() を使おうとしたが、
Router::parse() を利用すると、Routing情報が書き換えられてしまうので利用できない。
Router::reload() や、Router::setRequestInfo() で調整しようとしたがうまくいかなかった。
public static isAdminSystem ( $url = null ) : boolean | ||
return | boolean |
/** * Form After Submit * * フォームの保存ボタンの前後に、一覧、プレビュー、削除ボタンを配置する * プレビューを配置する場合は、設定にて、preview を true にする * * @param CakeEvent $event * @return string */ public function formAfterSubmit(CakeEvent $event) { if (!BcUtil::isAdminSystem()) { return; } $View = $event->subject(); $data = $View->request->data; if (!preg_match('/(AdminEditForm|AdminEditAliasForm)$/', $event->data['id'])) { return; } $output = $View->BcHtml->link('一覧に戻る', array('plugin' => '', 'admin' => true, 'controller' => 'contents', 'action' => 'index'), array('class' => 'button')); $setting = Configure::read('BcContents.items.' . $data['Content']['plugin'] . '.' . $data['Content']['type']); if (!empty($setting['preview']) && $data['Content']['type'] != 'ContentFolder') { $output .= "\n" . $View->BcForm->button('プレビュー', array('class' => 'button', 'id' => 'BtnPreview')); } $output .= $event->data['out']; if (empty($data['Content']['site_root'])) { if ($data['Content']['alias_id']) { $deleteText = '削除'; } else { $deleteText = 'ゴミ箱へ移動'; } $output .= $View->BcForm->button($deleteText, array('class' => 'button', 'id' => 'BtnDelete')); } return $output; }
/** * formAfterInput * * @param CakeEvent $event * @return string */ public function formAfterInput(CakeEvent $event) { if (!BcUtil::isAdminSystem()) { return $event->data['out']; } $View = $event->subject(); if (!in_array($View->request->params['controller'], $this->targetController)) { return $event->data['out']; } if (!in_array($View->request->params['action'], $this->targetAction)) { return $event->data['out']; } if (!isset($View->request->data['KeywordConfig'])) { return $event->data['out']; } if (!$View->request->data['KeywordConfig']['status']) { return $event->data['out']; } // 固定ページ:入力欄の下にキーワード入力欄を表示する if ($event->data['fieldName'] == 'Page.description') { $event->data['out'] = $event->data['out'] . $View->element('Keyword.keyword_form'); } // ブログ記事:記事タイトル入力欄の下にキーワード入力欄を表示する if ($event->data['fieldName'] == 'BlogPost.name') { $event->data['out'] = $event->data['out'] . $View->element('Keyword.keyword_form'); } return $event->data['out']; }
/** * beforeFilter * * @return void */ public function beforeFilter() { parent::beforeFilter(); $this->BcAuth->allow('add', 'captcha', 'smartphone_add', 'smartphone_captcha', 'get_token'); if (BcUtil::isAdminSystem()) { $this->subMenuElements = array('blog_posts'); $this->request->params['Content'] = $this->BcContents->getContent($this->request->params['pass'][0])['Content']; $this->Security->enabled = true; $this->Security->requireAuth('add'); } $crumbs = array(); if (!empty($this->params['pass'][1])) { $dbDatas = $this->BlogPost->find('first', ['conditions' => ['BlogPost.id' => $this->params['pass'][1]]]); if (!$dbDatas) { $this->notFound(); } $this->blogPost = array('BlogPost' => $dbDatas['BlogPost']); $this->blogContent = array('BlogContent' => $dbDatas['BlogContent']); if (BcUtil::isAdminSystem()) { $crumbs[] = array('name' => $this->request->params['Content']['title'] . '設定', 'url' => array('controller' => 'blog_posts', 'action' => 'index', $this->blogContent['BlogContent']['id'])); $crumbs[] = array('name' => $this->blogPost['BlogPost']['name'], 'url' => array('controller' => 'blog_posts', 'action' => 'edit', $this->blogContent['BlogContent']['id'], $this->blogPost['BlogPost']['id'])); } } elseif (!empty($this->params['pass'][0])) { if (!in_array($this->request->action, ['captcha', 'smartphone_captcha', 'get_token'])) { $dbDatas = $this->BlogPost->BlogContent->find('first', ['conditions' => ['BlogContent.id' => $this->params['pass'][0]]]); $this->blogContent = array('BlogContent' => $dbDatas['BlogContent']); if (BcUtil::isAdminSystem()) { $crumbs[] = array('name' => $this->request->params['Content']['title'] . '設定', 'url' => array('controller' => 'blog_posts', 'action' => 'index', $this->blogContent['BlogContent']['id'])); } } } $this->crumbs = array_merge($this->crumbs, $crumbs); }
/** * beforeFilter * * @return void */ public function beforeFilter() { parent::beforeFilter(); // 認証設定 $this->BcAuth->allow('search', 'mobile_search', 'smartphone_search'); if (!empty($this->request->params['admin'])) { $this->crumbs = array(array('name' => 'システム設定', 'url' => array('controller' => 'site_configs', 'action' => 'form')), array('name' => '検索インデックス管理', 'url' => array('controller' => 'search_indices', 'action' => 'index'))); } if (!BcUtil::isAdminSystem()) { $Content = ClassRegistry::init('Content'); $currentSite = BcSite::findCurrent(true); $url = '/'; if ($this->request->params['action'] != 'search') { $prefix = str_replace('_search', '', $this->request->params['action']); if ($prefix == $currentSite->name) { $url = '/' . $currentSite->alias . '/'; $this->request->params['action'] = 'search'; $this->action = 'search'; } } $content = $Content->find('first', ['conditions' => ['Content.url' => $url], 'recursive' => 0]); $this->request->params['Content'] = $content['Content']; $this->request->params['Site'] = $content['Site']; } }
/** * After Render * * @param CakeEvent $event */ public function afterRender(CakeEvent $event) { if (BcUtil::isAdminSystem()) { return; } $View = $event->subject(); $this->_execShortCode($View); }
/** * Constructor. * * @return void * @access public */ public function __construct(View $View, $settings = array()) { parent::__construct($View, $settings); $this->_Content = ClassRegistry::init('Content'); $this->_Permission = ClassRegistry::init('Permission'); if (BcUtil::isAdminSystem()) { $this->setup(); } }
/** * blogBlogPostBeforeRender * * @param CakeEvent $event */ public function blogBlogPostsBeforeRender(CakeEvent $event) { if (!BcUtil::isAdminSystem()) { return; } $View = $event->subject(); if (in_array($View->request->params['action'], $this->targetAction)) { $this->setUpModel(); $data = $this->KeywordConfigModel->find('first', array('conditions' => array('KeywordConfig.model' => 'BlogContent', 'KeywordConfig.content_id' => $View->viewVars['blogContent']['BlogContent']['id']))); if ($data) { $View->request->data['KeywordConfig'] = $data['KeywordConfig']; } } }
/** * beforeLayout * * @param CakeEvent $event * @return boolean */ public function beforeLayout(CakeEvent $event) { if (BcUtil::isAdminSystem()) { return true; } $View = $event->subject; // ユーザ(サイト制作者)定義CSSの自動読込 $userCssList = array(); // themeのcss優先 if (file_exists(WWW_ROOT . 'theme' . DS . Configure::read('BcSite.theme') . DS . 'css' . DS . 'bge_style.css')) { $userCssList[] = "bge_style.css"; // themeになく、webroot/cssにあれば読込 } elseif (file_exists(WWW_ROOT . 'css' . DS . 'bge_style.css')) { $userCssList[] = "bge_style.css"; // themeになく、webroot/cssにもない場合、プラグイン標準のファイルを読み込む } else { $userCssList[] = 'BurgerEditor.bge_style'; } // colorbox用スタイル $userCssList[] = 'BurgerEditor.colorbox'; if ($userCssList) { $View->BcBaser->css($userCssList, array('inline' => false)); } // JSの自動読込 $jsList = array(); // デバックモードの場合は圧縮前のJSを読み込む if (Configure::read('debug')) { $jsList[] = 'BurgerEditor.bge_modules/bge_functions.js'; } else { $jsList[] = 'BurgerEditor.bge_modules/bge_functions.min.js'; } // jquery.colorbox.jsの自動読み込み $jsList[] = 'BurgerEditor.bge_modules/jquery.colorbox-min.js'; // google map APIの読込 $jsList[] = '//maps.google.com/maps/api/js?sensor=false'; if ($jsList) { $View->BcBaser->js($jsList, false); } return true; }
public function afterLayout(CakeEvent $event) { $View = $event->subject(); if (!BcUtil::isAdminSystem() || $View->name == 'CakeError') { return; } $this->BcHtml = $View->BcHtml; if (isset($View->BcCkeditor)) { if (preg_match_all("/(editor_[a-z0-9_]*?)\\s*?=\\s*?CKEDITOR\\.replace/s", $View->output, $matches)) { /* ckeditor_uploader.js を読み込む */ $jscode = $this->BcHtml->scriptBlock("var baseUrl ='" . $View->request->base . "/';"); $jscode .= $this->BcHtml->scriptBlock("var adminPrefix ='" . Configure::read('Routing.prefixes.0') . "';"); $jscode .= $this->BcHtml->script('Uploader.admin/libs/ckeditor_uploader'); $View->output = str_replace('</head>', $jscode . '</head>', $View->output); /* CSSを読み込む */ // 適用の優先順位の問題があるので、bodyタグの直後に読み込む $css = $this->BcHtml->css('Uploader.uploader'); $View->output = str_replace('</body>', $css . '</body>', $View->output); /* VIEWのCKEDITOR読込部分のコードを書き換える */ foreach ($matches[1] as $match) { $jscode = $this->__getCkeditorUploaderScript($match); $pattern = "/<script type=\"text\\/javascript\">[\\s\n]*?\\/\\/<\\!\\[CDATA\\[[\\s\n]*?([\$]\\(window\\)\\.load.+?" . $match . "\\s=\\sCKEDITOR\\.replace.*?)\\/\\/\\]\\]>\n*?<\\/script>/s"; $output = preg_replace($pattern, $this->BcHtml->scriptBlock("\$1" . $jscode), $View->output); if (!is_null($output)) { $View->output = $output; } } /* 通常の画像貼り付けダイアログを画像アップローダーダイアログに変換する */ $pattern = "/(CKEDITOR\\.replace.*?\"toolbar\".*?)\"Image\"(.*?);/is"; $View->output = preg_replace($pattern, "\$1" . '"BaserUploader"' . "\$2;", $View->output); } } if (!empty($View->request->params['prefix']) && $View->request->params['prefix'] == 'mobile') { /* モバイル画像に差し替える */ $aMatch = "/<array([^>]*?)href=\"([^>]*?)\"([^>]*?)><img([^>]*?)\\/><\\/a>/is"; $imgMatch = "/<img([^>]*?)src=\"([^>]*?)\"([^>]*?)\\/>/is"; $View->output = preg_replace_callback($aMatch, array($this, "__mobileImageAnchorReplace"), $View->output); $View->output = preg_replace_callback($imgMatch, array($this, "__mobileImageReplace"), $View->output); } }
/** * */ public function beforeRender(CakeEvent $event) { if (BcUtil::isAdminSystem()) { return; } $View = $event->subject(); if (!empty($View->BcBaser)) { $View->BcBaser->js('Suggest.jquery.autocomplete', false); $View->BcBaser->css('Suggest.jquery.autocomplete', array('inline' => false)); $url = $View->BcBaser->getUrl('/suggest/suggest/ajax_keyword'); $script = <<<DOC_END \$(document).ready(function(){ \$('#ContentQ').autocomplete('{$url}',{ \t\tscroll:false, \t\tonItemSelect:function(){ \t\t\t\$("#ContentSearchForm").submit(); \t\t} \t}); }); DOC_END; $View->BcHtml->scriptBlock($script, array('inline' => false)); } }
/** * 現在のURLを正規化して取得する * * $this->request->here は、ビューキャッシュの命名規則に影響する為、 * CacheHelper 等で、このメソッドを利用する事で、同一ページによる複数キャッシュの生成を防ぐ * * (例) * /news/ → /news/index * /company/ → /company/index * * @return string */ public function normalizedHere() { $here = $this->here; if (!BcUtil::isAdminSystem() && $this->params['controller'] == 'pages') { if (!empty($this->params['pass']) && $this->params['pass'][count($this->params['pass']) - 1] == 'index' && !preg_match('/\\/index$/', $here)) { if (preg_match('/\\/$/', $here)) { $here .= 'index'; } else { $here .= '/index'; } } $here = preg_replace('/\\.html$/', '', $here); } else { if ($this->action == 'index') { list($here, ) = explode('?', $here); if (!empty($this->params['pass'])) { foreach ($this->params['pass'] as $pass) { $here = preg_replace('/\\/' . $pass . '$/', '', $here); } } if (!preg_match('/\\/index$/', $here)) { if (preg_match('/\\/$/', $here)) { $here .= 'index'; } else { $here .= '/index'; } } } } return $here; }
/** * Parses a string URL into an array. If a plugin key is found, it will be copied to the * controller parameter * * @param string $url The URL to parse * @return mixed false on failure, or an array of request parameters */ public function parse($url) { if (is_array($url)) { return false; } if (BcUtil::isAdminSystem($url)) { return false; } $request = Router::getRequest(true); //管理システムにログインしているかつプレビューの場合は公開状態のステータスは無視する $publish = true; if (!empty($request->query['preview']) || !empty($request->query['force'])) { $publish = false; } $sameUrl = false; $site = BcSite::findCurrentSub(true); if ($site) { // 同一URL対応 $sameUrl = true; $checkUrl = $site->makeUrl($request); @header('Vary: User-Agent'); } else { $site = BcSite::findCurrent(true); if (!is_null($site->name)) { if ($site->useSubDomain) { $checkUrl = '/' . $site->alias . ($url ? $url : '/'); } else { $checkUrl = $url ? $url : '/'; } } else { if (!empty($request->query['force']) && BcUtil::isAdminUser()) { // ================================================================================================= // 2016/11/10 ryuring // 別ドメインの際に、固定ページのプレビューで、正しくサイト情報を取得できない。 // そのため、文字列でリクエストアクションを送信し、URLでホストを判定する。 // ================================================================================================= $tmpSite = BcSite::findByUrl($url); if (!is_null($tmpSite)) { $site = $tmpSite; } } $checkUrl = $url ? $url : '/'; } } $content = $this->getContent($checkUrl, $publish, false, $sameUrl, $site->useSubDomain); if (!$content) { $content = $this->getContent($checkUrl, $publish, true, $sameUrl, $site->useSubDomain); } if (!$content) { return false; } // データが存在してもプレビューで管理システムにログインしていない場合はログイン画面に遷移 if ((!empty($request->query['preview']) || !empty($request->query['force'])) && !BcUtil::loginUser()) { $_SESSION['Auth']['redirect'] = $_SERVER['REQUEST_URI']; header('Location: ' . topLevelUrl(false) . baseUrl() . Configure::read('BcAuthPrefix.admin.alias') . '/users/login'); exit; } $Content = ClassRegistry::init('Content'); if ($content['Content']['alias_id'] && !$Content->isPublishById($content['Content']['alias_id'])) { return false; } $request->params['Content'] = $content['Content']; $request->params['Site'] = $content['Site']; $url = $site->getPureUrl($url); $params = $this->getParams($url, $content['Content']['url'], $content['Content']['plugin'], $content['Content']['type'], $content['Content']['entity_id'], $site->alias); if ($params) { return $params; } return false; }
/** * 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 string $url 対象URL * @param bool $expect 期待値 * @dataProvider isAdminSystemDataProvider */ public function testIsAdminSystem($url, $expect) { $this->_getRequest($url); $result = BcUtil::isAdminSystem(); $this->assertEquals($expect, $result, '正しく管理システムかチェックできません'); }
/** * After Render * * @param string $viewFile */ public function afterRender($viewFile) { parent::afterRender($viewFile); if (BcUtil::isAdminSystem()) { return; } if (empty($this->request->params['Site'])) { return; } if (isset($this->request->params['Site']['name']) && is_null($this->request->params['Site']['name'])) { return; } if (isset($this->request->params['Site']['device']) && $this->request->params['Site']['device'] != '') { return; } // 別URLの場合、alternateを出力(スマートフォンのみ対応) $pureUrl = $this->BcContents->getPureUrl($this->request->url, $this->request->params['Site']['id']); $agent = BcAgent::find('smartphone'); $subSite = BcSite::findCurrentSub(false, $agent); if (!$subSite) { return; } $url = $subSite->makeUrl(new CakeRequest($pureUrl)); $this->_View->set('meta', $this->BcHtml->meta('canonical', $this->BcHtml->url($url, true), ['rel' => 'canonical', 'media' => 'only screen and (max-width: 640px)', 'type' => null, 'title' => null, 'inline' => false])); }
/** * blogBlogBeforeRender * * @param CakeEvent $event */ public function blogBlogBeforeRender(CakeEvent $event) { $Controller = $event->subject(); if (BcUtil::isAdminSystem()) { // 管理側でプレビューの際に入力中のキーワードデータを送る // XXX 固定ページのプレビューの場合、pagesBeforeRender がそのまま反映されるためそちらは処理不要 if ($Controller->preview) { if (!empty($Controller->request->data['Keyword'])) { $Controller->viewVars['Keyword'] = $Controller->request->data['Keyword']; } } return; } if ($Controller->request->params['action'] != 'archives') { return; } if (count($Controller->request->params['pass']) != 1) { return; } if (!empty($Controller->viewVars['post'])) { // ブログ記事のデータを元に、キーワードデータを取得する $keyword = $Controller->BlogPost->Keyword->find('first', array('conditions' => array('Keyword.model' => 'BlogPost', 'Keyword.model_id' => $Controller->viewVars['post']['BlogPost']['id']))); if ($keyword) { $Controller->viewVars['keywords'] = $keyword['Keyword']['keywords']; $Controller->viewVars['Keyword'] = $keyword['Keyword']; } } }
/** * beforeRender * * @return void */ public function beforeRender() { parent::beforeRender(); $favoriteBoxOpened = false; if (BcUtil::isAdminSystem()) { $this->__updateFirstAccess(); if (!empty($this->BcAuth) && !empty($this->request->url) && $this->request->url != 'update') { $user = $this->BcAuth->user(); if ($user) { if ($this->Session->check('Baser.favorite_box_opened')) { $favoriteBoxOpened = $this->Session->read('Baser.favorite_box_opened'); } else { $favoriteBoxOpened = true; } } } } else { // テーマのヘルパーをセット if (BC_INSTALLED) { $this->setThemeHelpers(); // ショートコード App::uses('BcShortCodeEventListener', 'Event'); CakeEventManager::instance()->attach(new BcShortCodeEventListener()); } } // テンプレートの拡張子 // RSSの場合、RequestHandlerのstartupで強制的に拡張子を.ctpに切り替えられてしまう為、 // beforeRenderでも再設定する仕様にした $this->ext = Configure::read('BcApp.templateExt'); // モバイルでは、mobileHelper::afterLayout をフックしてSJISへの変換が必要だが、 // エラーが発生した場合には、afterLayoutでは、エラー用のビューを持ったviewクラスを取得できない。 // 原因は、エラーが発生する前のcontrollerがviewを登録してしまっている為。 // エラー時のview登録にフックする場所はここしかないのでここでviewの登録を削除する if ($this->name == 'CakeError') { ClassRegistry::removeObject('view'); $this->response->disableCache(); } $this->__loadDataToView(); $this->set('favoriteBoxOpened', $favoriteBoxOpened); $this->set('isSSL', $this->request->is('ssl')); $this->set('safeModeOn', ini_get('safe_mode')); $this->set('baserVersion', $this->getBaserVersion()); $this->set('siteConfig', $this->siteConfigs); if (isset($this->siteConfigs['widget_area'])) { $this->set('widgetArea', $this->siteConfigs['widget_area']); } }
/** * コンテンツ内で設定した CSS や javascript をレイアウトテンプレートに出力し、ログイン中の場合、ツールバー用のCSSも出力する * また、テーマ用のCSSが存在する場合には出力する * * 利用する際は、</head>タグの直前あたりに記述する。 * コンテンツ内で、レイアウトテンプレートへの出力を設定する場合には、inline オプションを false にする * * 《利用例》 * $this->BcBaser->css('admin/layout', array('inline' => false)); * $this->BcBaser->js('admin/startup', false); * * @return void */ public function scripts() { $currentPrefix = $this->_View->get('currentPrefix'); $authPrefix = Configure::read('BcAuthPrefix.' . $currentPrefix); $toolbar = true; if (isset($authPrefix['toolbar'])) { $toolbar = $authPrefix['toolbar']; } $scripts = $this->_View->fetch('meta') . $this->_View->fetch('css') . $this->_View->fetch('script'); // TODO CakePHP では、 scripts_for_layout は deprecated となっているが後方互換の為残しておく // baserCMS 4系で除外予定 $scripts .= str_replace($scripts, '', $this->_View->get('scripts_for_layout')); echo $scripts; // ### ツールバー用CSS出力 // 《表示条件》 // - プレビューでない // - auth prefix の設定で、利用するように定義されている // - モバイルでない // - Query String で、toolbar=false に定義されていない // - 管理画面でない // - ログインしている if (empty($this->_View->viewVars['preview']) && $toolbar && !Configure::read('BcRequest.agent')) { if (!isset($this->request->query['toolbar']) || $this->request->query['toolbar'] !== false && $this->request->query['toolbar'] !== 'false') { if (empty($this->request->params['admin']) && !empty($this->_View->viewVars['user'])) { $this->css('admin/toolbar'); } } } // ### テーマ用CSS出力 // 《表示条件》 // - インストーラーではない // - /files/theme_configs/config.css が存在する if (!BcUtil::isAdminSystem() && $this->params['controller'] != 'installations' && file_exists(WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css')) { $this->css('/files/theme_configs/config'); } }
/** * URLにセッションIDを付加する * 既に付加されている場合は重複しない * * @param mixed $url * @return mixed */ function addSessionId($url, $force = false) { if (BcUtil::isAdminSystem()) { return $url; } $sessionId = session_id(); if (!$sessionId) { return $url; } // use_trans_sid が有効になっている場合、2重で付加されてしまう $site = BcSite::findCurrent(); if ($site && $site->device == 'mobile' && Configure::read('BcAgent.mobile.sessionId') && (!ini_get('session.use_trans_sid') || $force)) { if (is_array($url)) { $url["?"][session_name()] = $sessionId; } else { if (strpos($url, '?') !== false) { $args = array(); $_url = explode('?', $url); if (!empty($_url[1])) { if (strpos($_url[1], '&') !== false) { $aryUrl = explode('&', $_url[1]); foreach ($aryUrl as $pass) { if (strpos($pass, '=') !== false) { list($key, $value) = explode('=', $pass); $args[$key] = $value; } } } else { if (strpos($_url[1], '=') !== false) { list($key, $value) = explode('=', $_url[1]); $args[$key] = $value; } } } $args[session_name()] = $sessionId; $pass = ''; foreach ($args as $key => $value) { if ($pass) { $pass .= '&'; } $pass .= $key . '=' . $value; } $url = $_url[0] . '?' . $pass; } else { $url .= '?' . session_name() . '=' . $sessionId; } } } return $url; }
/** * Finds URL for specified action. * * Returns an URL pointing to a combination of controller and action. Param * $url can be: * + Empty - the method will find adress to actuall controller/action. * + '/' - the method will find base URL of application. * + A combination of controller/action - the method will find url for it. * * @param mixed $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" * or an array specifying any of the following: 'controller', 'action', * and/or 'plugin', in addition to named arguments (keyed array elements), * and standard URL arguments (indexed array elements) * @param boolean $full If true, the full base URL will be prepended to the result * @return string Full translated URL with base path. */ public function url($url = null, $full = false, $sessionId = true) { if ($sessionId) { $url = addSessionId($url); } //====================================================================== // FormHelper::createで id をキーとして使うので、ルーターでマッチしない場合がある。 // id というキー名を除外する事で対応。 //====================================================================== if (is_array($url) && isset($url['id'])) { array_push($url, $url['id']); unset($url['id']); } if (is_array($url) && !isset($url['admin']) && !empty($this->request->params['admin'])) { $url = array_merge($url, array('admin' => true)); } if (!is_array($url) && preg_match('/\\/(img|css|js|files)\\//', $url)) { return $this->webroot($url); } elseif (!is_array($url) && preg_match('/^javascript:/', $url)) { return $url; } else { if (!BcUtil::isAdminSystem() && !is_array($url) && !empty($this->request->params['Content'])) { $Content = ClassRegistry::init('Content'); $url = $Content->getUrl($url, $full, @$this->_View->request->params['Site']['use_subdomain']); } else { $url = parent::url($url, $full); } $params = explode('?', $url); $url = preg_replace('/\\/index$/', '/', $params[0]); if (!empty($params[1])) { $url .= '?' . $params[1]; } return $url; } }
* イベント登録 */ App::uses('CakeEventManager', 'Event'); App::uses('BcControllerEventDispatcher', 'Event'); App::uses('BcModelEventDispatcher', 'Event'); App::uses('BcViewEventDispatcher', 'Event'); App::uses('PagesControllerEventListener', 'Event'); $CakeEvent = CakeEventManager::instance(); $CakeEvent->attach(new BcControllerEventDispatcher()); $CakeEvent->attach(new BcModelEventDispatcher()); $CakeEvent->attach(new BcViewEventDispatcher()); $CakeEvent->attach(new PagesControllerEventListener()); /** * テーマの bootstrap を実行する */ if (!BcUtil::isAdminSystem()) { $themePath = WWW_ROOT . 'theme' . DS . Configure::read('BcSite.theme') . DS; $themeBootstrap = $themePath . 'Config' . DS . 'bootstrap.php'; if (file_exists($themeBootstrap)) { include $themeBootstrap; } } } /** * 文字コードの検出順を指定 */ mb_detect_order(Configure::read('BcEncode.detectOrder')); /** * メモリー設定 */ $memoryLimit = (int) ini_get('memory_limit');
/** * Before render * * @param Controller $controller * @return void */ public function beforeRender(Controller $controller) { parent::beforeRender($controller); if (BcUtil::isAdminSystem()) { $controller->set('contentsSettings', $this->settings['items']); // パンくずをセット array_unshift($controller->crumbs, array('name' => 'コンテンツ一覧', 'url' => array('plugin' => null, 'controller' => 'contents', 'action' => 'index'))); if ($controller->subMenuElements && !in_array('contents', $controller->subMenuElements)) { array_unshift($controller->subMenuElements, 'contents'); } else { $controller->subMenuElements = ['contents']; } if ($this->useForm && in_array($controller->request->action, [$this->editAction, 'admin_edit_alias']) && !empty($controller->request->data['Content'])) { // フォームをセット $this->settingForm($controller, $controller->request->data['Content']['site_id'], $controller->request->data['Content']['id']); // フォームを読み込む為のイベントを設定 // 内部で useForm を参照できない為、ここに記述。 // フォームの設定しかできないイベントになってしまっている。 // TODO 改善要 App::uses('BcContentsEventListener', 'Event'); CakeEventManager::instance()->attach(new BcContentsEventListener()); } } else { // ビューキャッシュ設定 if (empty($controller->request->query['preview'])) { // @deprecated 5.0.0 since 4.0.0 // CakePHP3では、ビューキャッシュは廃止となる為、別の方法に移行する if ($this->useViewCache && !BcUtil::loginUser('admin') && !isConsole() && !empty($controller->request->params['Content'])) { $controller->helpers[] = 'BcCache'; $controller->cacheAction = $controller->Content->getCacheTime($controller->request->params['Content']); } } } }