Adding construct_debug_block()
[isso.git] / kernel.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Iris Studios Shared Object Framework Kernel
24 * kernel.php
25 *
26 * @package ISSO
27 */
28
29 if (!function_exists('version_compare'))
30 {
31 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', E_USER_ERROR);
32 exit;
33 }
34
35 if (version_compare(PHP_VERSION, '5.0.0', '>='))
36 {
37 if (ini_get('error_reporting') & E_NOTICE)
38 {
39 error_reporting(ini_get('error_reporting') - E_NOTICE);
40 }
41 if (ini_get('error_reporting') & E_USER_NOTICE)
42 {
43 error_reporting(ini_get('error_reporting') - E_USER_NOTICE);
44 }
45 }
46
47 $oldlevel = ini_get('error_reporting');
48 $newlevel = $oldlevel;
49 $levels = array(E_ERROR => E_USER_ERROR, E_WARNING => E_USER_WARNING, E_NOTICE => E_USER_NOTICE);
50 foreach ($levels AS $php => $isso)
51 {
52 if ($oldlevel & $php)
53 {
54 if (!($oldlevel & $isso))
55 {
56 $newlevel += $isso;
57 }
58 }
59 else
60 {
61 if ($oldlevel & $isso)
62 {
63 $newlevel -= $isso;
64 }
65 }
66 }
67 error_reporting($newlevel);
68
69 if ((bool)ini_get('register_globals') === true)
70 {
71 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
72 foreach ($superglobals AS $global)
73 {
74 if (is_array(${$global}))
75 {
76 foreach (${$global} AS $_key => $_val)
77 {
78 if (isset(${$_key}))
79 {
80 unset(${$_key});
81 }
82 }
83 }
84 }
85 }
86
87 /**#@+
88 * Input cleaning type constant
89 */
90 /**
91 * Integer type
92 */
93 define('TYPE_INT', 1);
94
95 /**
96 * Unsigned integer
97 */
98 define('TYPE_UINT', 2);
99
100 /**
101 * Float type
102 */
103 define('TYPE_FLOAT', 4);
104
105 /**
106 * Boolean type
107 */
108 define('TYPE_BOOL', 8);
109
110 /**
111 * String - cleaned
112 */
113 define('TYPE_STR', 16);
114
115 /**
116 * String - deliberate unclean
117 */
118 define('TYPE_STRUN', 32);
119
120 /**
121 * No cleaning - here for use in API
122 */
123 define('TYPE_NOCLEAN', 64);
124 /**#@-*/
125
126 /**
127 * Iris Studios Shared Object Framework (ISSO)
128 *
129 * This framework allows a common backend to be used amongst all Iris
130 * Studios applications and is built to be abstract and flexible.
131 * The base framework handles all loading and module management.
132 *
133 * @author Iris Studios, Inc.
134 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
135 * @version $Revision$
136 * @package ISSO
137 *
138 */
139 class Shared_Object_Framework
140 {
141 /**
142 * ISSO version
143 * @var string
144 */
145 var $version = '[#]version[#]';
146
147 /**
148 * Location of ISSO, used for internal linking
149 * @var string
150 */
151 var $sourcepath = '';
152
153 /**
154 * Path of the current application
155 * @var string
156 */
157 var $apppath = '';
158
159 /**
160 * Web path used to get the web location of the installation of ISSO; only used for Printer module
161 * @var string
162 */
163 var $webpath = '';
164
165 /**
166 * Name of the current application
167 * @var string
168 */
169 var $application = '';
170
171 /**
172 * Version of the current application
173 * @var string
174 */
175 var $appversion = '';
176
177 /**
178 * Whether debug mode is on or off
179 * @var bool
180 */
181 var $debug = false;
182
183 /**
184 * List of all active debug messages
185 * @var array
186 */
187 var $debuginfo = array();
188
189 /**
190 * List of loaded modules
191 * @var array
192 */
193 var $modules = array();
194
195 /**
196 * An array of sanitized variables that have been cleaned for HTML tag openers and double quotes
197 * @var array
198 */
199 var $in = array();
200
201 /**
202 * If we are running with magic_quotes_gpc on or off
203 * @var int
204 */
205 var $magicquotes = 0;
206
207 /**
208 * If we should automagically escape strings, mimicking magic_quotes_gpc
209 * @var bool
210 */
211 var $escapestrings = false;
212
213 // ###################################################################
214 /**
215 * Constructor
216 */
217 function __construct()
218 {
219 // error reporting
220 set_error_handler(array(&$this, '_error_handler'));
221
222 // magic quotes
223 $this->magicquotes = get_magic_quotes_gpc();
224 set_magic_quotes_runtime(0);
225
226 if (defined('ISSO_ESCAPE_STRINGS'))
227 {
228 $this->escapestrings = (bool)constant('ISSO_ESCAPE_STRINGS');
229 }
230
231 // start input sanitize using variable_order GPC
232 if (!$this->escapestrings)
233 {
234 $this->exec_sanitize_data();
235 }
236
237 if (defined('ISSO_CHECK_POST_REFERER'))
238 {
239 $this->exec_referer_check();
240 }
241
242 $GLOBALS['isso:null-framework'] = null;
243 }
244
245 // ###################################################################
246 /**
247 * (PHP 4) Constructor
248 */
249 function Shared_Object_Framework()
250 {
251 $this->__construct();
252 }
253
254 // ###################################################################
255 /**
256 * Prepares a path for being set as the sourcepath
257 *
258 * @access public
259 *
260 * @param string Source path or URL
261 *
262 * @return string Prepared source path
263 */
264 function fetch_sourcepath($source)
265 {
266 if (substr($source, strlen($source) - 1) != DIRECTORY_SEPARATOR)
267 {
268 $source .= DIRECTORY_SEPARATOR;
269 }
270 return $source;
271 }
272
273 // ###################################################################
274 /**
275 * Loads a framework module
276 *
277 * @access public
278 *
279 * @param string Name of the framework file to load
280 * @param string Internal variable to initialize as; to not instantiate (just require) leave it as NULL
281 * @param bool Globalize the internal variable?
282 *
283 * @return object Instantiated instance
284 */
285 function &load($framework, $asobject, $globalize = false)
286 {
287 // set the object interlock
288 if (!method_exists($GLOBALS['isso:null-framework'], 'load'))
289 {
290 $GLOBALS['isso:null-framework'] =& $this;
291 }
292
293 if ($this->is_loaded($framework))
294 {
295 return $this->modules["$framework"];
296 }
297
298 if ($this->sourcepath == '')
299 {
300 trigger_error('Invalid sourcepath specified', E_USER_ERROR);
301 }
302
303 if (file_exists($this->sourcepath . $framework . '.php'))
304 {
305 require_once($this->sourcepath . $framework . '.php');
306 }
307 else
308 {
309 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR);
310 }
311
312 if ($asobject === null)
313 {
314 return;
315 }
316
317 if (isset($this->$asobject))
318 {
319 trigger_error('Cannot instantiate framework `' . $framework . '` into `' . $asobject . '`', E_USER_ERROR);
320 }
321
322 $this->$asobject = new $framework($this);
323
324 $this->modules["$framework"] =& $this->$asobject;
325
326 if ($globalize)
327 {
328 $GLOBALS["$asobject"] =& $this->$asobject;
329 }
330
331 return $this->$asobject;
332 }
333
334 // ###################################################################
335 /**
336 * Prints a list of all currently loaded framework modules
337 *
338 * @access public
339 *
340 * @param bool Return the data as an array?
341 *
342 * @return mixed HTML output or an array of loaded modules
343 */
344 function show_modules($return = false)
345 {
346 foreach ($this->modules AS $object)
347 {
348 $modules[] = get_class($object);
349 }
350
351 if ($return)
352 {
353 return $modules;
354 }
355 else
356 {
357 $output = "\n\n<ul>\n\t<li>";
358 $output .= implode("</li>\n\t<li>", $modules);
359 $output .= "</li>\n</ul>\n\n";
360 $this->message('Loaded Modules', $output, 1);
361 }
362 }
363
364 // ###################################################################
365 /**
366 * Verifies to see if a framework has been loaded
367 *
368 * @access public
369 *
370 * @param string Framework name
371 *
372 * @return bool Whether or not the framework has been loaded
373 */
374 function is_loaded($framework)
375 {
376 if (isset($this->modules["$framework"]))
377 {
378 return true;
379 }
380 else
381 {
382 return false;
383 }
384 }
385
386 // ###################################################################
387 /**
388 * Prints an ISSO message
389 *
390 * @access public
391 *
392 * @param string The title of the message
393 * @param string The content of the message
394 * @param integer Type of message to be printed
395 * @param bool Return the output?
396 * @param bool Show the debug stack?
397 *
398 * @return mixed Output or null
399 */
400 function message($title, $message, $type, $return = false, $stack = true)
401 {
402 switch ($type)
403 {
404 // Message
405 case 1:
406 $prefix = 'Message';
407 $color = '#669900';
408 $font = '#000000';
409 break;
410
411 // Warning
412 case 2:
413 $prefix = 'Warning';
414 $color = '#003399';
415 $font = '#FFFFFF';
416 break;
417
418 case 3:
419 $prefix = 'Error';
420 $color = '#990000';
421 $font = '#EFEFEF';
422 break;
423 }
424
425 $backtrace = debug_backtrace();
426 unset($backtrace[0]);
427
428 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"500\" style=\"background-color: $color; color: black; font-family: Verdana, sans-serif; font-size: 12px;\">";
429 $output .= "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
430 $output .= "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
431 $output .= (($stack AND $GLOBALS['isso:null-framework']->debug) ? "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>" . print_r($backtrace, true) . "</pre></td>\n</tr>" : '');
432 $output .= "\n</table>\n<br />\n";
433
434 if ($return)
435 {
436 return $output;
437 }
438 else
439 {
440 print($output);
441 }
442 }
443
444 // ###################################################################
445 /**
446 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
447 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
448 *
449 * @access private
450 *
451 * @param integer Error number
452 * @param string Error message string
453 * @param string File that contains the error
454 * @param string The line number of the error
455 * @param string The active symbol table at which point the error occurred
456 */
457 function _error_handler($errno, $errstr, $errfile, $errline)
458 {
459 switch ($errno)
460 {
461 // Fatal
462 case E_USER_ERROR:
463 $title = 'Fatal';
464 $level = 3;
465 if (!(ini_get('error_reporting') & E_USER_ERROR))
466 {
467 return;
468 }
469 break;
470
471 // Error
472 case E_USER_WARNING:
473 $title = 'Warning';
474 $level = 2;
475 if (!(ini_get('error_reporting') & E_USER_WARNING) AND !(ini_get('error_reporting') & E_WARNING))
476 {
477 return;
478 }
479 break;
480
481 // Warning
482 case E_USER_NOTICE:
483 default:
484 $title = 'Notice';
485 $level = 1;
486 if (!(ini_get('error_reporting') & E_USER_NOTICE) AND !(ini_get('error_reporting') & E_NOTICE))
487 {
488 return;
489 }
490 break;
491 }
492
493 $errfile = str_replace(array(getcwd(), dirname(getcwd())), '', $errfile);
494
495 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
496
497 $this->message($title, $errstr, $level);
498
499 if ($errno == E_USER_ERROR)
500 {
501 exit;
502 }
503 }
504
505 // ###################################################################
506 /**
507 * Creates a table that explains the error reporting levels and their
508 * state
509 *
510 * @access public
511 */
512 function explain_error_reporting()
513 {
514 $levels = array(
515 'E_ERROR' => E_ERROR,
516 'E_WARNING' => E_WARNING,
517 'E_PARSE' => E_PARSE,
518 'E_NOTICE' => E_NOTICE,
519 'E_CORE_ERROR' => E_CORE_ERROR,
520 'E_CORE_WARNING' => E_CORE_WARNING,
521 'E_COMPILE_ERROR' => 64,
522 'E_COMPILE_WARNING' => 128,
523 'E_USER_ERROR' => E_USER_ERROR,
524 'E_USER_WARNING' => E_USER_WARNING,
525 'E_USER_NOTICE' => E_USER_NOTICE,
526 'E_ALL' => E_ALL,
527 'E_STRICT' => 2048
528 );
529
530 $table = '<table cellspacing="0" cellpadding="2" border="0">';
531
532 foreach ($levels AS $name => $value)
533 {
534 $table .= '
535 <tr>
536 <td>' . $name . '</td>
537 <td>' . (ini_get('error_reporting') & $value) . '</td>
538 </tr>';
539 }
540
541 $table .= '
542 </table>';
543
544 $this->message('Error Reporting', $table, 1);
545 }
546
547 // ###################################################################
548 /**
549 * Logs a debug message for verbose output
550 *
551 * @access public
552 *
553 * @param string Message
554 */
555 function debug($message)
556 {
557 $this->debuginfo[] = $message;
558 }
559
560 // ###################################################################
561 /**
562 * Recursive XSS cleaner
563 *
564 * @access private
565 *
566 * @param mixed Unsanitized REQUEST data
567 *
568 * @return mixed Sanitized data
569 */
570 function _sanitize_input_recursive($data)
571 {
572 foreach ($data AS $key => $value)
573 {
574 if (is_array($value))
575 {
576 $data["$key"] = $this->_sanitize_input_recursive($value);
577 }
578 else
579 {
580 $data["$key"] = $this->sanitize($value);
581 }
582 }
583 return $data;
584 }
585
586 // ###################################################################
587 /**
588 * Simple way to protect against HTML attacks with Unicode support
589 *
590 * @access public
591 *
592 * @param string Unsanitzed text
593 *
594 * @return string Properly protected text that only encodes potential threats
595 */
596 function sanitize($text)
597 {
598 if ($this->magicquotes)
599 {
600 return str_replace(array('<', '>', '\"', '"'), array('&lt;', '&gt;', '&quot;', '&quot;'), $text);
601 }
602 else
603 {
604 return str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $text);
605 }
606 }
607
608 // ###################################################################
609 /**
610 * Unicode-safe entity encoding system; similar to sanitize()
611 *
612 * @access public
613 *
614 * @param string Unsanitized text
615 *
616 * @return string Unicode-safe sanitized text with entities preserved
617 */
618 function entity_encode($text)
619 {
620 $text = str_replace('&', '&amp;', $text);
621 $text = $this->sanitize($text);
622 return $text;
623 }
624
625 // ###################################################################
626 /**
627 * Takes text that has been processed for HTML and unsanitizes it
628 *
629 * @access public
630 *
631 * @param string Text that needs to be turned back into HTML
632 *
633 * @return string Unsanitized text
634 */
635 function unsanitize($text)
636 {
637 return str_replace(array('&lt;', '&gt;', '&quot;'), array('<', '>', '"'), $text);
638 }
639
640 // ###################################################################
641 /**
642 * Smart addslashes() that only applies itself it the Magic Quotes GPC
643 * is off. This should only be run on database query values.
644 *
645 * @access public
646 *
647 * @param string Some string
648 * @param bool If the data is binary; if so it'll be run through DB::escape_stringing()
649 * @param bool Force magic quotes to be off
650 *
651 * @return string String that has slashes added
652 */
653 function escape($str, $binary = false, $force = true)
654 {
655 if ($this->magicquotes AND !$force)
656 {
657 if (isset($this->db) AND $binary)
658 {
659 if (is_resource($this->db->link_id))
660 {
661 return $this->db->escape_string(str_replace(array("\'", '\"'), array("'", '"'), $str));
662 }
663 }
664 return $str;
665 }
666 else
667 {
668 if (isset($this->db) AND $binary)
669 {
670 if (is_resource($this->db->link_id))
671 {
672 return $this->db->escape_string($str);
673 }
674 }
675 return addslashes($str);
676 }
677 }
678
679 // ###################################################################
680 /**
681 * Runs through all of the input data and sanitizes it.
682 *
683 * @access public
684 */
685 function exec_sanitize_data()
686 {
687 $this->in = $this->_sanitize_input_recursive(array_merge($_GET, $_POST, $_COOKIE));
688 }
689
690 // ###################################################################
691 /**
692 * Sanitize function for something other than a string (which
693 * everything is sanitized for if you use exec_sanitize_data(). Cleaned
694 * data is placed back into $isso->in; this makes it so you don't have
695 * to constantly intval() [etc.] data.
696 *
697 * @access public
698 *
699 * @param array Array of elements to clean as varname => type
700 */
701 function input_clean_array($vars)
702 {
703 foreach ($vars AS $varname => $type)
704 {
705 $this->input_clean($varname, $type);
706 }
707 }
708
709 // ###################################################################
710 /**
711 * Sanitize function that does a single variable as oppoesd to an array
712 * (see input_clean_array() for more details)
713 *
714 * @access public
715 *
716 * @param string Variable name in $isso->in[]
717 * @param integer Sanitization type constant
718 */
719 function input_clean($varname, $type)
720 {
721 if (isset($this->in["$varname"]))
722 {
723 $this->in["$varname"] = $this->clean($this->in["$varname"], $type);
724 }
725 else
726 {
727 $this->in["$varname"] = null;
728 }
729 }
730
731 // ###################################################################
732 /**
733 * Cleaning function that does the work for input_clean(); this is
734 * moved here so it can be used to clean things that aren't in
735 * $isso->in[]
736 *
737 * @access public
738 *
739 * @param mixed Data
740 * @param integer Sanitization type constant
741 *
742 * @return mixed Cleaned data
743 */
744 function clean($value, $type)
745 {
746 if ($type == TYPE_INT)
747 {
748 $value = intval($value);
749 }
750 else if ($type == TYPE_UINT)
751 {
752 $value = abs(intval($value));
753 }
754 else if ($type == TYPE_FLOAT)
755 {
756 $value = floatval($value);
757 }
758 else if ($type == TYPE_BOOL)
759 {
760 $value = (bool)$value;
761 }
762 else if ($type == TYPE_STR)
763 {
764 $value = $value;
765 }
766 else if ($type == TYPE_STRUN)
767 {
768 $value = $this->unsanitize($value);
769 }
770 else if ($type == TYPE_NOCLEAN)
771 {
772 $value = $value;
773 }
774 else
775 {
776 trigger_error('Invalid clean type `' . $type . '` specified', E_USER_ERROR);
777 }
778
779 return $value;
780 }
781
782 // ###################################################################
783 /**
784 * Checks to see if a POST refer is actually from us
785 *
786 * @access public
787 */
788 function exec_referer_check()
789 {
790 if ($_SERVER['REQUEST_METHOD'] == 'POST')
791 {
792 $host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
793
794 if ($host AND $_SERVER['HTTP_REFERER'])
795 {
796 $parts = parse_url($_SERVER['HTTP_REFERER']);
797 $ourhost = $parts['host'] . (($parts['port']) ? ":$parts[port]" : '');
798
799 if ($ourhost != $host)
800 {
801 trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR);
802 }
803 $this->debug('remote post check = ok');
804 }
805 else
806 {
807 $this->debug('remote post check = FAILED');
808 }
809 }
810 }
811
812 // ###################################################################
813 /**
814 * Constructs a debug information box that contains various debugging
815 * information points
816 *
817 * @access public
818 *
819 * @param bool Show template information?
820 *
821 * @return string Debugging block
822 */
823 function construct_debug_block($dotemplates)
824 {
825 $debug = '';
826
827 if ($this->registry->debug)
828 {
829 // --- START
830 $debug = "\n<ul>";
831
832 // templates
833 if ($dotemplates)
834 {
835 $optlist = array();
836 $usage = array();
837 foreach ($this->usage AS $name => $count)
838 {
839 if (in_array($name, $this->uncached))
840 {
841 $optlist[] = $name . '[' . $count . ']';
842 }
843 $usage[] = $name . " ($count)";
844 }
845
846 $sizeof = sizeof($this->uncached);
847 if ($sizeof > 0)
848 {
849 $debug .= "\n\t<li><strong style=\"color: red\">Uncached Template(s):</strong> $sizeof ( " . implode(' &nbsp; ', $optlist) . " )</li>";
850 }
851 }
852
853 // source control
854 $scinfo = 'Not Under Source Control';
855 $possiblescms = array('cvs', 'svn', 'cvs_information', 'svn_information', 'scm', 'sc_information', 'scm_information');
856 foreach ($possiblescms AS $scm)
857 {
858 if (defined(strtoupper($scm)))
859 {
860 $scinfo = constant(strtoupper($scm));
861
862 $type = '';
863 // CVS
864 if (strpos($scinfo, 'RCSfile:') !== false)
865 {
866 $type = 'cvs';
867 }
868 else if (strpos($scinfo, ',v ') !== false)
869 {
870 $type = 'cvs';
871 }
872 // SVN
873 else if (strpos($scinfo, 'URL:') !== false)
874 {
875 $type = 'svn';
876 }
877 else if (strpos($scinfo, 'https://') !== false OR strpos($scinfo, 'http://') !== false)
878 {
879 $type= 'svn';
880 }
881 // not found so just return it
882 // try a SVN ID tag as we can't really tell if we're using it
883 else
884 {
885 $test = preg_replace('#\$' . 'Id: (.+?) (.+?) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.+?) (.+?) \$#', '\\1 - SVN \\2', $scinfo);
886 if ($test == '$' . 'Id: $')
887 {
888 $scinfo = 'Not Under Source Control';
889 }
890 else
891 {
892 $scinfo = $test;
893 }
894 break;
895 }
896
897 if ($type == 'cvs')
898 {
899 $scinfo = preg_replace('#\$' . 'RCSfile: (.+?) \$#', '\\1', $scinfo);
900 $scinfo = preg_replace('#\$' . 'Revision: (.+?) \$#', 'CVS \\1', $scinfo);
901 $scinfo = preg_replace('#\$' . 'Id: (.+?) (.+?) [0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} (.+?) (.+?) \$#', '\\1 - CVS \\2', $scinfo);
902 }
903 else if ($type == 'svn')
904 {
905 $scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo);
906 $scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo);
907 $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);
908 }
909 else
910 {
911 $scinfo = 'Not Under Source Control';
912 }
913 break;
914 }
915 }
916 $scinfo = trim($scinfo);
917 $debug .= "\n\t<li><strong>Source Control:</strong> $scinfo</li>";
918
919 // query information
920 if (is_object($this->registry->modules['db_mysql']))
921 {
922 $debug .= "\n\t<li><strong>Total Queries:</strong> " . sizeof($this->registry->modules['db_mysql']->history) . " (<a href=\"" . $this->registry->sanitize($_SERVER['REQUEST_URI']) . ((strpos($_SERVER['REQUEST_URI'], '?') !== false) ? '&amp;query=1' : '?query=1') . "\">?</a>)</li>";
923 }
924
925 // total execution time
926 if (defined('ISSO_MT_START'))
927 {
928 $this->registry->load('functions', 'functions');
929 $debug .= "\n\t<li><strong>Total Execution Time:</strong> " . round($this->registry->modules['functions']->fetch_microtime_diff(ISSO_MT_START), 10) . "</li>";
930 }
931
932 // debug notices
933 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Debug Notices (" . sizeof($this->registry->debuginfo) . ")</option>";
934 foreach ((array)$this->registry->debuginfo AS $msg)
935 {
936 $debug .= "\n\t\t\t<option>--- $msg</option>";
937 }
938 $debug .= "\n\t\t</select>\n\t</li>";
939
940 // loaded modules
941 $modules = $this->registry->show_modules(true);
942 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Loaded Modules (" . sizeof($modules) . ")</option>";
943 foreach ($modules AS $mod)
944 {
945 $debug .= "\n\t\t\t<option>--- $mod</option>";
946 }
947 $debug .= "\n\t\t</select>\n\t</li>";
948
949 // template usage
950 if ($dotemplates)
951 {
952 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Template Usage (" . array_sum($this->usage) . ")</option>";
953 foreach ($usage AS $tpl)
954 {
955 $debug .= "\n\t\t\t<option>--- $tpl</option>";
956 }
957 $debug .= "\n\t\t</select>\n\t</li>";
958 }
959
960 // --- END
961 $debug .= "\n</ul>";
962
963 $debug = "\n<hr />\n" . $this->registry->message('Debug Information', $debug, 1, true, false);
964 $template = str_replace('</body>', "\n\n<!-- dev debug -->\n<div align=\"center\">\n$debug\n</div>\n<!-- / dev debug -->\n\n</body>", $template);
965 }
966
967 return $debug;
968 }
969 }
970
971 /*=====================================================================*\
972 || ###################################################################
973 || # $HeadURL$
974 || # $Id$
975 || ###################################################################
976 \*=====================================================================*/
977 ?>