| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2011 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 SC_View() { |
|---|
| 34 | |
|---|
| 35 | $this->_smarty = new Smarty; |
|---|
| 36 | $this->_smarty->left_delimiter = '<!--{'; |
|---|
| 37 | $this->_smarty->right_delimiter = '}-->'; |
|---|
| 38 | $this->_smarty->register_modifier('sfDispDBDate', array('SC_Utils_Ex', 'sfDispDBDate')); |
|---|
| 39 | $this->_smarty->register_modifier('sfConvSendDateToDisp', array('SC_Utils_Ex', 'sfConvSendDateToDisp')); |
|---|
| 40 | $this->_smarty->register_modifier('sfConvSendWdayToDisp', array('SC_Utils_Ex', 'sfConvSendWdayToDisp')); |
|---|
| 41 | $this->_smarty->register_modifier('sfGetVal', array('SC_Utils_Ex', 'sfGetVal')); |
|---|
| 42 | $this->_smarty->register_modifier('sfGetErrorColor', array('SC_Utils_Ex', 'sfGetErrorColor')); |
|---|
| 43 | $this->_smarty->register_modifier('sfTrim', array('SC_Utils_Ex', 'sfTrim')); |
|---|
| 44 | $this->_smarty->register_modifier('sfCalcIncTax', array('SC_Helper_DB_Ex', 'sfCalcIncTax')); |
|---|
| 45 | $this->_smarty->register_modifier('sfPrePoint', array('SC_Utils_Ex', 'sfPrePoint')); |
|---|
| 46 | $this->_smarty->register_modifier('sfGetChecked',array('SC_Utils_Ex', 'sfGetChecked')); |
|---|
| 47 | $this->_smarty->register_modifier('sfTrimURL', array('SC_Utils_Ex', 'sfTrimURL')); |
|---|
| 48 | $this->_smarty->register_modifier('sfMultiply', array('SC_Utils_Ex', 'sfMultiply')); |
|---|
| 49 | $this->_smarty->register_modifier('sfRmDupSlash', array('SC_Utils_Ex', 'sfRmDupSlash')); |
|---|
| 50 | $this->_smarty->register_modifier('sfCutString', array('SC_Utils_Ex', 'sfCutString')); |
|---|
| 51 | $this->_smarty->plugins_dir=array('plugins', realpath(dirname(__FILE__)) . '/../smarty_extends'); |
|---|
| 52 | $this->_smarty->register_modifier('sfMbConvertEncoding', array('SC_Utils_Ex', 'sfMbConvertEncoding')); |
|---|
| 53 | $this->_smarty->register_modifier('sfGetEnabled', array('SC_Utils_Ex', 'sfGetEnabled')); |
|---|
| 54 | $this->_smarty->register_modifier('sfGetCategoryId', array('SC_Utils_Ex', 'sfGetCategoryId')); |
|---|
| 55 | $this->_smarty->register_modifier('sfNoImageMainList', array('SC_Utils_Ex', 'sfNoImageMainList')); |
|---|
| 56 | // XXX register_function で登録すると if で使用できないのではないか? |
|---|
| 57 | $this->_smarty->register_function('sfIsHTTPS', array('SC_Utils_Ex', 'sfIsHTTPS')); |
|---|
| 58 | $this->_smarty->register_function('sfSetErrorStyle', array('SC_Utils_Ex', 'sfSetErrorStyle')); |
|---|
| 59 | $this->_smarty->register_function('printXMLDeclaration', array('GC_Utils_Ex', 'printXMLDeclaration')); |
|---|
| 60 | $this->_smarty->default_modifiers = array('script_escape'); |
|---|
| 61 | |
|---|
| 62 | if (ADMIN_MODE == '1') { |
|---|
| 63 | $this->time_start = microtime(true); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | if(SMARTY_FORCE_COMPILE_MODE === true) { |
|---|
| 67 | $this->_smarty->force_compile = true; |
|---|
| 68 | } else { |
|---|
| 69 | $this->_smarty->force_compile = false; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | // テンプレートに値を割り当てる |
|---|
| 74 | function assign($val1, $val2) { |
|---|
| 75 | $this->_smarty->assign($val1, $val2); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | // テンプレートの処理結果を取得 |
|---|
| 79 | function fetch($template, $no_error=false) { |
|---|
| 80 | return $this->_smarty->fetch($template); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * SC_Display用にレスポンスを返す |
|---|
| 85 | * @global string $GLOBAL_ERR |
|---|
| 86 | * @param array $template |
|---|
| 87 | * @param boolean $no_error |
|---|
| 88 | * @return string |
|---|
| 89 | */ |
|---|
| 90 | function getResponse($template, $no_error = false) { |
|---|
| 91 | if (!$no_error) { |
|---|
| 92 | global $GLOBAL_ERR; |
|---|
| 93 | if (!defined('OUTPUT_ERR')) { |
|---|
| 94 | // GLOBAL_ERR を割り当て |
|---|
| 95 | $this->assign('GLOBAL_ERR', $GLOBAL_ERR); |
|---|
| 96 | define('OUTPUT_ERR','ON'); |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | // 各filterをセットします. |
|---|
| 100 | $this->registFilter(); |
|---|
| 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 | return $res; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * Pageオブジェクトをセットします. |
|---|
| 112 | * @param LC_Page_Ex $objPage |
|---|
| 113 | * @return void |
|---|
| 114 | */ |
|---|
| 115 | function setPage(LC_Page_Ex $objPage) { |
|---|
| 116 | $this->objPage = $objPage; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Smartyのfilterをセットします. |
|---|
| 121 | * @return void |
|---|
| 122 | */ |
|---|
| 123 | function registFilter() { |
|---|
| 124 | $this->_smarty->register_prefilter(array(&$this, 'prefilter_transform')); |
|---|
| 125 | $this->_smarty->register_outputfilter(array(&$this, 'outputfilter_transform')); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | * prefilter用のフィルタ関数。プラグイン用のフックポイント処理を実行 |
|---|
| 130 | * @param string $source ソース |
|---|
| 131 | * @param Smarty_Compiler $smarty Smartyのコンパイラクラス |
|---|
| 132 | * @return string $source ソース |
|---|
| 133 | */ |
|---|
| 134 | function prefilter_transform($source, &$smarty) { |
|---|
| 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 | return $source; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * outputfilter用のフィルタ関数。プラグイン用のフックポイント処理を実行 |
|---|
| 143 | * @param string $source ソース |
|---|
| 144 | * @param Smarty_Compiler $smarty Smartyのコンパイラクラス |
|---|
| 145 | * @return string $source ソース |
|---|
| 146 | */ |
|---|
| 147 | function outputfilter_transform($source, &$smarty) { |
|---|
| 148 | // フックポイントを実行. |
|---|
| 149 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->objPage->plugin_activate_flg); |
|---|
| 150 | $objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $smarty->_current_file)); |
|---|
| 151 | return $source; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | // テンプレートの処理結果を表示 |
|---|
| 155 | function display($template, $no_error = false) { |
|---|
| 156 | if (!$no_error) { |
|---|
| 157 | global $GLOBAL_ERR; |
|---|
| 158 | if (!defined('OUTPUT_ERR')) { |
|---|
| 159 | // GLOBAL_ERR を割り当て |
|---|
| 160 | $this->assign('GLOBAL_ERR', $GLOBAL_ERR); |
|---|
| 161 | define('OUTPUT_ERR','ON'); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | $this->_smarty->display($template); |
|---|
| 166 | if (ADMIN_MODE == '1') { |
|---|
| 167 | $time_end = microtime(true); |
|---|
| 168 | $time = $time_end - $this->time_start; |
|---|
| 169 | echo '処理時間: ' . sprintf('%.3f', $time) . '秒'; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | // オブジェクト内の変数をすべて割り当てる。 |
|---|
| 174 | function assignobj($obj) { |
|---|
| 175 | $data = get_object_vars($obj); |
|---|
| 176 | |
|---|
| 177 | foreach ($data as $key => $value) { |
|---|
| 178 | $this->_smarty->assign($key, $value); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | // 連想配列内の変数をすべて割り当てる。 |
|---|
| 183 | function assignarray($array) { |
|---|
| 184 | foreach ($array as $key => $val) { |
|---|
| 185 | $this->_smarty->assign($key, $val); |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | /* サイト初期設定 */ |
|---|
| 190 | function initpath() { |
|---|
| 191 | |
|---|
| 192 | $array['tpl_mainnavi'] = realpath(dirname(__FILE__)) . '/../Smarty/templates/frontparts/mainnavi.tpl'; |
|---|
| 193 | |
|---|
| 194 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 195 | $array['tpl_root_id'] = $objDb->sfGetRootId(); |
|---|
| 196 | $this->assignarray($array); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /** |
|---|
| 200 | * テンプレートパスをアサインする. |
|---|
| 201 | * |
|---|
| 202 | * @param integer $device_type_id 端末種別ID |
|---|
| 203 | */ |
|---|
| 204 | function assignTemplatePath($device_type_id) { |
|---|
| 205 | |
|---|
| 206 | // テンプレート変数を割り当て |
|---|
| 207 | $this->assign('TPL_URLPATH', SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true)); |
|---|
| 208 | |
|---|
| 209 | // ヘッダとフッタを割り当て |
|---|
| 210 | $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id); |
|---|
| 211 | $header_tpl = $templatePath . 'header.tpl'; |
|---|
| 212 | $footer_tpl = $templatePath . 'footer.tpl'; |
|---|
| 213 | |
|---|
| 214 | $this->assign('header_tpl', $header_tpl); |
|---|
| 215 | $this->assign('footer_tpl', $footer_tpl); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | // デバッグ |
|---|
| 219 | function debug($var = true) { |
|---|
| 220 | $this->_smarty->debugging = $var; |
|---|
| 221 | } |
|---|
| 222 | } |
|---|