source: branches/comu-ver2/data/class/helper/SC_Helper_PageLayout.php @ 18201

Revision 18201, 11.3 KB checked in by miningbrownie, 15 years ago (diff)

http://svn.ec-cube.net/open_trac/ticket/518 この件を修正しました。SC_Helper_PageLayoutでの順番が間違えていたのと、insert_data.sqlでのそのスペースの名前の付け方に揺らぎがありました。

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