source: branches/version-2_5-dev/data/class/helper/SC_Helper_PageLayout.php @ 19713

Revision 19713, 10.1 KB checked in by nanasess, 13 years ago (diff)
  • #748(モバイルのデザイン管理機能)
    • dtb_pagelayout, dtb_bloc, dtb_blocposition のデータを追加
    • dtb_blocposition.filename を削除
    • dtb_bloc.filename を device_type_id と filename のユニークキーへ変更
  • #787(スマートフォン対応)
    • data/install.php のモバイル関連の定数を data/class/SC_Initial.php へ移動
    • テンプレート, PHPファイル追加
  • #832 SC_Helper_PageLayout#sfGetPageLayout()) の呼び出しを1ヶ所に集約
  • #820 フラグ, マスタIDの値を定数にする
    • mtb_target の値を定数化
  • 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-2010 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($_SERVER['PHP_SELF'] の情報)
44     * @param integer $device_type_id 端末種別ID
45     * @return void
46     */
47    function sfGetPageLayout(&$objPage, $preview = false, $url = "", $device_type_id = DEVICE_TYPE_PC) {
48        $debug_message = "";
49        $arrPageLayout = array();
50
51        // 現在のURLの取得
52        if ($preview === false) {
53            $url = preg_replace('|^' . preg_quote(URL_DIR) . '|', '', $url);
54
55            // URLを元にページデザインを取得
56            $arrPageData = $this->lfGetPageData("device_type_id = ? AND url = ? AND page_id <> 0" , array($device_type_id, $url));
57        } else {
58            // TODO
59            $arrPageData = $this->lfGetPageData("device_type_id = ? AND page_id = 0", array($device_type_id));
60            $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id, true)
61                . "preview/" . $arrPageData[0]['filename'] . ".tpl";
62        }
63
64        $arrPageLayout = $arrPageData[0];
65
66        // tpl_mainpageの設定なし、又はトップページの場合
67        if (!isset($objPage->tpl_mainpage) || $url == "index.php") {
68            // ユーザテンプレートのパスを取得
69            $user_tpl =  $this->getTemplatePath($device_type_id, true)
70                . $arrPageLayout['filename'] . ".tpl";
71
72            // ユーザテンプレートの存在チェック
73            if (is_file($user_tpl)) {
74                $objPage->tpl_mainpage = $user_tpl;
75            }
76            // 存在しない場合は指定テンプレートを使用
77            else {
78                $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id)
79                    . $arrPageLayout['filename'] . ".tpl";
80            }
81        }
82
83        // ページタイトルを設定
84        if (!isset($objPage->tpl_title)) {
85            $objPage->tpl_title = $arrPageLayout['page_name'];
86        }
87
88        // 全ナビデータを取得する
89        $arrNavi = $this->lfGetNaviData($arrPageLayout['page_id'], $device_type_id);
90        $masterData = new SC_DB_MasterData();
91        $arrTarget = $masterData->getMasterData("mtb_target");
92
93        foreach (array_keys($arrTarget) as $key) {
94            if (TARGET_ID_UNUSED != $key) {
95                $arrPageLayout[$arrTarget[$key]]
96                    = $this->lfGetNavi($arrNavi, $key, $device_type_id);
97            }
98        }
99        $objPage->arrPageLayout = $arrPageLayout;
100
101        // カラム数を取得する
102        $objPage->tpl_column_num = $this->lfGetColumnNum($arrPageLayout);
103    }
104
105    /**
106     * ページ情報を取得する.
107     *
108     * @param string $where クエリのWHERE句
109     * @param array $arrVal WHERE句の条件値
110     * @return array ページ情報を格納した配列
111     */
112    function lfGetPageData($where = 'page_id <> 0', $arrVal = array()) {
113        $objQuery =& SC_Query::getSingletonInstance();
114        $objQuery->setOrder('page_id');
115        return $objQuery->select("*", "dtb_pagelayout", $where, $arrVal);
116    }
117
118    /**
119     * ナビ情報を取得する.
120     *
121     * @param integer $page_id ページID
122     * @param integer $device_type_id 端末種別ID
123     * @return array ナビ情報の配列
124     */
125    function lfGetNaviData($page_id, $device_type_id = DEVICE_TYPE_PC) {
126        $objQuery =& SC_Query::getSingletonInstance();
127        $table = <<< __EOF__
128            dtb_blocposition AS pos
129       JOIN dtb_bloc AS bloc
130         ON bloc.bloc_id = pos.bloc_id
131        AND bloc.device_type_id = pos.device_type_id
132__EOF__;
133        $where = "bloc.device_type_id = ? AND (anywhere = 1 OR pos.page_id = ?)";
134        $objQuery->setOrder('target_id, bloc_row');
135        return $objQuery->select("*", $table, $where,
136                                 array($device_type_id, $page_id));
137    }
138
139    /**
140     * 各部分のナビ情報を取得する.
141     *
142     * @param array $arrNavi ナビ情報の配列
143     * @param integer $target_id ターゲットID
144     * @param integer $device_type_id 端末種別ID
145     * @return array ブロック情報の配列
146     */
147    function lfGetNavi($arrNavi, $target_id, $device_type_id = DEVICE_TYPE_PC) {
148        $arrRet = array();
149        if (is_array($arrNavi)) {
150            foreach ($arrNavi as $key => $val) {
151                // 指定された箇所と同じデータだけを取得する
152                if ($target_id == $val['target_id'] ) {
153                    if ($val['php_path'] != '') {
154                        $arrNavi[$key]['php_path'] = HTML_PATH . $val['php_path'];
155                    } else {
156                        $user_block_path = $this->getTemplatePath($device_type_id, true) .  "/" . $val['tpl_path'];
157                        if (is_file($user_block_path)) {
158                            $arrNavi[$key]['tpl_path'] = $user_block_path;
159                        } else {
160                            $arrNavi[$key]['tpl_path'] = $this->getTemplatePath($device_type_id) . $val['tpl_path'];
161                        }
162                    }
163                    // phpから呼び出されるか、tplファイルが存在する場合
164                    if ($val['php_path'] != '' || is_file($arrNavi[$key]['tpl_path'])) {
165                        $arrRet[] = $arrNavi[$key];
166                    } else {
167                        GC_Utils::gfPrintLog("ブロック読み込みエラー:" . $arrNavi[$key]['tpl_path']);
168                    }
169                }
170            }
171        }
172        return $arrRet;
173    }
174
175    /**
176     * カラム数を取得する.
177     *
178     * @param array $arrPageLayout レイアウト情報の配列
179     * @return integer $col_num カラム数
180     */
181    function lfGetColumnNum($arrPageLayout) {
182        // メインは確定
183        $col_num = 1;
184        // LEFT NAVI
185        if (count($arrPageLayout['LeftNavi']) > 0) $col_num++;
186        // RIGHT NAVI
187        if (count($arrPageLayout['RightNavi']) > 0) $col_num++;
188
189        return $col_num;
190    }
191
192    /**
193     * ページ情報を削除する.
194     *
195     * @param integer $page_id ページID
196     * @param integer $device_type_id 端末種別ID
197     * @return integer 削除数
198     */
199    function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) {
200        $objQuery =& SC_Query::getSingletonInstance();
201        $arrDelData = array();      // 抽出データ用
202
203        // page_id が空でない場合にはdeleteを実行
204        if ($page_id != '') {
205
206            $arrPageData = $this->lfGetPageData("page_id = ? AND device_type_id = ?" , array($page_id, $device_type_id));
207            // SQL実行
208            $ret = $objQuery->delete("dtb_pagelayout", "page_id = ? AND device_type_id = ?", array($page_id, $device_type_id));
209
210            // ファイルの削除
211            $this->lfDelFile($arrPageData[0]);
212        }
213        return $ret;
214    }
215
216    /**
217     * ページのファイルを削除する.
218     *
219     * @param array $arrData ページ情報の配列
220     * @return void // TODO boolean にするべき?
221     */
222    function lfDelFile($arrData) {
223        // ファイルディレクトリ取得
224        $del_php = HTML_PATH . $arrData['php_dir'] . $arrData['filename'] . ".php";
225        $del_tpl = HTML_PATH . $arrData['tpl_dir'] . $arrData['filename'] . ".tpl";
226
227        // phpファイルの削除
228        if (file_exists($del_php)) {
229            unlink($del_php);
230        }
231
232        // tplファイルの削除
233        if (file_exists($del_tpl)) {
234            unlink($del_tpl);
235        }
236    }
237
238    /**
239     * データがベースデータかどうか.
240     *
241     * @param integer $page_id ページID
242     * @param integer $device_type_id 端末種別ID
243     * @return boolean ベースデータの場合 true
244     */
245    function lfCheckBaseData($page_id, $device_type_id) {
246        $result = false;
247
248        if ($page_id == 0) {
249            return $result;
250        }
251
252        $arrChkData = $this->lfgetPageData("page_id = ? AND device_type_id = ?",
253                                           array($page_id, $device_type_id));
254
255        if ($arrChkData[0]['edit_flg'] == 2) {
256            $result = true;
257        }
258
259        return $result;
260    }
261
262    /**
263     * テンプレートのパスを取得する.
264     */
265    function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false) {
266        $templateName = "";
267        switch ($device_type_id) {
268        case DEVICE_TYPE_MOBILE:
269            $dir = MOBILE_TEMPLATE_DIR;
270            $templateName = MOBILE_TEMPLATE_NAME;
271            break;
272
273        case DEVICE_TYPE_SMARTPHONE:
274            $dir = SMARTPHONE_TEMPLATE_DIR;
275            $templateName = SMARTPHONE_TEMPLATE_NAME;
276            break;
277
278        case DEVICE_TYPE_PC:
279        default:
280            $dir = TEMPLATE_DIR;
281            $templateName = TEMPLATE_NAME;
282        }
283        if ($isUser) {
284            $dir = USER_TEMPLATE_DIR . $templateName . "/";
285        }
286        return $dir;
287    }
288}
289?>
Note: See TracBrowser for help on using the repository browser.