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

View File

@@ -4,206 +4,274 @@
<meta charset="utf-8">
<title>Error</title>
<style type="text/css">
* { margin: 0; padding: 0; }
#gelato-error
{
#gelato-error {
background:#eee;
color:333;
color:0;
width:95%;
margin:20px auto;
font-size: 14px;
font-size:14px;
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>
<body>
<div id="gelato-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; ?>
<span class="pull-right">Gelato</span>
</div>
<div class="body">
<strong>Message:</strong> <?php echo htmlspecialchars($error['message'], ENT_COMPAT, 'UTF-8', false); ?>
<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; ?>
<span class="pull-right">Gelato</span>
</div>
<div class="body">
<strong>Message:</strong> <?php echo htmlspecialchars($error['message'], ENT_COMPAT, 'UTF-8', false); ?>
<?php if(!empty($error['file'])): ?>
<br><br>
<strong>Location:</strong> <?php echo $error['file']; ?> (line <?php echo $error['line']; ?>)
<?php endif; ?>
<?php if(!empty($error['file'])): ?>
<br><br>
<strong>Location:</strong> <?php echo $error['file']; ?> (line <?php echo $error['line']; ?>)
<?php endif; ?>
<?php if(!empty($error['highlighted'])): ?>
<br><br>
<div class="code">
<?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>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php if(!empty($error['highlighted'])): ?>
<br><br>
<div class="code">
<?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>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php if(!empty($error['backtrace'])): ?>
<div class="heading">
Backtrace <a href="#" onclick="return toggle('backtrace', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="backtrace">
<?php foreach($error['backtrace'] as $trace): ?>
<div class="backtrace">
<p><strong>Function:</strong> <?php echo $trace['function']; ?></p>
<?php if(!empty($trace['arguments'])): $id = md5(uniqid('', true)); ?>
<p><strong>Arguments: [<a href="#" onclick="return toggle('<?php echo $id; ?>', this);">+</a>]</strong></p>
<div style="display:none" id="<?php echo $id; ?>">
<ol>
<?php foreach($trace['arguments'] as $arg): ?>
<li><pre><?php echo $arg; ?></pre></li>
<?php endforeach; ?>
</ol>
</div>
<?php endif; ?>
<?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>
<div class="code" style="display:none" id="<?php echo $id; ?>">
<?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>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if(!empty($error['backtrace'])): ?>
<div class="heading">
Backtrace <a href="#" onclick="return toggle('backtrace', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="backtrace">
<?php foreach($error['backtrace'] as $trace): ?>
<div class="backtrace">
<p><strong>Function:</strong> <?php echo $trace['function']; ?></p>
<?php if(!empty($trace['arguments'])): $id = md5(uniqid('', true)); ?>
<p><strong>Arguments: [<a href="#" onclick="return toggle('<?php echo $id; ?>', this);">+</a>]</strong></p>
<div style="display:none" id="<?php echo $id; ?>">
<ol>
<?php foreach($trace['arguments'] as $arg): ?>
<li><pre><?php echo $arg; ?></pre></li>
<?php endforeach; ?>
</ol>
</div>
<?php endif; ?>
<?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>
<div class="code" style="display:none" id="<?php echo $id; ?>">
<?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>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="heading">
Superglobals <a href="#" onclick="return toggle('superglobals', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="superglobals">
<div class="heading">
Superglobals <a href="#" onclick="return toggle('superglobals', this);" style="float:right">+</a>
</div>
<div class="body" style="display:none;" id="superglobals">
<?php if(!empty($_SERVER)): ?>
<p><b>$_SERVER [<a href="#" onclick="return toggle('_server', this);">+</a>]</b></p>
<div id="_server" style="display:none">
<table width="100%">
<?php foreach($_SERVER as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_SERVER)): ?>
<p><b>$_SERVER [<a href="#" onclick="return toggle('_server', this);">+</a>]</b></p>
<div id="_server" style="display:none">
<table width="100%">
<?php foreach($_SERVER as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_GET)): ?>
<p><b>$_GET [<a href="#" onclick="return toggle('_get', this);">+</a>]</b></p>
<div id="_get" style="display:none">
<table width="100%">
<?php foreach($_GET as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_GET)): ?>
<p><b>$_GET [<a href="#" onclick="return toggle('_get', this);">+</a>]</b></p>
<div id="_get" style="display:none">
<table width="100%">
<?php foreach($_GET as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_POST)): ?>
<p><b>$_POST [<a href="#" onclick="return toggle('_post', this);">+</a>]</b></p>
<div id="_post" style="display:none">
<table width="100%">
<?php foreach($_POST as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_POST)): ?>
<p><b>$_POST [<a href="#" onclick="return toggle('_post', this);">+</a>]</b></p>
<div id="_post" style="display:none">
<table width="100%">
<?php foreach($_POST as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_FILES)): ?>
<p><b>$_FILES [<a href="#" onclick="return toggle('_files', this);">+</a>]</b></p>
<div id="_files" style="display:none">
<table width="100%">
<?php foreach($_FILES as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_FILES)): ?>
<p><b>$_FILES [<a href="#" onclick="return toggle('_files', this);">+</a>]</b></p>
<div id="_files" style="display:none">
<table width="100%">
<?php foreach($_FILES as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_COOKIE)): ?>
<p><b>$_COOKIE [<a href="#" onclick="return toggle('_cookie', this);">+</a>]</b></p>
<div id="_cookie" style="display:none">
<table width="100%">
<?php foreach($_COOKIE as $k => $v): ?>
<tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_COOKIE)): ?>
<p><b>$_COOKIE [<a href="#" onclick="return toggle('_cookie', this);">+</a>]</b></p>
<div id="_cookie" style="display:none">
<table width="100%">
<?php foreach($_COOKIE as $k => $v): ?>
<tr>
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
<td width="85%"><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_SESSION)): ?>
<p><b>$_SESSION [<a href="#" onclick="return toggle('_session', this);">+</a>]</b></p>
<div id="_session" style="display:none">
<table width="100%">
<?php foreach($_SESSION as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_SESSION)): ?>
<p><b>$_SESSION [<a href="#" onclick="return toggle('_session', this);">+</a>]</b></p>
<div id="_session" style="display:none">
<table width="100%">
<?php foreach($_SESSION as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
<?php if(!empty($_ENV)): ?>
<p><b>$_ENV [<a href="#" onclick="return toggle('_env', this);">+</a>]</b></p>
<div id="_env" style="display:none">
<table width="100%">
<?php foreach($_ENV as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</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>
<?php if(!empty($_ENV)): ?>
<p><b>$_ENV [<a href="#" onclick="return toggle('_env', this);">+</a>]</b></p>
<div id="_env" style="display:none">
<table width="100%">
<?php foreach($_ENV as $k => $v): ?>
<tr>
<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>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</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>
<script type="text/javascript">
@@ -215,13 +283,11 @@ function toggle(id, link)
if (link != null) {
link.innerHTML = '-';
}
div.style.display = "block";
} else {
if (link != null) {
link.innerHTML = '+';
}
div.style.display = "none";
}
@@ -229,4 +295,4 @@ function toggle(id, link)
}
</script>
</body>
</html>
</html>

View File

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

View File

@@ -1,28 +1,28 @@
<?php
// Add plugin navigation link
Navigation::add(__('Information', 'information'), 'system', 'information', 5);
// Add plugin navigation link
Navigation::add(__('Information', 'information'), 'system', 'information', 5);
/**
* Information Admin Class
*/
class InformationAdmin extends Backend
{
/**
* Information Admin Class
* Information main function
*/
class InformationAdmin extends Backend
public static function main()
{
/**
* Information main function
*/
public static function main()
{
// Init vars
$php_modules = array();
// Init vars
$php_modules = array();
// Get array with the names of all modules compiled and loaded
$php_modules = get_loaded_extensions();
// Display view
View::factory('box/information/views/backend/index')
->assign('php_modules', $php_modules)
->display();
}
// Get array with the names of all modules compiled and loaded
$php_modules = get_loaded_extensions();
// Display view
View::factory('box/information/views/backend/index')
->assign('php_modules', $php_modules)
->display();
}
}

View File

@@ -1,29 +1,29 @@
<?php
/**
* Information plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012-2013 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
/**
* Information plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012-2013 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Information', 'information'),
__('Information plugin', 'information'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
// Register plugin
Plugin::register( __FILE__,
__('Information', 'information'),
__('Information plugin', 'information'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'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
Plugin::Admin('information', 'box');
// Include Information Admin
Plugin::Admin('information', 'box');
}
}

View File

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