2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * Blue Static ISSO Framework Kernel
29 if (!function_exists('stripos'))
31 trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR
);
35 if ((bool
)ini_get('register_globals') === true
)
37 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
38 foreach ($superglobals AS $global)
40 if (is_array($
{$global}))
42 foreach ($
{$global} AS $_key => $_val)
64 * Blue Static ISSO Framework (ISSO)
66 * This framework allows a common backend to be used amongst all Blue
67 * Static applications and is built to be abstract and flexible.
68 * The base framework handles all loading and module management.
71 * ISSO_MT_START - Define the microtime() value at the top of your
72 * script and this will calculate the total execution
74 * SVN - Place SVN keywords (like $Id) to display the information on output
77 * @copyright Copyright ©2002 - [#]year[#], Blue Static
88 private $version = '[#]issoversion[#]';
91 * List of loaded modules
94 private $modules = array();
96 // ###################################################################
100 public function __construct()
102 $GLOBALS['isso:callback'] = null
;
105 set_error_handler(array(&$this, '_error_handler'));
108 // ###################################################################
110 * Prints a list of all currently loaded framework modules
112 * @param bool Return the data as an array?
114 * @return mixed HTML output or an array of loaded modules
116 public function show_modules($return = false
)
119 foreach ($this->modules
AS $object)
121 $module = get_class($object);
122 if (method_exists($object, 'init_as_package') AND in_array($module, $modules))
124 $module = $object->init_as_package() . " - ($module)";
127 $modules[] = $module;
136 $output = "\n\n<ul>\n\t<li>";
137 $output .= implode("</li>\n\t<li>", $modules);
138 $output .= "</li>\n</ul>\n\n";
139 $this->message('Loaded Modules', $output, 1);
143 // ###################################################################
145 * Prints an ISSO message
147 * @param string The title of the message
148 * @param string The content of the message
149 * @param integer Type of message to be printed
150 * @param bool Return the output?
151 * @param bool Show the debug stack?
152 * @param integer Message width
154 * @return mixed Output or null
156 public function message($title, $message, $type, $return = false
, $stack = true
, $width = 500)
181 $backtrace = debug_backtrace();
182 array_shift($backtrace);
184 if (isset($backtrace[0]) AND $backtrace[0]['function'] == '_error_handler')
186 array_shift($backtrace);
189 $trace = $this->format_debug_trace($backtrace);
191 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"$width\" style=\"background-color: $color; color: black; font-family: Verdana, sans-serif; font-size: 12px;\">";
192 $output .= "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
193 $output .= "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
194 $output .= (($stack AND $GLOBALS['isso:callback']->debug
) ?
"\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>" . implode("\n", $trace) . "</pre></td>\n</tr>" : '');
195 $output .= "\n</table>\n<br />\n";
207 // ###################################################################
209 * Prepares a debug_backtrace() array for output to the browser by
210 * compressing the array into visible text
212 * @param array debug_backtrace() array
214 * @return array Formatted trace output
216 public function format_debug_trace($backtrace)
219 foreach ($backtrace AS $i => $step)
222 $file = $step['file'] . ':' . $step['line'];
223 $funct = (isset($step['class']) ?
$step['class'] . '::' . $step['function'] : $step['function']);
225 if (isset($step['args']) AND is_array($step['args']))
227 // we need to do this so we don't get "Array to string conversion" notices
228 foreach ($step['args'] AS $id => $arg)
232 $step['args']["$id"] = 'Array';
235 $args = implode(', ', $step['args']);
238 $trace[] = "#$i $funct($args) called at [$file]";
244 // ###################################################################
246 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
247 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
249 * @param integer Error number
250 * @param string Error message string
251 * @param string File that contains the error
252 * @param string The line number of the error
253 * @param string The active symbol table at which point the error occurred
255 public function _error_handler($errno, $errstr, $errfile, $errline, $errcontext)
257 $level = ini_get('error_reporting');
265 if (!($level & E_USER_ERROR
))
276 if (! (($level & E_USER_WARNING
) AND ($level & E_WARNING
)) )
288 if (! (($level & E_USER_NOTICE
) AND ($level & E_NOTICE
)) )
295 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
297 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
299 $this->message($title, $errstr, $mode);
301 if ($errno == E_USER_ERROR
)
307 // ###################################################################
309 * Creates a table that explains the error reporting levels and their
312 public function explain_error_reporting()
315 'E_ERROR' => E_ERROR
,
316 'E_WARNING' => E_WARNING
,
317 'E_PARSE' => E_PARSE
,
318 'E_NOTICE' => E_NOTICE
,
319 'E_CORE_ERROR' => E_CORE_ERROR
,
320 'E_CORE_WARNING' => E_CORE_WARNING
,
321 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
322 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
323 'E_USER_ERROR' => E_USER_ERROR
,
324 'E_USER_WARNING' => E_USER_WARNING
,
325 'E_USER_NOTICE' => E_USER_NOTICE
,
327 'E_STRICT' => E_STRICT
330 $table = '<table cellspacing="0" cellpadding="2" border="0">';
332 foreach ($levels AS $name => $value)
336 <td>' . $name . '</td>
337 <td>' . (ini_get('error_reporting') & $value) . '</td>
344 $this->message('Error Reporting', $table, 1);
347 // ###################################################################
349 * Constructs a debug information box that contains various debugging
352 * @param bool Show template information?
354 * @return string Debugging block
356 public function construct_debug_block($dotemplates)
369 foreach ($this->modules
['template']->usage
AS $name => $count)
371 if (in_array($name, $this->modules
['template']->uncached
))
373 $optlist[] = $name . '[' . $count . ']';
375 $usage[] = $name . " ($count)";
378 $sizeof = sizeof($this->modules
['template']->uncached
);
381 $debug .= "\n\t<li><strong style=\"color: red\">Uncached Template(s):</strong> $sizeof ( " . implode(' ', $optlist) . " )</li>";
386 $scinfo = 'Not Under Source Control';
389 $scinfo = constant('SVN');
391 if (preg_match('#\$Id:?\s*\$#', $scinfo))
393 $scinfo = 'Not Under Source Control';
397 $scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo);
398 $scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo);
399 $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);
403 $scinfo = trim($scinfo);
404 $debug .= "\n\t<li><strong>Source Control:</strong> $scinfo</li>";
407 if (is_object($this->modules
[ISSO_DB_LAYER
]))
409 $debug .= "\n\t<li><strong>Total Queries:</strong> " . sizeof($this->modules
[ISSO_DB_LAYER
]->history
) . " (<a href=\"" . $this->sanitize($_SERVER['REQUEST_URI']) . ((strpos($_SERVER['REQUEST_URI'], '?') !== false
) ?
'&query=1' : '?query=1') . "\">?</a>)</li>";
412 // total execution time
413 if (defined('ISSO_MT_START'))
415 $this->load('functions', 'functions');
416 $debug .= "\n\t<li><strong>Total Execution Time:</strong> " . round($this->modules
['functions']->fetch_microtime_diff(ISSO_MT_START
), 10) . "</li>";
420 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Debug Notices (" . sizeof($this->debuginfo
) . ")</option>";
421 foreach ((array)$this->debuginfo
AS $msg)
423 $debug .= "\n\t\t\t<option>--- $msg</option>";
425 $debug .= "\n\t\t</select>\n\t</li>";
428 $modules = $this->show_modules(true
);
429 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Loaded Modules (" . sizeof($modules) . ")</option>";
430 foreach ($modules AS $mod)
432 $debug .= "\n\t\t\t<option>--- $mod</option>";
434 $debug .= "\n\t\t</select>\n\t</li>";
439 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Template Usage (" . array_sum($this->modules
['template']->usage
) . ")</option>";
440 foreach ($usage AS $tpl)
442 $debug .= "\n\t\t\t<option>--- $tpl</option>";
444 $debug .= "\n\t\t</select>\n\t</li>";
449 $debug = "\n\n<!-- dev debug -->\n<div align=\"center\">\n\n<hr />\n" . $this->message('Debug Information', $debug, 1, true
, false
) . "\n</div>\n<!-- / dev debug -->\n\n";
456 /*=====================================================================*\
457 || ###################################################################
460 || ###################################################################
461 \*=====================================================================*/