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

Revision 21514, 13.1 KB checked in by Seasoft, 12 years ago (diff)

#1625 (typo修正・ソース整形・ソースコメントの改善)

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