]>
src.bluestatic.org Git - isso.git/blob - kernel.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 define('ERR_FATAL', E_USER_ERROR
);
14 define('ERR_ALERT', E_USER_WARNING
);
15 define('ERR_WARNING', E_USER_NOTICE
);
17 if (PHP_VERSION
< '4.1.0')
19 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', ERR_FATAL
);
23 if (PHP_VERSION
> '5.0.0')
25 if (ini_get('error_reporting') & E_USER_NOTICE
)
27 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
31 if (!(ini_get('error_reporting') & E_NOTICE
))
33 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
36 if (!(ini_get('error_reporting') & E_WARNING
))
38 error_reporting(ini_get('error_reporting') - E_USER_WARNING
);
41 if (!(ini_get('error_reporting') & E_ERROR
))
43 error_reporting(ini_get('error_reporting') - E_USER_ERROR
);
46 if ((bool)ini_get('register_globals') === true)
48 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
49 foreach ($superglobals AS $global)
51 if (is_array(${$global}))
53 foreach (${$global} AS $_key => $_val)
65 * Iris Studios Shared Object Framework (ISSO)
67 * This framework allows a common backend to be used amongst all Iris
68 * Studios applications and can is built to be abstract and flexible.
69 * The base framework handles all loading and module management.
71 * @author Iris Studios, Inc.
72 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
76 class Shared_Object_Framework
79 * Global environment variables
81 * This is where we keep the global variables that are used within the shared framework
83 * @var version ISSO version
84 * @var sourcepath The location of the framework sources
85 * @var appath The path to the application's location
86 * @var application The name of the application that is using the framework
87 * @var debug Variable for debug mode
88 * @var debuginfo Listing of all debug notices
89 * @var modules An array of loaded framework modules
90 * @var input All input data for the system
91 * @var i Short-hand reference to $isso::input
92 * @var in Short-hand reference to $isso::input
93 * @var magicquotes Status of Magic Quotes GPC
95 var $version = '[#]version[#]';
98 var $application = '';
100 var $debuginfo = array();
101 var $modules = array();
102 var $input = array();
105 var $magicquotes = 0;
110 function Shared_Object_Framework()
113 set_error_handler(array(&$this, '_error_handler'));
116 $this->magicquotes
= get_magic_quotes_gpc();
117 set_magic_quotes_runtime(0);
119 // start input sanitize using variable_order GP
120 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
121 $this->i
=& $this->input
;
122 $this->in
=& $this->input
;
124 $this->modules
['kernel'] = 'Shared Object Framework Core';
128 * Prepares a path for being set as the sourcepath
130 * @param str Source path or URL
132 * @return str Prepared source path
134 function fetch_sourcepath($source)
136 if (substr($source, strlen($source) - 1) != '/')
144 * Loads a framework extension
146 * @param str Name of the framework
148 function load($framework)
150 if (!$this->is_loaded($framework))
152 $newobj = $this->locate($framework);
153 $this->$newobj['OBJ'] = new $newobj['CLASS']();
154 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
155 $this->modules
["$framework"] = $newobj['OBJECT'];
160 * Includes a framework module. Module definitions need three variables:
161 * class, object, and obj. Class is the name of the class, object is
162 * the name human-readable name, and obj is the name that the module
163 * should be initialized as; this is used in class extensions.
165 * @param str Name of the framework
167 * @return array List of initialization variables
169 function locate($framework)
171 if ($this->sourcepath == '')
173 trigger_error('Invalid sourcepath specified', ERR_FATAL);
176 if (file_exists($this->sourcepath . $framework . '.php'))
178 require_once($this->sourcepath . $framework . '.php');
179 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
183 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', ERR_FATAL);
189 * Prints a list of all currently loaded framework modules
191 * @param bool Return the data as an array?
193 * @return mixed HTML output or an array of loaded modules
195 function show_modules($return = false)
199 return $this->modules;
203 $output = "\n\n
<ul
>\n\t<li
>";
204 $output .= implode("</li
>\n\t<li
>", $this->modules);
205 $output .= "</li
>\n</ul
>\n\n";
206 $this->_message('Loaded Modules', $output, 1);
211 * Verifies to see if a framework has been loaded
213 * @param str Framework name
215 * @return bool Whether or not the framework has been loaded
217 function is_loaded($framework)
219 if (isset($this->modules["$framework"]))
230 * Prints an ISSO message
232 * @param str The title of the message
233 * @param str The content of the message
234 * @param int Type of message to be printed
235 * @param bool Return the output?
237 * @return mixed Output or null
239 function _message($title, $message, $type, $return = false)
264 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"500\" style=\"background-color: $color; font-family: Verdana, sans-serif; font-size: 12px;\">";
265 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
266 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
279 * Custom error handler for ISSO
281 * @param int Error number
282 * @param str Error message string
283 * @param str File that contains the error
284 * @param str The line number of the error
285 * @param str The active symbol table at which point the error occurred
287 function _error_handler($errno, $errstr, $errfile, $errline)
294 if (!(ini_get('error_reporting') & ERR_FATAL
))
303 if (!(ini_get('error_reporting') & ERR_ALERT
))
313 if (!(ini_get('error_reporting') & ERR_WARNING
))
320 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
322 $this->_message($title, $errstr, 3);
324 if ($errno == ERR_FATAL
)
331 * Logs a debug message for verbose output
335 function debug($message)
339 $this->debuginfo
[] = $message;
344 * Recursive XSS cleaner
346 * @param mixed Unsanitized REQUEST data
348 * @return mixed Sanitized data
350 function _sanitize_input_recursive($data)
352 foreach($data AS $key => $value)
354 if (is_array($value))
356 $data["$key"] = $this->_sanitize_input_recursive($value);
360 $data["$key"] = $this->sanitize($value);
367 * Simple way to protect against HTML attacks with Unicode support
369 * @param str Unsanitzed text
371 * @return str Properly protected text that only encodes potential threats
373 function sanitize($text)
375 if ($this->magicquotes
)
377 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
381 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
386 * Takes text that has been processed for HTML and unsanitizes it
388 * @param str Text that needs to be turned back into HTML
390 * @return str Unsanitized text
392 function unsanitize($text)
394 if ($this->magicquotes
)
396 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
400 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
405 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
407 * @param str Some string
409 * @return str String that has slashes added
411 function escape($str)
415 if ($this->magicquotes
)
421 if (isset($_isso->db
))
423 if (is_resource($_isso->db
->link_id
))
425 return $_isso->db
->escape_string($str);
429 return addslashes($str);
434 return addslashes($str);
441 * Global callback used for module calls back to the kernel
443 $_isso = new Shared_Object_Framework();
446 * Wrapper for ternary operator that has to be in the global scope
448 * @param expr Expression
449 * @param mixed If the expression is true
450 * @param mixed If the expression is false
452 * @return mixed True or false data
454 function iff($condition, $iftrue, $iffalse = null)
456 return ($condition) ? ($iftrue) : ($iffalse);
459 /*=====================================================================*\
460 || ###################################################################
463 || ###################################################################
464 \*=====================================================================*/