source: branches/version-2_5-dev/data/class/SC_View.php @ 20540

Revision 20540, 6.7 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)

  • 半SP
  • 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-2010 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    // コンストラクタ
31    function SC_View($siteinfo = true) {
32
33        $this->_smarty = new Smarty;
34        $this->_smarty->left_delimiter = '<!--{';
35        $this->_smarty->right_delimiter = '}-->';
36        $this->_smarty->register_modifier('sfDispDBDate', array("SC_Utils_Ex", 'sfDispDBDate'));
37        $this->_smarty->register_modifier('sfConvSendDateToDisp', array("SC_Utils_Ex", 'sfConvSendDateToDisp'));
38        $this->_smarty->register_modifier('sfConvSendWdayToDisp', array("SC_Utils_Ex", 'sfConvSendWdayToDisp'));
39        $this->_smarty->register_modifier('sfGetVal', array("SC_Utils_Ex", 'sfGetVal'));
40        $this->_smarty->register_modifier('sfGetErrorColor', array("SC_Utils_Ex", 'sfGetErrorColor'));
41        $this->_smarty->register_modifier('sfTrim', array("SC_Utils_Ex", 'sfTrim'));
42        $this->_smarty->register_modifier('sfCalcIncTax', array("SC_Helper_DB_Ex", 'sfCalcIncTax'));
43        $this->_smarty->register_modifier('sfPrePoint', array("SC_Utils_Ex", 'sfPrePoint'));
44        $this->_smarty->register_modifier('sfGetChecked',array("SC_Utils_Ex", 'sfGetChecked'));
45        $this->_smarty->register_modifier('sfTrimURL', array("SC_Utils_Ex", 'sfTrimURL'));
46        $this->_smarty->register_modifier('sfMultiply', array("SC_Utils_Ex", 'sfMultiply'));
47        $this->_smarty->register_modifier('sfPutBR', array("SC_Utils_Ex", 'sfPutBR'));
48        $this->_smarty->register_modifier('sfRmDupSlash', array("SC_Utils_Ex", 'sfRmDupSlash'));
49        $this->_smarty->register_modifier('sfCutString', array("SC_Utils_Ex", 'sfCutString'));
50        $this->_smarty->plugins_dir=array('plugins', realpath(dirname(__FILE__)) . "/../smarty_extends");
51        $this->_smarty->register_modifier('sfMbConvertEncoding', array("SC_Utils_Ex", 'sfMbConvertEncoding'));
52        $this->_smarty->register_modifier('sfGetEnabled', array("SC_Utils_Ex", 'sfGetEnabled'));
53        $this->_smarty->register_modifier('sfGetCategoryId', array("SC_Utils_Ex", 'sfGetCategoryId'));
54        $this->_smarty->register_modifier('sfNoImageMainList', array("SC_Utils_Ex", 'sfNoImageMainList'));
55        $this->_smarty->register_function('sfIsHTTPS', array("SC_Utils_Ex", 'sfIsHTTPS'));
56        $this->_smarty->register_function('sfSetErrorStyle', array("SC_Utils_Ex", 'sfSetErrorStyle'));
57        $this->_smarty->register_function('printXMLDeclaration', array("SC_Utils_Ex", 'printXMLDeclaration'));
58        $this->_smarty->default_modifiers = array('script_escape');
59
60        if(ADMIN_MODE == '1') {
61            $this->time_start = SC_Utils_Ex::sfMicrotimeFloat();
62        }
63    }
64
65    // テンプレートに値を割り当てる
66    function assign($val1, $val2) {
67        $this->_smarty->assign($val1, $val2);
68    }
69
70    // テンプレートの処理結果を取得
71    function fetch($template, $no_error=false) {
72        return $this->_smarty->fetch($template);
73    }
74
75    /**
76     * SC_Display用にレスポンスを返す
77     * @global string $GLOBAL_ERR
78     * @param array $template
79     * @param boolean $no_error
80     * @return string
81     */
82    function getResponse($template, $no_error = false) {
83        if(!$no_error) {
84            global $GLOBAL_ERR;
85            if(!defined('OUTPUT_ERR')) {
86                // GLOBAL_ERR を割り当て
87                $this->assign("GLOBAL_ERR", $GLOBAL_ERR);
88                define('OUTPUT_ERR','ON');
89            }
90        }
91        $res =  $this->_smarty->fetch($template);
92        if(ADMIN_MODE == '1') {
93            $time_end = SC_Utils_Ex::sfMicrotimeFloat();
94            $time = $time_end - $this->time_start;
95            $res .= '処理時間: ' . sprintf('%.3f', $time) . '秒';
96        }
97        return $res;
98    }
99
100    // テンプレートの処理結果を表示
101    function display($template, $no_error = false) {
102        if(!$no_error) {
103            global $GLOBAL_ERR;
104            if(!defined('OUTPUT_ERR')) {
105                // GLOBAL_ERR を割り当て
106                $this->assign("GLOBAL_ERR", $GLOBAL_ERR);
107                define('OUTPUT_ERR','ON');
108            }
109        }
110
111        $this->_smarty->display($template);
112        if(ADMIN_MODE == '1') {
113            $time_end = SC_Utils_Ex::sfMicrotimeFloat();
114            $time = $time_end - $this->time_start;
115            echo '処理時間: ' . sprintf('%.3f', $time) . '秒';
116        }
117    }
118
119      // オブジェクト内の変数をすべて割り当てる。
120      function assignobj($obj) {
121        $data = get_object_vars($obj);
122
123        foreach ($data as $key => $value){
124            $this->_smarty->assign($key, $value);
125        }
126      }
127
128      // 連想配列内の変数をすべて割り当てる。
129      function assignarray($array) {
130          foreach ($array as $key => $val) {
131              $this->_smarty->assign($key, $val);
132          }
133      }
134
135    /* サイト初期設定 */
136    function initpath() {
137
138        $array['tpl_mainnavi'] = realpath(dirname(__FILE__)) . '/../Smarty/templates/frontparts/mainnavi.tpl';
139
140        $objDb = new SC_Helper_DB_Ex();
141        $array['tpl_root_id'] = $objDb->sfGetRootId();
142        $this->assignarray($array);
143    }
144
145    /**
146     * テンプレートパスをアサインする.
147     *
148     * @param integer $device_type_id 端末種別ID
149     */
150    function assignTemplatePath($device_type_id) {
151
152        // テンプレート変数を割り当て
153        $this->assign("TPL_URLPATH", SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true));
154
155        // ヘッダとフッタを割り当て
156        $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id);
157        $header_tpl = $templatePath . "header.tpl";
158        $footer_tpl = $templatePath . "footer.tpl";
159
160        $this->assign("header_tpl", $header_tpl);
161        $this->assign("footer_tpl", $footer_tpl);
162    }
163
164    // デバッグ
165    function debug($var = true){
166        $this->_smarty->debugging = $var;
167    }
168}
169
170?>
Note: See TracBrowser for help on using the repository browser.