Adding field requirement checker
[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_NO, '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 * Makes sure that all of the required fields in ISSO are set before
333 * any action is done. This will throw an error block describing
334 * the fields that need to be set if any are missing.
335 *
336 * @access protected
337 */
338 function check_isso_fields()
339 {
340 $missing = array();
341 foreach ($this->fields AS $name => $field)
342 {
343 if ($field[0] == REQ_YES AND $field[2] == false)
344 {
345 $missing[] = $name;
346 }
347 }
348
349 if (count($missing) > 0)
350 {
351 $error = 'You are missing required ISSO fields. Please make sure you have set:' . "\n";
352 $error .= '<ul>';
353
354 foreach ($missing AS $field)
355 {
356 $error .= "\n\t" . '<li>' . $field . '</li>';
357 }
358
359 $error .= "\n" . '</ul>';
360
361 $this->message('Missing Fields', $error, 3);
362 exit;
363 }
364 }
365
366 // ###################################################################
367 /**
368 * Prepares a path for being set as the sourcepath
369 *
370 * @access public
371 *
372 * @param string Source path or URL
373 *
374 * @return string Prepared source path
375 */
376 function fetch_sourcepath($source)
377 {
378 if (substr($source, strlen($source) - 1) != DIRECTORY_SEPARATOR)
379 {
380 $source .= DIRECTORY_SEPARATOR;
381 }
382 return $source;
383 }
384
385 // ###################################################################
386 /**
387 * Loads a framework module
388 *
389 * @access public
390 *
391 * @param string Name of the framework file to load
392 * @param string Internal variable to initialize as; to not instantiate (just require) leave it as NULL
393 * @param bool Globalize the internal variable?
394 *
395 * @return object Instantiated instance
396 */
397 function &load($framework, $asobject, $globalize = false)
398 {
399 $this->check_isso_fields();
400
401 // set the object interlock
402 if (!method_exists($GLOBALS['isso:null-framework'], 'load'))
403 {
404 $GLOBALS['isso:null-framework'] =& $this;
405 }
406
407 if ($this->is_loaded($framework))
408 {
409 return $this->modules["$framework"];
410 }
411
412 if ($this->sourcepath == '')
413 {
414 trigger_error('Invalid sourcepath specified', E_USER_ERROR);
415 }
416
417 if (file_exists($this->sourcepath . $framework . '.php'))
418 {
419 require_once($this->sourcepath . $framework . '.php');
420 }
421 else
422 {
423 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR);
424 }
425
426 if ($asobject === null)
427 {
428 return;
429 }
430
431 if (isset($this->$asobject))
432 {
433 trigger_error('Cannot instantiate framework `' . $framework . '` into `' . $asobject . '`', E_USER_ERROR);
434 }
435
436 $this->$asobject = new $framework($this);
437
438 $this->modules["$framework"] =& $this->$asobject;
439
440 if ($globalize)
441 {
442 $GLOBALS["$asobject"] =& $this->$asobject;
443 }
444
445 return $this->$asobject;
446 }
447
448 // ###################################################################
449 /**
450 * Prints a list of all currently loaded framework modules
451 *
452 * @access public
453 *
454 * @param bool Return the data as an array?
455 *
456 * @return mixed HTML output or an array of loaded modules
457 */
458 function show_modules($return = false)
459 {
460 foreach ($this->modules AS $object)
461 {
462 $modules[] = get_class($object);
463 }
464
465 if ($return)
466 {
467 return $modules;
468 }
469 else
470 {
471 $output = "\n\n<ul>\n\t<li>";
472 $output .= implode("</li>\n\t<li>", $modules);
473 $output .= "</li>\n</ul>\n\n";
474 $this->message('Loaded Modules', $output, 1);
475 }
476 }
477
478 // ###################################################################
479 /**
480 * Verifies to see if a framework has been loaded
481 *
482 * @access public
483 *
484 * @param string Framework name
485 *
486 * @return bool Whether or not the framework has been loaded
487 */
488 function is_loaded($framework)
489 {
490 if (isset($this->modules["$framework"]))
491 {
492 return true;
493 }
494 else
495 {
496 return false;
497 }
498 }
499
500 // ###################################################################
501 /**
502 * Prints an ISSO message
503 *
504 * @access public
505 *
506 * @param string The title of the message
507 * @param string The content of the message
508 * @param integer Type of message to be printed
509 * @param bool Return the output?
510 * @param bool Show the debug stack?
511 *
512 * @return mixed Output or null
513 */
514 function message($title, $message, $type, $return = false, $stack = true)
515 {
516 switch ($type)
517 {
518 // Message
519 case 1:
520 $prefix = 'Message';
521 $color = '#669900';
522 $font = '#000000';
523 break;
524
525 // Warning
526 case 2:
527 $prefix = 'Warning';
528 $color = '#003399';
529 $font = '#FFFFFF';
530 break;
531
532 case 3:
533 $prefix = 'Error';
534 $color = '#990000';
535 $font = '#EFEFEF';
536 break;
537 }
538
539 $backtrace = debug_backtrace();
540 unset($backtrace[0]);
541
542 $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;\">";
543 $output .= "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
544 $output .= "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
545 $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>" : '');
546 $output .= "\n</table>\n<br />\n";
547
548 if ($return)
549 {
550 return $output;
551 }
552 else
553 {
554 print($output);
555 }
556 }
557
558 // ###################################################################
559 /**
560 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
561 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
562 *
563 * @access private
564 *
565 * @param integer Error number
566 * @param string Error message string
567 * @param string File that contains the error
568 * @param string The line number of the error
569 * @param string The active symbol table at which point the error occurred
570 */
571 function _error_handler($errno, $errstr, $errfile, $errline)
572 {
573 switch ($errno)
574 {
575 // Fatal
576 case E_USER_ERROR:
577 $title = 'Fatal';
578 $level = 3;
579 if (!(ini_get('error_reporting') & E_USER_ERROR))
580 {
581 return;
582 }
583 break;
584
585 // Error
586 case E_USER_WARNING:
587 $title = 'Warning';
588 $level = 2;
589 if (!(ini_get('error_reporting') & E_USER_WARNING) AND !(ini_get('error_reporting') & E_WARNING))
590 {
591 return;
592 }
593 break;
594
595 // Warning
596 case E_USER_NOTICE:
597 default:
598 $title = 'Notice';
599 $level = 1;
600 if (!(ini_get('error_reporting') & E_USER_NOTICE) AND !(ini_get('error_reporting') & E_NOTICE))
601 {
602 return;
603 }
604 break;
605 }
606
607 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
608
609 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
610
611 $this->message($title, $errstr, $level);
612
613 if ($errno == E_USER_ERROR)
614 {
615 exit;
616 }
617 }
618
619 // ###################################################################
620 /**
621 * Creates a table that explains the error reporting levels and their
622 * state
623 *
624 * @access public
625 */
626 function explain_error_reporting()
627 {
628 $levels = array(
629 'E_ERROR' => E_ERROR,
630 'E_WARNING' => E_WARNING,
631 'E_PARSE' => E_PARSE,
632 'E_NOTICE' => E_NOTICE,
633 'E_CORE_ERROR' => E_CORE_ERROR,
634 'E_CORE_WARNING' => E_CORE_WARNING,
635 'E_COMPILE_ERROR' => 64,
636 'E_COMPILE_WARNING' => 128,
637 'E_USER_ERROR' => E_USER_ERROR,
638 'E_USER_WARNING' => E_USER_WARNING,
639 'E_USER_NOTICE' => E_USER_NOTICE,
640 'E_ALL' => E_ALL,
641 'E_STRICT' => 2048
642 );
643
644 $table = '<table cellspacing="0" cellpadding="2" border="0">';
645
646 foreach ($levels AS $name => $value)
647 {
648 $table .= '
649 <tr>
650 <td>' . $name . '</td>
651 <td>' . (ini_get('error_reporting') & $value) . '</td>
652 </tr>';
653 }
654
655 $table .= '
656 </table>';
657
658 $this->message('Error Reporting', $table, 1);
659 }
660
661 // ###################################################################
662 /**
663 * Logs a debug message for verbose output
664 *
665 * @access public
666 *
667 * @param string Message
668 */
669 function debug($message)
670 {
671 $this->debuginfo[] = $message;
672 }
673
674 // ###################################################################
675 /**
676 * Recursive XSS cleaner
677 *
678 * @access private
679 *
680 * @param mixed Unsanitized REQUEST data
681 *
682 * @return mixed Sanitized data
683 */
684 function _sanitize_input_recursive($data)
685 {
686 foreach ($data AS $key => $value)
687 {
688 if (is_array($value))
689 {
690 $data["$key"] = $this->_sanitize_input_recursive($value);
691 }
692 else
693 {
694 $data["$key"] = $this->sanitize($value);
695 }
696 }
697 return $data;
698 }
699
700 // ###################################################################
701 /**
702 * Simple way to protect against HTML attacks with Unicode support
703 *
704 * @access public
705 *
706 * @param string Unsanitzed text
707 *
708 * @return string Properly protected text that only encodes potential threats
709 */
710 function sanitize($text)
711 {
712 if ($this->magicquotes)
713 {
714 return str_replace(array('<', '>', '\"', '"'), array('&lt;', '&gt;', '&quot;', '&quot;'), $text);
715 }
716 else
717 {
718 return str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $text);
719 }
720 }
721
722 // ###################################################################
723 /**
724 * Unicode-safe entity encoding system; similar to sanitize()
725 *
726 * @access public
727 *
728 * @param string Unsanitized text
729 *
730 * @return string Unicode-safe sanitized text with entities preserved
731 */
732 function entity_encode($text)
733 {
734 $text = str_replace('&', '&amp;', $text);
735 $text = $this->sanitize($text);
736 return $text;
737 }
738
739 // ###################################################################
740 /**
741 * Takes text that has been processed for HTML and unsanitizes it
742 *
743 * @access public
744 *
745 * @param string Text that needs to be turned back into HTML
746 *
747 * @return string Unsanitized text
748 */
749 function unsanitize($text)
750 {
751 return str_replace(array('&lt;', '&gt;', '&quot;'), array('<', '>', '"'), $text);
752 }
753
754 // ###################################################################
755 /**
756 * Smart addslashes() that only applies itself it the Magic Quotes GPC
757 * is off. This should only be run on database query values.
758 *
759 * @access public
760 *
761 * @param string Some string
762 * @param bool If the data is binary; if so it'll be run through DB::escape_stringing()
763 * @param bool Force magic quotes to be off
764 *
765 * @return string String that has slashes added
766 */
767 function escape($str, $binary = false, $force = true)
768 {
769 if ($this->magicquotes AND !$force)
770 {
771 if (isset($this->modules[ISSO_DB_LAYER]) AND $binary)
772 {
773 return $this->modules[ISSO_DB_LAYER]->escape_string(str_replace(array("\'", '\"'), array("'", '"'), $str));
774 }
775 return $str;
776 }
777 else
778 {
779 if (isset($this->modules[ISSO_DB_LAYER]) AND $binary)
780 {
781 return $this->modules[ISSO_DB_LAYER]->escape_string($str);
782 }
783 return addslashes($str);
784 }
785 }
786
787 // ###################################################################
788 /**
789 * Runs through all of the input data and sanitizes it.
790 *
791 * @access public
792 */
793 function exec_sanitize_data()
794 {
795 $this->in = $this->_sanitize_input_recursive(array_merge($_GET, $_POST, $_COOKIE));
796 }
797
798 // ###################################################################
799 /**
800 * Sanitize function for something other than a string (which
801 * everything is sanitized for if you use exec_sanitize_data(). Cleaned
802 * data is placed back into $isso->in; this makes it so you don't have
803 * to constantly intval() [etc.] data.
804 *
805 * @access public
806 *
807 * @param array Array of elements to clean as varname => type
808 */
809 function input_clean_array($vars)
810 {
811 foreach ($vars AS $varname => $type)
812 {
813 $this->input_clean($varname, $type);
814 }
815 }
816
817 // ###################################################################
818 /**
819 * Sanitize function that does a single variable as oppoesd to an array
820 * (see input_clean_array() for more details)
821 *
822 * @access public
823 *
824 * @param string Variable name in $isso->in[]
825 * @param integer Sanitization type constant
826 */
827 function input_clean($varname, $type)
828 {
829 if (isset($this->in["$varname"]))
830 {
831 $this->in["$varname"] = $this->clean($this->in["$varname"], $type);
832 }
833 else
834 {
835 $this->in["$varname"] = null;
836 }
837
838 return $this->in["$varname"];
839 }
840
841 // ###################################################################
842 /**
843 * Cleaning function that does the work for input_clean(); this is
844 * moved here so it can be used to clean things that aren't in
845 * $isso->in[]
846 *
847 * @access public
848 *
849 * @param mixed Data
850 * @param integer Sanitization type constant
851 *
852 * @return mixed Cleaned data
853 */
854 function clean($value, $type)
855 {
856 if ($type == TYPE_INT)
857 {
858 $value = intval($value);
859 }
860 else if ($type == TYPE_UINT)
861 {
862 $value = abs(intval($value));
863 }
864 else if ($type == TYPE_FLOAT)
865 {
866 $value = floatval($value);
867 }
868 else if ($type == TYPE_BOOL)
869 {
870 $value = (bool)$value;
871 }
872 else if ($type == TYPE_STR)
873 {
874 $value = $value;
875 }
876 else if ($type == TYPE_STRUN)
877 {
878 $value = $this->unsanitize($value);
879 }
880 else if ($type == TYPE_NOCLEAN)
881 {
882 $value = $value;
883 }
884 else
885 {
886 trigger_error('Invalid clean type `' . $type . '` specified', E_USER_ERROR);
887 }
888
889 return $value;
890 }
891
892 // ###################################################################
893 /**
894 * Checks to see if a POST refer is actually from us
895 *
896 * @access public
897 */
898 function exec_referer_check()
899 {
900 if ($_SERVER['REQUEST_METHOD'] == 'POST')
901 {
902 $host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
903
904 if ($host AND $_SERVER['HTTP_REFERER'])
905 {
906 $parts = parse_url($_SERVER['HTTP_REFERER']);
907 $ourhost = $parts['host'] . (isset($parts['port']) ? ":$parts[port]" : '');
908
909 if ($ourhost != $host)
910 {
911 trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR);
912 }
913 $this->debug('remote post check = ok');
914 }
915 else
916 {
917 $this->debug('remote post check = FAILED');
918 }
919 }
920 }
921
922 // ###################################################################
923 /**
924 * Constructs a debug information box that contains various debugging
925 * information points
926 *
927 * @access public
928 *
929 * @param bool Show template information?
930 *
931 * @return string Debugging block
932 */
933 function construct_debug_block($dotemplates)
934 {
935 $debug = '';
936
937 if ($this->debug)
938 {
939 $debug = "\n<ul>";
940
941 // templates
942 if ($dotemplates)
943 {
944 // both template and template_fs are viable, so we need to determine the right one
945 if ($this->is_loaded('template'))
946 {
947 $tpl_obj =& $this->modules['template'];
948 }
949 else if ($this->is_loaded('template_fs'))
950 {
951 $tpl_obj =& $this->modules['template_fs'];
952 }
953 else
954 {
955 $tpl_obj = null;
956 }
957
958 $optlist = array();
959 $usage = array();
960 foreach ($tpl_obj->usage AS $name => $count)
961 {
962 if (in_array($name, $tpl_obj->uncached))
963 {
964 $optlist[] = $name . '[' . $count . ']';
965 }
966 $usage[] = $name . " ($count)";
967 }
968
969 $sizeof = sizeof($tpl_obj->uncached);
970 if ($sizeof > 0)
971 {
972 $debug .= "\n\t<li><strong style=\"color: red\">Uncached Template(s):</strong> $sizeof ( " . implode(' &nbsp; ', $optlist) . " )</li>";
973 }
974 }
975
976 // source control
977 $scinfo = 'Not Under Source Control';
978 if (defined('SVN'))
979 {
980 $scinfo = constant('SVN');
981
982 if (preg_match('#\$Id:?\s*\$#', $scinfo))
983 {
984 $scinfo = 'Not Under Source Control';
985 }
986 else
987 {
988 $scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo);
989 $scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo);
990 $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);
991 }
992 }
993
994 $scinfo = trim($scinfo);
995 $debug .= "\n\t<li><strong>Source Control:</strong> $scinfo</li>";
996
997 // query information
998 if (is_object($this->modules[ISSO_DB_LAYER]))
999 {
1000 $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>";
1001 }
1002
1003 // total execution time
1004 if (defined('ISSO_MT_START'))
1005 {
1006 $this->load('functions', 'functions');
1007 $debug .= "\n\t<li><strong>Total Execution Time:</strong> " . round($this->modules['functions']->fetch_microtime_diff(ISSO_MT_START), 10) . "</li>";
1008 }
1009
1010 // debug notices
1011 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Debug Notices (" . sizeof($this->debuginfo) . ")</option>";
1012 foreach ((array)$this->debuginfo AS $msg)
1013 {
1014 $debug .= "\n\t\t\t<option>--- $msg</option>";
1015 }
1016 $debug .= "\n\t\t</select>\n\t</li>";
1017
1018 // loaded modules
1019 $modules = $this->show_modules(true);
1020 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Loaded Modules (" . sizeof($modules) . ")</option>";
1021 foreach ($modules AS $mod)
1022 {
1023 $debug .= "\n\t\t\t<option>--- $mod</option>";
1024 }
1025 $debug .= "\n\t\t</select>\n\t</li>";
1026
1027 // template usage
1028 if ($dotemplates)
1029 {
1030 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Template Usage (" . array_sum($tpl_obj->usage) . ")</option>";
1031 foreach ($usage AS $tpl)
1032 {
1033 $debug .= "\n\t\t\t<option>--- $tpl</option>";
1034 }
1035 $debug .= "\n\t\t</select>\n\t</li>";
1036 }
1037
1038 $debug .= "\n</ul>";
1039
1040 $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";
1041 }
1042
1043 return $debug;
1044 }
1045 }
1046
1047 /*=====================================================================*\
1048 || ###################################################################
1049 || # $HeadURL$
1050 || # $Id$
1051 || ###################################################################
1052 \*=====================================================================*/
1053 ?>