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 (PHP_VERSION
< '4.1.0')
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()
151 var $input = array();
156 * If we are running with magic_quotes_gpc on or off
158 * @see escape(), exec_sanitize_data()
160 var $magicquotes = 0;
163 * If we should automagically escape strings, mimicking magic_quotes_gpc
165 * @see exec_sanitize_data()
167 var $escapestrings = false;
172 function Shared_Object_Framework()
175 set_error_handler(array(&$this, '_error_handler'));
178 $this->magicquotes
= get_magic_quotes_gpc();
179 set_magic_quotes_runtime(0);
181 if (defined('ISSO_ESCAPE_STRINGS'))
183 $this->escapestrings
= (bool)constant('ISSO_ESCAPE_STRINGS');
186 // start input sanitize using variable_order GP
187 if (!$this->escapestrings
)
189 $this->exec_sanitize_data();
192 $this->modules
['kernel'] = 'Shared Object Framework Core';
196 * Prepares a path for being set as the sourcepath
198 * @param str Source path or URL
200 * @return str Prepared source path
202 function fetch_sourcepath($source)
204 if (substr($source, strlen($source) - 1) != '/')
212 * Loads a framework extension
214 * @param str Name of the framework
216 function load($framework)
218 if (!$this->is_loaded($framework))
220 $newobj = $this->locate($framework);
221 $this->$newobj['OBJ'] = new $newobj['CLASS']();
222 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
223 $this->modules
["$framework"] = $newobj['OBJECT'];
228 * Includes a framework module. Module definitions need three variables:
229 * class, object, and obj. Class is the name of the class, object is
230 * the name human-readable name, and obj is the name that the module
231 * should be initialized as; this is used in class extensions.
233 * @param str Name of the framework
235 * @return array List of initialization variables
237 function locate($framework)
239 if ($this->sourcepath == '')
241 trigger_error('Invalid sourcepath specified', E_USER_ERROR);
244 if (file_exists($this->sourcepath . $framework . '.php'))
246 require_once($this->sourcepath . $framework . '.php');
247 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
251 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR);
257 * Prints a list of all currently loaded framework modules
259 * @param bool Return the data as an array?
261 * @return mixed HTML output or an array of loaded modules
263 function show_modules($return = false)
267 return $this->modules;
271 $output = "\n\n
<ul
>\n\t<li
>";
272 $output .= implode("</li
>\n\t<li
>", $this->modules);
273 $output .= "</li
>\n</ul
>\n\n";
274 $this->_message('Loaded Modules', $output, 1);
279 * Verifies to see if a framework has been loaded
281 * @param str Framework name
283 * @return bool Whether or not the framework has been loaded
285 function is_loaded($framework)
287 if (isset($this->modules["$framework"]))
298 * Prints an ISSO message
300 * @param str The title of the message
301 * @param str The content of the message
302 * @param int Type of message to be printed
303 * @param bool Return the output?
305 * @return mixed Output or null
307 function _message($title, $message, $type, $return = false)
332 $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;\">";
333 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
334 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
347 * Custom error handler for ISSO
348 * We only handle E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
350 * @param int Error number
351 * @param str Error message string
352 * @param str File that contains the error
353 * @param str The line number of the error
354 * @param str The active symbol table at which point the error occurred
356 function _error_handler($errno, $errstr, $errfile, $errline)
363 if (!(ini_get('error_reporting') & E_USER_ERROR
))
372 if (!(ini_get('error_reporting') & E_USER_WARNING
) AND !(ini_get('error_reporting') & E_WARNING
))
382 if (!(ini_get('error_reporting') & E_USER_NOTICE
) AND !(ini_get('error_reporting') & E_NOTICE
))
389 $errfile = str_replace(getcwd(), '', $errfile);
391 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
393 $this->_message($title, $errstr, 3);
395 if ($errno == E_USER_ERROR
)
402 * Logs a debug message for verbose output
406 function debug($message)
408 $this->debuginfo
[] = $message;
412 * Recursive XSS cleaner
414 * @param mixed Unsanitized REQUEST data
416 * @return mixed Sanitized data
418 function _sanitize_input_recursive($data)
420 foreach ($data AS $key => $value)
422 if (is_array($value))
424 $data["$key"] = $this->_sanitize_input_recursive($value);
428 if ($this->escapestrings)
430 $data["$key"] = $this->escape($this->sanitize($value));
434 $data["$key"] = $this->sanitize($value);
442 * Simple way to protect against HTML attacks with Unicode support
444 * @param str Unsanitzed text
446 * @return str Properly protected text that only encodes potential threats
448 function sanitize($text)
450 if ($this->magicquotes)
452 return str_replace(array('<', '>', '\"', '"'), array('<
;', '>
;', '"
;', '"
;'), $text);
456 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
461 * Takes text that has been processed for HTML and unsanitizes it
463 * @param str Text that needs to be turned back into HTML
464 * @param bool Force magicquotes off
466 * @return str Unsanitized text
468 function unsanitize($text, $force = false)
470 if ($this->magicquotes AND !$force)
472 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
476 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
481 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
483 * @param str Some string
484 * @param bool If the data is binary; if so it'll be run through DB
::escape_string()
485 * @param
bool Force magic quotes to be off
487 * @return str
String that has slashes added
489 function escape($str, $binary = false, $force = false)
493 if ($this->magicquotes
AND !$force)
495 if (isset($_isso->db
) AND $binary)
497 if (is_resource($_isso->db
->link_id
))
499 return $_isso->db
->escape_string(stripslashes($str));
506 if (isset($_isso->db
) AND $binary)
508 if (is_resource($_isso->db
->link_id
))
510 return $_isso->db
->escape_string($str);
513 return addslashes($str);
518 * Runs through all of the input data and sanitizes it.
520 function exec_sanitize_data()
522 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
523 $this->i
=& $this->input
;
524 $this->in
=& $this->input
;
525 // we're now using magic quotes
526 if ($this->escapestrings
)
528 $this->magicquotes
= 1;
534 * Global callback used for module calls back to the kernel
536 $_isso = new Shared_Object_Framework();
539 * Wrapper for ternary operator that has to be in the global scope.
540 * This function is going to be removed from our applications due
541 * to it's latency in processing. This will remain here purely
542 * for legacy reasons. It will be removed when necessary.
544 * @deprecated The normal ternary operators should be used instead; function calls are too expensive
546 * @param expr Expression
547 * @param mixed If the expression is true
548 * @param mixed If the expression is false
550 * @return mixed True or false data
552 function iff($condition, $iftrue, $iffalse = null)
554 return ($condition) ? ($iftrue) : ($iffalse);
557 if (defined('ISSO_CHECK_POST_REFERER'))
559 if ($_SERVER['REQUEST_METHOD'] == 'POST')
561 $host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
562 $parts = parse_url($_SERVER['HTTP_REFERER']);
563 $ourhost = $parts['host'] . (($parts['port']) ? ":$parts[port]" : '');
565 if ($ourhost != $host)
567 trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR
);
569 $_isso->debug('remote post check = ok');
573 /*=====================================================================*\
574 || ###################################################################
577 || ###################################################################
578 \*=====================================================================*/