source: branches/version-2_11-dev/data/class/helper/SC_Helper_PageLayout.php @ 20970

Revision 20970, 12.8 KB checked in by Seasoft, 13 years ago (diff)

#1288 (「-er」カタカナ表記の統一)

  • 現状で混在が発生しているもののみ改修。
  • 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-2011 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     * 現在の URL に応じたページのレイアウト情報を取得し, LC_Page インスタンスに
40     * 設定する.
41     *
42     * @access public
43     * @param LC_Page $objPage LC_Page インスタンス
44     * @param boolean $preview プレビュー表示の場合 true
45     * @param string $url ページのURL($_SERVER['PHP_SELF'] の情報)
46     * @param integer $device_type_id 端末種別ID
47     * @return void
48     */
49    function sfGetPageLayout(&$objPage, $preview = false, $url = "", $device_type_id = DEVICE_TYPE_PC) {
50
51        // URLを元にページ情報を取得
52        if ($preview === false) {
53            $url = preg_replace('|^' . preg_quote(ROOT_URLPATH) . '|', '', $url);
54            $arrPageData = $this->getPageProperties($device_type_id, null, 'url = ?', array($url));
55        }
56        // プレビューの場合は, プレビュー用のデータを取得
57        else {
58            $arrPageData = $this->getPageProperties($device_type_id, 0);
59        }
60
61        $objPage->tpl_mainpage = $this->getTemplatePath($device_type_id) . $arrPageData[0]['filename'] . ".tpl";
62        $objPage->arrPageLayout =& $arrPageData[0];
63
64        // ページタイトルを設定
65        if (SC_Utils_Ex::isBlank($objPage->tpl_title)) {
66            $objPage->tpl_title = $objPage->arrPageLayout['page_name'];
67        }
68
69        // 該当ページのブロックを取得し, 配置する
70        $masterData = new SC_DB_MasterData();
71        $arrTarget = $masterData->getMasterData("mtb_target");
72        $arrBlocs = $this->getBlocPositions($device_type_id, $objPage->arrPageLayout['page_id']);
73        // php_path, tpl_path が存在するものを, 各ターゲットに配置
74        foreach (array_keys($arrTarget) as $target_id) {
75            foreach ($arrBlocs as $arrBloc) {
76                if ($arrBloc['target_id'] != $target_id) {
77                    continue;
78                }
79                if (is_file($arrBloc['php_path'])
80                    || is_file($arrBloc['tpl_path'])) {
81                    $objPage->arrPageLayout[$arrTarget[$target_id]][] = $arrBloc;
82                } else {
83                    $error = "ブロックが見つかりません\n"
84                        . "tpl_path: " . $arrBloc['tpl_path'] . "\n"
85                        . "php_path: " . $arrBloc['php_path'];
86                    GC_Utils_Ex::gfPrintLog($error);
87                }
88            }
89        }
90        // カラム数を取得する
91        $objPage->tpl_column_num = $this->getColumnNum($objPage->arrPageLayout);
92    }
93
94    /**
95     * ページの属性を取得する.
96     *
97     * この関数は, dtb_pagelayout の情報を検索する.
98     * $device_type_id は必須. デフォルト値は DEVICE_TYPE_PC.
99     * $page_id が null の場合は, $page_id が 0 以外のものを検索する.
100     *
101     * @access public
102     * @param integer $device_type_id 端末種別ID
103     * @param integer $page_id ページID; null の場合は, 0 以外を検索する.
104     * @param string $where 追加の検索条件
105     * @param array $arrParams 追加の検索パラメーター
106     * @return array ページ属性の配列
107     */
108    function getPageProperties($device_type_id = DEVICE_TYPE_PC, $page_id = null, $where = '', $arrParams = array()) {
109        $objQuery =& SC_Query_Ex::getSingletonInstance();
110        $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where);
111        if ($page_id === null) {
112            $where = 'page_id <> ? AND ' . $where;
113            $page_id = 0;
114        } else {
115            $where = 'page_id = ? AND ' . $where;
116        }
117        $objQuery->setOrder('page_id');
118        $arrParams = array_merge(array($page_id, $device_type_id), $arrParams);
119        return $objQuery->select('*', 'dtb_pagelayout', $where, $arrParams);
120    }
121
122    /**
123     * ブロック情報を取得する.
124     *
125     * @access public
126     * @param integer $device_type_id 端末種別ID
127     * @param string $where 追加の検索条件
128     * @param array $arrParams 追加の検索パラメーター
129     * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true
130     * @return array ブロック情報の配列
131     */
132    function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true) {
133        $objQuery =& SC_Query_Ex::getSingletonInstance();
134        $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where);
135        $arrParams = array_merge(array($device_type_id), $arrParams);
136        $objQuery->setOrder('bloc_id');
137        $arrBlocs = $objQuery->select('*', 'dtb_bloc', $where, $arrParams);
138        if ($has_realpath) {
139            $this->setBlocPathTo($device_type_id, $arrBlocs);
140        }
141        return $arrBlocs;
142    }
143
144    /**
145     * ブロック配置情報を取得する.
146     *
147     * @access public
148     * @param integer $device_type_id 端末種別ID
149     * @param integer $page_id ページID
150     * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true
151     * @return array 配置情報を含めたブロックの配列
152     */
153    function getBlocPositions($device_type_id, $page_id, $has_realpath = true) {
154        $objQuery =& SC_Query_Ex::getSingletonInstance();
155        $table = <<< __EOF__
156            dtb_blocposition AS pos
157       JOIN dtb_bloc AS bloc
158         ON bloc.bloc_id = pos.bloc_id
159        AND bloc.device_type_id = pos.device_type_id
160__EOF__;
161        $where = "bloc.device_type_id = ? AND (anywhere = 1 OR pos.page_id = ?)";
162        $objQuery->setOrder('target_id, bloc_row');
163        $arrBlocs = $objQuery->select("*", $table, $where,
164                                      array($device_type_id, $page_id));
165        if ($has_realpath) {
166            $this->setBlocPathTo($device_type_id, $arrBlocs);
167        }
168        return $arrBlocs;
169    }
170
171    /**
172     * ページ情報を削除する.
173     *
174     * XXX ファイルを確実に削除したかどうかのチェック
175     *
176     * @access public
177     * @param integer $page_id ページID
178     * @param integer $device_type_id 端末種別ID
179     * @return integer 削除数
180     */
181    function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) {
182        $objQuery =& SC_Query_Ex::getSingletonInstance();
183        $arrDelData = array();      // 抽出データ用
184
185        // page_id が空でない場合にはdeleteを実行
186        if ($page_id != '') {
187            $arrPageData = $this->getPageProperties($device_type_id, $page_id);
188            $ret = $objQuery->delete("dtb_pagelayout", "page_id = ? AND device_type_id = ?", array($page_id, $device_type_id));
189            // ファイルの削除
190            $this->lfDelFile($arrPageData[0]['filename'], $device_type_id);
191        }
192        return $ret;
193    }
194
195    /**
196     * ページのファイルを削除する.
197     *
198     * dtb_pagelayout の削除後に呼び出すこと。
199     *
200     * @access private
201     * @param string $filename
202     * @param integer $device_type_id 端末種別ID
203     * @return void // TODO boolean にするべき?
204     */
205    function lfDelFile($filename, $device_type_id) {
206        $objQuery =& SC_Query_Ex::getSingletonInstance();
207
208        /*
209         * 同名ファイルの使用件数
210         * PHP ファイルは, 複数のデバイスで共有するため, device_type_id を条件に入れない
211         */
212        $count = $objQuery->count('dtb_pagelayout', 'filename = ?', array($filename));
213
214        if ($count == 0) {
215            // phpファイルの削除
216            $del_php = HTML_REALDIR . $filename . '.php';
217            if (file_exists($del_php)) {
218                unlink($del_php);
219            }
220        }
221
222        // tplファイルの削除
223        $del_tpl = $this->getTemplatePath($device_type_id) . $filename . '.tpl';
224        if (file_exists($del_tpl)) {
225            unlink($del_tpl);
226        }
227    }
228
229    /**
230     * 編集可能ページかどうか.
231     *
232     * @access public
233     * @param integer $device_type_id 端末種別ID
234     * @param integer $page_id ページID
235     * @return 編集可能ページの場合 true
236     */
237    function isEditablePage($device_type_id, $page_id) {
238        if ($page_id == 0) {
239            return false;
240        }
241        $arrPages = $this->getPageProperties($device_type_id, $page_id);
242        if ($arrPages[0]['edit_flg'] != 2) {
243            return true;
244        }
245        return false;
246    }
247
248    /**
249     * テンプレートのパスを取得する.
250     *
251     * @access public
252     * @param integer $device_type_id 端末種別ID
253     * @param boolean $isUser USER_REALDIR 以下のパスを返す場合 true
254     * @return string テンプレートのパス
255     */
256    function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false) {
257        $templateName = "";
258        switch ($device_type_id) {
259        case DEVICE_TYPE_MOBILE:
260            $dir = MOBILE_TEMPLATE_REALDIR;
261            $templateName = MOBILE_TEMPLATE_NAME;
262            break;
263
264        case DEVICE_TYPE_SMARTPHONE:
265            $dir = SMARTPHONE_TEMPLATE_REALDIR;
266            $templateName = SMARTPHONE_TEMPLATE_NAME;
267            break;
268
269        case DEVICE_TYPE_PC:
270        default:
271            $dir = TEMPLATE_REALDIR;
272            $templateName = TEMPLATE_NAME;
273        }
274        $userPath = USER_REALDIR;
275        if ($isUser) {
276            $dir = $userPath . USER_PACKAGE_DIR . $templateName . "/";
277        }
278        return $dir;
279    }
280
281    /**
282     * DocumentRoot から user_data のパスを取得する.
283     *
284     * 引数 $hasPackage を true にした場合は, user_data/packages/template_name
285     * を取得する.
286     *
287     * @access public
288     * @param integer $device_type_id 端末種別ID
289     * @param boolean $hasPackage パッケージのパスも含める場合 true
290     * @return string 端末に応じた DocumentRoot から user_data までのパス
291     */
292    function getUserDir($device_type_id = DEVICE_TYPE_PC, $hasPackage = false) {
293        switch ($device_type_id) {
294        case DEVICE_TYPE_MOBILE:
295            $templateName = MOBILE_TEMPLATE_NAME;
296            break;
297
298        case DEVICE_TYPE_SMARTPHONE:
299            $templateName = SMARTPHONE_TEMPLATE_NAME;
300            break;
301
302        case DEVICE_TYPE_PC:
303        default:
304            $templateName = TEMPLATE_NAME;
305        }
306        $userDir = ROOT_URLPATH . USER_DIR;
307        if ($hasPackage) {
308            return $userDir . USER_PACKAGE_DIR . $templateName . "/";
309        }
310        return $userDir;
311    }
312
313    // }}}
314    // {{{ private functions
315
316    /**
317     * ブロックの php_path, tpl_path を設定する.
318     *
319     * @access private
320     * @param integer $device_type_id 端末種別ID
321     * @param array $arrBlocs 設定するブロックの配列
322     * @return void
323     */
324    function setBlocPathTo($device_type_id = DEVICE_TYPE_PC, &$arrBlocs) {
325        foreach (array_keys($arrBlocs) as $key) {
326            $arrBloc =& $arrBlocs[$key];
327            $arrBloc['php_path'] = SC_Utils_Ex::isBlank($arrBloc['php_path']) ? '' : HTML_REALDIR . $arrBloc['php_path'];
328            $bloc_dir = $this->getTemplatePath($device_type_id) . BLOC_DIR;
329            $arrBloc['tpl_path'] = SC_Utils_Ex::isBlank($arrBloc['tpl_path']) ? '' : $bloc_dir . $arrBloc['tpl_path'];
330        }
331    }
332
333    /**
334     * カラム数を取得する.
335     *
336     * @access private
337     * @param array $arrPageLayout レイアウト情報の配列
338     * @return integer $col_num カラム数
339     */
340    function getColumnNum($arrPageLayout) {
341        // メインは確定
342        $col_num = 1;
343        // LEFT NAVI
344        if (count($arrPageLayout['LeftNavi']) > 0) $col_num++;
345        // RIGHT NAVI
346        if (count($arrPageLayout['RightNavi']) > 0) $col_num++;
347
348        return $col_num;
349    }
350}
351?>
Note: See TracBrowser for help on using the repository browser.