Пример #1
0
 /**
  * URLがエージェント用かどうかを判定
  *
  * @param bool $expect 期待値
  * @param string $userAgent ユーザーエージェントの文字列
  * @return void
  * @dataProvider isMatchDecisionKeyDataProvider
  */
 public function testIsMatchDecisionKey($expect, $userAgent)
 {
     $_SERVER['HTTP_USER_AGENT'] = $userAgent;
     $this->assertEquals($expect, $this->agent->isMatchDecisionKey());
 }
Пример #2
0
 /**
  * 固定ページ表示用のURLかどうかを判定
  * [注]ルーターによるURLパース後のみ
  *
  * @param CakeRequest $request リクエスト
  * @return bool
  */
 public function isPage(CakeRequest $request)
 {
     $params = explode('/', $request->url);
     $agent = BcAgent::findByAlias($params[0]);
     if (is_null($agent)) {
         $action = 'display';
     } else {
         $action = "{$agent->prefix}_display";
     }
     return $request->params['controller'] === 'pages' && $request->params['action'] === $action;
 }
Пример #3
0
 /**
  * リクエストをリダイレクトするURLを生成
  *
  * @param string $expect 期待値
  * @param string $url URL文字列
  * @param array $query クエリパラメータの配列
  * @return void
  * @dataProvider makeRedirectUrlDataProvider
  */
 public function testMakeRedirectUrl($expect, $url, $query = null)
 {
     $request = new CakeRequest($url, false);
     $request->query = $query;
     $this->assertEquals($expect, $this->agent->makeRedirectUrl($request));
 }
Пример #4
0
 /**
  * リクエスト検出器の設定を取得
  *
  * @return array
  */
 public function getDetectorConfigs()
 {
     $configs = array();
     $configs['admin'] = array('callback' => array($this, 'isAdmin'));
     $configs['asset'] = array('callback' => array($this, 'isAsset'));
     $configs['install'] = array('callback' => array($this, 'isInstall'));
     $configs['maintenance'] = array('callback' => array($this, 'isMaintenance'));
     $configs['update'] = array('callback' => array($this, 'isUpdate'));
     $configs['page'] = array('callback' => array($this, 'isPage'));
     $configs['requestview'] = array('callback' => array($this, 'isRequestView'));
     $agents = BcAgent::findAll();
     foreach ($agents as $agent) {
         $configs[$agent->name] = array('env' => 'HTTP_USER_AGENT', 'pattern' => $agent->getDetectorRegex());
     }
     return $configs;
 }
Пример #5
0
 /**
  * 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]));
 }
Пример #6
0
 /**
  * 現在のサイトとユーザーエージェントに関連するサブサイトを取得する
  *
  * @param BcAbstractDetector $detector
  * @param bool $sameMainUrl
  * @return BcSite|null
  */
 public static function findCurrentSub($sameMainUrl = false, BcAgent $agent = null, $lang = null)
 {
     $currentSite = self::findCurrent();
     $sites = self::findAll();
     $subSite = null;
     if (!$lang) {
         $lang = BcLang::findCurrent();
     }
     if (!$agent) {
         $agent = BcAgent::findCurrent();
     }
     // 言語の一致するサブサイト候補に絞り込む
     $subSites = [];
     if ($lang) {
         foreach ($sites as $site) {
             if (!$sameMainUrl || $sameMainUrl && $site->sameMainUrl) {
                 if ($site->lang == $lang->name && $currentSite->id == $site->mainSiteId) {
                     $subSites[] = $site;
                     break;
                 }
             }
         }
     }
     if (!$subSites) {
         $subSites = $sites;
     }
     if ($agent) {
         foreach ($subSites as $subSite) {
             if (!$sameMainUrl || $sameMainUrl && $subSite->sameMainUrl) {
                 if ($subSite->device == $agent->name && $currentSite->id == $subSite->mainSiteId) {
                     return $subSite;
                 }
             }
         }
     }
     return null;
 }