='))
{
if (ini_get('error_reporting') & E_NOTICE)
{
error_reporting(ini_get('error_reporting') - E_NOTICE);
}
if (ini_get('error_reporting') & E_USER_NOTICE)
{
error_reporting(ini_get('error_reporting') - E_USER_NOTICE);
}
}
$oldlevel = ini_get('error_reporting');
$newlevel = $oldlevel;
$levels = array(E_ERROR => E_USER_ERROR, E_WARNING => E_USER_WARNING, E_NOTICE => E_USER_NOTICE);
foreach ($levels AS $php => $isso)
{
if ($oldlevel & $php)
{
if (!($oldlevel & $isso))
{
//echo "increasing newlevel by $isso; ";
$newlevel += $isso;
}
}
else
{
if ($oldlevel & $isso)
{
//echo "decreasing newlevel by $isso; ";
$newlevel -= $isso;
}
}
}
error_reporting($newlevel);
if ((bool)ini_get('register_globals') === true)
{
$superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
foreach ($superglobals AS $global)
{
if (is_array(${$global}))
{
foreach (${$global} AS $_key => $_val)
{
if (isset(${$_key}))
{
unset(${$_key});
}
}
}
}
}
/**
* Iris Studios Shared Object Framework (ISSO)
*
* This framework allows a common backend to be used amongst all Iris
* Studios applications and is built to be abstract and flexible.
* The base framework handles all loading and module management.
*
* @author Iris Studios, Inc.
* @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
* @version $Revision$
* @package ISSO
*
*/
class Shared_Object_Framework
{
/**
* ISSO version
* @var str
*/
var $version = '[#]version[#]';
/**
* Location of ISSO, used for internal linking
* @var str
* @see fetch_sourcepath(), load(), locate()
*/
var $sourcepath = '';
/**
* Path of the current application
* @var str
*/
var $apppath = '';
/**
* Name of the current application
* @var str
*/
var $application = '';
/**
* Version of the current application
* @var str
*/
var $appversion = '';
/**
* Whether debug mode is on or off
* @var bool
*/
var $debug = false;
/**
* List of all active debug messages
* @var array
* @see debug()
*/
var $debuginfo = array();
/**
* List of loaded modules
* @var array
* @see load(), show_modules()
*/
var $modules = array();
/**
* An array of sanitized variables that have been cleaned for HTML tag openers and double quotes
* @var array
* @see sanitize(), exec_sanitize_data()
*/
var $in = array();
/**
* If we are running with magic_quotes_gpc on or off
* @var int
* @see escape(), exec_sanitize_data()
*/
var $magicquotes = 0;
/**
* If we should automagically escape strings, mimicking magic_quotes_gpc
* @var bool
* @see exec_sanitize_data()
*/
var $escapestrings = false;
/**
* Constructor
*/
function Shared_Object_Framework()
{
// error reporting
set_error_handler(array(&$this, '_error_handler'));
// magic quotes
$this->magicquotes = get_magic_quotes_gpc();
set_magic_quotes_runtime(0);
if (defined('ISSO_ESCAPE_STRINGS'))
{
$this->escapestrings = (bool)constant('ISSO_ESCAPE_STRINGS');
}
// start input sanitize using variable_order GPC
if (!$this->escapestrings)
{
$this->exec_sanitize_data();
}
$this->modules['kernel'] = 'Shared Object Framework Core';
}
/**
* Prepares a path for being set as the sourcepath
*
* @param str Source path or URL
*
* @return str Prepared source path
*/
function fetch_sourcepath($source)
{
if (substr($source, strlen($source) - 1) != '/')
{
$source .= '/';
}
return $source;
}
/**
* Loads a framework extension
*
* @param str Name of the framework
*/
function load($framework)
{
if (!$this->is_loaded($framework))
{
$newobj = $this->locate($framework);
$this->$newobj['OBJ'] = new $newobj['CLASS']();
$GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
$this->modules["$framework"] = $newobj['OBJECT'];
}
}
/**
* Includes a framework module. Module definitions need three variables:
* class, object, and obj. Class is the name of the class, object is
* the name human-readable name, and obj is the name that the module
* should be initialized as; this is used in class extensions.
*
* @param str Name of the framework
*
* @return array List of initialization variables
*/
function locate($framework)
{
if ($this->sourcepath == '')
{
trigger_error('Invalid sourcepath specified', E_USER_ERROR);
}
if (file_exists($this->sourcepath . $framework . '.php'))
{
require_once($this->sourcepath . $framework . '.php');
return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
}
else
{
trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR);
exit;
}
}
/**
* Prints a list of all currently loaded framework modules
*
* @param bool Return the data as an array?
*
* @return mixed HTML output or an array of loaded modules
*/
function show_modules($return = false)
{
if ($return)
{
return $this->modules;
}
else
{
$output = "\n\n
\n\t- ";
$output .= implode("
\n\t- ", $this->modules);
$output .= "
\n
\n\n";
$this->_message('Loaded Modules', $output, 1);
}
}
/**
* Verifies to see if a framework has been loaded
*
* @param str Framework name
*
* @return bool Whether or not the framework has been loaded
*/
function is_loaded($framework)
{
if (isset($this->modules["$framework"]))
{
return true;
}
else
{
return false;
}
}
/**
* Prints an ISSO message
*
* @param str The title of the message
* @param str The content of the message
* @param int Type of message to be printed
* @param bool Return the output?
*
* @return mixed Output or null
*/
function _message($title, $message, $type, $return = false)
{
switch ($type)
{
// Message
case 1:
$prefix = 'Message';
$color = '#669900';
$font = '#000000';
break;
// Warning
case 2:
$prefix = 'Warning';
$color = '#003399';
$font = '#FFFFFF';
break;
case 3:
$prefix = 'Error';
$color = '#990000';
$font = '#EFEFEF';
break;
}
$output = "\n
\n";
$output .= "\n\n\t$prefix: $title | \n
";
$output .= "\n\n\t$message | \n
\n
\n
\n";
if ($return)
{
return $output;
}
else
{
print($output);
}
}
/**
* Custom error handler for ISSO
* We only handle E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
*
* @param int Error number
* @param str Error message string
* @param str File that contains the error
* @param str The line number of the error
* @param str The active symbol table at which point the error occurred
*/
function _error_handler($errno, $errstr, $errfile, $errline)
{
switch ($errno)
{
// Fatal
case E_USER_ERROR:
$title = 'Fatal';
if (!(ini_get('error_reporting') & E_USER_ERROR))
{
return;
}
break;
// Error
case E_USER_WARNING:
$title = 'Warning';
if (!(ini_get('error_reporting') & E_USER_WARNING) AND !(ini_get('error_reporting') & E_WARNING))
{
return;
}
break;
// Warning
case E_USER_NOTICE:
default:
$title = 'Notice';
if (!(ini_get('error_reporting') & E_USER_NOTICE) AND !(ini_get('error_reporting') & E_NOTICE))
{
return;
}
break;
}
$errfile = str_replace(array(getcwd(), dirname(getcwd())), '', $errfile);
$errstr .= " in $errfile on line $errline";
$this->_message($title, $errstr, 3);
if ($errno == E_USER_ERROR)
{
exit;
}
}
/**
* Logs a debug message for verbose output
*
* @param str Message
*/
function debug($message)
{
$this->debuginfo[] = $message;
}
/**
* Recursive XSS cleaner
*
* @param mixed Unsanitized REQUEST data
*
* @return mixed Sanitized data
*/
function _sanitize_input_recursive($data)
{
foreach ($data AS $key => $value)
{
if (is_array($value))
{
$data["$key"] = $this->_sanitize_input_recursive($value);
}
else
{
if ($this->escapestrings)
{
$data["$key"] = $this->escape($this->sanitize($value), false, false);
}
else
{
$data["$key"] = $this->sanitize($value);
}
}
}
return $data;
}
/**
* Simple way to protect against HTML attacks with Unicode support
*
* @param str Unsanitzed text
*
* @return str Properly protected text that only encodes potential threats
*/
function sanitize($text)
{
if ($this->magicquotes)
{
return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
}
else
{
return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
}
}
/**
* Takes text that has been processed for HTML and unsanitizes it
*
* @param str Text that needs to be turned back into HTML
* @param bool Force magicquotes off
*
* @return str Unsanitized text
*/
function unsanitize($text, $force = false)
{
if ($this->magicquotes AND !$force)
{
return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
}
else
{
return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
}
}
/**
* Smart addslashes() that only applies itself it the Magic Quotes GPC is off
*
* @param str Some string
* @param bool If the data is binary; if so it'll be run through DB::escape_string()
* @param bool Force magic quotes to be off
*
* @return str String that has slashes added
*/
function escape($str, $binary = false, $force = true)
{
global $_isso;
if ($this->magicquotes AND !$force)
{
if (isset($_isso->db) AND $binary)
{
if (is_resource($_isso->db->link_id))
{
return $_isso->db->escape_string(stripslashes($str));
}
}
return $str;
}
else
{
if (isset($_isso->db) AND $binary)
{
if (is_resource($_isso->db->link_id))
{
return $_isso->db->escape_string($str);
}
}
return addslashes($str);
}
}
/**
* Runs through all of the input data and sanitizes it.
*/
function exec_sanitize_data()
{
$this->in = $this->_sanitize_input_recursive(array_merge($_GET, $_POST, $_COOKIE));
// we're now using magic quotes
if ($this->escapestrings)
{
$this->magicquotes = 1;
}
}
}
/**
* Global callback used for module calls back to the kernel
*/
$_isso = new Shared_Object_Framework();
/**
* Wrapper for ternary operator that has to be in the global scope.
* This function is going to be removed from our applications due
* to it's latency in processing. This will remain here purely
* for legacy reasons. It will be removed when necessary.
*
* @deprecated The normal ternary operators should be used instead; function calls are too expensive
*
* @param expr Expression
* @param mixed If the expression is true
* @param mixed If the expression is false
*
* @return mixed True or false data
*/
function iff($condition, $iftrue, $iffalse = null)
{
return ($condition) ? ($iftrue) : ($iffalse);
}
if (defined('ISSO_CHECK_POST_REFERER'))
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$host = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
if ($host AND $_SERVER['HTTP_REFERER'])
{
$parts = parse_url($_SERVER['HTTP_REFERER']);
$ourhost = $parts['host'] . (($parts['port']) ? ":$parts[port]" : '');
if ($ourhost != $host)
{
trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR);
}
$_isso->debug('remote post check = ok');
}
else
{
$_isso->debug('remote post check = FAILED');
}
}
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>