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;
}
}
// コンテンツ公開チェック
// TODO 統合コンテンツ管理のチェックに変更する
// 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 {
$sslUrl = Configure::read('BcEnv.sslUrl');
if ($sslUrl) {
$url = $sslUrl . $_url;
} else {
$url = '/' . $_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;
}