source: branches/version-2_5-dev/data/class/SC_Display.php @ 19814

Revision 19814, 4.8 KB checked in by Seasoft, 13 years ago (diff)

#887(LC_Page#sendHttpStatus を SC_Response へ移植) 事前準備

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
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 */
30class SC_Display{
31
32    var $response;
33
34    var $device;
35
36    var $autoSet;
37
38    /** SC_View インスタンス */
39    var $view;
40
41    var $deviceSeted = false;
42
43    /*
44     * TODO php4を捨てたときに ここのコメントアウトを外してね。
45     * const('MOBILE',1);
46     * const('SMARTPHONE',2);
47     * const('PC',10);
48     * const('ADMIN',99);
49     */
50
51    function SC_Display($hasPrevURL = true, $autoGenerateHttpHeaders = true) {
52        $this->response = new SC_Response_Ex();
53        $this->autoSet = $autoGenerateHttpHeaders;
54        if ($hasPrevURL) {
55            $this->setPrevURL();
56        }
57    }
58
59    function setPrevURL(){
60        // TODO SC_SiteSession で実装した方が良さげ
61        $objCartSess = new SC_CartSession();
62        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
63    }
64
65    /**
66     * LC_Page のパラメータを, テンプレートに設定し, 出力の準備を行う.
67     *
68     * @param LC_Page $page LC_Page インスタンス
69     * @param $is_admin boolean 管理画面を扱う場合 true
70     */
71    function prepare($page, $is_admin = false){
72        if(!$this->deviceSeted || !is_null($this->view)){
73            $device = ($is_admin) ? DEVICE_TYPE_ADMIN : $this->detectDevice();
74            $this->setDevice($device);
75        }
76        $this->assignobj($page);
77        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
78    }
79
80    /**
81     * リダイレクトを行う.
82     *
83     * SC_Response::sendRedirect() のラッパーです.
84     */
85    function redirect($location){
86        $this->response->sendRedirect($location);
87    }
88
89    /**
90     * リロードを行う.
91     *
92     * SC_Response::reload() のラッパーです.
93     */
94    function reload($queryString = array(), $removeQueryString = false){
95        $this->response->reload($queryString, $removeQueryString);
96    }
97
98    function noAction(){
99        return;
100    }
101
102    /**
103     * ヘッダを追加する.
104     */
105    function addHeader($name, $value){
106        $this->response->addHeader($name, $value);
107    }
108
109    /**
110     * デバイス毎の出力方法を自動で変更する、ファサード
111     * Enter description here ...
112     */
113    function setDevice($device = DEVICE_TYPE_PC){
114
115        switch ($device){
116            case DEVICE_TYPE_MOBILE:
117                $this->response->setContentType("text/html");
118                $this->setView(new SC_MobileView());
119                break;
120            case DEVICE_TYPE_SMARTPHONE:
121                $this->setView(new SC_SmartphoneView());
122                break;
123            case DEVICE_TYPE_PC:
124                $this->setView(new SC_SiteView());
125                break;
126            case DEVICE_TYPE_ADMIN:
127                $this->setView(new SC_AdminView());
128        }
129        $this->deviceSeted = true;
130    }
131
132    /**
133     * SC_View インスタンスを設定する.
134     */
135    function setView($view){
136        $this->view = $view;
137    }
138
139    /**
140     * 機種を判別する。
141     * SC_Display::MOBILE = ガラケー = 1
142     * SC_Display::SMARTPHONE = スマホ = 2
143     * SC_Display::PC = PC = 10
144     * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。
145     * @return
146     */
147    function detectDevice(){
148        $nu = new Net_UserAgent_Mobile();
149        $su = new SC_SmartphoneUserAgent();
150        $retDevice = 0;
151        if($nu->isMobile()){
152            $retDevice = DEVICE_TYPE_MOBILE;
153        }elseif ($su->isSmartphone()){
154            $retDevice = DEVICE_TYPE_SMARTPHONE;
155        }else{
156            $retDevice = DEVICE_TYPE_PC;
157        }
158
159        if($this->autoSet){
160            $this->setDevice($retDevice);
161        }
162        return $retDevice;
163    }
164
165    function assign($val1,$val2){
166        $this->view->assign($val1, $val2);
167    }
168
169    function assignobj($obj){
170        $this->view->assignobj($obj);
171    }
172
173    function assignarray($array){
174        $this->view->assignarray($array);
175    }
176}
Note: See TracBrowser for help on using the repository browser.