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

Revision 17574, 10.8 KB checked in by Seasoft, 16 years ago (diff)

・marge 17340(一部)
・プレビューの内容が本番に影響する不具合を修正。

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