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