Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Wrapped all common functions to check if it already exists. This allo…
…ws anyone to override a lot more of the core by simply defining these function prior to loading them.
  • Loading branch information
dhrrgn committed May 8, 2011
1 parent 2e1837a commit 3ef65bd
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions system/core/Common.php
Expand Up @@ -39,6 +39,8 @@
* @param string
* @return bool TRUE if the current version is $version or higher
*/
if ( ! function_exists('is_php'))
{
function is_php($version = '5.0.0')
{
static $_is_php;
Expand All @@ -51,6 +53,7 @@ function is_php($version = '5.0.0')

return $_is_php[$version];
}
}

// ------------------------------------------------------------------------

Expand All @@ -64,6 +67,8 @@ function is_php($version = '5.0.0')
* @access private
* @return void
*/
if ( ! function_exists('is_really_writable'))
{
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
Expand Down Expand Up @@ -96,6 +101,7 @@ function is_really_writable($file)
fclose($fp);
return TRUE;
}
}

// ------------------------------------------------------------------------

Expand All @@ -112,6 +118,8 @@ function is_really_writable($file)
* @param string the class name prefix
* @return object
*/
if ( ! function_exists('load_class'))
{
function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
static $_classes = array();
Expand Down Expand Up @@ -166,6 +174,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
$_classes[$class] = new $name();
return $_classes[$class];
}
}

// --------------------------------------------------------------------

Expand All @@ -176,6 +185,8 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
* @access public
* @return array
*/
if ( ! function_exists('is_loaded'))
{
function is_loaded($class = '')
{
static $_is_loaded = array();
Expand All @@ -187,6 +198,7 @@ function is_loaded($class = '')

return $_is_loaded;
}
}

// ------------------------------------------------------------------------

Expand All @@ -199,6 +211,8 @@ function is_loaded($class = '')
* @access private
* @return array
*/
if ( ! function_exists('get_config'))
{
function &get_config($replace = array())
{
static $_config;
Expand Down Expand Up @@ -242,6 +256,7 @@ function &get_config($replace = array())

return $_config[0] =& $config;
}
}

// ------------------------------------------------------------------------

Expand All @@ -251,6 +266,8 @@ function &get_config($replace = array())
* @access public
* @return mixed
*/
if ( ! function_exists('config_item'))
{
function config_item($item)
{
static $_config_item = array();
Expand All @@ -268,6 +285,7 @@ function config_item($item)

return $_config_item[$item];
}
}

// ------------------------------------------------------------------------

Expand All @@ -283,12 +301,15 @@ function config_item($item)
* @access public
* @return void
*/
if ( ! function_exists('show_error'))
{
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
$_error =& load_class('Exceptions', 'core');
echo $_error->show_error($heading, $message, 'error_general', $status_code);
exit;
}
}

// ------------------------------------------------------------------------

Expand All @@ -302,12 +323,15 @@ function show_error($message, $status_code = 500, $heading = 'An Error Was Encou
* @access public
* @return void
*/
if ( ! function_exists('show_404'))
{
function show_404($page = '', $log_error = TRUE)
{
$_error =& load_class('Exceptions', 'core');
$_error->show_404($page, $log_error);
exit;
}
}

// ------------------------------------------------------------------------

Expand All @@ -320,6 +344,8 @@ function show_404($page = '', $log_error = TRUE)
* @access public
* @return void
*/
if ( ! function_exists('log_message'))
{
function log_message($level = 'error', $message, $php_error = FALSE)
{
static $_log;
Expand All @@ -332,6 +358,7 @@ function log_message($level = 'error', $message, $php_error = FALSE)
$_log =& load_class('Log');
$_log->write_log($level, $message, $php_error);
}
}

// ------------------------------------------------------------------------

Expand All @@ -343,6 +370,8 @@ function log_message($level = 'error', $message, $php_error = FALSE)
* @param string
* @return void
*/
if ( ! function_exists('set_status_header'))
{
function set_status_header($code = 200, $text = '')
{
$stati = array(
Expand Down Expand Up @@ -417,6 +446,7 @@ function set_status_header($code = 200, $text = '')
header("HTTP/1.1 {$code} {$text}", TRUE, $code);
}
}
}

// --------------------------------------------------------------------

Expand All @@ -434,6 +464,8 @@ function set_status_header($code = 200, $text = '')
* @access private
* @return void
*/
if ( ! function_exists('_exception_handler'))
{
function _exception_handler($severity, $message, $filepath, $line)
{
// We don't bother with "strict" notices since they tend to fill up
Expand Down Expand Up @@ -463,19 +495,22 @@ function _exception_handler($severity, $message, $filepath, $line)

$_error->log_exception($severity, $message, $filepath, $line);
}
}

// --------------------------------------------------------------------

/**
* Remove Invisible Characters
*
* This prevents sandwiching null characters
* between ascii characters, like Java\0script.
*
* @access public
* @param string
* @return string
*/
// --------------------------------------------------------------------

/**
* Remove Invisible Characters
*
* This prevents sandwiching null characters
* between ascii characters, like Java\0script.
*
* @access public
* @param string
* @return string
*/
if ( ! function_exists('remove_invisible_characters'))
{
function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displayables = array();
Expand All @@ -499,7 +534,7 @@ function remove_invisible_characters($str, $url_encoded = TRUE)

return $str;
}

}

/* End of file Common.php */
/* Location: ./system/core/Common.php */

0 comments on commit 3ef65bd

Please sign in to comment.