source: tmp/version-2_5-test/data/class/helper/SC_Helper_PageLayout.php @ 18609

Revision 18609, 11.4 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

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