]>
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 ((bool)ini_get('register_globals') === true)
33 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
34 foreach ($superglobals AS $global)
36 if (is_array(${$global}))
38 foreach (${$global} AS $_key => $_val)
50 * Iris Studios Shared Object Framework (ISSO)
52 * This framework allows a common backend to be used amongst all Iris
53 * Studios applications and can is built to be abstract and flexible.
54 * The base framework handles all loading and module management.
56 * @author Iris Studios, Inc.
57 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
61 class Shared_Object_Framework
64 * Global environment variables
66 * This is where we keep the global variables that are used within the shared framework
68 * @var version ISSO version
69 * @var sourcepath The location of the framework sources
70 * @var appath The path to the application's location
71 * @var application The name of the application that is using the framework
72 * @var debug Variable for debug mode
73 * @var debuginfo Listing of all debug notices
74 * @var modules An array of loaded framework modules
75 * @var input All input data for the system
76 * @var i Short-hand reference to $isso::input
77 * @var in Short-hand reference to $isso::input
78 * @var magicquotes Status of Magic Quotes GPC
80 var $version = '[#]version[#]';
83 var $application = '';
85 var $debuginfo = array();
86 var $modules = array();
95 function Shared_Object_Framework()
98 set_error_handler(array(&$this, '_error_handler'));
101 $this->magicquotes
= get_magic_quotes_gpc();
102 set_magic_quotes_runtime(0);
104 // start input sanitize using variable_order GP
105 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
106 $this->i
=& $this->input
;
107 $this->in
=& $this->input
;
109 $this->modules
['kernel'] = 'Shared Object Framework Core';
113 * Prepares a path for being set as the sourcepath
115 * @param str Source path or URL
117 * @return str Prepared source path
119 function fetch_sourcepath($source)
121 if (substr($source, strlen($source) - 1) != '/')
129 * Loads a framework extension
131 * @param str Name of the framework
133 function load($framework)
135 if (!$this->is_loaded($framework))
137 $newobj = $this->locate($framework);
138 $this->$newobj['OBJ'] = new $newobj['CLASS']();
139 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
140 $this->modules
["$framework"] = $newobj['OBJECT'];
145 * Includes a framework module. Module definitions need three variables:
146 * class, object, and obj. Class is the name of the class, object is
147 * the name human-readable name, and obj is the name that the module
148 * should be initialized as; this is used in class extensions.
150 * @param str Name of the framework
152 * @return array List of initialization variables
154 function locate($framework)
156 if ($this->sourcepath == '')
158 trigger_error('Invalid sourcepath specified', ERR_FATAL);
161 if (file_exists($this->sourcepath . $framework . '.php'))
163 require_once($this->sourcepath . $framework . '.php');
164 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
168 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', ERR_FATAL);
174 * Prints a list of all currently loaded framework modules
176 * @param bool Return the data as an array?
178 * @return mixed HTML output or an array of loaded modules
180 function show_modules($return = false)
184 return $this->modules;
188 $output = "\n\n
<ul
>\n\t<li
>";
189 $output .= implode("</li
>\n\t<li
>", $this->modules);
190 $output .= "</li
>\n</ul
>\n\n";
191 $this->_message('Loaded Modules', $output, 1);
196 * Verifies to see if a framework has been loaded
198 * @param str Framework name
200 * @return bool Whether or not the framework has been loaded
202 function is_loaded($framework)
204 if (isset($this->modules["$framework"]))
215 * Prints an ISSO message
217 * @param str The title of the message
218 * @param str The content of the message
219 * @param int Type of message to be printed
220 * @param bool Return the output?
222 * @return mixed Output or null
224 function _message($title, $message, $type, $return = false)
249 $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;\">";
250 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
251 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
264 * Custom error handler for ISSO
266 * @param int Error number
267 * @param str Error message string
268 * @param str File that contains the error
269 * @param str The line number of the error
270 * @param str The active symbol table at which point the error occurred
272 function _error_handler($errno, $errstr, $errfile, $errline)
279 if (!(ini_get('error_reporting') & ERR_FATAL
))
288 if (!(ini_get('error_reporting') & ERR_ALERT
))
298 if (!(ini_get('error_reporting') & ERR_WARNING
))
305 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
307 $this->_message($title, $errstr, 3);
309 if ($errno == ERR_FATAL
)
316 * Logs a debug message for verbose output
320 function debug($message)
324 $this->debuginfo
[] = $message;
329 * Recursive XSS cleaner
331 * @param mixed Unsanitized REQUEST data
333 * @return mixed Sanitized data
335 function _sanitize_input_recursive($data)
337 foreach($data AS $key => $value)
339 if (is_array($value))
341 $data["$key"] = $this->_sanitize_input_recursive($value);
345 $data["$key"] = $this->sanitize($value);
352 * Simple way to protect against HTML attacks with Unicode support
354 * @param str Unsanitzed text
356 * @return str Properly protected text that only encodes potential threats
358 function sanitize($text)
360 if ($this->magicquotes
)
362 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
366 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
371 * Takes text that has been processed for HTML and unsanitizes it
373 * @param str Text that needs to be turned back into HTML
375 * @return str Unsanitized text
377 function unsanitize($text)
379 if ($this->magicquotes
)
381 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
385 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
390 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
392 * @param str Some string
394 * @return str String that has slashes added
396 function escape($str)
400 if ($this->magicquotes
)
406 if (isset($_isso->db
))
408 if (is_resource($_isso->db
->link_id
))
410 return $_isso->db
->escape_string($str);
414 return addslashes($str);
419 return addslashes($str);
426 * Global callback used for module calls back to the kernel
428 $_isso = new Shared_Object_Framework();
431 * Wrapper for ternary operator that has to be in the global scope
433 * @param expr Expression
434 * @param mixed If the expression is true
435 * @param mixed If the expression is false
437 * @return mixed True or false data
439 function iff($condition, $iftrue, $iffalse = null)
441 return ($condition) ? ($iftrue) : ($iffalse);
444 /*=====================================================================*\
445 || ###################################################################
448 || ###################################################################
449 \*=====================================================================*/