source: branches/version-2_13-dev/data/class/SC_Display.php @ 23124

Revision 23124, 5.0 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

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