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