source: branches/version-2_13-dev/data/class/helper/SC_Helper_PageLayout.php @ 23056

Revision 23056, 13.5 KB checked in by h_yoshimoto, 11 years ago (diff)

#2327 #2334 「ログアウト」「MYページ>お届け先追加」でシステムエラーが発行する為、一旦差し戻します。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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 */
31class 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    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        $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id) . $arrPageData[0]['filename'] . '.tpl';
59
60        $objPage->arrPageLayout =& $arrPageData[0];
61        if (strlen($objPage->arrPageLayout['author']) === 0) {
62            $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
63            $objPage->arrPageLayout['author'] = $arrInfo['company_name'];
64        }
65
66        // ページタイトルを設定
67        if (SC_Utils_Ex::isBlank($objPage->tpl_title)) {
68            $objPage->tpl_title = $objPage->arrPageLayout['page_name'];
69        }
70
71        // 該当ページのブロックを取得し, 配置する
72        $masterData = new SC_DB_MasterData_Ex();
73        $arrTarget = $masterData->getMasterData('mtb_target');
74        $arrBlocs = $this->getBlocPositions($device_type_id, $objPage->arrPageLayout['page_id']);
75        // 無効なプラグインのブロックを取り除く.
76        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
77        $arrBlocs = $objPlugin->getEnableBlocs($arrBlocs);
78        // php_path, tpl_path が存在するものを, 各ターゲットに配置
79        foreach ($arrTarget as $target_id => $value) {
80            foreach ($arrBlocs as $arrBloc) {
81                if ($arrBloc['target_id'] != $target_id) {
82                    continue;
83                }
84                if (is_file($arrBloc['php_path'])
85                    || is_file($arrBloc['tpl_path'])) {
86                    $objPage->arrPageLayout[$arrTarget[$target_id]][] = $arrBloc;
87                } else {
88                    $error = "ブロックが見つかりません\n"
89                        . 'tpl_path: ' . $arrBloc['tpl_path'] . "\n"
90                        . 'php_path: ' . $arrBloc['php_path'];
91                    trigger_error($error, E_USER_WARNING);
92                }
93            }
94        }
95        // カラム数を取得する
96        $objPage->tpl_column_num = $this->getColumnNum($objPage->arrPageLayout);
97    }
98
99    /**
100     * ページの属性を取得する.
101     *
102     * この関数は, dtb_pagelayout の情報を検索する.
103     * $device_type_id は必須. デフォルト値は DEVICE_TYPE_PC.
104     * $page_id が null の場合は, $page_id が 0 以外のものを検索する.
105     *
106     * @access public
107     * @param integer $device_type_id 端末種別ID
108     * @param integer $page_id ページID; null の場合は, 0 以外を検索する.
109     * @param string $where 追加の検索条件
110     * @param array $arrParams 追加の検索パラメーター
111     * @return array ページ属性の配列
112     */
113    function getPageProperties($device_type_id = DEVICE_TYPE_PC, $page_id = null, $where = '', $arrParams = array())
114    {
115        $objQuery =& SC_Query_Ex::getSingletonInstance();
116        $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where);
117        if ($page_id === null) {
118            $where = 'page_id <> ? AND ' . $where;
119            $page_id = 0;
120        } else {
121            $where = 'page_id = ? AND ' . $where;
122        }
123        $objQuery->setOrder('page_id');
124        $arrParams = array_merge(array($page_id, $device_type_id), $arrParams);
125
126        return $objQuery->select('*', 'dtb_pagelayout', $where, $arrParams);
127    }
128
129    /**
130     * ブロック情報を取得する.
131     *
132     * @access public
133     * @param integer $device_type_id 端末種別ID
134     * @param string $where 追加の検索条件
135     * @param array $arrParams 追加の検索パラメーター
136     * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true
137     * @return array ブロック情報の配列
138     */
139    function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true)
140    {
141        $objBloc = new SC_Helper_Bloc_Ex($device_type_id);
142        $arrBlocs = $objBloc->getWhere($where, $arrParams);
143        if ($has_realpath) {
144            $this->setBlocPathTo($device_type_id, $arrBlocs);
145        }
146
147        return $arrBlocs;
148    }
149
150    /**
151     * ブロック配置情報を取得する.
152     *
153     * @access public
154     * @param integer $device_type_id 端末種別ID
155     * @param integer $page_id ページID
156     * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true
157     * @return array 配置情報を含めたブロックの配列
158     */
159    function getBlocPositions($device_type_id, $page_id, $has_realpath = true)
160    {
161        $objQuery =& SC_Query_Ex::getSingletonInstance();
162
163        $table = <<< __EOF__
164        dtb_blocposition AS pos
165            JOIN dtb_bloc AS bloc
166                ON bloc.bloc_id = pos.bloc_id
167                    AND bloc.device_type_id = pos.device_type_id
168__EOF__;
169        $where = 'bloc.device_type_id = ? AND ((anywhere = 1 AND pos.page_id != 0) OR pos.page_id = ?)';
170        $objQuery->setOrder('target_id, bloc_row');
171        $arrBlocs = $objQuery->select('*', $table, $where, array($device_type_id, $page_id));
172        if ($has_realpath) {
173            $this->setBlocPathTo($device_type_id, $arrBlocs);
174        }
175
176        //全ページ設定と各ページのブロックの重複を削除
177        $arrUniqBlocIds = array();
178        foreach ($arrBlocs as $index => $arrBloc) {
179            if ($arrBloc['anywhere'] == 1){
180                $arrUniqBlocIds[] = $arrBloc['bloc_id'];
181            }
182        }
183        foreach ($arrBlocs as $bloc_index => $arrBlocData) {
184            if (in_array($arrBlocData['bloc_id'], $arrUniqBlocIds) && $arrBlocData['anywhere'] == 0){
185                unset($arrBlocs[$bloc_index]);
186            }
187        }
188
189        return $arrBlocs;
190    }
191
192    /**
193     * ページ情報を削除する.
194     *
195     * XXX ファイルを確実に削除したかどうかのチェック
196     *
197     * @access public
198     * @param integer $page_id ページID
199     * @param integer $device_type_id 端末種別ID
200     * @return integer 削除数
201     */
202    function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC)
203    {
204        $objQuery =& SC_Query_Ex::getSingletonInstance();
205        // page_id が空でない場合にはdeleteを実行
206        if ($page_id != '') {
207            $arrPageData = $this->getPageProperties($device_type_id, $page_id);
208            $ret = $objQuery->delete('dtb_pagelayout', 'page_id = ? AND device_type_id = ?', array($page_id, $device_type_id));
209            // ファイルの削除
210            $this->lfDelFile($arrPageData[0]['filename'], $device_type_id);
211        }
212
213        return $ret;
214    }
215
216    /**
217     * ページのファイルを削除する.
218     *
219     * dtb_pagelayout の削除後に呼び出すこと。
220     *
221     * @access private
222     * @param string $filename
223     * @param integer $device_type_id 端末種別ID
224     * @return void // TODO boolean にするべき?
225     */
226    function lfDelFile($filename, $device_type_id)
227    {
228        $objQuery =& SC_Query_Ex::getSingletonInstance();
229
230        /*
231         * 同名ファイルの使用件数
232         * PHP ファイルは, 複数のデバイスで共有するため, device_type_id を条件に入れない
233         */
234        $exists = $objQuery->exists('dtb_pagelayout', 'filename = ?', array($filename));
235
236        if (!$exists) {
237            // phpファイルの削除
238            $del_php = HTML_REALDIR . $filename . '.php';
239            if (file_exists($del_php)) {
240                unlink($del_php);
241            }
242        }
243
244        // tplファイルの削除
245        $del_tpl = $this->getTemplatePath($device_type_id) . $filename . '.tpl';
246        if (file_exists($del_tpl)) {
247            unlink($del_tpl);
248        }
249    }
250
251    /**
252     * 編集可能ページかどうか.
253     *
254     * @access public
255     * @param integer $device_type_id 端末種別ID
256     * @param integer $page_id ページID
257     * @return 編集可能ページの場合 true
258     */
259    function isEditablePage($device_type_id, $page_id)
260    {
261        if ($page_id == 0) {
262            return false;
263        }
264        $arrPages = $this->getPageProperties($device_type_id, $page_id);
265        if ($arrPages[0]['edit_flg'] != 2) {
266            return true;
267        }
268
269        return false;
270    }
271
272    /**
273     * テンプレートのパスを取得する.
274     *
275     * @access public
276     * @param integer $device_type_id 端末種別ID
277     * @param boolean $isUser USER_REALDIR 以下のパスを返す場合 true
278     * @return string テンプレートのパス
279     */
280    function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false)
281    {
282        $templateName = '';
283        switch ($device_type_id) {
284            case DEVICE_TYPE_MOBILE:
285                $dir = MOBILE_TEMPLATE_REALDIR;
286                $templateName = MOBILE_TEMPLATE_NAME;
287                break;
288
289            case DEVICE_TYPE_SMARTPHONE:
290                $dir = SMARTPHONE_TEMPLATE_REALDIR;
291                $templateName = SMARTPHONE_TEMPLATE_NAME;
292                break;
293
294            case DEVICE_TYPE_PC:
295            default:
296                $dir = TEMPLATE_REALDIR;
297                $templateName = TEMPLATE_NAME;
298                break;
299        }
300        $userPath = USER_REALDIR;
301        if ($isUser) {
302            $dir = $userPath . USER_PACKAGE_DIR . $templateName . '/';
303        }
304
305        return $dir;
306    }
307
308    /**
309     * DocumentRoot から user_data のパスを取得する.
310     *
311     * 引数 $hasPackage を true にした場合は, user_data/packages/template_name
312     * を取得する.
313     *
314     * @access public
315     * @param integer $device_type_id 端末種別ID
316     * @param boolean $hasPackage パッケージのパスも含める場合 true
317     * @return string 端末に応じた DocumentRoot から user_data までのパス
318     */
319    function getUserDir($device_type_id = DEVICE_TYPE_PC, $hasPackage = false)
320    {
321        switch ($device_type_id) {
322        case DEVICE_TYPE_MOBILE:
323            $templateName = MOBILE_TEMPLATE_NAME;
324            break;
325
326        case DEVICE_TYPE_SMARTPHONE:
327            $templateName = SMARTPHONE_TEMPLATE_NAME;
328            break;
329
330        case DEVICE_TYPE_PC:
331        default:
332            $templateName = TEMPLATE_NAME;
333        }
334        $userDir = ROOT_URLPATH . USER_DIR;
335        if ($hasPackage) {
336            return $userDir . USER_PACKAGE_DIR . $templateName . '/';
337        }
338
339        return $userDir;
340    }
341
342    /**
343     * ブロックの php_path, tpl_path を設定する.
344     *
345     * @access private
346     * @param integer $device_type_id 端末種別ID
347     * @param array $arrBlocs 設定するブロックの配列
348     * @return void
349     */
350    function setBlocPathTo($device_type_id = DEVICE_TYPE_PC, &$arrBlocs = array())
351    {
352        foreach ($arrBlocs as $key => $value) {
353            $arrBloc =& $arrBlocs[$key];
354            $arrBloc['php_path'] = SC_Utils_Ex::isBlank($arrBloc['php_path']) ? '' : HTML_REALDIR . $arrBloc['php_path'];
355            $bloc_dir = $this->getTemplatePath($device_type_id) . BLOC_DIR;
356            $arrBloc['tpl_path'] = SC_Utils_Ex::isBlank($arrBloc['tpl_path']) ? '' : $bloc_dir . $arrBloc['tpl_path'];
357        }
358    }
359
360    /**
361     * カラム数を取得する.
362     *
363     * @access private
364     * @param array $arrPageLayout レイアウト情報の配列
365     * @return integer $col_num カラム数
366     */
367    function getColumnNum($arrPageLayout)
368    {
369        // メインは確定
370        $col_num = 1;
371        // LEFT NAVI
372        if (count($arrPageLayout['LeftNavi']) > 0) $col_num++;
373        // RIGHT NAVI
374        if (count($arrPageLayout['RightNavi']) > 0) $col_num++;
375
376        return $col_num;
377    }
378}
Note: See TracBrowser for help on using the repository browser.