source: branches/version-2_12-dev/data/class/pages/LC_Page.php @ 21716

Revision 21716, 13.2 KB checked in by Seasoft, 12 years ago (diff)

#1436 (CSS を改善)

  • 画面を特定した記述をできるように html 要素のクラスにページクラスを入れた。
  • 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 Page を制御する基底クラス
26 *
27 * Web Page を制御する Page クラスは必ずこのクラスを継承する.
28 * PHP4 ではこのような抽象クラスを作っても継承先で何でもできてしまうため、
29 * あまり意味がないが、アーキテクトを統一するために作っておく.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id:LC_Page.php 15532 2007-08-31 14:39:46Z nanasess $
34 */
35class LC_Page {
36
37    // {{{ properties
38
39    /** メインテンプレート */
40    var $tpl_mainpage;
41
42    /** テンプレートのカラム数 */
43    var $tpl_column_num;
44
45    /** メインナンバー */
46    var $tpl_mainno;
47
48    /** CSS のパス */
49    var $tpl_css;
50
51    /** JavaScript */
52    var $tpl_javascript;
53
54    /** タイトル */
55    var $tpl_title;
56
57    /** カテゴリ */
58    var $tpl_page_category;
59
60    /** ログインメールアドレス */
61    var $tpl_login_email;
62
63    /** HTML ロード後に実行する JavaScript コード */
64    var $tpl_onload;
65
66    /** トランザクションID */
67    var $transactionid;
68
69    /** メインテンプレート名 */
70    var $template = SITE_FRAME;
71
72    /** 店舗基本情報 */
73    var $arrSiteInfo;
74
75    /** プラグインを実行フラグ */
76    var $plugin_activate_flg = true;
77
78    // }}}
79    // {{{ functions
80
81    /**
82     * Page を初期化する.
83     *
84     * @return void
85     */
86    function init() {
87        // 開始時刻を設定する。
88        $this->timeStart = microtime(true);
89
90        $this->tpl_authority = $_SESSION['authority'];
91
92        // ディスプレイクラス生成
93        $this->objDisplay = new SC_Display_Ex();
94
95        $layout = new SC_Helper_PageLayout_Ex();
96        $layout->sfGetPageLayout($this, false, $_SERVER['SCRIPT_NAME'],
97                                 $this->objDisplay->detectDevice());
98
99        // スーパーフックポイントを実行.
100        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
101        $objPlugin->doAction('LC_Page_preProcess', array($this));
102
103        // 店舗基本情報取得
104        $this->arrSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
105
106        // トランザクショントークンの検証と生成
107        $this->doValidToken();
108        $this->setTokenTo();
109    }
110
111    /**
112     * Page のプロセス.
113     *
114     * @return void
115     */
116    function process() {}
117
118    /**
119     * Page のレスポンス送信.
120     *
121     * @return void
122     */
123    function sendResponse() {
124
125        // HeadNaviにpluginテンプレートを追加する.
126        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
127        $objPlugin->setHeadNaviBlocs($this->arrPageLayout['HeadNavi']);
128
129        // スーパーフックポイントを実行.
130        $objPlugin->doAction('LC_Page_process', array($this));
131
132        // ページクラス名をテンプレートに渡す
133        $arrBacktrace = debug_backtrace();
134        if (strlen($this->tpl_page_class_name) === 0) {
135            $this->tpl_page_class_name = $arrBacktrace[1]['class'];
136            $this->tpl_page_class_name = preg_replace('/_Ex$/', '', $this->tpl_page_class_name);
137        }
138
139        $this->objDisplay->prepare($this);
140        $this->objDisplay->response->write();
141    }
142
143    /**
144     * Page のレスポンス送信(ダウンロード).
145     *
146     * @return void
147     */
148    function sendResponseCSV($file_name, $data) {
149        $this->objDisplay->prepare($this);
150        $this->objDisplay->addHeader('Content-disposition', "attachment; filename=${file_name}");
151        $this->objDisplay->addHeader('Content-type', "application/octet-stream; name=${file_name}");
152        $this->objDisplay->addHeader('Cache-Control', '');
153        $this->objDisplay->addHeader('Pragma', '');
154
155        $this->objDisplay->response->body = $data;
156        $this->objDisplay->response->write();
157        exit;
158    }
159
160    /**
161     * デストラクタ.
162     *
163     * @return void
164     */
165    function destroy() {
166        // 一定時間以上かかったページの場合、ログ出力する。
167        // エラー画面の表示では $this->timeStart が出力されない
168        if (defined('PAGE_DISPLAY_TIME_LOG_MODE') && PAGE_DISPLAY_TIME_LOG_MODE == true && isset($this->timeStart)) {
169            $timeEnd = microtime(true);
170            $timeExecTime = $timeEnd - $this->timeStart;
171            if (defined('PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME') && $timeExecTime >= (float)PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME) {
172                $logMsg = sprintf('PAGE_DISPLAY_TIME_LOG [%.2fsec]', $timeExecTime);
173                GC_Utils_Ex::gfPrintLog($logMsg);
174            }
175        }
176
177    }
178
179    /**
180     * テンプレート取得
181     *
182     */
183    function getTemplate() {
184        return $this->template;
185    }
186
187    /**
188     * テンプレート設定(ポップアップなどの場合)
189     *
190     */
191    function setTemplate($template) {
192        $this->template = $template;
193    }
194
195    /**
196     * $path から URL を取得する.
197     *
198     * 以下の順序で 引数 $path から URL を取得する.
199     * 1. realpath($path) で $path の 絶対パスを取得
200     * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除
201     * 3. $useSSL の値に応じて, HTTP_URL 又は, HTTPS_URL を付与する.
202     *
203     * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式
204     * の配列を $param へ渡す.
205     *
206     * @access protected
207     * @param string $path 結果を取得するためのパス
208     * @param array $param URL に付与するパラメーターの配列
209     * @param mixed $useSSL 結果に HTTPS_URL を使用する場合 true,
210     *                         HTTP_URL を使用する場合 false,
211     *                         デフォルト 'escape' 現在のスキーマを使用
212     * @return string $path の存在する http(s):// から始まる絶対パス
213     * @see Net_URL
214     */
215    function getLocation($path, $param = array(), $useSSL = 'escape') {
216        $rootPath = $this->getRootPath($path);
217
218        // スキーマを定義
219        if ($useSSL === true) {
220            $url = HTTPS_URL . $rootPath;
221        } elseif ($useSSL === false) {
222            $url = HTTP_URL . $rootPath;
223        } elseif ($useSSL == 'escape') {
224            if (SC_Utils_Ex::sfIsHTTPS()) {
225                $url = HTTPS_URL . $rootPath;
226            } else {
227                $url = HTTP_URL . $rootPath;
228            }
229        } else {
230            die("[BUG] Illegal Parametor of \$useSSL ");
231        }
232
233        $netURL = new Net_URL($url);
234        // QUERY_STRING 生成
235        foreach ($param as $key => $val) {
236            $netURL->addQueryString($key, $val);
237        }
238
239        return $netURL->getURL();
240    }
241
242    /**
243     * EC-CUBE のWEBルート(/html/)を / としたパスを返す
244     *
245     * @param string $path 結果を取得するためのパス
246     * @return string EC-CUBE のWEBルート(/html/)を / としたパス
247     */
248    function getRootPath($path) {
249        // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
250        $path = str_replace('\\', '/', $path);
251        $htmlPath = str_replace('\\', '/', HTML_REALDIR);
252
253        // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9)
254        if (strlen($path) == 0) {
255            $path = '.';
256        }
257
258        // $path が / で始まっている場合
259        if (substr($path, 0, 1) == '/') {
260            $realPath = realpath($htmlPath . substr_replace($path, '', 0, strlen(ROOT_URLPATH)));
261        // 相対パスの場合
262        } else {
263            $realPath = realpath($path);
264        }
265        $realPath = str_replace('\\', '/', $realPath);
266
267        // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。
268        if (substr($path, -1, 1) == '/' && substr($realPath, -1, 1) != '/') {
269            $realPath .= '/';
270        }
271
272        // HTML_REALDIR を削除した文字列を取得.
273        $rootPath = str_replace($htmlPath, '', $realPath);
274        $rootPath = ltrim($rootPath, '/');
275
276        return $rootPath;
277    }
278
279    /**
280     * 互換性確保用メソッド
281     *
282     * @access protected
283     * @return void
284     * @deprecated 決済モジュール互換のため
285     */
286    function allowClientCache() {
287        $this->httpCacheControl('private');
288    }
289
290    /**
291     * クライアント・プロキシのキャッシュを制御する.
292     *
293     * @access protected
294     * @param string $mode (nocache/private)
295     * @return void
296     */
297    function httpCacheControl($mode = '') {
298        switch ($mode) {
299            case 'nocache':
300                header('Pragma: no-cache');
301                header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
302                header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
303                header('Last-Modified:');
304                break;
305
306            case 'private':
307                $cache_expire = session_cache_expire() * 60;
308                header('Pragma: no-cache');                                                            // anti-proxy
309                header('Expires:');                                                                    // anti-mozilla
310                header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}");  // HTTP/1.1 client
311                header('Last-Modified:');
312                break;
313
314            default:
315                break;
316        }
317    }
318
319    /**
320     * リクエストパラメーター 'mode' を取得する.
321     *
322     * 1. $_GET['mode'] の値を取得する.
323     * 2. 1 が存在しない場合は $_POST['mode'] の値を取得する.
324     * 3. どちらも存在しない場合は null を返す.
325     *
326     * mode に, 半角英数字とアンダーバー(_) 以外の文字列が検出された場合は null を
327     * 返す.
328     *
329     * @access protected
330     * @return string $_GET['mode'] 又は $_POST['mode'] の文字列
331     */
332    function getMode() {
333        $pattern = '/^[a-zA-Z0-9_]+$/';
334        $mode = null;
335        if (isset($_GET['mode']) && preg_match($pattern, $_GET['mode'])) {
336            $mode =  $_GET['mode'];
337        } elseif (isset($_POST['mode']) && preg_match($pattern, $_POST['mode'])) {
338            $mode = $_POST['mode'];
339        }
340        return $mode;
341    }
342
343    /**
344     * POST アクセスの妥当性を検証する.
345     *
346     * 生成されたトランザクショントークンの妥当性を検証し,
347     * 不正な場合はエラー画面へ遷移する.
348     *
349     * この関数は, 基本的に init() 関数で呼び出され, POST アクセスの場合は自動的に
350     * トランザクショントークンを検証する.
351     * ページによって検証タイミングなどを制御する必要がある場合は, この関数を
352     * オーバーライドし, 個別に設定を行うこと.
353     *
354     * @access protected
355     * @param boolean $is_admin 管理画面でエラー表示をする場合 true
356     * @return void
357     */
358    function doValidToken($is_admin = false) {
359        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
360            if (!SC_Helper_Session_Ex::isValidToken(false)) {
361                if ($is_admin) {
362                    SC_Utils_Ex::sfDispError(INVALID_MOVE_ERRORR);
363                } else {
364                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
365                }
366                exit;
367            }
368        }
369    }
370
371    /**
372     * トランザクショントークンを取得し, 設定する.
373     *
374     * @access protected
375     * @return void
376     */
377    function setTokenTo() {
378        $this->transactionid = SC_Helper_Session_Ex::getToken();
379    }
380
381    /**
382     * 前方互換用
383     *
384     * @deprecated 2.12.0 GC_Utils_Ex::gfPrintLog を使用すること
385     */
386    function log($mess, $log_level) {
387        trigger_error('前方互換用メソッドが使用されました。', E_USER_WARNING);
388        // ログレベル=Debugの場合は、DEBUG_MODEがtrueの場合のみログ出力する
389        if ($log_level === 'Debug' && DEBUG_MODE === false) {
390            return;
391        }
392
393        // ログ出力
394        GC_Utils_Ex::gfPrintLog($mess, '', true);
395    }
396
397    /**
398     * デバック出力を行う.
399     *
400     * デバック用途のみに使用すること.
401     *
402     * @access protected
403     * @param mixed $val デバックする要素
404     * @return void
405     */
406    function p($val) {
407        SC_Utils_Ex::sfPrintR($val);
408    }
409}
Note: See TracBrowser for help on using the repository browser.