summaryrefslogtreecommitdiffstats
path: root/system/core
diff options
context:
space:
mode:
Diffstat (limited to 'system/core')
-rw-r--r--system/core/Base4.php8
-rw-r--r--system/core/Base5.php2
-rw-r--r--system/core/Benchmark.php4
-rw-r--r--system/core/CodeIgniter.php64
-rw-r--r--system/core/Common.php70
-rw-r--r--system/core/Compat.php10
-rw-r--r--system/core/Config.php48
-rw-r--r--system/core/Controller.php16
-rw-r--r--system/core/Exceptions.php26
-rw-r--r--system/core/Hooks.php16
-rw-r--r--system/core/Input.php8
-rw-r--r--system/core/Lang.php2
-rw-r--r--system/core/Loader.php310
-rw-r--r--system/core/Model.php14
-rw-r--r--system/core/Output.php161
-rw-r--r--system/core/Router.php160
-rw-r--r--system/core/URI.php6
-rw-r--r--system/core/Unicode.php28
18 files changed, 484 insertions, 469 deletions
diff --git a/system/core/Base4.php b/system/core/Base4.php
index bd0434158..ef7838d69 100644
--- a/system/core/Base4.php
+++ b/system/core/Base4.php
@@ -32,7 +32,7 @@
* Since PHP 5 doesn't suffer from this problem so we load one of
* two files based on the version of PHP being run.
* @PHP4
- *
+ *
* @package CodeIgniter
* @subpackage codeigniter
* @category front-controller
@@ -46,7 +46,7 @@
// This allows syntax like $this->load->foo() to work
parent::CI_Loader();
$this->load =& $this;
-
+
// This allows resources used within controller constructors to work
global $OBJ;
$OBJ = $this->load; // Do NOT use a reference.
@@ -56,12 +56,12 @@
function &get_instance()
{
global $CI, $OBJ;
-
+
if (is_object($CI))
{
return $CI;
}
-
+
return $OBJ->load;
}
diff --git a/system/core/Base5.php b/system/core/Base5.php
index 6f2fbdab0..ac6c7f020 100644
--- a/system/core/Base5.php
+++ b/system/core/Base5.php
@@ -23,7 +23,7 @@
* run under PHP 5. It allows us to manage the CI super object more
* gracefully than what is possible with PHP 4.
* @PHP4 (no need for separate Bases after PHP 4 is gone)
- *
+ *
* @package CodeIgniter
* @subpackage codeigniter
* @category front-controller
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index 1149b7a76..80933f424 100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -80,13 +80,13 @@ class CI_Benchmark {
{
$this->marker[$point2] = microtime();
}
-
+
list($sm, $ss) = explode(' ', $this->marker[$point1]);
list($em, $es) = explode(' ', $this->marker[$point2]);
return number_format(($em + $es) - ($sm + $ss), $decimals);
}
-
+
// --------------------------------------------------------------------
/**
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 295917c92..f67bb8c10 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -61,10 +61,10 @@
* ------------------------------------------------------
*/
set_error_handler('_exception_handler');
-
+
if ( ! is_php('5.3'))
{
- @set_magic_quotes_runtime(0); // Kill magic quotes
+ @set_magic_quotes_runtime(0); // Kill magic quotes
}
// Set a liberal script execution time limit
@@ -78,18 +78,18 @@
* Set the subclass_prefix
* ------------------------------------------------------
*
- * Normally the "subclass_prefix" is set in the config file.
- * The subclass prefix allows CI to know if a core class is
+ * Normally the "subclass_prefix" is set in the config file.
+ * The subclass prefix allows CI to know if a core class is
* being extended via a library in the local application
- * "libraries" folder. Since CI allows config items to be
- * overriden via data set in the main index. php file,
- * before proceeding we need to know if a subclass_prefix
+ * "libraries" folder. Since CI allows config items to be
+ * overriden via data set in the main index. php file,
+ * before proceeding we need to know if a subclass_prefix
* override exists. If so, we will set this value now,
* before any classes are loaded
- * Note: Since the config file data is cached it doesn't
+ * Note: Since the config file data is cached it doesn't
* hurt to load it here.
*/
- if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
+ if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
{
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
}
@@ -121,12 +121,12 @@
* ------------------------------------------------------
* Instantiate the config class
* ------------------------------------------------------
- */
+ */
$CFG =& load_class('Config', 'core');
// Do we have any manually set config items in the index.php file?
if (isset($assign_to_config))
- {
+ {
$CFG->_assign_to_config($assign_to_config);
}
@@ -134,16 +134,16 @@
* ------------------------------------------------------
* Instantiate the Unicode class
* ------------------------------------------------------
- *
+ *
* Note: Order here is rather important as the Unicode
* class needs to be used very early on, but it cannot
- * properly determine if UTf-8 can be supported until
+ * properly determine if UTf-8 can be supported until
* after the Config class is instantiated.
- *
+ *
*/
$UNI =& load_class('Unicode', 'core');
-
+
/*
* ------------------------------------------------------
* Instantiate the URI class
@@ -155,10 +155,10 @@
* ------------------------------------------------------
* Instantiate the routing class and set the routing
* ------------------------------------------------------
- */
+ */
$RTR =& load_class('Router', 'core');
$RTR->_set_routing();
-
+
// Set any routing overrides that may exist in the main index file
if (isset($routing))
{
@@ -190,7 +190,7 @@
* Load the Input class and sanitize globals
* ------------------------------------------------------
*/
- $IN =& load_class('Input', 'core');
+ $IN =& load_class('Input', 'core');
/*
* ------------------------------------------------------
@@ -208,9 +208,9 @@
* conditionally load different versions of the base
* class. Retaining PHP 4 compatibility requires a bit of a hack.
* @PHP4
- *
+ *
*/
- if (is_php('5.0.0') == TRUE)
+ if (is_php('5.0.0') == TRUE)
{
require(BASEPATH.'core/Base5'.EXT);
}
@@ -220,25 +220,25 @@
load_class('Loader', 'core');
require(BASEPATH.'core/Base4'.EXT);
}
-
+
// Load the base controller class
require BASEPATH.'core/Controller'.EXT;
-
+
if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
{
require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
}
-
+
// Load the local application controller
- // Note: The Router class automatically validates the controller path using the router->_validate_request().
+ // Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
-
+
include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
-
+
// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
@@ -253,7 +253,7 @@
*/
$class = $RTR->fetch_class();
$method = $RTR->fetch_method();
-
+
if ( ! class_exists($class)
OR $method == 'controller'
OR strncmp($method, '_', 1) == 0
@@ -277,7 +277,7 @@
*/
// Mark a start point so we can benchmark the controller
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
-
+
$CI = new $class();
/*
@@ -307,11 +307,11 @@
}
// Call the requested method.
- // Any URI segments present (besides the class/function) will be passed to the method for convenience
- call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
+ // Any URI segments present (besides the class/function) will be passed to the method for convenience
+ call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
}
-
+
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
@@ -331,7 +331,7 @@
{
$OUT->_display();
}
-
+
/*
* ------------------------------------------------------
* Is there a "post_system" hook?
diff --git a/system/core/Common.php b/system/core/Common.php
index 2b8ad26b1..90ba7c963 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -43,7 +43,7 @@
{
static $_is_php;
$version = (string)$version;
-
+
if ( ! isset($_is_php[$version]))
{
$_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;
@@ -57,13 +57,13 @@
/**
* Tests for file writability
*
- * is_writable() returns TRUE on Windows servers when you really can't write to
+ * is_writable() returns TRUE on Windows servers when you really can't write to
* the file, based on the read-only attribute. is_writable() is also unreliable
* on Unix servers if safe_mode is on.
*
* @access private
* @return void
- */
+ */
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
@@ -115,7 +115,7 @@
function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
static $_classes = array();
-
+
// Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
@@ -127,25 +127,25 @@
// Look for the class first in the native system/libraries folder
// thenin the local application/libraries folder
foreach (array(BASEPATH, APPPATH) as $path)
- {
+ {
if (file_exists($path.$directory.'/'.$class.EXT))
{
$name = $prefix.$class;
-
+
if (class_exists($name) === FALSE)
{
require($path.$directory.'/'.$class.EXT);
}
-
+
break;
}
}
// Is the request a class extension? If so we load it too
if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT))
- {
+ {
$name = config_item('subclass_prefix').$class;
-
+
if (class_exists($name) === FALSE)
{
require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT);
@@ -155,8 +155,8 @@
// Did we find the class?
if ($name === FALSE)
{
- // Note: We use exit() rather then show_error() in order to avoid a
- // self-referencing loop with the Excptions class
+ // Note: We use exit() rather then show_error() in order to avoid a
+ // self-referencing loop with the Excptions class
exit('Unable to locate the specified class: '.$class.EXT);
}
@@ -176,7 +176,7 @@
* Required to retain PHP 4 compatibility and also not make PHP 5.3 cry.
*
* Use: $obj =& instantiate_class(new Foo());
- *
+ *
* @access public
* @param object
* @return object
@@ -221,11 +221,11 @@
function &get_config($replace = array())
{
static $_config;
-
+
if (isset($_config))
{
return $_config[0];
- }
+ }
// Fetch the config file
if ( ! file_exists(APPPATH.'config/config'.EXT))
@@ -254,7 +254,7 @@
}
}
}
-
+
return $_config[0] =& $config;
}
@@ -269,18 +269,18 @@
function config_item($item)
{
static $_config_item = array();
-
+
if ( ! isset($_config_item[$item]))
{
$config =& get_config();
-
+
if ( ! isset($config[$item]))
{
return FALSE;
}
$_config_item[$item] = $config[$item];
}
-
+
return $_config_item[$item];
}
@@ -343,7 +343,7 @@
{
return;
}
-
+
$_log =& load_class('Log');
$_log->write_log($level, $message, $php_error);
}
@@ -354,10 +354,10 @@
* Set HTTP Status Header
*
* @access public
- * @param int the status code
- * @param string
+ * @param int the status code
+ * @param string
* @return void
- */
+ */
function set_status_header($code = 200, $text = '')
{
$stati = array(
@@ -408,15 +408,15 @@
}
if (isset($stati[$code]) AND $text == '')
- {
+ {
$text = $stati[$code];
}
-
+
if ($text == '')
{
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
-
+
$server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
if (substr(php_sapi_name(), 0, 3) == 'cgi')
@@ -432,7 +432,7 @@
header("HTTP/1.1 {$code} {$text}", TRUE, $code);
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -450,20 +450,20 @@
* @return void
*/
function _exception_handler($severity, $message, $filepath, $line)
- {
+ {
// We don't bother with "strict" notices since they tend to fill up
// the log file with excess information that isn't normally very helpful.
- // For example, if you are running PHP 5 and you use version 4 style
- // class functions (without prefixes like "public", "private", etc.)
+ // For example, if you are running PHP 5 and you use version 4 style
+ // class functions (without prefixes like "public", "private", etc.)
// you'll get notices telling you that these have been deprecated.
if ($severity == E_STRICT)
{
return;
}
-
+
$_error =& load_class('Exceptions', 'core');
-
- // Should we display the error? We'll get the current error_reporting
+
+ // Should we display the error? We'll get the current error_reporting
// level and add its bits with the severity bits to find out.
if (($severity & error_reporting()) == $severity)
{
@@ -475,12 +475,12 @@
{
return;
}
-
+
$_error->log_exception($severity, $message, $filepath, $line);
}
// --------------------------------------------------------------------
-
+
/**
* Remove Invisible Characters
*
@@ -494,7 +494,7 @@
function remove_invisible_characters($str)
{
static $non_displayables;
-
+
if ( ! isset($non_displayables))
{
// every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
diff --git a/system/core/Compat.php b/system/core/Compat.php
index 088d5815a..bd11b9836 100644
--- a/system/core/Compat.php
+++ b/system/core/Compat.php
@@ -32,7 +32,7 @@
/*
* PHP versions prior to 5.0 don't support the E_STRICT constant
- * so we need to explicitly define it otherwise the Exception class
+ * so we need to explicitly define it otherwise the Exception class
* will generate errors when running under PHP 4
* @PHP4
*
@@ -61,9 +61,9 @@ if ( ! function_exists('ctype_digit'))
{
return FALSE;
}
-
+
return ! preg_match('/[^0-9]/', $str);
- }
+ }
}
// --------------------------------------------------------------------
@@ -87,9 +87,9 @@ if ( ! function_exists('ctype_alnum'))
{
return FALSE;
}
-
+
return ! preg_match('/[^0-9a-z]/i', $str);
- }
+ }
}
// --------------------------------------------------------------------
diff --git a/system/core/Config.php b/system/core/Config.php
index 7e0443c1f..24503ab5d 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -45,10 +45,10 @@ class CI_Config {
*/
function CI_Config()
{
- $this->config =& get_config();
+ $this->config =& get_config();
log_message('debug', "Config Class Initialized");
}
-
+
// --------------------------------------------------------------------
/**
@@ -57,16 +57,16 @@ class CI_Config {
* @access public
* @param string the config file name
* @return boolean if the file was loaded correctly
- */
+ */
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
$loaded = FALSE;
-
+
foreach($this->_config_paths as $path)
{
$file_path = $path.'config/'.$file.EXT;
-
+
if (in_array($file_path, $this->is_loaded, TRUE))
{
$loaded = TRUE;
@@ -77,7 +77,7 @@ class CI_Config {
{
continue;
}
-
+
include($file_path);
if ( ! isset($config) OR ! is_array($config))
@@ -88,7 +88,7 @@ class CI_Config {
}
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
}
-
+
if ($use_sections === TRUE)
{
if (isset($this->config[$file]))
@@ -104,14 +104,14 @@ class CI_Config {
{
$this->config = array_merge($this->config, $config);
}
-
+
$this->is_loaded[] = $file_path;
unset($config);
-
+
$loaded = TRUE;
log_message('debug', 'Config file loaded: '.$file_path);
}
-
+
if ($loaded === FALSE)
{
if ($fail_gracefully === TRUE)
@@ -123,7 +123,7 @@ class CI_Config {
return TRUE;
}
-
+
// --------------------------------------------------------------------
/**
@@ -137,9 +137,9 @@ class CI_Config {
* @return string
*/
function item($item, $index = '')
- {
+ {
if ($index == '')
- {
+ {
if ( ! isset($this->config[$item]))
{
return FALSE;
@@ -164,8 +164,8 @@ class CI_Config {
return $pref;
}
-
- // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
/**
* Fetch a config file item - adds slash after item
@@ -188,13 +188,13 @@ class CI_Config {
$pref = $this->config[$item];
if ($pref != '' && substr($pref, -1) != '/')
- {
+ {
$pref .= '/';
}
return $pref;
}
-
+
// --------------------------------------------------------------------
/**
@@ -224,9 +224,9 @@ class CI_Config {
{
$uri = implode('/', $uri);
}
-
+
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
- return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
+ return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
}
else
{
@@ -254,7 +254,7 @@ class CI_Config {
}
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -268,7 +268,7 @@ class CI_Config {
$x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
return $this->slash_item('base_url').end($x).'/';
}
-
+
// --------------------------------------------------------------------
/**
@@ -283,7 +283,7 @@ class CI_Config {
{
$this->config[$item] = $value;
}
-
+
// --------------------------------------------------------------------
/**
@@ -296,7 +296,7 @@ class CI_Config {
* @access private
* @param array
* @return void
- */
+ */
function _assign_to_config($items = array())
{
if (is_array($items))
@@ -305,7 +305,7 @@ class CI_Config {
{
$this->set_item($key, $val);
}
- }
+ }
}
}
diff --git a/system/core/Controller.php b/system/core/Controller.php
index c9d797ca2..9bd9912dc 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -28,18 +28,18 @@
* @link http://codeigniter.com/user_guide/general/controllers.html
*/
class Controller extends CI_Base {
-
+
/**
* Constructor
*
* Calls the initialize() function
*/
function Controller()
- {
+ {
parent::CI_Base();
// Assign all the class objects that were instantiated by the
- // bootstrap file (CodeIgniter.php) to local class variables
+ // bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
@@ -48,18 +48,18 @@ class Controller extends CI_Base {
// In PHP 5 the Loader class is run as a discreet
// class. In PHP 4 it extends the Controller @PHP4
- if (is_php('5.0.0') == TRUE)
+ if (is_php('5.0.0') == TRUE)
{
$this->load =& load_class('Loader', 'core');
-
+
$this->load->_base_classes =& is_loaded();
-
+
$this->load->_ci_autoloader();
}
else
{
$this->_ci_autoloader();
-
+
// sync up the objects since PHP4 was working from a copy
foreach (array_keys(get_object_vars($this)) as $attribute)
{
@@ -71,7 +71,7 @@ class Controller extends CI_Base {
}
log_message('debug', "Controller Class Initialized");
-
+
}
}
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 419ea2b61..108861de7 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -51,13 +51,13 @@ class CI_Exceptions {
/**
* Constructor
*
- */
+ */
function CI_Exceptions()
{
$this->ob_level = ob_get_level();
// Note: Do not log messages from this constructor.
}
-
+
// --------------------------------------------------------------------
/**
@@ -73,9 +73,9 @@ class CI_Exceptions {
* @return string
*/
function log_exception($severity, $message, $filepath, $line)
- {
+ {
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
+
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
}
@@ -89,7 +89,7 @@ class CI_Exceptions {
* @return string
*/
function show_404($page = '', $log_error = TRUE)
- {
+ {
$heading = "404 Page Not Found";
$message = "The page you requested was not found.";
@@ -102,7 +102,7 @@ class CI_Exceptions {
echo $this->show_error($heading, $message, 'error_404', 404);
exit;
}
-
+
// --------------------------------------------------------------------
/**
@@ -121,12 +121,12 @@ class CI_Exceptions {
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
set_status_header($status_code);
-
+
$message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
if (ob_get_level() > $this->ob_level + 1)
{
- ob_end_flush();
+ ob_end_flush();
}
ob_start();
include(APPPATH.'errors/'.$template.EXT);
@@ -148,21 +148,21 @@ class CI_Exceptions {
* @return string
*/
function show_php_error($severity, $message, $filepath, $line)
- {
+ {
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
+
$filepath = str_replace("\\", "/", $filepath);
-
+
// For safety reasons we do not show the full file path
if (FALSE !== strpos($filepath, '/'))
{
$x = explode('/', $filepath);
$filepath = $x[count($x)-2].'/'.end($x);
}
-
+
if (ob_get_level() > $this->ob_level + 1)
{
- ob_end_flush();
+ ob_end_flush();
}
ob_start();
include(APPPATH.'errors/error_php'.EXT);
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 3b063f792..9026a5eb6 100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -28,8 +28,8 @@
*/
class CI_Hooks {
- var $enabled = FALSE;
- var $hooks = array();
+ var $enabled = FALSE;
+ var $hooks = array();
var $in_progress = FALSE;
/**
@@ -41,7 +41,7 @@ class CI_Hooks {
$this->_initialize();
log_message('debug', "Hooks Class Initialized");
}
-
+
// --------------------------------------------------------------------
/**
@@ -49,9 +49,9 @@ class CI_Hooks {
*
* @access private
* @return void
- */
- function _initialize()
- {
+ */
+ function _initialize()
+ {
$CFG =& load_class('Config', 'core');
// If hooks are not enabled in the config file
@@ -74,8 +74,8 @@ class CI_Hooks {
$this->hooks =& $hook;
$this->enabled = TRUE;
- }
-
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/core/Input.php b/system/core/Input.php
index 2eef82458..df3be207c 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -257,7 +257,7 @@ class CI_Input {
{
return $this->ip_address;
}
-
+
if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
{
$proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
@@ -308,7 +308,7 @@ class CI_Input {
* Validate IP Address
*
* Updated version suggested by Geert De Deckere
- *
+ *
* @access public
* @param string
* @return string
@@ -330,7 +330,7 @@ class CI_Input {
// Check each segment
foreach ($ip_segments as $segment)
{
- // IP segments must be digits and can not be
+ // IP segments must be digits and can not be
// longer than 3 digits or greater then 255
if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
{
@@ -383,7 +383,7 @@ class CI_Input {
$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN');
- // Unset globals for securiy.
+ // Unset globals for securiy.
// This is effectively the same as register_globals = off
foreach (array($_GET, $_POST, $_COOKIE) as $global)
{
diff --git a/system/core/Lang.php b/system/core/Lang.php
index e071495b8..cbd4e38b8 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -120,7 +120,7 @@ class CI_Lang {
* Fetch a single line of text from the language array
*
* @access public
- * @param string $line the language line
+ * @param string $line the language line
* @return string
*/
function line($line = '')
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 292fdc955..5a2175c2d 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -34,7 +34,7 @@ class CI_Loader {
var $_ci_library_paths = array();
var $_ci_model_paths = array();
var $_ci_helper_paths = array();
- var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance()
+ var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance()
var $_base_classes = array(); // Set by the controller class
var $_ci_cached_vars = array();
var $_ci_classes = array();
@@ -42,7 +42,7 @@ class CI_Loader {
var $_ci_models = array();
var $_ci_helpers = array();
var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
-
+
/**
* Constructor
@@ -52,18 +52,18 @@ class CI_Loader {
* @access public
*/
function CI_Loader()
- {
+ {
$this->_ci_view_path = APPPATH.'views/';
$this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(APPPATH, BASEPATH);
$this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH);
-
+
log_message('debug', "Loader Class Initialized");
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Class Loader
*
@@ -75,9 +75,19 @@ class CI_Loader {
* @param mixed the optional parameters
* @param string an optional object name
* @return void
- */
+ */
function library($library = '', $params = NULL, $object_name = NULL)
{
+ if (is_array($library))
+ {
+ foreach($library as $read)
+ {
+ $this->library($read);
+ }
+
+ return;
+ }
+
if ($library == '' OR isset($this->_base_classes[$library]))
{
return FALSE;
@@ -99,12 +109,12 @@ class CI_Loader {
{
$this->_ci_load_class($library, $params, $object_name);
}
-
+
$this->_ci_assign_to_models();
}
// --------------------------------------------------------------------
-
+
/**
* Model Loader
*
@@ -115,14 +125,14 @@ class CI_Loader {
* @param string name for the model
* @param bool database connection
* @return void
- */
+ */
function model($model, $name = '', $db_conn = FALSE)
- {
+ {
if (is_array($model))
{
foreach($model as $babe)
{
- $this->model($babe);
+ $this->model($babe);
}
return;
}
@@ -131,9 +141,9 @@ class CI_Loader {
{
return;
}
-
+
$path = '';
-
+
// Is the model in a sub-folder? If so, parse out the filename and path.
if (($last_slash = strrpos($model, '/')) !== FALSE)
{
@@ -143,23 +153,23 @@ class CI_Loader {
// And the model name behind it
$model = substr($model, $last_slash + 1);
}
-
+
if ($name == '')
{
$name = $model;
}
-
+
if (in_array($name, $this->_ci_models, TRUE))
{
return;
}
-
+
$CI =& get_instance();
if (isset($CI->$name))
{
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}
-
+
$model = strtolower($model);
foreach ($this->_ci_model_paths as $mod_path)
@@ -177,7 +187,7 @@ class CI_Loader {
$CI->load->database($db_conn, FALSE, TRUE);
}
- if ( ! class_exists('Model'))
+ if ( ! class_exists('CI_Model'))
{
load_class('Model', 'core');
}
@@ -192,13 +202,13 @@ class CI_Loader {
$this->_ci_models[] = $name;
return;
}
-
+
// couldn't find the model
show_error('Unable to locate the model you have specified: '.$model);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Database Loader
*
@@ -207,57 +217,57 @@ class CI_Loader {
* @param bool whether to return the DB object
* @param bool whether to enable active record (this allows us to override the config setting)
* @return object
- */
+ */
function database($params = '', $return = FALSE, $active_record = NULL)
{
// Grab the super object
$CI =& get_instance();
-
+
// Do we even need to load the database class?
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
{
return FALSE;
- }
-
+ }
+
require_once(BASEPATH.'database/DB'.EXT);
if ($return === TRUE)
{
return DB($params, $active_record);
}
-
- // Initialize the db variable. Needed to prevent
+
+ // Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
-
+
// Load the DB class
- $CI->db =& DB($params, $active_record);
-
+ $CI->db =& DB($params, $active_record);
+
// Assign the DB object to any existing models
$this->_ci_assign_to_models();
}
-
+
// --------------------------------------------------------------------
/**
* Load the Utilities Class
*
* @access public
- * @return string
- */
+ * @return string
+ */
function dbutil()
{
if ( ! class_exists('CI_DB'))
{
$this->database();
}
-
+
$CI =& get_instance();
// for backwards compatibility, load dbforge so we can extend dbutils off it
// this use is deprecated and strongly discouraged
$CI->load->dbforge();
-
+
require_once(BASEPATH.'database/DB_utility'.EXT);
require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
$class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
@@ -266,35 +276,35 @@ class CI_Loader {
$CI->load->_ci_assign_to_models();
}
-
+
// --------------------------------------------------------------------
/**
* Load the Database Forge Class
*
* @access public
- * @return string
- */
+ * @return string
+ */
function dbforge()
{
if ( ! class_exists('CI_DB'))
{
$this->database();
}
-
+
$CI =& get_instance();
-
+
require_once(BASEPATH.'database/DB_forge'.EXT);
require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT);
$class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
$CI->dbforge = new $class();
-
+
$CI->load->_ci_assign_to_models();
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Load View
*
@@ -316,9 +326,9 @@ class CI_Loader {
{
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Load File
*
@@ -333,9 +343,9 @@ class CI_Loader {
{
return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set Variables
*
@@ -352,9 +362,9 @@ class CI_Loader {
{
$vars = array($vars => $val);
}
-
+
$vars = $this->_ci_object_to_array($vars);
-
+
if (is_array($vars) AND count($vars) > 0)
{
foreach ($vars as $key => $val)
@@ -363,9 +373,9 @@ class CI_Loader {
}
}
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Load Helper
*
@@ -376,9 +386,9 @@ class CI_Loader {
* @return void
*/
function helper($helpers = array())
- {
+ {
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
- {
+ {
if (isset($this->_ci_helpers[$helper]))
{
continue;
@@ -386,33 +396,33 @@ class CI_Loader {
$ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
- // Is this a helper extension request?
+ // Is this a helper extension request?
if (file_exists($ext_helper))
{
$base_helper = BASEPATH.'helpers/'.$helper.EXT;
-
+
if ( ! file_exists($base_helper))
{
show_error('Unable to load the requested file: helpers/'.$helper.EXT);
}
-
+
include_once($ext_helper);
include_once($base_helper);
-
+
$this->_ci_helpers[$helper] = TRUE;
log_message('debug', 'Helper loaded: '.$helper);
continue;
}
-
+
// Try to load the helper
foreach ($this->_ci_helper_paths as $path)
{
if (file_exists($path.'helpers/'.$helper.EXT))
- {
+ {
include_once($path.'helpers/'.$helper.EXT);
$this->_ci_helpers[$helper] = TRUE;
- log_message('debug', 'Helper loaded: '.$helper);
+ log_message('debug', 'Helper loaded: '.$helper);
break;
}
}
@@ -420,13 +430,13 @@ class CI_Loader {
// unable to load the helper
if ( ! isset($this->_ci_helpers[$helper]))
{
- show_error('Unable to load the requested file: helpers/'.$helper.EXT);
+ show_error('Unable to load the requested file: helpers/'.$helper.EXT);
}
- }
+ }
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Load Helpers
*
@@ -441,9 +451,9 @@ class CI_Loader {
{
$this->helper($helpers);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Loads a language file
*
@@ -462,13 +472,13 @@ class CI_Loader {
}
foreach ($file as $langfile)
- {
+ {
$CI->lang->load($langfile, $lang);
}
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Loads a config file
*
@@ -477,7 +487,7 @@ class CI_Loader {
* @return void
*/
function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
- {
+ {
$CI =& get_instance();
$CI->config->load($file, $use_sections, $fail_gracefully);
}
@@ -501,19 +511,19 @@ class CI_Loader {
// we aren't instantiating an object here, that'll be done by the Library itself
require BASEPATH.'libraries/Driver'.EXT;
}
-
+
// We can save the loader some time since Drivers will *always* be in a subfolder,
// and typically identically named to the library
if ( ! strpos($library, '/'))
{
$library = ucfirst($library).'/'.$library;
}
-
+
return $this->library($library, $params, $object_name);
}
// --------------------------------------------------------------------
-
+
/**
* Add Package Path
*
@@ -528,7 +538,7 @@ class CI_Loader {
array_unshift($this->_ci_library_paths, $path);
array_unshift($this->_ci_model_paths, $path);
array_unshift($this->_ci_helper_paths, $path);
-
+
// Add config file path
$config =& $this->_ci_get_component('config');
array_unshift($config->_config_paths, $path);
@@ -549,7 +559,7 @@ class CI_Loader {
function remove_package_path($path = '', $remove_config_path = TRUE)
{
$config =& $this->_ci_get_component('config');
-
+
if ($path == '')
{
$void = array_shift($this->_ci_library_paths);
@@ -566,13 +576,13 @@ class CI_Loader {
unset($this->{$var}[$key]);
}
}
-
+
if (($key = array_search($path, $config->_config_paths)) !== FALSE)
{
unset($config->_config_paths[$key]);
}
}
-
+
// make sure the application default paths are still in the array
$this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
$this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
@@ -581,7 +591,7 @@ class CI_Loader {
}
// --------------------------------------------------------------------
-
+
/**
* Loader
*
@@ -613,16 +623,16 @@ class CI_Loader {
$_ci_x = explode('/', $_ci_path);
$_ci_file = end($_ci_x);
}
-
+
if ( ! file_exists($_ci_path))
{
show_error('Unable to load the requested file: '.$_ci_file);
}
-
+
// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.
// Only needed when running PHP 5
-
+
if ($this->_ci_is_instance())
{
$_ci_CI =& get_instance();
@@ -642,13 +652,13 @@ class CI_Loader {
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
- */
+ */
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars);
-
+
/*
* Buffer the output
*
@@ -662,11 +672,11 @@ class CI_Loader {
* the browser and then stop the timer it won't be accurate.
*/
ob_start();
-
+
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
-
+
if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
{
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
@@ -675,12 +685,12 @@ class CI_Loader {
{
include($_ci_path); // include() vs include_once() allows for multiple views with the same name
}
-
+
log_message('debug', 'File loaded: '.$_ci_path);
-
+
// Return the file data if requested
if ($_ci_return === TRUE)
- {
+ {
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
@@ -695,7 +705,7 @@ class CI_Loader {
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*
- */
+ */
if (ob_get_level() > $this->_ci_ob_level + 1)
{
ob_end_flush();
@@ -717,18 +727,18 @@ class CI_Loader {
* This function loads the requested class.
*
* @access private
- * @param string the item that is being loaded
+ * @param string the item that is being loaded
* @param mixed any additional parameters
* @param string an optional object name
- * @return void
+ * @return void
*/
function _ci_load_class($class, $params = NULL, $object_name = NULL)
- {
- // Get the class name, and while we're at it trim any slashes.
- // The directory path can be included as part of the class name,
+ {
+ // Get the class name, and while we're at it trim any slashes.
+ // The directory path can be included as part of the class name,
// but we don't want a leading slash
$class = str_replace(EXT, '', trim($class, '/'));
-
+
// Was the path included with the class name?
// We look for a slash to determine this
$subdir = '';
@@ -736,7 +746,7 @@ class CI_Loader {
{
// Extract the path
$subdir = substr($class, 0, $last_slash + 1);
-
+
// Get the filename from the path
$class = substr($class, $last_slash + 1);
}
@@ -746,11 +756,11 @@ class CI_Loader {
{
$subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;
- // Is this a class extension request?
+ // Is this a class extension request?
if (file_exists($subclass))
{
$baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
-
+
if ( ! file_exists($baseclass))
{
log_message('error', "Unable to load the requested class: ".$class);
@@ -768,22 +778,22 @@ class CI_Loader {
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
- return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
+ return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
}
}
-
+
$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
-
- include_once($baseclass);
+
+ include_once($baseclass);
include_once($subclass);
$this->_ci_loaded_files[] = $subclass;
-
- return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
+
+ return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
}
-
+
// Lets search for the requested library file and load it.
$is_duplicate = FALSE;
foreach ($this->_ci_library_paths as $path)
@@ -795,7 +805,7 @@ class CI_Loader {
{
continue;
}
-
+
// Safety: Was the class already loaded by a previous call?
if (in_array($filepath, $this->_ci_loaded_files))
{
@@ -810,15 +820,15 @@ class CI_Loader {
return $this->_ci_init_class($class, '', $params, $object_name);
}
}
-
+
$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
-
+
include_once($filepath);
$this->_ci_loaded_files[] = $filepath;
- return $this->_ci_init_class($class, '', $params, $object_name);
+ return $this->_ci_init_class($class, '', $params, $object_name);
}
} // END FOREACH
@@ -829,7 +839,7 @@ class CI_Loader {
$path = strtolower($class).'/'.$class;
return $this->_ci_load_class($path, $params);
}
-
+
// If we got this far we were unable to find the requested class.
// We do not issue errors if the load call failed due to a duplicate request
if ($is_duplicate == FALSE)
@@ -838,7 +848,7 @@ class CI_Loader {
show_error("Unable to load the requested class: ".$class);
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -851,7 +861,7 @@ class CI_Loader {
* @return null
*/
function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
- {
+ {
// Is there an associated config file for this class? Note: these should always be lowercase
if ($config === NULL)
{
@@ -860,20 +870,20 @@ class CI_Loader {
if (file_exists(APPPATH.'config/'.strtolower($class).EXT))
{
include_once(APPPATH.'config/'.strtolower($class).EXT);
- }
+ }
elseif (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT))
{
include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT);
}
}
-
+
if ($prefix == '')
- {
- if (class_exists('CI_'.$class))
+ {
+ if (class_exists('CI_'.$class))
{
$name = 'CI_'.$class;
}
- elseif (class_exists(config_item('subclass_prefix').$class))
+ elseif (class_exists(config_item('subclass_prefix').$class))
{
$name = config_item('subclass_prefix').$class;
}
@@ -886,18 +896,18 @@ class CI_Loader {
{
$name = $prefix.$class;
}
-
+
// Is the class name valid?
if ( ! class_exists($name))
{
log_message('error', "Non-existent class: ".$name);
show_error("Non-existent class: ".$class);
}
-
+
// Set the variable name we will assign the class to
// Was a custom class name supplied? If so we'll use it
$class = strtolower($class);
-
+
if (is_null($object_name))
{
$classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
@@ -907,23 +917,23 @@ class CI_Loader {
$classvar = $object_name;
}
- // Save the class name and object name
+ // Save the class name and object name
$this->_ci_classes[$class] = $classvar;
- // Instantiate the class
+ // Instantiate the class
$CI =& get_instance();
if ($config !== NULL)
{
$CI->$classvar = new $name($config);
}
else
- {
+ {
$CI->$classvar = new $name;
- }
- }
-
+ }
+ }
+
// --------------------------------------------------------------------
-
+
/**
* Autoloader
*
@@ -935,31 +945,31 @@ class CI_Loader {
* @return void
*/
function _ci_autoloader()
- {
+ {
include_once(APPPATH.'config/autoload'.EXT);
-
+
if ( ! isset($autoload))
{
return FALSE;
}
-
+
// Load any custom config file
if (count($autoload['config']) > 0)
- {
+ {
$CI =& get_instance();
foreach ($autoload['config'] as $key => $val)
{
$CI->config->load($val);
}
- }
+ }
// Autoload helpers and languages
foreach (array('helper', 'language') as $type)
- {
+ {
if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
{
$this->$type($autoload[$type]);
- }
+ }
}
// A little tweak to remain backward compatible
@@ -968,7 +978,7 @@ class CI_Loader {
{
$autoload['libraries'] = $autoload['core'];
}
-
+
// Load libraries
if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
{
@@ -978,13 +988,13 @@ class CI_Loader {
$this->database();
$autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
}
-
+
// Load all other libraries
foreach ($autoload['libraries'] as $item)
{
$this->library($item);
}
- }
+ }
// Autoload models
if (isset($autoload['model']))
@@ -993,7 +1003,7 @@ class CI_Loader {
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -1012,13 +1022,13 @@ class CI_Loader {
{
return;
}
-
+
foreach($this->_ci_models as $model)
{
$model = $this->_ci_get_component($model);
$model->_assign_libraries();
}
- }
+ }
// --------------------------------------------------------------------
@@ -1041,7 +1051,7 @@ class CI_Loader {
/**
* Determines whether we should use the CI instance or $this
* @PHP4
- *
+ *
* @access private
* @return bool
*/
@@ -1051,11 +1061,11 @@ class CI_Loader {
{
return TRUE;
}
-
+
global $CI;
return (is_object($CI)) ? TRUE : FALSE;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1078,7 +1088,7 @@ class CI_Loader {
}
// --------------------------------------------------------------------
-
+
/**
* Prep filename
*
@@ -1091,20 +1101,20 @@ class CI_Loader {
function _ci_prep_filename($filename, $extension)
{
if ( ! is_array($filename))
- {
- return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension));
+ {
+ return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension));
}
else
{
foreach ($filename as $key => $val)
{
- $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension);
+ $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension);
}
-
+
return $filename;
}
}
-
+
}
diff --git a/system/core/Model.php b/system/core/Model.php
index 16c4e7dd8..ebbb0fbe6 100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -37,11 +37,11 @@ class CI_Model {
{
// If the magic __get() or __set() methods are used in a Model references can't be used.
$this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
-
+
// We don't want to assign the model object to itself when using the
// assign_libraries function below so we'll grab the name of the model parent
$this->_parent_name = ucfirst(get_class($this));
-
+
log_message('debug', "Model Class Initialized");
}
@@ -50,17 +50,17 @@ class CI_Model {
*
* Creates local references to all currently instantiated objects
* so that any syntax that can be legally used in a controller
- * can be used within models.
+ * can be used within models.
*
* @access private
- */
+ */
function _assign_libraries($use_reference = TRUE)
{
- $CI =& get_instance();
+ $CI =& get_instance();
foreach (array_keys(get_object_vars($CI)) as $key)
{
if ( ! isset($this->$key) AND $key != $this->_parent_name)
- {
+ {
// In some cases using references can cause
// problems so we'll conditionally use them
if ($use_reference == TRUE)
@@ -74,7 +74,7 @@ class CI_Model {
$this->$key = $CI->$key;
}
}
- }
+ }
}
}
diff --git a/system/core/Output.php b/system/core/Output.php
index 7d3e2e180..04e452d2c 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -30,8 +30,8 @@ class CI_Output {
var $final_output;
var $cache_expiration = 0;
- var $headers = array();
- var $enable_profiler = FALSE;
+ var $headers = array();
+ var $enable_profiler = FALSE;
var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
var $_zlib_oc = FALSE;
@@ -40,12 +40,12 @@ class CI_Output {
function CI_Output()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
-
+
log_message('debug', "Output Class Initialized");
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Get Output
*
@@ -53,14 +53,14 @@ class CI_Output {
*
* @access public
* @return string
- */
+ */
function get_output()
{
return $this->final_output;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set Output
*
@@ -69,7 +69,7 @@ class CI_Output {
* @access public
* @param string
* @return void
- */
+ */
function set_output($output)
{
$this->final_output = $output;
@@ -85,7 +85,7 @@ class CI_Output {
* @access public
* @param string
* @return void
- */
+ */
function append_output($output)
{
if ($this->final_output == '')
@@ -111,52 +111,52 @@ class CI_Output {
* @access public
* @param string
* @return void
- */
+ */
function set_header($header, $replace = TRUE)
{
// If zlib.output_compression is enabled it will compress the output,
// but it will not modify the content-length header to compensate for
// the reduction, causing the browser to hang waiting for more data.
// We'll just skip content-length in those cases.
-
+
if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0)
{
return;
}
-
+
$this->headers[] = array($header, $replace);
}
// --------------------------------------------------------------------
-
+
/**
* Set HTTP Status Header
* moved to Common procedural functions in 1.7.2
- *
+ *
* @access public
- * @param int the status code
- * @param string
+ * @param int the status code
+ * @param string
* @return void
- */
+ */
function set_status_header($code = 200, $text = '')
{
set_status_header($code, $text);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Enable/disable Profiler
*
* @access public
* @param bool
* @return void
- */
+ */
function enable_profiler($val = TRUE)
{
$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
}
-
+
// --------------------------------------------------------------------
/**
@@ -177,21 +177,21 @@ class CI_Output {
}
// --------------------------------------------------------------------
-
+
/**
* Set Cache
*
* @access public
* @param integer
* @return void
- */
+ */
function cache($time)
{
$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Display Output
*
@@ -205,47 +205,55 @@ class CI_Output {
*
* @access public
* @return mixed
- */
+ */
function _display($output = '')
- {
+ {
// Note: We use globals because we can't use $CI =& get_instance()
// since this function is sometimes called by the caching mechanism,
// which happens before the CI super object is available.
global $BM, $CFG;
-
+
+ // Grab the super object if we can.
+ if (function_exists('get_instance'))
+ {
+ $CI =& get_instance();
+ }
+
// --------------------------------------------------------------------
-
+
// Set the output data
if ($output == '')
{
$output =& $this->final_output;
}
-
+
// --------------------------------------------------------------------
-
- // Do we need to write a cache file?
- if ($this->cache_expiration > 0)
+
+ // Do we need to write a cache file? Only if the controller does not have its
+ // own _output() method and we are not dealing with a cache file, which we
+ // can determine by the existence of the $CI object above
+ if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
{
$this->_write_cache($output);
}
-
+
// --------------------------------------------------------------------
// Parse out the elapsed time and memory usage,
// then swap the pseudo-variables with the data
-
- $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
+
+ $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
if ($this->parse_exec_vars === TRUE)
{
$memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
-
+
$output = str_replace('{elapsed_time}', $elapsed, $output);
$output = str_replace('{memory_usage}', $memory, $output);
}
// --------------------------------------------------------------------
-
+
// Is compression requested?
if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE)
{
@@ -259,7 +267,7 @@ class CI_Output {
}
// --------------------------------------------------------------------
-
+
// Are there any server headers to send?
if (count($this->headers) > 0)
{
@@ -267,36 +275,33 @@ class CI_Output {
{
@header($header[0], $header[1]);
}
- }
+ }
// --------------------------------------------------------------------
-
- // Does the get_instance() function exist?
+
+ // Does the $CI object exist?
// If not we know we are dealing with a cache file so we'll
// simply echo out the data and exit.
- if ( ! function_exists('get_instance'))
+ if ( ! isset($CI))
{
echo $output;
log_message('debug', "Final output sent to browser");
log_message('debug', "Total execution time: ".$elapsed);
return TRUE;
}
-
+
// --------------------------------------------------------------------
- // Grab the super object. We'll need it in a moment...
- $CI =& get_instance();
-
// Do we need to generate profile data?
// If so, load the Profile class and run it.
if ($this->enable_profiler == TRUE)
{
- $CI->load->library('profiler');
-
+ $CI->load->library('profiler');
+
if ( ! empty($this->_profiler_sections))
{
$CI->profiler->set_sections($this->_profiler_sections);
- }
+ }
// If the output data contains closing </body> and </html> tags
// we will remove them and add them back after we insert the profile data
@@ -311,7 +316,7 @@ class CI_Output {
$output .= $CI->profiler->run();
}
}
-
+
// --------------------------------------------------------------------
// Does the controller contain a function named _output()?
@@ -324,36 +329,36 @@ class CI_Output {
{
echo $output; // Send it to the browser!
}
-
+
log_message('debug', "Final output sent to browser");
- log_message('debug', "Total execution time: ".$elapsed);
+ log_message('debug', "Total execution time: ".$elapsed);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Write a Cache File
*
* @access public
* @return void
- */
+ */
function _write_cache($output)
{
- $CI =& get_instance();
+ $CI =& get_instance();
$path = $CI->config->item('cache_path');
-
+
$cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
-
+
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
log_message('error', "Unable to write cache file: ".$cache_path);
return;
}
-
+
$uri = $CI->config->item('base_url').
$CI->config->item('index_page').
$CI->uri->uri_string();
-
+
$cache_path .= md5($uri);
if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
@@ -361,9 +366,9 @@ class CI_Output {
log_message('error', "Unable to write cache file: ".$cache_path);
return;
}
-
+
$expire = time() + ($this->cache_expiration * 60);
-
+
if (flock($fp, LOCK_EX))
{
fwrite($fp, $expire.'TS--->'.$output);
@@ -381,51 +386,51 @@ class CI_Output {
}
// --------------------------------------------------------------------
-
+
/**
* Update/serve a cached file
*
* @access public
* @return void
- */
+ */
function _display_cache(&$CFG, &$URI)
{
$cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path');
-
+
// Build the file path. The file name is an MD5 hash of the full URI
$uri = $CFG->item('base_url').
$CFG->item('index_page').
$URI->uri_string;
-
+
$filepath = $cache_path.md5($uri);
-
+
if ( ! @file_exists($filepath))
{
return FALSE;
}
-
+
if ( ! $fp = @fopen($filepath, FOPEN_READ))
{
return FALSE;
}
-
+
flock($fp, LOCK_SH);
-
+
$cache = '';
if (filesize($filepath) > 0)
{
$cache = fread($fp, filesize($filepath));
}
-
+
flock($fp, LOCK_UN);
fclose($fp);
-
- // Strip out the embedded timestamp
+
+ // Strip out the embedded timestamp
if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
{
return FALSE;
}
-
+
// Has the file expired? If so we'll delete it.
if (time() >= trim(str_replace('TS--->', '', $match['1'])))
{
@@ -433,13 +438,13 @@ class CI_Output {
{
@unlink($filepath);
log_message('debug', "Cache file has expired. File deleted");
- return FALSE;
+ return FALSE;
}
}
// Display the cache
$this->_display(str_replace($match['0'], '', $cache));
- log_message('debug', "Cache file is current. Sending it to browser.");
+ log_message('debug', "Cache file is current. Sending it to browser.");
return TRUE;
}
diff --git a/system/core/Router.php b/system/core/Router.php
index b371d5241..918ea24bf 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -28,14 +28,14 @@
*/
class CI_Router {
- var $config;
- var $routes = array();
+ var $config;
+ var $routes = array();
var $error_routes = array();
var $class = '';
var $method = 'index';
var $directory = '';
var $default_controller;
-
+
/**
* Constructor
*
@@ -47,9 +47,9 @@ class CI_Router {
$this->uri =& load_class('URI', 'core');
log_message('debug', "Router Class Initialized");
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set the route mapping
*
@@ -60,9 +60,9 @@ class CI_Router {
* @return void
*/
function _set_routing()
- {
+ {
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
- // since URI segments are more search-engine friendly, but they can optionally be used.
+ // since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
$segments = array();
if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
@@ -72,65 +72,65 @@ class CI_Router {
$this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
$segments[] = $this->fetch_directory();
}
-
+
if (isset($_GET[$this->config->item('controller_trigger')]))
{
$this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
$segments[] = $this->fetch_class();
}
-
+
if (isset($_GET[$this->config->item('function_trigger')]))
{
$this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
$segments[] = $this->fetch_method();
}
}
-
+
// Load the routes.php file.
@include(APPPATH.'config/routes'.EXT);
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);
-
+
// Set the default controller so we can display it in the event
// the URI doesn't correlated to a valid controller.
- $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
-
+ $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
+
// Were there any query string segments? If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
{
return $this->_validate_request($segments);
}
-
+
// Fetch the complete URI string
$this->uri->_fetch_uri_string();
-
+
// Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
if ($this->uri->uri_string == '')
{
return $this->_set_default_controller();
}
-
+
// Do we need to remove the URL suffix?
$this->uri->_remove_url_suffix();
-
+
// Compile the segments into an array
$this->uri->_explode_segments();
-
+
// Parse any custom routing that may exist
- $this->_parse_routes();
-
+ $this->_parse_routes();
+
// Re-index the segment array so that it starts with 1 rather than 0
$this->uri->_reindex_segments();
}
// --------------------------------------------------------------------
-
+
/**
* Set the default controller
*
* @access private
* @return void
- */
+ */
function _set_default_controller()
{
if ($this->default_controller === FALSE)
@@ -141,26 +141,26 @@ class CI_Router {
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
-
+
$this->set_class($x[0]);
$this->set_method($x[1]);
$this->_set_request(array($x[0], $x[1]));
- }
+ }
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
$this->_set_request(array($this->default_controller, 'index'));
}
-
+
// re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();
-
+
log_message('debug', "No URI present. Default controller set.");
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set the Route
*
@@ -173,16 +173,16 @@ class CI_Router {
* @return void
*/
function _set_request($segments = array())
- {
+ {
$segments = $this->_validate_request($segments);
-
+
if (count($segments) == 0)
{
return $this->_set_default_controller();
}
-
+
$this->set_class($segments[0]);
-
+
if (isset($segments[1]))
{
// A standard method request
@@ -194,15 +194,15 @@ class CI_Router {
// index method is being used.
$segments[1] = 'index';
}
-
+
// Update our "routed" segment array to contain the segments.
// Note: If there is no custom routing, this array will be
// identical to $this->uri->segments
$this->uri->rsegments = $segments;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Validates the supplied segments. Attempts to determine the path to
* the controller.
@@ -210,33 +210,33 @@ class CI_Router {
* @access private
* @param array
* @return array
- */
+ */
function _validate_request($segments)
{
if (count($segments) == 0)
{
return $segments;
}
-
+
// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
{
return $segments;
}
-
+
// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
// Set the directory and remove it from the segment array
$this->set_directory($segments[0]);
$segments = array_slice($segments, 1);
-
+
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
{
- show_404($this->fetch_directory().$segments[0]);
+ show_404($this->fetch_directory().$segments[0]);
}
}
else
@@ -245,29 +245,29 @@ class CI_Router {
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
-
+
$this->set_class($x[0]);
$this->set_method($x[1]);
- }
+ }
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
}
-
+
// Does the default controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
{
$this->directory = '';
return array();
}
-
+
}
-
+
return $segments;
}
-
-
+
+
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
if (isset($this->routes['404_override']) AND $this->routes['404_override'] != '')
@@ -275,20 +275,20 @@ class CI_Router {
if (strpos($this->routes['404_override'], '/') !== FALSE)
{
$x = explode('/', $this->routes['404_override']);
-
+
$this->set_class($x[0]);
$this->set_method($x[1]);
-
+
return $x;
- }
+ }
}
-
+
// Nothing else to do at this point but show a 404
- show_404($segments[0]);
+ show_404($segments[0]);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Parse Routes
*
@@ -303,16 +303,16 @@ class CI_Router {
{
// Turn the segment array into a URI string
$uri = implode('/', $this->uri->segments);
-
+
// Is there a literal match? If so we're done
if (isset($this->routes[$uri]))
{
return $this->_set_request(explode('/', $this->routes[$uri]));
}
-
+
// Loop through the route array looking for wild-cards
foreach ($this->routes as $key => $val)
- {
+ {
// Convert wild-cards to RegEx
$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
@@ -324,8 +324,8 @@ class CI_Router {
{
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
-
- return $this->_set_request(explode('/', $val));
+
+ return $this->_set_request(explode('/', $val));
}
}
@@ -335,54 +335,54 @@ class CI_Router {
}
// --------------------------------------------------------------------
-
+
/**
* Set the class name
*
* @access public
* @param string
* @return void
- */
+ */
function set_class($class)
{
- $this->class = $class;
+ $this->class = str_replace(array('/', '.'), '', $class);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Fetch the current class
*
* @access public
* @return string
- */
+ */
function fetch_class()
{
return $this->class;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set the method name
*
* @access public
* @param string
* @return void
- */
+ */
function set_method($method)
{
$this->method = $method;
}
// --------------------------------------------------------------------
-
+
/**
* Fetch the current method
*
* @access public
* @return string
- */
+ */
function fetch_method()
{
if ($this->method == $this->fetch_class())
@@ -394,58 +394,58 @@ class CI_Router {
}
// --------------------------------------------------------------------
-
+
/**
* Set the directory name
*
* @access public
* @param string
* @return void
- */
+ */
function set_directory($dir)
{
- $this->directory = trim($dir, '/').'/';
+ $this->directory = str_replace(array('/', '.'), '', $dir).'/';
}
// --------------------------------------------------------------------
-
+
/**
* Fetch the sub-directory (if any) that contains the requested controller class
*
* @access public
* @return string
- */
+ */
function fetch_directory()
{
return $this->directory;
}
// --------------------------------------------------------------------
-
+
/**
* Set the controller overrides
*
* @access public
* @param array
* @return null
- */
+ */
function _set_overrides($routing)
{
if ( ! is_array($routing))
{
return;
}
-
+
if (isset($routing['directory']))
{
$this->set_directory($routing['directory']);
}
-
+
if (isset($routing['controller']) AND $routing['controller'] != '')
{
$this->set_class($routing['controller']);
}
-
+
if (isset($routing['function']))
{
$routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
diff --git a/system/core/URI.php b/system/core/URI.php
index cffffc20d..a3bd45091 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -195,7 +195,7 @@ class CI_URI {
}
// Convert programatic characters to entities
- $bad = array('$', '(', ')', '%28', '%29');
+ $bad = array('$', '(', ')', '%28', '%29');
$good = array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;');
return str_replace($bad, $good, $str);
@@ -321,7 +321,7 @@ class CI_URI {
*/
function uri_to_assoc($n = 3, $default = array())
{
- return $this->_uri_to_assoc($n, $default, 'segment');
+ return $this->_uri_to_assoc($n, $default, 'segment');
}
/**
* Identical to above only it uses the re-routed segment array
@@ -329,7 +329,7 @@ class CI_URI {
*/
function ruri_to_assoc($n = 3, $default = array())
{
- return $this->_uri_to_assoc($n, $default, 'rsegment');
+ return $this->_uri_to_assoc($n, $default, 'rsegment');
}
// --------------------------------------------------------------------
diff --git a/system/core/Unicode.php b/system/core/Unicode.php
index ec40c11ed..3aeb51b57 100644
--- a/system/core/Unicode.php
+++ b/system/core/Unicode.php
@@ -30,14 +30,14 @@ class CI_Unicode {
/**
* Constructor
- *
+ *
* Determines if UTF-8 support is to be enabled
- *
+ *
*/
function CI_Unicode()
{
log_message('debug', "Unicode Class Initialized");
-
+
global $CFG;
if (
@@ -48,7 +48,7 @@ class CI_Unicode {
)
{
log_message('debug', "Unicode Class - UTF-8 Support Enabled");
-
+
define('UTF8_ENABLED', TRUE);
// set internal encoding for multibyte string functions if necessary
@@ -68,11 +68,11 @@ class CI_Unicode {
{
log_message('debug', "Unicode Class - UTF-8 Support Disabled");
define('UTF8_ENABLED', FALSE);
- }
+ }
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Clean UTF-8 strings
*
@@ -88,19 +88,19 @@ class CI_Unicode {
{
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
}
-
+
return $str;
}
// --------------------------------------------------------------------
-
+
/**
* Remove ASCII control characters
*
* Removes all ASCII control characters except horizontal tabs,
* line feeds, and carriage returns, as all others can cause
* problems in XML
- *
+ *
* @access public
* @param string
* @return string
@@ -111,7 +111,7 @@ class CI_Unicode {
}
// --------------------------------------------------------------------
-
+
/**
* Convert to UTF-8
*
@@ -136,12 +136,12 @@ class CI_Unicode {
{
return FALSE;
}
-
+
return $str;
}
// --------------------------------------------------------------------
-
+
/**
* Is ASCII?
*
@@ -157,7 +157,7 @@ class CI_Unicode {
}
// --------------------------------------------------------------------
-
+
}
// End Unicode Class