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

Revision 19722, 11.4 KB checked in by nanasess, 13 years ago (diff)

#748(モバイル/スマートフォンのデザイン管理)

  • tpl ファイルの取得方法を修正
  • 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        // ユーザテンプレートのパスを取得
67        $user_tpl =  $this->getTemplatePath($device_type_id, true)
68            . $arrPageLayout['filename'] . ".tpl";
69
70        // ユーザテンプレートの存在チェック
71        if (is_file($user_tpl)) {
72            $objPage->tpl_mainpage = $user_tpl;
73        }
74        // 存在しない場合は指定テンプレートを使用
75        else {
76            $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id)
77                . $arrPageLayout['filename'] . ".tpl";
78        }
79
80        // ページタイトルを設定
81        if (!isset($objPage->tpl_title)) {
82            $objPage->tpl_title = $arrPageLayout['page_name'];
83        }
84
85        // 全ナビデータを取得する
86        $arrNavi = $this->lfGetNaviData($arrPageLayout['page_id'], $device_type_id);
87        $masterData = new SC_DB_MasterData();
88        $arrTarget = $masterData->getMasterData("mtb_target");
89
90        foreach (array_keys($arrTarget) as $key) {
91            if (TARGET_ID_UNUSED != $key) {
92                $arrPageLayout[$arrTarget[$key]]
93                    = $this->lfGetNavi($arrNavi, $key, $device_type_id);
94            }
95        }
96        $objPage->arrPageLayout = $arrPageLayout;
97
98        // カラム数を取得する
99        $objPage->tpl_column_num = $this->lfGetColumnNum($arrPageLayout);
100    }
101
102    /**
103     * ページ情報を取得する.
104     *
105     * @param string $where クエリのWHERE句
106     * @param array $arrVal WHERE句の条件値
107     * @return array ページ情報を格納した配列
108     */
109    function lfGetPageData($where = 'page_id <> 0', $arrVal = array()) {
110        $objQuery =& SC_Query::getSingletonInstance();
111        $objQuery->setOrder('page_id');
112        return $objQuery->select("*", "dtb_pagelayout", $where, $arrVal);
113    }
114
115    /**
116     * ナビ情報を取得する.
117     *
118     * @param integer $page_id ページID
119     * @param integer $device_type_id 端末種別ID
120     * @return array ナビ情報の配列
121     */
122    function lfGetNaviData($page_id, $device_type_id = DEVICE_TYPE_PC) {
123        $objQuery =& SC_Query::getSingletonInstance();
124        $table = <<< __EOF__
125            dtb_blocposition AS pos
126       JOIN dtb_bloc AS bloc
127         ON bloc.bloc_id = pos.bloc_id
128        AND bloc.device_type_id = pos.device_type_id
129__EOF__;
130        $where = "bloc.device_type_id = ? AND (anywhere = 1 OR pos.page_id = ?)";
131        $objQuery->setOrder('target_id, bloc_row');
132        return $objQuery->select("*", $table, $where,
133                                 array($device_type_id, $page_id));
134    }
135
136    /**
137     * 各部分のナビ情報を取得する.
138     *
139     * @param array $arrNavi ナビ情報の配列
140     * @param integer $target_id ターゲットID
141     * @param integer $device_type_id 端末種別ID
142     * @return array ブロック情報の配列
143     */
144    function lfGetNavi($arrNavi, $target_id, $device_type_id = DEVICE_TYPE_PC) {
145        $arrRet = array();
146        if (is_array($arrNavi)) {
147            foreach ($arrNavi as $key => $val) {
148                // 指定された箇所と同じデータだけを取得する
149                if ($target_id == $val['target_id'] ) {
150                    if ($val['php_path'] != '') {
151                        $arrNavi[$key]['php_path'] = HTML_PATH . $val['php_path'];
152                    } else {
153                        $user_block_path = $this->getTemplatePath($device_type_id, true) .  "/" . $val['tpl_path'];
154                        if (is_file($user_block_path)) {
155                            $arrNavi[$key]['tpl_path'] = $user_block_path;
156                        } else {
157                            $arrNavi[$key]['tpl_path'] = $this->getTemplatePath($device_type_id) . $val['tpl_path'];
158                        }
159                    }
160                    // phpから呼び出されるか、tplファイルが存在する場合
161                    if ($val['php_path'] != '' || is_file($arrNavi[$key]['tpl_path'])) {
162                        $arrRet[] = $arrNavi[$key];
163                    } else {
164                        GC_Utils::gfPrintLog("ブロック読み込みエラー:" . $arrNavi[$key]['tpl_path']);
165                    }
166                }
167            }
168        }
169        return $arrRet;
170    }
171
172    /**
173     * カラム数を取得する.
174     *
175     * @param array $arrPageLayout レイアウト情報の配列
176     * @return integer $col_num カラム数
177     */
178    function lfGetColumnNum($arrPageLayout) {
179        // メインは確定
180        $col_num = 1;
181        // LEFT NAVI
182        if (count($arrPageLayout['LeftNavi']) > 0) $col_num++;
183        // RIGHT NAVI
184        if (count($arrPageLayout['RightNavi']) > 0) $col_num++;
185
186        return $col_num;
187    }
188
189    /**
190     * ページ情報を削除する.
191     *
192     * @param integer $page_id ページID
193     * @param integer $device_type_id 端末種別ID
194     * @return integer 削除数
195     */
196    function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) {
197        $objQuery =& SC_Query::getSingletonInstance();
198        $arrDelData = array();      // 抽出データ用
199
200        // page_id が空でない場合にはdeleteを実行
201        if ($page_id != '') {
202
203            $arrPageData = $this->lfGetPageData("page_id = ? AND device_type_id = ?" , array($page_id, $device_type_id));
204            // SQL実行
205            $ret = $objQuery->delete("dtb_pagelayout", "page_id = ? AND device_type_id = ?", array($page_id, $device_type_id));
206
207            // ファイルの削除
208            $this->lfDelFile($arrPageData[0]);
209        }
210        return $ret;
211    }
212
213    /**
214     * ページのファイルを削除する.
215     *
216     * @param array $arrData ページ情報の配列
217     * @return void // TODO boolean にするべき?
218     */
219    function lfDelFile($arrData) {
220        // ファイルディレクトリ取得
221        $del_php = HTML_PATH . $arrData['php_dir'] . $arrData['filename'] . ".php";
222        $del_tpl = HTML_PATH . $arrData['tpl_dir'] . $arrData['filename'] . ".tpl";
223
224        // phpファイルの削除
225        if (file_exists($del_php)) {
226            unlink($del_php);
227        }
228
229        // tplファイルの削除
230        if (file_exists($del_tpl)) {
231            unlink($del_tpl);
232        }
233    }
234
235    /**
236     * データがベースデータかどうか.
237     *
238     * @param integer $page_id ページID
239     * @param integer $device_type_id 端末種別ID
240     * @return boolean ベースデータの場合 true
241     */
242    function lfCheckBaseData($page_id, $device_type_id) {
243        $result = false;
244
245        if ($page_id == 0) {
246            return $result;
247        }
248
249        $arrChkData = $this->lfgetPageData("page_id = ? AND device_type_id = ?",
250                                           array($page_id, $device_type_id));
251
252        if ($arrChkData[0]['edit_flg'] == 2) {
253            $result = true;
254        }
255
256        return $result;
257    }
258
259    /**
260     * テンプレートのパスを取得する.
261     */
262    function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false) {
263        $templateName = "";
264        switch ($device_type_id) {
265        case DEVICE_TYPE_MOBILE:
266            $dir = MOBILE_TEMPLATE_DIR;
267            $userPath = HTML_PATH . MOBILE_DIR . USER_DIR;
268            $templateName = MOBILE_TEMPLATE_NAME;
269            break;
270
271        case DEVICE_TYPE_SMARTPHONE:
272            $dir = SMARTPHONE_TEMPLATE_DIR;
273            $userPath = HTML_PATH . SMARTPHONE_DIR . USER_DIR;
274            $templateName = SMARTPHONE_TEMPLATE_NAME;
275            break;
276
277        case DEVICE_TYPE_PC:
278        default:
279            $dir = TEMPLATE_DIR;
280            $userPath = USER_PATH;
281            $templateName = TEMPLATE_NAME;
282        }
283        if ($isUser) {
284            $dir = $userPath . USER_PACKAGE_DIR . $templateName . "/";
285        }
286        return $dir;
287    }
288
289    /**
290     * user_data の絶対パスを返す.
291     *
292     * @param integer $device_type_id 端末種別ID
293     * @return string 端末に応じた user_data の絶対パス
294     */
295    function getUserPath($device_type_id = DEVICE_TYPE_PC) {
296        switch ($device_type_id) {
297        case DEVICE_TYPE_MOBILE:
298            return HTML_PATH . MOBILE_DIR . USER_DIR;
299            break;
300
301        case DEVICE_TYPE_SMARTPHONE:
302            return HTML_PATH . SMARTPHONE_DIR . USER_DIR;
303            break;
304
305        case DEVICE_TYPE_PC:
306        default:
307        }
308        return USER_PATH;
309    }
310
311    /**
312     * DocumentRoot から user_data のパスを取得する.
313     *
314     * @param integer $device_type_id 端末種別ID
315     * @return string 端末に応じた DocumentRoot から user_data までのパス
316     */
317    function getUserDir($device_type_id = DEVICE_TYPE_PC) {
318        switch ($device_type_id) {
319        case DEVICE_TYPE_MOBILE:
320            $userDir = URL_DIR . MOBILE_DIR . USER_DIR;
321            $templateName = MOBILE_TEMPLATE_NAME;
322            break;
323
324        case DEVICE_TYPE_SMARTPHONE:
325            $userDir = URL_DIR . SMARTPHONE_DIR . USER_DIR;
326            break;
327
328        case DEVICE_TYPE_PC:
329        default:
330            $userDir = URL_DIR . USER_DIR;
331        }
332        return $userDir;
333    }
334}
335?>
Note: See TracBrowser for help on using the repository browser.