source: branches/version-2_12-dev/data/class/SC_Display.php @ 21649

Revision 21649, 4.5 KB checked in by yomoro, 12 years ago (diff)

#675 モバイルサイトを使わない場合、パラメータ設定により明示的に利用を制限する
USE_MOBILE === false の場合はページを表示しない形で対処。(PCサイトをそのまま表示する事も考えたが、どちらにせよモバイルでcookieが使えないとサイト閲覧もままならないのでそのまま表示しない形とした。エラー文表示等要検討。)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[19661]1<?php
[19705]2/*
3 * This file is part of EC-CUBE
4 *
[20764]5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
[19705]6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * Http コンテンツ出力を制御するクラス.
26 *
27 * @author Ryuichi Tokugami
28 * @version $Id$
29 */
[19661]30class SC_Display{
31
32    var $response;
33
34    var $device;
35
[19705]36    /** SC_View インスタンス */
[19661]37    var $view;
[19705]38
[19661]39    var $deviceSeted = false;
[19705]40
[19661]41    /*
[19705]42     * TODO php4を捨てたときに ここのコメントアウトを外してね。
43     * const('MOBILE',1);
44     * const('SMARTPHONE',2);
[19706]45     * const('PC',10);
46     * const('ADMIN',99);
[19705]47     */
48
[19823]49    function SC_Display($hasPrevURL = true) {
[19661]50        $this->response = new SC_Response_Ex();
[19705]51        if ($hasPrevURL) {
[19661]52            $this->setPrevURL();
53        }
54    }
[19705]55
[21479]56    function setPrevURL() {
[19705]57        // TODO SC_SiteSession で実装した方が良さげ
[20444]58        $objCartSess = new SC_CartSession_Ex();
[19661]59        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
60    }
61
62    /**
[20970]63     * LC_Page のパラメーターを, テンプレートに設定し, 出力の準備を行う.
[19705]64     *
65     * @param LC_Page $page LC_Page インスタンス
66     * @param $is_admin boolean 管理画面を扱う場合 true
67     */
[21479]68    function prepare($page, $is_admin = false) {
[21441]69        if (!$this->deviceSeted || !is_null($this->view)) {
[19706]70            $device = ($is_admin) ? DEVICE_TYPE_ADMIN : $this->detectDevice();
[19661]71            $this->setDevice($device);
72        }
73        $this->assignobj($page);
[21546]74        $this->view->setPage($page);
[19661]75        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
76    }
[21552]77
[19705]78    /**
79     * リロードを行う.
80     *
81     * SC_Response::reload() のラッパーです.
82     */
[21479]83    function reload($queryString = array(), $removeQueryString = false) {
[19661]84        $this->response->reload($queryString, $removeQueryString);
85    }
[19705]86
[21479]87    function noAction() {
[19661]88        return;
89    }
[19705]90
91    /**
92     * ヘッダを追加する.
93     */
[21479]94    function addHeader($name, $value) {
[19661]95        $this->response->addHeader($name, $value);
96    }
97
98    /**
99     * デバイス毎の出力方法を自動で変更する、ファサード
100     * Enter description here ...
101     */
[21479]102    function setDevice($device = DEVICE_TYPE_PC) {
[19705]103
[21441]104        switch ($device) {
[19706]105            case DEVICE_TYPE_MOBILE:
[21649]106                if (USE_MOBILE === false) {
107                    exit;
108                }
109                $this->response->setContentType('text/html');
110                $this->setView(new SC_MobileView_Ex());
[19661]111                break;
[19706]112            case DEVICE_TYPE_SMARTPHONE:
[20306]113                $this->setView(new SC_SmartphoneView_Ex());
[19661]114                break;
[19706]115            case DEVICE_TYPE_PC:
[20306]116                $this->setView(new SC_SiteView_Ex());
[19661]117                break;
[19706]118            case DEVICE_TYPE_ADMIN:
[20306]119                $this->setView(new SC_AdminView_Ex());
[19661]120        }
121        $this->deviceSeted = true;
122    }
[19705]123
124    /**
125     * SC_View インスタンスを設定する.
126     */
[21479]127    function setView($view) {
[19661]128        $this->view = $view;
129    }
130
131    /**
132     * 機種を判別する。
[19823]133     *
[19661]134     * SC_Display::MOBILE = ガラケー = 1
135     * SC_Display::SMARTPHONE = スマホ = 2
[19706]136     * SC_Display::PC = PC = 10
[19823]137     *
138     * @static
139     * @return integer 端末種別ID
[19661]140     */
[21479]141    function detectDevice() {
[19661]142        $nu = new Net_UserAgent_Mobile();
[20494]143        $su = new SC_SmartphoneUserAgent_Ex();
[19661]144        $retDevice = 0;
[19823]145        if ($nu->isMobile()) {
146            return DEVICE_TYPE_MOBILE;
147        } elseif ($su->isSmartphone()) {
148            return DEVICE_TYPE_SMARTPHONE;
149        } else {
150            return DEVICE_TYPE_PC;
[19661]151        }
152    }
153
[21479]154    function assign($val1,$val2) {
[19661]155        $this->view->assign($val1, $val2);
156    }
157
[21479]158    function assignobj($obj) {
[19661]159        $this->view->assignobj($obj);
160    }
161
[21479]162    function assignarray($array) {
[19661]163        $this->view->assignarray($array);
164    }
165}
Note: See TracBrowser for help on using the repository browser.