Warning: Can't use blame annotator:
svn blame failed on branches/version-2_13-dev/data/class/helper/SC_Helper_PageLayout.php: バイナリファイル 'file:///home/svn/open/branches/version-2_13-dev/data/class/helper/SC_Helper_PageLayout.php' に対しては blame で各行の最終変更者を計算できません 195004

source: branches/version-2_13-dev/data/class/helper/SC_Helper_PageLayout.php @ 23610

Revision 23610, 14.1 KB checked in by kimoto, 10 years ago (diff)

#2426 ブロックのtpl_pathに絶対パスが指定できない
setBlocPathToが必要なのは、php_pathがない場合だけなので、条件を変更

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