1<?php 2/************************* 3 Coppermine Photo Gallery 4 ************************ 5 Copyright (c) 2003-2016 Coppermine Dev Team 6 v1.0 originally written by Gregory Demar 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License version 3 10 as published by the Free Software Foundation. 11 12 ******************************************** 13 Coppermine version: 1.6.03 14 $HeadURL$ 15**********************************************/ 16 17if (!defined('E_STRICT')) { 18 define('E_STRICT', 2048); // PHP 5 19} 20 21if (!defined('E_DEPRECATED')) { 22 define('E_DEPRECATED', 8192); // PHP 5.3 23} 24 25class cpg_debugger { 26 // Define variables that store the old error reporting and logging states 27 var $old_handler; 28 var $old_display_level; 29 var $old_error_logging; 30 var $old_error_log; 31 32 var $logfile; 33 var $report; 34 var $active = false; 35 var $error_level; 36 var $basepath_len; 37 38 function __construct($log = 'debug.log') { 39 $this->logfile = $log; 40 $this->basepath_len = strlen(dirname(dirname(__FILE__))); 41 } 42 43 function start() { 44 if (!$this->active) { 45 $this->report = false; 46 if (CAN_MOD_INI) { 47 $this->old_display_level = ini_set('display_errors', 1); 48 $this->old_error_logging = ini_set('log_errors', 0); 49 } 50 $phpver = explode('.', phpversion()); 51 $phpver = "$phpver[0]$phpver[1]"; 52 if ($phpver < 43) { 53 $this->old_handler = set_error_handler('cpg_error_handler'); 54 } else { 55 $this->old_handler = set_error_handler(array(&$this, 'handler')); 56 } 57 if (is_bool($this->old_handler)) { 58 error_reporting(E_ALL ^ E_NOTICE); 59 } 60// $this->old_error_log = ini_set('error_log', $this->logfile); 61 $this->error_level = E_ALL; 62 $this->active = true; 63 } 64 } 65 66 function stop() { 67 if ($this->active) { 68 // restore the previous state 69 if (!is_bool($this->old_handler) && $this->old_handler) { 70 set_error_handler($this->old_handler); 71 } 72 if (CAN_MOD_INI) { 73 ini_set('display_errors', $this->old_display_level); 74 ini_set('log_errors', $this->old_error_logging); 75// ini_set('error_log', $this->old_error_log); 76 } 77 $this->active = false; 78 return $this->report; 79 } 80 } 81 82 // user defined error handling function 83 function handler($errno, $errmsg, $filename, $linenum, $vars='') 84 { 85 $filename = substr($filename, $this->basepath_len); 86 $errortype = array ( 87// E_ERROR => 'Error', 88 E_WARNING => 'Warning', 89// E_PARSE => 'Parsing Error', 90 E_NOTICE => 'Notice', 91 E_CORE_ERROR => 'Core Error', 92 E_CORE_WARNING => 'Core Warning', 93 E_COMPILE_ERROR => 'Compile Error', 94 E_COMPILE_WARNING => 'Compile Warning', 95 E_USER_ERROR => 'CPG Error', 96 E_USER_WARNING => 'CPG Warning', 97 E_USER_NOTICE => 'CPG Notice', 98 E_STRICT => 'Runtime Notice', 99 E_DEPRECATED => 'Deprecated', 100 ); 101 // NOTE: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR and E_COMPILE_WARNING 102 // error levels will be handled as per the error_reporting settings. 103 if ($errno == E_USER_ERROR) { 104 if (USER_IS_ADMIN) { 105 $errmsg = $errortype[$errno]." $filename line $linenum: ".$errmsg; 106 } else { 107 $errmsg = "A error occured while processing this page.<br />Please report the following error to the owner of this website.<br /><br /><strong>$errmsg</strong>"; 108 } 109 cpg_die(CRITICAL_ERROR, $errmsg, $filename, $linenum); 110 } 111 112 // set of errors for which a var trace will be saved 113 if ($errno & $this->error_level) { 114 $this->report[$filename][] = $errortype[$errno]." line $linenum: ".$errmsg; 115 } 116 117 // save to the error log 118 // error_log($err, 0); //message is sent to PHP's system logger 119 // error_log($err, 1, 'operator@example.com'); //message is sent by email to the address in the destination 120 // error_log($err, 3, $this->logfile); //message is appended to the file destination. 121 } 122} 123 124function cpg_error_handler($errno, $errmsg, $filename, $linenum, $vars='') { 125 global $cpgdebugger; 126 $cpgdebugger->handler($errno, $errmsg, $filename, $linenum, $vars); 127} 128define('CAN_MOD_INI', strpos(ini_get('disable_functions'), 'ini_set') === FALSE); 129 130error_reporting(E_ALL); 131$cpgdebugger = new cpg_debugger(); 132$cpgdebugger->start(); 133//EOF