aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-20 15:34:08 -0500
committerjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-20 15:34:08 -0500
commit3af9846d4ecc1e0274833740fd21012afe9ef51f (patch)
tree2266233bfca1233f2860f3b8a75d453a9513f8c7
parentc0048a6c5a910588be35e30ea96d2b9b335c0503 (diff)
downloadbayonetcms-3af9846d4ecc1e0274833740fd21012afe9ef51f.tar.gz
Error handling functions added, and applied
git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@380 c5b2fb0a-d05d-0410-98c8-828840a80ff6
-rw-r--r--includes/functions.php28
-rw-r--r--index.php16
-rw-r--r--modules.php14
3 files changed, 54 insertions, 4 deletions
diff --git a/includes/functions.php b/includes/functions.php
index cd25792..0203d34 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -322,6 +322,34 @@ function CloseBlock()
echo "</div>";
CloseTable();
}
+
+static $error_stack_messages = array(); //global stack of errors accumulated throughout execution
+function push_error_stack($message)
+{
+ global $error_stack_messages;
+ array_push($error_stack_messages, $message);
+}
+
+function fatal_error_handler($buffer) {
+ if (ereg("(error</b>:)(.+)(<br)", $buffer, $regs) ) {
+ $err = preg_replace("/<.*?>/","",$regs[2]);
+ //ReportError($err);
+ }
+ return $buffer;
+}
+
+function handle_error ($errno, $errstr, $errfile, $errline)
+{
+ //error_log("$errstr in $errfile on line $errline");
+ //ReportError("<pre>$errstr</pre>");
+ push_error_stack("<b>Error Number:</b> $errno<br/><b>Error:</b> $errstr<br/><b>In File:</b> $errfile<br/><b>Line:</b> $errline");
+ if($errno == FATAL || $errno == ERROR){
+ push_error_stack($errstr);
+ ob_end_flush();
+ exit(0);
+ }
+}
+
/**
* ReportError()
*
diff --git a/index.php b/index.php
index e1ded92..3687f0d 100644
--- a/index.php
+++ b/index.php
@@ -1,4 +1,3 @@
-<?php try { ?>
<?php
/**
* Bayonet Conent Management System
@@ -8,12 +7,19 @@
* with ease and without needing to have any coding knowledge in order
* to maintain it. Visit www.eodesign.com/cms for any updates or feedback.
*/
-
+
+/* Begin try/catch block */
+try {
+
include './includes/debug.php';
include './includes/config.php';
include './includes/sql.class.php';
include './includes/functions.php';
+/* Setup error handing callbacks */
+ob_start("fatal_error_handler");
+set_error_handler("handle_error");
+
$db = new Bayonet_SQL();
$db->Connect(
$config['sql']['hostname'],
@@ -22,7 +28,6 @@ $db->Connect(
);
$db->Select_db($config['sql']['database']);
-
include 'header.php';
//session_start();
?>
@@ -54,7 +59,10 @@ include 'header.php';
</div>
<?php include 'footer.php'; ?>
-<?php
+<?php
+/* Flushing is needed by the error handler */
+ob_end_flush();
+
} //try ^^
catch(Exception $e)
{
diff --git a/modules.php b/modules.php
index 96bb241..5eaf705 100644
--- a/modules.php
+++ b/modules.php
@@ -51,6 +51,20 @@ for($chars = 0; $chars <= strlen($load_temp); ++$chars)
}
}
*/
+
+/* If the error stack has recieved messages, output each failure in a clean fashion */
+global $error_stack_messages;
+if(!empty($error_stack_messages))
+{
+ $messageBuffer = NULL;
+ foreach($error_stack_messages as $order => $error)
+ {
+ $messageBuffer .= "<p><b>Stack Order:</b>$order<br/>$error</p>";
+ }
+ ReportError($messageBuffer);
+ //exit(1);
+}
+
if(isset($load) && !empty($load) && !isset($file))
{
if(file_exists("modules/" . $load))