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 | /** |
---|
25 | * Webãã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ
å ±ãå¶å¾¡ãããã«ãã¼ã¯ã©ã¹. |
---|
26 | * |
---|
27 | * @package Helper |
---|
28 | * @author LOCKON CO.,LTD. |
---|
29 | * @version $Id:SC_Helper_PageLayout.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
30 | */ |
---|
31 | class SC_Helper_PageLayout |
---|
32 | { |
---|
33 | /** |
---|
34 | * ãã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ
å ±ãåå¾ã, è¨å®ãã. |
---|
35 | * |
---|
36 | * ç¾å¨ã® URL ã«å¿ãããã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ
å ±ãåå¾ã, LC_Page ã¤ã³ã¹ã¿ã³ã¹ã« |
---|
37 | * è¨å®ãã. |
---|
38 | * |
---|
39 | * @access public |
---|
40 | * @param LC_Page $objPage LC_Page ã¤ã³ã¹ã¿ã³ã¹ |
---|
41 | * @param boolean $preview ãã¬ãã¥ã¼è¡¨ç¤ºã®å ´å true |
---|
42 | * @param string $url ãã¼ã¸ã®URL($_SERVER['SCRIPT_NAME'] ã®æ
å ±) |
---|
43 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
44 | * @return void |
---|
45 | */ |
---|
46 | public function sfGetPageLayout(&$objPage, $preview = false, $url = '', $device_type_id = DEVICE_TYPE_PC) |
---|
47 | { |
---|
48 | // URLãå
ã«ãã¼ã¸æ
å ±ãåå¾ |
---|
49 | if ($preview === false) { |
---|
50 | $url = preg_replace('|^' . preg_quote(ROOT_URLPATH) . '|', '', $url); |
---|
51 | $arrPageData = $this->getPageProperties($device_type_id, null, 'url = ?', array($url)); |
---|
52 | } |
---|
53 | // ãã¬ãã¥ã¼ã®å ´åã¯, ãã¬ãã¥ã¼ç¨ã®ãã¼ã¿ãåå¾ |
---|
54 | else { |
---|
55 | $arrPageData = $this->getPageProperties($device_type_id, 0); |
---|
56 | } |
---|
57 | |
---|
58 | if (empty($arrPageData[0])) { |
---|
59 | trigger_error('ãã¼ã¸æ
å ±ãåå¾ã§ãã¾ããã§ããã', E_USER_ERROR); |
---|
60 | } |
---|
61 | |
---|
62 | $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id) . $arrPageData[0]['filename'] . '.tpl'; |
---|
63 | |
---|
64 | if (!file_exists($objPage->tpl_mainpage)) { |
---|
65 | $msg = 'ã¡ã¤ã³é¨ã®ãã³ãã¬ã¼ããåå¨ãã¾ããã[' . $objPage->tpl_mainpage . ']'; |
---|
66 | trigger_error($msg, E_USER_ERROR); |
---|
67 | } |
---|
68 | |
---|
69 | $objPage->arrPageLayout =& $arrPageData[0]; |
---|
70 | if (strlen($objPage->arrPageLayout['author']) === 0) { |
---|
71 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
72 | $objPage->arrPageLayout['author'] = $arrInfo['company_name']; |
---|
73 | } |
---|
74 | |
---|
75 | // ãã¼ã¸ã¿ã¤ãã«ãè¨å® |
---|
76 | if (SC_Utils_Ex::isBlank($objPage->tpl_title)) { |
---|
77 | $objPage->tpl_title = $objPage->arrPageLayout['page_name']; |
---|
78 | } |
---|
79 | |
---|
80 | // 該å½ãã¼ã¸ã®ãããã¯ãåå¾ã, é
ç½®ãã |
---|
81 | $masterData = new SC_DB_MasterData_Ex(); |
---|
82 | $arrTarget = $masterData->getMasterData('mtb_target'); |
---|
83 | $arrBlocs = $this->getBlocPositions($device_type_id, $objPage->arrPageLayout['page_id']); |
---|
84 | // ç¡å¹ãªãã©ã°ã¤ã³ã®ãããã¯ãåãé¤ã. |
---|
85 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(); |
---|
86 | $arrBlocs = $objPlugin->getEnableBlocs($arrBlocs); |
---|
87 | // php_path, tpl_path ãåå¨ãããã®ã, åã¿ã¼ã²ããã«é
ç½® |
---|
88 | foreach ($arrTarget as $target_id => $value) { |
---|
89 | foreach ($arrBlocs as $arrBloc) { |
---|
90 | if ($arrBloc['target_id'] != $target_id) { |
---|
91 | continue; |
---|
92 | } |
---|
93 | if (is_file($arrBloc['php_path']) |
---|
94 | || is_file($arrBloc['tpl_path'])) { |
---|
95 | $objPage->arrPageLayout[$arrTarget[$target_id]][] = $arrBloc; |
---|
96 | } else { |
---|
97 | $error = "ãããã¯ãè¦ã¤ããã¾ãã\n" |
---|
98 | . 'tpl_path: ' . $arrBloc['tpl_path'] . "\n" |
---|
99 | . 'php_path: ' . $arrBloc['php_path']; |
---|
100 | trigger_error($error, E_USER_WARNING); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | // ã«ã©ã æ°ãåå¾ãã |
---|
105 | $objPage->tpl_column_num = $this->getColumnNum($objPage->arrPageLayout); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * ãã¼ã¸ã®å±æ§ãåå¾ãã. |
---|
110 | * |
---|
111 | * ãã®é¢æ°ã¯, dtb_pagelayout ã®æ
å ±ãæ¤ç´¢ãã. |
---|
112 | * $device_type_id ã¯å¿
é . ããã©ã«ãå¤ã¯ DEVICE_TYPE_PC. |
---|
113 | * $page_id ã null ã®å ´åã¯, $page_id ã 0 以å¤ã®ãã®ãæ¤ç´¢ãã. |
---|
114 | * |
---|
115 | * @access public |
---|
116 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
117 | * @param integer $page_id ãã¼ã¸ID; null ã®å ´åã¯, 0 以å¤ãæ¤ç´¢ãã. |
---|
118 | * @param string $where 追å ã®æ¤ç´¢æ¡ä»¶ |
---|
119 | * @param array $arrParams 追å ã®æ¤ç´¢ãã©ã¡ã¼ã¿ã¼ |
---|
120 | * @return array ãã¼ã¸å±æ§ã®é
å |
---|
121 | */ |
---|
122 | public function getPageProperties($device_type_id = DEVICE_TYPE_PC, $page_id = null, $where = '', $arrParams = array()) |
---|
123 | { |
---|
124 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
125 | $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where); |
---|
126 | if ($page_id === null) { |
---|
127 | $where = 'page_id <> ? AND ' . $where; |
---|
128 | $page_id = 0; |
---|
129 | } else { |
---|
130 | $where = 'page_id = ? AND ' . $where; |
---|
131 | } |
---|
132 | $objQuery->setOrder('page_id'); |
---|
133 | $arrParams = array_merge(array($page_id, $device_type_id), $arrParams); |
---|
134 | |
---|
135 | return $objQuery->select('*', 'dtb_pagelayout', $where, $arrParams); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * ãããã¯æ
å ±ãåå¾ãã. |
---|
140 | * |
---|
141 | * @access public |
---|
142 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
143 | * @param string $where 追å ã®æ¤ç´¢æ¡ä»¶ |
---|
144 | * @param array $arrParams 追å ã®æ¤ç´¢ãã©ã¡ã¼ã¿ã¼ |
---|
145 | * @param boolean $has_realpath php_path, tpl_path ã®çµ¶å¯¾ãã¹ãå«ããå ´å true |
---|
146 | * @return array ãããã¯æ
å ±ã®é
å |
---|
147 | */ |
---|
148 | public function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true) |
---|
149 | { |
---|
150 | $objBloc = new SC_Helper_Bloc_Ex($device_type_id); |
---|
151 | $arrBlocs = $objBloc->getWhere($where, $arrParams); |
---|
152 | if ($has_realpath) { |
---|
153 | $this->setBlocPathTo($device_type_id, $arrBlocs); |
---|
154 | } |
---|
155 | |
---|
156 | return $arrBlocs; |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * ãããã¯é
ç½®æ
å ±ãåå¾ãã. |
---|
161 | * |
---|
162 | * @access public |
---|
163 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
164 | * @param integer $page_id ãã¼ã¸ID |
---|
165 | * @param boolean $has_realpath php_path, tpl_path ã®çµ¶å¯¾ãã¹ãå«ããå ´å true |
---|
166 | * @return array é
ç½®æ
å ±ãå«ãããããã¯ã®é
å |
---|
167 | */ |
---|
168 | public function getBlocPositions($device_type_id, $page_id, $has_realpath = true) |
---|
169 | { |
---|
170 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
171 | |
---|
172 | $table = <<< __EOF__ |
---|
173 | dtb_blocposition AS pos |
---|
174 | JOIN dtb_bloc AS bloc |
---|
175 | ON bloc.bloc_id = pos.bloc_id |
---|
176 | AND bloc.device_type_id = pos.device_type_id |
---|
177 | __EOF__; |
---|
178 | $where = 'bloc.device_type_id = ? AND ((anywhere = 1 AND pos.page_id != 0) OR pos.page_id = ?)'; |
---|
179 | $objQuery->setOrder('target_id, bloc_row'); |
---|
180 | $arrBlocs = $objQuery->select('*', $table, $where, array($device_type_id, $page_id)); |
---|
181 | if ($has_realpath) { |
---|
182 | $this->setBlocPathTo($device_type_id, $arrBlocs); |
---|
183 | } |
---|
184 | |
---|
185 | //å
¨ãã¼ã¸è¨å®ã¨åãã¼ã¸ã®ãããã¯ã®éè¤ãåé¤ |
---|
186 | $arrUniqBlocIds = array(); |
---|
187 | foreach ($arrBlocs as $index => $arrBloc) { |
---|
188 | if ($arrBloc['anywhere'] == 1) { |
---|
189 | $arrUniqBlocIds[] = $arrBloc['bloc_id']; |
---|
190 | } |
---|
191 | } |
---|
192 | foreach ($arrBlocs as $bloc_index => $arrBlocData) { |
---|
193 | if (in_array($arrBlocData['bloc_id'], $arrUniqBlocIds) && $arrBlocData['anywhere'] == 0) { |
---|
194 | unset($arrBlocs[$bloc_index]); |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | return $arrBlocs; |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * ãã¼ã¸æ
å ±ãåé¤ãã. |
---|
203 | * |
---|
204 | * XXX ãã¡ã¤ã«ã確å®ã«åé¤ãããã©ããã®ãã§ã㯠|
---|
205 | * |
---|
206 | * @access public |
---|
207 | * @param integer $page_id ãã¼ã¸ID |
---|
208 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
209 | * @return integer åé¤æ° |
---|
210 | */ |
---|
211 | public function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) |
---|
212 | { |
---|
213 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
214 | // page_id ã空ã§ãªãå ´åã«ã¯deleteãå®è¡ |
---|
215 | if ($page_id != '') { |
---|
216 | $arrPageData = $this->getPageProperties($device_type_id, $page_id); |
---|
217 | $ret = $objQuery->delete('dtb_pagelayout', 'page_id = ? AND device_type_id = ?', array($page_id, $device_type_id)); |
---|
218 | // ãã¡ã¤ã«ã®åé¤ |
---|
219 | $this->lfDelFile($arrPageData[0]['filename'], $device_type_id); |
---|
220 | } |
---|
221 | |
---|
222 | return $ret; |
---|
223 | } |
---|
224 | |
---|
225 | /** |
---|
226 | * ãã¼ã¸ã®ãã¡ã¤ã«ãåé¤ãã. |
---|
227 | * |
---|
228 | * dtb_pagelayout ã®åé¤å¾ã«å¼ã³åºããã¨ã |
---|
229 | * |
---|
230 | * @access private |
---|
231 | * @param string $filename |
---|
232 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
233 | * @return void // TODO boolean ã«ããã¹ã? |
---|
234 | */ |
---|
235 | public function lfDelFile($filename, $device_type_id) |
---|
236 | { |
---|
237 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
238 | |
---|
239 | /* |
---|
240 | * ååãã¡ã¤ã«ã®ä½¿ç¨ä»¶æ° |
---|
241 | * PHP ãã¡ã¤ã«ã¯, è¤æ°ã®ããã¤ã¹ã§å
±æãããã, device_type_id ãæ¡ä»¶ã«å
¥ããªã |
---|
242 | */ |
---|
243 | $exists = $objQuery->exists('dtb_pagelayout', 'filename = ?', array($filename)); |
---|
244 | |
---|
245 | if (!$exists) { |
---|
246 | // phpãã¡ã¤ã«ã®åé¤ |
---|
247 | $del_php = HTML_REALDIR . $filename . '.php'; |
---|
248 | if (file_exists($del_php)) { |
---|
249 | unlink($del_php); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | // tplãã¡ã¤ã«ã®åé¤ |
---|
254 | $del_tpl = $this->getTemplatePath($device_type_id) . $filename . '.tpl'; |
---|
255 | if (file_exists($del_tpl)) { |
---|
256 | unlink($del_tpl); |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * ç·¨éå¯è½ãã¼ã¸ãã©ãã. |
---|
262 | * |
---|
263 | * @access public |
---|
264 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
265 | * @param integer $page_id ãã¼ã¸ID |
---|
266 | * @return ç·¨éå¯è½ãã¼ã¸ã®å ´å true |
---|
267 | */ |
---|
268 | public function isEditablePage($device_type_id, $page_id) |
---|
269 | { |
---|
270 | if ($page_id == 0) { |
---|
271 | return false; |
---|
272 | } |
---|
273 | $arrPages = $this->getPageProperties($device_type_id, $page_id); |
---|
274 | if ($arrPages[0]['edit_flg'] != 2) { |
---|
275 | return true; |
---|
276 | } |
---|
277 | |
---|
278 | return false; |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | * ãã³ãã¬ã¼ãã®ãã¹ãåå¾ãã. |
---|
283 | * |
---|
284 | * @access public |
---|
285 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
286 | * @param boolean $isUser USER_REALDIR 以ä¸ã®ãã¹ãè¿ãå ´å true |
---|
287 | * @return string ãã³ãã¬ã¼ãã®ãã¹ |
---|
288 | */ |
---|
289 | public function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false) |
---|
290 | { |
---|
291 | $templateName = ''; |
---|
292 | switch ($device_type_id) { |
---|
293 | case DEVICE_TYPE_MOBILE: |
---|
294 | $dir = MOBILE_TEMPLATE_REALDIR; |
---|
295 | $templateName = MOBILE_TEMPLATE_NAME; |
---|
296 | break; |
---|
297 | |
---|
298 | case DEVICE_TYPE_SMARTPHONE: |
---|
299 | $dir = SMARTPHONE_TEMPLATE_REALDIR; |
---|
300 | $templateName = SMARTPHONE_TEMPLATE_NAME; |
---|
301 | break; |
---|
302 | |
---|
303 | case DEVICE_TYPE_PC: |
---|
304 | default: |
---|
305 | $dir = TEMPLATE_REALDIR; |
---|
306 | $templateName = TEMPLATE_NAME; |
---|
307 | break; |
---|
308 | } |
---|
309 | $userPath = USER_REALDIR; |
---|
310 | if ($isUser) { |
---|
311 | $dir = $userPath . USER_PACKAGE_DIR . $templateName . '/'; |
---|
312 | } |
---|
313 | |
---|
314 | return $dir; |
---|
315 | } |
---|
316 | |
---|
317 | /** |
---|
318 | * DocumentRoot ãã user_data ã®ãã¹ãåå¾ãã. |
---|
319 | * |
---|
320 | * å¼æ° $hasPackage ã true ã«ããå ´åã¯, user_data/packages/template_name |
---|
321 | * ãåå¾ãã. |
---|
322 | * |
---|
323 | * @access public |
---|
324 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
325 | * @param boolean $hasPackage ããã±ã¼ã¸ã®ãã¹ãå«ããå ´å true |
---|
326 | * @return string 端æ«ã«å¿ãã DocumentRoot ãã user_data ã¾ã§ã®ãã¹ |
---|
327 | */ |
---|
328 | public function getUserDir($device_type_id = DEVICE_TYPE_PC, $hasPackage = false) |
---|
329 | { |
---|
330 | switch ($device_type_id) { |
---|
331 | case DEVICE_TYPE_MOBILE: |
---|
332 | $templateName = MOBILE_TEMPLATE_NAME; |
---|
333 | break; |
---|
334 | |
---|
335 | case DEVICE_TYPE_SMARTPHONE: |
---|
336 | $templateName = SMARTPHONE_TEMPLATE_NAME; |
---|
337 | break; |
---|
338 | |
---|
339 | case DEVICE_TYPE_PC: |
---|
340 | default: |
---|
341 | $templateName = TEMPLATE_NAME; |
---|
342 | } |
---|
343 | $userDir = ROOT_URLPATH . USER_DIR; |
---|
344 | if ($hasPackage) { |
---|
345 | return $userDir . USER_PACKAGE_DIR . $templateName . '/'; |
---|
346 | } |
---|
347 | |
---|
348 | return $userDir; |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | * ãããã¯ã® php_path, tpl_path ãè¨å®ãã. |
---|
353 | * |
---|
354 | * @access private |
---|
355 | * @param integer $device_type_id 端æ«ç¨®å¥ID |
---|
356 | * @param array $arrBlocs è¨å®ãããããã¯ã®é
å |
---|
357 | * @return void |
---|
358 | */ |
---|
359 | public function setBlocPathTo($device_type_id = DEVICE_TYPE_PC, &$arrBlocs = array()) |
---|
360 | { |
---|
361 | foreach ($arrBlocs as $key => $value) { |
---|
362 | $arrBloc =& $arrBlocs[$key]; |
---|
363 | $arrBloc['php_path'] = SC_Utils_Ex::isBlank($arrBloc['php_path']) ? '' : HTML_REALDIR . $arrBloc['php_path']; |
---|
364 | $bloc_dir = $this->getTemplatePath($device_type_id) . BLOC_DIR; |
---|
365 | $arrBloc['tpl_path'] = SC_Utils_Ex::isBlank($arrBloc['tpl_path']) ? '' : $bloc_dir . $arrBloc['tpl_path']; |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | /** |
---|
370 | * ã«ã©ã æ°ãåå¾ãã. |
---|
371 | * |
---|
372 | * @access private |
---|
373 | * @param array $arrPageLayout ã¬ã¤ã¢ã¦ãæ
å ±ã®é
å |
---|
374 | * @return integer $col_num ã«ã©ã æ° |
---|
375 | */ |
---|
376 | public function getColumnNum($arrPageLayout) |
---|
377 | { |
---|
378 | // ã¡ã¤ã³ã¯ç¢ºå® |
---|
379 | $col_num = 1; |
---|
380 | // LEFT NAVI |
---|
381 | if (count($arrPageLayout['LeftNavi']) > 0) $col_num++; |
---|
382 | // RIGHT NAVI |
---|
383 | if (count($arrPageLayout['RightNavi']) > 0) $col_num++; |
---|
384 | return $col_num; |
---|
385 | } |
---|
386 | } |
---|