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