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

Revision 22796, 4.9 KB checked in by h_yoshimoto, 13 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

  • 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 *
[22206]5 * Copyright(c) 2000-2013 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 */
[22796]30class SC_Display{
[19661]31
32    var $response;
33
[21963]34    /** 端末種別を保持する */
35    // XXX プロパティとして保持する必要があるのか疑問。
36    static $device;
[19661]37
[19705]38    /** SC_View インスタンス */
[19661]39    var $view;
[19705]40
[19661]41    var $deviceSeted = false;
[19705]42
[19661]43    /*
[19705]44     * TODO php4を捨てたときに ここのコメントアウトを外してね。
45     * const('MOBILE',1);
46     * const('SMARTPHONE',2);
[19706]47     * const('PC',10);
48     * const('ADMIN',99);
[19705]49     */
50
[22796]51    function __construct($hasPrevURL = true) {
[19661]52        $this->response = new SC_Response_Ex();
[19705]53        if ($hasPrevURL) {
[19661]54            $this->setPrevURL();
55        }
56    }
[19705]57
[22796]58    function setPrevURL() {
[19705]59        // TODO SC_SiteSession で実装した方が良さげ
[20444]60        $objCartSess = new SC_CartSession_Ex();
[19661]61        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
62    }
63
64    /**
[20970]65     * LC_Page のパラメーターを, テンプレートに設定し, 出力の準備を行う.
[19705]66     *
67     * @param LC_Page $page LC_Page インスタンス
68     * @param $is_admin boolean 管理画面を扱う場合 true
69     */
[22796]70    function prepare($page, $is_admin = false) {
[21441]71        if (!$this->deviceSeted || !is_null($this->view)) {
[19706]72            $device = ($is_admin) ? DEVICE_TYPE_ADMIN : $this->detectDevice();
[19661]73            $this->setDevice($device);
74        }
75        $this->assignobj($page);
[21546]76        $this->view->setPage($page);
[19661]77        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
78    }
[21552]79
[19705]80    /**
81     * リロードを行う.
82     *
83     * SC_Response::reload() のラッパーです.
84     */
[22796]85    function reload($queryString = array(), $removeQueryString = false) {
[19661]86        $this->response->reload($queryString, $removeQueryString);
87    }
[19705]88
[22796]89    function noAction() {
[19661]90        return;
91    }
[19705]92
93    /**
94     * ヘッダを追加する.
95     */
[22796]96    function addHeader($name, $value) {
[19661]97        $this->response->addHeader($name, $value);
98    }
99
100    /**
101     * デバイス毎の出力方法を自動で変更する、ファサード
102     * Enter description here ...
103     */
[22796]104    function setDevice($device = DEVICE_TYPE_PC) {
[19705]105
[21441]106        switch ($device) {
[19706]107            case DEVICE_TYPE_MOBILE:
[21664]108                if (USE_MOBILE === false) {
109                    exit;
[21649]110                }
[21664]111                $this->response->setContentType('text/html');
112                $this->setView(new SC_MobileView_Ex());
[19661]113                break;
[19706]114            case DEVICE_TYPE_SMARTPHONE:
[20306]115                $this->setView(new SC_SmartphoneView_Ex());
[19661]116                break;
[19706]117            case DEVICE_TYPE_PC:
[20306]118                $this->setView(new SC_SiteView_Ex());
[19661]119                break;
[19706]120            case DEVICE_TYPE_ADMIN:
[20306]121                $this->setView(new SC_AdminView_Ex());
[19661]122        }
123        $this->deviceSeted = true;
124    }
[19705]125
126    /**
127     * SC_View インスタンスを設定する.
128     */
[22796]129    function setView($view) {
[19661]130        $this->view = $view;
131    }
132
133    /**
[21963]134     * 端末種別を判別する。
[19823]135     *
[21963]136     * SC_Display::MOBILE = ガラケー = 1
137     * SC_Display::SMARTPHONE = スマホ = 2
[19706]138     * SC_Display::PC = PC = 10
[19823]139     *
140     * @static
[21962]141     * @param   $reset  boolean
[21963]142     * @return integer 端末種別ID
[19661]143     */
[22796]144    public static function detectDevice($reset = FALSE) {
[21963]145        if (is_null(SC_Display_Ex::$device) || $reset) {
[21962]146            $nu = new Net_UserAgent_Mobile();
147            $su = new SC_SmartphoneUserAgent_Ex();
148            if ($nu->isMobile()) {
149                SC_Display_Ex::$device = DEVICE_TYPE_MOBILE;
150            } elseif ($su->isSmartphone()) {
151                SC_Display_Ex::$device = DEVICE_TYPE_SMARTPHONE;
152            } else {
153                SC_Display_Ex::$device = DEVICE_TYPE_PC;
154            }
[19661]155        }
[21962]156        return SC_Display_Ex::$device;
[19661]157    }
158
[22796]159    function assign($val1,$val2) {
[19661]160        $this->view->assign($val1, $val2);
161    }
162
[22796]163    function assignobj($obj) {
[19661]164        $this->view->assignobj($obj);
165    }
166
[22796]167    function assignarray($array) {
[19661]168        $this->view->assignarray($array);
169    }
170}
Note: See TracBrowser for help on using the repository browser.