Moving some checks from kernel.php to Loader.php
[isso.git] / kernel.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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 * Blue Static ISSO Framework Kernel
24 * kernel.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Yes, required
31 */
32 define('REQ_YES', 1);
33
34 /**
35 * No, not required
36 */
37 define('REQ_NO', 0);
38
39 /**
40 * Blue Static ISSO Framework (ISSO)
41 *
42 * This framework allows a common backend to be used amongst all Blue
43 * Static applications and is built to be abstract and flexible.
44 * The base framework handles all loading and module management.
45 *
46 * Constants:
47 * ISSO_MT_START - Define the microtime() value at the top of your
48 * script and this will calculate the total execution
49 * time
50 * SVN - Place SVN keywords (like $Id) to display the information on output
51 *
52 * @author Blue Static
53 * @copyright Copyright ©2002 - [#]year[#], Blue Static
54 * @version $Revision$
55 * @package ISSO
56 *
57 */
58 class ISSO
59 {
60 /**
61 * ISSO version
62 * @var string
63 */
64 private $version = '[#]issoversion[#]';
65
66 /**
67 * List of loaded modules
68 * @var array
69 */
70 private $modules = array();
71
72 // ###################################################################
73 /**
74 * Prints a list of all currently loaded framework modules
75 *
76 * @param bool Return the data as an array?
77 *
78 * @return mixed HTML output or an array of loaded modules
79 */
80 public function show_modules($return = false)
81 {
82 $modules = array();
83 foreach ($this->modules AS $object)
84 {
85 $module = get_class($object);
86 if (method_exists($object, 'init_as_package') AND in_array($module, $modules))
87 {
88 $module = $object->init_as_package() . " - ($module)";
89 }
90
91 $modules[] = $module;
92 }
93
94 if ($return)
95 {
96 return $modules;
97 }
98 else
99 {
100 $output = "\n\n<ul>\n\t<li>";
101 $output .= implode("</li>\n\t<li>", $modules);
102 $output .= "</li>\n</ul>\n\n";
103 $this->message('Loaded Modules', $output, 1);
104 }
105 }
106
107 // ###################################################################
108 /**
109 * Constructs a debug information box that contains various debugging
110 * information points
111 *
112 * @param bool Show template information?
113 *
114 * @return string Debugging block
115 */
116 public function construct_debug_block($dotemplates)
117 {
118 $debug = '';
119
120 if ($this->debug)
121 {
122 $debug = "\n<ul>";
123
124 // templates
125 if ($dotemplates)
126 {
127 $optlist = array();
128 $usage = array();
129 foreach ($this->modules['template']->usage AS $name => $count)
130 {
131 if (in_array($name, $this->modules['template']->uncached))
132 {
133 $optlist[] = $name . '[' . $count . ']';
134 }
135 $usage[] = $name . " ($count)";
136 }
137
138 $sizeof = sizeof($this->modules['template']->uncached);
139 if ($sizeof > 0)
140 {
141 $debug .= "\n\t<li><strong style=\"color: red\">Uncached Template(s):</strong> $sizeof ( " . implode(' &nbsp; ', $optlist) . " )</li>";
142 }
143 }
144
145 // source control
146 $scinfo = 'Not Under Source Control';
147 if (defined('SVN'))
148 {
149 $scinfo = constant('SVN');
150
151 if (preg_match('#\$Id:?\s*\$#', $scinfo))
152 {
153 $scinfo = 'Not Under Source Control';
154 }
155 else
156 {
157 $scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo);
158 $scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo);
159 $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);
160 }
161 }
162
163 $scinfo = trim($scinfo);
164 $debug .= "\n\t<li><strong>Source Control:</strong> $scinfo</li>";
165
166 // query information
167 if (is_object($this->modules[ISSO_DB_LAYER]))
168 {
169 $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>";
170 }
171
172 // total execution time
173 if (defined('ISSO_MT_START'))
174 {
175 $this->load('functions', 'functions');
176 $debug .= "\n\t<li><strong>Total Execution Time:</strong> " . round($this->modules['functions']->fetch_microtime_diff(ISSO_MT_START), 10) . "</li>";
177 }
178
179 // debug notices
180 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Debug Notices (" . sizeof($this->debuginfo) . ")</option>";
181 foreach ((array)$this->debuginfo AS $msg)
182 {
183 $debug .= "\n\t\t\t<option>--- $msg</option>";
184 }
185 $debug .= "\n\t\t</select>\n\t</li>";
186
187 // loaded modules
188 $modules = $this->show_modules(true);
189 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Loaded Modules (" . sizeof($modules) . ")</option>";
190 foreach ($modules AS $mod)
191 {
192 $debug .= "\n\t\t\t<option>--- $mod</option>";
193 }
194 $debug .= "\n\t\t</select>\n\t</li>";
195
196 // template usage
197 if ($dotemplates)
198 {
199 $debug .= "\n\t<li>\n\t\t<select>\n\t\t\t<option>Template Usage (" . array_sum($this->modules['template']->usage) . ")</option>";
200 foreach ($usage AS $tpl)
201 {
202 $debug .= "\n\t\t\t<option>--- $tpl</option>";
203 }
204 $debug .= "\n\t\t</select>\n\t</li>";
205 }
206
207 $debug .= "\n</ul>";
208
209 $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";
210 }
211
212 return $debug;
213 }
214 }
215
216 /*=====================================================================*\
217 || ###################################################################
218 || # $HeadURL$
219 || # $Id$
220 || ###################################################################
221 \*=====================================================================*/
222 ?>