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