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