source: branches/version-2_5-dev/data/class/SC_View.php @ 19725

Revision 19725, 10.5 KB checked in by nanasess, 13 years ago (diff)

#748(モバイル/スマートフォンのデザイン管理)

  • テンプレートの取得方法を修正
  • 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-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$SC_VIEW_PHP_DIR = realpath(dirname(__FILE__));
25require_once($SC_VIEW_PHP_DIR . "/../module/Smarty/libs/Smarty.class.php");
26//require_once(CLASS_EX_PATH . "util_extends/SC_Utils_Ex.php");
27
28class SC_View {
29
30    var $_smarty;
31    var $objSiteInfo; // サイト情報
32
33    // コンストラクタ
34    function SC_View($siteinfo = true) {
35        global $SC_VIEW_PHP_DIR;
36
37        $this->_smarty = new Smarty;
38        $this->_smarty->left_delimiter = '<!--{';
39        $this->_smarty->right_delimiter = '}-->';
40        $this->_smarty->register_modifier("sfDispDBDate", array("SC_Utils_Ex", "sfDispDBDate"));
41        $this->_smarty->register_modifier("sfConvSendDateToDisp", array("SC_Utils_Ex", "sfConvSendDateToDisp"));
42        $this->_smarty->register_modifier("sfConvSendWdayToDisp", array("SC_Utils_Ex", "sfConvSendWdayToDisp"));
43        $this->_smarty->register_modifier("sfGetVal", array("SC_Utils_Ex", "sfGetVal"));
44        $this->_smarty->register_modifier("sfGetErrorColor", array("SC_Utils_Ex", "sfGetErrorColor"));
45        $this->_smarty->register_modifier("sfTrim", array("SC_Utils_Ex", "sfTrim"));
46        $this->_smarty->register_modifier("sfCalcIncTax", array("SC_Helper_DB_Ex", "sfCalcIncTax"));
47        $this->_smarty->register_modifier("sfPrePoint", array("SC_Utils_Ex", "sfPrePoint"));
48        $this->_smarty->register_modifier("sfGetChecked",array("SC_Utils_Ex", "sfGetChecked"));
49        $this->_smarty->register_modifier("sfTrimURL", array("SC_Utils_Ex", "sfTrimURL"));
50        $this->_smarty->register_modifier("sfMultiply", array("SC_Utils_Ex", "sfMultiply"));
51        $this->_smarty->register_modifier("sfPutBR", array("SC_Utils_Ex", "sfPutBR"));
52        $this->_smarty->register_modifier("sfRmDupSlash", array("SC_Utils_Ex", "sfRmDupSlash"));
53        $this->_smarty->register_modifier("sfCutString", array("SC_Utils_Ex", "sfCutString"));
54        $this->_smarty->plugins_dir=array("plugins", $SC_VIEW_PHP_DIR . "/../smarty_extends");
55        $this->_smarty->register_modifier("sf_mb_convert_encoding", array("SC_Utils_Ex", "sf_mb_convert_encoding"));
56        $this->_smarty->register_modifier("sfGetEnabled", array("SC_Utils_Ex", "sfGetEnabled"));
57//        $this->_smarty->register_modifier("sfPrintEbisTag", array("SC_Utils_Ex", "sfPrintEbisTag"));
58//        $this->_smarty->register_modifier("sfPrintAffTag", array("SC_Utils_Ex", "sfPrintAffTag"));
59        $this->_smarty->register_modifier("sfGetCategoryId", array("SC_Utils_Ex", "sfGetCategoryId"));
60        $this->_smarty->register_modifier("sfNoImageMainList", array("SC_Utils_Ex", "sfNoImageMainList"));
61        $this->_smarty->register_function("sfIsHTTPS", array("SC_Utils_Ex", "sfIsHTTPS"));
62        $this->_smarty->register_function("sfSetErrorStyle", array("SC_Utils_Ex", "sfSetErrorStyle"));
63        $this->_smarty->register_function("printXMLDeclaration", array("SC_Utils_Ex", "printXMLDeclaration"));
64        $this->_smarty->default_modifiers = array('script_escape');
65
66        if(ADMIN_MODE == '1') {
67            $this->time_start = SC_Utils_Ex::sfMicrotimeFloat();
68        }
69
70        // サイト情報を取得する
71        // XXX 要動作確認. 不要の可能性有り
72        if($siteinfo) {
73            if(!defined('LOAD_SITEINFO')) {
74                $this->objSiteInfo = new SC_SiteInfo();
75                $arrInfo['arrSiteInfo'] = $this->objSiteInfo->data;
76
77                // 都道府県名を変換
78                $masterData = new SC_DB_MasterData_Ex();
79                $arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
80                $arrInfo['arrSiteInfo']['pref'] =
81                    isset($arrPref[$arrInfo['arrSiteInfo']['pref']])
82                    ? $arrPref[$arrInfo['arrSiteInfo']['pref']] : "";
83
84                 // サイト情報を割り当てる
85                foreach ($arrInfo as $key => $value){
86                    $this->_smarty->assign($key, $value);
87                }
88
89                define('LOAD_SITEINFO', 1);
90            }
91        }
92    }
93
94    // テンプレートに値を割り当てる
95    function assign($val1, $val2) {
96        $this->_smarty->assign($val1, $val2);
97    }
98
99    // テンプレートの処理結果を取得
100    function fetch($template, $no_error=false) {
101        return $this->_smarty->fetch($template);
102    }
103
104    /**
105     * SC_Display用にレスポンスを返す
106     * @global string $GLOBAL_ERR
107     * @param array $template
108     * @param boolean $no_error
109     * @return string
110     */
111    function getResponse($template, $no_error = false) {
112        if(!$no_error) {
113            global $GLOBAL_ERR;
114            if(!defined('OUTPUT_ERR')) {
115                // GLOBAL_ERR を割り当て
116                $this->assign("GLOBAL_ERR", $GLOBAL_ERR);
117                define('OUTPUT_ERR','ON');
118            }
119        }
120        $res =  $this->_smarty->fetch($template);
121        if(ADMIN_MODE == '1') {
122            $time_end = SC_Utils_Ex::sfMicrotimeFloat();
123            $time = $time_end - $this->time_start;
124            $res .= '処理時間: ' . sprintf('%.3f', $time) . '秒';
125        }
126        return $res;
127    }
128
129    // テンプレートの処理結果を表示
130    function display($template, $no_error = false) {
131        if(!$no_error) {
132            global $GLOBAL_ERR;
133            if(!defined('OUTPUT_ERR')) {
134                // GLOBAL_ERR を割り当て
135                $this->assign("GLOBAL_ERR", $GLOBAL_ERR);
136                define('OUTPUT_ERR','ON');
137            }
138        }
139
140        $this->_smarty->display($template);
141        if(ADMIN_MODE == '1') {
142            $time_end = SC_Utils_Ex::sfMicrotimeFloat();
143            $time = $time_end - $this->time_start;
144            echo '処理時間: ' . sprintf('%.3f', $time) . '秒';
145        }
146    }
147
148      // オブジェクト内の変数をすべて割り当てる。
149      function assignobj($obj) {
150        $data = get_object_vars($obj);
151       
152        foreach ($data as $key => $value){
153            $this->_smarty->assign($key, $value);
154        }
155      }
156
157      // 連想配列内の変数をすべて割り当てる。
158      function assignarray($array) {
159          foreach ($array as $key => $val) {
160              $this->_smarty->assign($key, $val);
161          }
162      }
163
164    /* サイト初期設定 */
165    function initpath() {
166        global $SC_VIEW_PHP_DIR;
167
168        $array['tpl_mainnavi'] = $SC_VIEW_PHP_DIR . '/../Smarty/templates/frontparts/mainnavi.tpl';
169
170        $objDb = new SC_Helper_DB_Ex();
171        $array['tpl_root_id'] = $objDb->sfGetRootId();
172        $this->assignarray($array);
173    }
174
175    /**
176     * テンプレートパスをアサインする.
177     *
178     * @param integer $device_type_id 端末種別ID
179     */
180    function assignTemplatePath($device_type_id) {
181
182        // テンプレート変数を割り当て
183        $this->assign("TPL_DIR", SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true));
184
185        // ヘッダとフッタを割り当て
186        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id, true);
187        $header_tpl = $templatePath . "header.tpl";
188        $footer_tpl = $templatePath . "footer.tpl";
189
190        // ユーザー作成のテンプレートが無ければ, 指定テンプレートを割り当て
191        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id);
192        if (!$this->_smarty->template_exists($header_tpl)) {
193            $header_tpl = $templatePath . "header.tpl";
194        }
195        if (!$this->_smarty->template_exists($footer_tpl)) {
196            $footer_tpl = $templatePath . "footer.tpl";
197        }
198
199        $this->assign("header_tpl", $header_tpl);
200        $this->assign("footer_tpl", $footer_tpl);
201    }
202
203    // デバッグ
204    function debug($var = true){
205        $this->_smarty->debugging = $var;
206    }
207}
208
209class SC_AdminView extends SC_View{
210    function SC_AdminView() {
211        parent::SC_View(false);
212        $this->_smarty->template_dir = TEMPLATE_ADMIN_DIR;
213        $this->_smarty->compile_dir = COMPILE_ADMIN_DIR;
214        $this->assign('TPL_DIR_DEFAULT', URL_DIR . USER_DIR . USER_PACKAGE_DIR . DEFAULT_TEMPLATE_NAME . '/');
215        $this->assign('TPL_DIR', URL_DIR . USER_DIR . USER_PACKAGE_DIR . ADMIN_DIR);
216        $this->initpath();
217    }
218}
219
220class SC_SiteView extends SC_View{
221    function SC_SiteView($setPrevURL = true) {
222        parent::SC_View();
223
224        $this->_smarty->template_dir = TEMPLATE_DIR;
225        $this->_smarty->compile_dir = COMPILE_DIR;
226
227        $this->assignTemplatePath(DEVICE_TYPE_PC);
228        $this->initpath();
229
230        if ($setPrevURL) {
231            $objCartSess = new SC_CartSession();
232            $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
233        }
234    }
235}
236
237class SC_UserView extends SC_SiteView{
238    function SC_UserView($template_dir, $compile_dir = COMPILE_DIR) {
239        parent::SC_SiteView();
240        $this->_smarty->template_dir = $template_dir;
241        $this->_smarty->compile_dir = $compile_dir;
242    }
243}
244
245class SC_InstallView extends SC_View{
246    function SC_InstallView($template_dir, $compile_dir = COMPILE_DIR) {
247        parent::SC_View(false);
248        $this->_smarty->template_dir = $template_dir;
249        $this->_smarty->compile_dir = $compile_dir;
250    }
251}
252
253class SC_MobileView extends SC_SiteView {
254    function SC_MobileView($setPrevURL = true) {
255        parent::SC_SiteView($setPrevURL);
256        $this->_smarty->template_dir = MOBILE_TEMPLATE_DIR;
257        $this->_smarty->compile_dir = MOBILE_COMPILE_DIR;
258        $this->assignTemplatePath(DEVICE_TYPE_MOBILE);
259    }
260}
261
262class SC_SmartphoneView extends SC_SiteView {
263    function SC_SmartphoneView($setPrevURL = true) {
264        parent::SC_SiteView($setPrevURL);
265        $this->_smarty->template_dir = SMARTPHONE_TEMPLATE_DIR;
266        $this->_smarty->compile_dir = SMARTPHONE_COMPILE_DIR;
267        $this->assignTemplatePath(DEVICE_TYPE_SMARTPHONE);
268    }
269}
270?>
Note: See TracBrowser for help on using the repository browser.