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

Revision 19805, 11.1 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部実装

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