\n\n";
$this->message('Loaded Modules', $output, 1);
}
}
// ###################################################################
/**
* Verifies to see if a framework has been loaded
*
* @access public
*
* @param string 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
*
* @access public
*
* @param string The title of the message
* @param string The content of the message
* @param integer Type of message to be printed
* @param bool Return the output?
* @param bool Show the debug stack?
*
* @return mixed Output or null
*/
function message($title, $message, $type, $return = false, $stack = true)
{
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;
}
$backtrace = debug_backtrace();
unset($backtrace[0]);
$output = "\n \n
";
$output .= "\n
\n\t
$prefix: $title
\n
";
$output .= "\n
\n\t
$message
\n
";
$output .= (($stack AND $GLOBALS['isso:null-framework']->debug) ? "\n
\n\t
Debug Stack:
" . print_r($backtrace, true) . "
\n
" : '');
$output .= "\n
\n \n";
if ($return)
{
return $output;
}
else
{
print($output);
}
}
// ###################################################################
/**
* Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
* E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
*
* @access private
*
* @param integer Error number
* @param string Error message string
* @param string File that contains the error
* @param string The line number of the error
* @param string 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';
$level = 3;
if (!(ini_get('error_reporting') & E_USER_ERROR))
{
return;
}
break;
// Error
case E_USER_WARNING:
$title = 'Warning';
$level = 2;
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';
$level = 1;
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, $level);
if ($errno == E_USER_ERROR)
{
exit;
}
}
// ###################################################################
/**
* Creates a table that explains the error reporting levels and their
* state
*
* @access public
*/
function explain_error_reporting()
{
$levels = array(
'E_ERROR' => E_ERROR,
'E_WARNING' => E_WARNING,
'E_PARSE' => E_PARSE,
'E_NOTICE' => E_NOTICE,
'E_CORE_ERROR' => E_CORE_ERROR,
'E_CORE_WARNING' => E_CORE_WARNING,
'E_COMPILE_ERROR' => 64,
'E_COMPILE_WARNING' => 128,
'E_USER_ERROR' => E_USER_ERROR,
'E_USER_WARNING' => E_USER_WARNING,
'E_USER_NOTICE' => E_USER_NOTICE,
'E_ALL' => E_ALL,
'E_STRICT' => 2048
);
$table = '
';
$this->message('Error Reporting', $table, 1);
}
// ###################################################################
/**
* Logs a debug message for verbose output
*
* @access public
*
* @param string Message
*/
function debug($message)
{
$this->debuginfo[] = $message;
}
// ###################################################################
/**
* Recursive XSS cleaner
*
* @access private
*
* @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
{
$data["$key"] = $this->sanitize($value);
}
}
return $data;
}
// ###################################################################
/**
* Simple way to protect against HTML attacks with Unicode support
*
* @access public
*
* @param string Unsanitzed text
*
* @return string 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);
}
}
// ###################################################################
/**
* Unicode-safe entity encoding system; similar to sanitize()
*
* @access public
*
* @param string Unsanitized text
*
* @return string Unicode-safe sanitized text with entities preserved
*/
function entity_encode($text)
{
$text = str_replace('&', '&', $text);
$text = $this->sanitize($text);
return $text;
}
// ###################################################################
/**
* Takes text that has been processed for HTML and unsanitizes it
*
* @access public
*
* @param string Text that needs to be turned back into HTML
*
* @return string Unsanitized text
*/
function unsanitize($text)
{
return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
}
// ###################################################################
/**
* Smart addslashes() that only applies itself it the Magic Quotes GPC
* is off. This should only be run on database query values.
*
* @access public
*
* @param string Some string
* @param bool If the data is binary; if so it'll be run through DB::escape_stringing()
* @param bool Force magic quotes to be off
*
* @return string String that has slashes added
*/
function escape($str, $binary = false, $force = true)
{
if ($this->magicquotes AND !$force)
{
if (isset($this->db) AND $binary)
{
if (is_resource($this->db->link_id))
{
return $this->db->escape_string(str_replace(array("\'", '\"'), array("'", '"'), $str));
}
}
return $str;
}
else
{
if (isset($this->db) AND $binary)
{
if (is_resource($this->db->link_id))
{
return $this->db->escape_string($str);
}
}
return addslashes($str);
}
}
// ###################################################################
/**
* Runs through all of the input data and sanitizes it.
*
* @access public
*/
function exec_sanitize_data()
{
$this->in = $this->_sanitize_input_recursive(array_merge($_GET, $_POST, $_COOKIE));
}
// ###################################################################
/**
* Sanitize function for something other than a string (which
* everything is sanitized for if you use exec_sanitize_data(). Cleaned
* data is placed back into $isso->in; this makes it so you don't have
* to constantly intval() [etc.] data.
*
* @access public
*
* @param array Array of elements to clean as varname => type
*/
function input_clean_array($vars)
{
foreach ($vars AS $varname => $type)
{
$this->input_clean($varname, $type);
}
}
// ###################################################################
/**
* Sanitize function that does a single variable as oppoesd to an array
* (see input_clean_array() for more details)
*
* @access public
*
* @param string Variable name in $isso->in[]
* @param integer Sanitization type constant
*/
function input_clean($varname, $type)
{
if (isset($this->in["$varname"]))
{
$this->in["$varname"] = $this->clean($this->in["$varname"], $type);
}
else
{
$this->in["$varname"] = null;
}
}
// ###################################################################
/**
* Cleaning function that does the work for input_clean(); this is
* moved here so it can be used to clean things that aren't in
* $isso->in[]
*
* @access public
*
* @param mixed Data
* @param integer Sanitization type constant
*
* @return mixed Cleaned data
*/
function clean($value, $type)
{
if ($type == TYPE_INT)
{
$value = intval($value);
}
else if ($type == TYPE_UINT)
{
$value = abs(intval($value));
}
else if ($type == TYPE_FLOAT)
{
$value = floatval($value);
}
else if ($type == TYPE_BOOL)
{
$value = (bool)$value;
}
else if ($type == TYPE_STR)
{
$value = $value;
}
else if ($type == TYPE_STRUN)
{
$value = $this->unsanitize($value);
}
else if ($type == TYPE_NOCLEAN)
{
$value = $value;
}
else
{
trigger_error('Invalid clean type `' . $type . '` specified', E_USER_ERROR);
}
return $value;
}
// ###################################################################
/**
* Checks to see if a POST refer is actually from us
*
* @access public
*/
function exec_referer_check()
{
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);
}
$this->debug('remote post check = ok');
}
else
{
$this->debug('remote post check = FAILED');
}
}
}
// ###################################################################
/**
* Constructs a debug information box that contains various debugging
* information points
*
* @access public
*
* @param bool Show template information?
*
* @return string Debugging block
*/
function construct_debug_block($dotemplates)
{
$debug = '';
if ($this->debug)
{
$debug = "\n
";
// templates
if ($dotemplates)
{
// both template and template_fs are viable, so we need to determine the right one
if ($this->is_loaded('template'))
{
$tpl_obj =& $this->modules['template'];
}
else if ($this->is_loaded('template_fs'))
{
$tpl_obj =& $this->modules['template_fs'];
}
else
{
$tpl_obj = null;
}
$optlist = array();
$usage = array();
foreach ($tpl_obj->usage AS $name => $count)
{
if (in_array($name, $tpl_obj->uncached))
{
$optlist[] = $name . '[' . $count . ']';
}
$usage[] = $name . " ($count)";
}
$sizeof = sizeof($tpl_obj->uncached);
if ($sizeof > 0)
{
$debug .= "\n\t