1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-04 20:27:40 +02:00

Core Improvements: Next Round #79 #80

This commit is contained in:
Awilum
2013-01-08 23:52:23 +02:00
parent 7552b2aee5
commit cb95f9cee2
6 changed files with 339 additions and 268 deletions

View File

@@ -39,7 +39,7 @@ class ErrorHandler
*/ */
protected static function highlightCode($file, $line, $padding = 6) protected static function highlightCode($file, $line, $padding = 6)
{ {
if (!is_readable($file)) { if ( ! is_readable($file)) {
return false; return false;
} }
@@ -47,7 +47,7 @@ class ErrorHandler
$lines = array(); $lines = array();
$currentLine = 0; $currentLine = 0;
while (!feof($handle)) { while ( ! feof($handle)) {
$currentLine++; $currentLine++;
$temp = fgets($handle); $temp = fgets($handle);
@@ -118,20 +118,23 @@ class ErrorHandler
return $backtrace; return $backtrace;
} }
// Remove unnecessary info from backtrace /**
* Remove unnecessary info from backtrace
*/
if ($backtrace[0]['function'] == '{closure}') { if ($backtrace[0]['function'] == '{closure}') {
unset($backtrace[0]); unset($backtrace[0]);
} }
// Format backtrace /**
* Format backtrace
*/
$trace = array(); $trace = array();
foreach ($backtrace as $entry) { foreach ($backtrace as $entry) {
// Function /**
* Function
*/
$function = ''; $function = '';
if (isset($entry['class'])) { if (isset($entry['class'])) {
@@ -140,8 +143,9 @@ class ErrorHandler
$function .= $entry['function'] . '()'; $function .= $entry['function'] . '()';
// Arguments /**
* Arguments
*/
$arguments = array(); $arguments = array();
if (isset($entry['args']) && count($entry['args']) > 0) { if (isset($entry['args']) && count($entry['args']) > 0) {
@@ -158,8 +162,9 @@ class ErrorHandler
} }
} }
// Location /**
* Location
*/
$location = array(); $location = array();
if (isset($entry['file'])) { if (isset($entry['file'])) {
@@ -168,8 +173,9 @@ class ErrorHandler
$location['code'] = static::highlightCode($entry['file'], $entry['line']); $location['code'] = static::highlightCode($entry['file'], $entry['line']);
} }
// Compile into array /**
* Compile into array
*/
$trace[] = array $trace[] = array
( (
'function' => $function, 'function' => $function,
@@ -265,7 +271,7 @@ class ErrorHandler
include 'Resources/Views/Errors/exception.php'; include 'Resources/Views/Errors/exception.php';
} else { } else {
Response::status(500); Response::status(500);
include 'Resources/Views/Errors/error.php'; include 'Resources/Views/Errors/production.php';
} }
} catch (Exception $e) { } catch (Exception $e) {
while(ob_get_level() > 0) ob_end_clean(); while(ob_get_level() > 0) ob_end_clean();

View File

@@ -4,206 +4,274 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Error</title> <title>Error</title>
<style type="text/css"> <style type="text/css">
* { margin: 0; padding: 0; } #gelato-error {
#gelato-error
{
background:#eee; background:#eee;
color:333; color:0;
width:95%; width:95%;
margin:20px auto; font-size:14px;
font-size: 14px;
font-family:Verdana, Arial, Helvetica, "Nimbus Sans", FreeSans, Malayalam, sans-serif; font-family:Verdana, Arial, Helvetica, "Nimbus Sans", FreeSans, Malayalam, sans-serif;
margin:20px auto;
}
#gelato-error pre {
font-family:"Andale Mono", "Courier New", Courier;
font-size:12px;
margin:0;
padding:0;
}
#gelato-error a {
color:#cc0a0a;
text-decoration:none;
}
#gelato-error .error {
background:#cc0a0a;
color:#fff;
font-size:24px;
font-weight:700;
padding:10px;
}
#gelato-error .body {
border:0 solid #ccc;
padding:10px;
}
#gelato-error .code {
background:#fff;
border:1px solid #ccc;
overflow:auto;
}
#gelato-error .heading {
background:#444;
color:#fff;
font-size:18px;
font-weight:700;
padding:10px;
}
#gelato-error .line {
background:#777;
color:#fff;
padding-left:4px;
padding-right:4px;
}
#gelato-error .highlighted {
background:#fceb71;
border-top:1px solid #ccc;
border-bottom:1px solid #ccc;
}
#gelato-error .backtrace {
background:#fff;
margin-bottom:10px;
border:1px solid #ccc;
padding:10px;
}
#gelato-error .backtrace ol {
padding-left:40px;
}
#gelato-error table {
border-spacing:0;
border-collapse:collapse;
border-color:#ddd;
border-style:solid;
border-width:0 0 1px 1px;
}
#gelato-error td {
font-size:14px;
background:#fff;
border-color:#ddd;
border-style:solid;
border-width:1px 1px 0 0;
margin:0;
padding:4px;
}
.pull-right {
float:right;
} }
#gelato-error pre {font-family:"Andale Mono", "Courier New", Courier;font-size:12px;margin:0px;padding:0px;}
#gelato-error a {color:#cc0a0a;text-decoration:none;}
#gelato-error .error {background:#cc0a0a;padding:10px;color:#fff;font-size:24px;font-weight:bold;}
#gelato-error .body {border:0px solid #ccc;padding:10px;}
#gelato-error .code {background:#fff;border:1px solid #ccc;overflow:auto;}
#gelato-error .heading {background:#444;padding:10px;color:#fff;font-size:18px;font-weight:bold;}
#gelato-error .line {background:#777;color:#fff;padding-left:4px;padding-right:4px;}
#gelato-error .highlighted {background:#fceb71;border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;}
#gelato-error .backtrace {background:#fff;padding:10px;margin-bottom:10px;border:1px solid #ccc;}
#gelato-error .backtrace ol {padding-left: 40px;}
#gelato-error table {border-spacing:0;border-collapse: collapse;border-color: #ddd;border-width: 0 0 1px 1px;border-style: solid;}
#gelato-error td {font-size:14px;background:#fff;border-color: #ddd;border-width: 1px 1px 0 0;border-style: solid;margin: 0;padding: 4px;}
.pull-right {float: right;}
</style> </style>
<body> <body>
<div id="gelato-error"> <div id="gelato-error">
<div class="error"> <div class="error">
<?php echo $error['type']; ?><?php if(isset($error['code'])): ?> <span style="color:#e1e1e1;padding:0px">[<?php echo $error['code']; ?>]</span><?php endif; ?> <?php echo $error['type']; ?><?php if(isset($error['code'])): ?> <span style="color:#e1e1e1;padding:0px">[<?php echo $error['code']; ?>]</span><?php endif; ?>
<span class="pull-right">Gelato</span> <span class="pull-right">Gelato</span>
</div> </div>
<div class="body"> <div class="body">
<strong>Message:</strong> <?php echo htmlspecialchars($error['message'], ENT_COMPAT, 'UTF-8', false); ?> <strong>Message:</strong> <?php echo htmlspecialchars($error['message'], ENT_COMPAT, 'UTF-8', false); ?>
<?php if(!empty($error['file'])): ?> <?php if(!empty($error['file'])): ?>
<br><br> <br><br>
<strong>Location:</strong> <?php echo $error['file']; ?> (line <?php echo $error['line']; ?>) <strong>Location:</strong> <?php echo $error['file']; ?> (line <?php echo $error['line']; ?>)
<?php endif; ?> <?php endif; ?>
<?php if(!empty($error['highlighted'])): ?> <?php if(!empty($error['highlighted'])): ?>
<br><br> <br><br>
<div class="code"> <div class="code">
<?php foreach($error['highlighted'] as $line): ?> <?php foreach($error['highlighted'] as $line): ?>
<pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre> <pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php if(!empty($error['backtrace'])): ?> <?php if(!empty($error['backtrace'])): ?>
<div class="heading"> <div class="heading">
Backtrace <a href="#" onclick="return toggle('backtrace', this);" style="float:right">+</a> Backtrace <a href="#" onclick="return toggle('backtrace', this);" style="float:right">+</a>
</div> </div>
<div class="body" style="display:none;" id="backtrace"> <div class="body" style="display:none;" id="backtrace">
<?php foreach($error['backtrace'] as $trace): ?> <?php foreach($error['backtrace'] as $trace): ?>
<div class="backtrace"> <div class="backtrace">
<p><strong>Function:</strong> <?php echo $trace['function']; ?></p> <p><strong>Function:</strong> <?php echo $trace['function']; ?></p>
<?php if(!empty($trace['arguments'])): $id = md5(uniqid('', true)); ?> <?php if(!empty($trace['arguments'])): $id = md5(uniqid('', true)); ?>
<p><strong>Arguments: [<a href="#" onclick="return toggle('<?php echo $id; ?>', this);">+</a>]</strong></p> <p><strong>Arguments: [<a href="#" onclick="return toggle('<?php echo $id; ?>', this);">+</a>]</strong></p>
<div style="display:none" id="<?php echo $id; ?>"> <div style="display:none" id="<?php echo $id; ?>">
<ol> <ol>
<?php foreach($trace['arguments'] as $arg): ?> <?php foreach($trace['arguments'] as $arg): ?>
<li><pre><?php echo $arg; ?></pre></li> <li><pre><?php echo $arg; ?></pre></li>
<?php endforeach; ?> <?php endforeach; ?>
</ol> </ol>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($trace['location'])): $id = md5(uniqid('', true)); ?> <?php if(!empty($trace['location'])): $id = md5(uniqid('', true)); ?>
<p><strong>Location:</strong> <?php echo $trace['location']['file']; ?> (<a href="#" onclick="return toggle('<?php echo $id; ?>');">line <?php echo $trace['location']['line']; ?></a>)</p> <p><strong>Location:</strong> <?php echo $trace['location']['file']; ?> (<a href="#" onclick="return toggle('<?php echo $id; ?>');">line <?php echo $trace['location']['line']; ?></a>)</p>
<div class="code" style="display:none" id="<?php echo $id; ?>"> <div class="code" style="display:none" id="<?php echo $id; ?>">
<?php foreach($trace['location']['code'] as $line): ?> <?php foreach($trace['location']['code'] as $line): ?>
<pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre> <pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="heading"> <div class="heading">
Superglobals <a href="#" onclick="return toggle('superglobals', this);" style="float:right">+</a> Superglobals <a href="#" onclick="return toggle('superglobals', this);" style="float:right">+</a>
</div> </div>
<div class="body" style="display:none;" id="superglobals"> <div class="body" style="display:none;" id="superglobals">
<?php if(!empty($_SERVER)): ?> <?php if(!empty($_SERVER)): ?>
<p><b>$_SERVER [<a href="#" onclick="return toggle('_server', this);">+</a>]</b></p> <p><b>$_SERVER [<a href="#" onclick="return toggle('_server', this);">+</a>]</b></p>
<div id="_server" style="display:none"> <div id="_server" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_SERVER as $k => $v): ?> <?php foreach($_SERVER as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_GET)): ?> <?php if(!empty($_GET)): ?>
<p><b>$_GET [<a href="#" onclick="return toggle('_get', this);">+</a>]</b></p> <p><b>$_GET [<a href="#" onclick="return toggle('_get', this);">+</a>]</b></p>
<div id="_get" style="display:none"> <div id="_get" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_GET as $k => $v): ?> <?php foreach($_GET as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_POST)): ?> <?php if(!empty($_POST)): ?>
<p><b>$_POST [<a href="#" onclick="return toggle('_post', this);">+</a>]</b></p> <p><b>$_POST [<a href="#" onclick="return toggle('_post', this);">+</a>]</b></p>
<div id="_post" style="display:none"> <div id="_post" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_POST as $k => $v): ?> <?php foreach($_POST as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_FILES)): ?> <?php if(!empty($_FILES)): ?>
<p><b>$_FILES [<a href="#" onclick="return toggle('_files', this);">+</a>]</b></p> <p><b>$_FILES [<a href="#" onclick="return toggle('_files', this);">+</a>]</b></p>
<div id="_files" style="display:none"> <div id="_files" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_FILES as $k => $v): ?> <?php foreach($_FILES as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_COOKIE)): ?> <?php if(!empty($_COOKIE)): ?>
<p><b>$_COOKIE [<a href="#" onclick="return toggle('_cookie', this);">+</a>]</b></p> <p><b>$_COOKIE [<a href="#" onclick="return toggle('_cookie', this);">+</a>]</b></p>
<div id="_cookie" style="display:none"> <div id="_cookie" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_COOKIE as $k => $v): ?> <?php foreach($_COOKIE as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></td> <td width="85%"><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_SESSION)): ?> <?php if(!empty($_SESSION)): ?>
<p><b>$_SESSION [<a href="#" onclick="return toggle('_session', this);">+</a>]</b></p> <p><b>$_SESSION [<a href="#" onclick="return toggle('_session', this);">+</a>]</b></p>
<div id="_session" style="display:none"> <div id="_session" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_SESSION as $k => $v): ?> <?php foreach($_SESSION as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($_ENV)): ?> <?php if(!empty($_ENV)): ?>
<p><b>$_ENV [<a href="#" onclick="return toggle('_env', this);">+</a>]</b></p> <p><b>$_ENV [<a href="#" onclick="return toggle('_env', this);">+</a>]</b></p>
<div id="_env" style="display:none"> <div id="_env" style="display:none">
<table width="100%"> <table width="100%">
<?php foreach($_ENV as $k => $v): ?> <?php foreach($_ENV as $k => $v): ?>
<tr> <tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td> <td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td> <td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="heading">
Included Files <a href="#" onclick="return toggle('files', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="files">
<table width="100%">
<?php foreach(get_included_files() as $k => $v): ?>
<tr>
<td width="5%"><?php echo $k + 1; ?></td>
<td width="95%"><?php echo $v; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div style="padding-top:20px;padding-bottom:20px; padding-left:10px;"><a href="http://gelato.monstra.org">Gelato Library</a></div>
<div class="heading">
Included Files <a href="#" onclick="return toggle('files', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="files">
<table width="100%">
<?php foreach(get_included_files() as $k => $v): ?>
<tr>
<td width="5%"><?php echo $k + 1; ?></td>
<td width="95%"><?php echo $v; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div style="padding-top:20px;padding-bottom:20px; padding-left:10px;"><a href="http://gelato.monstra.org">Gelato Library</a></div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
@@ -215,13 +283,11 @@ function toggle(id, link)
if (link != null) { if (link != null) {
link.innerHTML = '-'; link.innerHTML = '-';
} }
div.style.display = "block"; div.style.display = "block";
} else { } else {
if (link != null) { if (link != null) {
link.innerHTML = '+'; link.innerHTML = '+';
} }
div.style.display = "none"; div.style.display = "none";
} }

View File

@@ -5,47 +5,47 @@
<title>Error</title> <title>Error</title>
<style type="text/css"> <style type="text/css">
body { body {
height:100%; height:100%;
background:#eee; background:#eee;
padding:0px; padding:0px;
margin:0px; margin:0px;
height: 100%; height: 100%;
font-size: 100%; font-size: 100%;
color:#333; color:#333;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 100%; line-height: 100%;
} }
a { a {
color:#0088cc; color:#0088cc;
text-decoration:none; text-decoration:none;
} }
a:hover { a:hover {
color:#005580; color:#005580;
text-decoration:underline; text-decoration:underline;
} }
h1 { h1 {
font-size: 4em; font-size: 4em;
} }
small { small {
font-size: 0.7em; font-size: 0.7em;
color: #999; color: #999;
font-weight: normal; font-weight: normal;
} }
hr { hr {
border:0px; border:0px;
border-bottom:1px #ddd solid; border-bottom:1px #ddd solid;
} }
#message { #message {
width: 700px; width: 700px;
margin: 15% auto; margin: 15% auto;
} }
</style> </style>
</head> </head>
<body> <body>
<div id="message"> <div id="message">
<h1>Error</h1> <h1>Error</h1>
<hr> <hr>
<p>Aw, snap! An error has occurred while processing your request.</p> <p>Aw, snap! An error has occurred while processing your request.</p>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -1,13 +1,13 @@
<?php <?php
// Add plugin navigation link // Add plugin navigation link
Navigation::add(__('Information', 'information'), 'system', 'information', 5); Navigation::add(__('Information', 'information'), 'system', 'information', 5);
/** /**
* Information Admin Class * Information Admin Class
*/ */
class InformationAdmin extends Backend class InformationAdmin extends Backend
{ {
/** /**
* Information main function * Information main function
*/ */
@@ -25,4 +25,4 @@
->display(); ->display();
} }
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
/** /**
* Information plugin * Information plugin
* *
* @package Monstra * @package Monstra
@@ -11,8 +11,8 @@
* *
*/ */
// Register plugin // Register plugin
Plugin::register( __FILE__, Plugin::register( __FILE__,
__('Information', 'information'), __('Information', 'information'),
__('Information plugin', 'information'), __('Information plugin', 'information'),
'1.0.0', '1.0.0',
@@ -21,9 +21,9 @@
null, null,
'box'); 'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) { if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
// Include Information Admin // Include Information Admin
Plugin::Admin('information', 'box'); Plugin::Admin('information', 'box');
} }

View File

@@ -54,5 +54,4 @@ class Menu
->display(); ->display();
} }
} }