| 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 | |
---|
| 24 | $viewDir = realpath(dirname(__FILE__)) . '/'; // XXX グローバル変数として流用あり |
---|
| 25 | require_once $viewDir . '../module/Smarty/libs/Smarty.class.php'; |
---|
| 26 | |
---|
| 27 | class SC_View { |
---|
| 28 | |
---|
| 29 | var $_smarty; |
---|
| 30 | var $objSiteInfo; // サイト情報 |
---|
| 31 | |
---|
| 32 | // コンストラクタ |
---|
| 33 | function SC_View($siteinfo = true) { |
---|
| 34 | global $viewDir; |
---|
| 35 | |
---|
| 36 | $this->_smarty = new Smarty; |
---|
| 37 | $this->_smarty->left_delimiter = '<!--{'; |
---|
| 38 | $this->_smarty->right_delimiter = '}-->'; |
---|
| 39 | $this->_smarty->register_modifier("sfDispDBDate", array("SC_Utils_Ex", "sfDispDBDate")); |
---|
| 40 | $this->_smarty->register_modifier("sfConvSendDateToDisp", array("SC_Utils_Ex", "sfConvSendDateToDisp")); |
---|
| 41 | $this->_smarty->register_modifier("sfConvSendWdayToDisp", array("SC_Utils_Ex", "sfConvSendWdayToDisp")); |
---|
| 42 | $this->_smarty->register_modifier("sfGetVal", array("SC_Utils_Ex", "sfGetVal")); |
---|
| 43 | $this->_smarty->register_modifier("sfGetErrorColor", array("SC_Utils_Ex", "sfGetErrorColor")); |
---|
| 44 | $this->_smarty->register_modifier("sfTrim", array("SC_Utils_Ex", "sfTrim")); |
---|
| 45 | $this->_smarty->register_modifier("sfCalcIncTax", array("SC_Helper_DB_Ex", "sfCalcIncTax")); |
---|
| 46 | $this->_smarty->register_modifier("sfPrePoint", array("SC_Utils_Ex", "sfPrePoint")); |
---|
| 47 | $this->_smarty->register_modifier("sfGetChecked",array("SC_Utils_Ex", "sfGetChecked")); |
---|
| 48 | $this->_smarty->register_modifier("sfTrimURL", array("SC_Utils_Ex", "sfTrimURL")); |
---|
| 49 | $this->_smarty->register_modifier("sfMultiply", array("SC_Utils_Ex", "sfMultiply")); |
---|
| 50 | $this->_smarty->register_modifier("sfPutBR", array("SC_Utils_Ex", "sfPutBR")); |
---|
| 51 | $this->_smarty->register_modifier("sfRmDupSlash", array("SC_Utils_Ex", "sfRmDupSlash")); |
---|
| 52 | $this->_smarty->register_modifier("sfCutString", array("SC_Utils_Ex", "sfCutString")); |
---|
| 53 | $this->_smarty->plugins_dir=array("plugins", $viewDir . "../smarty_extends"); |
---|
| 54 | $this->_smarty->register_modifier("sfMbConvertEncoding", array("SC_Utils_Ex", "sfMbConvertEncoding")); |
---|
| 55 | $this->_smarty->register_modifier("sfGetEnabled", array("SC_Utils_Ex", "sfGetEnabled")); |
---|
| 56 | $this->_smarty->register_modifier("sfGetCategoryId", array("SC_Utils_Ex", "sfGetCategoryId")); |
---|
| 57 | $this->_smarty->register_modifier("sfNoImageMainList", array("SC_Utils_Ex", "sfNoImageMainList")); |
---|
| 58 | $this->_smarty->register_function("sfIsHTTPS", array("SC_Utils_Ex", "sfIsHTTPS")); |
---|
| 59 | $this->_smarty->register_function("sfSetErrorStyle", array("SC_Utils_Ex", "sfSetErrorStyle")); |
---|
| 60 | $this->_smarty->register_function("printXMLDeclaration", array("SC_Utils_Ex", "printXMLDeclaration")); |
---|
| 61 | $this->_smarty->default_modifiers = array('script_escape'); |
---|
| 62 | |
---|
| 63 | if(ADMIN_MODE == '1') { |
---|
| 64 | $this->time_start = SC_Utils_Ex::sfMicrotimeFloat(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // サイト情報を取得する |
---|
| 68 | // XXX LC_Page 配下で取得した方が良い |
---|
| 69 | if($siteinfo) { |
---|
| 70 | if(!defined('LOAD_SITEINFO')) { |
---|
| 71 | $this->objSiteInfo = new SC_SiteInfo(); |
---|
| 72 | $arrInfo['arrSiteInfo'] = $this->objSiteInfo->data; |
---|
| 73 | |
---|
| 74 | // 都道府県名を変換 |
---|
| 75 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 76 | $arrPref = $masterData->getMasterData('mtb_pref'); |
---|
| 77 | $arrInfo['arrSiteInfo']['pref'] = |
---|
| 78 | isset($arrPref[$arrInfo['arrSiteInfo']['pref']]) |
---|
| 79 | ? $arrPref[$arrInfo['arrSiteInfo']['pref']] : ""; |
---|
| 80 | |
---|
| 81 | // サイト情報を割り当てる |
---|
| 82 | foreach ($arrInfo as $key => $value){ |
---|
| 83 | $this->_smarty->assign($key, $value); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | define('LOAD_SITEINFO', 1); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | // テンプレートに値を割り当てる |
---|
| 92 | function assign($val1, $val2) { |
---|
| 93 | $this->_smarty->assign($val1, $val2); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | // テンプレートの処理結果を取得 |
---|
| 97 | function fetch($template, $no_error=false) { |
---|
| 98 | return $this->_smarty->fetch($template); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * SC_Display用にレスポンスを返す |
---|
| 103 | * @global string $GLOBAL_ERR |
---|
| 104 | * @param array $template |
---|
| 105 | * @param boolean $no_error |
---|
| 106 | * @return string |
---|
| 107 | */ |
---|
| 108 | function getResponse($template, $no_error = false) { |
---|
| 109 | if(!$no_error) { |
---|
| 110 | global $GLOBAL_ERR; |
---|
| 111 | if(!defined('OUTPUT_ERR')) { |
---|
| 112 | // GLOBAL_ERR を割り当て |
---|
| 113 | $this->assign("GLOBAL_ERR", $GLOBAL_ERR); |
---|
| 114 | define('OUTPUT_ERR','ON'); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | $res = $this->_smarty->fetch($template); |
---|
| 118 | if(ADMIN_MODE == '1') { |
---|
| 119 | $time_end = SC_Utils_Ex::sfMicrotimeFloat(); |
---|
| 120 | $time = $time_end - $this->time_start; |
---|
| 121 | $res .= '処理時間: ' . sprintf('%.3f', $time) . '秒'; |
---|
| 122 | } |
---|
| 123 | return $res; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // テンプレートの処理結果を表示 |
---|
| 127 | function display($template, $no_error = false) { |
---|
| 128 | if(!$no_error) { |
---|
| 129 | global $GLOBAL_ERR; |
---|
| 130 | if(!defined('OUTPUT_ERR')) { |
---|
| 131 | // GLOBAL_ERR を割り当て |
---|
| 132 | $this->assign("GLOBAL_ERR", $GLOBAL_ERR); |
---|
| 133 | define('OUTPUT_ERR','ON'); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | $this->_smarty->display($template); |
---|
| 138 | if(ADMIN_MODE == '1') { |
---|
| 139 | $time_end = SC_Utils_Ex::sfMicrotimeFloat(); |
---|
| 140 | $time = $time_end - $this->time_start; |
---|
| 141 | echo '処理時間: ' . sprintf('%.3f', $time) . '秒'; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | // オブジェクト内の変数をすべて割り当てる。 |
---|
| 146 | function assignobj($obj) { |
---|
| 147 | $data = get_object_vars($obj); |
---|
| 148 | |
---|
| 149 | foreach ($data as $key => $value){ |
---|
| 150 | $this->_smarty->assign($key, $value); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // 連想配列内の変数をすべて割り当てる。 |
---|
| 155 | function assignarray($array) { |
---|
| 156 | foreach ($array as $key => $val) { |
---|
| 157 | $this->_smarty->assign($key, $val); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /* サイト初期設定 */ |
---|
| 162 | function initpath() { |
---|
| 163 | global $viewDir; |
---|
| 164 | |
---|
| 165 | $array['tpl_mainnavi'] = $viewDir . '../Smarty/templates/frontparts/mainnavi.tpl'; |
---|
| 166 | |
---|
| 167 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 168 | $array['tpl_root_id'] = $objDb->sfGetRootId(); |
---|
| 169 | $this->assignarray($array); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * テンプレートパスをアサインする. |
---|
| 174 | * |
---|
| 175 | * @param integer $device_type_id 端末種別ID |
---|
| 176 | */ |
---|
| 177 | function assignTemplatePath($device_type_id) { |
---|
| 178 | |
---|
| 179 | // テンプレート変数を割り当て |
---|
| 180 | $this->assign("TPL_URLPATH", SC_Helper_PageLayout_Ex::getUserDir($device_type_id, true)); |
---|
| 181 | |
---|
| 182 | // ヘッダとフッタを割り当て |
---|
| 183 | $templatePath = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id); |
---|
| 184 | $header_tpl = $templatePath . "header.tpl"; |
---|
| 185 | $footer_tpl = $templatePath . "footer.tpl"; |
---|
| 186 | |
---|
| 187 | $this->assign("header_tpl", $header_tpl); |
---|
| 188 | $this->assign("footer_tpl", $footer_tpl); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | // デバッグ |
---|
| 192 | function debug($var = true){ |
---|
| 193 | $this->_smarty->debugging = $var; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | ?> |
---|