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

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

#1613 (ソース整形・ソースコメントの改善)

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