1 | <?php
|
---|
2 |
|
---|
3 | class ErrorHandler extends Module
|
---|
4 | {
|
---|
5 | function Init()
|
---|
6 | {
|
---|
7 | set_error_handler(array($this, 'Handle'));
|
---|
8 | }
|
---|
9 |
|
---|
10 | function Handle($Number, $Message, $Filename, $LineNumber, $Variables)
|
---|
11 | {
|
---|
12 | global $Config;
|
---|
13 |
|
---|
14 | $Date = date('Y-m-d H:i:s'); // časové razítko položky
|
---|
15 | $ErrorType = array
|
---|
16 | (
|
---|
17 | 1 => 'Error',
|
---|
18 | 2 => 'Warning',
|
---|
19 | 4 => 'Parsing Error',
|
---|
20 | 8 => 'Notice',
|
---|
21 | 16 => 'Core Error',
|
---|
22 | 32 => 'Core Warning',
|
---|
23 | 64 => 'Compile Error',
|
---|
24 | 128 => 'Compile Warning',
|
---|
25 | 256 => 'User Error',
|
---|
26 | 512 => 'User Warning',
|
---|
27 | 1024 => 'User Notice'
|
---|
28 | );
|
---|
29 | $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;
|
---|
30 |
|
---|
31 | if(($UserErrors & $Number))
|
---|
32 | {
|
---|
33 | $Error = '# '.$Date.' : '.$Message.' on line '.$LineNumber."\n";
|
---|
34 | $Backtrace = debug_backtrace();
|
---|
35 | $Backtrace[0]['function'] = '';
|
---|
36 | $Backtrace[0]['args'] = '';
|
---|
37 | $Backtrace[0]['file'] = '';
|
---|
38 | $Backtrace[0]['line'] = '';
|
---|
39 | //$First = array_shift($Backtrace);
|
---|
40 | //print_r($First);
|
---|
41 |
|
---|
42 | //array_unshift($Backtrace, $First);
|
---|
43 | //array_shift($Backtrace);
|
---|
44 | //print_r($Backtrace);
|
---|
45 | foreach($Backtrace as $Item)
|
---|
46 | {
|
---|
47 | $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];
|
---|
48 | $Arguments = '';
|
---|
49 | if(array_key_exists('args', $Item) and is_array($Item['args']))
|
---|
50 | foreach($Item['args'] as $Item)
|
---|
51 | {
|
---|
52 | if(is_array($Item)) $Arguments .= "'".serialize($Item)."',";
|
---|
53 | else $Arguments .= "'".$Item."',";
|
---|
54 | }
|
---|
55 | if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';
|
---|
56 | $Error .= "\n";
|
---|
57 |
|
---|
58 | }
|
---|
59 | $Error .= "\n";
|
---|
60 |
|
---|
61 | $this->System->Modules['Log']->NewRecord('Error', 'Log', $Error);
|
---|
62 |
|
---|
63 | //if($Config['Web']['ErrorLogFile'] != '')
|
---|
64 | //error_log($Error, 3, $Config['Web']['ErrorLogFile']);
|
---|
65 | // Pošli mi zprávu (pokud je to kritická chyba)
|
---|
66 | //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
|
---|
67 | // Show error message
|
---|
68 | if($Config['Web']['ShowPHPError'] == true)
|
---|
69 | {
|
---|
70 | echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
|
---|
71 | '<meta http-equiv="Content-Language" content="cs">'."\n".
|
---|
72 | '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"></head><body>'."\n".
|
---|
73 | 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
|
---|
74 | echo('<pre>'.$Error.'</pre><br/>'); // V případě ladění chybu i zobraz
|
---|
75 | echo('</body></html>');
|
---|
76 | }
|
---|
77 | if((E_ERROR | E_PARSE) & $Number) die();
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | ?>
|
---|