Update of /cvsroot/mxbb/mx_music/phpbb2/mx_mod/mx_shared/ErrorHandler In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19367/mx_mod/mx_shared/ErrorHandler Added Files: Handler.php error.tpl example1.html example2.html index.htm prepend.php readme.txt showSource.php Log Message: upgrade --- NEW FILE: prepend.php --- <?php include_once dirname(__FILE__) . '/Handler.php'; $__ErrorHandler = new ErrorHandler; set_error_handler(array(&$__ErrorHandler, 'raiseError')); ?> --- NEW FILE: showSource.php --- <?php /** * @project mygosuLib * @package ErrorHandler * @version 2.0.0 * @license BSD * @copyright (c) 2003,2004 Cezary Tomczak * @link http://gosu.pl/software/mygosulib.html */ $file = @$_GET['file']; $line = @$_GET['line']; $prev = @$_GET['prev'] ? $_GET['prev'] : 10; $next = @$_GET['next'] ? $_GET['next'] : 10; showSource($file, $line, $prev, $next); /** * Show source part of the file * @param string $file Filename * @param int $line Line to read * @param int $prev How many lines before main line to read * @param int $next How many lines after main line to read * @return string * @access public * @package ErrorHandler */ function showSource($file, $line, $prev = 10, $next = 10) { if (!(file_exists($file) && is_file($file))) { return trigger_error("showSource() failed, file does not exist `$file`", E_USER_ERROR); return false; } //read code ob_start(); highlight_file($file); $data = ob_get_contents(); ob_end_clean(); //seperate lines $data = explode('<br />', $data); $count = count($data) - 1; //count which lines to display $start = $line - $prev; if ($start < 1) { $start = 1; } $end = $line + $next; if ($end > $count) { $end = $count + 1; } //color for numbering lines $highlight_default = ini_get('highlight.default'); //displaying echo '<table cellspacing="0" cellpadding="0"><tr>'; echo '<td style="vertical-align: top;"><code style="background-color: #FFFFCC; color: #666666;">'; for ($x = $start; $x <= $end; $x++) { echo '<a name="'.$x.'"></a>'; echo ($line == $x ? '<font style="background-color: red; color: white;">' : ''); echo str_repeat(' ', (strlen($end) - strlen($x)) + 1); echo $x; echo ' '; echo ($line == $x ? '</font>' : ''); echo '<br />'; } echo '</code></td><td style="vertical-align: top;"><code>'; while ($start <= $end) { echo ' ' . $data[$start - 1] . '<br />'; ++$start; } echo '</code></td>'; echo '</tr></table>'; if ($prev != 10000 || $next != 10000) { echo '<br>'; echo '<a style="font-family: tahoma; font-size: 12px;" href="'.@$_SERVER['PHP_SELF'].'?file='.urlencode($file).'&line='.$line.'&prev=10000&next=10000#'.($line - 15).'">View Full Source</a>'; } } ?> --- NEW FILE: example1.html --- <script type="text/javascript"> function showParam(i) { currentParam = i; document.getElementById('paramHide').style.display = '' document.getElementById('paramSpace').style.display = '' document.getElementById('param').style.display = '' document.getElementById('param').innerHTML = '<pre>' + document.getElementById('param' + i).innerHTML + '</pre>' } function hideParam() { currentParam = -1; document.getElementById('paramHide').style.display = 'none' document.getElementById('paramSpace').style.display = 'none' document.getElementById('param').style.display = 'none' } function showOrHideParam(i) { if (currentParam == i) { hideParam() } else { showParam(i) } } function showFile(id) { eval('display = document.getElementById("file' + id + '").style.display') eval('if (display == "none") { document.getElementById("file' + id + '").style.display = "" } else { document.getElementById("file' + id + '").style.display = "none" } '); } function showDetails(cnt) { for (i = 0; i < cnt; ++i) { eval('document.getElementById("file' + i + '").style.display = ""') } } function hideDetails(cnt) { for (i = 0; i < cnt; ++i) { eval('document.getElementById("file' + i + '").style.display = "none"') } } var currentParam = -1; </script> <pre> <hr /> <b>Error type:</b> Php Notice <b>Message:</b> Undefined variable: show_error <span style="font-family: monospaced; font-size: 11px;">Trace: 7</span> <span style="font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="showDetails(7)">[show details]</span> <span style="font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="hideDetails(7)">[hide details]</span> <ul><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(0)">_query</span> () <span id="file0" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDb%5CMysql%5CMysql.php&line=70&prev=10&next=10">Mysql.php</a> LINE: <font color="#007700">70</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\includes\Db\Mysql</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(1)">dbmysql._query</span> (<span style="cursor: pointer; color: #404040;" onclick="showOrHideParam(2)" onmouseout="this.style.color='#404040'" onmouseover="this.style.color='#dd0000'">string[85]</span><span id="param2" style="display: none;"> SELECT * FROM cat WHERE id_cat = 22 </span>) <span id="file1" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDb%5CSql%5CSql.php&line=79&prev=10&next=10">Sql.php</a> LINE: <font color="#007700">79</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\includes\Db\Sql</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(2)">dbmysql.query</span> (<span style="cursor: pointer; color: #404040;" onclick="showOrHideParam(4)" onmouseout="this.style.color='#404040'" onmouseover="this.style.color='#dd0000'">string[85]</span><span id="param4" style="display: none;"> SELECT * FROM cat WHERE id_cat = 22 </span>) <span id="file2" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDb%5CSql%5CSql.php&line=271&prev=10&next=10">Sql.php</a> LINE: <font color="#007700">271</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\includes\Db\Sql</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(3)">dbmysql.execute</span> (<span style="cursor: pointer; color: #404040;" onclick="showOrHideParam(6)" onmouseout="this.style.color='#404040'" onmouseover="this.style.color='#dd0000'">string[84]</span><span id="param6" style="display: none;"> SELECT * FROM cat WHERE id_cat = ? </span>, <span style="cursor: pointer; color: #404040;" onclick="showOrHideParam(7)" onmouseout="this.style.color='#404040'" onmouseover="this.style.color='#dd0000'">array[1]</span><span id="param7" style="display: none;">Array ( [0] => 22 ) </span>) <span id="file3" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDb%5CSql%5CSql.php&line=402&prev=10&next=10">Sql.php</a> LINE: <font color="#007700">402</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\includes\Db\Sql</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(4)">dbmysql.getrow</span> (<span style="cursor: pointer; color: #404040;" onclick="showOrHideParam(9)" onmouseout="this.style.color='#404040'" onmouseover="this.style.color='#dd0000'">string[84]</span><span id="param9" style="display: none;"> SELECT * FROM cat WHERE id_cat = ? </span>, <span style="cursor: pointer; color: #800080;" onclick="showOrHideParam(10)" onmouseout="this.style.color='#800080'" onmouseover="this.style.color='#dd0000'">22</span><span id="param10" style="display: none;">22</span>) <span id="file4" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDao.php&line=129&prev=10&next=10">Dao.php</a> LINE: <font color="#007700">129</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\includes</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(5)">catdao.find</span> (<span style="cursor: pointer; color: #800080;" onclick="showOrHideParam(12)" onmouseout="this.style.color='#800080'" onmouseover="this.style.color='#dd0000'">22</span><span id="param12" style="display: none;">22</span>) <span id="file5" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cadmin%5Cincludes%5Ccheck_id_cat.php&line=14&prev=10&next=10">check_id_cat.php</a> LINE: <font color="#007700">14</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\admin\includes</font></span></li><li style="list-style-type: square;"><span onmouseover="this.style.color='#0000ff'" onmouseout="this.style.color='#0000A0'" style="color: #0000A0; cursor: pointer;" onclick="showFile(6)">check_id_cat</span> (<span style="cursor: pointer; color: #800080;" onclick="showOrHideParam(14)" onmouseout="this.style.color='#800080'" onmouseover="this.style.color='#dd0000'">22</span><span id="param14" style="display: none;">22</span>) <span id="file6" style="display: none; color: gray;">FILE: <a onmouseout="this.style.color='#007700'" onmouseover="this.style.color='#FF6600'" style="color: #007700; text-decoration: none;" target="_blank" href="http://127.0.0.1/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cadmin%5Cmanage%5Cindex.php&line=21&prev=10&next=10">index.php</a> LINE: <font color="#007700">21</font> DIR: <font color="#007700">d:\public_html\mygosudoc\www\admin\manage</font></span></li></ul> <span id="paramHide" style="display: none; font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="hideParam()">[hide param]</span><span id="paramSpace" style="display: none;"> </span><div id="param" perm="0" style="background-color: #FFFFE1; padding: 2px; display: none;"></div><hr /> Trick: click on a function's argument to see it fully Trick: click on a function to see the file & line Trick: click on the file name to see the source code </pre> --- NEW FILE: readme.txt --- INSTALL ------- Edit "error.tpl" and change variable $showSourceUri (path to "showSource.php") Include "prepend.php" at the beginning of your script. FILES ----- example1.html - example of displaying an error example2.html - example of displaying source of the file where the error appeared Handler.php - ErrorHandler class showSource.php - show source of the file, highlights the line where the error appeared error.tpl - template for displaying errors --- NEW FILE: error.tpl --- <?php $showSourceUri = 'http://localhost/modules/ErrorHandler/showSource.php'; $showSourcePrev = 10; $showSourceNext = 10; ?> <script type="text/javascript"> function showParam(i) { currentParam = i; document.getElementById('paramHide').style.display = '' document.getElementById('paramSpace').style.display = '' document.getElementById('param').style.display = '' document.getElementById('param').innerHTML = '<pre>' + document.getElementById('param' + i).innerHTML + '</pre>' } function hideParam() { currentParam = -1; document.getElementById('paramHide').style.display = 'none' document.getElementById('paramSpace').style.display = 'none' document.getElementById('param').style.display = 'none' } function showOrHideParam(i) { if (currentParam == i) { hideParam() } else { showParam(i) } } function showFile(id) { eval('display = document.getElementById("file' + id + '").style.display') eval('if (display == "none") { document.getElementById("file' + id + '").style.display = "" } else { document.getElementById("file' + id + '").style.display = "none" } '); } function showDetails(cnt) { for (i = 0; i < cnt; ++i) { eval('document.getElementById("file' + i + '").style.display = ""') } } function hideDetails(cnt) { for (i = 0; i < cnt; ++i) { eval('document.getElementById("file' + i + '").style.display = "none"') } } var currentParam = -1; </script> <pre> <hr /> <b>Error type:</b> <?php echo $errType[$errNo]; ?> <?php function fontStart($color) { return '<font color="' . $color . '">'; } function fontEnd() { return '</font>'; } $c['default'] = '#000000'; $c['keyword'] = '#0000A0'; $c['number'] = '#800080'; $c['string'] = '#404040'; $c['comment'] = '#808080'; if (count($info)) { foreach ($info as $k => $v) { echo '<b>'; echo $k; echo ':</b> '; echo $v; echo "\r\n"; } } else { echo '<b>Message:</b> '; echo $errMsg; echo "\r\n"; } echo "\r\n"; if (count($trace)) { echo '<span style="font-family: monospaced; font-size: 11px;">Trace: ' . count($trace) . "</span> "; echo '<span style="font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="showDetails('.count($trace).')">[show details]</span> '; echo '<span style="font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="hideDetails('.count($trace).')">[hide details]</span>'; echo "\r\n"; echo "\r\n"; echo '<ul>'; $currentParam = -1; foreach ($trace as $k => $v) { $currentParam++; echo '<li style="list-style-type: square;">'; if (isset($v['class'])) { echo '<span onmouseover="this.style.color=\'#0000ff\'" onmouseout="this.style.color=\''.$c['keyword'].'\'" style="color: '.$c['keyword'].'; cursor: pointer;" onclick="showFile('.$k.')">'; echo $v['class']; echo "."; } else { echo '<span onmouseover="this.style.color=\'#0000ff\'" onmouseout="this.style.color=\''.$c['keyword'].'\'" style="color: '.$c['keyword'].'; cursor: pointer;" onclick="showFile('.$k.')">'; } echo $v['function']; echo '</span>'; echo " ("; $sep = ''; $v['args'] = (array) @$v['args']; foreach ($v['args'] as $arg) { $currentParam++; echo $sep; $sep = ', '; $color = '#404040'; switch (true) { case is_bool($arg): $param = 'TRUE'; $string = $param; break; case is_int($arg): case is_float($arg): $param = $arg; $string = $arg; $color = $c['number']; break; case is_null($arg): $param = 'NULL'; $string = $param; break; case is_string($arg): $param = $arg; $string = 'string[' . strlen($arg) . ']'; break; case is_array($arg): ob_start(); print_r($arg); $param = ob_get_contents(); ob_end_clean(); $string = 'array[' . count($arg) . ']'; break; case is_object($arg): ob_start(); print_r($arg); $param = ob_get_contents(); ob_end_clean(); $string = 'object: ' . get_class($arg); break; case is_resource($arg): $param = 'resource: ' . get_resource_type($arg); $string = 'resource'; break; default: $param = 'unknown'; $string = $param; break; } echo '<span style="cursor: pointer; color: '.$color.';" onclick="showOrHideParam('.$currentParam.')" onmouseout="this.style.color=\''.$color.'\'" onmouseover="this.style.color=\'#dd0000\'">'; echo $string; echo '</span>'; echo '<span id="param'.$currentParam.'" style="display: none;">' . $param . '</span>'; } echo ")"; echo "\r\n"; if (!isset($v['file'])) { $v['file'] = 'unknown'; } if (!isset($v['line'])) { $v['line'] = 'unknown'; } $v['line'] = @$v['line']; echo '<span id="file'.$k.'" style="display: none; color: gray;">'; if ($v['file'] && $v['line']) { echo 'FILE: <a onmouseout="this.style.color=\'#007700\'" onmouseover="this.style.color=\'#FF6600\'" style="color: #007700; text-decoration: none;" target="_blank" href="'.$showSourceUri.'?file='.urlencode($v['file']).'&line='.$v['line'].'&prev='.$showSourcePrev.'&next='.$showSourceNext.'">'.basename($v['file']).'</a>'; } else { echo 'FILE: ' . fontStart('#007700') . basename($v['file']) . fontEnd(); } echo "\r\n"; echo 'LINE: ' . fontStart('#007700') . $v['line'] . fontEnd() . "\r\n"; echo 'DIR: ' . fontStart('#007700') . dirname($v['file']) . fontEnd(); echo '</span>'; echo '</li>'; } echo '</ul>'; } else { echo '<b>File:</b> '; echo basename($file); echo ' (' . $line . ') '; echo dirname($file); } ?> <?php echo '<span id="paramHide" style="display: none; font-family: monospaced; font-size: 11px; cursor: pointer;" onclick="hideParam()">[hide param]</span>';?> <span id="paramSpace" style="display: none;"> </span><div id="param" perm="0" style="background-color: #FFFFE1; padding: 2px; display: none;"></div><hr /> Trick: click on a function's argument to see it fully Trick: click on a function to see the file & line Trick: click on the file name to see the source code </pre> --- NEW FILE: example2.html --- <table cellspacing="0" cellpadding="0"><tr><td style="vertical-align: top;"><code style="background-color: #FFFFCC; color: #666666;"><a name="60"></a> 60 <br /><a name="61"></a> 61 <br /><a name="62"></a> 62 <br /><a name="63"></a> 63 <br /><a name="64"></a> 64 <br /><a name="65"></a> 65 <br /><a name="66"></a> 66 <br /><a name="67"></a> 67 <br /><a name="68"></a> 68 <br /><a name="69"></a> 69 <br /><a name="70"></a><font style="background-color: red; color: white;"> 70 </font><br /><a name="71"></a> 71 <br /><a name="72"></a> 72 <br /><a name="73"></a> 73 <br /><a name="74"></a> 74 <br /><a name="75"></a> 75 <br /><a name="76"></a> 76 <br /><a name="77"></a> 77 <br /><a name="78"></a> 78 <br /><a name="79"></a> 79 <br /><a name="80"></a> 80 <br /></code></td><td style="vertical-align: top;"><code> </font><font color="#007700">function </font><font color="#0000BB">_disconnect</font><font color="#007700">() { <br /> return @</font><font color="#0000BB">mysql_close</font><font color="#007700">(</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">connectId</font><font color="#007700">); <br /> } <br /> <br /> </font><font color="#FF8000">/** <br /> * @param string $query <br /> * @return resource|true|false Example: resource on SELECT, true on DELETE, false on error <br /> * @access protected <br /> */ <br /> </font><font color="#007700">function </font><font color="#0000BB">_query</font><font color="#007700">(&</font><font color="#0000BB">$query</font><font color="#007700">) { <br /> echo </font><font color="#0000BB">$show_error</font><font color="#007700">; <br /> return @</font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">, </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">connectId</font><font color="#007700">); <br /> } <br /> <br /> </font><font color="#FF8000">/** <br /> * Modify limit query <br /> * @param string $query <br /> * @param int $offset <br /> * @param int $limit <br /> * @return string <br /> * @access public <br /></code></td></tr></table><br><a style="font-family: tahoma; font-size: 12px;" href="/dev/showSource.php?file=d%3A%5Cpublic_html%5Cmygosudoc%5Cwww%5Cincludes%5CDb%5CMysql%5CMysql.php&line=70&prev=10000&next=10000#55">View Full Source</a> --- NEW FILE: index.htm --- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> --- NEW FILE: Handler.php --- <?php /** * @project mygosuLib * @package ErrorHandler * @version 2.0.1 * @license BSD * @copyright (c) 2003,2004 Cezary Tomczak * @link http://gosu.pl/software/mygosulib.html */ define('ERROR_HANDLER_ROOT', dirname(__FILE__)); /** * @access public * @package ErrorHandler */ class ErrorHandler { /** * Constructor * @access public */ function ErrorHandler() { ini_set('docref_root', null); ini_set('docref_ext', null); } /** * @param int $errNo * @param string $errMsg * @param string $file * @param int $line * @return void * @access public */ function raiseError($errNo, $errMsg, $file, $line) { global $mx_user; if (! ($errNo & error_reporting())) { return; } while (ob_get_level()) { ob_end_clean(); } $errType = array ( 1 => "Php Error", 2 => "Php Warning", 4 => "Parsing Error", 8 => "Php Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "Php User Error", 512 => "Php User Warning", 1024 => "Php User Notice" ); $info = array(); if (($errNo & E_USER_ERROR) && is_array($arr = @unserialize($errMsg))) { foreach ($arr as $k => $v) { $info[$k] = $v; } } $trace = array(); if (function_exists('debug_backtrace')) { $trace = debug_backtrace(); array_shift($trace); } include ERROR_HANDLER_ROOT . '/error.tpl'; exit; } } ?> |