source: branches/version-2_13-dev/data/class/SC_View.php @ 22811

Revision 22811, 8.5 KB checked in by Seasoft, 11 years ago (diff)

#2241 (プラグイン機構の自殺を阻止)

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