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

Revision 23003, 8.1 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
存在しないメソッドを呼び出しているので削除

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