source: branches/version-2_12-dev/data/class/SC_View.php @ 21765

Revision 21765, 8.6 KB checked in by shutta, 12 years ago (diff)

#1296 SC_* のコンストラクタの拡張が無視される
SC_*Viewの修正

  • 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-2011 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
24require_once realpath(dirname(__FILE__)) . '/../module/Smarty/libs/Smarty.class.php';
25
26class SC_View {
27
28    var $_smarty;
29
30    var $objPage;
31
32    // コンストラクタ
33    function __construct() {
34        $this->init();
35    }
36
37    function init() {
38        $this->_smarty = new Smarty;
39        $this->_smarty->left_delimiter = '<!--{';
40        $this->_smarty->right_delimiter = '}-->';
41        $this->_smarty->register_modifier('sfDispDBDate', array('SC_Utils_Ex', 'sfDispDBDate'));
42        $this->_smarty->register_modifier('sfConvSendDateToDisp', array('SC_Utils_Ex', 'sfConvSendDateToDisp'));
43        $this->_smarty->register_modifier('sfConvSendWdayToDisp', array('SC_Utils_Ex', 'sfConvSendWdayToDisp'));
44        $this->_smarty->register_modifier('sfGetVal', array('SC_Utils_Ex', 'sfGetVal'));
45        $this->_smarty->register_modifier('sfGetErrorColor', array('SC_Utils_Ex', 'sfGetErrorColor'));
46        $this->_smarty->register_modifier('sfTrim', array('SC_Utils_Ex', 'sfTrim'));
47        $this->_smarty->register_modifier('sfCalcIncTax', array('SC_Helper_DB_Ex', 'sfCalcIncTax'));
48        $this->_smarty->register_modifier('sfPrePoint', array('SC_Utils_Ex', 'sfPrePoint'));
49        $this->_smarty->register_modifier('sfGetChecked',array('SC_Utils_Ex', 'sfGetChecked'));
50        $this->_smarty->register_modifier('sfTrimURL', array('SC_Utils_Ex', 'sfTrimURL'));
51        $this->_smarty->register_modifier('sfMultiply', array('SC_Utils_Ex', 'sfMultiply'));
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', realpath(dirname(__FILE__)) . '/../smarty_extends');
55        $this->_smarty->register_modifier('sfMbConvertEncoding', array('SC_Utils_Ex', 'sfMbConvertEncoding'));
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        // XXX register_function で登録すると if で使用できないのではないか?
60        $this->_smarty->register_function('sfIsHTTPS', array('SC_Utils_Ex', 'sfIsHTTPS'));
61        $this->_smarty->register_function('sfSetErrorStyle', array('SC_Utils_Ex', 'sfSetErrorStyle'));
62        $this->_smarty->register_function('printXMLDeclaration', array('GC_Utils_Ex', 'printXMLDeclaration'));
63        $this->_smarty->default_modifiers = array('script_escape');
64
65        if (ADMIN_MODE == '1') {
66            $this->time_start = microtime(true);
67        }
68
69        if(SMARTY_FORCE_COMPILE_MODE === true) {
70            $this->_smarty->force_compile = true;
71        } else {
72            $this->_smarty->force_compile = false;
73        }
74    }
75
76    // テンプレートに値を割り当てる
77    function assign($val1, $val2) {
78        $this->_smarty->assign($val1, $val2);
79    }
80
81    // テンプレートの処理結果を取得
82    function fetch($template, $no_error=false) {
83        return $this->_smarty->fetch($template);
84    }
85
86    /**
87     * SC_Display用にレスポンスを返す
88     * @global string $GLOBAL_ERR
89     * @param array $template
90     * @param boolean $no_error
91     * @return string
92     */
93    function getResponse($template, $no_error = false) {
94        if (!$no_error) {
95            global $GLOBAL_ERR;
96            if (!defined('OUTPUT_ERR')) {
97                // GLOBAL_ERR を割り当て
98                $this->assign('GLOBAL_ERR', $GLOBAL_ERR);
99                define('OUTPUT_ERR','ON');
100            }
101        }
102        // 各filterをセットします.
103        $this->registFilter();
104        $res =  $this->_smarty->fetch($template);
105        if (ADMIN_MODE == '1') {
106            $time_end = microtime(true);
107            $time = $time_end - $this->time_start;
108            $res .= '処理時間: ' . sprintf('%.3f', $time) . '秒';
109        }
110        return $res;
111    }
112
113    /**
114     * Pageオブジェクトをセットします.
115     * @param LC_Page_Ex $objPage
116     * @return void
117     */
118    function setPage(LC_Page_Ex $objPage) {
119       $this->objPage = $objPage;
120    }
121
122    /**
123     * Smartyのfilterをセットします.
124     * @return void
125     */
126    function registFilter() {
127        $this->_smarty->register_prefilter(array(&$this, 'prefilter_transform'));
128        $this->_smarty->register_outputfilter(array(&$this, 'outputfilter_transform'));
129    }
130
131    /**
132     * prefilter用のフィルタ関数。プラグイン用のフックポイント処理を実行
133     * @param string $source ソース
134     * @param Smarty_Compiler $smarty Smartyのコンパイラクラス
135     * @return string $source ソース
136     */
137    function prefilter_transform($source, &$smarty) {
138        // フックポイントを実行.
139        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg);
140        $objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
141        return $source;
142    }
143
144    /**
145     * outputfilter用のフィルタ関数。プラグイン用のフックポイント処理を実行
146     * @param string $source ソース
147     * @param Smarty_Compiler $smarty Smartyのコンパイラクラス
148     * @return string $source ソース
149     */
150    function outputfilter_transform($source, &$smarty) {
151        // フックポイントを実行.
152        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg);
153        $objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
154        return $source;
155    }
156
157    // テンプレートの処理結果を表示
158    function display($template, $no_error = false) {
159        if (!$no_error) {
160            global $GLOBAL_ERR;
161            if (!defined('OUTPUT_ERR')) {
162                // GLOBAL_ERR を割り当て
163                $this->assign('GLOBAL_ERR', $GLOBAL_ERR);
164                define('OUTPUT_ERR','ON');
165            }
166        }
167
168        $this->_smarty->display($template);
169        if (ADMIN_MODE == '1') {
170            $time_end = microtime(true);
171            $time = $time_end - $this->time_start;
172            echo '処理時間: ' . sprintf('%.3f', $time) . '秒';
173        }
174    }
175
176    // オブジェクト内の変数をすべて割り当てる。
177    function assignobj($obj) {
178        $data = get_object_vars($obj);
179
180        foreach ($data as $key => $value) {
181            $this->_smarty->assign($key, $value);
182        }
183    }
184
185    // 連想配列内の変数をすべて割り当てる。
186    function assignarray($array) {
187        foreach ($array as $key => $val) {
188            $this->_smarty->assign($key, $val);
189        }
190    }
191
192    /* サイト初期設定 */
193    function initpath() {
194
195        $array['tpl_mainnavi'] = realpath(dirname(__FILE__)) . '/../Smarty/templates/frontparts/mainnavi.tpl';
196
197        $objDb = new SC_Helper_DB_Ex();
198        $array['tpl_root_id'] = $objDb->sfGetRootId();
199        $this->assignarray($array);
200    }
201
202    /**
203     * テンプレートパスをアサインする.
204     *
205     * @param integer $device_type_id 端末種別ID
206     */
207    function assignTemplatePath($device_type_id) {
208
209        // テンプレート変数を割り当て
210        $this->assign('TPL_URLPATH', SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true));
211
212        // ヘッダとフッタを割り当て
213        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id);
214        $header_tpl = $templatePath . 'header.tpl';
215        $footer_tpl = $templatePath . 'footer.tpl';
216
217        $this->assign('header_tpl', $header_tpl);
218        $this->assign('footer_tpl', $footer_tpl);
219    }
220
221    // デバッグ
222    function debug($var = true) {
223        $this->_smarty->debugging = $var;
224    }
225}
Note: See TracBrowser for help on using the repository browser.