findCurrent() публичный статический Метод

URLからサブサイトを取得する
public static findCurrent ( boolean $direct = true ) : BcSite | null
$direct boolean
Результат BcSite | null
Пример #1
0
 /**
  * afterLayout
  *
  * @return void
  */
 public function afterLayout($layoutFile)
 {
     /* 出力データをSJISに変換 */
     $View = $this->_View;
     if (isset($this->request->params['ext']) && $this->request->params['ext'] == 'rss') {
         $rss = true;
     } else {
         $rss = false;
     }
     $site = BcSite::findCurrent(true);
     if (!$rss && $site && $site->device == 'mobile' && $View->layoutPath != 'Emails' . DS . 'text') {
         $View->output = str_replace('&', '&', $View->output);
         $View->output = str_replace('<', '<', $View->output);
         $View->output = str_replace('>', '>', $View->output);
         $View->response->charset('Shift_JIS');
         $View->output = mb_convert_kana($View->output, "rak", "UTF-8");
         $View->output = mb_convert_encoding($View->output, "SJIS-win", "UTF-8");
         // 内部リンクの自動変換
         if ($site->autoLink) {
             $currentAlias = $this->request->params['Site']['alias'];
             // 一旦プレフィックスを除外
             $reg = '/href="' . preg_quote(BC_BASE_URL, '/') . '(' . $currentAlias . '\\/([^\\"]*?))\\"/';
             $View->output = preg_replace_callback($reg, array($this, '_removeMobilePrefix'), $View->output);
             // プレフィックス追加
             $reg = '/href=\\"' . preg_quote(BC_BASE_URL, '/') . '([^\\"]*?)\\"/';
             $View->output = preg_replace_callback($reg, array($this, '_addMobilePrefix'), $View->output);
         }
         // XMLとして出力する場合、デバッグモードで出力する付加情報で、
         // ブラウザによってはXMLパースエラーとなってしまうので強制的にデバッグモードをオフ
         Configure::write('debug', 0);
     }
 }
 /**
  * beforeDispatch Event
  *
  * @param CakeEvent $event イベント
  * @return void|CakeResponse
  */
 public function beforeDispatch(CakeEvent $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     if (!empty($request->params['Content'])) {
         return;
     } else {
         if ($this->_existController($request)) {
             return;
         }
     }
     $site = BcSite::findCurrent();
     if (!$site || !$site->enabled) {
         return;
     }
     $mainSite = $site->getMain();
     if (!$mainSite) {
         return;
     }
     $mainSiteUrl = '/' . preg_replace('/^' . $site->alias . '\\//', '', $request->url);
     if ($mainSite->alias) {
         $mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl;
     }
     if ($mainSiteUrl) {
         $request = new CakeRequest($mainSiteUrl);
         $params = Router::parse($request->url);
         $request->addParams($params);
         if ($this->_existController($request)) {
             $response->header('Location', $request->base . $mainSiteUrl);
             $response->statusCode(302);
             return $response;
         }
     }
     return;
 }
 /**
  * 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'];
     }
 }
Пример #4
0
 /**
  * afterLayout
  *
  * @return void
  */
 public function afterLayout($layoutFile)
 {
     if (isset($this->request->params['ext']) && $this->request->params['ext'] == 'rss') {
         $rss = true;
     } else {
         $rss = false;
     }
     $site = BcSite::findCurrent();
     if (!$rss && $site->device == 'smartphone' && $this->_View->layoutPath != 'Emails' . DS . 'text') {
         if (empty($this->request->params['Site'])) {
             return;
         }
         // 内部リンクの自動変換
         if ($site->autoLink) {
             $bcBaseUrl = BC_BASE_URL;
             if ($this->_View->BcBaser->isSSL()) {
                 $bcBaseUrl = Configure::read('BcEnv.siteUrl');
             }
             $currentAlias = $this->request->params['Site']['alias'];
             // 一旦プレフィックスを除外
             $reg = '/a(.*?)href="' . preg_quote($bcBaseUrl, '/') . '(' . $currentAlias . '\\/([^\\"]*?))\\"/';
             $this->_View->output = preg_replace_callback($reg, array($this, '_removePrefix'), $this->_View->output);
             // プレフィックス追加
             $reg = '/a(.*?)href=\\"' . preg_quote($bcBaseUrl, '/') . '([^\\"]*?)\\"/';
             $this->_View->output = preg_replace_callback($reg, array($this, '_addPrefix'), $this->_View->output);
         }
     }
 }
Пример #5
0
 /**
  * beforeDispatch Event
  *
  * @param CakeEvent $event イベント
  * @return void|CakeResponse
  */
 public function beforeDispatch(CakeEvent $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     $this->addDetectors($request);
     // アセットならスキップ
     if ($this->isAsset($request)) {
         Configure::write('BcRequest.asset', true);
         return;
     }
     // URLからエージェントを取得
     $site = BcSite::findCurrent(true);
     if ($site && $site->device) {
         /*
          * =========================================================
          * /m/files/... へのアクセスの場合、/files/... へ自動リダイレクト
          * CMSで作成するページ内のリンクは、モバイルでアクセスすると、
          * 自動的に、/m/ 付のリンクに書き換えられてしまう為、
          * files内のファイルへのリンクがリンク切れになってしまうので暫定対策。
          *
          * 2014/12/30 nakae bootstrap.phpから移行
          * =========================================================
          */
         $param = preg_replace('/^' . $site->alias . '\\//', '', $request->url);
         if (preg_match('/^files/', $param)) {
             $response->statusCode(301);
             $response->header('Location', "{$request->base}/{$param}");
             return $response;
         }
     }
     //bootstrapから移動する
     //Configure::write('BcRequest.isUpdater', $this->isUpdate($request));
     //Configure::write('BcRequest.isMaintenance', $this->isMaintenance($request));
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * [PUBLIC] ブログアーカイブを表示する
  *
  * @param mixed	blog_post_id / type
  * @param mixed	blog_post_id / ""
  * @return void
  */
 public function archives()
 {
     // パラメーター処理
     $pass = $this->request->params['pass'];
     $type = $year = $month = $day = $id = '';
     $crumbs = $posts = array();
     $single = false;
     $posts = array();
     if ($pass[0] == 'category') {
         $type = 'category';
     } elseif ($pass[0] == 'author') {
         $type = 'author';
     } elseif ($pass[0] == 'tag') {
         $type = 'tag';
     } elseif ($pass[0] == 'date') {
         $type = 'date';
     }
     $crumbs[] = array('name' => $this->request->params['Content']['title'], 'url' => $this->request->params['Content']['url']);
     switch ($type) {
         /* カテゴリ一覧 */
         case 'category':
             $category = $pass[count($pass) - 1];
             if (empty($category)) {
                 //$this->notFound();
             }
             // ナビゲーションを設定
             $categoryId = $this->BlogCategory->field('id', array('BlogCategory.blog_content_id' => $this->contentId, 'BlogCategory.name' => urlencode($category)));
             if (!$categoryId) {
                 $this->notFound();
             }
             // 記事を取得
             $posts = $this->_getBlogPosts(array('conditions' => array('category' => urlencode($category))));
             $blogCategories = $this->BlogCategory->getPath($categoryId, array('name', 'title'));
             if (count($blogCategories) > 1) {
                 foreach ($blogCategories as $key => $blogCategory) {
                     if ($key < count($blogCategories) - 1) {
                         $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => $this->request->params['Content']['url'] . '/archives/category/' . $blogCategory['BlogCategory']['name']);
                     }
                 }
             }
             $this->pageTitle = $blogCategories[count($blogCategories) - 1]['BlogCategory']['title'];
             $template = $this->blogContent['BlogContent']['template'] . DS . 'archives';
             $this->set('blogArchiveType', $type);
             break;
         case 'author':
             $author = h($pass[count($pass) - 1]);
             $posts = $this->_getBlogPosts(array('conditions' => array('author' => $author)));
             $data = $this->BlogPost->User->find('first', array('fields' => array('real_name_1', 'real_name_2', 'nickname'), 'conditions' => array('User.name' => $author)));
             App::uses('BcBaserHelper', 'View/Helper');
             $BcBaser = new BcBaserHelper(new View());
             $userName = $BcBaser->getUserName($data);
             $this->pageTitle = urldecode($userName);
             $template = $this->blogContent['BlogContent']['template'] . DS . 'archives';
             $this->set('blogArchiveType', $type);
             break;
             /* タグ別記事一覧 */
         /* タグ別記事一覧 */
         case 'tag':
             $tag = h($pass[count($pass) - 1]);
             if (empty($this->blogContent['BlogContent']['tag_use']) || empty($tag)) {
                 $this->notFound();
             }
             $posts = $this->_getBlogPosts(array('conditions' => array('tag' => $tag)));
             $this->pageTitle = urldecode($tag);
             $template = $this->blogContent['BlogContent']['template'] . DS . 'archives';
             $this->set('blogArchiveType', $type);
             break;
             /* 月別アーカイブ一覧 */
         /* 月別アーカイブ一覧 */
         case 'date':
             $year = h($pass[1]);
             $month = h(@$pass[2]);
             $day = h(@$pass[3]);
             if (!$year && !$month && !$day) {
                 $this->notFound();
             }
             $posts = $this->_getBlogPosts(array('conditions' => array('year' => $year, 'month' => $month, 'day' => $day)));
             $this->pageTitle = $year . '年';
             if ($month) {
                 $this->pageTitle .= $month . '月';
             }
             if ($day) {
                 $this->pageTitle .= $day . '日';
             }
             $template = $this->blogContent['BlogContent']['template'] . DS . 'archives';
             if ($day) {
                 $this->set('blogArchiveType', 'daily');
             } elseif ($month) {
                 $this->set('blogArchiveType', 'monthly');
             } else {
                 $this->set('blogArchiveType', 'yearly');
             }
             break;
             /* 単ページ */
         /* 単ページ */
         default:
             // プレビュー
             if ($this->BcContents->preview && !empty($this->request->data['BlogPost'])) {
                 $post = $this->BlogPost->createPreviewData($this->request->data);
             } else {
                 if (!empty($pass[0])) {
                     $id = $pass[0];
                 } else {
                     $this->notFound();
                 }
                 // コメント送信
                 if (isset($this->request->data['BlogComment'])) {
                     $this->add_comment($id);
                 }
                 $post = $this->_getBlogPosts(array('preview' => (bool) $this->BcContents->preview, 'conditions' => array('id' => $id)));
                 if (!empty($post[0])) {
                     $post = $post[0];
                 } else {
                     $this->notFound();
                 }
                 // 一覧系のページの場合、時限公開の記事が存在し、キャッシュがあると反映できないが、
                 // 詳細ページの場合は、記事の終了期間の段階でキャッシュが切れる前提となる為、キャッシュを利用する
                 // プレビューでは利用しない事。
                 // コメント送信時、キャッシュはクリアされるが、モバイルの場合、このメソッドに対してデータを送信する為、
                 // キャッシュがあるとデータが処理されないので、キャッシュは全く作らない設定とする
                 if (BcSite::findCurrent()->device != 'mobile') {
                     $this->BcContents->useViewCache = true;
                 }
             }
             if (BcUtil::isAdminUser()) {
                 $this->set('editLink', array('admin' => true, 'plugin' => 'blog', 'controller' => 'blog_posts', 'action' => 'edit', $post['BlogPost']['blog_content_id'], $post['BlogPost']['id']));
             }
             // ナビゲーションを設定
             if (!empty($post['BlogPost']['blog_category_id'])) {
                 $blogCategories = $this->BlogCategory->getPath($post['BlogPost']['blog_category_id'], array('name', 'title'));
                 if ($blogCategories) {
                     foreach ($blogCategories as $blogCategory) {
                         $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => $this->request->params['Content']['url'] . '/archives/category/' . $blogCategory['BlogCategory']['name']);
                     }
                 }
             }
             $this->pageTitle = $post['BlogPost']['name'];
             $single = true;
             $template = $this->blogContent['BlogContent']['template'] . DS . 'single';
             if ($this->BcContents->preview) {
                 $this->blogContent['BlogContent']['comment_use'] = false;
             }
             $this->set('post', $post);
     }
     // 表示設定
     $this->crumbs = array_merge($this->crumbs, $crumbs);
     $this->set('single', $single);
     $this->set('posts', $posts);
     $this->set('year', $year);
     $this->set('month', $month);
     $this->render($template);
 }
Пример #8
0
/**
 * baserCMS :  Based Website Development Project <http://basercms.net>
 * Copyright (c) baserCMS Users Community <http://basercms.net/community/>
 *
 * @copyright		Copyright (c) baserCMS Users Community
 * @link			http://basercms.net baserCMS Project
 * @package			Feed.View
 * @since			baserCMS v 0.1.0
 * @license			http://basercms.net/license/index.html
 */
/**
 * [PUBLISH] フィード読み込みAJAX
 */
header("Content-type: text/javascript charset=UTF-8");
$this->BcBaser->cacheHeader(MONTH, 'js');
$site = BcSite::findCurrent();
?>
document.write('<div id="feeds<?php 
echo $id;
?>
"><?php 
echo $this->html->image('admin/ajax-loader.gif', array('alt' => 'loading now...', 'style' => 'display:block;margin:auto'));
?>
</div>');

// 読込み成功時の処理
var successCallback = function (response)
{
	if(response == 'false'){
		$("#feeds<?php 
echo $id;
Пример #9
0
/**
 * 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;
}
Пример #10
0
 /**
  * 現在のページがトップページかどうかを判定する
  *
  * MEMO: BcRequest.(agent).aliasは廃止
  *
  * @return bool
  */
 public function isHome()
 {
     if (empty($this->request->params['Site'])) {
         return false;
     }
     $site = BcSite::findCurrent(true);
     if (!$site->alias || $site->sameMainUrl || $site->useSubDomain) {
         return $this->request->url == false || $this->request->url == 'index';
     } else {
         return $this->request->url == $site->alias . '/' || $this->request->url == $site->alias . '/index';
     }
 }