$_val)
{
if (isset(${$_key}))
{
unset(${$_key});
}
}
}
}
}
$oldlevel = ini_get('error_reporting');
$newlevel = $oldlevel;
$levels = array(E_ERROR => E_USER_ERROR, E_WARNING => E_USER_WARNING, E_NOTICE => E_USER_NOTICE);
foreach ($levels AS $php => $isso)
{
if ($oldlevel & $php)
{
if (!($oldlevel & $isso))
{
$newlevel += $isso;
}
}
else
{
if ($oldlevel & $isso)
{
$newlevel -= $isso;
}
}
}
error_reporting($newlevel);
/**
* Yes, required
*/
define('REQ_YES', 1);
/**
* No, not required
*/
define('REQ_NO', 0);
/**
* Blue Static ISSO Framework (ISSO)
*
* This framework allows a common backend to be used amongst all Blue
* Static applications and is built to be abstract and flexible.
* The base framework handles all loading and module management.
*
* Constants:
* ISSO_MT_START - Define the microtime() value at the top of your
* script and this will calculate the total execution
* time
* SVN - Place SVN keywords (like $Id) to display the information on output
*
* @author Blue Static
* @copyright Copyright ©2002 - [#]year[#], Blue Static
* @version $Revision$
* @package ISSO
*
*/
class ISSO
{
/**
* ISSO version
* @var string
*/
private $version = '[#]issoversion[#]';
/**
* List of all active debug messages
* @var array
*/
private $debuginfo = array();
/**
* List of loaded modules
* @var array
*/
private $modules = array();
// ###################################################################
/**
* Constructor
*/
public function __construct()
{
$GLOBALS['isso:callback'] = null;
// error reporting
set_error_handler(array(&$this, '_error_handler'));
}
// ###################################################################
/**
* Prints a list of all currently loaded framework modules
*
* @param bool Return the data as an array?
*
* @return mixed HTML output or an array of loaded modules
*/
public function show_modules($return = false)
{
$modules = array();
foreach ($this->modules AS $object)
{
$module = get_class($object);
if (method_exists($object, 'init_as_package') AND in_array($module, $modules))
{
$module = $object->init_as_package() . " - ($module)";
}
$modules[] = $module;
}
if ($return)
{
return $modules;
}
else
{
$output = "\n\n
\n\t- ";
$output .= implode("
\n\t- ", $modules);
$output .= "
\n
\n\n";
$this->message('Loaded Modules', $output, 1);
}
}
// ###################################################################
/**
* Prints an ISSO message
*
* @param string The title of the message
* @param string The content of the message
* @param integer Type of message to be printed
* @param bool Return the output?
* @param bool Show the debug stack?
* @param integer Message width
*
* @return mixed Output or null
*/
public function message($title, $message, $type, $return = false, $stack = true, $width = 500)
{
switch ($type)
{
// Message
case 1:
$prefix = 'Message';
$color = '#669900';
$font = '#000000';
break;
// Warning
case 2:
$prefix = 'Warning';
$color = '#003399';
$font = '#FFFFFF';
break;
case 3:
$prefix = 'Error';
$color = '#990000';
$font = '#EFEFEF';
break;
}
$backtrace = debug_backtrace();
array_shift($backtrace);
if (isset($backtrace[0]) AND $backtrace[0]['function'] == '_error_handler')
{
array_shift($backtrace);
}
$trace = $this->format_debug_trace($backtrace);
$output = "\n
\n";
$output .= "\n\n\t$prefix: $title | \n
";
$output .= "\n\n\t$message | \n
";
$output .= (($stack AND $GLOBALS['isso:callback']->debug) ? "\n\n\tDebug Stack: " . implode("\n", $trace) . " | \n
" : '');
$output .= "\n
\n
\n";
if ($return)
{
return $output;
}
else
{
print($output);
}
}
// ###################################################################
/**
* Prepares a debug_backtrace() array for output to the browser by
* compressing the array into visible text
*
* @param array debug_backtrace() array
*
* @return array Formatted trace output
*/
public function format_debug_trace($backtrace)
{
$trace = array();
foreach ($backtrace AS $i => $step)
{
$args = '';
$file = $step['file'] . ':' . $step['line'];
$funct = (isset($step['class']) ? $step['class'] . '::' . $step['function'] : $step['function']);
if (isset($step['args']) AND is_array($step['args']))
{
// we need to do this so we don't get "Array to string conversion" notices
foreach ($step['args'] AS $id => $arg)
{
if (is_array($arg))
{
$step['args']["$id"] = 'Array';
}
}
$args = implode(', ', $step['args']);
}
$trace[] = "#$i $funct($args) called at [$file]";
}
return $trace;
}
// ###################################################################
/**
* Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
* E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
*
* @param integer Error number
* @param string Error message string
* @param string File that contains the error
* @param string The line number of the error
* @param string The active symbol table at which point the error occurred
*/
public function _error_handler($errno, $errstr, $errfile, $errline, $errcontext)
{
$level = ini_get('error_reporting');
switch ($errno)
{
// Fatal
case E_USER_ERROR:
$title = 'Fatal';
$mode = 3;
if (!($level & E_USER_ERROR))
{
return;
}
break;
// Error
case E_USER_WARNING:
case E_WARNING:
$title = 'Warning';
$mode = 2;
if (! (($level & E_USER_WARNING) AND ($level & E_WARNING)) )
{
return;
}
break;
// Warning
case E_USER_NOTICE:
case E_NOTICE:
default:
$title = 'Notice';
$mode = 1;
if (! (($level & E_USER_NOTICE) AND ($level & E_NOTICE)) )
{
return;
}
break;
}
$errstr .= " in $errfile on line $errline";
$errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
$this->message($title, $errstr, $mode);
if ($errno == E_USER_ERROR)
{
exit;
}
}
// ###################################################################
/**
* Creates a table that explains the error reporting levels and their
* state
*/
public function explain_error_reporting()
{
$levels = array(
'E_ERROR' => E_ERROR,
'E_WARNING' => E_WARNING,
'E_PARSE' => E_PARSE,
'E_NOTICE' => E_NOTICE,
'E_CORE_ERROR' => E_CORE_ERROR,
'E_CORE_WARNING' => E_CORE_WARNING,
'E_COMPILE_ERROR' => E_COMPILE_ERROR,
'E_COMPILE_WARNING' => E_COMPILE_WARNING,
'E_USER_ERROR' => E_USER_ERROR,
'E_USER_WARNING' => E_USER_WARNING,
'E_USER_NOTICE' => E_USER_NOTICE,
'E_ALL' => E_ALL,
'E_STRICT' => E_STRICT
);
$table = '';
foreach ($levels AS $name => $value)
{
$table .= '
' . $name . ' |
' . (ini_get('error_reporting') & $value) . ' |
';
}
$table .= '
';
$this->message('Error Reporting', $table, 1);
}
// ###################################################################
/**
* Logs a debug message for verbose output
*
* @param string Message
*/
public function debug($message)
{
$this->debuginfo[] = $message;
}
// ###################################################################
/**
* Constructs a debug information box that contains various debugging
* information points
*
* @param bool Show template information?
*
* @return string Debugging block
*/
public function construct_debug_block($dotemplates)
{
$debug = '';
if ($this->debug)
{
$debug = "\n";
// templates
if ($dotemplates)
{
$optlist = array();
$usage = array();
foreach ($this->modules['template']->usage AS $name => $count)
{
if (in_array($name, $this->modules['template']->uncached))
{
$optlist[] = $name . '[' . $count . ']';
}
$usage[] = $name . " ($count)";
}
$sizeof = sizeof($this->modules['template']->uncached);
if ($sizeof > 0)
{
$debug .= "\n\t- Uncached Template(s): $sizeof ( " . implode(' ', $optlist) . " )
";
}
}
// source control
$scinfo = 'Not Under Source Control';
if (defined('SVN'))
{
$scinfo = constant('SVN');
if (preg_match('#\$Id:?\s*\$#', $scinfo))
{
$scinfo = 'Not Under Source Control';
}
else
{
$scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo);
$scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo);
$scinfo = preg_replace('#\$' . 'Id: (.+?) ([0-9].+?) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.+?) (.+?) \$#', '\\1 - SVN \\2', $scinfo);
}
}
$scinfo = trim($scinfo);
$debug .= "\n\t- Source Control: $scinfo
";
// query information
if (is_object($this->modules[ISSO_DB_LAYER]))
{
$debug .= "\n\t- Total Queries: " . sizeof($this->modules[ISSO_DB_LAYER]->history) . " (sanitize($_SERVER['REQUEST_URI']) . ((strpos($_SERVER['REQUEST_URI'], '?') !== false) ? '&query=1' : '?query=1') . "\">?)
";
}
// total execution time
if (defined('ISSO_MT_START'))
{
$this->load('functions', 'functions');
$debug .= "\n\t- Total Execution Time: " . round($this->modules['functions']->fetch_microtime_diff(ISSO_MT_START), 10) . "
";
}
// debug notices
$debug .= "\n\t- \n\t\t\n\t
";
// loaded modules
$modules = $this->show_modules(true);
$debug .= "\n\t- \n\t\t\n\t
";
// template usage
if ($dotemplates)
{
$debug .= "\n\t- \n\t\t\n\t
";
}
$debug .= "\n
";
$debug = "\n\n\n\n\n
\n" . $this->message('Debug Information', $debug, 1, true, false) . "\n\n\n\n";
}
return $debug;
}
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>