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

Revision 20485, 12.1 KB checked in by shutta, 13 years ago (diff)

SC_Display(基底クラス)をSC_Display_Ex(拡張クラス)を利用するように書き換え。

  • 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// {{{ 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        if(defined('PAGE_DISPLAY_TIME_LOG_MODE') && PAGE_DISPLAY_TIME_LOG_MODE == true) {
162            $timeEnd = SC_Utils_Ex::sfMicrotimeFloat();;
163            $timeExecTime = $timeEnd - $this->timeStart;
164            if(defined('PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME') && $timeExecTime >= (float)PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME) {
165                $logMsg = sprintf("PAGE_DISPLAY_TIME_LOG [%.2fsec]", $timeExecTime);
166                GC_Utils_Ex::gfPrintLog($logMsg);
167            }
168        }
169
170    }
171
172    /**
173     * テンプレート取得
174     *
175     */
176    function getTemplate() {
177        return $this->template;
178    }
179
180    /**
181     * テンプレート設定(ポップアップなどの場合)
182     *
183     */
184    function setTemplate($template) {
185        $this->template = $template;
186    }
187
188    /**
189     * $path から URL を取得する.
190     *
191     * 以下の順序で 引数 $path から URL を取得する.
192     * 1. realpath($path) で $path の 絶対パスを取得
193     * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除
194     * 3. $useSSL の値に応じて, HTTP_URL 又は, HTTPS_URL を付与する.
195     *
196     * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式
197     * の配列を $param へ渡す.
198     *
199     * @access protected
200     * @param string $path 結果を取得するためのパス
201     * @param array $param URL に付与するパラメータの配列
202     * @param mixed $useSSL 結果に HTTPS_URL を使用する場合 true,
203     *                         HTTP_URL を使用する場合 false,
204     *                         デフォルト "escape" 現在のスキーマを使用
205     * @return string $path の存在する http(s):// から始まる絶対パス
206     * @see Net_URL
207     */
208    function getLocation($path, $param = array(), $useSSL = "escape") {
209        $rootPath = $this->getRootPath($path);
210
211        // スキーマを定義
212        if ($useSSL === true) {
213            $url = HTTPS_URL . $rootPath;
214        } elseif ($useSSL === false){
215            $url = HTTP_URL . $rootPath;
216        } elseif ($useSSL == "escape") {
217            if (SC_Utils_Ex::sfIsHTTPS()) {
218                $url = HTTPS_URL . $rootPath;
219            } else {
220                $url = HTTP_URL . $rootPath;
221            }
222        } else {
223            die("[BUG] Illegal Parametor of \$useSSL ");
224        }
225
226        $netURL = new Net_URL($url);
227        // QUERY_STRING 生成
228        foreach ($param as $key => $val) {
229            $netURL->addQueryString($key, $val);
230        }
231
232        return $netURL->getURL();
233    }
234
235    /**
236     * EC-CUBE のWEBルート(/html/)を / としたパスを返す
237     *
238     * @param string $path 結果を取得するためのパス
239     * @return string EC-CUBE のWEBルート(/html/)を / としたパス
240     */
241    function getRootPath($path) {
242        // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
243        $path = str_replace('\\', '/', $path);
244        $htmlPath = str_replace('\\', '/', HTML_REALDIR);
245
246        // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9 )
247        if (strlen($path) == 0) {
248            $path = '.';
249        }
250
251        // $path が / で始まっている場合
252        if (substr($path, 0, 1) == '/') {
253            $realPath = realpath($htmlPath . substr_replace($path, '', 0, strlen(ROOT_URLPATH)));
254        // 相対パスの場合
255        } else {
256            $realPath = realpath($path);
257        }
258        $realPath = str_replace('\\', '/', $realPath);
259
260        // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。
261        if (substr($path, -1, 1) == '/' && substr($realPath, -1, 1) != '/') {
262            $realPath .= '/';
263        }
264
265        // HTML_REALDIR を削除した文字列を取得.
266        $rootPath = str_replace($htmlPath, '', $realPath);
267        $rootPath = ltrim($rootPath, '/');
268
269        return $rootPath;
270    }
271
272    /**
273     * 互換性確保用メソッド
274     *
275     * @access protected
276     * @return void
277     * @deprecated 決済モジュール互換のため
278     */
279    function allowClientCache() {
280        $this->httpCacheControl('private');
281    }
282
283    /**
284     * クライアント・プロキシのキャッシュを制御する.
285     *
286     * @access protected
287     * @param string $mode (nocache/private)
288     * @return void
289     */
290    function httpCacheControl($mode = '') {
291        switch ($mode) {
292            case 'nocache':
293                header('Pragma: no-cache');
294                header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
295                header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
296                header('Last-Modified:');
297                break;
298
299            case 'private':
300                $cache_expire = session_cache_expire() * 60;
301                header('Pragma: no-cache');                                                            // anti-proxy
302                header('Expires:');                                                                    // anti-mozilla
303                header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}");  // HTTP/1.1 client
304                header('Last-Modified:');
305                break;
306
307            default:
308                break;
309        }
310    }
311
312    /**
313     * リクエストパラメータ "mode" を取得する.
314     *
315     * 1. $_GET['mode'] の値を取得する.
316     * 2. 1 が存在しない場合は $_POST['mode'] の値を取得する.
317     * 3. どちらも存在しない場合は null を返す.
318     *
319     * mode に, 半角英数字とアンダーバー(_) 以外の文字列が検出された場合は null を
320     * 返す.
321     *
322     * @access protected
323     * @return string $_GET['mode'] 又は $_POST['mode'] の文字列
324     */
325    function getMode() {
326        $pattern = '/^[a-zA-Z0-9_]+$/';
327        $mode = null;
328        if (isset($_GET['mode']) && preg_match($pattern, $_GET['mode'])) {
329            $mode =  $_GET['mode'];
330        } elseif (isset($_POST['mode']) && preg_match($pattern, $_POST['mode'])) {
331            $mode = $_POST['mode'];
332        }
333        return $mode;
334    }
335
336    /**
337     * POST アクセスの妥当性を検証する.
338     *
339     * 生成されたトランザクショントークンの妥当性を検証し,
340     * 不正な場合はエラー画面へ遷移する.
341     *
342     * この関数は, 基本的に init() 関数で呼び出され, POST アクセスの場合は自動的に
343     * トランザクショントークンを検証する.
344     * ページによって検証タイミングなどを制御する必要がある場合は, この関数を
345     * オーバーライドし, 個別に設定を行うこと.
346     *
347     * @access protected
348     * @param boolean $is_admin 管理画面でエラー表示をする場合 true
349     * @return void
350     */
351    function doValidToken($is_admin = false) {
352        if ($_SERVER["REQUEST_METHOD"] == "POST") {
353            if (!SC_Helper_Session_Ex::isValidToken(false)) {
354                if ($is_admin) {
355                    SC_Utils_Ex::sfDispError(INVALID_MOVE_ERRORR);
356                } else {
357                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
358                }
359                exit;
360            }
361        }
362    }
363
364    /**
365     * トランザクショントークンを取得し, 設定する.
366     *
367     * @access protected
368     * @return void
369     */
370    function setTokenTo() {
371        $this->transactionid = SC_Helper_Session_Ex::getToken();
372    }
373
374    /**
375     * デバック出力を行う.
376     *
377     * デバック用途のみに使用すること.
378     *
379     * @access protected
380     * @param mixed $val デバックする要素
381     * @return void
382     */
383    function p($val) {
384        SC_Utils_Ex::sfPrintR($val);
385    }
386}
387?>
Note: See TracBrowser for help on using the repository browser.