Example #1
0
 /**
  * aタグを取得するだけのラッパー
  * 
  * @param string $title
  * @param string $url
  * @param array $htmlAttributes
  * @param boolean $confirmMessage
  * @param boolean $escapeTitle
  * @return string
  * @access public
  */
 function getLink($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = false)
 {
     $htmlAttributes = $this->executeHook('beforeBaserGetLink', $title, $url, $htmlAttributes, $confirmMessage, $escapeTitle);
     if (!empty($htmlAttributes['prefix'])) {
         if (!empty($this->params['prefix'])) {
             $url[$this->params['prefix']] = true;
         }
         unset($htmlAttributes['prefix']);
     }
     if (isset($htmlAttributes['forceTitle'])) {
         $forceTitle = $htmlAttributes['forceTitle'];
         unset($htmlAttributes['forceTitle']);
     } else {
         $forceTitle = false;
     }
     if (isset($htmlAttributes['ssl'])) {
         $ssl = true;
         unset($htmlAttributes['ssl']);
     } else {
         $ssl = false;
     }
     // 管理システムメニュー対策
     // プレフィックスが変更された場合も正常動作させる為
     // TODO メニューが廃止になったら削除
     if (!is_array($url)) {
         $url = preg_replace('/^\\/admin\\//', '/' . Configure::read('Routing.admin') . '/', $url);
     }
     $url = $this->getUrl($url);
     $_url = preg_replace('/^' . preg_quote($this->base, '/') . '\\//', '/', $url);
     $enabled = true;
     // 認証チェック
     if (isset($this->Permission) && !empty($this->_view->viewVars['user']['user_group_id'])) {
         $userGroupId = $this->_view->viewVars['user']['user_group_id'];
         if (!$this->Permission->check($_url, $userGroupId)) {
             $enabled = false;
         }
     }
     // ページ公開チェック
     if (isset($this->Page) && empty($this->params['admin'])) {
         $adminPrefix = Configure::read('Routing.admin');
         if (isset($this->Page) && !preg_match('/^\\/' . $adminPrefix . '/', $_url)) {
             if ($this->Page->isPageUrl($_url) && !$this->Page->checkPublish($_url)) {
                 $enabled = false;
             }
         }
     }
     if (!$enabled) {
         if ($forceTitle) {
             return "<span>{$title}</span>";
         } else {
             return '';
         }
     }
     // 現在SSLのURLの場合、フルパスで取得
     if ($this->isSSL() || $ssl) {
         $_url = preg_replace("/^\\//", "", $_url);
         if (preg_match('/^admin\\//', $_url)) {
             $admin = true;
         } else {
             $admin = false;
         }
         if (Configure::read('App.baseUrl')) {
             $_url = 'index.php/' . $_url;
         }
         if (!$ssl && !$admin) {
             $url = Configure::read('BcEnv.siteUrl') . $_url;
         } else {
             $url = Configure::read('BcEnv.sslUrl') . $_url;
         }
     } else {
         $url = $_url;
     }
     // Cake1.2系との互換対応
     if (isset($htmlAttributes['escape']) && $escapeTitle == true) {
         $escapeTitle = $htmlAttributes['escape'];
     }
     if (!$htmlAttributes) {
         $htmlAttributes = array();
     }
     $htmlAttributes = array_merge($htmlAttributes, array('escape' => $escapeTitle));
     $out = $this->BcHtml->link($title, $url, $htmlAttributes, $confirmMessage);
     return $this->executeHook('afterBaserGetLink', $url, $out);
 }
Example #2
0
 /**
  * アンカータグを取得する
  *
  * @param string $title タイトル
  * @param mixed $url オプション(初期値 : null)
  * @param array $options オプション(初期値 : array())
  *	- `escape` : タイトルをエスケープするかどうか(初期値 : false)
  *  - `prefix` : URLにプレフィックスをつけるかどうか(初期値 : false)
  *	- `forceTitle` : 許可されていないURLの際にタイトルを強制的に出力するかどうか(初期値 : false)
  *	- `ssl` : SSL用のURLをして出力するかどうか(初期値 : false)
  *	 ※ その他のパラメータについては、HtmlHelper::image() を参照。
  * @param bool $confirmMessage 確認メッセージ(初期値 : false)
  *	リンクをクリックした際に確認メッセージが表示され、はいをクリックした場合のみ遷移する
  * @return string
  */
 public function getLink($title, $url = null, $options = array(), $confirmMessage = false)
 {
     $adminAlias = Configure::read('BcAuthPrefix.admin.alias');
     if (!is_array($options)) {
         $options = array($options);
     }
     $options = array_merge(array('escape' => false, 'prefix' => false, 'forceTitle' => false, 'ssl' => false), $options);
     /*** beforeGetLink ***/
     $event = $this->dispatchEvent('beforeGetLink', array('title' => $title, 'url' => $url, 'options' => $options, 'confirmMessage' => $confirmMessage), array('class' => 'Html', 'plugin' => ''));
     if ($event !== false) {
         $options = $event->result === null || $event->result === true ? $event->data['options'] : $event->result;
     }
     if ($options['prefix']) {
         if (!empty($this->request->params['prefix']) && is_array($url)) {
             $url[$this->request->params['prefix']] = true;
         }
     }
     $forceTitle = $options['forceTitle'];
     $ssl = $options['ssl'];
     unset($options['prefix']);
     unset($options['forceTitle']);
     unset($options['ssl']);
     // 管理システムメニュー対策
     // プレフィックスが変更された場合も正常動作させる為
     // TODO メニューが廃止になったら削除
     if (!is_array($url)) {
         $prefixes = Configure::read('Routing.prefixes');
         $url = preg_replace('/^\\/' . $adminAlias . '\\//', '/' . $prefixes[0] . '/', $url);
     }
     $_url = $this->getUrl($url);
     $_url = preg_replace('/^' . preg_quote($this->request->base, '/') . '\\//', '/', $_url);
     $enabled = true;
     if ($options == false) {
         $enabled = false;
     }
     // 認証チェック
     if (isset($this->_Permission) && !empty($this->_View->viewVars['user']['user_group_id'])) {
         $userGroupId = $this->_View->viewVars['user']['user_group_id'];
         if (!$this->_Permission->check($_url, $userGroupId)) {
             $enabled = false;
         }
     }
     // ページ公開チェック
     if (isset($this->_Page) && empty($this->request->params['admin'])) {
         $adminPrefix = Configure::read('Routing.prefixes.0');
         if (isset($this->_Page) && !preg_match('/^\\/' . $adminPrefix . '/', $_url)) {
             if ($this->_Page->isPageUrl($_url) && !$this->_Page->checkPublish($_url)) {
                 $enabled = false;
             }
         }
     }
     if (!$enabled) {
         if ($forceTitle) {
             return "<span>{$title}</span>";
         } else {
             return '';
         }
     }
     // 現在SSLのURLの場合、フルパスで取得(javascript:とhttpから始まるものは除外)
     // //(スラッシュスラッシュ)から始まるSSL、非SSL共有URLも除外する
     if (($this->isSSL() || $ssl) && !(strpos($_url, 'javascript') === 0) && !(strpos($_url, 'http') === 0) && !(strpos($_url, '//') === 0)) {
         $_url = preg_replace("/^\\//", "", $_url);
         if (preg_match('/^' . $adminAlias . '\\//', $_url)) {
             $admin = true;
         } else {
             $admin = false;
         }
         if (Configure::read('App.baseUrl')) {
             $_url = 'index.php/' . $_url;
         }
         if (!$ssl && !$admin) {
             $url = Configure::read('BcEnv.siteUrl') . $_url;
         } else {
             $url = Configure::read('BcEnv.sslUrl') . $_url;
         }
     }
     if (!$options) {
         $options = array();
     }
     $out = $this->BcHtml->link($title, $url, $options, $confirmMessage);
     /*** afterGetLink ***/
     $event = $this->dispatchEvent('afterGetLink', array('url' => $url, 'out' => $out), array('class' => 'Html', 'plugin' => ''));
     if ($event !== false) {
         $out = $event->result === null || $event->result === true ? $event->data['out'] : $event->result;
     }
     return $out;
 }
Example #3
0
 /**
  * 公開チェックを行う
  * 
  * @param string $url
  * @param array $expected 期待値
  * @param string $message テストが失敗した時に表示されるメッセージ
  * @dataProvider checkPublishDataProvider
  */
 public function testCheckPublish($url, $expected, $message = null)
 {
     $result = $this->Page->checkPublish($url);
     $this->assertEquals($expected, $result, $message);
 }