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 \*=====================================================================*/
13 if (PHP_VERSION
< '4.1.0')
15 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', E_USER_ERROR
);
19 if (version_compare(PHP_VERSION
, '5.0.0', '>='))
21 if (ini_get('error_reporting') & E_NOTICE
)
23 error_reporting(ini_get('error_reporting') - E_NOTICE
);
25 if (ini_get('error_reporting') & E_USER_NOTICE
)
27 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
31 $oldlevel = ini_get('error_reporting');
32 $newlevel = $oldlevel;
33 $levels = array(E_ERROR
=> E_USER_ERROR
, E_WARNING
=> E_USER_WARNING
, E_NOTICE
=> E_USER_NOTICE
);
34 foreach ($levels AS $php => $isso)
38 if (!($oldlevel & $isso))
40 echo "increasing newlevel by $isso; ";
46 if ($oldlevel & $isso)
48 echo "decreasing newlevel by $isso; ";
53 error_reporting($newlevel);
55 if ((bool
)ini_get('register_globals') === true
)
57 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
58 foreach ($superglobals AS $global)
60 if (is_array($
{$global}))
62 foreach ($
{$global} AS $_key => $_val)
74 * Iris Studios Shared Object Framework (ISSO)
76 * This framework allows a common backend to be used amongst all Iris
77 * Studios applications and can is built to be abstract and flexible.
78 * The base framework handles all loading and module management.
80 * @author Iris Studios, Inc.
81 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
85 class Shared_Object_Framework
88 * Global environment variables
90 * This is where we keep the global variables that are used within the shared framework
92 * @var version ISSO version
93 * @var sourcepath The location of the framework sources
94 * @var appath The path to the application's location
95 * @var application The name of the application that is using the framework
96 * @var appversion The version of the application
97 * @var debug Variable for debug mode
98 * @var debuginfo Listing of all debug notices
99 * @var modules An array of loaded framework modules
100 * @var input All input data for the system
101 * @var i Short-hand reference to $isso::input
102 * @var in Short-hand reference to $isso::input
103 * @var magicquotes Status of Magic Quotes GPC
104 * @var escapestrings Sets whether or not we escape strings automatically
106 var $version = '[#]version[#]';
107 var $sourcepath = '';
109 var $application = '';
110 var $appversion = '';
112 var $debuginfo = array();
113 var $modules = array();
114 var $input = array();
117 var $magicquotes = 0;
118 var $escapestrings = false
;
123 function Shared_Object_Framework()
126 set_error_handler(array(&$this, '_error_handler'));
129 $this->magicquotes
= get_magic_quotes_gpc();
130 set_magic_quotes_runtime(0);
132 if (defined('ISSO_ESCAPE_STRINGS'))
134 $this->escapestrings
= (bool
)constant('ISSO_ESCAPE_STRINGS');
137 // start input sanitize using variable_order GP
138 if (!$this->escapestrings
)
140 $this->exec_sanitize_data();
143 $this->modules
['kernel'] = 'Shared Object Framework Core';
147 * Prepares a path for being set as the sourcepath
149 * @param str Source path or URL
151 * @return str Prepared source path
153 function fetch_sourcepath($source)
155 if (substr($source, strlen($source) - 1) != '/')
163 * Loads a framework extension
165 * @param str Name of the framework
167 function load($framework)
169 if (!$this->is_loaded($framework))
171 $newobj = $this->locate($framework);
172 $this->$newobj['OBJ'] = new $newobj['CLASS']();
173 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
174 $this->modules
["$framework"] = $newobj['OBJECT'];
179 * Includes a framework module. Module definitions need three variables:
180 * class, object, and obj. Class is the name of the class, object is
181 * the name human-readable name, and obj is the name that the module
182 * should be initialized as; this is used in class extensions.
184 * @param str Name of the framework
186 * @return array List of initialization variables
188 function locate($framework)
190 if ($this->sourcepath
== '')
192 trigger_error('Invalid sourcepath specified', E_USER_ERROR
);
195 if (file_exists($this->sourcepath
. $framework . '.php'))
197 require_once($this->sourcepath
. $framework . '.php');
198 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
202 trigger_error('Could not find the framework ' . $this->sourcepath
. $framework . '.php', E_USER_ERROR
);
208 * Prints a list of all currently loaded framework modules
210 * @param bool Return the data as an array?
212 * @return mixed HTML output or an array of loaded modules
214 function show_modules($return = false
)
218 return $this->modules
;
222 $output = "\n\n<ul>\n\t<li>";
223 $output .= implode("</li>\n\t<li>", $this->modules
);
224 $output .= "</li>\n</ul>\n\n";
225 $this->_message('Loaded Modules', $output, 1);
230 * Verifies to see if a framework has been loaded
232 * @param str Framework name
234 * @return bool Whether or not the framework has been loaded
236 function is_loaded($framework)
238 if (isset($this->modules
["$framework"]))
249 * Prints an ISSO message
251 * @param str The title of the message
252 * @param str The content of the message
253 * @param int Type of message to be printed
254 * @param bool Return the output?
256 * @return mixed Output or null
258 function _message($title, $message, $type, $return = false
)
283 $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;\">";
284 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
285 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
298 * Custom error handler for ISSO
299 * We only handle E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
301 * @param int Error number
302 * @param str Error message string
303 * @param str File that contains the error
304 * @param str The line number of the error
305 * @param str The active symbol table at which point the error occurred
307 function _error_handler($errno, $errstr, $errfile, $errline)
314 if (!(ini_get('error_reporting') & E_USER_ERROR
))
323 if (!(ini_get('error_reporting') & E_USER_WARNING
) AND !(ini_get('error_reporting') & E_WARNING
))
333 if (!(ini_get('error_reporting') & E_USER_NOTICE
) AND !(ini_get('error_reporting') & E_NOTICE
))
340 $errfile = str_replace(getcwd(), '', $errfile);
342 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
344 $this->_message($title, $errstr, 3);
346 if ($errno == E_USER_ERROR
)
353 * Logs a debug message for verbose output
357 function debug($message)
359 $this->debuginfo
[] = $message;
363 * Recursive XSS cleaner
365 * @param mixed Unsanitized REQUEST data
367 * @return mixed Sanitized data
369 function _sanitize_input_recursive($data)
371 foreach ($data AS $key => $value)
373 if (is_array($value))
375 $data["$key"] = $this->_sanitize_input_recursive($value);
379 if ($this->escapestrings
)
381 $data["$key"] = $this->escape($this->sanitize($value));
385 $data["$key"] = $this->sanitize($value);
393 * Simple way to protect against HTML attacks with Unicode support
395 * @param str Unsanitzed text
397 * @return str Properly protected text that only encodes potential threats
399 function sanitize($text)
401 if ($this->magicquotes
)
403 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
407 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
412 * Takes text that has been processed for HTML and unsanitizes it
414 * @param str Text that needs to be turned back into HTML
415 * @param bool Force magicquotes off
417 * @return str Unsanitized text
419 function unsanitize($text, $force = false
)
421 if ($this->magicquotes
AND !$force)
423 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
427 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
432 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
434 * @param str Some string
435 * @param bool If the data is binary; if so it'll be run through DB::escape_string()
436 * @param bool Force magic quotes to be off
438 * @return str String that has slashes added
440 function escape($str, $binary = false
, $force = false
)
444 if ($this->magicquotes
AND !$force)
446 if (isset($_isso->db
) AND $binary)
448 if (is_resource($_isso->db
->link_id
))
450 return $_isso->db
->escape_string(stripslashes($str));
457 if (isset($_isso->db
) AND $binary)
459 if (is_resource($_isso->db
->link_id
))
461 return $_isso->db
->escape_string($str);
464 return addslashes($str);
469 * Runs through all of the input data and sanitizes it.
471 function exec_sanitize_data()
473 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
474 $this->i
=& $this->input
;
475 $this->in
=& $this->input
;
476 // we're now using magic quotes
477 if ($this->escapestrings
)
479 $this->magicquotes
= 1;
485 * Global callback used for module calls back to the kernel
487 $_isso = new Shared_Object_Framework();
490 * Wrapper for ternary operator that has to be in the global scope.
491 * This function is going to be removed from our applications due
492 * to it's latency in processing. This will remain here purely
493 * for legacy reasons. It will be removed when necessary.
495 * @param expr Expression
496 * @param mixed If the expression is true
497 * @param mixed If the expression is false
499 * @return mixed True or false data
501 function iff($condition, $iftrue, $iffalse = null
)
503 return ($condition) ?
($iftrue) : ($iffalse);
506 if (defined('ISSO_CHECK_POST_REFERER'))
508 if ($_SERVER['REQUEST_METHOD'] == 'POST')
510 $host = ($_SERVER['HTTP_HOST']) ?
$_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
511 $parts = parse_url($_SERVER['HTTP_REFERER']);
512 $ourhost = $parts['host'] . (($parts['port']) ?
":$parts[port]" : '');
514 if ($ourhost != $host)
516 trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR
);
518 $_isso->debug('remote post check = ok');
522 /*=====================================================================*\
523 || ###################################################################
526 || ###################################################################
527 \*=====================================================================*/