source: branches/version-2_5-dev/data/class/pages/LC_Page.php @ 20764

Revision 20764, 12.2 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

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