source: branches/version-2_4-dev/data/class/helper/SC_Helper_PageLayout.php @ 18550

Revision 18550, 11.5 KB checked in by shutta, 14 years ago (diff)

#598(SITE_URLの設定と異なるURLでのアクセス時にuser_data/以下のページが表示されない)の対応

  • 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-2007 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    // {{{ functions
35
36    /**
37     * ページのレイアウト情報をセットする.
38     *
39     * LC_Page オブジェクトにページのレイアウト情報をセットする.
40     *
41     * @param LC_Page $objPage ページ情報
42     * @param boolean $preview プレビュー表示の場合 true
43     * @param string $url ページのURL
44     * @return void
45     */
46    function sfGetPageLayout(&$objPage, $preview = false, $url = ""){
47        $debug_message = "";
48        $arrPageLayout = array();
49
50        // 現在のURLの取得
51        if ($preview === false) {
52            if ($url == "") {
53                $url = SITE_URL . preg_replace('|^' . preg_quote(URL_DIR) . '|', '' , $_SERVER['PHP_SELF']);
54            }
55            // URLを元にページデザインを取得
56            $arrPageData = $this->lfgetPageData(" url = ? " , array($url));
57        }else{
58            $arrPageData = $this->lfgetPageData(" page_id = ? " , array("0"));
59            $objPage->tpl_mainpage = USER_PATH . "templates/preview/"
60                . TEMPLATE_NAME . "/" . $arrPageData[0]['filename'] . ".tpl";
61        }
62       
63        reset($arrPageData[0]);
64        while( list($key,$val) = each($arrPageData[0]) ){
65             $debug_message.= "arrPageData[$key]:" . $val . "\n";
66        }
67       
68        $debug_message.= "TEMPLATE_NAME:".TEMPLATE_NAME . "\n";
69       
70        // tpl_mainpageの設定なし、又はトップページの場合
71        if (!isset($objPage->tpl_mainpage) || $url == "index.php") {
72            // ユーザテンプレートのパスを取得
73            $user_tpl =  HTML_PATH . USER_DIR . USER_PACKAGE_DIR . TEMPLATE_NAME . "/" . $arrPageData[0]['filename'] . ".tpl";
74            $debug_message.= "ユーザテンプレートチェック:".$user_tpl."\n";
75           
76            // ユーザテンプレートの存在チェック
77            if (is_file($user_tpl)) {
78                $objPage->tpl_mainpage = $user_tpl;
79                $debug_message.= "tpl_mainpage:ユーザーテンプレート\n";
80            // 存在しない場合は指定テンプレートを使用
81            } else {
82                $objPage->tpl_mainpage = TEMPLATE_DIR . $arrPageData[0]['filename'] . ".tpl";
83                $debug_message.= "tpl_mainpage:標準テンプレート\n";
84            }
85        } else {
86            $debug_message.= "tpl_mainpage:設定あり" . "\n";
87        }
88       
89        $debug_message.= "tpl_mainpage:" . $objPage->tpl_mainpage . "\n";
90
91        // ページタイトルを設定
92        if (!isset($objPage->tpl_title)) {
93            $objPage->tpl_title = $arrPageData[0]['page_name'];
94        }
95
96        $arrPageLayout = $arrPageData[0];
97
98        // 全ナビデータを取得する
99        $arrNavi = $this->lfGetNaviData($url, $preview);
100
101        $arrPageLayout['LeftNavi']  = $this->lfGetNavi($arrNavi,1); // LEFT NAVI
102        $arrPageLayout['MainHead']  = $this->lfGetNavi($arrNavi,2); // メイン上部
103        $arrPageLayout['RightNavi'] = $this->lfGetNavi($arrNavi,3); // RIGHT NAVI
104        $arrPageLayout['MainFoot']  = $this->lfGetNavi($arrNavi,4); // メイン下部
105
106        GC_Utils::gfDebugLog($arrPageLayout);
107       
108        $objPage->arrPageLayout = $arrPageLayout;
109       
110        // カラム数を取得する
111        $objPage->tpl_column_num = $this->lfGetColumnNum($arrPageLayout);
112
113        GC_Utils::gfDebugLog($debug_message);
114    }
115
116    /**
117     * ページ情報を取得する.
118     *
119     * @param string $where クエリのWHERE句
120     * @param array $arrVal WHERE句の条件値
121     * @return array ページ情報を格納した配列
122     */
123    function lfgetPageData($addwhere = '', $sqlval = ''){
124        $objQuery = new SC_Query;       // DB操作オブジェクト
125        $arrRet = array();              // データ取得用
126
127        // SQL文生成
128        // 取得するカラム
129        $col  = " page_id";             // ページID
130        $col .= " ,page_name";          // 名称
131        $col .= " ,url";                // URL
132        $col .= " ,php_dir";            // php保存先ディレクトリ
133        $col .= " ,tpl_dir";            // tpl保存先ディレクトリ
134        $col .= " ,filename";           // ファイル名称
135        $col .= " ,header_chk ";        // ヘッダー使用FLG
136        $col .= " ,footer_chk ";        // フッター使用FLG
137        $col .= " ,edit_flg ";          // 編集可能FLG
138        $col .= " ,author";             // authorタグ
139        $col .= " ,description";        // descriptionタグ
140        $col .= " ,keyword";            // keywordタグ
141        $col .= " ,update_url";         // 更新URL
142        $col .= " ,create_date";        // データ作成日
143        $col .= " ,update_date";        // データ更新日
144       
145        // 取得するテーブル
146        $table = "dtb_pagelayout";
147       
148        // where句の指定があれば追加
149        $where = ($addwhere != '') ? $addwhere : "page_id <> 0";
150       
151        // 並び変え
152        $objQuery->setOrder('page_id');
153       
154        // SQL実行
155        $arrRet = $objQuery->select($col, $table, $where, $sqlval);
156       
157        // 結果を返す
158        return $arrRet;
159    }
160
161    /**
162     * ナビ情報を取得する.
163     *
164     * @param string $url ページのURL
165     * @param boolean $preview プレビュー表示の場合 true
166     * @return array ナビ情報の配列
167     */
168    function lfGetNaviData($url, $preview=false){
169        $objQuery = new SC_Query;       // DB操作オブジェクト
170        $sql = "";                      // データ取得SQL生成用
171        $arrRet = array();              // データ取得用
172        $arrData = array();
173
174        // SQL文生成
175        // 取得するカラム
176        $col = "target_id, bloc_name, tpl_path, php_path";
177       
178        // 取得するテーブル
179        $table = "dtb_blocposition AS pos, dtb_bloc AS bloc";
180       
181        // where文生成
182        $where = "bloc.bloc_id = pos.bloc_id";
183        if ($preview == true) {
184            $where .= " AND EXISTS (SELECT page_id FROM dtb_pagelayout AS lay WHERE page_id = '0' AND pos.page_id = lay.page_id)";
185        }else{
186            $where .= " AND EXISTS (SELECT page_id FROM dtb_pagelayout AS lay WHERE url = ? AND page_id <> '0' AND pos.page_id = lay.page_id)";
187            $sqlval = array($url);
188        }
189        // 並び変え
190        $objQuery->setOrder('target_id, bloc_row');
191       
192        // SQL実行
193        $arrRet = $objQuery->select($col, $table, $where, $sqlval);
194                                           
195        // 結果を返す
196        return $arrRet;
197    }
198
199    /**
200     * 各部分のナビ情報を取得する.
201     *
202     * @param array $arrNavi ナビ情報の配列
203     * @param integer|string $target_id ターゲットID
204     * @return array ブロック情報の配列
205     */
206    function lfGetNavi($arrNavi, $target_id) {
207        $arrRet = array();
208        if(is_array($arrNavi) === true) {
209            reset($arrNavi);
210            while( list($key,$val)= each($arrNavi) ){
211                // 指定された箇所と同じデータだけを取得する
212                if ($target_id == $val['target_id']){
213                    if ($val['php_path'] != '') {
214                        $arrNavi[$key]['php_path'] = HTML_PATH . $val['php_path'];
215                    }else{
216                        $user_block_path = USER_TEMPLATE_PATH . TEMPLATE_NAME . "/" . $val['tpl_path'];
217                        if(is_file($user_block_path)) {
218                           $arrNavi[$key]['tpl_path'] = $user_block_path;
219                        } else {
220                           $arrNavi[$key]['tpl_path'] = TEMPLATE_DIR . $val['tpl_path'];
221                        }
222                    }
223                   
224                    // phpから呼び出されるか、tplファイルが存在する場合
225                    if($val['php_path'] != '' || is_file($arrNavi[$key]['tpl_path'])) {
226                        $arrRet[] = $arrNavi[$key];
227                    } else {
228                        GC_Utils::gfPrintLog("ブロック読み込みエラー:" . $arrNavi[$key]['tpl_path']);
229                    }
230                }
231            }
232        }
233        return $arrRet;
234    }
235
236    /**
237     * カラム数を取得する.
238     *
239     * @param array $arrPageLayout レイアウト情報の配列
240     * @return integer $col_num カラム数
241     */
242    function lfGetColumnNum($arrPageLayout) {
243        // メインは確定
244        $col_num = 1;
245        // LEFT NAVI
246        if (count($arrPageLayout['LeftNavi']) > 0) $col_num++;
247        // RIGHT NAVI
248        if (count($arrPageLayout['RightNavi']) > 0) $col_num++;
249       
250        return $col_num;
251    }
252
253    /**
254     * ページ情報を削除する.
255     *
256     * @param integer|string $page_id ページID
257     * @return integer 削除数
258     */
259    function lfDelPageData($page_id){
260        // DBへデータを更新する
261        $objQuery = new SC_Query;       // DB操作オブジェクト
262        $sql = "";                      // データ更新SQL生成用
263        $ret = "";                      // データ更新結果格納用
264        $arrDelData = array();          // 更新データ生成用
265
266        // page_id が空でない場合にはdeleteを実行
267        if ($page_id != '') {
268
269            $arrPageData = $this->lfgetPageData(" page_id = ? " , array($page_id));
270            // SQL実行
271            $ret = $objQuery->delete("dtb_pagelayout", "page_id = ?", array($page_id));
272
273            // ファイルの削除
274            $this->lfDelFile($arrPageData[0]);
275        }
276        return $ret;
277    }
278
279    /**
280     * ページのファイルを削除する.
281     *
282     * @param array $arrData ページ情報の配列
283     * @return void // TODO boolean にするべき?
284     */
285    function lfDelFile($arrData){
286        // ファイルディレクトリ取得
287        $del_php = HTML_PATH . $arrData['php_dir'] . $arrData['filename'] . ".php";
288        $del_tpl = HTML_PATH . $arrData['tpl_dir'] . $arrData['filename'] . ".tpl";
289
290        // phpファイルの削除
291        if (file_exists($del_php)){
292            unlink($del_php);
293        }
294
295        // tplファイルの削除
296        if (file_exists($del_tpl)){
297            unlink($del_tpl);
298        }
299    }
300
301    /**
302     * データがベースデータかどうか.
303     *
304     * @param integer|string $data ページID
305     * @return boolean ベースデータの場合 true
306     */
307    function lfCheckBaseData($data){
308        $ret = false;
309
310        if ($data == 0) {
311            return $ret;
312        }
313
314        $arrChkData = $this->lfgetPageData("page_id = ?", array($data));
315
316        if ($arrChkData[0]['edit_flg'] == 2){
317            $ret = true;
318        }
319
320        return $ret;
321    }
322}
323?>
Note: See TracBrowser for help on using the repository browser.