| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 4 | * |
|---|
| 5 | * http://www.lockon.co.jp/ |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | $SC_VIEW_PHP_DIR = realpath(dirname(__FILE__)); |
|---|
| 9 | require_once($SC_VIEW_PHP_DIR . "/../module/Smarty/libs/Smarty.class.php"); |
|---|
| 10 | require_once($SC_VIEW_PHP_DIR . "/../include/php_ini.inc"); |
|---|
| 11 | |
|---|
| 12 | class SC_View { |
|---|
| 13 | |
|---|
| 14 | /** Smarty¥¤¥ó¥¹¥¿¥ó¥¹ */ |
|---|
| 15 | var $_smarty; |
|---|
| 16 | /** SC_SiteInfo¤Î¥¤¥ó¥¹¥¿¥ó¥¹ */ |
|---|
| 17 | var $objSiteInfo; |
|---|
| 18 | /** ¥Ú¡¼¥¸½ÐÎÏ¥Ù¥ó¥Á¥Þ¡¼¥¯¤Î³«»Ï»þ´Ö */ |
|---|
| 19 | var $time_start; |
|---|
| 20 | /** »ÈÍѤ·¤Æ¤¤¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥Ã¥±¡¼¥¸Ì¾ */ |
|---|
| 21 | var $tplName; |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * ¥³¥ó¥¹¥È¥é¥¯¥¿ |
|---|
| 25 | * |
|---|
| 26 | * @param boolean $assignSiteInfo ¥µ¥¤¥È¾ðÊó¤òassign¤¹¤ë¤«¤É¤¦¤« |
|---|
| 27 | */ |
|---|
| 28 | function SC_View($assignSiteInfo = true) { |
|---|
| 29 | // ¥Ú¡¼¥¸½ÐÎϤΥ٥ó¥Á¥Þ¡¼¥¯¥¹¥¿¡¼¥È |
|---|
| 30 | $this->setStartTime(); |
|---|
| 31 | |
|---|
| 32 | // Smarty½é´ü²½ |
|---|
| 33 | $this->initSmarty(); |
|---|
| 34 | |
|---|
| 35 | $this->tplName = $this->getTemplateName(); |
|---|
| 36 | $this->assignDefaultVars(); |
|---|
| 37 | |
|---|
| 38 | // ¥µ¥¤¥È¾ðÊó¤òassign¤¹¤ë |
|---|
| 39 | if($assignSiteInfo) $this->assignSiteInfo(); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * Smarty¤Î½é´ü²½. |
|---|
| 44 | * ½¤¾þ»ì¤ä¥Æ¥ó¥×¥ì¡¼¥È´Ø¿ô¤ÎÄêµÁ¤ò¹Ô¤¦. |
|---|
| 45 | * |
|---|
| 46 | * @param void |
|---|
| 47 | * @return void |
|---|
| 48 | */ |
|---|
| 49 | function initSmarty() { |
|---|
| 50 | $SC_VIEW_PHP_DIR = realpath(dirname(__FILE__)); |
|---|
| 51 | |
|---|
| 52 | $this->_smarty = new Smarty; |
|---|
| 53 | $this->_smarty->left_delimiter = '<!--{'; |
|---|
| 54 | $this->_smarty->right_delimiter = '}-->'; |
|---|
| 55 | $this->_smarty->register_modifier("sfDispDBDate","sfDispDBDate"); |
|---|
| 56 | $this->_smarty->register_modifier("sfConvSendDateToDisp","sfConvSendDateToDisp"); |
|---|
| 57 | $this->_smarty->register_modifier("sfConvSendWdayToDisp","sfConvSendWdayToDisp"); |
|---|
| 58 | $this->_smarty->register_modifier("sfGetVal", "sfGetVal"); |
|---|
| 59 | $this->_smarty->register_function("sfSetErrorStyle","sfSetErrorStyle"); |
|---|
| 60 | $this->_smarty->register_function("sfGetErrorColor","sfGetErrorColor"); |
|---|
| 61 | $this->_smarty->register_function("sfTrim", "sfTrim"); |
|---|
| 62 | $this->_smarty->register_function("sfPreTax", "sfPreTax"); |
|---|
| 63 | $this->_smarty->register_function("sfPrePoint", "sfPrePoint"); |
|---|
| 64 | $this->_smarty->register_function("sfGetChecked", "sfGetChecked"); |
|---|
| 65 | $this->_smarty->register_function("sfTrimURL", "sfTrimURL"); |
|---|
| 66 | $this->_smarty->register_function("sfMultiply", "sfMultiply"); |
|---|
| 67 | $this->_smarty->register_function("sfPutBR", "sfPutBR"); |
|---|
| 68 | $this->_smarty->register_function("sfRmDupSlash", "sfRmDupSlash"); |
|---|
| 69 | $this->_smarty->register_function("sfCutString", "sfCutString"); |
|---|
| 70 | $this->_smarty->plugins_dir = array("plugins", $SC_VIEW_PHP_DIR . "/../smarty_extends"); |
|---|
| 71 | $this->_smarty->register_function("sf_mb_convert_encoding","sf_mb_convert_encoding"); |
|---|
| 72 | $this->_smarty->register_function("sf_mktime","sf_mktime"); |
|---|
| 73 | $this->_smarty->register_function("sf_date","sf_date"); |
|---|
| 74 | $this->_smarty->register_function("str_replace","str_replace"); |
|---|
| 75 | $this->_smarty->register_function("sfPrintEbisTag","sfPrintEbisTag"); |
|---|
| 76 | $this->_smarty->register_function("sfPrintAffTag","sfPrintAffTag"); |
|---|
| 77 | $this->_smarty->register_function("sfIsHTTPS","sfIsHTTPS"); |
|---|
| 78 | $this->_smarty->default_modifiers = array('script_escape'); |
|---|
| 79 | $this->_smarty->force_compile = true; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * ¥Ú¡¼¥¸½ÐÎÏ¥Ù¥ó¥Á¥Þ¡¼¥¯¤Î³«»Ï»þ´Ö¤ò¥»¥Ã¥È¤¹¤ë. |
|---|
| 84 | * |
|---|
| 85 | * @param void |
|---|
| 86 | * @return void |
|---|
| 87 | */ |
|---|
| 88 | function setStartTime() { |
|---|
| 89 | // TODO PEAR::BenchMark»È¤¦¡© |
|---|
| 90 | $this->time_start = time(); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * ¥Ç¥Õ¥©¥ë¥È¤Î¥Æ¥ó¥×¥ì¡¼¥ÈÊÑ¿ô¤òassign¤¹¤ë. |
|---|
| 95 | */ |
|---|
| 96 | function assignDefaultVars() { |
|---|
| 97 | $arrDefaultParams = array( |
|---|
| 98 | 'URL_DIR' => URL_DIR, |
|---|
| 99 | // FIXME tplName¤¬null¤Î¾ì¹ç¤Î½èÍý |
|---|
| 100 | 'TPL_PKG_URL' => URL_DIR . USER_DIR . TPL_PKG_DIR . $this->tplName . '/' |
|---|
| 101 | ); |
|---|
| 102 | $this->assignArray($arrDefaultParams); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * ¥µ¥¤¥È¾ðÊó¤òassign¤¹¤ë. |
|---|
| 107 | * |
|---|
| 108 | * @param void |
|---|
| 109 | * @return void |
|---|
| 110 | */ |
|---|
| 111 | function assignSiteInfo() { |
|---|
| 112 | if (!defined('LOAD_SITEINFO')) { |
|---|
| 113 | $this->objSiteInfo = new SC_SiteInfo(); |
|---|
| 114 | $arrInfo['arrSiteInfo'] = $this->objSiteInfo->data; |
|---|
| 115 | |
|---|
| 116 | // ÅÔÆ»Éܸ©Ì¾¤òÊÑ´¹ |
|---|
| 117 | global $arrPref; |
|---|
| 118 | $arrInfo['arrSiteInfo']['pref'] = $arrPref[$arrInfo['arrSiteInfo']['pref']]; |
|---|
| 119 | |
|---|
| 120 | // ¥µ¥¤¥È¾ðÊó¤ò³ä¤êÅö¤Æ¤ë |
|---|
| 121 | $this->assignArray($arrInfo); |
|---|
| 122 | |
|---|
| 123 | define('LOAD_SITEINFO', 1); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * ¥Æ¥ó¥×¥ì¡¼¥È¤ËÃͤò³ä¤êÅö¤Æ¤ë |
|---|
| 129 | * |
|---|
| 130 | * @param string $key |
|---|
| 131 | * @param mixed $value |
|---|
| 132 | * @return void |
|---|
| 133 | */ |
|---|
| 134 | function assign($key, $value) { |
|---|
| 135 | $this->_smarty->assign($key, $value); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /** |
|---|
| 139 | * ¥Æ¥ó¥×¥ì¡¼¥È¤Î½èÍý·ë²Ì¤ò¼èÆÀ |
|---|
| 140 | * |
|---|
| 141 | * @param string $template tpl¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹ |
|---|
| 142 | * @return string ½ÐÎÏ·ë²Ì |
|---|
| 143 | */ |
|---|
| 144 | function fetch($template) { |
|---|
| 145 | return $this->_smarty->fetch($template); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * ¥Æ¥ó¥×¥ì¡¼¥È¤Î½èÍý·ë²Ì¤òɽ¼¨. |
|---|
| 150 | * |
|---|
| 151 | * @param string $template tpl¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹ |
|---|
| 152 | * @return void |
|---|
| 153 | */ |
|---|
| 154 | function display($template, $display = false) { |
|---|
| 155 | // ¥Æ¥ó¥×¥ì¡¼¥ÈÀÚ¤êÂØ¤¨½èÍý |
|---|
| 156 | $this->initDisplay($template); |
|---|
| 157 | |
|---|
| 158 | // ¥°¥í¡¼¥Ð¥ë¥¨¥é¡¼¤Îɽ¼¨ |
|---|
| 159 | $this->displayGlobalError($display); |
|---|
| 160 | |
|---|
| 161 | // ²èÌÌɽ¼¨ |
|---|
| 162 | $this->_smarty->display($template); |
|---|
| 163 | |
|---|
| 164 | // ¥Ù¥ó¥Á¥Þ¡¼¥¯·ë²Ì¤Îɽ¼¨ |
|---|
| 165 | $this->displayBenchMark(); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | /** |
|---|
| 169 | * ¥Æ¥ó¥×¥ì¡¼¥ÈÀÚ¤êÂØ¤¨½èÍý¤ò¹Ô¤¦. |
|---|
| 170 | * ¼ÂÁõ¤Ï»Ò¥¯¥é¥¹¤Ç¹Ô¤¦. |
|---|
| 171 | */ |
|---|
| 172 | function initDisplay($template) {} |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * ¥°¥í¡¼¥Ð¥ë¥¨¥é¡¼¤òɽ¼¨¤¹¤ë. |
|---|
| 176 | * |
|---|
| 177 | * @param boolean $display |
|---|
| 178 | * @return void |
|---|
| 179 | */ |
|---|
| 180 | function displayGlobalError($display = false) { |
|---|
| 181 | if (!$display) { |
|---|
| 182 | global $GLOBAL_ERR; |
|---|
| 183 | if(!defined('OUTPUT_ERR')) { |
|---|
| 184 | print($GLOBAL_ERR); |
|---|
| 185 | define('OUTPUT_ERR','ON'); |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | /** |
|---|
| 191 | * ¥Ú¡¼¥¸½ÐÎÏ¥Ù¥ó¥Á¥Þ¡¼¥¯¤Î·ë²Ì¤òɽ¼¨¤¹¤ë. |
|---|
| 192 | * ADMIN_MODE¤¬true¤Î¤È¤¤Î¤ß͸ú. |
|---|
| 193 | * |
|---|
| 194 | * @param void |
|---|
| 195 | * @return void |
|---|
| 196 | */ |
|---|
| 197 | function displayBenchMark() { |
|---|
| 198 | if (ADMIN_MODE) { |
|---|
| 199 | $time_end = time(); |
|---|
| 200 | $time = $time_end - $this->time_start; |
|---|
| 201 | print("½èÍý»þ´Ö:" . $time . "ÉÃ"); |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | /** |
|---|
| 206 | * ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥á¥ó¥ÐÊÑ¿ô¤òassign¤¹¤ë. |
|---|
| 207 | * |
|---|
| 208 | * @param object $obj LC_Page¤Î¥¤¥ó¥¹¥¿¥ó¥¹ |
|---|
| 209 | * @return void |
|---|
| 210 | */ |
|---|
| 211 | function assignObj($obj) { |
|---|
| 212 | $this->assignArray(get_object_vars($obj)); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | /** |
|---|
| 216 | * Ï¢ÁÛÇÛÎó¤òassign¤¹¤ë. |
|---|
| 217 | * |
|---|
| 218 | * @param array $arrAssignVars assign¤¹¤ëÏ¢ÁÛÇÛÎó |
|---|
| 219 | * @return void |
|---|
| 220 | */ |
|---|
| 221 | function assignArray($arrAssignVars) { |
|---|
| 222 | foreach ($arrAssignVars as $key => $val) { |
|---|
| 223 | $this->assign($key, $val); |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | /** |
|---|
| 228 | * »ÈÍѤ·¤Æ¤¤¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò¼èÆÀ¤¹¤ë |
|---|
| 229 | */ |
|---|
| 230 | function getTemplateName() { |
|---|
| 231 | $objQuery = new SC_Query(); |
|---|
| 232 | $arrRet = $objQuery->select('top_tpl', 'dtb_baseinfo'); |
|---|
| 233 | |
|---|
| 234 | if (isset($arrRet[0]['top_tpl'])) { |
|---|
| 235 | return $arrRet[0]['top_tpl']; |
|---|
| 236 | } |
|---|
| 237 | return null; |
|---|
| 238 | } |
|---|
| 239 | /** |
|---|
| 240 | * Smarty¤Î¥Ç¥Ð¥Ã¥°½ÐÎϤò͸ú¤Ë¤¹¤ë. |
|---|
| 241 | * |
|---|
| 242 | * @param void |
|---|
| 243 | * @return void |
|---|
| 244 | */ |
|---|
| 245 | function debug($var = true){ |
|---|
| 246 | $this->_smarty->debugging = $var; |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | class SC_AdminView extends SC_View{ |
|---|
| 251 | function SC_AdminView() { |
|---|
| 252 | parent::SC_View(false); |
|---|
| 253 | $this->_smarty->template_dir = TEMPLATE_ADMIN_DIR; |
|---|
| 254 | $this->_smarty->compile_dir = COMPILE_ADMIN_DIR; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | class SC_SiteView extends SC_View{ |
|---|
| 260 | function SC_SiteView($cart = true) { |
|---|
| 261 | parent::SC_View(); |
|---|
| 262 | |
|---|
| 263 | $this->_smarty->template_dir = TEMPLATE_DIR; |
|---|
| 264 | $this->_smarty->compile_dir = COMPILE_DIR; |
|---|
| 265 | |
|---|
| 266 | // PHP5¤Ç¤Ïsession¤ò¥¹¥¿¡¼¥È¤¹¤ëÁ°¤Ë¥Ø¥Ã¥À¡¼¾ðÊó¤òÁ÷¿®¤·¤Æ¤¤¤ë¤È·Ù¹ð¤¬½Ð¤ë¤¿¤á¡¢Àè¤Ë¥»¥Ã¥·¥ç¥ó¤ò¥¹¥¿¡¼¥È¤¹¤ë¤è¤¦¤ËÊѹ¹ |
|---|
| 267 | sfDomainSessionStart(); |
|---|
| 268 | |
|---|
| 269 | if($cart){ |
|---|
| 270 | $include_dir = realpath(dirname( __FILE__)); |
|---|
| 271 | require_once($include_dir . "/SC_CartSession.php"); |
|---|
| 272 | $objCartSess = new SC_CartSession(); |
|---|
| 273 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | function initDisplay($template) { |
|---|
| 278 | // ¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ïreturn |
|---|
| 279 | if (empty($this->tplName)) return; |
|---|
| 280 | |
|---|
| 281 | /** |
|---|
| 282 | * tpl_mainpage¤¬ÁêÂХѥ¹¤Ç¤¢¤ì¤Ð |
|---|
| 283 | * ¥æ¡¼¥¶¡¼¥Æ¥ó¥×¥ì¡¼¥È¤Ø¤ÎÀäÂХѥ¹¤ËÊѹ¹¤· |
|---|
| 284 | * ¤½¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ð¤¢¤¤¤Ïtpl_meinpage¤òºÆÅÙassign¤·¾å½ñ¤¤¹¤ë |
|---|
| 285 | */ |
|---|
| 286 | $tpl_mainpage = $this->_smarty->get_template_vars('tpl_mainpage'); |
|---|
| 287 | $template_dir = TPL_PKG_PATH . $this->tplName . '/templates/'; |
|---|
| 288 | |
|---|
| 289 | $win = "^[a-zA-Z]{1}:"; |
|---|
| 290 | $other = "^\/"; |
|---|
| 291 | $pattern = "/($win)|($other)/"; |
|---|
| 292 | if (!preg_match($pattern, $tpl_mainpage)) { |
|---|
| 293 | $tpl_pkg_mainpage = $template_dir . $tpl_mainpage; |
|---|
| 294 | if (file_exists($tpl_pkg_mainpage)) { |
|---|
| 295 | $this->assign('tpl_mainpage', $tpl_pkg_mainpage); |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | class SC_UserView extends SC_SiteView{ |
|---|
| 301 | function SC_UserView($template_dir, $compile_dir = COMPILE_DIR) { |
|---|
| 302 | parent::SC_SiteView(); |
|---|
| 303 | $this->_smarty->template_dir = $template_dir; |
|---|
| 304 | $this->_smarty->compile_dir = $compile_dir; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | function display($template) { |
|---|
| 308 | $this->_smarty->display($template); |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | class SC_InstallView extends SC_View{ |
|---|
| 313 | function SC_InstallView($template_dir, $compile_dir = COMPILE_DIR) { |
|---|
| 314 | parent::SC_View(false); |
|---|
| 315 | $this->_smarty->template_dir = $template_dir; |
|---|
| 316 | $this->_smarty->compile_dir = $compile_dir; |
|---|
| 317 | } |
|---|
| 318 | function getTemplateName() {} |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | class SC_MobileView extends SC_SiteView { |
|---|
| 322 | function SC_MobileView() { |
|---|
| 323 | parent::SC_SiteView(); |
|---|
| 324 | $this->_smarty->template_dir = MOBILE_TEMPLATE_DIR; |
|---|
| 325 | $this->_smarty->compile_dir = MOBILE_COMPILE_DIR; |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | ?> |
|---|