2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Iris Studios Shared Object Framework Kernel
20 if (!function_exists('version_compare'))
22 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', E_USER_ERROR
);
26 if (version_compare(PHP_VERSION
, '5.0.0', '>='))
28 if (ini_get('error_reporting') & E_NOTICE
)
30 error_reporting(ini_get('error_reporting') - E_NOTICE
);
32 if (ini_get('error_reporting') & E_USER_NOTICE
)
34 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
38 $oldlevel = ini_get('error_reporting');
39 $newlevel = $oldlevel;
40 $levels = array(E_ERROR
=> E_USER_ERROR
, E_WARNING
=> E_USER_WARNING
, E_NOTICE
=> E_USER_NOTICE
);
41 foreach ($levels AS $php => $isso)
45 if (!($oldlevel & $isso))
47 //echo "increasing newlevel by $isso; ";
53 if ($oldlevel & $isso)
55 //echo "decreasing newlevel by $isso; ";
60 error_reporting($newlevel);
62 if ((bool)ini_get('register_globals') === true)
64 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
65 foreach ($superglobals AS $global)
67 if (is_array(${$global}))
69 foreach (${$global} AS $_key => $_val)
81 * Iris Studios Shared Object Framework (ISSO)
83 * This framework allows a common backend to be used amongst all Iris
84 * Studios applications and is built to be abstract and flexible.
85 * The base framework handles all loading and module management.
87 * @author Iris Studios, Inc.
88 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
93 class Shared_Object_Framework
99 var $version = '[#]version[#]';
102 * Location of ISSO, used for internal linking
104 * @see fetch_sourcepath(), load(), locate()
106 var $sourcepath = '';
109 * Path of the current application
115 * Name of the current application
118 var $application = '';
121 * Version of the current application
124 var $appversion = '';
127 * Whether debug mode is on or off
133 * List of all active debug messages
137 var $debuginfo = array();
140 * List of loaded modules
142 * @see load(), show_modules()
144 var $modules = array();
147 * An array of sanitized variables that have been cleaned for HTML tag openers and double quotes
149 * @see sanitize(), exec_sanitize_data()
154 * If we are running with magic_quotes_gpc on or off
156 * @see escape(), exec_sanitize_data()
158 var $magicquotes = 0;
161 * If we should automagically escape strings, mimicking magic_quotes_gpc
163 * @see exec_sanitize_data()
165 var $escapestrings = false;
170 function Shared_Object_Framework()
173 set_error_handler(array(&$this, '_error_handler'));
176 $this->magicquotes
= get_magic_quotes_gpc();
177 set_magic_quotes_runtime(0);
179 if (defined('ISSO_ESCAPE_STRINGS'))
181 $this->escapestrings
= (bool)constant('ISSO_ESCAPE_STRINGS');
184 // start input sanitize using variable_order GPC
185 if (!$this->escapestrings
)
187 $this->exec_sanitize_data();
190 $this->modules
['kernel'] = 'Shared Object Framework Core';
194 * Prepares a path for being set as the sourcepath
196 * @param str Source path or URL
198 * @return str Prepared source path
200 function fetch_sourcepath($source)
202 if (substr($source, strlen($source) - 1) != '/')
210 * Loads a framework extension
212 * @param str Name of the framework
214 function load($framework)
216 if (!$this->is_loaded($framework))
218 $newobj = $this->locate($framework);
219 $this->$newobj['OBJ'] = new $newobj['CLASS']();
220 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
221 $this->modules
["$framework"] = $newobj['OBJECT'];
226 * Includes a framework module. Module definitions need three variables:
227 * class, object, and obj. Class is the name of the class, object is
228 * the name human-readable name, and obj is the name that the module
229 * should be initialized as; this is used in class extensions.
231 * @param str Name of the framework
233 * @return array List of initialization variables
235 function locate($framework)
237 if ($this->sourcepath == '')
239 trigger_error('Invalid sourcepath specified', E_USER_ERROR);
242 if (file_exists($this->sourcepath . $framework . '.php'))
244 require_once($this->sourcepath . $framework . '.php');
245 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
249 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR);
255 * Prints a list of all currently loaded framework modules
257 * @param bool Return the data as an array?
259 * @return mixed HTML output or an array of loaded modules
261 function show_modules($return = false)
265 return $this->modules;
269 $output = "\n\n
<ul
>\n\t<li
>";
270 $output .= implode("</li
>\n\t<li
>", $this->modules);
271 $output .= "</li
>\n</ul
>\n\n";
272 $this->_message('Loaded Modules', $output, 1);
277 * Verifies to see if a framework has been loaded
279 * @param str Framework name
281 * @return bool Whether or not the framework has been loaded
283 function is_loaded($framework)
285 if (isset($this->modules["$framework"]))
296 * Prints an ISSO message
298 * @param str The title of the message
299 * @param str The content of the message
300 * @param int Type of message to be printed
301 * @param bool Return the output?
303 * @return mixed Output or null
305 function _message($title, $message, $type, $return = false)
330 $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;\">";
331 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
332 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
345 * Custom error handler for ISSO
346 * We only handle E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
348 * @param int Error number
349 * @param str Error message string
350 * @param str File that contains the error
351 * @param str The line number of the error
352 * @param str The active symbol table at which point the error occurred
354 function _error_handler($errno, $errstr, $errfile, $errline)
361 if (!(ini_get('error_reporting') & E_USER_ERROR
))
370 if (!(ini_get('error_reporting') & E_USER_WARNING
) AND !(ini_get('error_reporting') & E_WARNING
))
380 if (!(ini_get('error_reporting') & E_USER_NOTICE
) AND !(ini_get('error_reporting') & E_NOTICE
))
387 $errfile = str_replace(getcwd(), '', $errfile);
389 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
391 $this->_message($title, $errstr, 3);
393 if ($errno == E_USER_ERROR
)
400 * Logs a debug message for verbose output
404 function debug($message)
406 $this->debuginfo
[] = $message;
410 * Recursive XSS cleaner
412 * @param mixed Unsanitized REQUEST data
414 * @return mixed Sanitized data
416 function _sanitize_input_recursive($data)
418 foreach ($data AS $key => $value)
420 if (is_array($value))
422 $data["$key"] = $this->_sanitize_input_recursive($value);
426 if ($this->escapestrings)
428 $data["$key"] = $this->escape($this->sanitize($value), false, false);
432 $data["$key"] = $this->sanitize($value);
440 * Simple way to protect against HTML attacks with Unicode support
442 * @param str Unsanitzed text
444 * @return str Properly protected text that only encodes potential threats
446 function sanitize($text)
448 if ($this->magicquotes)
450 return str_replace(array('<', '>', '\"', '"'), array('<
;', '>
;', '"
;', '"
;'), $text);
454 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
459 * Takes text that has been processed for HTML and unsanitizes it
461 * @param str Text that needs to be turned back into HTML
462 * @param bool Force magicquotes off
464 * @return str Unsanitized text
466 function unsanitize($text, $force = false)
468 if ($this->magicquotes AND !$force)
470 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
474 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
479 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
481 * @param str Some string
482 * @param bool If the data is binary; if so it'll be run through DB
::escape_string()
483 * @param
bool Force magic quotes to be off
485 * @return str
String that has slashes added
487 function escape($str, $binary = false, $force = true)
491 if ($this->magicquotes
AND !$force)
493 if (isset($_isso->db
) AND $binary)
495 if (is_resource($_isso->db
->link_id
))
497 return $_isso->db
->escape_string(stripslashes($str));
504 if (isset($_isso->db
) AND $binary)
506 if (is_resource($_isso->db
->link_id
))
508 return $_isso->db
->escape_string($str);
511 return addslashes($str);
516 * Runs through all of the input data and sanitizes it.
518 function exec_sanitize_data()
520 $this->in
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST, $_COOKIE));
521 // we're now using magic quotes
522 if ($this->escapestrings
)
524 $this->magicquotes
= 1;
530 * Global callback used for module calls back to the kernel
532 $_isso = new Shared_Object_Framework();
535 * Wrapper for ternary operator that has to be in the global scope.
536 * This function is going to be removed from our applications due
537 * to it's latency in processing. This will remain here purely
538 * for legacy reasons. It will be removed when necessary.
540 * @deprecated The normal ternary operators should be used instead; function calls are too expensive
542 * @param expr Expression
543 * @param mixed If the expression is true
544 * @param mixed If the expression is false
546 * @return mixed True or false data
548 function iff($condition, $iftrue, $iffalse = null)
550 return ($condition) ? ($iftrue) : ($iffalse);
553 if (defined('ISSO_CHECK_POST_REFERER'))
555 if ($_SERVER['REQUEST_METHOD'] == 'POST')
557 $host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
558 $parts = parse_url($_SERVER['HTTP_REFERER']);
559 $ourhost = $parts['host'] . (($parts['port']) ? ":$parts[port]" : '');
561 if ($ourhost != $host)
563 trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR
);
565 $_isso->debug('remote post check = ok');
569 /*=====================================================================*\
570 || ###################################################################
573 || ###################################################################
574 \*=====================================================================*/