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

Revision 19805, 4.9 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部実装

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