| [ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: error_api.php,v 1.53.2.1 2007-10-13 22:35:26 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### Error API ### 25 26 # set up error_handler() as the new default error handling function 27 set_error_handler( 'error_handler' ); 28 29 ######################################### 30 # SECURITY NOTE: these globals are initialized here to prevent them 31 # being spoofed if register_globals is turned on 32 # 33 $g_error_parameters = array(); 34 $g_error_handled = false; 35 $g_error_proceed_url = null; 36 37 # --------------- 38 # Default error handler 39 # 40 # This handler will not receive E_ERROR, E_PARSE, E_CORE_*, or E_COMPILE_* 41 # errors. 42 # 43 # E_USER_* are triggered by us and will contain an error constant in $p_error 44 # The others, being system errors, will come with a string in $p_error 45 # 46 function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) { 47 global $g_error_parameters, $g_error_handled, $g_error_proceed_url; 48 global $g_lang_overrides; 49 global $g_error_send_page_header; 50 51 # check if errors were disabled with @ somewhere in this call chain 52 # also suppress php 5 strict warnings 53 if ( 0 == error_reporting() || 2048 == $p_type ) { 54 return; 55 } 56 57 $t_lang_pushed = false; 58 59 # flush any language overrides to return to user's natural default 60 if ( function_exists( 'db_is_connected' ) ) { 61 if ( db_is_connected() ) { 62 lang_push( lang_get_default() ); 63 $t_lang_pushed = true; 64 } 65 } 66 67 $t_short_file = basename( $p_file ); 68 $t_method_array = config_get( 'display_errors' ); 69 if ( isset( $t_method_array[$p_type] ) ) { 70 $t_method = $t_method_array[$p_type]; 71 } else { 72 $t_method = 'none'; 73 } 74 75 # build an appropriate error string 76 switch ( $p_type ) { 77 case E_WARNING: 78 $t_error_type = 'SYSTEM WARNING'; 79 $t_error_description = $p_error; 80 break; 81 case E_NOTICE: 82 $t_error_type = 'SYSTEM NOTICE'; 83 $t_error_description = $p_error; 84 break; 85 case E_USER_ERROR: 86 $t_error_type = "APPLICATION ERROR #$p_error"; 87 $t_error_description = error_string( $p_error ); 88 break; 89 case E_USER_WARNING: 90 $t_error_type = "APPLICATION WARNING #$p_error"; 91 $t_error_description = error_string( $p_error ); 92 break; 93 case E_USER_NOTICE: 94 # used for debugging 95 $t_error_type = 'DEBUG'; 96 $t_error_description = $p_error; 97 break; 98 default: 99 #shouldn't happen, just display the error just in case 100 $t_error_type = ''; 101 $t_error_description = $p_error; 102 } 103 104 $t_error_description = nl2br( $t_error_description ); 105 106 if ( 'halt' == $t_method ) { 107 $t_old_contents = ob_get_contents(); 108 # ob_end_clean() still seems to call the output handler which 109 # outputs the headers indicating compression. If we had 110 # PHP > 4.2.0 we could use ob_clean() instead but as it is 111 # we need to disable compression. 112 compress_disable(); 113 114 if ( ob_get_length() ) { 115 ob_end_clean(); 116 } 117 118 # don't send the page header information if it has already been sent 119 if ( $g_error_send_page_header ) { 120 html_page_top1(); 121 if ( $p_error != ERROR_DB_QUERY_FAILED ) { 122 html_page_top2(); 123 } else { 124 html_page_top2a(); 125 } 126 } 127 128 PRINT '<br /><div align="center"><table class="width50" cellspacing="1">'; 129 PRINT "<tr><td class=\"form-title\">$t_error_type</td></tr>"; 130 PRINT "<tr><td><p class=\"center\" style=\"color:red\">$t_error_description</p></td></tr>"; 131 132 PRINT '<tr><td><p class="center">'; 133 if ( null === $g_error_proceed_url ) { 134 PRINT lang_get( 'error_no_proceed' ); 135 } else { 136 PRINT "<a href=\"$g_error_proceed_url\">" . lang_get( 'proceed' ) . '</a>'; 137 } 138 PRINT '</p></td></tr>'; 139 140 if ( ON == config_get( 'show_detailed_errors' ) ) { 141 PRINT '<tr><td>'; 142 error_print_details( $p_file, $p_line, $p_context ); 143 PRINT '</td></tr>'; 144 PRINT '<tr><td>'; 145 error_print_stack_trace(); 146 PRINT '</td></tr>'; 147 } 148 PRINT '</table></div>'; 149 150 if ( $g_error_handled && !is_blank( $t_old_contents ) ) { 151 PRINT '<p>Previous non-fatal errors occurred. Page contents follow.</p>'; 152 153 PRINT '<div style="border: solid 1px black;padding: 4px">'; 154 PRINT $t_old_contents; 155 PRINT '</div>'; 156 } 157 158 if ( $p_error != ERROR_DB_QUERY_FAILED ) { 159 html_page_bottom1(); 160 } else { 161 html_body_end(); 162 html_end(); 163 } 164 exit(); 165 } else if ( 'inline' == $t_method ) { 166 PRINT "<p style=\"color:red\">$t_error_type: $t_error_description</p>"; 167 } else { 168 # do nothing 169 } 170 171 if ( $t_lang_pushed ) { 172 lang_pop(); 173 } 174 175 $g_error_parameters = array(); 176 $g_error_handled = true; 177 $g_error_proceed_url = null; 178 } 179 180 # --------------- 181 # Print out the error details including context 182 function error_print_details( $p_file, $p_line, $p_context ) { 183 ?> 184 <center> 185 <table class="width75"> 186 <tr> 187 <td>Full path: <?php PRINT string_html_entities( $p_file ) ?></td> 188 </tr> 189 <tr> 190 <td>Line: <?php PRINT $p_line ?></td> 191 </tr> 192 <tr> 193 <td> 194 <?php error_print_context( $p_context ) ?> 195 </td> 196 </tr> 197 </table> 198 </center> 199 <?php 200 } 201 202 # --------------- 203 # Print out the variable context given 204 function error_print_context( $p_context ) { 205 if( !is_array( $p_context ) ) { 206 return; 207 } 208 209 PRINT '<table class="width100"><tr><th>Variable</th><th>Value</th><th>Type</th></tr>'; 210 211 # print normal variables 212 foreach ( $p_context as $t_var => $t_val ) { 213 if ( !is_array( $t_val ) && !is_object( $t_val ) ) { 214 $t_val = string_html_entities( (string)$t_val ); 215 $t_type = gettype( $t_val ); 216 217 # Mask Passwords 218 if ( strpos( $t_var, 'password' ) !== false ) { 219 $t_val = '**********'; 220 } 221 222 PRINT "<tr><td>$t_var</td><td>$t_val</td><td>$t_type</td></tr>\n"; 223 } 224 } 225 226 # print arrays 227 foreach ( $p_context as $t_var => $t_val ) { 228 if ( is_array( $t_val ) && ( $t_var != 'GLOBALS' ) ) { 229 PRINT "<tr><td colspan=\"3\" align=\"left\"><br /><strong>$t_var</strong></td></tr>"; 230 PRINT "<tr><td colspan=\"3\">"; 231 error_print_context( $t_val ); 232 PRINT "</td></tr>"; 233 } 234 } 235 236 PRINT '</table>'; 237 } 238 239 # --------------- 240 # Print out a stack trace if PHP provides the facility or xdebug is present 241 function error_print_stack_trace() { 242 if ( extension_loaded( 'xdebug' ) ) { #check for xdebug presence 243 $t_stack = xdebug_get_function_stack(); 244 245 # reverse the array in a separate line of code so the 246 # array_reverse() call doesn't appear in the stack 247 $t_stack = array_reverse( $t_stack ); 248 array_shift( $t_stack ); #remove the call to this function from the stack trace 249 250 PRINT '<center><table class="width75">'; 251 252 foreach ( $t_stack as $t_frame ) { 253 PRINT '<tr ' . helper_alternate_class() . '>'; 254 PRINT '<td>' . string_html_entities( $t_frame['file'] ) . '</td><td>' . $t_frame['line'] . '</td><td>' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : '???' ) . '</td>'; 255 256 $t_args = array(); 257 if ( isset( $t_frame['params'] ) ) { 258 foreach( $t_frame['params'] as $t_value ) { 259 $t_args[] = error_build_parameter_string( $t_value ); 260 } 261 } 262 263 PRINT '<td>( ' . string_html_entities( implode( $t_args, ', ' ) ) . ' )</td></tr>'; 264 } 265 PRINT '</table></center>'; 266 } else { 267 $t_stack = debug_backtrace(); 268 269 array_shift( $t_stack ); #remove the call to this function from the stack trace 270 array_shift( $t_stack ); #remove the call to the error handler from the stack trace 271 272 PRINT '<center><table class="width75">'; 273 PRINT '<tr><th>Filename</th><th>Line</th><th>Function</th><th>Args</th></tr>'; 274 275 foreach ( $t_stack as $t_frame ) { 276 PRINT '<tr ' . helper_alternate_class() . '>'; 277 PRINT '<td>' . string_html_entities( $t_frame['file'] ) . '</td><td>' . (isset( $t_frame['line'] ) ? $t_frame['line'] : '-') . '</td><td>' . $t_frame['function'] . '</td>'; 278 279 $t_args = array(); 280 if ( isset( $t_frame['args'] ) ) { 281 foreach( $t_frame['args'] as $t_value ) { 282 $t_args[] = error_build_parameter_string( $t_value ); 283 } 284 } 285 286 PRINT '<td>( ' . string_html_entities( implode( $t_args, ', ' ) ) . ' )</td></tr>'; 287 } 288 289 PRINT '</table></center>'; 290 } 291 } 292 293 # --------------- 294 # Build a string describing the parameters to a function 295 function error_build_parameter_string( $p_param ) { 296 if ( is_array( $p_param ) ) { 297 $t_results = array(); 298 299 foreach ( $p_param as $t_key => $t_value ) { 300 $t_results[] = '[' . error_build_parameter_string( $t_key ) . ']' . 301 ' => ' . error_build_parameter_string( $t_value ); 302 } 303 304 return '{ ' . implode( $t_results, ', ' ) . ' }'; 305 } else if ( is_bool( $p_param ) ) { 306 if ( $p_param ) { 307 return 'true'; 308 } else { 309 return 'false'; 310 } 311 } else if ( is_float( $p_param ) || is_int( $p_param ) ) { 312 return $p_param; 313 } else if ( is_null( $p_param ) ) { 314 return 'null'; 315 } else if ( is_object( $p_param ) ) { 316 $t_results = array(); 317 318 $t_class_name = get_class( $p_param ); 319 $t_inst_vars = get_object_vars( $p_param ); 320 321 foreach ( $t_inst_vars as $t_name => $t_value ) { 322 $t_results[] = "[$t_name]" . 323 ' => ' . error_build_parameter_string( $t_value ); 324 } 325 326 return 'Object <$t_class_name> ( ' . implode( $t_results, ', ' ) . ' )'; 327 } else if ( is_string( $p_param ) ) { 328 return "'$p_param'"; 329 } 330 } 331 332 # --------------- 333 # Return an error string (in the current language) for the given error 334 function error_string( $p_error ) { 335 global $g_error_parameters; 336 337 $MANTIS_ERROR = lang_get( 'MANTIS_ERROR' ); 338 339 # We pad the parameter array to make sure that we don't get errors if 340 # the caller didn't give enough parameters for the error string 341 $t_padding = array_pad( array(), 10, '' ); 342 343 $t_error = $MANTIS_ERROR[$p_error]; 344 345 return string_html_specialchars( call_user_func_array( 'sprintf', array_merge( array( $t_error ), $g_error_parameters, $t_padding ) ) ); 346 } 347 348 # --------------- 349 # Check if we have handled an error during this page 350 # Return true if an error has been handled, false otherwise 351 function error_handled() { 352 global $g_error_handled; 353 354 return ( true == $g_error_handled ); 355 } 356 357 # --------------- 358 # Set additional info parameters to be used when displaying the next error 359 # This function takes a variable number of parameters 360 # 361 # When writing internationalized error strings, note that you can change the 362 # order of parameters in the string. See the PHP manual page for the 363 # sprintf() function for more details. 364 function error_parameters() { 365 global $g_error_parameters; 366 367 $g_error_parameters = func_get_args(); 368 } 369 370 # --------------- 371 # Set a url to give to the user to proceed after viewing the error 372 function error_proceed_url( $p_url ) { 373 global $g_error_proceed_url; 374 375 $g_error_proceed_url = $p_url; 376 } 377 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
|