source: branches/comu-ver2/data/class/pages/error/LC_Page_Error_SystemError.php @ 18291

Revision 18291, 5.3 KB checked in by Seasoft, 15 years ago (diff)

システムエラーでソース以外にも任意のメッセージを複数表示できるように改訂。

  • 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-2007 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(CLASS_PATH . "pages/error/LC_Page_Error.php");
26
27/**
28 * システムエラー表示のページクラス
29 * システムエラーや例外が発生した場合の表示ページ
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Error_SystemError extends LC_Page_Error {
36   
37    /** PEAR_Error */
38    var $pearResult;
39   
40    /** PEAR_Error がセットされていない場合用のバックトレーススタック */
41    var $backtrace;
42
43    /** デバッグ用のメッセージ配列 */
44    var $arrDebugMsg = array();
45
46    // }}}
47    // {{{ functions
48
49    /**
50     * Page を初期化する.
51     *
52     * @return void
53     */
54    function init() {
55        parent::init();
56
57        $this->tpl_title = 'システムエラー';
58        $this->adminPage = $this->isAdminPage();
59
60        if ($this->adminPage) {
61            $this->tpl_mainpage = 'login_error.tpl';
62            $this->flame = LOGIN_FRAME;
63        } else {
64            $this->flame = SITE_FRAME;
65        }
66    }
67
68    /**
69     * Page のプロセス。
70     *
71     * @return void
72     */
73    function process() {
74        require_once CLASS_PATH . 'SC_MobileUserAgent.php';
75
76        $objView = null;
77        if (SC_MobileUserAgent::isMobile() && $this->adminPage == false) {
78            $objView = new SC_InstallView(MOBILE_TEMPLATE_DIR, MOBILE_COMPILE_DIR);
79        } elseif($this->adminPage) {
80            $objView = new SC_InstallView(TEMPLATE_ADMIN_DIR, COMPILE_ADMIN_DIR);
81        } else {
82            $objView = new SC_InstallView(TEMPLATE_DIR, COMPILE_DIR);
83        }
84
85        $this->tpl_error = "システムエラーが発生しました。<br />大変お手数ですが、サイト管理者までご連絡ください。";
86
87        $objView->assignobj($this);
88        $objView->display($this->flame);
89       
90        if (DEBUG_MODE) {
91            echo '<div class="debug">';
92            echo '<div>▼▼▼ デバッグ情報ここから ▼▼▼</div>';
93            echo '<pre>';
94            print_r(htmlspecialchars($this->sfGetErrMsg(), ENT_QUOTES, CHAR_CODE));
95            echo '</pre>';
96            echo '<div>▲▲▲ デバッグ情報ここまで ▲▲▲</div>';
97            echo '</div>';
98        }
99    }
100
101    /**
102     * デストラクタ.
103     *
104     * @return void
105     */
106    function destroy() {
107        parent::destroy();
108    }
109
110    /**
111     * 管理機能かどうかを判定する.
112     *
113     * @return boolean
114     */
115    function isAdminPage() {
116        return preg_match('|/admin/|', $_SERVER['PHP_SELF']);
117    }
118   
119    /**
120     * エラーメッセージを生成する
121     *
122     * @return string
123     */
124    function sfGetErrMsg() {
125        $errmsg = '';
126        $errmsg .= $this->lfGetErrMsgHead();
127        $errmsg .= "\n";
128       
129        // デバッグ用のメッセージが指定されている場合
130        if (!empty($this->arrDebugMsg)) {
131            $errmsg .= implode("\n\n", $this->arrDebugMsg) . "\n";
132            $errmsg .= "\n";
133        }
134       
135        // PEAR エラーを伴う場合
136        if (!is_null($this->pearResult)) {
137            $errmsg .= $this->pearResult->message . "\n\n";
138            $errmsg .= $this->pearResult->userinfo . "\n\n";
139            $errmsg .= SC_Utils_Ex::sfBacktraceToString($this->pearResult->backtrace);
140        }
141        // (上に該当せず)バックトレーススタックが指定されている場合
142        else if (is_array($this->backtrace)) {
143            $errmsg .= SC_Utils_Ex::sfBacktraceToString($this->backtrace);
144        }
145        // (上に該当せず)バックトレースを生成できる環境(一般的には PHP 4 >= 4.3.0, PHP 5)の場合
146        else if (function_exists("debug_backtrace")) {
147            $errmsg .= SC_Utils_Ex::sfBacktraceToString(array_slice(debug_backtrace(), 2));
148        }
149       
150        return $errmsg;
151    }
152   
153    /**
154     * エラーメッセージの冒頭部を生成する
155     *
156     * @return string
157     */
158    function lfGetErrMsgHead() {
159        $errmsg = '';
160        $errmsg .= SC_Utils_Ex::sfGetUrl() . "\n";
161        $errmsg .= "\n";
162        $errmsg .= "SERVER_ADDR: " . $_SERVER['SERVER_ADDR'] . "\n";
163        $errmsg .= "REMOTE_ADDR: " . $_SERVER['REMOTE_ADDR'] . "\n";
164        $errmsg .= "USER_AGENT: " . $_SERVER['HTTP_USER_AGENT'] . "\n";
165       
166        return $errmsg;
167    }
168
169    /**
170     * デバッグ用のメッセージを追加
171     *
172     * @return void
173     */
174    function addDebugMsg($debugMsg) {
175        $this->arrDebugMsg[] = rtrim($debugMsg, "\n");
176    }
177}
178?>
Note: See TracBrowser for help on using the repository browser.