source: branches/camp/camp-2_5-E/data/class/pages/LC_Page.php @ 19540

Revision 19540, 19.2 KB checked in by Yammy, 16 years ago (diff)

LC_Page::reload() を SC_DIsplay::reload() に変更

  • 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_PATH . '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 = 2;
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    /** body タグの onload 属性 */
67    var $tpl_onload;
68
69    /** 送料合計 */
70    var $tpl_total_deliv_fee;
71
72    /** トランザクションID */
73    var $transactionid;
74
75    /** テンプレート名 */
76    var $template;
77
78    // }}}
79    // {{{ functions
80
81    /**
82     * Page を初期化する.
83     *
84     * @return void
85     */
86    function init() {
87        $this->tpl_authority = $_SESSION['authority'];
88        // XXX すべてのページで宣言するべき
89        $layout = new SC_Helper_PageLayout_Ex();
90        $layout->sfGetPageLayout($this, false);
91
92        $this->template = SITE_FRAME;
93
94        // ディスプレイクラス生成
95        $this->objDisplay = new SC_Display();
96
97        // プラグインクラス生成
98        $this->objPlugin = new SC_Helper_Plugin_Ex();
99        $this->objPlugin->preProcess($this);
100    }
101
102    /**
103     * Page のプロセス.
104     *
105     * @return void
106     */
107    function process() {}
108
109    /**
110     * Page のプロセス.(モバイル)
111     *
112     * @return void
113     */
114    function mobileProcess() {}
115
116    /**
117     * Page のレスポンス送信.
118     *
119     * @return void
120     */
121    function sendResponse() {
122        // post-prosess処理(暫定的)
123        $this->objPlugin->process($this);
124
125        $this->objDisplay->hoge($this);
126        $this->objDisplay->response->response();
127    }
128
129    /**
130     * Page のレスポンス送信(ダウンロード).
131     *
132     * @return void
133     */
134    function sendResponseCSV($file_name, $data) {
135        $this->objDisplay->hoge($this);
136        $this->objDisplay->addHeader("Content-disposition", "attachment; filename=${file_name}");
137        $this->objDisplay->addHeader("Content-type", "application/octet-stream; name=${file_name}");
138        $this->objDisplay->addHeader("Cache-Control", "");
139        $this->objDisplay->addHeader("Pragma", "");
140
141        $this->objDisplay->response->body = $data;
142        $this->objDisplay->response->response();
143        exit;
144    }
145
146    /**
147     * デストラクタ.
148     *
149     * @return void
150     */
151    function destroy() {}
152
153    /**
154     * テンプレート取得
155     *
156     */
157    function getTemplate() {
158        return $this->template;
159    }
160
161    /**
162     * テンプレート設定(ポップアップなどの場合)
163     *
164     */
165    function setTemplate($template) {
166        $this->template = $template;
167    }
168
169    /**
170     * 指定の URL へリダイレクトする.
171     *
172     * リダイレクト先 URL に SITE_URL 及び SSL_URL を含むかチェックし,
173     * LC_Page::getToken() の値を URLパラメータで自動的に付与する.
174     *
175     * @param string $url リダイレクト先 URL
176     * @param boolean $isMobile モバイル用にセッションIDを付与する場合 true
177     * @return void|boolean $url に SITE_URL 及び, SSL_URL を含まない場合 false,
178     *                       正常に遷移可能な場合は, $url の ロケーションヘッダを出力する.
179     * @see Net_URL
180     */
181    function sendRedirect($url, $isMobile = false) {
182echo "SC_Response.php::sendRedirect()に移行してね。";
183exit;
184
185        if (preg_match("/(" . preg_quote(SITE_URL, '/')
186                          . "|" . preg_quote(SSL_URL, '/') . ")/", $url)) {
187
188            $netURL = new Net_URL($url);
189            if (!empty($_SERVER['QUERY_STRING'])) {
190                $netURL->addRawQueryString($_SERVER['QUERY_STRING']);
191            }
192
193            $session = SC_SessionFactory::getInstance();
194            if ($isMobile || $session->useCookie() == false) {
195                $netURL->addQueryString(session_name(), session_id());
196            }
197
198            $netURL->addQueryString(TRANSACTION_ID_NAME, $this->getToken());
199            header("Location: " . $netURL->getURL());
200            //return true;
201            exit();
202        }
203        return false;
204    }
205
206    // }}}
207    // {{{ protected functions
208
209    /**
210     * トランザクショントークンを生成し, 取得する.
211     *
212     * 悪意のある不正な画面遷移を防止するため, 予測困難な文字列を生成して返す.
213     * 同時に, この文字列をセッションに保存する.
214     *
215     * この関数を使用するためには, 生成した文字列を次画面へ渡すパラメータとして
216     * 出力する必要がある.
217     *
218     * 例)
219     * <input type="hidden" name="transactionid" value="この関数の返り値" />
220     *
221     * 遷移先のページで, LC_Page::isValidToken() の返り値をチェックすることにより,
222     * 画面遷移の妥当性が確認できる.
223     *
224     * @access protected
225     * @return string トランザクショントークンの文字列
226     */
227    function getToken() {
228echo "SC_Helper_Session.php::getToken()に移行してね。";
229exit;
230        if (empty($_SESSION[TRANSACTION_ID_NAME])) {
231            $_SESSION[TRANSACTION_ID_NAME] = $this->createToken();
232        }
233        return $_SESSION[TRANSACTION_ID_NAME];
234    }
235
236    /**
237     * トランザクショントークンの妥当性をチェックする.
238     *
239     * 前画面で生成されたトランザクショントークンの妥当性をチェックする.
240     * この関数を使用するためには, 前画面のページクラスで LC_Page::getToken()
241     * を呼んでおく必要がある.
242     *
243     * @access protected
244     * @return boolean トランザクショントークンが有効な場合 true
245     */
246    function isValidToken() {
247echo "SC_Helper_Session.php::isValidToken()に移行してね。";
248exit;
249
250        $checkToken = "";
251
252        // $_POST の値を優先する
253        if (isset($_POST[TRANSACTION_ID_NAME])) {
254
255            $checkToken = $_POST[TRANSACTION_ID_NAME];
256        } elseif (isset($_GET[TRANSACTION_ID_NAME])) {
257
258            $checkToken = $_GET[TRANSACTION_ID_NAME];
259        }
260
261        $ret = false;
262        // token の妥当性チェック
263        if ($checkToken === $_SESSION[TRANSACTION_ID_NAME]) {
264
265            $ret = true;
266        }
267
268        unset($_SESSION[TRANSACTION_ID_NAME]);
269        return $ret;
270    }
271
272    /**
273     * $path から URL を取得する.
274     *
275     * 以下の順序で 引数 $path から URL を取得する.
276     * 1. realpath($path) で $path の 絶対パスを取得
277     * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除
278     * 3. $useSSL の値に応じて, SITE_URL 又は, SSL_URL を付与する.
279     *
280     * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式
281     * の配列を $param へ渡す.
282     *
283     * @access protected
284     * @param string $path 結果を取得するためのパス
285     * @param array $param URL に付与するパラメータの配列
286     * @param mixed $useSSL 結果に SSL_URL を使用する場合 true,
287     *                         SITE_URL を使用する場合 false,
288     *                         デフォルト "escape" 現在のスキーマを使用
289     * @return string $path の存在する http(s):// から始まる絶対パス
290     * @see Net_URL
291     */
292    function getLocation($path, $param = array(), $useSSL = "escape") {
293        $rootPath = $this->getRootPath($path);
294
295        // スキーマを定義
296        if ($useSSL === true) {
297            $url = SSL_URL . $rootPath;
298        } elseif ($useSSL === false){
299            $url = SITE_URL . $rootPath;
300        } elseif ($useSSL == "escape") {
301            if (SC_Utils_Ex::sfIsHTTPS()) {
302                $url = SSL_URL . $rootPath;
303            } else {
304                $url = SITE_URL . $rootPath;
305            }
306        } else {
307            die("[BUG] Illegal Parametor of \$useSSL ");
308        }
309
310        $netURL = new Net_URL($url);
311        // QUERY_STRING 生成
312        foreach ($param as $key => $val) {
313            $netURL->addQueryString($key, $val);
314        }
315
316        return $netURL->getURL();
317    }
318
319    /**
320     * EC-CUBE のWEBルート(/html/)を / としたパスを返す
321     *
322     * @param string $path 結果を取得するためのパス
323     * @return string EC-CUBE のWEBルート(/html/)を / としたパス
324     */
325    function getRootPath($path) {
326        // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
327        $path = str_replace('\\', '/', $path);
328        $htmlPath = str_replace('\\', '/', HTML_PATH);
329       
330        // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9 )
331        if (strlen($path) == 0) {
332            $path = '.';
333        }
334       
335        // $path が / で始まっている場合
336        if (substr($path, 0, 1) == '/') {
337            $realPath = realpath($htmlPath . substr_replace($path, '', 0, strlen(URL_DIR)));
338        // 相対パスの場合
339        } else {
340            $realPath = realpath($path);
341        }
342        $realPath = str_replace('\\', '/', $realPath);
343       
344        // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。
345        if (substr($path, -1, 1) == '/' && substr($realPath, -1, 1) != '/') {
346            $realPath .= '/';
347        }
348       
349        // HTML_PATH を削除した文字列を取得.
350        $rootPath = str_replace($htmlPath, '', $realPath);
351        $rootPath = ltrim($rootPath, '/');
352
353        return $rootPath;
354    }
355
356    /**
357     * ページをリロードする.
358     *
359     * 引数 $queryString に, $_SERVER['QUERY_STRING'] の値を使用してはならない.
360     * この関数は, 内部で LC_Page::sendRedirect() を使用するため,
361     * $_SERVER['QUERY_STRING'] の値は自動的に付与される.
362     *
363     * @param array $queryString QueryString の配列
364     * @param bool $removeQueryString 付与されていた QueryString を削除する場合 true
365     * @return void
366     * @see Net_URL
367     */
368    function reload($queryString = array(), $removeQueryString = false) {
369echo "SC_Display.php::reload()に移行してね。";
370exit;
371
372        // 現在の URL を取得
373        $netURL = new Net_URL($_SERVER['REQUEST_URI']);
374
375        if ($removeQueryString) {
376            $netURL->querystring = array();
377            $_SERVER['QUERY_STRING'] = ''; // sendRedirect() での処理用らしい
378        }
379
380        // QueryString を付与
381        if (!empty($queryString)) {
382            foreach ($queryString as $key => $val) {
383                $netURL->addQueryString($key, $val);
384            }
385        }
386
387        $this->sendRedirect($netURL->getURL());
388    }
389
390    /**
391     * 互換性確保用メソッド
392     *
393     * @access protected
394     * @return void
395     * @deprecated 決済モジュール互換のため
396     */
397    function allowClientCache() {
398        LC_Page::httpCacheControl('private');
399    }
400
401    /**
402     * クライアント・プロキシのキャッシュを制御する.
403     *
404     * @access protected
405     * @param string $mode (nocache/private)
406     * @return void
407     */
408    function httpCacheControl($mode = '') {
409        switch ($mode) {
410            case 'nocache':
411                header('Pragma: no-cache');
412                header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
413                header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
414                header('Last-Modified:');
415                break;
416               
417            case 'private':
418                $cache_expire = session_cache_expire() * 60;
419                header('Pragma: no-cache');                                                            // anti-proxy
420                header('Expires:');                                                                    // anti-mozilla
421                header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}");  // HTTP/1.1 client
422                header('Last-Modified:');
423                break;
424               
425            default:
426                break;
427        }
428    }
429
430    /**
431     * デバック出力を行う.
432     *
433     * デバック用途のみに使用すること.
434     *
435     * @access protected
436     * @param mixed $val デバックする要素
437     * @return void
438     */
439    function p($val) {
440        SC_Utils_Ex::sfPrintR($val);
441    }
442
443    // }}}
444    // {{{ private functions
445
446    /**
447     * トランザクショントークン用の予測困難な文字列を生成して返す.
448     *
449     * @access private
450     * @return string トランザクショントークン用の文字列
451     */
452    function createToken() {
453        return sha1(uniqid(rand(), true));
454    }
455   
456    /**
457     * HTTPステータスコードを送出する。
458     *
459     * @param integer $code HTTPステータスコード
460     * @return void
461     * @author Seasoft (新規作成)
462     * @see Moony_Action::status() (オリジナル)
463     * @link http://moony.googlecode.com/ (オリジナル)
464     * @author YAMAOKA Hiroyuki (オリジナル)
465     * @copyright 2005-2008 YAMAOKA Hiroyuki (オリジナル)
466     * @license http://opensource.org/licenses/bsd-license.php New BSD License (オリジナル)
467     * @link http://ja.wikipedia.org/wiki/HTTP%E3%82%B9%E3%83%86%E3%83%BC%E3%82%BF%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%89 (邦訳)
468     * @license http://www.gnu.org/licenses/fdl.html GFDL (邦訳)
469     */
470    function sendHttpStatus($code) {
471        $protocol = $_SERVER['SERVER_PROTOCOL'];
472        $httpVersion = (strpos($protocol, '1.1') !== false) ? '1.1' : '1.0';
473        $messages = array(
474            // Informational 1xx                        // 【情報】
475            100 => 'Continue',                          // 継続
476            101 => 'Switching Protocols',               // プロトコル切替え
477            // Success 2xx                              // 【成功】
478            200 => 'OK',                                // OK
479            201 => 'Created',                           // 作成
480            202 => 'Accepted',                          // 受理
481            203 => 'Non-Authoritative Information',     // 信頼できない情報
482            204 => 'No Content',                        // 内容なし
483            205 => 'Reset Content',                     // 内容のリセット
484            206 => 'Partial Content',                   // 部分的内容
485            // Redirection 3xx                          // 【リダイレクション】
486            300 => 'Multiple Choices',                  // 複数の選択
487            301 => 'Moved Permanently',                 // 恒久的に移動した
488            302 => 'Found',  // 1.1                     // 発見した (リクエストしたリソースは一時的に移動されているときに返される)
489            303 => 'See Other',                         // 他を参照せよ
490            304 => 'Not Modified',                      // 未更新
491            305 => 'Use Proxy',                         // プロキシを使用せよ
492            // 306 is no longer used but still reserved // 将来のために予約されている
493            307 => 'Temporary Redirect',                // 一時的リダイレクト
494            // Client Error 4xx                         // 【クライアントエラー】
495            400 => 'Bad Request',                       // リクエストが不正である
496            401 => 'Unauthorized',                      // 認証が必要である
497            402 => 'Payment Required',                  // 支払いが必要である
498            403 => 'Forbidden',                         // 禁止されている
499            404 => 'Not Found',                         // 未検出
500            405 => 'Method Not Allowed',                // 許可されていないメソッド
501            406 => 'Not Acceptable',                    // 受理できない
502            407 => 'Proxy Authentication Required',     // プロキシ認証が必要である
503            408 => 'Request Timeout',                   // リクエストタイムアウト
504            409 => 'Conflict',                          // 矛盾
505            410 => 'Gone',                              // 消滅した
506            411 => 'Length Required',                   // 長さが必要
507            412 => 'Precondition Failed',               // 前提条件で失敗した
508            413 => 'Request Entity Too Large',          // リクエストエンティティが大きすぎる
509            414 => 'Request-URI Too Long',              // リクエストURIが大きすぎる
510            415 => 'Unsupported Media Type',            // サポートしていないメディアタイプ
511            416 => 'Requested Range Not Satisfiable',   // リクエストしたレンジは範囲外にある
512            417 => 'Expectation Failed',                // 期待するヘッダに失敗
513            // Server Error 5xx                         // 【サーバエラー】
514            500 => 'Internal Server Error',             // サーバ内部エラー
515            501 => 'Not Implemented',                   // 実装されていない
516            502 => 'Bad Gateway',                       // 不正なゲートウェイ
517            503 => 'Service Unavailable',               // サービス利用不可
518            504 => 'Gateway Timeout',                   // ゲートウェイタイムアウト
519            505 => 'HTTP Version Not Supported',        // サポートしていないHTTPバージョン
520            509 => 'Bandwidth Limit Exceeded'           // 帯域幅制限超過
521        );
522        if (isset($messages[$code])) {
523            if ($httpVersion !== '1.1') {
524                // HTTP/1.0
525                $messages[302] = 'Moved Temporarily';
526            }
527            header("HTTP/{$httpVersion} {$code} {$messages[$code]}");
528            header("Status: {$code} {$messages[$code]}", true, $code);
529        }
530    }
531}
532?>
Note: See TracBrowser for help on using the repository browser.