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

Revision 22567, 14.9 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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