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

Revision 19807, 9.8 KB checked in by Seasoft, 13 years ago (diff)

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

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