source: branches/camp/camp-2_13-tax/data/class/SC_View.php @ 22567

Revision 22567, 8.4 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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            $objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
147        }
148        return $source;
149    }
150
151    /**
152     * outputfilter用のフィルタ関数。プラグイン用のフックポイント処理を実行
153     * @param string $source ソース
154     * @param Smarty_Compiler $smarty Smartyのコンパイラクラス
155     * @return string $source ソース
156     */
157    function outputfilter_transform($source, &$smarty)
158    {
159        if (!is_null($this->objPage)) {
160            // フックポイントを実行.
161            $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg);
162            $objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $smarty->_current_file));
163        }
164        return $source;
165    }
166
167    // テンプレートの処理結果を表示
168    function display($template, $no_error = false)
169    {
170        if (!$no_error) {
171            global $GLOBAL_ERR;
172            if (!defined('OUTPUT_ERR')) {
173                // GLOBAL_ERR を割り当て
174                $this->assign('GLOBAL_ERR', $GLOBAL_ERR);
175                define('OUTPUT_ERR','ON');
176            }
177        }
178
179        $this->_smarty->display($template);
180        if (ADMIN_MODE == '1') {
181            $time_end = microtime(true);
182            $time = $time_end - $this->time_start;
183            echo '処理時間: ' . sprintf('%.3f', $time) . '秒';
184        }
185    }
186
187    // オブジェクト内の変数をすべて割り当てる。
188    function assignobj($obj)
189    {
190        $data = get_object_vars($obj);
191
192        foreach ($data as $key => $value) {
193            $this->_smarty->assign($key, $value);
194        }
195    }
196
197    // 連想配列内の変数をすべて割り当てる。
198    function assignarray($array)
199    {
200        foreach ($array as $key => $val) {
201            $this->_smarty->assign($key, $val);
202        }
203    }
204
205    /**
206     * テンプレートパスをアサインする.
207     *
208     * @param integer $device_type_id 端末種別ID
209     */
210    function assignTemplatePath($device_type_id)
211    {
212
213        // テンプレート変数を割り当て
214        $this->assign('TPL_URLPATH', SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true));
215
216        // ヘッダとフッタを割り当て
217        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id);
218        $header_tpl = $templatePath . 'header.tpl';
219        $footer_tpl = $templatePath . 'footer.tpl';
220
221        $this->assign('header_tpl', $header_tpl);
222        $this->assign('footer_tpl', $footer_tpl);
223    }
224
225    // デバッグ
226    function debug($var = true)
227    {
228        $this->_smarty->debugging = $var;
229    }
230}
Note: See TracBrowser for help on using the repository browser.