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

Revision 22206, 8.3 KB checked in by kim, 11 years ago (diff)

#2003 copyrightを2013に更新

  • 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        $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        $this->_smarty->force_compile = SMARTY_FORCE_COMPILE_MODE === true;
70        // 各filterをセットします.
71        $this->registFilter();
72    }
73
74    // テンプレートに値を割り当てる
75    function assign($val1, $val2) {
76        $this->_smarty->assign($val1, $val2);
77    }
78
79    // テンプレートの処理結果を取得
80    function fetch($template) {
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        if (!$no_error) {
93            global $GLOBAL_ERR;
94            if (!defined('OUTPUT_ERR')) {
95                // GLOBAL_ERR を割り当て
96                $this->assign('GLOBAL_ERR', $GLOBAL_ERR);
97                define('OUTPUT_ERR','ON');
98            }
99        }
100        $res =  $this->_smarty->fetch($template);
101        if (ADMIN_MODE == '1') {
102            $time_end = microtime(true);
103            $time = $time_end - $this->time_start;
104            $res .= '処理時間: ' . sprintf('%.3f', $time) . '秒';
105        }
106        return $res;
107    }
108
109    /**
110     * Pageオブジェクトをセットします.
111     * @param LC_Page_Ex $objPage
112     * @return void
113     */
114    function setPage($objPage) {
115       $this->objPage = $objPage;
116    }
117
118    /**
119     * Smartyのfilterをセットします.
120     * @return void
121     */
122    function registFilter() {
123        $this->_smarty->register_prefilter(array(&$this, 'prefilter_transform'));
124        $this->_smarty->register_outputfilter(array(&$this, 'outputfilter_transform'));
125    }
126
127    /**
128     * prefilter用のフィルタ関数。プラグイン用のフックポイント処理を実行
129     * @param string $source ソース
130     * @param Smarty_Compiler $smarty Smartyのコンパイラクラス
131     * @return string $source ソース
132     */
133    function prefilter_transform($source, &$smarty) {
134        if (!is_null($this->objPage)) {
135            // フックポイントを実行.
136            $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg);
137            $objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
138        }
139        return $source;
140    }
141
142    /**
143     * outputfilter用のフィルタ関数。プラグイン用のフックポイント処理を実行
144     * @param string $source ソース
145     * @param Smarty_Compiler $smarty Smartyのコンパイラクラス
146     * @return string $source ソース
147     */
148    function outputfilter_transform($source, &$smarty) {
149        if (!is_null($this->objPage)) {
150            // フックポイントを実行.
151            $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg);
152            $objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
153        }
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     * テンプレートパスをアサインする.
194     *
195     * @param integer $device_type_id 端末種別ID
196     */
197    function assignTemplatePath($device_type_id) {
198
199        // テンプレート変数を割り当て
200        $this->assign('TPL_URLPATH', SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true));
201
202        // ヘッダとフッタを割り当て
203        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id);
204        $header_tpl = $templatePath . 'header.tpl';
205        $footer_tpl = $templatePath . 'footer.tpl';
206
207        $this->assign('header_tpl', $header_tpl);
208        $this->assign('footer_tpl', $footer_tpl);
209    }
210
211    // デバッグ
212    function debug($var = true) {
213        $this->_smarty->debugging = $var;
214    }
215}
Note: See TracBrowser for help on using the repository browser.