Upgrade to CodeIgniter 2.0.3

This commit is contained in:
Eike Foken
2011-09-13 19:15:50 +02:00
parent 8dd1099e04
commit a8c2551be2
53 changed files with 1949 additions and 578 deletions

View File

@@ -37,7 +37,7 @@
| |
*/ */
$autoload['packages'] = array(APPPATH.'third_party'); $autoload['packages'] = array();
/* /*

View File

@@ -44,6 +44,7 @@ $platforms = array (
'unix' => 'Unknown Unix OS' 'unix' => 'Unknown Unix OS'
); );
// The order of this array should NOT be changed. Many browsers return // The order of this array should NOT be changed. Many browsers return
// multiple browser types so we want to identify the sub-type first. // multiple browser types so we want to identify the sub-type first.
$browsers = array( $browsers = array(

View File

@@ -98,7 +98,7 @@ if (defined('ENVIRONMENT'))
// if your controller is not in a sub-folder within the "controllers" folder // if your controller is not in a sub-folder within the "controllers" folder
// $routing['directory'] = ''; // $routing['directory'] = '';
// The controller class file name. Example: Mycontroller.php // The controller class file name. Example: Mycontroller
// $routing['controller'] = ''; // $routing['controller'] = '';
// The controller function you wish to be called. // The controller function you wish to be called.
@@ -163,6 +163,7 @@ if (defined('ENVIRONMENT'))
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// The PHP file extension // The PHP file extension
// this global constant is deprecated.
define('EXT', '.php'); define('EXT', '.php');
// Path to the system folder // Path to the system folder
@@ -198,7 +199,7 @@ if (defined('ENVIRONMENT'))
* And away we go... * And away we go...
* *
*/ */
require_once BASEPATH.'core/CodeIgniter'.EXT; require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */ /* End of file index.php */
/* Location: ./index.php */ /* Location: ./index.php */

View File

@@ -32,7 +32,7 @@
* Define the CodeIgniter Version * Define the CodeIgniter Version
* ------------------------------------------------------ * ------------------------------------------------------
*/ */
define('CI_VERSION', '2.0.2'); define('CI_VERSION', '2.0.3');
/* /*
* ------------------------------------------------------ * ------------------------------------------------------
@@ -46,20 +46,20 @@
* Load the global functions * Load the global functions
* ------------------------------------------------------ * ------------------------------------------------------
*/ */
require(BASEPATH.'core/Common'.EXT); require(BASEPATH.'core/Common.php');
/* /*
* ------------------------------------------------------ * ------------------------------------------------------
* Load the framework constants * Load the framework constants
* ------------------------------------------------------ * ------------------------------------------------------
*/ */
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT)) if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
{ {
require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT); require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
} }
else else
{ {
require(APPPATH.'config/constants'.EXT); require(APPPATH.'config/constants.php');
} }
/* /*
@@ -224,7 +224,7 @@
* *
*/ */
// Load the base controller class // Load the base controller class
require BASEPATH.'core/Controller'.EXT; require BASEPATH.'core/Controller.php';
function &get_instance() function &get_instance()
{ {
@@ -232,20 +232,20 @@
} }
if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT)) if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
{ {
require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT; require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
} }
// Load the local application controller // 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 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)) if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
{ {
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); 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); include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
// Set a mark point for benchmarking // Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end'); $BM->mark('loading_time:_base_classes_end');
@@ -318,12 +318,12 @@
$method = (isset($x[1]) ? $x[1] : 'index'); $method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class)) if ( ! class_exists($class))
{ {
if ( ! file_exists(APPPATH.'controllers/'.$class.EXT)) if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
{ {
show_404("{$class}/{$method}"); show_404("{$class}/{$method}");
} }
include_once(APPPATH.'controllers/'.$class.EXT); include_once(APPPATH.'controllers/'.$class.'.php');
unset($CI); unset($CI);
$CI = new $class(); $CI = new $class();
} }

View File

@@ -39,6 +39,8 @@
* @param string * @param string
* @return bool TRUE if the current version is $version or higher * @return bool TRUE if the current version is $version or higher
*/ */
if ( ! function_exists('is_php'))
{
function is_php($version = '5.0.0') function is_php($version = '5.0.0')
{ {
static $_is_php; static $_is_php;
@@ -51,6 +53,7 @@
return $_is_php[$version]; return $_is_php[$version];
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -64,6 +67,8 @@
* @access private * @access private
* @return void * @return void
*/ */
if ( ! function_exists('is_really_writable'))
{
function is_really_writable($file) function is_really_writable($file)
{ {
// If we're on a Unix server with safe_mode off we call is_writable // If we're on a Unix server with safe_mode off we call is_writable
@@ -96,6 +101,7 @@
fclose($fp); fclose($fp);
return TRUE; return TRUE;
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -112,6 +118,8 @@
* @param string the class name prefix * @param string the class name prefix
* @return object * @return object
*/ */
if ( ! function_exists('load_class'))
{
function &load_class($class, $directory = 'libraries', $prefix = 'CI_') function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{ {
static $_classes = array(); static $_classes = array();
@@ -128,13 +136,13 @@
// thenin the local application/libraries folder // thenin the local application/libraries folder
foreach (array(BASEPATH, APPPATH) as $path) foreach (array(BASEPATH, APPPATH) as $path)
{ {
if (file_exists($path.$directory.'/'.$class.EXT)) if (file_exists($path.$directory.'/'.$class.'.php'))
{ {
$name = $prefix.$class; $name = $prefix.$class;
if (class_exists($name) === FALSE) if (class_exists($name) === FALSE)
{ {
require($path.$directory.'/'.$class.EXT); require($path.$directory.'/'.$class.'.php');
} }
break; break;
@@ -142,13 +150,13 @@
} }
// Is the request a class extension? If so we load it too // Is the request a class extension? If so we load it too
if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT)) if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
{ {
$name = config_item('subclass_prefix').$class; $name = config_item('subclass_prefix').$class;
if (class_exists($name) === FALSE) if (class_exists($name) === FALSE)
{ {
require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT); require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
} }
} }
@@ -157,7 +165,7 @@
{ {
// Note: We use exit() rather then show_error() in order to avoid a // Note: We use exit() rather then show_error() in order to avoid a
// self-referencing loop with the Excptions class // self-referencing loop with the Excptions class
exit('Unable to locate the specified class: '.$class.EXT); exit('Unable to locate the specified class: '.$class.'.php');
} }
// Keep track of what we just loaded // Keep track of what we just loaded
@@ -166,6 +174,7 @@
$_classes[$class] = new $name(); $_classes[$class] = new $name();
return $_classes[$class]; return $_classes[$class];
} }
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -176,6 +185,8 @@
* @access public * @access public
* @return array * @return array
*/ */
if ( ! function_exists('is_loaded'))
{
function is_loaded($class = '') function is_loaded($class = '')
{ {
static $_is_loaded = array(); static $_is_loaded = array();
@@ -187,6 +198,7 @@
return $_is_loaded; return $_is_loaded;
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -199,6 +211,8 @@
* @access private * @access private
* @return array * @return array
*/ */
if ( ! function_exists('get_config'))
{
function &get_config($replace = array()) function &get_config($replace = array())
{ {
static $_config; static $_config;
@@ -209,9 +223,9 @@
} }
// Is the config file in the environment folder? // Is the config file in the environment folder?
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT)) if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{ {
$file_path = APPPATH.'config/config'.EXT; $file_path = APPPATH.'config/config.php';
} }
// Fetch the config file // Fetch the config file
@@ -242,6 +256,7 @@
return $_config[0] =& $config; return $_config[0] =& $config;
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -251,6 +266,8 @@
* @access public * @access public
* @return mixed * @return mixed
*/ */
if ( ! function_exists('config_item'))
{
function config_item($item) function config_item($item)
{ {
static $_config_item = array(); static $_config_item = array();
@@ -268,6 +285,7 @@
return $_config_item[$item]; return $_config_item[$item];
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -283,12 +301,15 @@
* @access public * @access public
* @return void * @return void
*/ */
if ( ! function_exists('show_error'))
{
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{ {
$_error =& load_class('Exceptions', 'core'); $_error =& load_class('Exceptions', 'core');
echo $_error->show_error($heading, $message, 'error_general', $status_code); echo $_error->show_error($heading, $message, 'error_general', $status_code);
exit; exit;
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -302,12 +323,15 @@
* @access public * @access public
* @return void * @return void
*/ */
if ( ! function_exists('show_404'))
{
function show_404($page = '', $log_error = TRUE) function show_404($page = '', $log_error = TRUE)
{ {
$_error =& load_class('Exceptions', 'core'); $_error =& load_class('Exceptions', 'core');
$_error->show_404($page, $log_error); $_error->show_404($page, $log_error);
exit; exit;
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -320,6 +344,8 @@
* @access public * @access public
* @return void * @return void
*/ */
if ( ! function_exists('log_message'))
{
function log_message($level = 'error', $message, $php_error = FALSE) function log_message($level = 'error', $message, $php_error = FALSE)
{ {
static $_log; static $_log;
@@ -332,6 +358,7 @@
$_log =& load_class('Log'); $_log =& load_class('Log');
$_log->write_log($level, $message, $php_error); $_log->write_log($level, $message, $php_error);
} }
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -343,6 +370,8 @@
* @param string * @param string
* @return void * @return void
*/ */
if ( ! function_exists('set_status_header'))
{
function set_status_header($code = 200, $text = '') function set_status_header($code = 200, $text = '')
{ {
$stati = array( $stati = array(
@@ -417,6 +446,7 @@
header("HTTP/1.1 {$code} {$text}", TRUE, $code); header("HTTP/1.1 {$code} {$text}", TRUE, $code);
} }
} }
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -434,6 +464,8 @@
* @access private * @access private
* @return void * @return void
*/ */
if ( ! function_exists('_exception_handler'))
{
function _exception_handler($severity, $message, $filepath, $line) function _exception_handler($severity, $message, $filepath, $line)
{ {
// We don't bother with "strict" notices since they tend to fill up // We don't bother with "strict" notices since they tend to fill up
@@ -463,19 +495,22 @@
$_error->log_exception($severity, $message, $filepath, $line); $_error->log_exception($severity, $message, $filepath, $line);
} }
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Remove Invisible Characters * Remove Invisible Characters
* *
* This prevents sandwiching null characters * This prevents sandwiching null characters
* between ascii characters, like Java\0script. * between ascii characters, like Java\0script.
* *
* @access public * @access public
* @param string * @param string
* @return string * @return string
*/ */
if ( ! function_exists('remove_invisible_characters'))
{
function remove_invisible_characters($str, $url_encoded = TRUE) function remove_invisible_characters($str, $url_encoded = TRUE)
{ {
$non_displayables = array(); $non_displayables = array();
@@ -499,7 +534,7 @@
return $str; return $str;
} }
}
/* End of file Common.php */ /* End of file Common.php */
/* Location: ./system/core/Common.php */ /* Location: ./system/core/Common.php */

View File

@@ -80,7 +80,7 @@ class CI_Config {
*/ */
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{ {
$file = ($file == '') ? 'config' : str_replace(EXT, '', $file); $file = ($file == '') ? 'config' : str_replace('.php', '', $file);
$found = FALSE; $found = FALSE;
$loaded = FALSE; $loaded = FALSE;
@@ -92,7 +92,7 @@ class CI_Config {
foreach ($check_locations as $location) foreach ($check_locations as $location)
{ {
$file_path = $path.'config/'.$location.EXT; $file_path = $path.'config/'.$location.'.php';
if (in_array($file_path, $this->is_loaded, TRUE)) if (in_array($file_path, $this->is_loaded, TRUE))
{ {
@@ -144,6 +144,7 @@ class CI_Config {
$loaded = TRUE; $loaded = TRUE;
log_message('debug', 'Config file loaded: '.$file_path); log_message('debug', 'Config file loaded: '.$file_path);
break;
} }
if ($loaded === FALSE) if ($loaded === FALSE)
@@ -152,7 +153,7 @@ class CI_Config {
{ {
return FALSE; return FALSE;
} }
show_error('The configuration file '.$file.EXT.' does not exist.'); show_error('The configuration file '.$file.'.php'.' does not exist.');
} }
return TRUE; return TRUE;
@@ -202,10 +203,7 @@ class CI_Config {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Fetch a config file item - adds slash after item * Fetch a config file item - adds slash after item (if item is not empty)
*
* The second parameter allows a slash to be added to the end of
* the item, in the case of a path.
* *
* @access public * @access public
* @param string the config item name * @param string the config item name
@@ -218,6 +216,10 @@ class CI_Config {
{ {
return FALSE; return FALSE;
} }
if( trim($this->config[$item]) == '')
{
return '';
}
return rtrim($this->config[$item], '/').'/'; return rtrim($this->config[$item], '/').'/';
} }
@@ -226,6 +228,7 @@ class CI_Config {
/** /**
* Site URL * Site URL
* Returns base_url . index_page [. uri_string]
* *
* @access public * @access public
* @param string the URI string * @param string the URI string
@@ -238,16 +241,50 @@ class CI_Config {
return $this->slash_item('base_url').$this->item('index_page'); return $this->slash_item('base_url').$this->item('index_page');
} }
if ($this->item('enable_query_strings') == FALSE)
{
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
}
else
{
return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
}
}
// -------------------------------------------------------------
/**
* Base URL
* Returns base_url [. uri_string]
*
* @access public
* @param string $uri
* @return string
*/
function base_url($uri = '')
{
return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
}
// -------------------------------------------------------------
/**
* Build URI string for use in Config::site_url() and Config::base_url()
*
* @access protected
* @param $uri
* @return string
*/
protected function _uri_string($uri)
{
if ($this->item('enable_query_strings') == FALSE) if ($this->item('enable_query_strings') == FALSE)
{ {
if (is_array($uri)) if (is_array($uri))
{ {
$uri = implode('/', $uri); $uri = implode('/', $uri);
} }
$uri = trim($uri, '/');
$index = $this->item('index_page') == '' ? '' : $this->slash_item('index_page');
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
return $this->slash_item('base_url').$index.trim($uri, '/').$suffix;
} }
else else
{ {
@@ -261,12 +298,10 @@ class CI_Config {
$str .= $prefix.$key.'='.$val; $str .= $prefix.$key.'='.$val;
$i++; $i++;
} }
$uri = $str; $uri = $str;
} }
return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
} }
return $uri;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -48,12 +48,9 @@ class CI_Controller {
$this->load =& load_class('Loader', 'core'); $this->load =& load_class('Loader', 'core');
$this->load->_base_classes =& is_loaded(); $this->load->set_base_classes()->ci_autoloader();
$this->load->_ci_autoloader();
log_message('debug', "Controller Class Initialized"); log_message('debug', "Controller Class Initialized");
} }
public static function &get_instance() public static function &get_instance()

View File

@@ -128,7 +128,7 @@ class CI_Exceptions {
ob_end_flush(); ob_end_flush();
} }
ob_start(); ob_start();
include(APPPATH.'errors/'.$template.EXT); include(APPPATH.'errors/'.$template.'.php');
$buffer = ob_get_contents(); $buffer = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $buffer; return $buffer;
@@ -164,7 +164,7 @@ class CI_Exceptions {
ob_end_flush(); ob_end_flush();
} }
ob_start(); ob_start();
include(APPPATH.'errors/error_php'.EXT); include(APPPATH.'errors/error_php.php');
$buffer = ob_get_contents(); $buffer = ob_get_contents();
ob_end_clean(); ob_end_clean();
echo $buffer; echo $buffer;

View File

@@ -65,13 +65,13 @@ class CI_Hooks {
// Grab the "hooks" definition file. // Grab the "hooks" definition file.
// If there are no hooks, we're done. // If there are no hooks, we're done.
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
} }
elseif (is_file(APPPATH.'config/hooks'.EXT)) elseif (is_file(APPPATH.'config/hooks.php'))
{ {
include(APPPATH.'config/hooks'.EXT); include(APPPATH.'config/hooks.php');
} }

View File

@@ -672,7 +672,7 @@ class CI_Input {
*/ */
public function is_cli_request() public function is_cli_request()
{ {
return (bool) defined('STDIN'); return (php_sapi_name() == 'cli') or defined('STDIN');
} }
} }

View File

@@ -51,14 +51,14 @@ class CI_Lang {
*/ */
function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{ {
$langfile = str_replace(EXT, '', $langfile); $langfile = str_replace('.php', '', $langfile);
if ($add_suffix == TRUE) if ($add_suffix == TRUE)
{ {
$langfile = str_replace('_lang.', '', $langfile).'_lang'; $langfile = str_replace('_lang.', '', $langfile).'_lang';
} }
$langfile .= EXT; $langfile .= '.php';
if (in_array($langfile, $this->is_loaded, TRUE)) if (in_array($langfile, $this->is_loaded, TRUE))
{ {
@@ -129,15 +129,15 @@ class CI_Lang {
*/ */
function line($line = '') function line($line = '')
{ {
$line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
// Because killer robots like unicorns! // Because killer robots like unicorns!
if ($line === FALSE) if ($value === FALSE)
{ {
log_message('error', 'Could not find the language line "'.$line.'"'); log_message('error', 'Could not find the language line "'.$line.'"');
} }
return $line; return $value;
} }
} }

View File

@@ -29,53 +29,91 @@
class CI_Loader { class CI_Loader {
// All these are set automatically. Don't mess with them. // All these are set automatically. Don't mess with them.
var $_ci_ob_level; protected $_ci_ob_level;
var $_ci_view_path = ''; protected $_ci_view_paths = array();
var $_ci_library_paths = array(); protected $_ci_library_paths = array();
var $_ci_model_paths = array(); protected $_ci_model_paths = array();
var $_ci_helper_paths = array(); protected $_ci_helper_paths = array();
var $_base_classes = array(); // Set by the controller class protected $_base_classes = array(); // Set by the controller class
var $_ci_cached_vars = array(); protected $_ci_cached_vars = array();
var $_ci_classes = array(); protected $_ci_classes = array();
var $_ci_loaded_files = array(); protected $_ci_loaded_files = array();
var $_ci_models = array(); protected $_ci_models = array();
var $_ci_helpers = array(); protected $_ci_helpers = array();
var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); protected $_ci_varmap = array('unit_test' => 'unit',
'user_agent' => 'agent');
/** /**
* Constructor * Constructor
* *
* Sets the path to the view files and gets the initial output buffering level * Sets the path to the view files and gets the initial output buffering level
*
* @access public
*/ */
function __construct() public function __construct()
{ {
$this->_ci_view_path = APPPATH.'views/';
$this->_ci_ob_level = ob_get_level(); $this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(APPPATH, BASEPATH); $this->_ci_library_paths = array(APPPATH, BASEPATH);
$this->_ci_helper_paths = array(APPPATH, BASEPATH); $this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH); $this->_ci_model_paths = array(APPPATH);
$this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
log_message('debug', "Loader Class Initialized"); log_message('debug', "Loader Class Initialized");
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Set _base_classes variable
*
* This method is called once in CI_Controller.
*
* @param array
* @return object
*/
public function set_base_classes()
{
$this->_base_classes =& is_loaded();
return $this;
}
// --------------------------------------------------------------------
/**
* Is Loaded
*
* A utility function to test if a class is in the self::$_ci_classes array.
* This function returns the object name if the class tested for is loaded,
* and returns FALSE if it isn't.
*
* It is mainly used in the form_helper -> _get_validation_object()
*
* @param string class being checked for
* @return mixed class object name on the CI SuperObject or FALSE
*/
public function is_loaded($class)
{
if (isset($this->_ci_classes[$class]))
{
return $this->_ci_classes[$class];
}
return FALSE;
}
// --------------------------------------------------------------------
/** /**
* Class Loader * Class Loader
* *
* This function lets users load and instantiate classes. * This function lets users load and instantiate classes.
* It is designed to be called from a user's app controllers. * It is designed to be called from a user's app controllers.
* *
* @access public
* @param string the name of the class * @param string the name of the class
* @param mixed the optional parameters * @param mixed the optional parameters
* @param string an optional object name * @param string an optional object name
* @return void * @return void
*/ */
function library($library = '', $params = NULL, $object_name = NULL) public function library($library = '', $params = NULL, $object_name = NULL)
{ {
if (is_array($library)) if (is_array($library))
{ {
@@ -107,13 +145,12 @@ class CI_Loader {
* *
* This function lets users load and instantiate models. * This function lets users load and instantiate models.
* *
* @access public
* @param string the name of the class * @param string the name of the class
* @param string name for the model * @param string name for the model
* @param bool database connection * @param bool database connection
* @return void * @return void
*/ */
function model($model, $name = '', $db_conn = FALSE) public function model($model, $name = '', $db_conn = FALSE)
{ {
if (is_array($model)) if (is_array($model))
{ {
@@ -161,7 +198,7 @@ class CI_Loader {
foreach ($this->_ci_model_paths as $mod_path) foreach ($this->_ci_model_paths as $mod_path)
{ {
if ( ! file_exists($mod_path.'models/'.$path.$model.EXT)) if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{ {
continue; continue;
} }
@@ -181,7 +218,7 @@ class CI_Loader {
load_class('Model', 'core'); load_class('Model', 'core');
} }
require_once($mod_path.'models/'.$path.$model.EXT); require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model); $model = ucfirst($model);
@@ -200,13 +237,12 @@ class CI_Loader {
/** /**
* Database Loader * Database Loader
* *
* @access public
* @param string the DB credentials * @param string the DB credentials
* @param bool whether to return the DB object * @param bool whether to return the DB object
* @param bool whether to enable active record (this allows us to override the config setting) * @param bool whether to enable active record (this allows us to override the config setting)
* @return object * @return object
*/ */
function database($params = '', $return = FALSE, $active_record = NULL) public function database($params = '', $return = FALSE, $active_record = NULL)
{ {
// Grab the super object // Grab the super object
$CI =& get_instance(); $CI =& get_instance();
@@ -217,7 +253,7 @@ class CI_Loader {
return FALSE; return FALSE;
} }
require_once(BASEPATH.'database/DB'.EXT); require_once(BASEPATH.'database/DB.php');
if ($return === TRUE) if ($return === TRUE)
{ {
@@ -237,10 +273,9 @@ class CI_Loader {
/** /**
* Load the Utilities Class * Load the Utilities Class
* *
* @access public
* @return string * @return string
*/ */
function dbutil() public function dbutil()
{ {
if ( ! class_exists('CI_DB')) if ( ! class_exists('CI_DB'))
{ {
@@ -253,8 +288,8 @@ class CI_Loader {
// this use is deprecated and strongly discouraged // this use is deprecated and strongly discouraged
$CI->load->dbforge(); $CI->load->dbforge();
require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/DB_utility.php');
require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
$CI->dbutil = new $class(); $CI->dbutil = new $class();
@@ -265,10 +300,9 @@ class CI_Loader {
/** /**
* Load the Database Forge Class * Load the Database Forge Class
* *
* @access public
* @return string * @return string
*/ */
function dbforge() public function dbforge()
{ {
if ( ! class_exists('CI_DB')) if ( ! class_exists('CI_DB'))
{ {
@@ -277,8 +311,8 @@ class CI_Loader {
$CI =& get_instance(); $CI =& get_instance();
require_once(BASEPATH.'database/DB_forge'.EXT); require_once(BASEPATH.'database/DB_forge.php');
require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
$CI->dbforge = new $class(); $CI->dbforge = new $class();
@@ -297,13 +331,12 @@ class CI_Loader {
* some cases it's advantageous to be able to return data so that * some cases it's advantageous to be able to return data so that
* a developer can process it in some way. * a developer can process it in some way.
* *
* @access public
* @param string * @param string
* @param array * @param array
* @param bool * @param bool
* @return void * @return void
*/ */
function view($view, $vars = array(), $return = FALSE) public function view($view, $vars = array(), $return = FALSE)
{ {
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
} }
@@ -315,12 +348,11 @@ class CI_Loader {
* *
* This is a generic file loader * This is a generic file loader
* *
* @access public
* @param string * @param string
* @param bool * @param bool
* @return string * @return string
*/ */
function file($path, $return = FALSE) public function file($path, $return = FALSE)
{ {
return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
} }
@@ -333,11 +365,10 @@ class CI_Loader {
* Once variables are set they become available within * Once variables are set they become available within
* the controller class and its "view" files. * the controller class and its "view" files.
* *
* @access public
* @param array * @param array
* @return void * @return void
*/ */
function vars($vars = array(), $val = '') public function vars($vars = array(), $val = '')
{ {
if ($val != '' AND is_string($vars)) if ($val != '' AND is_string($vars))
{ {
@@ -357,16 +388,30 @@ class CI_Loader {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Get Variable
*
* Check if a variable is set and retrieve it.
*
* @param array
* @return void
*/
public function get_var($key)
{
return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
}
// --------------------------------------------------------------------
/** /**
* Load Helper * Load Helper
* *
* This function loads the specified helper file. * This function loads the specified helper file.
* *
* @access public
* @param mixed * @param mixed
* @return void * @return void
*/ */
function helper($helpers = array()) public function helper($helpers = array())
{ {
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
{ {
@@ -375,16 +420,16 @@ class CI_Loader {
continue; continue;
} }
$ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
// Is this a helper extension request? // Is this a helper extension request?
if (file_exists($ext_helper)) if (file_exists($ext_helper))
{ {
$base_helper = BASEPATH.'helpers/'.$helper.EXT; $base_helper = BASEPATH.'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper)) if ( ! file_exists($base_helper))
{ {
show_error('Unable to load the requested file: helpers/'.$helper.EXT); show_error('Unable to load the requested file: helpers/'.$helper.'.php');
} }
include_once($ext_helper); include_once($ext_helper);
@@ -398,9 +443,9 @@ class CI_Loader {
// Try to load the helper // Try to load the helper
foreach ($this->_ci_helper_paths as $path) foreach ($this->_ci_helper_paths as $path)
{ {
if (file_exists($path.'helpers/'.$helper.EXT)) if (file_exists($path.'helpers/'.$helper.'.php'))
{ {
include_once($path.'helpers/'.$helper.EXT); include_once($path.'helpers/'.$helper.'.php');
$this->_ci_helpers[$helper] = TRUE; $this->_ci_helpers[$helper] = TRUE;
log_message('debug', 'Helper loaded: '.$helper); log_message('debug', 'Helper loaded: '.$helper);
@@ -411,7 +456,7 @@ class CI_Loader {
// unable to load the helper // unable to load the helper
if ( ! isset($this->_ci_helpers[$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.'.php');
} }
} }
} }
@@ -424,11 +469,10 @@ class CI_Loader {
* This is simply an alias to the above function in case the * This is simply an alias to the above function in case the
* user has written the plural form of this function. * user has written the plural form of this function.
* *
* @access public
* @param array * @param array
* @return void * @return void
*/ */
function helpers($helpers = array()) public function helpers($helpers = array())
{ {
$this->helper($helpers); $this->helper($helpers);
} }
@@ -438,12 +482,11 @@ class CI_Loader {
/** /**
* Loads a language file * Loads a language file
* *
* @access public
* @param array * @param array
* @param string * @param string
* @return void * @return void
*/ */
function language($file = array(), $lang = '') public function language($file = array(), $lang = '')
{ {
$CI =& get_instance(); $CI =& get_instance();
@@ -463,11 +506,10 @@ class CI_Loader {
/** /**
* Loads a config file * Loads a config file
* *
* @access public
* @param string * @param string
* @return void * @return void
*/ */
function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{ {
$CI =& get_instance(); $CI =& get_instance();
$CI->config->load($file, $use_sections, $fail_gracefully); $CI->config->load($file, $use_sections, $fail_gracefully);
@@ -485,12 +527,12 @@ class CI_Loader {
* @param string an optional object name * @param string an optional object name
* @return void * @return void
*/ */
function driver($library = '', $params = NULL, $object_name = NULL) public function driver($library = '', $params = NULL, $object_name = NULL)
{ {
if ( ! class_exists('CI_Driver_Library')) if ( ! class_exists('CI_Driver_Library'))
{ {
// we aren't instantiating an object here, that'll be done by the Library itself // we aren't instantiating an object here, that'll be done by the Library itself
require BASEPATH.'libraries/Driver'.EXT; require BASEPATH.'libraries/Driver.php';
} }
// We can save the loader some time since Drivers will *always* be in a subfolder, // We can save the loader some time since Drivers will *always* be in a subfolder,
@@ -510,11 +552,11 @@ class CI_Loader {
* *
* Prepends a parent path to the library, model, helper, and config path arrays * Prepends a parent path to the library, model, helper, and config path arrays
* *
* @access public
* @param string * @param string
* @param boolean
* @return void * @return void
*/ */
function add_package_path($path) public function add_package_path($path, $view_cascade=TRUE)
{ {
$path = rtrim($path, '/').'/'; $path = rtrim($path, '/').'/';
@@ -522,6 +564,8 @@ class CI_Loader {
array_unshift($this->_ci_model_paths, $path); array_unshift($this->_ci_model_paths, $path);
array_unshift($this->_ci_helper_paths, $path); array_unshift($this->_ci_helper_paths, $path);
$this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
// Add config file path // Add config file path
$config =& $this->_ci_get_component('config'); $config =& $this->_ci_get_component('config');
array_unshift($config->_config_paths, $path); array_unshift($config->_config_paths, $path);
@@ -534,11 +578,10 @@ class CI_Loader {
* *
* Return a list of all package paths, by default it will ignore BASEPATH. * Return a list of all package paths, by default it will ignore BASEPATH.
* *
* @access public
* @param string * @param string
* @return void * @return void
*/ */
function get_package_paths($include_base = FALSE) public function get_package_paths($include_base = FALSE)
{ {
return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths; return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
} }
@@ -551,11 +594,10 @@ class CI_Loader {
* Remove a path from the library, model, and helper path arrays if it exists * Remove a path from the library, model, and helper path arrays if it exists
* If no path is provided, the most recently added path is removed. * If no path is provided, the most recently added path is removed.
* *
* @access public
* @param type * @param type
* @return type * @return type
*/ */
function remove_package_path($path = '', $remove_config_path = TRUE) public function remove_package_path($path = '', $remove_config_path = TRUE)
{ {
$config =& $this->_ci_get_component('config'); $config =& $this->_ci_get_component('config');
@@ -564,12 +606,12 @@ class CI_Loader {
$void = array_shift($this->_ci_library_paths); $void = array_shift($this->_ci_library_paths);
$void = array_shift($this->_ci_model_paths); $void = array_shift($this->_ci_model_paths);
$void = array_shift($this->_ci_helper_paths); $void = array_shift($this->_ci_helper_paths);
$void = array_shift($this->_ci_view_paths);
$void = array_shift($config->_config_paths); $void = array_shift($config->_config_paths);
} }
else else
{ {
$path = rtrim($path, '/').'/'; $path = rtrim($path, '/').'/';
foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
{ {
if (($key = array_search($path, $this->{$var})) !== FALSE) if (($key = array_search($path, $this->{$var})) !== FALSE)
@@ -578,6 +620,11 @@ class CI_Loader {
} }
} }
if (isset($this->_ci_view_paths[$path.'views/']))
{
unset($this->_ci_view_paths[$path.'views/']);
}
if (($key = array_search($path, $config->_config_paths)) !== FALSE) if (($key = array_search($path, $config->_config_paths)) !== FALSE)
{ {
unset($config->_config_paths[$key]); unset($config->_config_paths[$key]);
@@ -588,6 +635,7 @@ class CI_Loader {
$this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); $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))); $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
$this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
$this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
$config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
} }
@@ -600,11 +648,10 @@ class CI_Loader {
* Variables are prefixed with _ci_ to avoid symbol collision with * Variables are prefixed with _ci_ to avoid symbol collision with
* variables made available to view files * variables made available to view files
* *
* @access private
* @param array * @param array
* @return void * @return void
*/ */
function _ci_load($_ci_data) protected function _ci_load($_ci_data)
{ {
// Set the default data variables // Set the default data variables
foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
@@ -612,20 +659,36 @@ class CI_Loader {
$$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
} }
$file_exists = FALSE;
// Set the path to the requested file // Set the path to the requested file
if ($_ci_path == '') if ($_ci_path != '')
{
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
$_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
$_ci_path = $this->_ci_view_path.$_ci_file;
}
else
{ {
$_ci_x = explode('/', $_ci_path); $_ci_x = explode('/', $_ci_path);
$_ci_file = end($_ci_x); $_ci_file = end($_ci_x);
} }
else
{
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
$_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;
if ( ! file_exists($_ci_path)) foreach ($this->_ci_view_paths as $view_file => $cascade)
{
if (file_exists($view_file.$_ci_file))
{
$_ci_path = $view_file.$_ci_file;
$file_exists = TRUE;
break;
}
if ( ! $cascade)
{
break;
}
}
}
if ( ! $file_exists && ! file_exists($_ci_path))
{ {
show_error('Unable to load the requested file: '.$_ci_file); show_error('Unable to load the requested file: '.$_ci_file);
} }
@@ -721,18 +784,17 @@ class CI_Loader {
* *
* This function loads the requested class. * 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 mixed any additional parameters
* @param string an optional object name * @param string an optional object name
* @return void * @return void
*/ */
function _ci_load_class($class, $params = NULL, $object_name = NULL) protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
{ {
// Get the class name, and while we're at it trim any slashes. // 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, // The directory path can be included as part of the class name,
// but we don't want a leading slash // but we don't want a leading slash
$class = str_replace(EXT, '', trim($class, '/')); $class = str_replace('.php', '', trim($class, '/'));
// Was the path included with the class name? // Was the path included with the class name?
// We look for a slash to determine this // We look for a slash to determine this
@@ -749,12 +811,12 @@ class CI_Loader {
// We'll test for both lowercase and capitalized versions of the file name // We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class) foreach (array(ucfirst($class), strtolower($class)) as $class)
{ {
$subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
// Is this a class extension request? // Is this a class extension request?
if (file_exists($subclass)) if (file_exists($subclass))
{ {
$baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
if ( ! file_exists($baseclass)) if ( ! file_exists($baseclass))
{ {
@@ -793,7 +855,7 @@ class CI_Loader {
$is_duplicate = FALSE; $is_duplicate = FALSE;
foreach ($this->_ci_library_paths as $path) foreach ($this->_ci_library_paths as $path)
{ {
$filepath = $path.'libraries/'.$subdir.$class.EXT; $filepath = $path.'libraries/'.$subdir.$class.'.php';
// Does the file exist? No? Bummer... // Does the file exist? No? Bummer...
if ( ! file_exists($filepath)) if ( ! file_exists($filepath))
@@ -849,13 +911,12 @@ class CI_Loader {
/** /**
* Instantiates a class * Instantiates a class
* *
* @access private
* @param string * @param string
* @param string * @param string
* @param string an optional object name * @param string an optional object name
* @return null * @return null
*/ */
function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) protected 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 // Is there an associated config file for this class? Note: these should always be lowercase
if ($config === NULL) if ($config === NULL)
@@ -872,24 +933,24 @@ class CI_Loader {
// We test for both uppercase and lowercase, for servers that // We test for both uppercase and lowercase, for servers that
// are case-sensitive with regard to file names. Check for environment // are case-sensitive with regard to file names. Check for environment
// first, global next // first, global next
if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT)) if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
{ {
include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT); include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
break; break;
} }
elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT)) elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
{ {
include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT); include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
break; break;
} }
elseif (file_exists($path .'config/'.strtolower($class).EXT)) elseif (file_exists($path .'config/'.strtolower($class).'.php'))
{ {
include_once($path .'config/'.strtolower($class).EXT); include_once($path .'config/'.strtolower($class).'.php');
break; break;
} }
elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).EXT)) elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php'))
{ {
include_once($path .'config/'.ucfirst(strtolower($class)).EXT); include_once($path .'config/'.ucfirst(strtolower($class)).'.php');
break; break;
} }
} }
@@ -959,19 +1020,21 @@ class CI_Loader {
* The config/autoload.php file contains an array that permits sub-systems, * The config/autoload.php file contains an array that permits sub-systems,
* libraries, and helpers to be loaded automatically. * libraries, and helpers to be loaded automatically.
* *
* @access private * This function is public, as it's used in the CI_Controller class.
* However, there is no reason you should ever needs to use it.
*
* @param array * @param array
* @return void * @return void
*/ */
function _ci_autoloader() public function ci_autoloader()
{ {
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT)) if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
{ {
include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT); include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
} }
else else
{ {
include_once(APPPATH.'config/autoload'.EXT); include_once(APPPATH.'config/autoload.php');
} }
@@ -1046,11 +1109,10 @@ class CI_Loader {
* *
* Takes an object as input and converts the class variables to array key/vals * Takes an object as input and converts the class variables to array key/vals
* *
* @access private
* @param object * @param object
* @return array * @return array
*/ */
function _ci_object_to_array($object) protected function _ci_object_to_array($object)
{ {
return (is_object($object)) ? get_object_vars($object) : $object; return (is_object($object)) ? get_object_vars($object) : $object;
} }
@@ -1060,10 +1122,9 @@ class CI_Loader {
/** /**
* Get a reference to a specific library or model * Get a reference to a specific library or model
* *
* @access private
* @return bool * @return bool
*/ */
function &_ci_get_component($component) protected function &_ci_get_component($component)
{ {
$CI =& get_instance(); $CI =& get_instance();
return $CI->$component; return $CI->$component;
@@ -1076,28 +1137,25 @@ class CI_Loader {
* *
* This function preps the name of various items to make loading them more reliable. * This function preps the name of various items to make loading them more reliable.
* *
* @access private
* @param mixed * @param mixed
* @return array * @return array
*/ */
function _ci_prep_filename($filename, $extension) protected function _ci_prep_filename($filename, $extension)
{ {
if ( ! is_array($filename)) if ( ! is_array($filename))
{ {
return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension)); return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension));
} }
else else
{ {
foreach ($filename as $key => $val) foreach ($filename as $key => $val)
{ {
$filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension); $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension);
} }
return $filename; return $filename;
} }
} }
} }
/* End of file Loader.php */ /* End of file Loader.php */

View File

@@ -42,13 +42,13 @@ class CI_Output {
$this->_zlib_oc = @ini_get('zlib.output_compression'); $this->_zlib_oc = @ini_get('zlib.output_compression');
// Get mime types for later // Get mime types for later
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{ {
include APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT; include APPPATH.'config/'.ENVIRONMENT.'/mimes.php';
} }
else else
{ {
include APPPATH.'config/mimes'.EXT; include APPPATH.'config/mimes.php';
} }

View File

@@ -87,13 +87,13 @@ class CI_Router {
} }
// Load the routes.php file. // Load the routes.php file.
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
} }
elseif (is_file(APPPATH.'config/routes'.EXT)) elseif (is_file(APPPATH.'config/routes.php'))
{ {
include(APPPATH.'config/routes'.EXT); include(APPPATH.'config/routes.php');
} }
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
@@ -227,7 +227,7 @@ class CI_Router {
} }
// Does the requested controller exist in the root folder? // Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
{ {
return $segments; return $segments;
} }
@@ -242,7 +242,7 @@ class CI_Router {
if (count($segments) > 0) if (count($segments) > 0)
{ {
// Does the requested controller exist in the sub-folder? // Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{ {
show_404($this->fetch_directory().$segments[0]); show_404($this->fetch_directory().$segments[0]);
} }
@@ -264,7 +264,7 @@ class CI_Router {
} }
// Does the default controller exist in the sub-folder? // Does the default controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
{ {
$this->directory = ''; $this->directory = '';
return array(); return array();

View File

@@ -58,8 +58,20 @@ class CI_Security {
*/ */
public function __construct() public function __construct()
{ {
// Append application specific cookie prefix to token name // CSRF config
$this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; foreach(array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
{
if (FALSE !== ($val = config_item($key)))
{
$this->{'_'.$key} = $val;
}
}
// Append application specific cookie prefix
if (config_item('cookie_prefix'))
{
$this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
}
// Set the CSRF hash // Set the CSRF hash
$this->_csrf_set_hash(); $this->_csrf_set_hash();

View File

@@ -62,7 +62,7 @@ class CI_URI {
if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
{ {
// Is the request coming from the command line? // Is the request coming from the command line?
if (defined('STDIN')) if (php_sapi_name() == 'cli' or defined('STDIN'))
{ {
$this->_set_uri_string($this->_parse_cli_args()); $this->_set_uri_string($this->_parse_cli_args());
return; return;
@@ -151,7 +151,7 @@ class CI_URI {
*/ */
private function _detect_uri() private function _detect_uri()
{ {
if ( ! isset($_SERVER['REQUEST_URI'])) if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
{ {
return ''; return '';
} }

View File

@@ -28,11 +28,11 @@ function &DB($params = '', $active_record_override = NULL)
if (is_string($params) AND strpos($params, '://') === FALSE) if (is_string($params) AND strpos($params, '://') === FALSE)
{ {
// Is the config file in the environment folder? // Is the config file in the environment folder?
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT)) if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
{ {
if ( ! file_exists($file_path = APPPATH.'config/database'.EXT)) if ( ! file_exists($file_path = APPPATH.'config/database.php'))
{ {
show_error('The configuration file database'.EXT.' does not exist.'); show_error('The configuration file database.php does not exist.');
} }
} }
@@ -116,11 +116,11 @@ function &DB($params = '', $active_record_override = NULL)
$active_record = $active_record_override; $active_record = $active_record_override;
} }
require_once(BASEPATH.'database/DB_driver'.EXT); require_once(BASEPATH.'database/DB_driver.php');
if ( ! isset($active_record) OR $active_record == TRUE) if ( ! isset($active_record) OR $active_record == TRUE)
{ {
require_once(BASEPATH.'database/DB_active_rec'.EXT); require_once(BASEPATH.'database/DB_active_rec.php');
if ( ! class_exists('CI_DB')) if ( ! class_exists('CI_DB'))
{ {
@@ -135,7 +135,7 @@ function &DB($params = '', $active_record_override = NULL)
} }
} }
require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
// Instantiate the DB adapter // Instantiate the DB adapter
$driver = 'CI_DB_'.$params['dbdriver'].'_driver'; $driver = 'CI_DB_'.$params['dbdriver'].'_driver';

View File

@@ -59,6 +59,8 @@ class CI_DB_active_record extends CI_DB_driver {
var $ar_cache_orderby = array(); var $ar_cache_orderby = array();
var $ar_cache_set = array(); var $ar_cache_set = array();
var $ar_no_escape = array();
var $ar_cache_no_escape = array();
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -67,18 +69,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates the SELECT portion of the query * Generates the SELECT portion of the query
* *
* @access public
* @param string * @param string
* @return object * @return object
*/ */
function select($select = '*', $escape = NULL) public function select($select = '*', $escape = NULL)
{ {
// Set the global value if this was sepecified
if (is_bool($escape))
{
$this->_protect_identifiers = $escape;
}
if (is_string($select)) if (is_string($select))
{ {
$select = explode(',', $select); $select = explode(',', $select);
@@ -91,11 +86,13 @@ class CI_DB_active_record extends CI_DB_driver {
if ($val != '') if ($val != '')
{ {
$this->ar_select[] = $val; $this->ar_select[] = $val;
$this->ar_no_escape[] = $escape;
if ($this->ar_caching === TRUE) if ($this->ar_caching === TRUE)
{ {
$this->ar_cache_select[] = $val; $this->ar_cache_select[] = $val;
$this->ar_cache_exists[] = 'select'; $this->ar_cache_exists[] = 'select';
$this->ar_cache_no_escape[] = $escape;
} }
} }
} }
@@ -109,12 +106,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates a SELECT MAX(field) portion of a query * Generates a SELECT MAX(field) portion of a query
* *
* @access public
* @param string the field * @param string the field
* @param string an alias * @param string an alias
* @return object * @return object
*/ */
function select_max($select = '', $alias = '') public function select_max($select = '', $alias = '')
{ {
return $this->_max_min_avg_sum($select, $alias, 'MAX'); return $this->_max_min_avg_sum($select, $alias, 'MAX');
} }
@@ -126,12 +122,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates a SELECT MIN(field) portion of a query * Generates a SELECT MIN(field) portion of a query
* *
* @access public
* @param string the field * @param string the field
* @param string an alias * @param string an alias
* @return object * @return object
*/ */
function select_min($select = '', $alias = '') public function select_min($select = '', $alias = '')
{ {
return $this->_max_min_avg_sum($select, $alias, 'MIN'); return $this->_max_min_avg_sum($select, $alias, 'MIN');
} }
@@ -143,12 +138,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates a SELECT AVG(field) portion of a query * Generates a SELECT AVG(field) portion of a query
* *
* @access public
* @param string the field * @param string the field
* @param string an alias * @param string an alias
* @return object * @return object
*/ */
function select_avg($select = '', $alias = '') public function select_avg($select = '', $alias = '')
{ {
return $this->_max_min_avg_sum($select, $alias, 'AVG'); return $this->_max_min_avg_sum($select, $alias, 'AVG');
} }
@@ -160,12 +154,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates a SELECT SUM(field) portion of a query * Generates a SELECT SUM(field) portion of a query
* *
* @access public
* @param string the field * @param string the field
* @param string an alias * @param string an alias
* @return object * @return object
*/ */
function select_sum($select = '', $alias = '') public function select_sum($select = '', $alias = '')
{ {
return $this->_max_min_avg_sum($select, $alias, 'SUM'); return $this->_max_min_avg_sum($select, $alias, 'SUM');
} }
@@ -180,12 +173,11 @@ class CI_DB_active_record extends CI_DB_driver {
* select_avg() * select_avg()
* select_sum() * select_sum()
* *
* @access public
* @param string the field * @param string the field
* @param string an alias * @param string an alias
* @return object * @return object
*/ */
function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
{ {
if ( ! is_string($select) OR $select == '') if ( ! is_string($select) OR $select == '')
{ {
@@ -222,11 +214,10 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Determines the alias name based on the table * Determines the alias name based on the table
* *
* @access private
* @param string * @param string
* @return string * @return string
*/ */
function _create_alias_from_table($item) protected function _create_alias_from_table($item)
{ {
if (strpos($item, '.') !== FALSE) if (strpos($item, '.') !== FALSE)
{ {
@@ -243,11 +234,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Sets a flag which tells the query string compiler to add DISTINCT * Sets a flag which tells the query string compiler to add DISTINCT
* *
* @access public
* @param bool * @param bool
* @return object * @return object
*/ */
function distinct($val = TRUE) public function distinct($val = TRUE)
{ {
$this->ar_distinct = (is_bool($val)) ? $val : TRUE; $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
return $this; return $this;
@@ -260,11 +250,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates the FROM portion of the query * Generates the FROM portion of the query
* *
* @access public
* @param mixed can be a string or array * @param mixed can be a string or array
* @return object * @return object
*/ */
function from($from) public function from($from)
{ {
foreach ((array)$from as $val) foreach ((array)$from as $val)
{ {
@@ -313,13 +302,12 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Generates the JOIN portion of the query * Generates the JOIN portion of the query
* *
* @access public
* @param string * @param string
* @param string the join condition * @param string the join condition
* @param string the type of join * @param string the type of join
* @return object * @return object
*/ */
function join($table, $cond, $type = '') public function join($table, $cond, $type = '')
{ {
if ($type != '') if ($type != '')
{ {
@@ -369,12 +357,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates the WHERE portion of the query. Separates * Generates the WHERE portion of the query. Separates
* multiple calls with AND * multiple calls with AND
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function where($key, $value = NULL, $escape = TRUE) public function where($key, $value = NULL, $escape = TRUE)
{ {
return $this->_where($key, $value, 'AND ', $escape); return $this->_where($key, $value, 'AND ', $escape);
} }
@@ -387,12 +374,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates the WHERE portion of the query. Separates * Generates the WHERE portion of the query. Separates
* multiple calls with OR * multiple calls with OR
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function or_where($key, $value = NULL, $escape = TRUE) public function or_where($key, $value = NULL, $escape = TRUE)
{ {
return $this->_where($key, $value, 'OR ', $escape); return $this->_where($key, $value, 'OR ', $escape);
} }
@@ -402,15 +388,14 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Where * Where
* *
* Called by where() or orwhere() * Called by where() or or_where()
* *
* @access private
* @param mixed * @param mixed
* @param mixed * @param mixed
* @param string * @param string
* @return object * @return object
*/ */
function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{ {
if ( ! is_array($key)) if ( ! is_array($key))
{ {
@@ -444,7 +429,7 @@ class CI_DB_active_record extends CI_DB_driver {
if ( ! $this->_has_operator($k)) if ( ! $this->_has_operator($k))
{ {
$k .= ' ='; $k .= ' = ';
} }
} }
else else
@@ -473,12 +458,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field IN ('item', 'item') SQL query joined with * Generates a WHERE field IN ('item', 'item') SQL query joined with
* AND if appropriate * AND if appropriate
* *
* @access public
* @param string The field to search * @param string The field to search
* @param array The values searched on * @param array The values searched on
* @return object * @return object
*/ */
function where_in($key = NULL, $values = NULL) public function where_in($key = NULL, $values = NULL)
{ {
return $this->_where_in($key, $values); return $this->_where_in($key, $values);
} }
@@ -491,12 +475,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field IN ('item', 'item') SQL query joined with * Generates a WHERE field IN ('item', 'item') SQL query joined with
* OR if appropriate * OR if appropriate
* *
* @access public
* @param string The field to search * @param string The field to search
* @param array The values searched on * @param array The values searched on
* @return object * @return object
*/ */
function or_where_in($key = NULL, $values = NULL) public function or_where_in($key = NULL, $values = NULL)
{ {
return $this->_where_in($key, $values, FALSE, 'OR '); return $this->_where_in($key, $values, FALSE, 'OR ');
} }
@@ -509,12 +492,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field NOT IN ('item', 'item') SQL query joined * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
* with AND if appropriate * with AND if appropriate
* *
* @access public
* @param string The field to search * @param string The field to search
* @param array The values searched on * @param array The values searched on
* @return object * @return object
*/ */
function where_not_in($key = NULL, $values = NULL) public function where_not_in($key = NULL, $values = NULL)
{ {
return $this->_where_in($key, $values, TRUE); return $this->_where_in($key, $values, TRUE);
} }
@@ -527,12 +509,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field NOT IN ('item', 'item') SQL query joined * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
* with OR if appropriate * with OR if appropriate
* *
* @access public
* @param string The field to search * @param string The field to search
* @param array The values searched on * @param array The values searched on
* @return object * @return object
*/ */
function or_where_not_in($key = NULL, $values = NULL) public function or_where_not_in($key = NULL, $values = NULL)
{ {
return $this->_where_in($key, $values, TRUE, 'OR '); return $this->_where_in($key, $values, TRUE, 'OR ');
} }
@@ -544,14 +525,13 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Called by where_in, where_in_or, where_not_in, where_not_in_or * Called by where_in, where_in_or, where_not_in, where_not_in_or
* *
* @access public
* @param string The field to search * @param string The field to search
* @param array The values searched on * @param array The values searched on
* @param boolean If the statement would be IN or NOT IN * @param boolean If the statement would be IN or NOT IN
* @param string * @param string
* @return object * @return object
*/ */
function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
{ {
if ($key === NULL OR $values === NULL) if ($key === NULL OR $values === NULL)
{ {
@@ -594,12 +574,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a %LIKE% portion of the query. Separates * Generates a %LIKE% portion of the query. Separates
* multiple calls with AND * multiple calls with AND
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function like($field, $match = '', $side = 'both') public function like($field, $match = '', $side = 'both')
{ {
return $this->_like($field, $match, 'AND ', $side); return $this->_like($field, $match, 'AND ', $side);
} }
@@ -612,12 +591,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a NOT LIKE portion of the query. Separates * Generates a NOT LIKE portion of the query. Separates
* multiple calls with AND * multiple calls with AND
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function not_like($field, $match = '', $side = 'both') public function not_like($field, $match = '', $side = 'both')
{ {
return $this->_like($field, $match, 'AND ', $side, 'NOT'); return $this->_like($field, $match, 'AND ', $side, 'NOT');
} }
@@ -630,12 +608,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a %LIKE% portion of the query. Separates * Generates a %LIKE% portion of the query. Separates
* multiple calls with OR * multiple calls with OR
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function or_like($field, $match = '', $side = 'both') public function or_like($field, $match = '', $side = 'both')
{ {
return $this->_like($field, $match, 'OR ', $side); return $this->_like($field, $match, 'OR ', $side);
} }
@@ -648,12 +625,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a NOT LIKE portion of the query. Separates * Generates a NOT LIKE portion of the query. Separates
* multiple calls with OR * multiple calls with OR
* *
* @access public
* @param mixed * @param mixed
* @param mixed * @param mixed
* @return object * @return object
*/ */
function or_not_like($field, $match = '', $side = 'both') public function or_not_like($field, $match = '', $side = 'both')
{ {
return $this->_like($field, $match, 'OR ', $side, 'NOT'); return $this->_like($field, $match, 'OR ', $side, 'NOT');
} }
@@ -665,13 +641,12 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Called by like() or orlike() * Called by like() or orlike()
* *
* @access private
* @param mixed * @param mixed
* @param mixed * @param mixed
* @param string * @param string
* @return object * @return object
*/ */
function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{ {
if ( ! is_array($field)) if ( ! is_array($field))
{ {
@@ -721,11 +696,10 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* GROUP BY * GROUP BY
* *
* @access public
* @param string * @param string
* @return object * @return object
*/ */
function group_by($by) public function group_by($by)
{ {
if (is_string($by)) if (is_string($by))
{ {
@@ -757,12 +731,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Separates multiple calls with AND * Separates multiple calls with AND
* *
* @access public
* @param string * @param string
* @param string * @param string
* @return object * @return object
*/ */
function having($key, $value = '', $escape = TRUE) public function having($key, $value = '', $escape = TRUE)
{ {
return $this->_having($key, $value, 'AND ', $escape); return $this->_having($key, $value, 'AND ', $escape);
} }
@@ -774,12 +747,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Separates multiple calls with OR * Separates multiple calls with OR
* *
* @access public
* @param string * @param string
* @param string * @param string
* @return object * @return object
*/ */
function or_having($key, $value = '', $escape = TRUE) public function or_having($key, $value = '', $escape = TRUE)
{ {
return $this->_having($key, $value, 'OR ', $escape); return $this->_having($key, $value, 'OR ', $escape);
} }
@@ -791,12 +763,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Called by having() or or_having() * Called by having() or or_having()
* *
* @access private
* @param string * @param string
* @param string * @param string
* @return object * @return object
*/ */
function _having($key, $value = '', $type = 'AND ', $escape = TRUE) protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
{ {
if ( ! is_array($key)) if ( ! is_array($key))
{ {
@@ -819,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver {
if ($v != '') if ($v != '')
{ {
$v = ' '.$this->escape_str($v); $v = ' '.$this->escape($v);
} }
$this->ar_having[] = $prefix.$k.$v; $this->ar_having[] = $prefix.$k.$v;
@@ -838,12 +809,11 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Sets the ORDER BY value * Sets the ORDER BY value
* *
* @access public
* @param string * @param string
* @param string direction: asc or desc * @param string direction: asc or desc
* @return object * @return object
*/ */
function order_by($orderby, $direction = '') public function order_by($orderby, $direction = '')
{ {
if (strtolower($direction) == 'random') if (strtolower($direction) == 'random')
{ {
@@ -894,12 +864,11 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Sets the LIMIT value * Sets the LIMIT value
* *
* @access public
* @param integer the limit value * @param integer the limit value
* @param integer the offset value * @param integer the offset value
* @return object * @return object
*/ */
function limit($value, $offset = '') public function limit($value, $offset = '')
{ {
$this->ar_limit = $value; $this->ar_limit = $value;
@@ -916,11 +885,10 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Sets the OFFSET value * Sets the OFFSET value
* *
* @access public
* @param integer the offset value * @param integer the offset value
* @return object * @return object
*/ */
function offset($offset) public function offset($offset)
{ {
$this->ar_offset = $offset; $this->ar_offset = $offset;
return $this; return $this;
@@ -931,13 +899,12 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* The "set" function. Allows key/value pairs to be set for inserting or updating * The "set" function. Allows key/value pairs to be set for inserting or updating
* *
* @access public
* @param mixed * @param mixed
* @param string * @param string
* @param boolean * @param boolean
* @return object * @return object
*/ */
function set($key, $value = '', $escape = TRUE) public function set($key, $value = '', $escape = TRUE)
{ {
$key = $this->_object_to_array($key); $key = $this->_object_to_array($key);
@@ -969,13 +936,12 @@ class CI_DB_active_record extends CI_DB_driver {
* Compiles the select statement based on the other functions called * Compiles the select statement based on the other functions called
* and runs the query * and runs the query
* *
* @access public
* @param string the table * @param string the table
* @param string the limit clause * @param string the limit clause
* @param string the offset clause * @param string the offset clause
* @return object * @return object
*/ */
function get($table = '', $limit = null, $offset = null) public function get($table = '', $limit = null, $offset = null)
{ {
if ($table != '') if ($table != '')
{ {
@@ -1001,11 +967,10 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a platform-specific query string that counts all records * Generates a platform-specific query string that counts all records
* returned by an Active Record query. * returned by an Active Record query.
* *
* @access public
* @param string * @param string
* @return string * @return string
*/ */
function count_all_results($table = '') public function count_all_results($table = '')
{ {
if ($table != '') if ($table != '')
{ {
@@ -1034,13 +999,12 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Allows the where clause, limit and offset to be added directly * Allows the where clause, limit and offset to be added directly
* *
* @access public
* @param string the where clause * @param string the where clause
* @param string the limit clause * @param string the limit clause
* @param string the offset clause * @param string the offset clause
* @return object * @return object
*/ */
function get_where($table = '', $where = null, $limit = null, $offset = null) public function get_where($table = '', $where = null, $limit = null, $offset = null)
{ {
if ($table != '') if ($table != '')
{ {
@@ -1071,12 +1035,11 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles batch insert strings and runs the queries * Compiles batch insert strings and runs the queries
* *
* @access public
* @param string the table to retrieve the results from * @param string the table to retrieve the results from
* @param array an associative array of insert values * @param array an associative array of insert values
* @return object * @return object
*/ */
function insert_batch($table = '', $set = NULL) public function insert_batch($table = '', $set = NULL)
{ {
if ( ! is_null($set)) if ( ! is_null($set))
{ {
@@ -1129,14 +1092,12 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
* *
* @access public
* @param mixed * @param mixed
* @param string * @param string
* @param boolean * @param boolean
* @return object * @return object
*/ */
public function set_insert_batch($key, $value = '', $escape = TRUE)
function set_insert_batch($key, $value = '', $escape = TRUE)
{ {
$key = $this->_object_to_array_batch($key); $key = $this->_object_to_array_batch($key);
@@ -1191,8 +1152,7 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles an insert string and runs the query * Compiles an insert string and runs the query
* *
* @access public * @param string the table to insert data into
* @param string the table to retrieve the results from
* @param array an associative array of insert values * @param array an associative array of insert values
* @return object * @return object
*/ */
@@ -1232,7 +1192,18 @@ class CI_DB_active_record extends CI_DB_driver {
return $this->query($sql); return $this->query($sql);
} }
function replace($table = '', $set = NULL) // --------------------------------------------------------------------
/**
* Replace
*
* Compiles an replace into string and runs the query
*
* @param string the table to replace data into
* @param array an associative array of insert values
* @return object
*/
public function replace($table = '', $set = NULL)
{ {
if ( ! is_null($set)) if ( ! is_null($set))
{ {
@@ -1275,13 +1246,12 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles an update string and runs the query * Compiles an update string and runs the query
* *
* @access public
* @param string the table to retrieve the results from * @param string the table to retrieve the results from
* @param array an associative array of update values * @param array an associative array of update values
* @param mixed the where clause * @param mixed the where clause
* @return object * @return object
*/ */
function update($table = '', $set = NULL, $where = NULL, $limit = NULL) public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
{ {
// Combine any cached components with the current statements // Combine any cached components with the current statements
$this->_merge_cache(); $this->_merge_cache();
@@ -1338,13 +1308,12 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles an update string and runs the query * Compiles an update string and runs the query
* *
* @access public
* @param string the table to retrieve the results from * @param string the table to retrieve the results from
* @param array an associative array of update values * @param array an associative array of update values
* @param string the where key * @param string the where key
* @return object * @return object
*/ */
function update_batch($table = '', $set = NULL, $index = NULL) public function update_batch($table = '', $set = NULL, $index = NULL)
{ {
// Combine any cached components with the current statements // Combine any cached components with the current statements
$this->_merge_cache(); $this->_merge_cache();
@@ -1404,14 +1373,12 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* The "set_update_batch" function. Allows key/value pairs to be set for batch updating * The "set_update_batch" function. Allows key/value pairs to be set for batch updating
* *
* @access public
* @param array * @param array
* @param string * @param string
* @param boolean * @param boolean
* @return object * @return object
*/ */
public function set_update_batch($key, $index = '', $escape = TRUE)
function set_update_batch($key, $index = '', $escape = TRUE)
{ {
$key = $this->_object_to_array_batch($key); $key = $this->_object_to_array_batch($key);
@@ -1464,11 +1431,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles a delete string and runs "DELETE FROM table" * Compiles a delete string and runs "DELETE FROM table"
* *
* @access public
* @param string the table to empty * @param string the table to empty
* @return object * @return object
*/ */
function empty_table($table = '') public function empty_table($table = '')
{ {
if ($table == '') if ($table == '')
{ {
@@ -1504,11 +1470,10 @@ class CI_DB_active_record extends CI_DB_driver {
* If the database does not support the truncate() command * If the database does not support the truncate() command
* This function maps to "DELETE FROM table" * This function maps to "DELETE FROM table"
* *
* @access public
* @param string the table to truncate * @param string the table to truncate
* @return object * @return object
*/ */
function truncate($table = '') public function truncate($table = '')
{ {
if ($table == '') if ($table == '')
{ {
@@ -1542,14 +1507,13 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Compiles a delete string and runs the query * Compiles a delete string and runs the query
* *
* @access public
* @param mixed the table(s) to delete from. String or array * @param mixed the table(s) to delete from. String or array
* @param mixed the where clause * @param mixed the where clause
* @param mixed the limit clause * @param mixed the limit clause
* @param boolean * @param boolean
* @return object * @return object
*/ */
function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
{ {
// Combine any cached components with the current statements // Combine any cached components with the current statements
$this->_merge_cache(); $this->_merge_cache();
@@ -1619,11 +1583,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Prepends a database prefix if one exists in configuration * Prepends a database prefix if one exists in configuration
* *
* @access public
* @param string the table * @param string the table
* @return string * @return string
*/ */
function dbprefix($table = '') public function dbprefix($table = '')
{ {
if ($table == '') if ($table == '')
{ {
@@ -1635,16 +1598,30 @@ class CI_DB_active_record extends CI_DB_driver {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Set DB Prefix
*
* Set's the DB Prefix to something new without needing to reconnect
*
* @param string the prefix
* @return string
*/
public function set_dbprefix($prefix = '')
{
return $this->dbprefix = $prefix;
}
// --------------------------------------------------------------------
/** /**
* Track Aliases * Track Aliases
* *
* Used to track SQL statements written with aliased tables. * Used to track SQL statements written with aliased tables.
* *
* @access private
* @param string The table to inspect * @param string The table to inspect
* @return string * @return string
*/ */
function _track_aliases($table) protected function _track_aliases($table)
{ {
if (is_array($table)) if (is_array($table))
{ {
@@ -1687,10 +1664,9 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a query string based on which functions were used. * Generates a query string based on which functions were used.
* Should not be called directly. The get() function calls it. * Should not be called directly. The get() function calls it.
* *
* @access private
* @return string * @return string
*/ */
function _compile_select($select_override = FALSE) protected function _compile_select($select_override = FALSE)
{ {
// Combine any cached components with the current statements // Combine any cached components with the current statements
$this->_merge_cache(); $this->_merge_cache();
@@ -1718,7 +1694,8 @@ class CI_DB_active_record extends CI_DB_driver {
// is because until the user calls the from() function we don't know if there are aliases // is because until the user calls the from() function we don't know if there are aliases
foreach ($this->ar_select as $key => $val) foreach ($this->ar_select as $key => $val)
{ {
$this->ar_select[$key] = $this->_protect_identifiers($val); $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL;
$this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
} }
$sql .= implode(', ', $this->ar_select); $sql .= implode(', ', $this->ar_select);
@@ -1753,9 +1730,7 @@ class CI_DB_active_record extends CI_DB_driver {
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
{ {
$sql .= "\n"; $sql .= "\nWHERE ";
$sql .= "WHERE ";
} }
$sql .= implode("\n", $this->ar_where); $sql .= implode("\n", $this->ar_where);
@@ -1830,11 +1805,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Takes an object as input and converts the class variables to array key/vals * Takes an object as input and converts the class variables to array key/vals
* *
* @access public
* @param object * @param object
* @return array * @return array
*/ */
function _object_to_array($object) public function _object_to_array($object)
{ {
if ( ! is_object($object)) if ( ! is_object($object))
{ {
@@ -1861,11 +1835,10 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Takes an object as input and converts the class variables to array key/vals * Takes an object as input and converts the class variables to array key/vals
* *
* @access public
* @param object * @param object
* @return array * @return array
*/ */
function _object_to_array_batch($object) public function _object_to_array_batch($object)
{ {
if ( ! is_object($object)) if ( ! is_object($object))
{ {
@@ -1901,10 +1874,9 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Starts AR caching * Starts AR caching
* *
* @access public
* @return void * @return void
*/ */
function start_cache() public function start_cache()
{ {
$this->ar_caching = TRUE; $this->ar_caching = TRUE;
} }
@@ -1916,10 +1888,9 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Stops AR caching * Stops AR caching
* *
* @access public
* @return void * @return void
*/ */
function stop_cache() public function stop_cache()
{ {
$this->ar_caching = FALSE; $this->ar_caching = FALSE;
} }
@@ -1934,22 +1905,21 @@ class CI_DB_active_record extends CI_DB_driver {
* @access public * @access public
* @return void * @return void
*/ */
function flush_cache() public function flush_cache()
{ {
$this->_reset_run( $this->_reset_run(array(
array( 'ar_cache_select' => array(),
'ar_cache_select' => array(), 'ar_cache_from' => array(),
'ar_cache_from' => array(), 'ar_cache_join' => array(),
'ar_cache_join' => array(), 'ar_cache_where' => array(),
'ar_cache_where' => array(), 'ar_cache_like' => array(),
'ar_cache_like' => array(), 'ar_cache_groupby' => array(),
'ar_cache_groupby' => array(), 'ar_cache_having' => array(),
'ar_cache_having' => array(), 'ar_cache_orderby' => array(),
'ar_cache_orderby' => array(), 'ar_cache_set' => array(),
'ar_cache_set' => array(), 'ar_cache_exists' => array(),
'ar_cache_exists' => array() 'ar_cache_no_escape' => array()
) ));
);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -1960,10 +1930,9 @@ class CI_DB_active_record extends CI_DB_driver {
* When called, this function merges any cached AR arrays with * When called, this function merges any cached AR arrays with
* locally called ones. * locally called ones.
* *
* @access private
* @return void * @return void
*/ */
function _merge_cache() protected function _merge_cache()
{ {
if (count($this->ar_cache_exists) == 0) if (count($this->ar_cache_exists) == 0)
{ {
@@ -1989,6 +1958,8 @@ class CI_DB_active_record extends CI_DB_driver {
{ {
$this->_track_aliases($this->ar_from); $this->_track_aliases($this->ar_from);
} }
$this->ar_no_escape = $this->ar_cache_no_escape;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -1996,11 +1967,10 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Resets the active record values. Called by the get() function * Resets the active record values. Called by the get() function
* *
* @access private
* @param array An array of fields to reset * @param array An array of fields to reset
* @return void * @return void
*/ */
function _reset_run($ar_reset_items) protected function _reset_run($ar_reset_items)
{ {
foreach ($ar_reset_items as $item => $default_value) foreach ($ar_reset_items as $item => $default_value)
{ {
@@ -2016,27 +1986,27 @@ class CI_DB_active_record extends CI_DB_driver {
/** /**
* Resets the active record values. Called by the get() function * Resets the active record values. Called by the get() function
* *
* @access private
* @return void * @return void
*/ */
function _reset_select() protected function _reset_select()
{ {
$ar_reset_items = array( $ar_reset_items = array(
'ar_select' => array(), 'ar_select' => array(),
'ar_from' => array(), 'ar_from' => array(),
'ar_join' => array(), 'ar_join' => array(),
'ar_where' => array(), 'ar_where' => array(),
'ar_like' => array(), 'ar_like' => array(),
'ar_groupby' => array(), 'ar_groupby' => array(),
'ar_having' => array(), 'ar_having' => array(),
'ar_orderby' => array(), 'ar_orderby' => array(),
'ar_wherein' => array(), 'ar_wherein' => array(),
'ar_aliased_tables' => array(), 'ar_aliased_tables' => array(),
'ar_distinct' => FALSE, 'ar_no_escape' => array(),
'ar_limit' => FALSE, 'ar_distinct' => FALSE,
'ar_offset' => FALSE, 'ar_limit' => FALSE,
'ar_order' => FALSE, 'ar_offset' => FALSE,
); 'ar_order' => FALSE,
);
$this->_reset_run($ar_reset_items); $this->_reset_run($ar_reset_items);
} }
@@ -2048,25 +2018,23 @@ class CI_DB_active_record extends CI_DB_driver {
* *
* Called by the insert() update() insert_batch() update_batch() and delete() functions * Called by the insert() update() insert_batch() update_batch() and delete() functions
* *
* @access private
* @return void * @return void
*/ */
function _reset_write() protected function _reset_write()
{ {
$ar_reset_items = array( $ar_reset_items = array(
'ar_set' => array(), 'ar_set' => array(),
'ar_from' => array(), 'ar_from' => array(),
'ar_where' => array(), 'ar_where' => array(),
'ar_like' => array(), 'ar_like' => array(),
'ar_orderby' => array(), 'ar_orderby' => array(),
'ar_keys' => array(), 'ar_keys' => array(),
'ar_limit' => FALSE, 'ar_limit' => FALSE,
'ar_order' => FALSE 'ar_order' => FALSE
); );
$this->_reset_run($ar_reset_items); $this->_reset_run($ar_reset_items);
} }
} }
/* End of file DB_active_rec.php */ /* End of file DB_active_rec.php */

View File

@@ -424,8 +424,8 @@ class CI_DB_driver {
if ( ! class_exists($driver)) if ( ! class_exists($driver))
{ {
include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/DB_result.php');
include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
} }
return $driver; return $driver;
@@ -1115,7 +1115,7 @@ class CI_DB_driver {
if ( ! class_exists('CI_DB_Cache')) if ( ! class_exists('CI_DB_Cache'))
{ {
if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) if ( ! @include(BASEPATH.'database/DB_cache.php'))
{ {
return $this->cache_off(); return $this->cache_off();
} }

View File

@@ -28,14 +28,14 @@
*/ */
class CI_DB_result { class CI_DB_result {
var $conn_id = NULL; var $conn_id = NULL;
var $result_id = NULL; var $result_id = NULL;
var $result_array = array(); var $result_array = array();
var $result_object = array(); var $result_object = array();
var $custom_result_object = array(); var $custom_result_object = array();
var $current_row = 0; var $current_row = 0;
var $num_rows = 0; var $num_rows = 0;
var $row_data = NULL; var $row_data = NULL;
/** /**
@@ -47,47 +47,52 @@ class CI_DB_result {
*/ */
function result($type = 'object') function result($type = 'object')
{ {
if ($type == 'array') return $this->result_array(); if ($type == 'array') return $this->result_array();
else if ($type == 'object') return $this->result_object(); else if ($type == 'object') return $this->result_object();
else return $this->custom_result_object($type); else return $this->custom_result_object($type);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Custom query result. * Custom query result.
* *
* @param class_name A string that represents the type of object you want back * @param class_name A string that represents the type of object you want back
* @return array of objects * @return array of objects
*/ */
function custom_result_object($class_name) function custom_result_object($class_name)
{ {
if (array_key_exists($class_name, $this->custom_result_object)) if (array_key_exists($class_name, $this->custom_result_object))
{ {
return $this->custom_result_object[$class_name]; return $this->custom_result_object[$class_name];
} }
if ($this->result_id === FALSE OR $this->num_rows() == 0) if ($this->result_id === FALSE OR $this->num_rows() == 0)
{ {
return array(); return array();
} }
// add the data to the object
$this->_data_seek(0);
$result_object = array();
// add the data to the object
$this->_data_seek(0);
$result_object = array();
while ($row = $this->_fetch_object()) while ($row = $this->_fetch_object())
{ {
$object = new $class_name(); $object = new $class_name();
foreach ($row as $key => $value)
{ foreach ($row as $key => $value)
$object->$key = $value; {
} $object->$key = $value;
}
$result_object[] = $object; $result_object[] = $object;
} }
// return the array // return the array
return $this->custom_result_object[$class_name] = $result_object; return $this->custom_result_object[$class_name] = $result_object;
} }
// --------------------------------------------------------------------
/** /**
* Query result. "object" version. * Query result. "object" version.
@@ -180,9 +185,9 @@ class CI_DB_result {
$n = 0; $n = 0;
} }
if ($type == 'object') return $this->row_object($n); if ($type == 'object') return $this->row_object($n);
else if ($type == 'array') return $this->row_array($n); else if ($type == 'array') return $this->row_array($n);
else return $this->custom_row_object($n, $type); else return $this->custom_row_object($n, $type);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -219,7 +224,7 @@ class CI_DB_result {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Returns a single result row - custom object version * Returns a single result row - custom object version
* *
* @access public * @access public
@@ -242,7 +247,7 @@ class CI_DB_result {
return $result[$this->current_row]; return $result[$this->current_row];
} }
/** /**
* Returns a single result row - object version * Returns a single result row - object version
* *
* @access public * @access public

View File

@@ -132,7 +132,22 @@ class CI_DB_mysql_driver extends CI_DB {
*/ */
function db_set_charset($charset, $collation) function db_set_charset($charset, $collation)
{ {
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); static $use_set_names;
if ( ! isset($use_set_names))
{
// mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback
$use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
}
if ($use_set_names)
{
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}
else
{
return @mysql_set_charset($charset, $this->conn_id);
}
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -119,9 +119,13 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
} }
if (array_key_exists('NULL', $attributes)) if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{ {
$sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; $sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
} }
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

View File

@@ -132,7 +132,22 @@ class CI_DB_mysqli_driver extends CI_DB {
*/ */
function _db_set_charset($charset, $collation) function _db_set_charset($charset, $collation)
{ {
return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); static $use_set_names;
if ( ! isset($use_set_names))
{
// mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback
$use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE;
}
if ($use_set_names)
{
return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'");
}
else
{
return @mysqli_set_charset($this->conn_id, $charset);
}
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -104,9 +104,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
} }
if (array_key_exists('NULL', $attributes)) if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{ {
$sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; $sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
} }
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

View File

@@ -553,6 +553,24 @@ class CI_DB_postgre_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Insert_batch statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert_batch($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
}
// --------------------------------------------------------------------
/** /**
* Update statement * Update statement
* *

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,598 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* SQLSRV Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
* class is being used or not.
*
* @package CodeIgniter
* @subpackage Drivers
* @category Database
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_sqlsrv_driver extends CI_DB {
var $dbdriver = 'sqlsrv';
// The character used for escaping
var $_escape_char = '';
// clause and character used for LIKE escape sequences
var $_like_escape_str = " ESCAPE '%s' ";
var $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword = ' ASC'; // not currently supported
/**
* Non-persistent database connection
*
* @access private called by the base class
* @return resource
*/
function db_connect($pooling = false)
{
// Check for a UTF-8 charset being passed as CI's default 'utf8'.
$character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set;
$connection = array(
'UID' => empty($this->username) ? '' : $this->username,
'PWD' => empty($this->password) ? '' : $this->password,
'Database' => $this->database,
'ConnectionPooling' => $pooling ? 1 : 0,
'CharacterSet' => $character_set,
'ReturnDatesAsStrings' => 1
);
// If the username and password are both empty, assume this is a
// 'Windows Authentication Mode' connection.
if(empty($connection['UID']) && empty($connection['PWD'])) {
unset($connection['UID'], $connection['PWD']);
}
return sqlsrv_connect($this->hostname, $connection);
}
// --------------------------------------------------------------------
/**
* Persistent database connection
*
* @access private called by the base class
* @return resource
*/
function db_pconnect()
{
$this->db_connect(TRUE);
}
// --------------------------------------------------------------------
/**
* Reconnect
*
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
* @access public
* @return void
*/
function reconnect()
{
// not implemented in MSSQL
}
// --------------------------------------------------------------------
/**
* Select the database
*
* @access private called by the base class
* @return resource
*/
function db_select()
{
return $this->_execute('USE ' . $this->database);
}
// --------------------------------------------------------------------
/**
* Set client character set
*
* @access public
* @param string
* @param string
* @return resource
*/
function db_set_charset($charset, $collation)
{
// @todo - add support if needed
return TRUE;
}
// --------------------------------------------------------------------
/**
* Execute the query
*
* @access private called by the base class
* @param string an SQL query
* @return resource
*/
function _execute($sql)
{
$sql = $this->_prep_query($sql);
return sqlsrv_query($this->conn_id, $sql, null, array(
'Scrollable' => SQLSRV_CURSOR_STATIC,
'SendStreamParamsAtExec' => true
));
}
// --------------------------------------------------------------------
/**
* Prep the query
*
* If needed, each database adapter can prep the query string
*
* @access private called by execute()
* @param string an SQL query
* @return string
*/
function _prep_query($sql)
{
return $sql;
}
// --------------------------------------------------------------------
/**
* Begin Transaction
*
* @access public
* @return bool
*/
function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
return sqlsrv_begin_transaction($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Commit Transaction
*
* @access public
* @return bool
*/
function trans_commit()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
return sqlsrv_commit($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Rollback Transaction
*
* @access public
* @return bool
*/
function trans_rollback()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
return sqlsrv_rollback($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Escape String
*
* @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
function escape_str($str, $like = FALSE)
{
// Escape single quotes
return str_replace("'", "''", $str);
}
// --------------------------------------------------------------------
/**
* Affected Rows
*
* @access public
* @return integer
*/
function affected_rows()
{
return @sqlrv_rows_affected($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Insert ID
*
* Returns the last id created in the Identity column.
*
* @access public
* @return integer
*/
function insert_id()
{
return $this->query('select @@IDENTITY as insert_id')->row('insert_id');
}
// --------------------------------------------------------------------
/**
* Parse major version
*
* Grabs the major version number from the
* database server version string passed in.
*
* @access private
* @param string $version
* @return int16 major version number
*/
function _parse_major_version($version)
{
preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
return $ver_info[1]; // return the major version b/c that's all we're interested in.
}
// --------------------------------------------------------------------
/**
* Version number query string
*
* @access public
* @return string
*/
function _version()
{
$info = sqlsrv_server_info($this->conn_id);
return sprintf("select '%s' as ver", $info['SQLServerVersion']);
}
// --------------------------------------------------------------------
/**
* "Count All" query
*
* Generates a platform-specific query string that counts all records in
* the specified database
*
* @access public
* @param string
* @return string
*/
function count_all($table = '')
{
if ($table == '')
return '0';
$query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
if ($query->num_rows() == 0)
return '0';
$row = $query->row();
return $row->numrows;
}
// --------------------------------------------------------------------
/**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
* @param boolean
* @return string
*/
function _list_tables($prefix_limit = FALSE)
{
return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
}
// --------------------------------------------------------------------
/**
* List column query
*
* Generates a platform-specific query string so that the column names can be fetched
*
* @access private
* @param string the table name
* @return string
*/
function _list_columns($table = '')
{
return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'";
}
// --------------------------------------------------------------------
/**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
*
* @access public
* @param string the table name
* @return object
*/
function _field_data($table)
{
return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
}
// --------------------------------------------------------------------
/**
* The error message string
*
* @access private
* @return string
*/
function _error_message()
{
$error = array_shift(sqlsrv_errors());
return !empty($error['message']) ? $error['message'] : null;
}
// --------------------------------------------------------------------
/**
* The error message number
*
* @access private
* @return integer
*/
function _error_number()
{
$error = array_shift(sqlsrv_errors());
return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null;
}
// --------------------------------------------------------------------
/**
* Escape Table Name
*
* This function adds backticks if the table name has a period
* in it. Some DBs will get cranky unless periods are escaped
*
* @access private
* @param string the table name
* @return string
*/
function _escape_table($table)
{
return $table;
}
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @access private
* @param string
* @return string
*/
function _escape_identifiers($item)
{
return $item;
}
// --------------------------------------------------------------------
/**
* From Tables
*
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
* @access public
* @param type
* @return type
*/
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return implode(', ', $tables);
}
// --------------------------------------------------------------------
/**
* Insert statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert($table, $keys, $values)
{
return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @param array the orderby clause
* @param array the limit clause
* @return string
*/
function _update($table, $values, $where)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
}
// --------------------------------------------------------------------
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
* @access public
* @param string the table name
* @return string
*/
function _truncate($table)
{
return "TRUNCATE ".$table;
}
// --------------------------------------------------------------------
/**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
*
* @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
function _delete($table, $where)
{
return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
}
// --------------------------------------------------------------------
/**
* Limit string
*
* Generates a platform-specific LIMIT clause
*
* @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
function _limit($sql, $limit, $offset)
{
$i = $limit + $offset;
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
}
// --------------------------------------------------------------------
/**
* Close DB Connection
*
* @access public
* @param resource
* @return void
*/
function _close($conn_id)
{
@sqlsrv_close($conn_id);
}
}
/* End of file mssql_driver.php */
/* Location: ./system/database/drivers/mssql/mssql_driver.php */

View File

@@ -0,0 +1,248 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* SQLSRV Forge Class
*
* @category Database
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Create database
*
* @access private
* @param string the database name
* @return bool
*/
function _create_database($name)
{
return "CREATE DATABASE ".$name;
}
// --------------------------------------------------------------------
/**
* Drop database
*
* @access private
* @param string the database name
* @return bool
*/
function _drop_database($name)
{
return "DROP DATABASE ".$name;
}
// --------------------------------------------------------------------
/**
* Drop Table
*
* @access private
* @return bool
*/
function _drop_table($table)
{
return "DROP TABLE ".$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
/**
* Create Table
*
* @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
* @param boolean should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
if ($if_not_exists === TRUE)
{
$sql .= 'IF NOT EXISTS ';
}
$sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
$sql .= "\n\t$attributes";
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t".$this->db->_protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
if (array_key_exists('DEFAULT', $attributes))
{
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{
$sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
}
// don't add a comma on the end of the last field
if (++$current_field_count < count($fields))
{
$sql .= ',';
}
}
if (count($primary_keys) > 0)
{
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
if (is_array($keys) && count($keys) > 0)
{
foreach ($keys as $key)
{
if (is_array($key))
{
$key = $this->db->_protect_identifiers($key);
}
else
{
$key = array($this->db->_protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
}
}
$sql .= "\n)";
return $sql;
}
// --------------------------------------------------------------------
/**
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
* @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
* @param boolean should 'NOT NULL' be added
* @param string the field after which we should add the new field
* @return object
*/
function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
return $sql;
}
$sql .= " $column_definition";
if ($default_value != '')
{
$sql .= " DEFAULT \"$default_value\"";
}
if ($null === NULL)
{
$sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
}
if ($after_field != '')
{
$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Rename a table
*
* Generates a platform-specific query so that a table can be renamed
*
* @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
function _rename_table($table_name, $new_table_name)
{
// I think this syntax will work, but can find little documentation on renaming tables in MSSQL
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
return $sql;
}
}
/* End of file mssql_forge.php */
/* Location: ./system/database/drivers/mssql/mssql_forge.php */

View File

@@ -0,0 +1,169 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* SQLSRV Result Class
*
* This class extends the parent result class: CI_DB_result
*
* @category Database
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Number of rows in the result set
*
* @access public
* @return integer
*/
function num_rows()
{
return @sqlsrv_num_rows($this->result_id);
}
// --------------------------------------------------------------------
/**
* Number of fields in the result set
*
* @access public
* @return integer
*/
function num_fields()
{
return @sqlsrv_num_fields($this->result_id);
}
// --------------------------------------------------------------------
/**
* Fetch Field Names
*
* Generates an array of column names
*
* @access public
* @return array
*/
function list_fields()
{
$field_names = array();
foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
$field_names[] = $field['Name'];
}
return $field_names;
}
// --------------------------------------------------------------------
/**
* Field data
*
* Generates an array of objects containing field meta-data
*
* @access public
* @return array
*/
function field_data()
{
$retval = array();
foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
$F = new stdClass();
$F->name = $field['Name'];
$F->type = $field['Type'];
$F->max_length = $field['Size'];
$F->primary_key = 0;
$F->default = '';
$retval[] = $F;
}
return $retval;
}
// --------------------------------------------------------------------
/**
* Free the result
*
* @return null
*/
function free_result()
{
if (is_resource($this->result_id))
{
sqlsrv_free_stmt($this->result_id);
$this->result_id = FALSE;
}
}
// --------------------------------------------------------------------
/**
* Data Seek
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
* @access private
* @return array
*/
function _data_seek($n = 0)
{
// Not implemented
}
// --------------------------------------------------------------------
/**
* Result - associative array
*
* Returns the result set as an array
*
* @access private
* @return array
*/
function _fetch_assoc()
{
return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
}
// --------------------------------------------------------------------
/**
* Result - object
*
* Returns the result set as an object
*
* @access private
* @return object
*/
function _fetch_object()
{
return sqlsrv_fetch_object($this->result_id);
}
}
/* End of file mssql_result.php */
/* Location: ./system/database/drivers/mssql/mssql_result.php */

View File

@@ -0,0 +1,88 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* SQLSRV Utility Class
*
* @category Database
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_sqlsrv_utility extends CI_DB_utility {
/**
* List databases
*
* @access private
* @return bool
*/
function _list_databases()
{
return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases
}
// --------------------------------------------------------------------
/**
* Optimize table query
*
* Generates a platform-specific query so that a table can be optimized
*
* @access private
* @param string the table name
* @return object
*/
function _optimize_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
// --------------------------------------------------------------------
/**
* Repair table query
*
* Generates a platform-specific query so that a table can be repaired
*
* @access private
* @param string the table name
* @return object
*/
function _repair_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
// --------------------------------------------------------------------
/**
* MSSQL Export
*
* @access private
* @param array Preferences
* @return mixed
*/
function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
}
}
/* End of file mssql_utility.php */
/* Location: ./system/database/drivers/mssql/mssql_utility.php */

Binary file not shown.

View File

@@ -58,13 +58,13 @@ if ( ! function_exists('force_download'))
$extension = end($x); $extension = end($x);
// Load the mime types // Load the mime types
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
} }
elseif (is_file(APPPATH.'config/mimes'.EXT)) elseif (is_file(APPPATH.'config/mimes.php'))
{ {
include(APPPATH.'config/mimes'.EXT); include(APPPATH.'config/mimes.php');
} }
// Set a default mime if we can't find it // Set a default mime if we can't find it

View File

@@ -352,13 +352,13 @@ if ( ! function_exists('get_mime_by_extension'))
if ( ! is_array($mimes)) if ( ! is_array($mimes))
{ {
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
} }
elseif (is_file(APPPATH.'config/mimes'.EXT)) elseif (is_file(APPPATH.'config/mimes.php'))
{ {
include(APPPATH.'config/mimes'.EXT); include(APPPATH.'config/mimes.php');
} }
if ( ! is_array($mimes)) if ( ! is_array($mimes))

View File

@@ -72,7 +72,7 @@ if ( ! function_exists('form_open'))
if (is_array($hidden) AND count($hidden) > 0) if (is_array($hidden) AND count($hidden) > 0)
{ {
$form .= sprintf("\n<div class=\"hidden\">%s</div>", form_hidden($hidden)); $form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
} }
return $form; return $form;
@@ -1032,22 +1032,20 @@ if ( ! function_exists('_get_validation_object'))
{ {
$CI =& get_instance(); $CI =& get_instance();
// We set this as a variable since we're returning by reference // We set this as a variable since we're returning by reference.
$return = FALSE; $return = FALSE;
if ( ! isset($CI->load->_ci_classes) OR ! isset($CI->load->_ci_classes['form_validation'])) if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
{ {
return $return; if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
} }
$object = $CI->load->_ci_classes['form_validation']; return $return;
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
} }
} }

View File

@@ -40,9 +40,10 @@
*/ */
if ( ! function_exists('heading')) if ( ! function_exists('heading'))
{ {
function heading($data = '', $h = '1') function heading($data = '', $h = '1', $attributes = '')
{ {
return "<h".$h.">".$data."</h".$h.">"; $attributes = ($attributes != '') ? ' '.$attributes : $attributes;
return "<h".$h.$attributes.">".$data."</h".$h.">";
} }
} }
@@ -123,6 +124,10 @@ if ( ! function_exists('_list'))
} }
$attributes = $atts; $attributes = $atts;
} }
elseif (is_string($attributes) AND strlen($attributes) > 0)
{
$attributes = ' '. $attributes;
}
// Write the opening list tag // Write the opening list tag
$out .= "<".$type.$attributes.">\n"; $out .= "<".$type.$attributes.">\n";
@@ -258,13 +263,13 @@ if ( ! function_exists('doctype'))
if ( ! is_array($_doctypes)) if ( ! is_array($_doctypes))
{ {
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
} }
elseif (is_file(APPPATH.'config/doctypes'.EXT)) elseif (is_file(APPPATH.'config/doctypes.php'))
{ {
include(APPPATH.'config/doctypes'.EXT); include(APPPATH.'config/doctypes.php');
} }
if ( ! is_array($_doctypes)) if ( ! is_array($_doctypes))

View File

@@ -41,30 +41,48 @@ if ( ! function_exists('singular'))
{ {
function singular($str) function singular($str)
{ {
$str = trim($str); $result = strval($str);
$end = substr($str, -3);
$str = preg_replace('/(.*)?([s|c]h)es/i','$1$2',$str); $singular_rules = array(
'/(matr)ices$/' => '\1ix',
'/(vert|ind)ices$/' => '\1ex',
'/^(ox)en/' => '\1',
'/(alias)es$/' => '\1',
'/([octop|vir])i$/' => '\1us',
'/(cris|ax|test)es$/' => '\1is',
'/(shoe)s$/' => '\1',
'/(o)es$/' => '\1',
'/(bus|campus)es$/' => '\1',
'/([m|l])ice$/' => '\1ouse',
'/(x|ch|ss|sh)es$/' => '\1',
'/(m)ovies$/' => '\1\2ovie',
'/(s)eries$/' => '\1\2eries',
'/([^aeiouy]|qu)ies$/' => '\1y',
'/([lr])ves$/' => '\1f',
'/(tive)s$/' => '\1',
'/(hive)s$/' => '\1',
'/([^f])ves$/' => '\1fe',
'/(^analy)ses$/' => '\1sis',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis',
'/([ti])a$/' => '\1um',
'/(p)eople$/' => '\1\2erson',
'/(m)en$/' => '\1an',
'/(s)tatuses$/' => '\1\2tatus',
'/(c)hildren$/' => '\1\2hild',
'/(n)ews$/' => '\1\2ews',
'/([^u])s$/' => '\1',
);
if (strtolower($end) == 'ies') foreach ($singular_rules as $rule => $replacement)
{ {
$str = substr($str, 0, strlen($str)-3).(preg_match('/[a-z]/',$end) ? 'y' : 'Y'); if (preg_match($rule, $result))
}
elseif (strtolower($end) == 'ses')
{
$str = substr($str, 0, strlen($str)-2);
}
else
{
$end = strtolower(substr($str, -1));
if ($end == 's')
{ {
$str = substr($str, 0, strlen($str)-1); $result = preg_replace($rule, $replacement, $result);
break;
} }
} }
return $str; return $result;
} }
} }
@@ -84,39 +102,40 @@ if ( ! function_exists('plural'))
{ {
function plural($str, $force = FALSE) function plural($str, $force = FALSE)
{ {
$str = trim($str); $result = strval($str);
$end = substr($str, -1);
if (preg_match('/y/i',$end)) $plural_rules = array(
'/^(ox)$/' => '\1\2en', // ox
'/([m|l])ouse$/' => '\1ice', // mouse, louse
'/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
'/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
'/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
'/(hive)$/' => '\1s', // archive, hive
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
'/sis$/' => 'ses', // basis, diagnosis
'/([ti])um$/' => '\1a', // datum, medium
'/(p)erson$/' => '\1eople', // person, salesperson
'/(m)an$/' => '\1en', // man, woman, spokesman
'/(c)hild$/' => '\1hildren', // child
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
'/(alias|status|virus)/' => '\1es', // alias
'/(octop)us$/' => '\1i', // octopus
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
'/s$/' => 's', // no change (compatibility)
'/$/' => 's',
);
foreach ($plural_rules as $rule => $replacement)
{ {
// Y preceded by vowel => regular plural if (preg_match($rule, $result))
$vowels = array('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
$str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
}
elseif (preg_match('/h/i',$end))
{
if(preg_match('/^[c|s]h$/i',substr($str, -2)))
{ {
$str .= 'es'; $result = preg_replace($rule, $replacement, $result);
break;
} }
else
{
$str .= 's';
}
}
elseif (preg_match('/s/i',$end))
{
if ($force == TRUE)
{
$str .= 'es';
}
}
else
{
$str .= 's';
} }
return $str; return $result;
} }
} }

View File

@@ -229,13 +229,13 @@ if ( ! function_exists('_get_smiley_array'))
{ {
function _get_smiley_array() function _get_smiley_array()
{ {
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
} }
elseif (file_exists(APPPATH.'config/smileys'.EXT)) elseif (file_exists(APPPATH.'config/smileys.php'))
{ {
include(APPPATH.'config/smileys'.EXT); include(APPPATH.'config/smileys.php');
} }
if (isset($smileys) AND is_array($smileys)) if (isset($smileys) AND is_array($smileys))

View File

@@ -366,13 +366,13 @@ if ( ! function_exists('convert_accented_characters'))
{ {
function convert_accented_characters($str) function convert_accented_characters($str)
{ {
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
} }
elseif (is_file(APPPATH.'config/foreign_chars'.EXT)) elseif (is_file(APPPATH.'config/foreign_chars.php'))
{ {
include(APPPATH.'config/foreign_chars'.EXT); include(APPPATH.'config/foreign_chars.php');
} }
if ( ! isset($foreign_characters)) if ( ! isset($foreign_characters))

View File

@@ -51,17 +51,20 @@ if ( ! function_exists('site_url'))
/** /**
* Base URL * Base URL
* *
* Returns the "base_url" item from your config file * Create a local URL based on your basepath.
* Segments can be passed in as a string or an array, same as site_url
* or a URL to a file can be passed in, e.g. to an image file.
* *
* @access public * @access public
* @param string
* @return string * @return string
*/ */
if ( ! function_exists('base_url')) if ( ! function_exists('base_url'))
{ {
function base_url() function base_url($uri = '')
{ {
$CI =& get_instance(); $CI =& get_instance();
return $CI->config->slash_item('base_url'); return $CI->config->base_url($uri);
} }
} }

View File

@@ -9,6 +9,7 @@ $lang['profiler_post_data'] = 'POST DATA';
$lang['profiler_uri_string'] = 'URI STRING'; $lang['profiler_uri_string'] = 'URI STRING';
$lang['profiler_memory_usage'] = 'MEMORY USAGE'; $lang['profiler_memory_usage'] = 'MEMORY USAGE';
$lang['profiler_config'] = 'CONFIG VARIABLES'; $lang['profiler_config'] = 'CONFIG VARIABLES';
$lang['profiler_session_data'] = 'SESSION DATA';
$lang['profiler_headers'] = 'HTTP HEADERS'; $lang['profiler_headers'] = 'HTTP HEADERS';
$lang['profiler_no_db'] = 'Database driver is not currently loaded'; $lang['profiler_no_db'] = 'Database driver is not currently loaded';
$lang['profiler_no_queries'] = 'No queries were run'; $lang['profiler_no_queries'] = 'No queries were run';
@@ -17,6 +18,8 @@ $lang['profiler_no_get'] = 'No GET data exists';
$lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_uri'] = 'No URI data exists';
$lang['profiler_no_memory'] = 'Memory Usage Unavailable'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable';
$lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; $lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.';
$lang['profiler_section_hide'] = 'Hide';
$lang['profiler_section_show'] = 'Show';
/* End of file profiler_lang.php */ /* End of file profiler_lang.php */
/* Location: ./system/language/english/profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */

View File

@@ -125,5 +125,5 @@ class CI_Cache_dummy extends CI_Driver {
} }
// End Class // End Class
/* End of file Cache_apc.php */ /* End of file Cache_dummy.php */
/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ /* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */

View File

@@ -47,7 +47,7 @@ class CI_Calendar {
{ {
$this->CI =& get_instance(); $this->CI =& get_instance();
if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE))
{ {
$this->CI->lang->load('calendar'); $this->CI->lang->load('calendar');
} }

View File

@@ -374,6 +374,7 @@ class CI_Cart {
// Lets add up the individual prices and set the cart sub-total // Lets add up the individual prices and set the cart sub-total
$total = 0; $total = 0;
$items = 0;
foreach ($this->_cart_contents as $key => $val) foreach ($this->_cart_contents as $key => $val)
{ {
// We make sure the array contains the proper indexes // We make sure the array contains the proper indexes
@@ -383,13 +384,14 @@ class CI_Cart {
} }
$total += ($val['price'] * $val['qty']); $total += ($val['price'] * $val['qty']);
$items += $val['qty'];
// Set the subtotal // Set the subtotal
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
} }
// Set the cart total and total items. // Set the cart total and total items.
$this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['total_items'] = $items;
$this->_cart_contents['cart_total'] = $total; $this->_cart_contents['cart_total'] = $total;
// Is our cart empty? If so we delete it from the session // Is our cart empty? If so we delete it from the session

View File

@@ -45,8 +45,8 @@ class CI_Driver_Library {
$child_class = $this->lib_name.'_'.$child; $child_class = $this->lib_name.'_'.$child;
// Remove the CI_ prefix and lowercase // Remove the CI_ prefix and lowercase
$lib_name = strtolower(preg_replace('/^CI_/', '', $this->lib_name)); $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name)));
$driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); $driver_name = strtolower(str_replace('CI_', '', $child_class));
if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
{ {
@@ -59,7 +59,7 @@ class CI_Driver_Library {
// loves me some nesting! // loves me some nesting!
foreach (array(ucfirst($driver_name), $driver_name) as $class) foreach (array(ucfirst($driver_name), $driver_name) as $class)
{ {
$filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.EXT; $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php';
if (file_exists($filepath)) if (file_exists($filepath))
{ {

View File

@@ -395,7 +395,7 @@ class CI_Email {
public function attach($filename, $disposition = 'attachment') public function attach($filename, $disposition = 'attachment')
{ {
$this->_attach_name[] = $filename; $this->_attach_name[] = $filename;
$this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
$this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters
return $this; return $this;
} }
@@ -722,7 +722,7 @@ class CI_Email {
{ {
if ( ! is_array($email)) if ( ! is_array($email))
{ {
$this->_set_error_message('email_must_be_array'); $this->_set_error_message('lang:email_must_be_array');
return FALSE; return FALSE;
} }
@@ -730,7 +730,7 @@ class CI_Email {
{ {
if ( ! $this->valid_email($val)) if ( ! $this->valid_email($val))
{ {
$this->_set_error_message('email_invalid_address', $val); $this->_set_error_message('lang:email_invalid_address', $val);
return FALSE; return FALSE;
} }
} }
@@ -1131,7 +1131,7 @@ class CI_Email {
if ( ! file_exists($filename)) if ( ! file_exists($filename))
{ {
$this->_set_error_message('email_attachment_missing', $filename); $this->_set_error_message('lang:email_attachment_missing', $filename);
return FALSE; return FALSE;
} }
@@ -1146,7 +1146,7 @@ class CI_Email {
if ( ! $fp = fopen($filename, FOPEN_READ)) if ( ! $fp = fopen($filename, FOPEN_READ))
{ {
$this->_set_error_message('email_attachment_unreadable', $filename); $this->_set_error_message('lang:email_attachment_unreadable', $filename);
return FALSE; return FALSE;
} }
@@ -1353,7 +1353,7 @@ class CI_Email {
( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
( ! isset($this->_headers['Cc']))) ( ! isset($this->_headers['Cc'])))
{ {
$this->_set_error_message('email_no_recipients'); $this->_set_error_message('lang:email_no_recipients');
return FALSE; return FALSE;
} }
@@ -1484,7 +1484,7 @@ class CI_Email {
if ( ! $this->_send_with_mail()) if ( ! $this->_send_with_mail())
{ {
$this->_set_error_message('email_send_failure_phpmail'); $this->_set_error_message('lang:email_send_failure_phpmail');
return FALSE; return FALSE;
} }
break; break;
@@ -1492,7 +1492,7 @@ class CI_Email {
if ( ! $this->_send_with_sendmail()) if ( ! $this->_send_with_sendmail())
{ {
$this->_set_error_message('email_send_failure_sendmail'); $this->_set_error_message('lang:email_send_failure_sendmail');
return FALSE; return FALSE;
} }
break; break;
@@ -1500,14 +1500,14 @@ class CI_Email {
if ( ! $this->_send_with_smtp()) if ( ! $this->_send_with_smtp())
{ {
$this->_set_error_message('email_send_failure_smtp'); $this->_set_error_message('lang:email_send_failure_smtp');
return FALSE; return FALSE;
} }
break; break;
} }
$this->_set_error_message('email_sent', $this->_get_protocol()); $this->_set_error_message('lang:email_sent', $this->_get_protocol());
return TRUE; return TRUE;
} }
@@ -1578,8 +1578,8 @@ class CI_Email {
if ($status != 0) if ($status != 0)
{ {
$this->_set_error_message('email_exit_status', $status); $this->_set_error_message('lang:email_exit_status', $status);
$this->_set_error_message('email_no_socket'); $this->_set_error_message('lang:email_no_socket');
return FALSE; return FALSE;
} }
@@ -1598,7 +1598,7 @@ class CI_Email {
{ {
if ($this->smtp_host == '') if ($this->smtp_host == '')
{ {
$this->_set_error_message('email_no_hostname'); $this->_set_error_message('lang:email_no_hostname');
return FALSE; return FALSE;
} }
@@ -1647,7 +1647,7 @@ class CI_Email {
if (strncmp($reply, '250', 3) != 0) if (strncmp($reply, '250', 3) != 0)
{ {
$this->_set_error_message('email_smtp_error', $reply); $this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE; return FALSE;
} }
@@ -1674,7 +1674,7 @@ class CI_Email {
if ( ! is_resource($this->_smtp_connect)) if ( ! is_resource($this->_smtp_connect))
{ {
$this->_set_error_message('email_smtp_error', $errno." ".$errstr); $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
return FALSE; return FALSE;
} }
@@ -1737,7 +1737,7 @@ class CI_Email {
if (substr($reply, 0, 3) != $resp) if (substr($reply, 0, 3) != $resp)
{ {
$this->_set_error_message('email_smtp_error', $reply); $this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE; return FALSE;
} }
@@ -1766,7 +1766,7 @@ class CI_Email {
if ($this->smtp_user == "" AND $this->smtp_pass == "") if ($this->smtp_user == "" AND $this->smtp_pass == "")
{ {
$this->_set_error_message('email_no_smtp_unpw'); $this->_set_error_message('lang:email_no_smtp_unpw');
return FALSE; return FALSE;
} }
@@ -1776,7 +1776,7 @@ class CI_Email {
if (strncmp($reply, '334', 3) != 0) if (strncmp($reply, '334', 3) != 0)
{ {
$this->_set_error_message('email_failed_smtp_login', $reply); $this->_set_error_message('lang:email_failed_smtp_login', $reply);
return FALSE; return FALSE;
} }
@@ -1786,7 +1786,7 @@ class CI_Email {
if (strncmp($reply, '334', 3) != 0) if (strncmp($reply, '334', 3) != 0)
{ {
$this->_set_error_message('email_smtp_auth_un', $reply); $this->_set_error_message('lang:email_smtp_auth_un', $reply);
return FALSE; return FALSE;
} }
@@ -1796,7 +1796,7 @@ class CI_Email {
if (strncmp($reply, '235', 3) != 0) if (strncmp($reply, '235', 3) != 0)
{ {
$this->_set_error_message('email_smtp_auth_pw', $reply); $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
return FALSE; return FALSE;
} }
@@ -1815,7 +1815,7 @@ class CI_Email {
{ {
if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
{ {
$this->_set_error_message('email_smtp_data_failure', $data); $this->_set_error_message('lang:email_smtp_data_failure', $data);
return FALSE; return FALSE;
} }
else else
@@ -1942,7 +1942,7 @@ class CI_Email {
$CI =& get_instance(); $CI =& get_instance();
$CI->lang->load('email'); $CI->lang->load('email');
if (FALSE === ($line = $CI->lang->line($msg))) if (substr($msg, 0, 5) != 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5))))
{ {
$this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />"; $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
} }

View File

@@ -524,7 +524,7 @@ class CI_Encrypt {
{ {
if ( ! function_exists('mhash')) if ( ! function_exists('mhash'))
{ {
require_once(BASEPATH.'libraries/Sha1'.EXT); require_once(BASEPATH.'libraries/Sha1.php');
$SH = new CI_SHA; $SH = new CI_SHA;
return $SH->generate($str); return $SH->generate($str);
} }

View File

@@ -628,6 +628,10 @@ class CI_Form_validation {
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
} }
} }
else
{
log_message('debug', "Unable to find validation rule: ".$rule);
}
continue; continue;
} }

View File

@@ -83,7 +83,7 @@ class CI_Log {
return FALSE; return FALSE;
} }
$filepath = $this->_log_path.'log-'.date('Y-m-d').EXT; $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
$message = ''; $message = '';
if ( ! file_exists($filepath)) if ( ! file_exists($filepath))

View File

@@ -30,7 +30,7 @@ class CI_Pagination {
var $prefix = ''; // A custom prefix added to the path. var $prefix = ''; // A custom prefix added to the path.
var $suffix = ''; // A custom suffix added to the path. var $suffix = ''; // A custom suffix added to the path.
var $total_rows = ''; // Total number of items (database results) var $total_rows = 0; // Total number of items (database results)
var $per_page = 10; // Max number of items you want shown per page var $per_page = 10; // Max number of items you want shown per page
var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
var $cur_page = 0; // The current page being viewed var $cur_page = 0; // The current page being viewed

View File

@@ -32,8 +32,6 @@
*/ */
class CI_Profiler { class CI_Profiler {
var $CI;
protected $_available_sections = array( protected $_available_sections = array(
'benchmarks', 'benchmarks',
'get', 'get',
@@ -43,14 +41,27 @@ class CI_Profiler {
'controller_info', 'controller_info',
'queries', 'queries',
'http_headers', 'http_headers',
'session_data',
'config' 'config'
); );
protected $_query_toggle_count = 25;
protected $CI;
// --------------------------------------------------------------------
public function __construct($config = array()) public function __construct($config = array())
{ {
$this->CI =& get_instance(); $this->CI =& get_instance();
$this->CI->load->language('profiler'); $this->CI->load->language('profiler');
if (isset($config['query_toggle_count']))
{
$this->_query_toggle_count = (int) $config['query_toggle_count'];
unset($config['query_toggle_count']);
}
// default all sections to display // default all sections to display
foreach ($this->_available_sections as $section) foreach ($this->_available_sections as $section)
{ {
@@ -162,7 +173,7 @@ class CI_Profiler {
$output .= "\n"; $output .= "\n";
$output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>'; $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';
$output .= "\n"; $output .= "\n";
$output .= "\n\n<table style='border:none; width:100%'>\n"; $output .= "\n\n<table style='border:none; width:100%;'>\n";
$output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n"; $output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";
$output .= "</table>\n"; $output .= "</table>\n";
$output .= "</fieldset>"; $output .= "</fieldset>";
@@ -178,13 +189,26 @@ class CI_Profiler {
$output = "\n\n"; $output = "\n\n";
$count = 0;
foreach ($dbs as $db) foreach ($dbs as $db)
{ {
$count++;
$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';
if ($hide_queries != '')
{
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
}
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n"; $output .= "\n";
$output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database').':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'&nbsp;&nbsp;&nbsp;</legend>'; $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database').':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'&nbsp;&nbsp;'.$show_hide_js.'</legend>';
$output .= "\n"; $output .= "\n";
$output .= "\n\n<table style='width:100%;'>\n"; $output .= "\n\n<table style='width:100%;{$hide_queries}' id='ci_profiler_queries_db_{$count}'>\n";
if (count($db->queries) == 0) if (count($db->queries) == 0)
{ {
@@ -388,7 +412,7 @@ class CI_Profiler {
} }
else else
{ {
$output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory_usage')."</div>"; $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory')."</div>";
} }
$output .= "</fieldset>"; $output .= "</fieldset>";
@@ -410,10 +434,10 @@ class CI_Profiler {
$output = "\n\n"; $output = "\n\n";
$output .= '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n"; $output .= "\n";
$output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_headers').'&nbsp;&nbsp;</legend>'; $output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_headers').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
$output .= "\n"; $output .= "\n";
$output .= "\n\n<table style='width:100%'>\n"; $output .= "\n\n<table style='width:100%;display:none' id='ci_profiler_httpheaders_table'>\n";
foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header)
{ {
@@ -441,10 +465,10 @@ class CI_Profiler {
$output = "\n\n"; $output = "\n\n";
$output .= '<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= '<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n"; $output .= "\n";
$output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_config').'&nbsp;&nbsp;</legend>'; $output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_config').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
$output .= "\n"; $output .= "\n";
$output .= "\n\n<table style='width:100%'>\n"; $output .= "\n\n<table style='width:100%; display:none' id='ci_profiler_config_table'>\n";
foreach ($this->CI->config->config as $config=>$val) foreach ($this->CI->config->config as $config=>$val)
{ {
@@ -464,6 +488,39 @@ class CI_Profiler {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Compile session userdata
*
* @return string
*/
private function _compile_session_data()
{
if ( ! isset($this->CI->session))
{
return;
}
$output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_session_data').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
$output .= "<table style='width:100%;display:none' id='ci_profiler_session_data'>";
foreach ($this->CI->session->all_userdata() as $key => $val)
{
if (is_array($val))
{
$val = print_r($val, TRUE);
}
$output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$key."&nbsp;&nbsp;</td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n";
}
$output .= '</table>';
$output .= "</fieldset>";
return $output;
}
// --------------------------------------------------------------------
/** /**
* Run the Profiler * Run the Profiler
* *
@@ -493,7 +550,6 @@ class CI_Profiler {
return $output; return $output;
} }
} }
// END CI_Profiler class // END CI_Profiler class

View File

@@ -189,7 +189,7 @@ class CI_Session {
} }
// Does the User Agent Match? // Does the User Agent Match?
if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120)))
{ {
$this->sess_destroy(); $this->sess_destroy();
return FALSE; return FALSE;
@@ -316,7 +316,7 @@ class CI_Session {
$this->userdata = array( $this->userdata = array(
'session_id' => md5(uniqid($sessid, TRUE)), 'session_id' => md5(uniqid($sessid, TRUE)),
'ip_address' => $this->CI->input->ip_address(), 'ip_address' => $this->CI->input->ip_address(),
'user_agent' => substr($this->CI->input->user_agent(), 0, 50), 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
'last_activity' => $this->now 'last_activity' => $this->now
); );
@@ -435,11 +435,11 @@ class CI_Session {
* Fetch all session data * Fetch all session data
* *
* @access public * @access public
* @return mixed * @return array
*/ */
function all_userdata() function all_userdata()
{ {
return ( ! isset($this->userdata)) ? FALSE : $this->userdata; return $this->userdata;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -945,13 +945,13 @@ class CI_Upload {
if (count($this->mimes) == 0) if (count($this->mimes) == 0)
{ {
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
} }
elseif (is_file(APPPATH.'config/mimes'.EXT)) elseif (is_file(APPPATH.'config/mimes.php'))
{ {
include(APPPATH.'config//mimes'.EXT); include(APPPATH.'config//mimes.php');
} }
else else
{ {

View File

@@ -84,13 +84,13 @@ class CI_User_agent {
*/ */
private function _load_agent_file() private function _load_agent_file()
{ {
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
{ {
include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT); include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
} }
elseif (is_file(APPPATH.'config/user_agents'.EXT)) elseif (is_file(APPPATH.'config/user_agents.php'))
{ {
include(APPPATH.'config/user_agents'.EXT); include(APPPATH.'config/user_agents.php');
} }
else else
{ {