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