C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RU7MSUA\html\class\errorhandler.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
// $Id: errorhandler.php,v 1.2.24.4 2005/07/26 07:11:46 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

/**
 * Error handler class
 *
 * @author Michael van Dam
 */
class XoopsErrorHandler
{
    
/**
     * List of errors
     * 
     * @var array 
     * @access private 
     */
    
var $_errors = array();

    
/**
     * Show error messages?
     *
     * @var boolean
     * @access private
     */
    
var $_showErrors false;

    
/**
     * Was there a fatal error (E_USER_ERROR)
     *
     * @var boolean
     * @access private
     */
    
var $_isFatal false;

    
/**
     * Constructor
     *
     * Registers the error handler and shutdown functions.  NOTE: when
     * registering an error handler, the setting or 'error_reporting' is
     * ignored and *everything* is trapped.
     */
    
function XoopsErrorHandler()
    {
        
set_error_handler('XoopsErrorHandler_HandleError');
        
register_shutdown_function('XoopsErrorHandler_Shutdown'); 
    }

    
/**
     * Get the (singleton) instance of the error handler
     *
     * @access public
     */
    
function &getInstance()
    {
        static 
$instance null;
        if (empty(
$instance)) {
            
$instance = new XoopsErrorHandler;
        }
        return 
$instance;
    }

    
/**
     * Activate the error handler
     *
     * @access public 
     * @param boolean $showErrors True if debug mode is on
     * @return void 
     */
    
function activate($showErrors=false)
    { 
        
$this->_showErrors $showErrors;
    } 

    
/**
     * Handle an error
     * 
     * @param array $error Associative array containing error info
     * @access public 
     * @return void 
     */
    
function handleError($error)
    {
        if ((
$error['errno'] & error_reporting()) != $error['errno']) {
            return;
        }
        
$this->_errors[] = $error;
        if (
$error['errno'] == E_USER_ERROR) {
            
$this->_isFatal true;
            exit();
        }
    }
    
    
/**
    * Redirect to an error page
    * 
    * @param int $code error code
    * @param int $moduleid ID of module this error is in
    *
    * @return void
    **/
    
function errorPage($code$moduleid 0) {
        
$modstring $moduleid "m=".intval($moduleid) : "";
        
header("location: ".XOOPS_URL."/error.php?c=".$code.$modstring);
        exit();
    }

    
/**
     * Render the list of errors
     *
     * NOTE: Unfortunately PHP 'fatal' and 'parse' errors are not trappable.
     * If the server has 'display_errors Off', then the result will be a
     * blank page.  It would be nice to print a message 'This page cannot
     * be displayed', but there seems to be no way to print this only when
     * exiting due to a fatal error rather than normal end of page.
     *
     * Thus, 'trigger_error' should be used to trap problems early and
     * display a meaningful message before a PHP fatal or parse error can
     * occur.
     * 
     * @TODO Use CSS
     * @TODO Use language? or allow customized message?
     *
     * @access public 
     * @return void 
     */
    
function renderErrors()
    {
        
$output '';
        if (
$this->_isFatal) {
            
// Local supporters should translate/customize this message for a user-friendly appearance
            
$output .= 'This page cannot be displayed due to an internal error.<br/><br/>';
            
$output .= 'If you are the administrator of this site, please visit the <a href="http://www.xoops.org/modules/smartfaq/faq.php?faqid=80" target="_blank">Xoops Troubleshooting Page</a>';
            
// Local supporter need uncomment and customize the line: 
            //$output .= ' or <a href="http://local.xoops.org/TroubleShootingPage/" target="_blank">Xoops Local Support Site</a>';
            
$output .= ' for assistance.<br/><br/>';
            
$output .= 'Helpful infomation you should provide while asking for assistance:<br/><br/>';
        }
        if (!
$this->_showErrors || empty($this->_errors)) {
            return 
$output;
        }

        foreach( 
$this->_errors as $error )
        {
            switch ( 
$error['errno'] )
            {
                case 
E_USER_NOTICE:
                    
$output .= "Notice [Xoops]: ";
                    break;
                case 
E_USER_WARNING:
                    
$output .= "Warning [Xoops]: ";
                    break;
                case 
E_USER_ERROR:
                    
$output .= "Error [Xoops]: ";
                    break;
                case 
E_NOTICE:
                    
$output .= "Notice [PHP]: ";
                    break;
                case 
E_WARNING:
                    
$output .= "Warning [PHP]: ";
                    break;
                default:
                    
$output .= "Unknown Condition [" $error['errno'] . "]: ";
            } 
            
$output .= sprintf"%s in file %s line %s<br>\n"$error['errstr'], $error['errfile'], $error['errline'] );
        } 
        return 
$output;
    } 



/**
 * User-defined error handler (called from 'trigger_error')
 * 
 * NOTE: Some recent versions of PHP have a 5th parameter, &$p_ErrContext
 * which is an associative array of all variables defined in scope in which
 * error occurred.  We cannot support this, for compatibility with older PHP.
 * 
 * @access public 
 * @param int $errNo Type of error
 * @param string $errStr Error message
 * @param string $errFile File in which error occurred
 * @param int $errLine Line number on which error occurred
 * @return void 
 */
function XoopsErrorHandler_HandleError($errNo$errStr$errFile$errLine)

    
// NOTE: we only store relative pathnames
    
$new_error = array( 
        
'errno' => $errNo,
        
'errstr' => $errStr,
        
'errfile' => preg_replace("|^" preg_quote(XOOPS_ROOT_PATH) . "/|"''$errFile),
        
'errline' => $errLine 
        
);
    
$error_handler =& XoopsErrorHandler::getInstance();
    
$error_handler->handleError($new_error);


/**
 * User-defined shutdown function (called from 'exit')
 * 
 * @access public 
 * @return void 
 */
function XoopsErrorHandler_Shutdown()
{
    
$error_handler =& XoopsErrorHandler::getInstance();
    echo 
$error_handler->renderErrors();


?>