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

Revision 19803, 4.9 KB checked in by Seasoft, 16 years ago (diff)

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

  • 一斉置換前の現状記録のためのコミット

#628(未使用処理・定義などの削除)

RevLine 
[19661]1<?php
[19705]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 */
[19661]30class SC_Display{
31
32    var $response;
33
34    var $device;
35
36    var $autoSet;
37
[19705]38    /** SC_View インスタンス */
[19661]39    var $view;
[19705]40
[19661]41    var $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
51    function SC_Display($hasPrevURL = true, $autoGenerateHttpHeaders = true) {
[19803]52        require_once(CLASS_EX_FILE_PATH . "SC_Response_Ex.php");
[19661]53        $this->response = new SC_Response_Ex();
54        $this->autoSet = $autoGenerateHttpHeaders;
[19705]55        if ($hasPrevURL) {
[19661]56            $this->setPrevURL();
57        }
58    }
[19705]59
[19661]60    function setPrevURL(){
[19705]61        // TODO SC_SiteSession で実装した方が良さげ
[19661]62        $objCartSess = new SC_CartSession();
63        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
64    }
65
66    /**
[19705]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){
[19661]73        if(!$this->deviceSeted || !is_null($this->view)){
[19706]74            $device = ($is_admin) ? DEVICE_TYPE_ADMIN : $this->detectDevice();
[19661]75            $this->setDevice($device);
76        }
77        $this->assignobj($page);
78        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
79    }
[19705]80
81    /**
82     * リダイレクトを行う.
83     *
84     * SC_Response::sendRedirect() のラッパーです.
85     */
[19661]86    function redirect($location){
87        $this->response->sendRedirect($location);
88    }
[19705]89
90    /**
91     * リロードを行う.
92     *
93     * SC_Response::reload() のラッパーです.
94     */
[19661]95    function reload($queryString = array(), $removeQueryString = false){
96        $this->response->reload($queryString, $removeQueryString);
97    }
[19705]98
99    function noAction(){
[19661]100        return;
101    }
[19705]102
103    /**
104     * ヘッダを追加する.
105     */
[19675]106    function addHeader($name, $value){
[19661]107        $this->response->addHeader($name, $value);
108    }
109
110    /**
111     * デバイス毎の出力方法を自動で変更する、ファサード
112     * Enter description here ...
113     */
[19706]114    function setDevice($device = DEVICE_TYPE_PC){
[19705]115
[19661]116        switch ($device){
[19706]117            case DEVICE_TYPE_MOBILE:
[19661]118                $this->response->setContentType("text/html");
119                $this->setView(new SC_MobileView());
120                break;
[19706]121            case DEVICE_TYPE_SMARTPHONE:
[19683]122                $this->setView(new SC_SmartphoneView());
[19661]123                break;
[19706]124            case DEVICE_TYPE_PC:
[19661]125                $this->setView(new SC_SiteView());
126                break;
[19706]127            case DEVICE_TYPE_ADMIN:
[19661]128                $this->setView(new SC_AdminView());
129        }
130        $this->deviceSeted = true;
131    }
[19705]132
133    /**
134     * SC_View インスタンスを設定する.
135     */
[19675]136    function setView($view){
[19661]137        $this->view = $view;
138    }
139
140    /**
141     * 機種を判別する。
142     * SC_Display::MOBILE = ガラケー = 1
143     * SC_Display::SMARTPHONE = スマホ = 2
[19706]144     * SC_Display::PC = PC = 10
[19661]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()){
[19706]153            $retDevice = DEVICE_TYPE_MOBILE;
[19661]154        }elseif ($su->isSmartphone()){
[19706]155            $retDevice = DEVICE_TYPE_SMARTPHONE;
[19661]156        }else{
[19706]157            $retDevice = DEVICE_TYPE_PC;
[19661]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.