summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/config/config.php2
-rw-r--r--application/config/database.php2
-rw-r--r--application/config/foreign_chars.php4
-rw-r--r--application/config/mimes.php6
-rw-r--r--index.php59
-rw-r--r--readme.rst4
-rwxr-xr-xsystem/core/Benchmark.php23
-rwxr-xr-xsystem/core/CodeIgniter.php44
-rw-r--r--system/core/Common.php153
-rwxr-xr-xsystem/core/Config.php114
-rw-r--r--system/core/Controller.php18
-rwxr-xr-xsystem/core/Exceptions.php81
-rwxr-xr-xsystem/core/Hooks.php41
-rwxr-xr-xsystem/core/Input.php164
-rwxr-xr-xsystem/core/Lang.php28
-rw-r--r--system/core/Loader.php109
-rwxr-xr-xsystem/core/Model.php21
-rwxr-xr-xsystem/core/Output.php153
-rwxr-xr-xsystem/core/Router.php107
-rwxr-xr-xsystem/core/Security.php286
-rwxr-xr-xsystem/core/URI.php190
-rw-r--r--system/core/Utf8.php32
-rwxr-xr-xsystem/database/DB.php55
-rw-r--r--system/database/DB_active_rec.php410
-rw-r--r--system/database/DB_cache.php49
-rw-r--r--system/database/DB_driver.php97
-rw-r--r--system/database/DB_forge.php94
-rw-r--r--system/database/DB_result.php83
-rw-r--r--system/database/DB_utility.php159
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php27
-rw-r--r--system/database/drivers/mssql/mssql_driver.php35
-rw-r--r--system/database/drivers/mysql/mysql_driver.php336
-rw-r--r--system/database/drivers/mysql/mysql_forge.php131
-rw-r--r--system/database/drivers/mysql/mysql_result.php57
-rw-r--r--system/database/drivers/mysql/mysql_utility.php75
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php333
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php137
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php57
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php34
-rw-r--r--system/database/drivers/oci8/oci8_driver.php68
-rw-r--r--system/database/drivers/odbc/odbc_driver.php18
-rw-r--r--system/database/drivers/odbc/odbc_result.php58
-rw-r--r--system/database/drivers/pdo/pdo_driver.php325
-rw-r--r--system/database/drivers/pdo/pdo_forge.php12
-rw-r--r--system/database/drivers/pdo/pdo_result.php67
-rw-r--r--system/database/drivers/postgre/postgre_driver.php18
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php18
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php68
-rw-r--r--system/helpers/download_helper.php85
-rw-r--r--system/helpers/file_helper.php14
-rw-r--r--system/helpers/inflector_helper.php152
-rw-r--r--system/helpers/typography_helper.php10
-rw-r--r--[-rwxr-xr-x]system/helpers/url_helper.php130
-rw-r--r--system/helpers/xml_helper.php26
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php1
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php2
-rw-r--r--system/libraries/Cart.php7
-rw-r--r--system/libraries/Email.php331
-rw-r--r--system/libraries/Encrypt.php112
-rw-r--r--system/libraries/Form_validation.php42
-rw-r--r--system/libraries/Image_lib.php441
-rw-r--r--system/libraries/Pagination.php2
-rw-r--r--system/libraries/Session.php133
-rw-r--r--system/libraries/Typography.php2
-rw-r--r--system/libraries/Upload.php121
-rw-r--r--user_guide_src/source/changelog.rst62
-rw-r--r--user_guide_src/source/database/configuration.rst4
-rw-r--r--user_guide_src/source/database/connecting.rst6
-rw-r--r--user_guide_src/source/general/styleguide.rst16
-rw-r--r--user_guide_src/source/general/urls.rst11
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst9
-rw-r--r--user_guide_src/source/libraries/security.rst4
-rw-r--r--user_guide_src/source/tutorial/static_pages.rst2
73 files changed, 2670 insertions, 3517 deletions
diff --git a/application/config/config.php b/application/config/config.php
index bb35324c3..17b854b29 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -326,12 +326,14 @@ $config['global_xss_filtering'] = FALSE;
| 'csrf_token_name' = The token name
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
+| 'csrf_regenerate' = Regenerate token on every submission
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
*/
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
+$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
/*
diff --git a/application/config/database.php b/application/config/database.php
index 7eac59b23..bd68db1d8 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -37,6 +37,7 @@
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
+| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
@@ -74,6 +75,7 @@
$active_group = 'default';
$active_record = TRUE;
+$db['default']['dsn'] = '';
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index f2f981c27..3abb2fd0c 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -5,9 +5,9 @@
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Academic Free License version 3.0
- *
+ *
* This source file is subject to the Academic Free License (AFL 3.0) that is
* bundled with this package in the files license_afl.txt / license_afl.rst.
* It is also available through the world wide web at this URL:
diff --git a/application/config/mimes.php b/application/config/mimes.php
index 8c34fd298..d69497a30 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -120,9 +120,9 @@ $mimes = array('hqx' => array('application/mac-binhex40', 'application/mac-binhe
'mov' => 'video/quicktime',
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
'movie' => 'video/x-sgi-movie',
- 'doc' => 'application/msword',
- 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ 'doc' => array('application/msword', 'application/vnd.ms-office'),
+ 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
+ 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
diff --git a/index.php b/index.php
index 4ae1ceebd..a37826690 100644
--- a/index.php
+++ b/index.php
@@ -5,9 +5,9 @@
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -41,7 +41,6 @@
* production
*
* NOTE: If you change these, also change the error_reporting() code below
- *
*/
define('ENVIRONMENT', 'development');
/*
@@ -60,12 +59,10 @@ if (defined('ENVIRONMENT'))
case 'development':
error_reporting(-1);
break;
-
case 'testing':
case 'production':
error_reporting(0);
break;
-
default:
exit('The application environment is not set correctly.');
}
@@ -79,7 +76,6 @@ if (defined('ENVIRONMENT'))
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
- *
*/
$system_path = 'system';
@@ -90,30 +86,28 @@ if (defined('ENVIRONMENT'))
*
* If you want this front controller to use a different "application"
* folder then the default one you can set its name here. The folder
- * can also be renamed or relocated anywhere on your server. If
+ * can also be renamed or relocated anywhere on your server. If
* you do, use a full server path. For more info please see the user guide:
* http://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
- *
*/
$application_folder = 'application';
-
+
/*
*---------------------------------------------------------------
* VIEW FOLDER NAME
*---------------------------------------------------------------
- *
- * If you want to move the view folder out of the application
+ *
+ * If you want to move the view folder out of the application
* folder set the path to the folder here. The folder can be renamed
- * and relocated anywhere on your server. If blank, it will default
- * to the standard location inside your application folder. If you
- * do move this, use the full server path to this folder
+ * and relocated anywhere on your server. If blank, it will default
+ * to the standard location inside your application folder. If you
+ * do move this, use the full server path to this folder.
*
* NO TRAILING SLASH!
- *
*/
- $view_folder = '';
+ $view_folder = '';
/*
@@ -123,18 +117,17 @@ if (defined('ENVIRONMENT'))
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
- * specific controller class/function here. For most applications, you
+ * specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
- * IMPORTANT: If you set the routing here, NO OTHER controller will be
+ * IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
- * specific controller. Leave the function name blank if you need
+ * specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
- *
*/
// The directory name, relative to the "controllers" folder. Leave blank
// if your controller is not in a sub-folder within the "controllers" folder
@@ -160,7 +153,6 @@ if (defined('ENVIRONMENT'))
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
- *
*/
// $assign_to_config['name_of_config_item'] = 'value of config item';
@@ -193,7 +185,7 @@ if (defined('ENVIRONMENT'))
// Is the system path correct?
if ( ! is_dir($system_path))
{
- exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
+ exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME));
}
/*
@@ -209,7 +201,7 @@ if (defined('ENVIRONMENT'))
define('EXT', '.php');
// Path to the system folder
- define('BASEPATH', str_replace("\\", "/", $system_path));
+ define('BASEPATH', str_replace('\\', '/', $system_path));
// Path to the front controller (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));
@@ -217,7 +209,6 @@ if (defined('ENVIRONMENT'))
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
-
// The path to the "application" folder
if (is_dir($application_folder))
{
@@ -227,27 +218,28 @@ if (defined('ENVIRONMENT'))
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
- exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
-
+
// The path to the "views" folder
- if (is_dir($view_folder))
+ if (is_dir($view_folder))
{
define ('VIEWPATH', $view_folder .'/');
}
- else
+ else
{
if ( ! is_dir(APPPATH.'views/'))
{
- exit("Your view folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
-
- define ('VIEWPATH', APPPATH.'views/' );
+
+ define ('VIEWPATH', APPPATH.'views/' );
}
-
/*
* --------------------------------------------------------------------
@@ -255,9 +247,8 @@ if (defined('ENVIRONMENT'))
* --------------------------------------------------------------------
*
* And away we go...
- *
*/
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
-/* Location: ./index.php */ \ No newline at end of file
+/* Location: ./index.php */
diff --git a/readme.rst b/readme.rst
index 26e04ceac..2369a8ddb 100644
--- a/readme.rst
+++ b/readme.rst
@@ -23,7 +23,7 @@ Changelog and New Features
**************************
You can find a list of all changes for each release in the `user
-guide change log <https://github.com/EllisLab/CodeIgniter/blob/develop/user_guide/changelog.html>`_.
+guide change log <https://github.com/EllisLab/CodeIgniter/blob/develop/user_guide_src/source/changelog.rst>`_.
*******************
Server Requirements
@@ -193,4 +193,4 @@ Acknowledgement
***************
The EllisLab team and The Reactor Engineers would like to thank all the
-contributors to the CodeIgniter project and you, the CodeIgniter user. \ No newline at end of file
+contributors to the CodeIgniter project and you, the CodeIgniter user.
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index da246c9e0..f4dfd3dab 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -15,7 +15,7 @@
* If you did not receive a copy of the license and are unable to obtain it
* through the world wide web, please send an email to
* licensing@ellislab.com so we can send you a copy immediately.
- *
+ *
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
@@ -46,7 +46,7 @@ class CI_Benchmark {
*
* @var array
*/
- var $marker = array();
+ public $marker = array();
// --------------------------------------------------------------------
@@ -56,11 +56,10 @@ class CI_Benchmark {
* Multiple calls to this function can be made so that several
* execution points can be timed
*
- * @access public
* @param string $name name of the marker
* @return void
*/
- function mark($name)
+ public function mark($name)
{
$this->marker[$name] = microtime();
}
@@ -75,13 +74,12 @@ class CI_Benchmark {
* execution time to be shown in a template. The output class will
* swap the real value for this variable.
*
- * @access public
* @param string a particular marked point
* @param string a particular marked point
* @param integer the number of decimal places
* @return mixed
*/
- function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
+ public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
{
if ($point1 == '')
{
@@ -114,17 +112,14 @@ class CI_Benchmark {
* without the memory being calculated until the end.
* The output class will swap the real value for this variable.
*
- * @access public
* @return string
*/
- function memory_usage()
+ public function memory_usage()
{
return '{memory_usage}';
}
}
-// END CI_Benchmark class
-
/* End of file Benchmark.php */
-/* Location: ./system/core/Benchmark.php */ \ No newline at end of file
+/* Location: ./system/core/Benchmark.php */
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 5152073d5..7af3c485d 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -59,7 +59,7 @@
* Load the framework constants
* ------------------------------------------------------
*/
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
+ if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
{
require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
}
@@ -91,12 +91,12 @@
* "libraries" folder. Since CI allows config items to be
* overriden via data set in the main index. php file,
* before proceeding we need to know if a subclass_prefix
- * override exists. If so, we will set this value now,
+ * override exists. If so, we will set this value now,
* before any classes are loaded
* Note: Since the config file data is cached it doesn't
* hurt to load it here.
*/
- if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
+ if (isset($assign_to_config['subclass_prefix']) && $assign_to_config['subclass_prefix'] != '')
{
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
}
@@ -106,13 +106,10 @@
* Set a liberal script execution time limit
* ------------------------------------------------------
*/
- if (function_exists("set_time_limit") AND @ini_get("safe_mode") == 0)
+ if (function_exists('set_time_limit') && @ini_get('safe_mode') == 0
+ && php_sapi_name() !== 'cli') // Do not override the Time Limit value if running from Command Line
{
- // Do not override the Time Limit value if running from Command Line
- if(php_sapi_name() != 'cli')
- {
- @set_time_limit(300);
- }
+ @set_time_limit(300);
}
/*
@@ -162,7 +159,6 @@
* after the Config class is instantiated.
*
*/
-
$UNI =& load_class('Utf8', 'core');
/*
@@ -195,15 +191,13 @@
/*
* ------------------------------------------------------
- * Is there a valid cache file? If so, we're done...
+ * Is there a valid cache file? If so, we're done...
* ------------------------------------------------------
*/
- if ($EXT->_call_hook('cache_override') === FALSE)
+ if ($EXT->_call_hook('cache_override') === FALSE
+ && $OUT->_display_cache($CFG, $URI) == TRUE)
{
- if ($OUT->_display_cache($CFG, $URI) == TRUE)
- {
- exit;
- }
+ exit;
}
/*
@@ -273,13 +267,13 @@
$method = $RTR->fetch_method();
if ( ! class_exists($class)
- OR strncmp($method, '_', 1) == 0
+ OR strpos($method, '_') === 0
OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
)
{
if ( ! empty($RTR->routes['404_override']))
{
- $x = explode('/', $RTR->routes['404_override']);
+ $x = explode('/', $RTR->routes['404_override'], 2);
$class = $x[0];
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
@@ -341,7 +335,7 @@
// Check and see if we are using a 404 override and use it.
if ( ! empty($RTR->routes['404_override']))
{
- $x = explode('/', $RTR->routes['404_override']);
+ $x = explode('/', $RTR->routes['404_override'], 2);
$class = $x[0];
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
@@ -367,7 +361,6 @@
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
}
-
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
@@ -400,11 +393,10 @@
* Close the DB connection if one exists
* ------------------------------------------------------
*/
- if (class_exists('CI_DB') AND isset($CI->db))
+ if (class_exists('CI_DB') && isset($CI->db))
{
$CI->db->close();
}
-
/* End of file CodeIgniter.php */
-/* Location: ./system/core/CodeIgniter.php */ \ No newline at end of file
+/* Location: ./system/core/CodeIgniter.php */
diff --git a/system/core/Common.php b/system/core/Common.php
index f42bb640c..491979350 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -56,7 +56,7 @@ if ( ! function_exists('is_php'))
function is_php($version = '5.0.0')
{
static $_is_php;
- $version = (string)$version;
+ $version = (string) $version;
if ( ! isset($_is_php[$version]))
{
@@ -73,10 +73,10 @@ if ( ! function_exists('is_php'))
* Tests for file writability
*
* is_writable() returns TRUE on Windows servers when you really can't write to
- * the file, based on the read-only attribute. is_writable() is also unreliable
+ * the file, based on the read-only attribute. is_writable() is also unreliable
* on Unix servers if safe_mode is on.
*
- * @access private
+ * @access public
* @return void
*/
if ( ! function_exists('is_really_writable'))
@@ -84,17 +84,17 @@ if ( ! function_exists('is_really_writable'))
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
- if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
+ if (DIRECTORY_SEPARATOR === '/' && (bool) @ini_get('safe_mode') === FALSE)
{
return is_writable($file);
}
- // For windows servers and safe_mode "on" installations we'll actually
- // write a file then read it. Bah...
+ /* For Windows servers and safe_mode "on" installations we'll actually
+ * write a file then read it. Bah...
+ */
if (is_dir($file))
{
$file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100));
-
if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
{
return FALSE;
@@ -120,7 +120,7 @@ if ( ! function_exists('is_really_writable'))
/**
* Class registry
*
-* This function acts as a singleton. If the requested class does not
+* This function acts as a singleton. If the requested class does not
* exist it is instantiated and set to a static variable. If it has
* previously been instantiated the variable is returned.
*
@@ -136,7 +136,7 @@ if ( ! function_exists('load_class'))
{
static $_classes = array();
- // Does the class exist? If so, we're done...
+ // Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
return $_classes[$class];
@@ -161,7 +161,7 @@ if ( ! function_exists('load_class'))
}
}
- // 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.'.php'))
{
$name = config_item('subclass_prefix').$class;
@@ -177,6 +177,7 @@ if ( ! function_exists('load_class'))
{
// Note: We use exit() rather then show_error() in order to avoid a
// self-referencing loop with the Excptions class
+ set_status_header(503);
exit('Unable to locate the specified class: '.$class.'.php');
}
@@ -191,7 +192,7 @@ if ( ! function_exists('load_class'))
// --------------------------------------------------------------------
/**
-* Keeps track of which libraries have been loaded. This function is
+* Keeps track of which libraries have been loaded. This function is
* called by the load_class() function above
*
* @access public
@@ -199,7 +200,7 @@ if ( ! function_exists('load_class'))
*/
if ( ! function_exists('is_loaded'))
{
- function is_loaded($class = '')
+ function &is_loaded($class = '')
{
static $_is_loaded = array();
@@ -243,6 +244,7 @@ if ( ! function_exists('get_config'))
// Fetch the config file
if ( ! file_exists($file_path))
{
+ set_status_header(503);
exit('The configuration file does not exist.');
}
@@ -251,6 +253,7 @@ if ( ! function_exists('get_config'))
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
+ set_status_header(503);
exit('Your config file does not appear to be formatted correctly.');
}
@@ -387,76 +390,76 @@ if ( ! function_exists('set_status_header'))
function set_status_header($code = 200, $text = '')
{
$stati = array(
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
-
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
-
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
- 422 => 'Unprocessable Entity',
-
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported'
- );
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 203 => 'Non-Authoritative Information',
+ 204 => 'No Content',
+ 205 => 'Reset Content',
+ 206 => 'Partial Content',
+
+ 300 => 'Multiple Choices',
+ 301 => 'Moved Permanently',
+ 302 => 'Found',
+ 304 => 'Not Modified',
+ 305 => 'Use Proxy',
+ 307 => 'Temporary Redirect',
+
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Long',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Requested Range Not Satisfiable',
+ 417 => 'Expectation Failed',
+ 422 => 'Unprocessable Entity',
+
+ 500 => 'Internal Server Error',
+ 501 => 'Not Implemented',
+ 502 => 'Bad Gateway',
+ 503 => 'Service Unavailable',
+ 504 => 'Gateway Timeout',
+ 505 => 'HTTP Version Not Supported'
+ );
if ($code == '' OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}
- if (isset($stati[$code]) AND $text == '')
+ if (isset($stati[$code]) && $text == '')
{
$text = $stati[$code];
}
if ($text == '')
{
- show_error('No status text available. Please check your status code number or supply your own message text.', 500);
+ show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
- $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
+ $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
- if (substr(php_sapi_name(), 0, 3) == 'cgi')
+ if (strpos(php_sapi_name(), 'cgi') === 0)
{
- header("Status: {$code} {$text}", TRUE);
+ header('Status: '.$code.' '.$text, TRUE);
}
- elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')
+ elseif ($server_protocol === 'HTTP/1.0')
{
- header($server_protocol." {$code} {$text}", TRUE, $code);
+ header('HTTP/1.0 '.$code.' '.$text, TRUE, $code);
}
else
{
- header("HTTP/1.1 {$code} {$text}", TRUE, $code);
+ header('HTTP/1.1 '.$code.' '.$text, TRUE, $code);
}
}
}
@@ -527,16 +530,15 @@ if ( ! function_exists('remove_invisible_characters'))
function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displayables = array();
-
- // every control character except newline (dec 10)
- // carriage return (dec 13), and horizontal tab (dec 09)
-
+
+ // every control character except newline (dec 10),
+ // carriage return (dec 13) and horizontal tab (dec 09)
if ($url_encoded)
{
$non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
$non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
}
-
+
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
do
@@ -562,16 +564,11 @@ if ( ! function_exists('html_escape'))
{
function html_escape($var)
{
- if (is_array($var))
- {
- return array_map('html_escape', $var);
- }
- else
- {
- return htmlspecialchars($var, ENT_QUOTES, config_item('charset'));
- }
+ return is_array($var)
+ ? array_map('html_escape', $var)
+ : htmlspecialchars($var, ENT_QUOTES, config_item('charset'));
}
}
/* End of file Common.php */
-/* Location: ./system/core/Common.php */ \ No newline at end of file
+/* Location: ./system/core/Common.php */
diff --git a/system/core/Config.php b/system/core/Config.php
index 3e2635494..68417435d 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -45,46 +45,45 @@ class CI_Config {
*
* @var array
*/
- var $config = array();
+ public $config = array();
/**
* List of all loaded config files
*
* @var array
*/
- var $is_loaded = array();
+ public $is_loaded = array();
/**
- * List of paths to search when trying to load a config file
+ * List of paths to search when trying to load a config file.
+ * This must be public as it's used by the Loader class.
*
* @var array
*/
- var $_config_paths = array(APPPATH);
+ public $_config_paths = array(APPPATH);
/**
* Constructor
*
* Sets the $config data from the primary config.php file as a class variable
*
- * @access public
* @param string the config file name
* @param boolean if configuration values should be loaded into their own section
* @param boolean true if errors should just return false, false if an error message should be displayed
* @return boolean if the file was successfully loaded or not
*/
- function __construct()
+ public function __construct()
{
$this->config =& get_config();
- log_message('debug', "Config Class Initialized");
+ log_message('debug', 'Config Class Initialized');
// Set the base_url automatically if none was provided
if ($this->config['base_url'] == '')
{
if (isset($_SERVER['HTTP_HOST']))
{
- $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
- $base_url .= '://'. $_SERVER['HTTP_HOST'];
- $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+ $base_url = ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
+ $base_url .= '://'. $_SERVER['HTTP_HOST']
+ . str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
-
else
{
$base_url = 'http://localhost/';
@@ -99,17 +98,15 @@ class CI_Config {
/**
* Load Config File
*
- * @access public
* @param string the config file name
- * @param boolean if configuration values should be loaded into their own section
- * @param boolean true if errors should just return false, false if an error message should be displayed
+ * @param boolean if configuration values should be loaded into their own section
+ * @param boolean true if errors should just return false, false if an error message should be displayed
* @return boolean if the file was loaded correctly
*/
- function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
+ public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$file = ($file == '') ? 'config' : str_replace('.php', '', $file);
- $found = FALSE;
- $loaded = FALSE;
+ $found = $loaded = FALSE;
foreach ($this->_config_paths as $path)
{
@@ -192,39 +189,19 @@ class CI_Config {
* Fetch a config file item
*
*
- * @access public
* @param string the config item name
* @param string the index name
* @param bool
* @return string
*/
- function item($item, $index = '')
+ public function item($item, $index = '')
{
if ($index == '')
{
- if ( ! isset($this->config[$item]))
- {
- return FALSE;
- }
-
- $pref = $this->config[$item];
- }
- else
- {
- if ( ! isset($this->config[$index]))
- {
- return FALSE;
- }
-
- if ( ! isset($this->config[$index][$item]))
- {
- return FALSE;
- }
-
- $pref = $this->config[$index][$item];
+ return isset($this->config[$item]) ? $this->config[$item] : FALSE;
}
- return $pref;
+ return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : FALSE;
}
// --------------------------------------------------------------------
@@ -232,18 +209,17 @@ class CI_Config {
/**
* Fetch a config file item - adds slash after item (if item is not empty)
*
- * @access public
* @param string the config item name
* @param bool
* @return string
*/
- function slash_item($item)
+ public function slash_item($item)
{
if ( ! isset($this->config[$item]))
{
return FALSE;
}
- if( trim($this->config[$item]) == '')
+ elseif (trim($this->config[$item]) == '')
{
return '';
}
@@ -257,11 +233,10 @@ class CI_Config {
* Site URL
* Returns base_url . index_page [. uri_string]
*
- * @access public
* @param string the URI string
* @return string
*/
- function site_url($uri = '')
+ public function site_url($uri = '')
{
if ($uri == '')
{
@@ -285,11 +260,10 @@ class CI_Config {
* Base URL
* Returns base_url [. uri_string]
*
- * @access public
* @param string $uri
* @return string
*/
- function base_url($uri = '')
+ public function base_url($uri = '')
{
return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
}
@@ -299,8 +273,7 @@ class CI_Config {
/**
* Build URI string for use in Config::site_url() and Config::base_url()
*
- * @access protected
- * @param $uri
+ * @param mixed $uri
* @return string
*/
protected function _uri_string($uri)
@@ -311,23 +284,21 @@ class CI_Config {
{
$uri = implode('/', $uri);
}
- $uri = trim($uri, '/');
+ return trim($uri, '/');
}
- else
+ elseif (is_array($uri))
{
- if (is_array($uri))
+ $i = 0;
+ $str = '';
+ foreach ($uri as $key => $val)
{
- $i = 0;
- $str = '';
- foreach ($uri as $key => $val)
- {
- $prefix = ($i == 0) ? '' : '&';
- $str .= $prefix.$key.'='.$val;
- $i++;
- }
- $uri = $str;
+ $prefix = ($i === 0) ? '' : '&';
+ $str .= $prefix.$key.'='.$val;
+ $i++;
}
+ return $str;
}
+
return $uri;
}
@@ -336,12 +307,11 @@ class CI_Config {
/**
* System URL
*
- * @access public
* @return string
*/
- function system_url()
+ public function system_url()
{
- $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
+ $x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH));
return $this->slash_item('base_url').end($x).'/';
}
@@ -350,12 +320,11 @@ class CI_Config {
/**
* Set a config file item
*
- * @access public
* @param string the config item key
* @param string the config item value
* @return void
*/
- function set_item($item, $value)
+ public function set_item($item, $value)
{
$this->config[$item] = $value;
}
@@ -366,14 +335,13 @@ class CI_Config {
* Assign to Config
*
* This function is called by the front controller (CodeIgniter.php)
- * after the Config class is instantiated. It permits config items
+ * after the Config class is instantiated. It permits config items
* to be assigned or overriden by variables contained in the index.php file
*
- * @access private
* @param array
* @return void
*/
- function _assign_to_config($items = array())
+ public function _assign_to_config($items = array())
{
if (is_array($items))
{
@@ -385,7 +353,5 @@ class CI_Config {
}
}
-// END CI_Config class
-
/* End of file Config.php */
/* Location: ./system/core/Config.php */
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 55b3ec235..0dc131701 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -43,13 +43,10 @@ class CI_Controller {
private static $instance;
- /**
- * Constructor
- */
public function __construct()
{
self::$instance =& $this;
-
+
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
@@ -59,10 +56,8 @@ class CI_Controller {
}
$this->load =& load_class('Loader', 'core');
-
$this->load->initialize();
-
- log_message('debug', "Controller Class Initialized");
+ log_message('debug', 'Controller Class Initialized');
}
public static function &get_instance()
@@ -70,7 +65,6 @@ class CI_Controller {
return self::$instance;
}
}
-// END Controller class
/* End of file Controller.php */
-/* Location: ./system/core/Controller.php */ \ No newline at end of file
+/* Location: ./system/core/Controller.php */
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 3737f2930..bf9901252 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -37,49 +37,44 @@
* @link http://codeigniter.com/user_guide/libraries/exceptions.html
*/
class CI_Exceptions {
- var $action;
- var $severity;
- var $message;
- var $filename;
- var $line;
+
+ public $action;
+ public $severity;
+ public $message;
+ public $filename;
+ public $line;
/**
* Nesting level of the output buffering mechanism
*
* @var int
- * @access public
*/
- var $ob_level;
+ public $ob_level;
/**
* List if available error levels
*
* @var array
- * @access public
*/
- var $levels = array(
- E_ERROR => 'Error',
- E_WARNING => 'Warning',
- E_PARSE => 'Parsing Error',
- E_NOTICE => 'Notice',
- E_CORE_ERROR => 'Core Error',
- E_CORE_WARNING => 'Core Warning',
- E_COMPILE_ERROR => 'Compile Error',
- E_COMPILE_WARNING => 'Compile Warning',
- E_USER_ERROR => 'User Error',
- E_USER_WARNING => 'User Warning',
- E_USER_NOTICE => 'User Notice',
- E_STRICT => 'Runtime Notice'
- );
+ public $levels = array(
+ E_ERROR => 'Error',
+ E_WARNING => 'Warning',
+ E_PARSE => 'Parsing Error',
+ E_NOTICE => 'Notice',
+ E_CORE_ERROR => 'Core Error',
+ E_CORE_WARNING => 'Core Warning',
+ E_COMPILE_ERROR => 'Compile Error',
+ E_COMPILE_WARNING => 'Compile Warning',
+ E_USER_ERROR => 'User Error',
+ E_USER_WARNING => 'User Warning',
+ E_USER_NOTICE => 'User Notice',
+ E_STRICT => 'Runtime Notice'
+ );
-
- /**
- * Constructor
- */
public function __construct()
{
$this->ob_level = ob_get_level();
- // Note: Do not log messages from this constructor.
+ // Note: Do not log messages from this constructor.
}
// --------------------------------------------------------------------
@@ -89,17 +84,15 @@ class CI_Exceptions {
*
* This function logs PHP generated error messages
*
- * @access private
* @param string the error severity
* @param string the error string
* @param string the error filepath
* @param string the error line number
- * @return string
+ * @return void
*/
- function log_exception($severity, $message, $filepath, $line)
+ public function log_exception($severity, $message, $filepath, $line)
{
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
}
@@ -108,15 +101,14 @@ class CI_Exceptions {
/**
* 404 Page Not Found Handler
*
- * @access private
* @param string the page
* @param bool log error yes/no
* @return string
*/
- function show_404($page = '', $log_error = TRUE)
+ public function show_404($page = '', $log_error = TRUE)
{
- $heading = "404 Page Not Found";
- $message = "The page you requested was not found.";
+ $heading = '404 Page Not Found';
+ $message = 'The page you requested was not found.';
// By default we log this, but allow a dev to skip it
if ($log_error)
@@ -137,14 +129,13 @@ class CI_Exceptions {
* (either as a string or an array) and displays
* it using the specified template.
*
- * @access private
* @param string the heading
* @param string the message
* @param string the template name
* @param int the status code
* @return string
*/
- function show_error($heading, $message, $template = 'error_general', $status_code = 500)
+ public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
set_status_header($status_code);
@@ -166,7 +157,6 @@ class CI_Exceptions {
/**
* Native PHP error handler
*
- * @access private
* @param string the error severity
* @param string the error string
* @param string the error filepath
@@ -176,8 +166,7 @@ class CI_Exceptions {
function show_php_error($severity, $message, $filepath, $line)
{
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
- $filepath = str_replace("\\", "/", $filepath);
+ $filepath = str_replace('\\', '/', $filepath);
// For safety reasons we do not show the full file path
if (FALSE !== strpos($filepath, '/'))
@@ -191,15 +180,13 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/error_php.php');
+ include(APPPATH.'errors/'.'error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
-
}
-// END Exceptions Class
/* End of file Exceptions.php */
-/* Location: ./system/core/Exceptions.php */ \ No newline at end of file
+/* Location: ./system/core/Exceptions.php */
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 174adcb19..e1ac58e6e 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -45,28 +45,24 @@ class CI_Hooks {
*
* @var bool
*/
- var $enabled = FALSE;
+ public $enabled = FALSE;
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
- var $hooks = array();
+ public $hooks = array();
/**
* Determines wether hook is in progress, used to prevent infinte loops
*
* @var bool
*/
- var $in_progress = FALSE;
+ public $in_progress = FALSE;
- /**
- * Constructor
- *
- */
- function __construct()
+ public function __construct()
{
$this->_initialize();
- log_message('debug', "Hooks Class Initialized");
+ log_message('debug', 'Hooks Class Initialized');
}
// --------------------------------------------------------------------
@@ -74,24 +70,20 @@ class CI_Hooks {
/**
* Initialize the Hooks Preferences
*
- * @access private
* @return void
*/
- function _initialize()
+ private function _initialize()
{
$CFG =& load_class('Config', 'core');
// If hooks are not enabled in the config file
// there is nothing else to do
-
if ($CFG->item('enable_hooks') == FALSE)
{
return;
}
// Grab the "hooks" definition file.
- // If there are no hooks, we're done.
-
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
@@ -101,7 +93,7 @@ class CI_Hooks {
include(APPPATH.'config/hooks.php');
}
-
+ // If there are no hooks, we're done.
if ( ! isset($hook) OR ! is_array($hook))
{
return;
@@ -116,13 +108,12 @@ class CI_Hooks {
/**
* Call Hook
*
- * Calls a particular hook
+ * Calls a particular hook. Called by CodeIgniter.php.
*
- * @access private
* @param string the hook name
* @return mixed
*/
- function _call_hook($which = '')
+ public function _call_hook($which = '')
{
if ( ! $this->enabled OR ! isset($this->hooks[$which]))
{
@@ -151,11 +142,10 @@ class CI_Hooks {
*
* Runs a particular hook
*
- * @access private
* @param array the hook details
* @return bool
*/
- function _run_hook($data)
+ protected function _run_hook($data)
{
if ( ! is_array($data))
{
@@ -168,7 +158,6 @@ class CI_Hooks {
// If the script being called happens to have the same
// hook call within it a loop can happen
-
if ($this->in_progress == TRUE)
{
return;
@@ -254,7 +243,5 @@ class CI_Hooks {
}
-// END CI_Hooks class
-
/* End of file Hooks.php */
-/* Location: ./system/core/Hooks.php */ \ No newline at end of file
+/* Location: ./system/core/Hooks.php */
diff --git a/system/core/Input.php b/system/core/Input.php
index 7cfa4c63f..ee15f4013 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Input Class
*
@@ -45,39 +43,39 @@ class CI_Input {
*
* @var string
*/
- var $ip_address = FALSE;
+ public $ip_address = FALSE;
/**
* user agent (web browser) being used by the current user
*
* @var string
*/
- var $user_agent = FALSE;
+ public $user_agent = FALSE;
/**
* If FALSE, then $_GET will be set to an empty array
*
* @var bool
*/
- var $_allow_get_array = TRUE;
+ protected $_allow_get_array = TRUE;
/**
* If TRUE, then newlines are standardized
*
* @var bool
*/
- var $_standardize_newlines = TRUE;
+ protected $_standardize_newlines = TRUE;
/**
* Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
* Set automatically based on config setting
*
* @var bool
*/
- var $_enable_xss = FALSE;
+ protected $_enable_xss = FALSE;
/**
* Enables a CSRF cookie token to be set.
* Set automatically based on config setting
*
* @var bool
*/
- var $_enable_csrf = FALSE;
+ protected $_enable_csrf = FALSE;
/**
* List of all HTTP request headers
*
@@ -85,21 +83,19 @@ class CI_Input {
*/
protected $headers = array();
-
/**
* Constructor
*
* Sets whether to globally enable the XSS processing
* and whether to allow the $_GET array
- *
*/
public function __construct()
{
- log_message('debug', "Input Class Initialized");
+ log_message('debug', 'Input Class Initialized');
$this->_allow_get_array = (config_item('allow_get_array') === TRUE);
- $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
- $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+ $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
global $SEC;
$this->security =& $SEC;
@@ -122,7 +118,6 @@ class CI_Input {
*
* This is a helper function to retrieve values from global arrays
*
- * @access protected
* @param array
* @param string
* @param bool
@@ -148,7 +143,6 @@ class CI_Input {
/**
* Fetch an item from the GET array
*
- * @access public
* @param string
* @param bool
* @return string
@@ -156,7 +150,7 @@ class CI_Input {
public function get($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
- if ($index === NULL AND ! empty($_GET))
+ if ($index === NULL && ! empty($_GET))
{
$get = array();
@@ -176,7 +170,6 @@ class CI_Input {
/**
* Fetch an item from the POST array
*
- * @access public
* @param string
* @param bool
* @return string
@@ -184,7 +177,7 @@ class CI_Input {
public function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
- if ($index === NULL AND ! empty($_POST))
+ if ($index === NULL && ! empty($_POST))
{
$post = array();
@@ -205,21 +198,15 @@ class CI_Input {
/**
* Fetch an item from either the GET array or the POST
*
- * @access public
* @param string The index key
* @param bool XSS cleaning
* @return string
*/
public function get_post($index = '', $xss_clean = FALSE)
{
- if ( ! isset($_POST[$index]) )
- {
- return $this->get($index, $xss_clean);
- }
- else
- {
- return $this->post($index, $xss_clean);
- }
+ return isset($_POST[$index])
+ ? $this->post($index, $xss_clean)
+ : $this->get($index, $xss_clean);
}
// --------------------------------------------------------------------
@@ -227,7 +214,6 @@ class CI_Input {
/**
* Fetch an item from the COOKIE array
*
- * @access public
* @param string
* @param bool
* @return string
@@ -245,7 +231,6 @@ class CI_Input {
* Accepts six parameter, or you can submit an associative
* array in the first parameter containing all the values.
*
- * @access public
* @param mixed
* @param string the value of the cookie
* @param string the number of seconds until expiration
@@ -269,19 +254,19 @@ class CI_Input {
}
}
- if ($prefix == '' AND config_item('cookie_prefix') != '')
+ if ($prefix == '' && config_item('cookie_prefix') != '')
{
$prefix = config_item('cookie_prefix');
}
- if ($domain == '' AND config_item('cookie_domain') != '')
+ if ($domain == '' && config_item('cookie_domain') != '')
{
$domain = config_item('cookie_domain');
}
- if ($path == '/' AND config_item('cookie_path') != '/')
+ if ($path == '/' && config_item('cookie_path') !== '/')
{
$path = config_item('cookie_path');
}
- if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+ if ($secure == FALSE && config_item('cookie_secure') != FALSE)
{
$secure = config_item('cookie_secure');
}
@@ -303,7 +288,6 @@ class CI_Input {
/**
* Fetch an item from the SERVER array
*
- * @access public
* @param string
* @param bool
* @return string
@@ -318,7 +302,6 @@ class CI_Input {
/**
* Fetch the IP Address
*
- * @access public
* @return string
*/
public function ip_address()
@@ -335,11 +318,11 @@ class CI_Input {
$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
}
- elseif (! $this->server('HTTP_CLIENT_IP') AND $this->server('REMOTE_ADDR'))
+ elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR'))
{
$this->ip_address = $_SERVER['REMOTE_ADDR'];
}
- elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
+ elseif ($this->server('REMOTE_ADDR') && $this->server('HTTP_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
@@ -354,8 +337,7 @@ class CI_Input {
if ($this->ip_address === FALSE)
{
- $this->ip_address = '0.0.0.0';
- return $this->ip_address;
+ return $this->ip_address = '0.0.0.0';
}
if (strpos($this->ip_address, ',') !== FALSE)
@@ -366,7 +348,7 @@ class CI_Input {
if ( ! $this->valid_ip($this->ip_address))
{
- $this->ip_address = '0.0.0.0';
+ return $this->ip_address = '0.0.0.0';
}
return $this->ip_address;
@@ -379,7 +361,6 @@ class CI_Input {
*
* Updated version suggested by Geert De Deckere
*
- * @access public
* @param string
* @return bool
*/
@@ -394,7 +375,7 @@ class CI_Input {
$ip_segments = explode('.', $ip);
// Always 4 segments needed
- if (count($ip_segments) != 4)
+ if (count($ip_segments) !== 4)
{
return FALSE;
}
@@ -408,7 +389,7 @@ class CI_Input {
{
// IP segments must be digits and can not be
// longer than 3 digits or greater then 255
- if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
+ if ($segment == '' OR preg_match('/[^0-9]/', $segment) OR $segment > 255 OR strlen($segment) > 3)
{
return FALSE;
}
@@ -422,7 +403,6 @@ class CI_Input {
/**
* User Agent
*
- * @access public
* @return string
*/
public function user_agent()
@@ -432,9 +412,7 @@ class CI_Input {
return $this->user_agent;
}
- $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
-
- return $this->user_agent;
+ return $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : FALSE;
}
// --------------------------------------------------------------------
@@ -444,22 +422,20 @@ class CI_Input {
*
* This function does the following:
*
- * Unsets $_GET data (if query strings are not enabled)
- *
- * Unsets all globals if register_globals is enabled
+ * - Unsets $_GET data (if query strings are not enabled)
+ * - Unsets all globals if register_globals is enabled
+ * - Standardizes newline characters to \n
*
- * Standardizes newline characters to \n
- *
- * @access private
* @return void
*/
- private function _sanitize_globals()
+ protected function _sanitize_globals()
{
// It would be "wrong" to unset any of these GLOBALS.
$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
- '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
- 'system_folder', 'application_folder', 'BM', 'EXT',
- 'CFG', 'URI', 'RTR', 'OUT', 'IN');
+ '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
+ 'system_folder', 'application_folder', 'BM', 'EXT',
+ 'CFG', 'URI', 'RTR', 'OUT', 'IN'
+ );
// Unset globals for securiy.
// This is effectively the same as register_globals = off
@@ -491,19 +467,16 @@ class CI_Input {
{
$_GET = array();
}
- else
+ elseif (is_array($_GET) && count($_GET) > 0)
{
- if (is_array($_GET) AND count($_GET) > 0)
+ foreach ($_GET as $key => $val)
{
- foreach ($_GET as $key => $val)
- {
- $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
- }
+ $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
}
// Clean $_POST Data
- if (is_array($_POST) AND count($_POST) > 0)
+ if (is_array($_POST) && count($_POST) > 0)
{
foreach ($_POST as $key => $val)
{
@@ -512,7 +485,7 @@ class CI_Input {
}
// Clean $_COOKIE Data
- if (is_array($_COOKIE) AND count($_COOKIE) > 0)
+ if (is_array($_COOKIE) && count($_COOKIE) > 0)
{
// Also get rid of specially treated cookies that might be set by a server
// or silly application, that are of no use to a CI application anyway
@@ -532,14 +505,13 @@ class CI_Input {
// Sanitize PHP_SELF
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
-
// CSRF Protection check
if ($this->_enable_csrf == TRUE)
{
$this->security->csrf_verify();
}
- log_message('debug', "Global POST and COOKIE data sanitized");
+ log_message('debug', 'Global POST and COOKIE data sanitized');
}
// --------------------------------------------------------------------
@@ -550,11 +522,10 @@ class CI_Input {
* This is a helper function. It escapes data and
* standardizes newline characters to \n
*
- * @access private
* @param string
* @return string
*/
- private function _clean_input_data($str)
+ protected function _clean_input_data($str)
{
if (is_array($str))
{
@@ -592,12 +563,9 @@ class CI_Input {
}
// Standardize newlines if needed
- if ($this->_standardize_newlines == TRUE)
+ if ($this->_standardize_newlines == TRUE && strpos($str, "\r") !== FALSE)
{
- if (strpos($str, "\r") !== FALSE)
- {
- $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
- }
+ return str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
}
return $str;
@@ -612,21 +580,21 @@ class CI_Input {
* from trying to exploit keys we make sure that keys are
* only named with alpha-numeric text and a few other items.
*
- * @access private
* @param string
* @return string
*/
- private function _clean_input_keys($str)
+ protected function _clean_input_keys($str)
{
- if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
+ if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
{
+ set_status_header(503);
exit('Disallowed Key Characters.');
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
- $str = $this->uni->clean_string($str);
+ return $this->uni->clean_string($str);
}
return $str;
@@ -640,10 +608,8 @@ class CI_Input {
* In Apache, you can simply call apache_request_headers(), however for
* people running other webservers the function is undefined.
*
- * @access public
* @param bool XSS cleaning
- *
- * @return array
+ * @return array
*/
public function request_headers($xss_clean = FALSE)
{
@@ -654,11 +620,11 @@ class CI_Input {
}
else
{
- $headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
+ $headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
foreach ($_SERVER as $key => $val)
{
- if (strncmp($key, 'HTTP_', 5) === 0)
+ if (strpos($key, 'HTTP_') === 0)
{
$headers[substr($key, 5)] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
}
@@ -684,10 +650,9 @@ class CI_Input {
*
* Returns the value of a single member of the headers class member
*
- * @access public
- * @param string array key for $this->headers
- * @param boolean XSS Clean or not
- * @return mixed FALSE on failure, string on success
+ * @param string array key for $this->headers
+ * @param bool XSS Clean or not
+ * @return mixed FALSE on failure, string on success
*/
public function get_request_header($index, $xss_clean = FALSE)
{
@@ -701,12 +666,9 @@ class CI_Input {
return FALSE;
}
- if ($xss_clean === TRUE)
- {
- return $this->security->xss_clean($this->headers[$index]);
- }
-
- return $this->headers[$index];
+ return ($xss_clean === TRUE)
+ ? $this->security->xss_clean($this->headers[$index])
+ : $this->headers[$index];
}
// --------------------------------------------------------------------
@@ -716,12 +678,11 @@ class CI_Input {
*
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header
*
- * @access public
- * @return boolean
+ * @return bool
*/
public function is_ajax_request()
{
- return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
+ return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}
// --------------------------------------------------------------------
@@ -731,12 +692,11 @@ class CI_Input {
*
* Test to see if a request was made from the command line
*
- * @access public
- * @return boolean
+ * @return bool
*/
public function is_cli_request()
{
- return (php_sapi_name() == 'cli') or defined('STDIN');
+ return (php_sapi_name() === 'cli' OR defined('STDIN'));
}
}
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 5eb2801f6..c40a6856e 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -43,22 +43,17 @@ class CI_Lang {
*
* @var array
*/
- var $language = array();
+ public $language = array();
/**
* List of loaded language files
*
* @var array
*/
- var $is_loaded = array();
+ public $is_loaded = array();
- /**
- * Constructor
- *
- * @access public
- */
- function __construct()
+ public function __construct()
{
- log_message('debug', "Language Class Initialized");
+ log_message('debug', 'Language Class Initialized');
}
// --------------------------------------------------------------------
@@ -66,7 +61,6 @@ class CI_Lang {
/**
* Load a language file
*
- * @access public
* @param mixed the name of the language file to be loaded. Can be an array
* @param string the language (english, etc.)
* @param bool return loaded array of translations
@@ -74,7 +68,7 @@ class CI_Lang {
* @param string alternative path to look for language file
* @return mixed
*/
- function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
+ public function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
$langfile = str_replace('.php', '', $langfile);
@@ -136,7 +130,7 @@ class CI_Lang {
}
$this->is_loaded[] = $langfile;
- $this->language = $this->language + $lang;
+ $this->language = array_merge($this->language, $lang);
unset($lang);
log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
@@ -148,11 +142,10 @@ class CI_Lang {
/**
* Fetch a single line of text from the language array
*
- * @access public
* @param string $line the language line
* @return string
*/
- function line($line = '')
+ public function line($line = '')
{
$value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
@@ -166,7 +159,6 @@ class CI_Lang {
}
}
-// END Language Class
/* End of file Lang.php */
/* Location: ./system/core/Lang.php */
diff --git a/system/core/Loader.php b/system/core/Loader.php
index c4a6b501c..12daaa928 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -45,88 +45,77 @@ class CI_Loader {
* Nesting level of the output buffering mechanism
*
* @var int
- * @access protected
*/
protected $_ci_ob_level;
/**
* List of paths to load views from
*
* @var array
- * @access protected
*/
protected $_ci_view_paths = array();
/**
* List of paths to load libraries from
*
* @var array
- * @access protected
*/
protected $_ci_library_paths = array();
/**
* List of paths to load models from
*
* @var array
- * @access protected
*/
protected $_ci_model_paths = array();
/**
* List of paths to load helpers from
*
* @var array
- * @access protected
*/
protected $_ci_helper_paths = array();
/**
* List of loaded base classes
- * Set by the controller class
*
* @var array
- * @access protected
*/
protected $_base_classes = array(); // Set by the controller class
/**
* List of cached variables
*
* @var array
- * @access protected
*/
protected $_ci_cached_vars = array();
/**
* List of loaded classes
*
* @var array
- * @access protected
*/
protected $_ci_classes = array();
/**
* List of loaded files
*
* @var array
- * @access protected
*/
protected $_ci_loaded_files = array();
/**
* List of loaded models
*
* @var array
- * @access protected
*/
protected $_ci_models = array();
/**
* List of loaded helpers
*
* @var array
- * @access protected
*/
protected $_ci_helpers = array();
/**
* List of class name mappings
*
* @var array
- * @access protected
*/
- protected $_ci_varmap = array('unit_test' => 'unit',
- 'user_agent' => 'agent');
+ protected $_ci_varmap = array(
+ 'unit_test' => 'unit',
+ 'user_agent' => 'agent'
+ );
/**
* Constructor
@@ -141,7 +130,7 @@ class CI_Loader {
$this->_ci_model_paths = array(APPPATH);
$this->_ci_view_paths = array(VIEWPATH => TRUE);
- log_message('debug', "Loader Class Initialized");
+ log_message('debug', 'Loader Class Initialized');
}
// --------------------------------------------------------------------
@@ -162,7 +151,6 @@ class CI_Loader {
$this->_base_classes =& is_loaded();
$this->_ci_autoloader();
-
return $this;
}
@@ -262,10 +250,10 @@ class CI_Loader {
if (($last_slash = strrpos($model, '/')) !== FALSE)
{
// The path is in front of the last slash
- $path = substr($model, 0, $last_slash + 1);
+ $path = substr($model, 0, ++$last_slash);
// And the model name behind it
- $model = substr($model, $last_slash + 1);
+ $model = substr($model, $last_slash);
}
if ($name == '')
@@ -311,9 +299,7 @@ class CI_Loader {
require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model);
-
$CI->$name = new $model();
-
$this->_ci_models[] = $name;
return;
}
@@ -350,7 +336,7 @@ class CI_Loader {
return DB($params, $active_record);
}
- // Initialize the db variable. Needed to prevent
+ // Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
@@ -716,11 +702,11 @@ class CI_Loader {
if ($path == '')
{
- $void = array_shift($this->_ci_library_paths);
- $void = array_shift($this->_ci_model_paths);
- $void = array_shift($this->_ci_helper_paths);
- $void = array_shift($this->_ci_view_paths);
- $void = array_shift($config->_config_paths);
+ array_shift($this->_ci_library_paths);
+ array_shift($this->_ci_model_paths);
+ array_shift($this->_ci_helper_paths);
+ array_shift($this->_ci_view_paths);
+ array_shift($config->_config_paths);
}
else
{
@@ -808,7 +794,6 @@ class CI_Loader {
// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.
-
$_ci_CI =& get_instance();
foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
{
@@ -837,22 +822,20 @@ class CI_Loader {
*
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
- * 2. So that the final rendered template can be
- * post-processed by the output class. Why do we
- * need post processing? For one thing, in order to
- * show the elapsed page load time. Unless we
- * can intercept the content right before it's sent to
- * the browser and then stop the timer it won't be accurate.
+ * 2. So that the final rendered template can be post-processed by
+ * the output class. Why do we need post processing? For one thing,
+ * in order to show the elapsed page load time. Unless we can
+ * intercept the content right before it's sent to the browser and
+ * then stop the timer it won't be accurate.
*/
ob_start();
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
-
if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
{
- echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
+ echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
}
else
{
@@ -877,7 +860,6 @@ class CI_Loader {
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
- *
*/
if (ob_get_level() > $this->_ci_ob_level + 1)
{
@@ -915,10 +897,10 @@ class CI_Loader {
if (($last_slash = strrpos($class, '/')) !== FALSE)
{
// Extract the path
- $subdir = substr($class, 0, $last_slash + 1);
+ $subdir = substr($class, 0, ++$last_slash);
// Get the filename from the path
- $class = substr($class, $last_slash + 1);
+ $class = substr($class, $last_slash);
}
// We'll test for both lowercase and capitalized versions of the file name
@@ -933,15 +915,15 @@ class CI_Loader {
if ( ! file_exists($baseclass))
{
- log_message('error', "Unable to load the requested class: ".$class);
- show_error("Unable to load the requested class: ".$class);
+ log_message('error', 'Unable to load the requested class: '.$class);
+ show_error('Unable to load the requested class: '.$class);
}
- // Safety: Was the class already loaded by a previous call?
+ // Safety: Was the class already loaded by a previous call?
if (in_array($subclass, $this->_ci_loaded_files))
{
// Before we deem this to be a duplicate request, let's see
- // if a custom object name is being supplied. If so, we'll
+ // if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ( ! is_null($object_name))
{
@@ -953,7 +935,7 @@ class CI_Loader {
}
$is_duplicate = TRUE;
- log_message('debug', $class." class already loaded. Second attempt ignored.");
+ log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
@@ -970,17 +952,17 @@ class CI_Loader {
{
$filepath = $path.'libraries/'.$subdir.$class.'.php';
- // Does the file exist? No? Bummer...
+ // Does the file exist? No? Bummer...
if ( ! file_exists($filepath))
{
continue;
}
- // Safety: Was the class already loaded by a previous call?
+ // Safety: Was the class already loaded by a previous call?
if (in_array($filepath, $this->_ci_loaded_files))
{
// Before we deem this to be a duplicate request, let's see
- // if a custom object name is being supplied. If so, we'll
+ // if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ( ! is_null($object_name))
{
@@ -992,7 +974,7 @@ class CI_Loader {
}
$is_duplicate = TRUE;
- log_message('debug', $class." class already loaded. Second attempt ignored.");
+ log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
@@ -1003,7 +985,7 @@ class CI_Loader {
} // END FOREACH
- // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
+ // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
if ($subdir == '')
{
$path = strtolower($class).'/'.$class;
@@ -1014,8 +996,8 @@ class CI_Loader {
// We do not issue errors if the load call failed due to a duplicate request
if ($is_duplicate == FALSE)
{
- log_message('error', "Unable to load the requested class: ".$class);
- show_error("Unable to load the requested class: ".$class);
+ log_message('error', 'Unable to load the requested class: '.$class);
+ show_error('Unable to load the requested class: '.$class);
}
}
@@ -1094,12 +1076,12 @@ class CI_Loader {
// Is the class name valid?
if ( ! class_exists($name))
{
- log_message('error', "Non-existent class: ".$name);
- show_error("Non-existent class: ".$class);
+ log_message('error', 'Non-existent class: '.$name);
+ show_error('Non-existent class: '.$class);
}
// Set the variable name we will assign the class to
- // Was a custom class name supplied? If so we'll use it
+ // Was a custom class name supplied? If so we'll use it
$class = strtolower($class);
if (is_null($object_name))
@@ -1181,13 +1163,6 @@ class CI_Loader {
}
}
- // A little tweak to remain backward compatible
- // The $autoload['core'] item was deprecated
- if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
- {
- $autoload['libraries'] = $autoload['core'];
- }
-
// Load libraries
if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
{
@@ -1256,13 +1231,13 @@ class CI_Loader {
{
if ( ! is_array($filename))
{
- return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension));
+ return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
}
else
{
foreach ($filename as $key => $val)
{
- $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension);
+ $filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
}
return $filename;
@@ -1271,4 +1246,4 @@ class CI_Loader {
}
/* End of file Loader.php */
-/* Location: ./system/core/Loader.php */ \ No newline at end of file
+/* Location: ./system/core/Loader.php */
diff --git a/system/core/Model.php b/system/core/Model.php
index fc640139a..a595a6ae2 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -38,14 +38,9 @@
*/
class CI_Model {
- /**
- * Constructor
- *
- * @access public
- */
- function __construct()
+ public function __construct()
{
- log_message('debug', "Model Class Initialized");
+ log_message('debug', 'Model Class Initialized');
}
/**
@@ -55,15 +50,13 @@ class CI_Model {
* syntax as controllers.
*
* @param string
- * @access private
*/
- function __get($key)
+ public function __get($key)
{
$CI =& get_instance();
return $CI->$key;
}
}
-// END Model Class
/* End of file Model.php */
-/* Location: ./system/core/Model.php */ \ No newline at end of file
+/* Location: ./system/core/Model.php */
diff --git a/system/core/Output.php b/system/core/Output.php
index e529f914d..abd8a0ea9 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -44,64 +44,52 @@ class CI_Output {
* Current output string
*
* @var string
- * @access protected
*/
protected $final_output;
/**
* Cache expiration time
*
* @var int
- * @access protected
*/
protected $cache_expiration = 0;
/**
* List of server headers
*
* @var array
- * @access protected
*/
protected $headers = array();
/**
* List of mime types
*
* @var array
- * @access protected
*/
protected $mime_types = array();
/**
* Determines wether profiler is enabled
*
* @var book
- * @access protected
*/
protected $enable_profiler = FALSE;
/**
* Determines if output compression is enabled
*
* @var bool
- * @access protected
*/
protected $_zlib_oc = FALSE;
/**
* List of profiler sections
*
* @var array
- * @access protected
*/
protected $_profiler_sections = array();
/**
* Whether or not to parse variables like {elapsed_time} and {memory_usage}
*
* @var bool
- * @access protected
*/
protected $parse_exec_vars = TRUE;
- /**
- * Constructor
- *
- */
- function __construct()
+ public function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
@@ -117,8 +105,7 @@ class CI_Output {
$this->mime_types = $mimes;
-
- log_message('debug', "Output Class Initialized");
+ log_message('debug', 'Output Class Initialized');
}
// --------------------------------------------------------------------
@@ -128,10 +115,9 @@ class CI_Output {
*
* Returns the current output string
*
- * @access public
* @return string
*/
- function get_output()
+ public function get_output()
{
return $this->final_output;
}
@@ -143,14 +129,12 @@ class CI_Output {
*
* Sets the output string
*
- * @access public
* @param string
* @return void
*/
- function set_output($output)
+ public function set_output($output)
{
$this->final_output = $output;
-
return $this;
}
@@ -161,11 +145,10 @@ class CI_Output {
*
* Appends data onto the output string
*
- * @access public
* @param string
* @return void
*/
- function append_output($output)
+ public function append_output($output)
{
if ($this->final_output == '')
{
@@ -189,25 +172,22 @@ class CI_Output {
* Note: If a file is cached, headers will not be sent. We need to figure out
* how to permit header data to be saved with the cache data...
*
- * @access public
* @param string
* @param bool
* @return void
*/
- function set_header($header, $replace = TRUE)
+ public function set_header($header, $replace = TRUE)
{
// If zlib.output_compression is enabled it will compress the output,
// but it will not modify the content-length header to compensate for
// the reduction, causing the browser to hang waiting for more data.
// We'll just skip content-length in those cases.
-
if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0)
{
return;
}
$this->headers[] = array($header, $replace);
-
return $this;
}
@@ -216,11 +196,10 @@ class CI_Output {
/**
* Set Content Type Header
*
- * @access public
* @param string extension of the file we're outputting
* @return void
*/
- function set_content_type($mime_type)
+ public function set_content_type($mime_type)
{
if (strpos($mime_type, '/') === FALSE)
{
@@ -241,7 +220,6 @@ class CI_Output {
$header = 'Content-Type: '.$mime_type;
$this->headers[] = array($header, TRUE);
-
return $this;
}
@@ -251,15 +229,13 @@ class CI_Output {
* Set HTTP Status Header
* moved to Common procedural functions in 1.7.2
*
- * @access public
* @param int the status code
* @param string
* @return void
*/
- function set_status_header($code = 200, $text = '')
+ public function set_status_header($code = 200, $text = '')
{
set_status_header($code, $text);
-
return $this;
}
@@ -268,14 +244,12 @@ class CI_Output {
/**
* Enable/disable Profiler
*
- * @access public
* @param bool
* @return void
*/
- function enable_profiler($val = TRUE)
+ public function enable_profiler($val = TRUE)
{
$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
-
return $this;
}
@@ -286,11 +260,10 @@ class CI_Output {
*
* Allows override of default / config settings for Profiler section display
*
- * @access public
* @param array
* @return void
*/
- function set_profiler_sections($sections)
+ public function set_profiler_sections($sections)
{
foreach ($sections as $section => $enable)
{
@@ -305,14 +278,12 @@ class CI_Output {
/**
* Set Cache
*
- * @access public
* @param integer
* @return void
*/
- function cache($time)
+ public function cache($time)
{
$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
-
return $this;
}
@@ -329,11 +300,10 @@ class CI_Output {
* with any server headers and profile data. It also stops the
* benchmark timer so the page rendering speed and memory usage can be shown.
*
- * @access public
* @param string
* @return mixed
*/
- function _display($output = '')
+ public function _display($output = '')
{
// Note: We use globals because we can't use $CI =& get_instance()
// since this function is sometimes called by the caching mechanism,
@@ -375,22 +345,17 @@ class CI_Output {
{
$memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
- $output = str_replace('{elapsed_time}', $elapsed, $output);
- $output = str_replace('{memory_usage}', $memory, $output);
+ $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
}
// --------------------------------------------------------------------
// Is compression requested?
- if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE)
+ if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE
+ && extension_loaded('zlib')
+ && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
{
- if (extension_loaded('zlib'))
- {
- if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
- {
- ob_start('ob_gzhandler');
- }
- }
+ ob_start('ob_gzhandler');
}
// --------------------------------------------------------------------
@@ -412,8 +377,8 @@ class CI_Output {
if ( ! isset($CI))
{
echo $output;
- log_message('debug', "Final output sent to browser");
- log_message('debug', "Total execution time: ".$elapsed);
+ log_message('debug', 'Final output sent to browser');
+ log_message('debug', 'Total execution time: '.$elapsed);
return TRUE;
}
@@ -424,7 +389,6 @@ class CI_Output {
if ($this->enable_profiler == TRUE)
{
$CI->load->library('profiler');
-
if ( ! empty($this->_profiler_sections))
{
$CI->profiler->set_sections($this->_profiler_sections);
@@ -432,20 +396,13 @@ class CI_Output {
// If the output data contains closing </body> and </html> tags
// we will remove them and add them back after we insert the profile data
- if (preg_match("|</body>.*?</html>|is", $output))
+ $output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count).$CI->profiler->run();
+ if ($count > 0)
{
- $output = preg_replace("|</body>.*?</html>|is", '', $output);
- $output .= $CI->profiler->run();
$output .= '</body></html>';
}
- else
- {
- $output .= $CI->profiler->run();
- }
}
- // --------------------------------------------------------------------
-
// Does the controller contain a function named _output()?
// If so send the output there. Otherwise, echo it.
if (method_exists($CI, '_output'))
@@ -454,11 +411,11 @@ class CI_Output {
}
else
{
- echo $output; // Send it to the browser!
+ echo $output; // Send it to the browser!
}
- log_message('debug', "Final output sent to browser");
- log_message('debug', "Total execution time: ".$elapsed);
+ log_message('debug', 'Final output sent to browser');
+ log_message('debug', 'Total execution time: '.$elapsed);
}
// --------------------------------------------------------------------
@@ -466,20 +423,18 @@ class CI_Output {
/**
* Write a Cache File
*
- * @access public
* @param string
* @return void
*/
- function _write_cache($output)
+ public function _write_cache($output)
{
$CI =& get_instance();
$path = $CI->config->item('cache_path');
-
$cache_path = ($path == '') ? APPPATH.'cache/' : $path;
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
- log_message('error', "Unable to write cache file: ".$cache_path);
+ log_message('error', 'Unable to write cache file: '.$cache_path);
return;
}
@@ -491,7 +446,7 @@ class CI_Output {
if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
{
- log_message('error', "Unable to write cache file: ".$cache_path);
+ log_message('error', 'Unable to write cache file: '.$cache_path);
return;
}
@@ -504,13 +459,13 @@ class CI_Output {
}
else
{
- log_message('error', "Unable to secure a file lock for file at: ".$cache_path);
+ log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
return;
}
fclose($fp);
@chmod($cache_path, FILE_WRITE_MODE);
- log_message('debug', "Cache file written: ".$cache_path);
+ log_message('debug', 'Cache file written: '.$cache_path);
}
// --------------------------------------------------------------------
@@ -518,69 +473,51 @@ class CI_Output {
/**
* Update/serve a cached file
*
- * @access public
* @param object config class
* @param object uri class
* @return void
*/
- function _display_cache(&$CFG, &$URI)
+ public function _display_cache(&$CFG, &$URI)
{
$cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
- // Build the file path. The file name is an MD5 hash of the full URI
- $uri = $CFG->item('base_url').
- $CFG->item('index_page').
- $URI->uri_string;
-
+ // Build the file path. The file name is an MD5 hash of the full URI
+ $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
$filepath = $cache_path.md5($uri);
- if ( ! @file_exists($filepath))
- {
- return FALSE;
- }
-
- if ( ! $fp = @fopen($filepath, FOPEN_READ))
+ if ( ! @file_exists($filepath) OR ! $fp = @fopen($filepath, FOPEN_READ))
{
return FALSE;
}
flock($fp, LOCK_SH);
- $cache = '';
- if (filesize($filepath) > 0)
- {
- $cache = fread($fp, filesize($filepath));
- }
+ $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : '';
flock($fp, LOCK_UN);
fclose($fp);
// Strip out the embedded timestamp
- if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
+ if ( ! preg_match('/(\d+TS--->)/', $cache, $match))
{
return FALSE;
}
// Has the file expired? If so we'll delete it.
- if (time() >= trim(str_replace('TS--->', '', $match['1'])))
+ if (time() >= trim(str_replace('TS--->', '', $match[1])) && is_really_writable($cache_path))
{
- if (is_really_writable($cache_path))
- {
- @unlink($filepath);
- log_message('debug', "Cache file has expired. File deleted");
- return FALSE;
- }
+ @unlink($filepath);
+ log_message('debug', 'Cache file has expired. File deleted.');
+ return FALSE;
}
// Display the cache
- $this->_display(str_replace($match['0'], '', $cache));
- log_message('debug', "Cache file is current. Sending it to browser.");
+ $this->_display(str_replace($match[0], '', $cache));
+ log_message('debug', 'Cache file is current. Sending it to browser.');
return TRUE;
}
-
}
-// END Output Class
/* End of file Output.php */
-/* Location: ./system/core/Output.php */ \ No newline at end of file
+/* Location: ./system/core/Output.php */
diff --git a/system/core/Router.php b/system/core/Router.php
index 8cad86888..d21319565 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -44,62 +44,55 @@ class CI_Router {
* Config class
*
* @var object
- * @access public
*/
- var $config;
+ public $config;
/**
* List of routes
*
* @var array
- * @access public
*/
- var $routes = array();
+ public $routes = array();
/**
* List of error routes
*
* @var array
- * @access public
*/
- var $error_routes = array();
+ public $error_routes = array();
/**
* Current class name
*
* @var string
- * @access public
*/
- var $class = '';
+ public $class = '';
/**
* Current method name
*
* @var string
- * @access public
*/
- var $method = 'index';
+ public $method = 'index';
/**
* Sub-directory that contains the requested controller class
*
* @var string
- * @access public
*/
- var $directory = '';
+ public $directory = '';
/**
* Default controller (and method if specific)
*
* @var string
- * @access public
*/
- var $default_controller;
+ public $default_controller;
/**
* Constructor
*
* Runs the route mapping function.
*/
- function __construct()
+ public function __construct()
{
$this->config =& load_class('Config', 'core');
$this->uri =& load_class('URI', 'core');
- log_message('debug', "Router Class Initialized");
+ log_message('debug', 'Router Class Initialized');
}
// --------------------------------------------------------------------
@@ -110,12 +103,11 @@ class CI_Router {
* This function determines what should be served based on the URI request,
* as well as any "routes" that have been set in the routing config file.
*
- * @access private
* @return void
*/
- function _set_routing()
+ public function _set_routing()
{
- // Are query strings enabled in the config file? Normally CI doesn't utilize query strings
+ // Are query strings enabled in the config file? Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
$segments = array();
@@ -157,7 +149,7 @@ class CI_Router {
// the URI doesn't correlated to a valid controller.
$this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
- // Were there any query string segments? If so, we'll validate them and bail out since we're done.
+ // Were there any query string segments? If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
{
return $this->_validate_request($segments);
@@ -172,17 +164,10 @@ class CI_Router {
return $this->_set_default_controller();
}
- // Do we need to remove the URL suffix?
- $this->uri->_remove_url_suffix();
-
- // Compile the segments into an array
- $this->uri->_explode_segments();
-
- // Parse any custom routing that may exist
- $this->_parse_routes();
-
- // Re-index the segment array so that it starts with 1 rather than 0
- $this->uri->_reindex_segments();
+ $this->uri->_remove_url_suffix(); // Remove the URL suffix
+ $this->uri->_explode_segments(); // Compile the segments into an array
+ $this->_parse_routes(); // Parse any custom routing that may exist
+ $this->uri->_reindex_segments(); // Re-index the segment array so that it starts with 1 rather than 0
}
// --------------------------------------------------------------------
@@ -190,20 +175,18 @@ class CI_Router {
/**
* Set the default controller
*
- * @access private
* @return void
*/
- function _set_default_controller()
+ protected function _set_default_controller()
{
if ($this->default_controller === FALSE)
{
- show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
+ show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
// Is the method being specified?
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
-
$this->set_class($x[0]);
$this->set_method($x[1]);
$this->_set_request($x);
@@ -218,7 +201,7 @@ class CI_Router {
// re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();
- log_message('debug', "No URI present. Default controller set.");
+ log_message('debug', 'No URI present. Default controller set.');
}
// --------------------------------------------------------------------
@@ -229,16 +212,15 @@ class CI_Router {
* This function takes an array of URI segments as
* input, and sets the current class/method
*
- * @access private
* @param array
* @param bool
* @return void
*/
- function _set_request($segments = array())
+ protected function _set_request($segments = array())
{
$segments = $this->_validate_request($segments);
- if (count($segments) == 0)
+ if (count($segments) === 0)
{
return $this->_set_default_controller();
}
@@ -269,13 +251,12 @@ class CI_Router {
* Validates the supplied segments. Attempts to determine the path to
* the controller.
*
- * @access private
* @param array
* @return array
*/
- function _validate_request($segments)
+ protected function _validate_request($segments)
{
- if (count($segments) == 0)
+ if (count($segments) === 0)
{
return $segments;
}
@@ -301,7 +282,6 @@ class CI_Router {
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
-
$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
@@ -320,7 +300,6 @@ class CI_Router {
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
-
$this->set_class($x[0]);
$this->set_method($x[1]);
}
@@ -344,18 +323,16 @@ class CI_Router {
// If we've gotten this far it means that the URI does not correlate to a valid
- // controller class. We will now see if there is an override
+ // controller class. We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
-
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
-
// Nothing else to do at this point but show a 404
show_404($segments[0]);
}
@@ -369,10 +346,9 @@ class CI_Router {
* the config/routes.php file against the URI to
* determine if the class/method need to be remapped.
*
- * @access private
* @return void
*/
- function _parse_routes()
+ protected function _parse_routes()
{
// Turn the segment array into a URI string
$uri = implode('/', $this->uri->segments);
@@ -387,7 +363,7 @@ class CI_Router {
foreach ($this->routes as $key => $val)
{
// Convert wild-cards to RegEx
- $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
+ $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key);
// Does the RegEx match?
if (preg_match('#^'.$key.'$#', $uri))
@@ -412,11 +388,10 @@ class CI_Router {
/**
* Set the class name
*
- * @access public
* @param string
* @return void
*/
- function set_class($class)
+ public function set_class($class)
{
$this->class = str_replace(array('/', '.'), '', $class);
}
@@ -426,10 +401,9 @@ class CI_Router {
/**
* Fetch the current class
*
- * @access public
* @return string
*/
- function fetch_class()
+ public function fetch_class()
{
return $this->class;
}
@@ -439,11 +413,10 @@ class CI_Router {
/**
* Set the method name
*
- * @access public
* @param string
* @return void
*/
- function set_method($method)
+ public function set_method($method)
{
$this->method = $method;
}
@@ -453,10 +426,9 @@ class CI_Router {
/**
* Fetch the current method
*
- * @access public
* @return string
*/
- function fetch_method()
+ public function fetch_method()
{
if ($this->method == $this->fetch_class())
{
@@ -471,11 +443,10 @@ class CI_Router {
/**
* Set the directory name
*
- * @access public
* @param string
* @return void
*/
- function set_directory($dir)
+ public function set_directory($dir)
{
$this->directory = str_replace(array('/', '.'), '', $dir).'/';
}
@@ -485,10 +456,9 @@ class CI_Router {
/**
* Fetch the sub-directory (if any) that contains the requested controller class
*
- * @access public
* @return string
*/
- function fetch_directory()
+ public function fetch_directory()
{
return $this->directory;
}
@@ -498,11 +468,10 @@ class CI_Router {
/**
* Set the controller overrides
*
- * @access public
* @param array
* @return null
*/
- function _set_overrides($routing)
+ public function _set_overrides($routing)
{
if ( ! is_array($routing))
{
@@ -526,9 +495,7 @@ class CI_Router {
}
}
-
}
-// END Router Class
/* End of file Router.php */
-/* Location: ./system/core/Router.php */ \ No newline at end of file
+/* Location: ./system/core/Router.php */
diff --git a/system/core/Security.php b/system/core/Security.php
index 272a8bf3f..1007f61f4 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -42,7 +42,6 @@ class CI_Security {
* Random Hash for protecting URLs
*
* @var string
- * @access protected
*/
protected $_xss_hash = '';
@@ -50,7 +49,6 @@ class CI_Security {
* Random Hash for Cross Site Request Forgery Protection Cookie
*
* @var string
- * @access protected
*/
protected $_csrf_hash = '';
@@ -59,7 +57,6 @@ class CI_Security {
* Defaults to two hours (in seconds)
*
* @var int
- * @access protected
*/
protected $_csrf_expire = 7200;
@@ -67,7 +64,6 @@ class CI_Security {
* Token name for Cross Site Request Forgery Protection Cookie
*
* @var string
- * @access protected
*/
protected $_csrf_token_name = 'ci_csrf_token';
@@ -75,46 +71,39 @@ class CI_Security {
* Cookie name for Cross Site Request Forgery Protection Cookie
*
* @var string
- * @access protected
*/
- protected $_csrf_cookie_name = 'ci_csrf_token';
+ protected $_csrf_cookie_name = 'ci_csrf_token';
/**
* List of never allowed strings
*
* @var array
- * @access protected
*/
-
protected $_never_allowed_str = array(
- 'document.cookie' => '[removed]',
- 'document.write' => '[removed]',
- '.parentNode' => '[removed]',
- '.innerHTML' => '[removed]',
- 'window.location' => '[removed]',
- '-moz-binding' => '[removed]',
- '<!--' => '&lt;!--',
- '-->' => '--&gt;',
- '<![CDATA[' => '&lt;![CDATA[',
- '<comment>' => '&lt;comment&gt;'
- );
+ 'document.cookie' => '[removed]',
+ 'document.write' => '[removed]',
+ '.parentNode' => '[removed]',
+ '.innerHTML' => '[removed]',
+ 'window.location' => '[removed]',
+ '-moz-binding' => '[removed]',
+ '<!--' => '&lt;!--',
+ '-->' => '--&gt;',
+ '<![CDATA[' => '&lt;![CDATA[',
+ '<comment>' => '&lt;comment&gt;'
+ );
/**
* List of never allowed regex replacement
*
* @var array
- * @access protected
*/
protected $_never_allowed_regex = array(
- "javascript\s*:" => '[removed]',
- "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE
- "vbscript\s*:" => '[removed]', // IE, surprise!
- "Redirect\s+302" => '[removed]'
- );
+ 'javascript\s*:',
+ 'expression\s*(\(|&\#40;)', // CSS and IE
+ 'vbscript\s*:', // IE, surprise!
+ 'Redirect\s+302'
+ );
- /**
- * Constructor
- */
public function __construct()
{
// CSRF config
@@ -135,7 +124,7 @@ class CI_Security {
// Set the CSRF hash
$this->_csrf_set_hash();
- log_message('debug', "Security Class Initialized");
+ log_message('debug', 'Security Class Initialized');
}
// --------------------------------------------------------------------
@@ -148,7 +137,7 @@ class CI_Security {
public function csrf_verify()
{
// If no POST data exists we will set the CSRF cookie
- if (count($_POST) == 0)
+ if (count($_POST) === 0)
{
return $this->csrf_set_cookie();
}
@@ -164,30 +153,27 @@ class CI_Security {
}
// Do the tokens exist in both the _POST and _COOKIE arrays?
- if ( ! isset($_POST[$this->_csrf_token_name]) OR
- ! isset($_COOKIE[$this->_csrf_cookie_name]))
+ if ( ! isset($_POST[$this->_csrf_token_name]) OR ! isset($_COOKIE[$this->_csrf_cookie_name])
+ OR $_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) // Do the tokens match?
{
$this->csrf_show_error();
}
- // Do the tokens match?
- if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name])
+ // We kill this since we're done and we don't want to polute the _POST array
+ unset($_POST[$this->_csrf_token_name]);
+
+ // Regenerate on every submission?
+ if (config_item('csrf_regenerate'))
{
- $this->csrf_show_error();
+ // Nothing should last forever
+ unset($_COOKIE[$this->_csrf_cookie_name]);
+ $this->_csrf_hash = '';
}
- // We kill this since we're done and we don't want to
- // polute the _POST array
- unset($_POST[$this->_csrf_token_name]);
-
- // Nothing should last forever
- unset($_COOKIE[$this->_csrf_cookie_name]);
- $this->_csrf_hash = '';
$this->_csrf_set_hash();
$this->csrf_set_cookie();
- log_message('debug', "CSRF token verified");
-
+ log_message('debug', 'CSRF token verified');
return $this;
}
@@ -203,19 +189,13 @@ class CI_Security {
$expire = time() + $this->_csrf_expire;
$secure_cookie = (bool) config_item('cookie_secure');
- if ($secure_cookie)
+ if ($secure_cookie && ( ! isset($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] == 'off' OR ! $_SERVER['HTTPS']))
{
- $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE;
-
- if ( ! $req OR $req == 'off')
- {
- return FALSE;
- }
+ return FALSE;
}
setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie);
-
- log_message('debug', "CRSF cookie Set");
+ log_message('debug', 'CRSF cookie Set');
return $this;
}
@@ -253,7 +233,7 @@ class CI_Security {
*
* Getter Method
*
- * @return string self::csrf_token_name
+ * @return string self::_csrf_token_name
*/
public function get_csrf_token_name()
{
@@ -273,7 +253,7 @@ class CI_Security {
* the filter.
*
* Note: This function should only be used to deal with data
- * upon submission. It's not something that should
+ * upon submission. It's not something that should
* be used for general runtime processing.
*
* This function was based in part on some code and ideas I
@@ -290,10 +270,7 @@ class CI_Security {
*/
public function xss_clean($str, $is_image = FALSE)
{
- /*
- * Is the string an array?
- *
- */
+ // Is the string an array?
if (is_array($str))
{
while (list($key) = each($str))
@@ -304,13 +281,8 @@ class CI_Security {
return $str;
}
- /*
- * Remove Invisible Characters
- */
- $str = remove_invisible_characters($str);
-
- // Validate Entities in URLs
- $str = $this->_validate_entities($str);
+ // Remove Invisible Characters and validate entities in URLs
+ $str = $this->_validate_entities(remove_invisible_characters($str));
/*
* URL Decode
@@ -320,7 +292,6 @@ class CI_Security {
* <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
*
* Note: Use rawurldecode() so it does not remove plus signs
- *
*/
$str = rawurldecode($str);
@@ -330,16 +301,11 @@ class CI_Security {
* This permits our tests below to work reliably.
* We only convert entities that are within tags since
* these are the ones that will pose security problems.
- *
*/
-
$str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
+ $str = preg_replace_callback('/<\w+.*?(?=>|<|$)/si', array($this, '_decode_entity'), $str);
- $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str);
-
- /*
- * Remove Invisible Characters Again!
- */
+ // Remove Invisible Characters Again!
$str = remove_invisible_characters($str);
/*
@@ -350,15 +316,9 @@ class CI_Security {
* NOTE: preg_replace was found to be amazingly slow here on
* large blocks of data, so we use str_replace.
*/
+ $str = str_replace("\t", ' ', $str);
- if (strpos($str, "\t") !== FALSE)
- {
- $str = str_replace("\t", ' ', $str);
- }
-
- /*
- * Capture converted string for later comparison
- */
+ // Capture converted string for later comparison
$converted_string = $str;
// Remove Strings that are never allowed
@@ -378,7 +338,7 @@ class CI_Security {
// Images have a tendency to have the PHP short opening and
// closing tags every so often so we skip those and only
// do the long opening tags.
- $str = preg_replace('/<\?(php)/i', "&lt;?\\1", $str);
+ $str = preg_replace('/<\?(php)/i', '&lt;?\\1', $str);
}
else
{
@@ -415,19 +375,19 @@ class CI_Security {
{
$original = $str;
- if (preg_match("/<a/i", $str))
+ if (preg_match('/<a/i', $str))
{
- $str = preg_replace_callback("#<a\s+([^>]*?)(>|$)#si", array($this, '_js_link_removal'), $str);
+ $str = preg_replace_callback('#<a\s+([^>]*?)(>|$)#si', array($this, '_js_link_removal'), $str);
}
- if (preg_match("/<img/i", $str))
+ if (preg_match('/<img/i', $str))
{
- $str = preg_replace_callback("#<img\s+([^>]*?)(\s?/?>|$)#si", array($this, '_js_img_removal'), $str);
+ $str = preg_replace_callback('#<img\s+([^>]*?)(\s?/?>|$)#si', array($this, '_js_img_removal'), $str);
}
- if (preg_match("/script/i", $str) OR preg_match("/xss/i", $str))
+ if (preg_match('/(script|xss)/i', $str))
{
- $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str);
+ $str = preg_replace('#<(/*)(script|xss)(.*?)\>#si', '[removed]', $str);
}
}
while($original != $str);
@@ -454,14 +414,16 @@ class CI_Security {
*
* Similar to above, only instead of looking for
* tags it looks for PHP and JavaScript commands
- * that are disallowed. Rather than removing the
+ * that are disallowed. Rather than removing the
* code, it simply converts the parenthesis to entities
* rendering the code un-executable.
*
* For example: eval('some code')
- * Becomes: eval&#40;'some code'&#41;
+ * Becomes: eval&#40;'some code'&#41;
*/
- $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2&#40;\\3&#41;", $str);
+ $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si',
+ '\\1\\2&#40;\\3&#41;',
+ $str);
// Final clean up
@@ -478,13 +440,12 @@ class CI_Security {
* string post-removal of XSS, then it fails, as there was unwanted XSS
* code found and removed/changed during processing.
*/
-
if ($is_image === TRUE)
{
- return ($str === $converted_string) ? TRUE : FALSE;
+ return ($str === $converted_string);
}
- log_message('debug', "XSS Filtering completed");
+ log_message('debug', 'XSS Filtering completed');
return $str;
}
@@ -516,7 +477,7 @@ class CI_Security {
* The reason we are not using html_entity_decode() by itself is because
* while it is not technically correct to leave out the semicolon
* at the end of an entity most browsers will still interpret the entity
- * correctly. html_entity_decode() does not convert entities without
+ * correctly. html_entity_decode() does not convert entities without
* semicolons, so we are left with our own little solution here. Bummer.
*
* @param string
@@ -552,38 +513,23 @@ class CI_Security {
public function sanitize_filename($str, $relative_path = FALSE)
{
$bad = array(
- "../",
- "<!--",
- "-->",
- "<",
- ">",
- "'",
- '"',
- '&',
- '$',
- '#',
- '{',
- '}',
- '[',
- ']',
- '=',
- ';',
- '?',
- "%20",
- "%22",
- "%3c", // <
- "%253c", // <
- "%3e", // >
- "%0e", // >
- "%28", // (
- "%29", // )
- "%2528", // (
- "%26", // &
- "%24", // $
- "%3f", // ?
- "%3b", // ;
- "%3d" // =
- );
+ '../', '<!--', '-->', '<', '>',
+ "'", '"', '&', '$', '#',
+ '{', '}', '[', ']', '=',
+ ';', '?', '%20', '%22',
+ '%3c', // <
+ '%253c', // <
+ '%3e', // >
+ '%0e', // >
+ '%28', // (
+ '%29', // )
+ '%2528', // (
+ '%26', // &
+ '%24', // $
+ '%3f', // ?
+ '%3b', // ;
+ '%3d' // =
+ );
if ( ! $relative_path)
{
@@ -636,26 +582,26 @@ class CI_Security {
if ($is_image === TRUE)
{
/*
- * Adobe Photoshop puts XML metadata into JFIF images,
+ * Adobe Photoshop puts XML metadata into JFIF images,
* including namespacing, so we have to allow this for images.
*/
unset($evil_attributes[array_search('xmlns', $evil_attributes)]);
}
-
+
do {
$count = 0;
$attribs = array();
-
+
// find occurrences of illegal attribute strings without quotes
- preg_match_all("/(".implode('|', $evil_attributes).")\s*=\s*([^\s]*)/is", $str, $matches, PREG_SET_ORDER);
-
+ preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*([^\s]*)/is', $str, $matches, PREG_SET_ORDER);
+
foreach ($matches as $attr)
{
$attribs[] = preg_quote($attr[0], '/');
}
-
+
// find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes)
- preg_match_all("/(".implode('|', $evil_attributes).")\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is", $str, $matches, PREG_SET_ORDER);
+ preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
@@ -665,11 +611,11 @@ class CI_Security {
// replace illegal attribute strings that are inside an html tag
if (count($attribs) > 0)
{
- $str = preg_replace("/<(\/?[^><]+?)([^A-Za-z\-])(".implode('|', $attribs).")([\s><])([><]*)/i", '<$1$2$4$5', $str, -1, $count);
+ $str = preg_replace('/<(\/?[^><]+?)([^A-Za-z\-])('.implode('|', $attribs).')([\s><])([><]*)/i', '<$1$2$4$5', $str, -1, $count);
}
-
+
} while ($count);
-
+
return $str;
}
@@ -685,14 +631,9 @@ class CI_Security {
*/
protected function _sanitize_naughty_html($matches)
{
- // encode opening brace
- $str = '&lt;'.$matches[1].$matches[2].$matches[3];
-
- // encode captured opening or closing brace to prevent recursive vectors
- $str .= str_replace(array('>', '<'), array('&gt;', '&lt;'),
- $matches[4]);
-
- return $str;
+ return '&lt;'.$matches[1].$matches[2].$matches[3] // encode opening brace
+ // encode captured opening or closing brace to prevent recursive vectors:
+ . str_replace(array('>', '<'), array('&gt;', '&lt;'), $matches[4]);
}
// --------------------------------------------------------------------
@@ -710,9 +651,12 @@ class CI_Security {
*/
protected function _js_link_removal($match)
{
- $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
-
- return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
+ return str_replace($match[1],
+ preg_replace('#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
+ '',
+ $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
+ ),
+ $match[0]);
}
// --------------------------------------------------------------------
@@ -730,9 +674,12 @@ class CI_Security {
*/
protected function _js_img_removal($match)
{
- $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
-
- return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
+ return str_replace($match[1],
+ preg_replace('#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
+ '',
+ $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
+ ),
+ $match[0]);
}
// --------------------------------------------------------------------
@@ -763,12 +710,11 @@ class CI_Security {
protected function _filter_attributes($str)
{
$out = '';
-
if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches))
{
foreach ($matches[0] as $match)
{
- $out .= preg_replace("#/\*.*?\*/#s", '', $match);
+ $out .= preg_replace('#/\*.*?\*/#s', '', $match);
}
}
@@ -806,33 +752,28 @@ class CI_Security {
* Protect GET variables in URLs
*/
- // 901119URL5918AMP18930PROTECT8198
-
- $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str);
+ // 901119URL5918AMP18930PROTECT8198
+ $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash().'\\1=\\2', $str);
/*
* Validate standard character entities
*
* Add a semicolon if missing. We do this to enable
* the conversion of entities to ASCII later.
- *
*/
- $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str);
+ $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', '\\1;\\2', $str);
/*
* Validate UTF16 two byte encoding (x00)
*
* Just as above, adds a semicolon if missing.
- *
*/
- $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str);
+ $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i', '\\1\\2;', $str);
/*
* Un-Protect GET variables in URLs
*/
- $str = str_replace($this->xss_hash(), '&', $str);
-
- return $str;
+ return str_replace($this->xss_hash(), '&', $str);
}
// ----------------------------------------------------------------------
@@ -847,14 +788,11 @@ class CI_Security {
*/
protected function _do_never_allowed($str)
{
- foreach ($this->_never_allowed_str as $key => $val)
- {
- $str = str_replace($key, $val, $str);
- }
+ $str = str_replace(array_keys($this->_never_allowed_str), $this->_never_allowed_str, $str);
- foreach ($this->_never_allowed_regex as $key => $val)
+ foreach ($this->_never_allowed_regex as $regex)
{
- $str = preg_replace("#".$key."#i", $val, $str);
+ $str = preg_replace('#'.$regex.'#i', '[removed]', $str);
}
return $str;
@@ -891,4 +829,4 @@ class CI_Security {
}
/* End of file Security.php */
-/* Location: ./system/core/Security.php */ \ No newline at end of file
+/* Location: ./system/core/Security.php */
diff --git a/system/core/URI.php b/system/core/URI.php
index 3c26d307b..b28ee198b 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -44,62 +44,56 @@ class CI_URI {
* List of cached uri segments
*
* @var array
- * @access public
*/
- var $keyval = array();
+ public $keyval = array();
/**
* Current uri string
*
* @var string
- * @access public
*/
- var $uri_string;
+ public $uri_string;
/**
* List of uri segments
*
* @var array
- * @access public
*/
- var $segments = array();
+ public $segments = array();
/**
* Re-indexed list of uri segments
* Starts at 1 instead of 0
*
* @var array
- * @access public
*/
- var $rsegments = array();
+ public $rsegments = array();
/**
* Constructor
*
- * Simply globalizes the $RTR object. The front
+ * Simply globalizes the $RTR object. The front
* loads the Router class early on so it's not available
* normally as other classes are.
- *
- * @access public
*/
- function __construct()
+ public function __construct()
{
$this->config =& load_class('Config', 'core');
- log_message('debug', "URI Class Initialized");
+ log_message('debug', 'URI Class Initialized');
}
-
// --------------------------------------------------------------------
/**
* Get the URI String
*
- * @access private
- * @return string
+ * Called by CI_Router
+ *
+ * @return void
*/
- function _fetch_uri_string()
+ public function _fetch_uri_string()
{
- if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
+ if (strtoupper($this->config->item('uri_protocol')) === 'AUTO')
{
// Is the request coming from the command line?
- if (php_sapi_name() == 'cli' or defined('STDIN'))
+ if (php_sapi_name() === 'cli' OR defined('STDIN'))
{
$this->_set_uri_string($this->_parse_cli_args());
return;
@@ -115,14 +109,14 @@ class CI_URI {
// Is there a PATH_INFO variable?
// Note: some servers seem to have trouble with getenv() so we'll test it two ways
$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
- if (trim($path, '/') != '' && $path != "/".SELF)
+ if (trim($path, '/') != '' && $path !== '/'.SELF)
{
$this->_set_uri_string($path);
return;
}
// No PATH_INFO?... What about QUERY_STRING?
- $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+ $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') != '')
{
$this->_set_uri_string($path);
@@ -130,7 +124,7 @@ class CI_URI {
}
// As a last ditch effort lets try using the $_GET array
- if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
+ if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '')
{
$this->_set_uri_string(key($_GET));
return;
@@ -143,12 +137,12 @@ class CI_URI {
$uri = strtoupper($this->config->item('uri_protocol'));
- if ($uri == 'REQUEST_URI')
+ if ($uri === 'REQUEST_URI')
{
$this->_set_uri_string($this->_detect_uri());
return;
}
- elseif ($uri == 'CLI')
+ elseif ($uri === 'CLI')
{
$this->_set_uri_string($this->_parse_cli_args());
return;
@@ -163,17 +157,16 @@ class CI_URI {
/**
* Set the URI String
*
- * @access public
* @param string
- * @return string
+ * @return void
*/
- function _set_uri_string($str)
+ public function _set_uri_string($str)
{
// Filter out control characters
$str = remove_invisible_characters($str, FALSE);
// If the URI contains only a slash we'll kill it
- $this->uri_string = ($str == '/') ? '' : $str;
+ $this->uri_string = ($str === '/') ? '' : $str;
}
// --------------------------------------------------------------------
@@ -184,7 +177,6 @@ class CI_URI {
* This function will detect the URI automatically and fix the query string
* if necessary.
*
- * @access private
* @return string
*/
protected function _detect_uri()
@@ -223,7 +215,7 @@ class CI_URI {
$_GET = array();
}
- if ($uri == '/' || empty($uri))
+ if ($uri == '/' OR empty($uri))
{
return '/';
}
@@ -241,13 +233,11 @@ class CI_URI {
*
* Take each command line argument and assume it is a URI segment.
*
- * @access private
* @return string
*/
protected function _parse_cli_args()
{
$args = array_slice($_SERVER['argv'], 1);
-
return $args ? '/' . implode('/', $args) : '';
}
@@ -256,27 +246,28 @@ class CI_URI {
/**
* Filter segments for malicious characters
*
- * @access private
+ * Called by CI_Router
+ *
* @param string
* @return string
*/
- function _filter_uri($str)
+ public function _filter_uri($str)
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
- if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
+ if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
}
- // Convert programatic characters to entities
- $bad = array('$', '(', ')', '%28', '%29');
- $good = array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;');
-
- return str_replace($bad, $good, $str);
+ // Convert programatic characters to entities and return
+ return str_replace(
+ array('$', '(', ')', '%28', '%29'), // Bad
+ array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;'), // Good
+ $str);
}
// --------------------------------------------------------------------
@@ -284,14 +275,15 @@ class CI_URI {
/**
* Remove the suffix from the URL if needed
*
- * @access private
+ * Called by CI_Router
+ *
* @return void
*/
- function _remove_url_suffix()
+ public function _remove_url_suffix()
{
- if ($this->config->item('url_suffix') != "")
+ if ($this->config->item('url_suffix') != '')
{
- $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
+ $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string);
}
}
@@ -301,12 +293,13 @@ class CI_URI {
* Explode the URI Segments. The individual segments will
* be stored in the $this->segments array.
*
- * @access private
+ * Called by CI_Router
+ *
* @return void
*/
- function _explode_segments()
+ public function _explode_segments()
{
- foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
+ foreach (explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $this->uri_string)) as $val)
{
// Filter segments for security
$val = trim($this->_filter_uri($val));
@@ -323,14 +316,15 @@ class CI_URI {
* Re-index Segments
*
* This function re-indexes the $this->segment array so that it
- * starts at 1 rather than 0. Doing so makes it simpler to
+ * starts at 1 rather than 0. Doing so makes it simpler to
* use functions like $this->uri->segment(n) since there is
* a 1:1 relationship between the segment array and the actual segments.
*
- * @access private
+ * Called by CI_Router
+ *
* @return void
*/
- function _reindex_segments()
+ public function _reindex_segments()
{
array_unshift($this->segments, NULL);
array_unshift($this->rsegments, NULL);
@@ -345,12 +339,11 @@ class CI_URI {
*
* This function returns the URI segment based on the number provided.
*
- * @access public
* @param integer
* @param bool
* @return string
*/
- function segment($n, $no_result = FALSE)
+ public function segment($n, $no_result = FALSE)
{
return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
}
@@ -364,12 +357,11 @@ class CI_URI {
* based on the number provided. If there is no routing this function returns the
* same result as $this->segment()
*
- * @access public
* @param integer
* @param bool
* @return string
*/
- function rsegment($n, $no_result = FALSE)
+ public function rsegment($n, $no_result = FALSE)
{
return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
}
@@ -392,25 +384,22 @@ class CI_URI {
* gender => male
* )
*
- * @access public
* @param integer the starting segment number
* @param array an array of default values
* @return array
*/
- function uri_to_assoc($n = 3, $default = array())
+ public function uri_to_assoc($n = 3, $default = array())
{
return $this->_uri_to_assoc($n, $default, 'segment');
}
/**
* Identical to above only it uses the re-routed segment array
*
- * @access public
* @param integer the starting segment number
* @param array an array of default values
* @return array
- *
*/
- function ruri_to_assoc($n = 3, $default = array())
+ public function ruri_to_assoc($n = 3, $default = array())
{
return $this->_uri_to_assoc($n, $default, 'rsegment');
}
@@ -420,25 +409,13 @@ class CI_URI {
/**
* Generate a key value pair from the URI string or Re-routed URI string
*
- * @access private
* @param integer the starting segment number
* @param array an array of default values
* @param string which array we should use
* @return array
*/
- function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
+ protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
{
- if ($which == 'segment')
- {
- $total_segments = 'total_segments';
- $segment_array = 'segment_array';
- }
- else
- {
- $total_segments = 'total_rsegments';
- $segment_array = 'rsegment_array';
- }
-
if ( ! is_numeric($n))
{
return $default;
@@ -449,23 +426,30 @@ class CI_URI {
return $this->keyval[$n];
}
+ if ($which === 'segment')
+ {
+ $total_segments = 'total_segments';
+ $segment_array = 'segment_array';
+ }
+ else
+ {
+ $total_segments = 'total_rsegments';
+ $segment_array = 'rsegment_array';
+ }
+
if ($this->$total_segments() < $n)
{
- if (count($default) == 0)
+ if (count($default) === 0)
{
return array();
}
- $retval = array();
- foreach ($default as $val)
- {
- $retval[$val] = FALSE;
- }
- return $retval;
+ return function_exists('array_fill_keys')
+ ? array_fill_keys($default, FALSE)
+ : array_combine($default, array_fill(0, count($default), FALSE));
}
$segments = array_slice($this->$segment_array(), ($n - 1));
-
$i = 0;
$lastval = '';
$retval = array();
@@ -506,11 +490,10 @@ class CI_URI {
* Generate a URI string from an associative array
*
*
- * @access public
* @param array an associative array of key/values
* @return array
*/
- function assoc_to_uri($array)
+ public function assoc_to_uri($array)
{
$temp = array();
foreach ((array)$array as $key => $val)
@@ -527,12 +510,11 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash
*
- * @access public
* @param integer
* @param string
* @return string
*/
- function slash_segment($n, $where = 'trailing')
+ public function slash_segment($n, $where = 'trailing')
{
return $this->_slash_segment($n, $where, 'segment');
}
@@ -542,12 +524,11 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash
*
- * @access public
* @param integer
* @param string
* @return string
*/
- function slash_rsegment($n, $where = 'trailing')
+ public function slash_rsegment($n, $where = 'trailing')
{
return $this->_slash_segment($n, $where, 'rsegment');
}
@@ -557,22 +538,20 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash - helper function
*
- * @access private
* @param integer
* @param string
* @param string
* @return string
*/
- function _slash_segment($n, $where = 'trailing', $which = 'segment')
+ protected function _slash_segment($n, $where = 'trailing', $which = 'segment')
{
- $leading = '/';
- $trailing = '/';
+ $leading = $trailing = '/';
- if ($where == 'trailing')
+ if ($where === 'trailing')
{
$leading = '';
}
- elseif ($where == 'leading')
+ elseif ($where === 'leading')
{
$trailing = '';
}
@@ -585,10 +564,9 @@ class CI_URI {
/**
* Segment Array
*
- * @access public
* @return array
*/
- function segment_array()
+ public function segment_array()
{
return $this->segments;
}
@@ -598,10 +576,9 @@ class CI_URI {
/**
* Routed Segment Array
*
- * @access public
* @return array
*/
- function rsegment_array()
+ public function rsegment_array()
{
return $this->rsegments;
}
@@ -611,10 +588,9 @@ class CI_URI {
/**
* Total number of segments
*
- * @access public
* @return integer
*/
- function total_segments()
+ public function total_segments()
{
return count($this->segments);
}
@@ -624,10 +600,9 @@ class CI_URI {
/**
* Total number of routed segments
*
- * @access public
* @return integer
*/
- function total_rsegments()
+ public function total_rsegments()
{
return count($this->rsegments);
}
@@ -637,10 +612,9 @@ class CI_URI {
/**
* Fetch the entire URI string
*
- * @access public
* @return string
*/
- function uri_string()
+ public function uri_string()
{
return $this->uri_string;
}
@@ -651,16 +625,14 @@ class CI_URI {
/**
* Fetch the entire Re-routed URI string
*
- * @access public
* @return string
*/
- function ruri_string()
+ public function ruri_string()
{
return '/'.implode('/', $this->rsegment_array());
}
}
-// END URI Class
/* End of file URI.php */
-/* Location: ./system/core/URI.php */ \ No newline at end of file
+/* Location: ./system/core/URI.php */
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index 40a7ac4c0..0e180d36f 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -47,20 +47,19 @@ class CI_Utf8 {
*/
public function __construct()
{
- log_message('debug', "Utf8 Class Initialized");
+ log_message('debug', 'Utf8 Class Initialized');
global $CFG;
if (
@preg_match('/./u', 'é') === 1 // PCRE must support UTF-8
&& function_exists('iconv') // iconv must be installed
- && ini_get('mbstring.func_overload') !== 1 // Multibyte string function overloading cannot be enabled
- && $CFG->item('charset') == 'UTF-8' // Application charset must be UTF-8
+ && @ini_get('mbstring.func_overload') != 1 // Multibyte string function overloading cannot be enabled
+ && $CFG->item('charset') === 'UTF-8' // Application charset must be UTF-8
)
{
- log_message('debug', "UTF-8 Support Enabled");
-
define('UTF8_ENABLED', TRUE);
+ log_message('debug', 'UTF-8 Support Enabled');
// set internal encoding for multibyte string functions if necessary
// and set a flag so we don't have to repeatedly use extension_loaded()
@@ -77,8 +76,8 @@ class CI_Utf8 {
}
else
{
- log_message('debug', "UTF-8 Support Disabled");
define('UTF8_ENABLED', FALSE);
+ log_message('debug', 'UTF-8 Support Disabled');
}
}
@@ -134,18 +133,14 @@ class CI_Utf8 {
{
if (function_exists('iconv'))
{
- $str = @iconv($encoding, 'UTF-8', $str);
+ return @iconv($encoding, 'UTF-8', $str);
}
elseif (function_exists('mb_convert_encoding'))
{
- $str = @mb_convert_encoding($str, 'UTF-8', $encoding);
- }
- else
- {
- return FALSE;
+ return @mb_convert_encoding($str, 'UTF-8', $encoding);
}
- return $str;
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -163,10 +158,7 @@ class CI_Utf8 {
return (preg_match('/[^\x00-\x7F]/S', $str) === 0);
}
- // --------------------------------------------------------------------
-
}
-// End Utf8 Class
/* End of file Utf8.php */
-/* Location: ./system/core/Utf8.php */ \ No newline at end of file
+/* Location: ./system/core/Utf8.php */
diff --git a/system/database/DB.php b/system/database/DB.php
index a0106c133..d06ffb40e 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Initialize the database
*
@@ -42,17 +40,15 @@ function &DB($params = '', $active_record_override = NULL)
if (is_string($params) AND strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+ if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+ AND ! file_exists($file_path = APPPATH.'config/database.php'))
{
- if ( ! file_exists($file_path = APPPATH.'config/database.php'))
- {
- show_error('The configuration file database.php does not exist.');
- }
+ show_error('The configuration file database.php does not exist.');
}
include($file_path);
- if ( ! isset($db) OR count($db) == 0)
+ if ( ! isset($db) OR count($db) === 0)
{
show_error('No database connection settings were found in the database config file.');
}
@@ -78,33 +74,32 @@ function &DB($params = '', $active_record_override = NULL)
* parameter. DSNs must have this prototype:
* $dsn = 'driver://username:password@hostname/database';
*/
-
if (($dns = @parse_url($params)) === FALSE)
{
show_error('Invalid DB Connection String');
}
$params = array(
- 'dbdriver' => $dns['scheme'],
- 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
- 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
- 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
- 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
- );
+ 'dbdriver' => $dns['scheme'],
+ 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
+ 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '',
+ 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
+ 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
+ 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
+ );
// were additional config items set?
if (isset($dns['query']))
{
parse_str($dns['query'], $extra);
-
foreach ($extra as $key => $val)
{
// booleans please
- if (strtoupper($val) == "TRUE")
+ if (strtoupper($val) === 'TRUE')
{
$val = TRUE;
}
- elseif (strtoupper($val) == "FALSE")
+ elseif (strtoupper($val) === 'FALSE')
{
$val = FALSE;
}
@@ -114,17 +109,15 @@ function &DB($params = '', $active_record_override = NULL)
}
}
- // No DB specified yet? Beat them senseless...
+ // No DB specified yet? Beat them senseless...
if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
{
show_error('You have not selected a database type to connect to.');
}
- // Load the DB classes. Note: Since the active record class is optional
+ // Load the DB classes. Note: Since the active record class is optional
// we need to dynamically create a class that extends proper parent class
// based on whether we're using the active record class or not.
- // Kudos to Paul for discovering this clever use of eval()
-
if ($active_record_override !== NULL)
{
$active_record = $active_record_override;
@@ -135,18 +128,14 @@ function &DB($params = '', $active_record_override = NULL)
if ( ! isset($active_record) OR $active_record == TRUE)
{
require_once(BASEPATH.'database/DB_active_rec.php');
-
if ( ! class_exists('CI_DB'))
{
class CI_DB extends CI_DB_active_record { }
}
}
- else
+ elseif ( ! class_exists('CI_DB'))
{
- if ( ! class_exists('CI_DB'))
- {
- class CI_DB extends CI_DB_driver { }
- }
+ class CI_DB extends CI_DB_driver { }
}
require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
@@ -168,7 +157,5 @@ function &DB($params = '', $active_record_override = NULL)
return $DB;
}
-
-
/* End of file DB.php */
-/* Location: ./system/database/DB.php */ \ No newline at end of file
+/* Location: ./system/database/DB.php */
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 486b4d775..eaae23f30 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -43,23 +43,23 @@ class CI_DB_active_record extends CI_DB_driver {
protected $return_delete_sql = FALSE;
protected $reset_delete_data = FALSE;
- protected $ar_select = array();
- protected $ar_distinct = FALSE;
- protected $ar_from = array();
- protected $ar_join = array();
- protected $ar_where = array();
- protected $ar_like = array();
- protected $ar_groupby = array();
- protected $ar_having = array();
- protected $ar_keys = array();
- protected $ar_limit = FALSE;
- protected $ar_offset = FALSE;
- protected $ar_order = FALSE;
- protected $ar_orderby = array();
- protected $ar_set = array();
- protected $ar_wherein = array();
+ protected $ar_select = array();
+ protected $ar_distinct = FALSE;
+ protected $ar_from = array();
+ protected $ar_join = array();
+ protected $ar_where = array();
+ protected $ar_like = array();
+ protected $ar_groupby = array();
+ protected $ar_having = array();
+ protected $ar_keys = array();
+ protected $ar_limit = FALSE;
+ protected $ar_offset = FALSE;
+ protected $ar_order = FALSE;
+ protected $ar_orderby = array();
+ protected $ar_set = array();
+ protected $ar_wherein = array();
protected $ar_aliased_tables = array();
- protected $ar_store_array = array();
+ protected $ar_store_array = array();
protected $ar_where_group_started = FALSE;
protected $ar_where_group_count = 0;
@@ -77,9 +77,7 @@ class CI_DB_active_record extends CI_DB_driver {
protected $ar_cache_set = array();
protected $ar_no_escape = array();
- protected $ar_cache_no_escape = array();
-
- // --------------------------------------------------------------------
+ protected $ar_cache_no_escape = array();
/**
* Select
@@ -113,6 +111,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
}
+
return $this;
}
@@ -188,7 +187,7 @@ class CI_DB_active_record extends CI_DB_driver {
* select_max()
* select_min()
* select_avg()
- * select_sum()
+ * select_sum()
*
* @param string the field
* @param string an alias
@@ -214,7 +213,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
-
$this->ar_select[] = $sql;
if ($this->ar_caching === TRUE)
@@ -238,7 +236,8 @@ class CI_DB_active_record extends CI_DB_driver {
{
if (strpos($item, '.') !== FALSE)
{
- return end(explode('.', $item));
+ $item = explode('.', $item);
+ return end($item);
}
return $item;
@@ -280,30 +279,27 @@ class CI_DB_active_record extends CI_DB_driver {
{
$v = trim($v);
$this->_track_aliases($v);
-
- $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $this->ar_cache_from[] = $v;
$this->ar_cache_exists[] = 'from';
}
}
-
}
else
{
$val = trim($val);
- // Extract any aliases that might exist. We use this information
+ // Extract any aliases that might exist. We use this information
// in the _protect_identifiers to know whether to add a table prefix
$this->_track_aliases($val);
-
- $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_cache_from[] = $val;
$this->ar_cache_exists[] = 'from';
}
}
@@ -340,23 +336,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // Extract any aliases that might exist. We use this information
+ // Extract any aliases that might exist. We use this information
// in the _protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
// Strip apart the condition and protect the identifiers
if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
{
- $match[1] = $this->_protect_identifiers($match[1]);
- $match[3] = $this->_protect_identifiers($match[3]);
-
- $cond = $match[1].$match[2].$match[3];
+ $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
}
// Assemble the JOIN statement
- $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
- $this->ar_join[] = $join;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_join[] = $join;
@@ -429,7 +421,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
+ $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -442,7 +434,6 @@ class CI_DB_active_record extends CI_DB_driver {
if ($escape === TRUE)
{
$k = $this->_protect_identifiers($k, FALSE, $escape);
-
$v = ' '.$this->escape($v);
}
@@ -457,7 +448,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$this->ar_where[] = $prefix.$k.$v;
-
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $prefix.$k.$v;
@@ -571,11 +561,9 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_wherein[] = $this->escape($value);
}
- $prefix = (count($this->ar_where) == 0) ? '' : $type;
-
- $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
+ $prefix = (count($this->ar_where) === 0) ? '' : $type;
+ $this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
- $this->ar_where[] = $where_in;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $where_in;
@@ -679,20 +667,18 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($field as $k => $v)
{
$k = $this->_protect_identifiers($k);
-
- $prefix = (count($this->ar_like) == 0) ? '' : $type;
-
+ $prefix = (count($this->ar_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
- if ($side == 'none')
+ if ($side === 'none')
{
$like_statement = $prefix." $k $not LIKE '{$v}'";
}
- elseif ($side == 'before')
+ elseif ($side === 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
- elseif ($side == 'after')
+ elseif ($side === 'after')
{
$like_statement = $prefix." $k $not LIKE '{$v}%'";
}
@@ -715,6 +701,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
+
return $this;
}
@@ -730,13 +717,10 @@ class CI_DB_active_record extends CI_DB_driver {
public function group_start($not = '', $type = 'AND ')
{
$type = $this->_group_get_type($type);
-
$this->ar_where_group_started = TRUE;
+ $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+ $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
- $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
- $value = $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' (';
-
- $this->ar_where[] = $value;
if ($this->ar_caching)
{
$this->ar_cache_where[] = $value;
@@ -790,16 +774,14 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function group_end()
{
- $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
+ $this->ar_where_group_started = FALSE;
+ $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
- $this->ar_where[] = $value;
if ($this->ar_caching)
{
$this->ar_cache_where[] = $value;
}
- $this->ar_where_group_started = FALSE;
-
return $this;
}
@@ -845,15 +827,16 @@ class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_groupby[] = $val = $this->_protect_identifiers($val);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_cache_groupby[] = $val;
$this->ar_cache_exists[] = 'groupby';
}
}
}
+
return $this;
}
@@ -909,7 +892,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_having) == 0) ? '' : $type;
+ $prefix = (count($this->ar_having) === 0) ? '' : $type;
if ($escape === TRUE)
{
@@ -949,7 +932,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function order_by($orderby, $direction = '', $escape = TRUE)
{
- if (strtolower($direction) == 'random')
+ if (strtolower($direction) === 'random')
{
$orderby = ''; // Random results want or don't need a field name
$direction = $this->_random_keyword;
@@ -960,7 +943,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
- if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE))
+ if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
{
$temp = array();
foreach (explode(',', $orderby) as $part)
@@ -976,7 +959,7 @@ class CI_DB_active_record extends CI_DB_driver {
$orderby = implode(', ', $temp);
}
- else if ($direction != $this->_random_keyword)
+ elseif ($direction != $this->_random_keyword)
{
if ($escape === TRUE)
{
@@ -984,9 +967,8 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- $orderby_statement = $orderby.$direction;
+ $this->ar_orderby[] = $orderby_statement = $orderby.$direction;
- $this->ar_orderby[] = $orderby_statement;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_orderby[] = $orderby_statement;
@@ -1121,9 +1103,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1145,20 +1125,17 @@ class CI_DB_active_record extends CI_DB_driver {
$this->from($table);
}
- $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
-
- $query = $this->query($sql);
+ $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
$this->_reset_select();
- if ($query->num_rows() == 0)
+ if ($result->num_rows() === 0)
{
return 0;
}
- $row = $query->row();
+ $row = $result->row();
return (int) $row->numrows;
}
-
// --------------------------------------------------------------------
/**
@@ -1188,9 +1165,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1213,11 +1188,11 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_insert_batch($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
if ($this->db_debug)
{
- //No valid data array. Folds in cases where keys and values did not match up
+ // No valid data array. Folds in cases where keys and values did not match up
return $this->display_error('db_must_use_set');
}
return FALSE;
@@ -1227,30 +1202,19 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
-
- $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
-
- //echo $sql;
-
- $this->query($sql);
+ $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
}
$this->_reset_write();
-
-
return TRUE;
}
@@ -1294,7 +1258,6 @@ class CI_DB_active_record extends CI_DB_driver {
else
{
$clean = array();
-
foreach ($row as $value)
{
$clean[] = $this->escape($value);
@@ -1398,24 +1361,16 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _validate_insert($table = '')
{
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
@@ -1444,31 +1399,22 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
$sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1543,7 +1489,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1559,34 +1504,28 @@ class CI_DB_active_record extends CI_DB_driver {
*
* @access public
* @param string the table to update data on
- * @return string
+ * @return bool
*/
protected function _validate_update($table = '')
{
if (count($this->ar_set) == 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
$this->ar_from[0] = $table;
}
+
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1599,7 +1538,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param string the table to retrieve the results from
* @param array an associative array of update values
* @param string the where key
- * @return object
+ * @return bool
*/
public function update_batch($table = '', $set = NULL, $index = NULL)
{
@@ -1608,12 +1547,7 @@ class CI_DB_active_record extends CI_DB_driver {
if (is_null($index))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_index');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
if ( ! is_null($set))
@@ -1621,39 +1555,29 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_update_batch($set, $index);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
- $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
-
- $this->query($sql);
+ $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
}
$this->_reset_write();
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1679,7 +1603,6 @@ class CI_DB_active_record extends CI_DB_driver {
{
$index_set = FALSE;
$clean = array();
-
foreach ($v as $k2 => $v2)
{
if ($k2 == $index)
@@ -1691,14 +1614,7 @@ class CI_DB_active_record extends CI_DB_driver {
$not[] = $k.'-'.$v;
}
- if ($escape === FALSE)
- {
- $clean[$this->_protect_identifiers($k2)] = $v2;
- }
- else
- {
- $clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
- }
+ $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
if ($index_set == FALSE)
@@ -1728,11 +1644,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1743,9 +1655,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_delete($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
@@ -1767,11 +1677,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1782,9 +1688,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_truncate($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
@@ -1830,11 +1734,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1864,29 +1764,18 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit);
}
- if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
+ if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_del_must_use_where');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
}
$sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
-
if ($reset_data)
{
$this->_reset_write();
}
- if ($this->return_delete_sql === true)
- {
- return $sql;
- }
-
- return $this->query($sql);
+ return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
}
// --------------------------------------------------------------------
@@ -1953,13 +1842,13 @@ class CI_DB_active_record extends CI_DB_driver {
}
// if a table alias is used we can recognize it by a space
- if (strpos($table, " ") !== FALSE)
+ if (strpos($table, ' ') !== FALSE)
{
// if the alias is written with the AS keyword, remove it
$table = preg_replace('/ AS /i', ' ', $table);
// Grab the alias
- $table = trim(strrchr($table, " "));
+ $table = trim(strrchr($table, ' '));
// Store the alias, if it doesn't already exist
if ( ! in_array($table, $this->ar_aliased_tables))
@@ -1984,10 +1873,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Combine any cached components with the current statements
$this->_merge_cache();
- // ----------------------------------------------------------------
-
// Write the "select" portion of the query
-
if ($select_override !== FALSE)
{
$sql = $select_override;
@@ -1996,7 +1882,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
- if (count($this->ar_select) == 0)
+ if (count($this->ar_select) === 0)
{
$sql .= '*';
}
@@ -2015,32 +1901,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // ----------------------------------------------------------------
-
// Write the "FROM" portion of the query
-
if (count($this->ar_from) > 0)
{
- $sql .= "\nFROM ";
-
- $sql .= $this->_from_tables($this->ar_from);
+ $sql .= "\nFROM ".$this->_from_tables($this->ar_from);
}
- // ----------------------------------------------------------------
-
// Write the "JOIN" portion of the query
-
if (count($this->ar_join) > 0)
{
- $sql .= "\n";
-
- $sql .= implode("\n", $this->ar_join);
+ $sql .= "\n".implode("\n", $this->ar_join);
}
- // ----------------------------------------------------------------
-
// Write the "WHERE" portion of the query
-
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
{
$sql .= "\nWHERE ";
@@ -2048,10 +1921,7 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_where);
- // ----------------------------------------------------------------
-
// Write the "LIKE" portion of the query
-
if (count($this->ar_like) > 0)
{
if (count($this->ar_where) > 0)
@@ -2062,50 +1932,32 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_like);
}
- // ----------------------------------------------------------------
-
// Write the "GROUP BY" portion of the query
-
if (count($this->ar_groupby) > 0)
{
- $sql .= "\nGROUP BY ";
-
- $sql .= implode(', ', $this->ar_groupby);
+ $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
}
- // ----------------------------------------------------------------
-
// Write the "HAVING" portion of the query
-
if (count($this->ar_having) > 0)
{
- $sql .= "\nHAVING ";
- $sql .= implode("\n", $this->ar_having);
+ $sql .= "\nHAVING ".implode("\n", $this->ar_having);
}
- // ----------------------------------------------------------------
-
// Write the "ORDER BY" portion of the query
-
if (count($this->ar_orderby) > 0)
{
- $sql .= "\nORDER BY ";
- $sql .= implode(', ', $this->ar_orderby);
-
+ $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
if ($this->ar_order !== FALSE)
{
$sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
}
}
- // ----------------------------------------------------------------
-
// Write the "LIMIT" portion of the query
-
if (is_numeric($this->ar_limit))
{
- $sql .= "\n";
- $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
+ return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
}
return $sql;
@@ -2165,14 +2017,12 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($fields as $val)
{
// There are some built in keys we need to ignore for this conversion
- if ($val != '_parent_name')
+ if ($val !== '_parent_name')
{
-
$i = 0;
foreach ($out[$val] as $data)
{
- $array[$i][$val] = $data;
- $i++;
+ $array[$i++][$val] = $data;
}
}
}
@@ -2247,7 +2097,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _merge_cache()
{
- if (count($this->ar_cache_exists) == 0)
+ if (count($this->ar_cache_exists) === 0)
{
return;
}
@@ -2257,7 +2107,7 @@ class CI_DB_active_record extends CI_DB_driver {
$ar_variable = 'ar_'.$val;
$ar_cache_var = 'ar_cache_'.$val;
- if (count($this->$ar_cache_var) == 0)
+ if (count($this->$ar_cache_var) === 0)
{
continue;
}
@@ -2282,7 +2132,6 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Publicly-visible method to reset the AR values.
*
- * @access public
* @return void
*/
public function reset_query()
@@ -2319,25 +2168,24 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_select()
{
- $ar_reset_items = array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE,
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_select' => array(),
+ 'ar_from' => array(),
+ 'ar_join' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_groupby' => array(),
+ 'ar_having' => array(),
+ 'ar_orderby' => array(),
+ 'ar_wherein' => array(),
+ 'ar_aliased_tables' => array(),
+ 'ar_no_escape' => array(),
+ 'ar_distinct' => FALSE,
+ 'ar_limit' => FALSE,
+ 'ar_offset' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
// --------------------------------------------------------------------
@@ -2351,19 +2199,19 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_write()
{
- $ar_reset_items = array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
+
}
/* End of file DB_active_rec.php */
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 1ff046c21..79651fcb0 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Cache Class
*
@@ -36,19 +34,12 @@
*/
class CI_DB_Cache {
- var $CI;
- var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
+ public $CI;
+ public $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct(&$db)
+ public function __construct(&$db)
{
- // Assign the main CI object to $this->CI
- // and load the file helper since we use it a lot
+ // Assign the main CI object to $this->CI and load the file helper since we use it a lot
$this->CI =& get_instance();
$this->db =& $db;
$this->CI->load->helper('file');
@@ -59,11 +50,10 @@ class CI_DB_Cache {
/**
* Set Cache Directory Path
*
- * @access public
* @param string the path to the cache directory
* @return bool
*/
- function check_path($path = '')
+ public function check_path($path = '')
{
if ($path == '')
{
@@ -76,7 +66,7 @@ class CI_DB_Cache {
}
// Add a trailing slash to the path if needed
- $path = preg_replace("/(.+?)\/*$/", "\\1/", $path);
+ $path = preg_replace('/(.+?)\/*$/', '\\1/', $path);
if ( ! is_dir($path) OR ! is_really_writable($path))
{
@@ -96,10 +86,9 @@ class CI_DB_Cache {
* The URI being requested will become the name of the cache sub-folder.
* An MD5 hash of the SQL statement will become the cache file name
*
- * @access public
* @return string
*/
- function read($sql)
+ public function read($sql)
{
if ( ! $this->check_path())
{
@@ -107,9 +96,7 @@ class CI_DB_Cache {
}
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
if (FALSE === ($cachedata = read_file($filepath)))
@@ -125,10 +112,9 @@ class CI_DB_Cache {
/**
* Write a query to a cache file
*
- * @access public
* @return bool
*/
- function write($sql, $object)
+ public function write($sql, $object)
{
if ( ! $this->check_path())
{
@@ -136,11 +122,8 @@ class CI_DB_Cache {
}
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
$filename = md5($sql);
if ( ! @is_dir($dir_path))
@@ -167,10 +150,9 @@ class CI_DB_Cache {
/**
* Delete cache files within a particular directory
*
- * @access public
* @return bool
*/
- function delete($segment_one = '', $segment_two = '')
+ public function delete($segment_one = '', $segment_two = '')
{
if ($segment_one == '')
{
@@ -183,7 +165,6 @@ class CI_DB_Cache {
}
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
delete_files($dir_path, TRUE);
}
@@ -192,16 +173,14 @@ class CI_DB_Cache {
/**
* Delete all existing cache files
*
- * @access public
* @return bool
*/
- function delete_all()
+ public function delete_all()
{
delete_files($this->db->cachedir, TRUE);
}
}
-
/* End of file DB_cache.php */
-/* Location: ./system/database/DB_cache.php */ \ No newline at end of file
+/* Location: ./system/database/DB_cache.php */
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 661b42ced..5f435e363 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -81,8 +81,7 @@ class CI_DB_driver {
var $stmt_id;
var $curs_id;
var $limit_used;
-
-
+
/**
* Constructor. Accepts one parameter containing the database
@@ -108,11 +107,9 @@ class CI_DB_driver {
/**
* Initialize Database Settings
*
- * @access private Called by the constructor
- * @param mixed
- * @return void
+ * @return bool
*/
- function initialize()
+ public function initialize()
{
// If an existing connection resource is available
// there is no need to connect and select the database
@@ -126,7 +123,7 @@ class CI_DB_driver {
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
- // No connection resource? Check if there is a failover else throw an error
+ // No connection resource? Check if there is a failover else throw an error
if ( ! $this->conn_id)
{
// Check if there is a failover set
@@ -168,31 +165,19 @@ class CI_DB_driver {
// ----------------------------------------------------------------
// Select the DB... assuming a database name is specified in the config file
- if ($this->database != '')
+ if ($this->database !== '' && ! $this->db_select())
{
- if ( ! $this->db_select())
- {
- log_message('error', 'Unable to select database: '.$this->database);
+ log_message('error', 'Unable to select database: '.$this->database);
- if ($this->db_debug)
- {
- $this->display_error('db_unable_to_select', $this->database);
- }
- return FALSE;
- }
- else
+ if ($this->db_debug)
{
- // We've selected the DB. Now we set the character set
- if ( ! $this->db_set_charset($this->char_set, $this->dbcollat))
- {
- return FALSE;
- }
-
- return TRUE;
+ $this->display_error('db_unable_to_select', $this->database);
}
+ return FALSE;
}
- return TRUE;
+ // Now we set the character set and that's all
+ return $this->db_set_charset($this->char_set, $this->dbcollat);
}
// --------------------------------------------------------------------
@@ -200,20 +185,19 @@ class CI_DB_driver {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation = '')
{
- if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat))
+ if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset, $collation))
{
- log_message('error', 'Unable to set database connection charset: '.$this->char_set);
+ log_message('error', 'Unable to set database connection charset: '.$charset);
if ($this->db_debug)
{
- $this->display_error('db_unable_to_set_charset', $this->char_set);
+ $this->display_error('db_unable_to_set_charset', $charset);
}
return FALSE;
@@ -257,7 +241,7 @@ class CI_DB_driver {
// Some DBs have functions that return the version, and don't run special
// SQL queries per se. In these instances, just return the result.
- $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo');
+ $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli');
if (in_array($this->dbdriver, $driver_version_exceptions))
{
@@ -660,17 +644,12 @@ class CI_DB_driver {
/**
* Determines if a query is a "write" type.
*
- * @access public
* @param string An SQL query string
- * @return boolean
+ * @return bool
*/
- function is_write_type($sql)
+ public function is_write_type($sql)
{
- if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
- {
- return FALSE;
- }
- return TRUE;
+ return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE)\s+/i', $sql);
}
// --------------------------------------------------------------------
@@ -814,20 +793,23 @@ class CI_DB_driver {
if ($query->num_rows() > 0)
{
- foreach ($query->result_array() as $row)
+ $table = FALSE;
+ $rows = $query->result_array();
+ $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row))));
+
+ if ($key)
{
- if (isset($row['TABLE_NAME']))
- {
- $retval[] = $row['TABLE_NAME'];
- }
- else
- {
- $retval[] = array_shift($row);
- }
+ $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name';
+ }
+
+ foreach ($rows as $row)
+ {
+ $retval[] = ( ! $table) ? current($row) : $row[$table];
}
}
$this->data_cache['table_names'] = $retval;
+
return $this->data_cache['table_names'];
}
@@ -1436,10 +1418,23 @@ class CI_DB_driver {
return $item.$alias;
}
+
+ // --------------------------------------------------------------------
+ /**
+ * Dummy method that allows Active Record class to be disabled
+ *
+ * This function is used extensively by every db driver.
+ *
+ * @access private
+ * @return void
+ */
+ protected function _reset_select()
+ {
+
+ }
}
-
/* End of file DB_driver.php */
/* Location: ./system/database/DB_driver.php */
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 762d18a46..336e9497d 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -36,23 +36,17 @@
*/
class CI_DB_forge {
- var $fields = array();
- var $keys = array();
- var $primary_keys = array();
- var $db_char_set = '';
+ public $fields = array();
+ public $keys = array();
+ public $primary_keys = array();
+ public $db_char_set = '';
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct()
+ public function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();
$this->db =& $CI->db;
- log_message('debug', "Database Forge Class Initialized");
+ log_message('debug', 'Database Forge Class Initialized');
}
// --------------------------------------------------------------------
@@ -60,20 +54,13 @@ class CI_DB_forge {
/**
* Create database
*
- * @access public
* @param string the database name
* @return bool
*/
- function create_database($db_name)
+ public function create_database($db_name)
{
$sql = $this->_create_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -81,20 +68,13 @@ class CI_DB_forge {
/**
* Drop database
*
- * @access public
* @param string the database name
* @return bool
*/
- function drop_database($db_name)
+ public function drop_database($db_name)
{
$sql = $this->_drop_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -152,7 +132,7 @@ class CI_DB_forge {
if (is_string($field))
{
- if ($field == 'id')
+ if ($field === 'id')
{
$this->add_field(array(
'id' => array(
@@ -178,7 +158,7 @@ class CI_DB_forge {
{
$this->fields = array_merge($this->fields, $field);
}
-
+
return $this;
}
@@ -197,21 +177,14 @@ class CI_DB_forge {
show_error('A table name is required for that operation.');
}
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
-
$this->_reset();
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -225,13 +198,7 @@ class CI_DB_forge {
public function drop_table($table_name)
{
$sql = $this->_drop_table($this->db->dbprefix.$table_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -250,8 +217,7 @@ class CI_DB_forge {
show_error('A table name is required for that operation.');
}
- $sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name);
- return $this->db->query($sql);
+ return $this->db->query($this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name));
}
// --------------------------------------------------------------------
@@ -273,8 +239,7 @@ class CI_DB_forge {
// add field info into field array, but we can only do one at a time
// so we cycle through
-
- foreach ($field as $k => $v)
+ foreach (array_keys($field) as $k)
{
$this->add_field(array($k => $field[$k]));
@@ -284,7 +249,6 @@ class CI_DB_forge {
}
$sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
-
$this->_reset();
if ($this->db->query($sql) === FALSE)
@@ -307,7 +271,6 @@ class CI_DB_forge {
*/
public function drop_column($table = '', $column_name = '')
{
-
if ($table == '')
{
show_error('A table name is required for that operation.');
@@ -318,9 +281,7 @@ class CI_DB_forge {
show_error('A column name is required for that operation.');
}
- $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
-
- return $this->db->query($sql);
+ return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name));
}
// --------------------------------------------------------------------
@@ -342,8 +303,7 @@ class CI_DB_forge {
// add field info into field array, but we can only do one at a time
// so we cycle through
-
- foreach ($field as $k => $v)
+ foreach (array_keys($field) as $k)
{
// If no name provided, use the current name
if ( ! isset($field[$k]['name']))
@@ -352,14 +312,12 @@ class CI_DB_forge {
}
$this->add_field(array($k => $field[$k]));
-
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
$sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
-
$this->_reset();
if ($this->db->query($sql) === FALSE)
@@ -382,12 +340,10 @@ class CI_DB_forge {
*/
protected function _reset()
{
- $this->fields = array();
- $this->keys = array();
- $this->primary_keys = array();
+ $this->fields = $this->keys = $this->primary_keys = array();
}
}
/* End of file DB_forge.php */
-/* Location: ./system/database/DB_forge.php */ \ No newline at end of file
+/* Location: ./system/database/DB_forge.php */
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index c4ed20b76..730443222 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Result Class
*
@@ -40,27 +38,25 @@
*/
class CI_DB_result {
- var $conn_id = NULL;
- var $result_id = NULL;
- var $result_array = array();
- var $result_object = array();
- var $custom_result_object = array();
- var $current_row = 0;
- var $num_rows = 0;
- var $row_data = NULL;
-
+ public $conn_id = NULL;
+ public $result_id = NULL;
+ public $result_array = array();
+ public $result_object = array();
+ public $custom_result_object = array();
+ public $current_row = 0;
+ public $num_rows = 0;
+ public $row_data = NULL;
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @access public
* @param string can be "object" or "array"
* @return mixed either a result object or array
*/
public function result($type = 'object')
{
- if ($type == 'array') return $this->result_array();
- else if ($type == 'object') return $this->result_object();
+ if ($type === 'array') return $this->result_array();
+ elseif ($type === 'object') return $this->result_object();
else return $this->custom_result_object($type);
}
@@ -69,8 +65,8 @@ class CI_DB_result {
/**
* Custom query result.
*
- * @param class_name A string that represents the type of object you want back
- * @return array of objects
+ * @param string A string that represents the type of object you want back
+ * @return array of objects
*/
public function custom_result_object($class_name)
{
@@ -91,7 +87,6 @@ class CI_DB_result {
while ($row = $this->_fetch_object())
{
$object = new $class_name();
-
foreach ($row as $key => $value)
{
$object->$key = $value;
@@ -109,7 +104,6 @@ class CI_DB_result {
/**
* Query result. "object" version.
*
- * @access public
* @return object
*/
public function result_object()
@@ -141,7 +135,6 @@ class CI_DB_result {
/**
* Query result. "array" version.
*
- * @access public
* @return array
*/
public function result_array()
@@ -173,7 +166,6 @@ class CI_DB_result {
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @access public
* @param string
* @param string can be "object" or "array"
* @return mixed either a result object or array
@@ -197,8 +189,8 @@ class CI_DB_result {
$n = 0;
}
- if ($type == 'object') return $this->row_object($n);
- else if ($type == 'array') return $this->row_array($n);
+ if ($type === 'object') return $this->row_object($n);
+ elseif ($type === 'array') return $this->row_array($n);
else return $this->custom_row_object($n, $type);
}
@@ -207,8 +199,7 @@ class CI_DB_result {
/**
* Assigns an item into a particular column slot
*
- * @access public
- * @return object
+ * @return void
*/
public function set_row($key, $value = NULL)
{
@@ -224,7 +215,6 @@ class CI_DB_result {
{
$this->row_data[$k] = $v;
}
-
return;
}
@@ -239,14 +229,12 @@ class CI_DB_result {
/**
* Returns a single result row - custom object version
*
- * @access public
* @return object
*/
public function custom_row_object($n, $type)
{
$result = $this->custom_result_object($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -262,14 +250,12 @@ class CI_DB_result {
/**
* Returns a single result row - object version
*
- * @access public
* @return object
*/
public function row_object($n = 0)
{
$result = $this->result_object();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -287,14 +273,12 @@ class CI_DB_result {
/**
* Returns a single result row - array version
*
- * @access public
* @return array
*/
public function row_array($n = 0)
{
$result = $this->result_array();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -313,18 +297,12 @@ class CI_DB_result {
/**
* Returns the "first" row
*
- * @access public
* @return object
*/
public function first_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
- {
- return $result;
- }
- return $result[0];
+ return (count($result) === 0) ? $result : $result[0];
}
// --------------------------------------------------------------------
@@ -332,18 +310,12 @@ class CI_DB_result {
/**
* Returns the "last" row
*
- * @access public
* @return object
*/
public function last_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
- {
- return $result;
- }
- return $result[count($result) -1];
+ return (count($result) === 0) ? $result : $result[count($result) - 1];
}
// --------------------------------------------------------------------
@@ -351,14 +323,12 @@ class CI_DB_result {
/**
* Returns the "next" row
*
- * @access public
* @return object
*/
public function next_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -376,14 +346,12 @@ class CI_DB_result {
/**
* Returns the "previous" row
*
- * @access public
* @return object
*/
public function previous_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -416,7 +384,6 @@ class CI_DB_result {
protected function _fetch_object() { return array(); }
}
-// END DB_result class
/* End of file DB_result.php */
/* Location: ./system/database/DB_result.php */
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 8db4f3bac..4c881d8a1 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Utility Class
*
@@ -36,22 +34,15 @@
*/
class CI_DB_utility extends CI_DB_forge {
- var $db;
- var $data_cache = array();
+ public $db;
+ public $data_cache = array();
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct()
+ public function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();
$this->db =& $CI->db;
-
- log_message('debug', "Database Utility Class Initialized");
+ log_message('debug', 'Database Utility Class Initialized');
}
// --------------------------------------------------------------------
@@ -59,10 +50,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* List databases
*
- * @access public
* @return bool
*/
- function list_databases()
+ public function list_databases()
{
// Is there a cached result?
if (isset($this->data_cache['db_names']))
@@ -80,8 +70,7 @@ class CI_DB_utility extends CI_DB_forge {
}
}
- $this->data_cache['db_names'] = $dbs;
- return $this->data_cache['db_names'];
+ return $this->data_cache['db_names'] = $dbs;
}
// --------------------------------------------------------------------
@@ -89,11 +78,10 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Determine if a particular database exists
*
- * @access public
* @param string
* @return boolean
*/
- function database_exists($database_name)
+ public function database_exists($database_name)
{
// Some databases won't have access to the list_databases() function, so
// this is intended to allow them to override with their own functions as
@@ -114,17 +102,17 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function optimize_table($table_name)
+ public function optimize_table($table_name)
{
$sql = $this->_optimize_table($table_name);
if (is_bool($sql))
{
- show_error('db_must_use_set');
+ show_error('db_must_use_set');
+ return FALSE;
}
$query = $this->db->query($sql);
@@ -140,10 +128,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Database
*
- * @access public
* @return array
*/
- function optimize_database()
+ public function optimize_database()
{
$result = array();
foreach ($this->db->list_tables() as $table_name)
@@ -177,11 +164,10 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Repair Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function repair_table($table_name)
+ public function repair_table($table_name)
{
$sql = $this->_repair_table($table_name);
@@ -203,14 +189,13 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Generate CSV from a query result object
*
- * @access public
* @param object The query result object
* @param string The delimiter - comma by default
* @param string The newline character - \n by default
* @param string The enclosure - double quote by default
* @return string
*/
- function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"')
+ public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
{
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
{
@@ -218,15 +203,13 @@ class CI_DB_utility extends CI_DB_forge {
}
$out = '';
-
// First generate the headings from the table column names
foreach ($query->list_fields() as $name)
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
}
- $out = rtrim($out);
- $out .= $newline;
+ $out = rtrim($out).$newline;
// Next blast through the result array and build out the rows
foreach ($query->result_array() as $row)
@@ -235,8 +218,7 @@ class CI_DB_utility extends CI_DB_forge {
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
}
- $out = rtrim($out);
- $out .= $newline;
+ $out = rtrim($out).$newline;
}
return $out;
@@ -247,12 +229,11 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Generate XML data from a query result object
*
- * @access public
* @param object The query result object
* @param array Any preferences
* @return string
*/
- function xml_from_result($query, $params = array())
+ public function xml_from_result($query, $params = array())
{
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
{
@@ -280,16 +261,14 @@ class CI_DB_utility extends CI_DB_forge {
foreach ($query->result_array() as $row)
{
$xml .= $tab."<{$element}>".$newline;
-
foreach ($row as $key => $val)
{
$xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline;
}
$xml .= $tab."</{$element}>".$newline;
}
- $xml .= "</$root>".$newline;
- return $xml;
+ return $xml .= "</$root>".$newline;
}
// --------------------------------------------------------------------
@@ -297,10 +276,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Database Backup
*
- * @access public
* @return void
*/
- function backup($params = array())
+ public function backup($params = array())
{
// If the parameters have not been submitted as an
// array then we know that it is simply the table
@@ -314,14 +292,14 @@ class CI_DB_utility extends CI_DB_forge {
// Set up our default preferences
$prefs = array(
- 'tables' => array(),
- 'ignore' => array(),
- 'filename' => '',
- 'format' => 'gzip', // gzip, zip, txt
- 'add_drop' => TRUE,
- 'add_insert' => TRUE,
- 'newline' => "\n"
- );
+ 'tables' => array(),
+ 'ignore' => array(),
+ 'filename' => '',
+ 'format' => 'gzip', // gzip, zip, txt
+ 'add_drop' => TRUE,
+ 'add_insert' => TRUE,
+ 'newline' => "\n"
+ );
// Did the user submit any preferences? If so set them....
if (count($params) > 0)
@@ -335,29 +313,23 @@ class CI_DB_utility extends CI_DB_forge {
}
}
- // ------------------------------------------------------
-
// Are we backing up a complete database or individual tables?
// If no table names were submitted we'll fetch the entire table list
- if (count($prefs['tables']) == 0)
+ if (count($prefs['tables']) === 0)
{
$prefs['tables'] = $this->db->list_tables();
}
- // ------------------------------------------------------
-
// Validate the format
if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
{
$prefs['format'] = 'txt';
}
- // ------------------------------------------------------
-
- // Is the encoder supported? If not, we'll either issue an
+ // Is the encoder supported? If not, we'll either issue an
// error or use plain text depending on the debug settings
- if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode'))
- OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress')))
+ if (($prefs['format'] === 'gzip' AND ! @function_exists('gzencode'))
+ OR ($prefs['format'] === 'zip' AND ! @function_exists('gzcompress')))
{
if ($this->db->db_debug)
{
@@ -367,60 +339,49 @@ class CI_DB_utility extends CI_DB_forge {
$prefs['format'] = 'txt';
}
- // ------------------------------------------------------
-
- // Set the filename if not provided - Only needed with Zip files
- if ($prefs['filename'] == '' AND $prefs['format'] == 'zip')
- {
- $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database;
- $prefs['filename'] .= '_'.date('Y-m-d_H-i', time());
- }
-
- // ------------------------------------------------------
-
- // Was a Gzip file requested?
- if ($prefs['format'] == 'gzip')
- {
- return gzencode($this->_backup($prefs));
- }
-
- // ------------------------------------------------------
-
- // Was a text file requested?
- if ($prefs['format'] == 'txt')
- {
- return $this->_backup($prefs);
- }
-
- // ------------------------------------------------------
-
// Was a Zip file requested?
- if ($prefs['format'] == 'zip')
+ if ($prefs['format'] === 'zip')
{
- // If they included the .zip file extension we'll remove it
- if (preg_match("|.+?\.zip$|", $prefs['filename']))
+ // Set the filename if not provided (only needed with Zip files)
+ if ($prefs['filename'] == '')
{
- $prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+ $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
+ .date('Y-m-d_H-i', time()).'.sql';
}
-
- // Tack on the ".sql" file extension if needed
- if ( ! preg_match("|.+?\.sql$|", $prefs['filename']))
+ else
{
- $prefs['filename'] .= '.sql';
+ // If they included the .zip file extension we'll remove it
+ if (preg_match('|.+?\.zip$|', $prefs['filename']))
+ {
+ $prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+ }
+
+ // Tack on the ".sql" file extension if needed
+ if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
+ {
+ $prefs['filename'] .= '.sql';
+ }
}
// Load the Zip class and output it
-
$CI =& get_instance();
$CI->load->library('zip');
$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
return $CI->zip->get_zip();
}
+ elseif ($prefs['format'] == 'txt') // Was a text file requested?
+ {
+ return $this->_backup($prefs);
+ }
+ elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
+ {
+ return gzencode($this->_backup($prefs));
+ }
+ return;
}
}
-
/* End of file DB_utility.php */
-/* Location: ./system/database/DB_utility.php */ \ No newline at end of file
+/* Location: ./system/database/DB_utility.php */
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index cde719eae..42f08fbf6 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -156,24 +156,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- // In CUBRID, there is no need to set charset or collation.
- // This is why returning true will allow the application continue
- // its normal process.
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
* @access public
@@ -362,12 +344,11 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
- return @cubrid_affected_rows($this->conn_id);
+ return @cubrid_affected_rows();
}
// --------------------------------------------------------------------
@@ -801,4 +782,4 @@ class CI_DB_cubrid_driver extends CI_DB {
/* End of file cubrid_driver.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2a1098932..2a4f2b575 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -114,30 +114,25 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
// Note: The brackets are required in the event that the DB name
// contains reserved characters
- return @mssql_select_db('['.$this->database.']', $this->conn_id);
- }
-
- // --------------------------------------------------------------------
+ if (@mssql_select_db('['.$database.']', $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
- /**
- * 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;
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -676,4 +671,4 @@ class CI_DB_mssql_driver extends CI_DB {
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 0f69a0723..c88a8a766 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Database Adapter Class
*
@@ -42,46 +40,47 @@
*/
class CI_DB_mysql_driver extends CI_DB {
- var $dbdriver = 'mysql';
+ public $dbdriver = 'mysql';
// The character used for escaping
- var $_escape_char = '`';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in MySQL
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
-
- /**
- * Whether to use the MySQL "delete hack" which allows the number
- * of affected rows to be shown. Uses a preg_replace when enabled,
- * adding a bit more processing to all queries.
- */
- var $delete_hack = TRUE;
+ protected $_like_escape_str = '';
+ protected $_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 = ' RAND()'; // database specific random keyword
-
- // whether SET NAMES must be used to set the character set
- var $use_set_names;
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
- * Non-persistent database connection
- *
- * @access private called by the base class
- * @return resource
+ * Whether to use the MySQL "delete hack" which allows the number
+ * of affected rows to be shown. Uses a preg_replace when enabled,
+ * adding a bit more processing to all queries.
*/
- function db_connect()
+ public $delete_hack = TRUE;
+
+ public function __construct($params)
{
+ parent::__construct($params);
+
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}
+ }
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
@@ -90,16 +89,10 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- if ($this->port != '')
- {
- $this->hostname .= ':'.$this->port;
- }
-
return @mysql_pconnect($this->hostname, $this->username, $this->password);
}
@@ -111,10 +104,9 @@ class CI_DB_mysql_driver extends CI_DB {
* 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()
+ public function reconnect()
{
if (mysql_ping($this->conn_id) === FALSE)
{
@@ -127,12 +119,23 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return @mysql_select_db($this->database, $this->conn_id);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysql_select_db($database, $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -140,12 +143,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
return function_exists('mysql_set_charset')
? @mysql_set_charset($charset, $this->conn_id)
@@ -157,12 +159,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return 'SELECT version() AS ver';
}
// --------------------------------------------------------------------
@@ -170,14 +171,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @mysql_query($sql, $this->conn_id);
+ return @mysql_query($this->_prep_query($sql), $this->conn_id);
}
// --------------------------------------------------------------------
@@ -187,20 +186,16 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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)
+ protected function _prep_query($sql)
{
- // "DELETE FROM TABLE" returns 0 affected rows This hack modifies
- // the query so that it returns the number of affected rows
- if ($this->delete_hack === TRUE)
+ // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
+ // modifies the query so that it a proper number of affected rows is returned.
+ if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
{
- if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
- {
- $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
- }
+ return preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql);
}
return $sql;
@@ -211,18 +206,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -230,7 +219,7 @@ class CI_DB_mysql_driver extends CI_DB {
// 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;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
@@ -242,18 +231,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -268,18 +251,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -294,12 +271,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* 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)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -311,7 +287,7 @@ class CI_DB_mysql_driver extends CI_DB {
return $str;
}
- if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id))
+ if (function_exists('mysql_real_escape_string') && is_resource($this->conn_id))
{
$str = mysql_real_escape_string($str, $this->conn_id);
}
@@ -327,7 +303,7 @@ class CI_DB_mysql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -338,10 +314,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mysql_affected_rows($this->conn_id);
}
@@ -351,10 +326,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @mysql_insert_id($this->conn_id);
}
@@ -367,27 +341,25 @@ class CI_DB_mysql_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -397,17 +369,16 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -420,13 +391,12 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ public function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -436,13 +406,12 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ public function _field_data($table)
{
- return "DESCRIBE ".$table;
+ return 'DESCRIBE '.$table;
}
// --------------------------------------------------------------------
@@ -450,10 +419,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return mysql_error($this->conn_id);
}
@@ -463,10 +431,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return mysql_errno($this->conn_id);
}
@@ -478,11 +445,10 @@ class CI_DB_mysql_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -493,24 +459,20 @@ class CI_DB_mysql_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -521,11 +483,10 @@ class CI_DB_mysql_driver extends CI_DB {
* 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
+ * @param string table name
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -542,15 +503,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -561,15 +521,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific replace 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 _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -579,15 +538,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -598,7 +556,6 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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
@@ -606,34 +563,22 @@ class CI_DB_mysql_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
{
foreach ($values as $key => $val)
{
- $valstr[] = $key . ' = ' . $val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- if (count($like) > 0)
+ $where = ($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '';
+ if (count($like) > 0)
{
- $sql .= ($where == '' AND count($where) <1) ? " WHERE " : ' AND ';
-
- foreach ($like as $st_like)
- {
- $sql .= " " . $st_like;
- }
+ $where .= ($where == '' ? ' WHERE ' : ' AND ').implode(' ', $like);
}
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -644,17 +589,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -668,30 +610,21 @@ class CI_DB_mysql_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
$cases = '';
-
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k." = CASE \n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
-
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
-
/**
* Truncate statement
*
@@ -699,13 +632,12 @@ class CI_DB_mysql_driver extends CI_DB {
* 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)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -715,31 +647,27 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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 = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -749,24 +677,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* 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
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
-
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.' LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
}
// --------------------------------------------------------------------
@@ -774,17 +692,15 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mysql_close($conn_id);
}
}
-
/* End of file mysql_driver.php */
-/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_driver.php */
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index a41a7b446..0f251b086 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Forge Class
*
@@ -39,13 +37,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
- return "CREATE DATABASE ".$name;
+ return 'CREATE DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -53,13 +50,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
- return "DROP DATABASE ".$name;
+ return 'DROP DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -67,83 +63,57 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ private function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ 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";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
- if (array_key_exists('TYPE', $attributes))
+ if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- if (array_key_exists('CONSTRAINT', $attributes))
+ if ( ! empty($attributes['CONSTRAINT']))
{
- switch ($attributes['TYPE'])
+ switch (strtolower($attributes['TYPE']))
{
case 'decimal':
case 'float':
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
-
+ break;
case 'enum':
case 'set':
$sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
-
+ break;
default:
$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';
- }
+ $sql .= (( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -161,15 +131,14 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -178,15 +147,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
$key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -204,13 +170,11 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$key = array($key_name);
}
- $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
-
- return $sql;
+ return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
}
// --------------------------------------------------------------------
@@ -218,12 +182,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
+ * @param string table name
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -232,33 +196,26 @@ class CI_DB_mysql_forge extends CI_DB_forge {
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * 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 array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -268,18 +225,16 @@ class CI_DB_mysql_forge extends CI_DB_forge {
*
* 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)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file mysql_forge.php */
-/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_forge.php */
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index dcb99cd60..8f04a936d 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// --------------------------------------------------------------------
-
/**
* MySQL Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mysql_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mysql_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mysql_fetch_field($this->result_id))
@@ -90,25 +85,21 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mysql_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
- $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = $type;
- $F->default = $field->Default;
- $F->max_length = $length;
- $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
+ $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
+ $F->primary_key = (int) ($field->Key === 'PRI');
$retval[] = $F;
}
@@ -121,9 +112,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -137,14 +128,13 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * 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)
+ protected function _data_seek($n = 0)
{
return mysql_data_seek($this->result_id, $n);
}
@@ -156,10 +146,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mysql_fetch_assoc($this->result_id);
}
@@ -171,16 +160,14 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mysql_fetch_object($this->result_id);
}
}
-
/* End of file mysql_result.php */
-/* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_result.php */
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 703524165..952f887fe 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_mysql_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SHOW DATABASES";
+ return 'SHOW DATABASES';
}
// --------------------------------------------------------------------
@@ -54,13 +51,12 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -70,26 +66,24 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
/**
* MySQL Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
- if (count($params) == 0)
+ if (count($params) === 0)
{
return FALSE;
}
@@ -99,16 +93,16 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Build the output
$output = '';
- foreach ((array)$tables as $table)
+ foreach ( (array) $tables as $table)
{
// Is the table in the "ignore" list?
- if (in_array($table, (array)$ignore, TRUE))
+ if (in_array($table, (array) $ignore, TRUE))
{
continue;
}
// Get the table schema
- $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`');
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table));
// No result means the table name was invalid
if ($query === FALSE)
@@ -121,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
if ($add_drop == TRUE)
{
- $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
+ $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
}
$i = 0;
@@ -141,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Grab all the data from the current table
- $query = $this->db->query("SELECT * FROM $table");
+ $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
if ($query->num_rows() == 0)
{
@@ -149,7 +143,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Fetch the field names and determine if the field is an
- // integer type. We use this info to decide whether to
+ // integer type. We use this info to decide whether to
// surround the data with quotes or not
$i = 0;
@@ -158,20 +152,17 @@ class CI_DB_mysql_utility extends CI_DB_utility {
while ($field = mysql_fetch_field($query->result_id))
{
// Most versions of MySQL store timestamp as a string
- $is_int[$i] = (in_array(
- strtolower(mysql_field_type($query->result_id, $i)),
- array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
- TRUE)
- ) ? TRUE : FALSE;
+ $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)),
+ array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
+ TRUE);
// Create a string of field names
- $field_str .= '`'.$field->name.'`, ';
+ $field_str .= $this->db->protect_identifiers($field->name).', ';
$i++;
}
// Trim off the end comma
- $field_str = preg_replace( "/, $/" , "" , $field_str);
-
+ $field_str = preg_replace('/, $/' , '', $field_str);
// Build the insert string
foreach ($query->result_array() as $row)
@@ -189,14 +180,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
else
{
// Escape the data if it's not an integer
- if ($is_int[$i] == FALSE)
- {
- $val_str .= $this->db->escape($v);
- }
- else
- {
- $val_str .= $v;
- }
+ $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v;
}
// Append a comma
@@ -205,10 +189,10 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Remove the comma at the end of the string
- $val_str = preg_replace( "/, $/" , "" , $val_str);
+ $val_str = preg_replace('/, $/' , '', $val_str);
// Build the INSERT string
- $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
}
$output .= $newline.$newline;
@@ -216,7 +200,8 @@ class CI_DB_mysql_utility extends CI_DB_utility {
return $output;
}
+
}
/* End of file mysql_utility.php */
-/* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_utility.php */
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index aff62a37d..dbba12e15 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,10 +25,8 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
- * MySQLi Database Adapter Class - MySQLi only works with PHP 5
+ * MySQLi Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
@@ -42,52 +40,40 @@
*/
class CI_DB_mysqli_driver extends CI_DB {
- var $dbdriver = 'mysqli';
+ public $dbdriver = 'mysqli';
// The character used for escaping
- var $_escape_char = '`';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in MySQL
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
+ protected $_like_escape_str = '';
+ protected $_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 = ' RAND()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
*/
- var $delete_hack = TRUE;
-
- // whether SET NAMES must be used to set the character set
- var $use_set_names;
-
- // --------------------------------------------------------------------
+ public $delete_hack = TRUE;
/**
* Non-persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_connect()
+ public function db_connect()
{
- if ($this->port != '')
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
- }
- else
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
- }
-
+ return ($this->port != '')
+ ? @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -95,12 +81,19 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return $this->db_connect();
+ // Persistent connection support was added in PHP 5.3.0
+ if ( ! is_php('5.3'))
+ {
+ return $this->db_connect();
+ }
+
+ return ($this->port != '')
+ ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -111,10 +104,9 @@ class CI_DB_mysqli_driver extends CI_DB {
* 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()
+ public function reconnect()
{
if (mysqli_ping($this->conn_id) === FALSE)
{
@@ -127,12 +119,23 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return @mysqli_select_db($this->conn_id, $this->database);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysqli_select_db($this->conn_id, $database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -140,12 +143,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Set client character set
*
- * @access private
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function _db_set_charset($charset, $collation)
+ protected function _db_set_charset($charset, $collation)
{
return function_exists('mysqli_set_charset')
? @mysqli_set_charset($this->conn_id, $charset)
@@ -157,12 +159,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return @mysqli_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
@@ -170,15 +171,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- $result = @mysqli_query($this->conn_id, $sql);
- return $result;
+ return @mysqli_query($this->conn_id, $this->_prep_query($sql));
}
// --------------------------------------------------------------------
@@ -188,20 +186,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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)
+ protected function _prep_query($sql)
{
- // "DELETE FROM TABLE" returns 0 affected rows This hack modifies
- // the query so that it returns the number of affected rows
- if ($this->delete_hack === TRUE)
+ // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
+ // modifies the query so that it a proper number of affected rows is returned.
+ if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
{
- if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
- {
- $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
- }
+ return preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql);
}
return $sql;
@@ -212,18 +206,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -231,7 +219,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// 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;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
@@ -243,18 +231,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -269,18 +251,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public 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)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -295,12 +271,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* 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)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -312,7 +287,7 @@ class CI_DB_mysqli_driver extends CI_DB {
return $str;
}
- if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
+ if (function_exists('mysqli_real_escape_string') && is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
@@ -328,7 +303,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -339,10 +314,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mysqli_affected_rows($this->conn_id);
}
@@ -352,10 +326,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @mysqli_insert_id($this->conn_id);
}
@@ -368,27 +341,25 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -399,16 +370,16 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -421,13 +392,12 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -437,13 +407,12 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "DESCRIBE ".$table;
+ return 'DESCRIBE '.$table;
}
// --------------------------------------------------------------------
@@ -451,10 +420,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return mysqli_error($this->conn_id);
}
@@ -464,10 +432,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return mysqli_errno($this->conn_id);
}
@@ -479,11 +446,10 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -494,24 +460,20 @@ class CI_DB_mysqli_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -522,11 +484,10 @@ class CI_DB_mysqli_driver extends CI_DB {
* 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
+ * @param string
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -543,15 +504,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -561,15 +521,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -580,17 +539,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific replace 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 _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
-
+
// --------------------------------------------------------------------
/**
@@ -598,7 +556,6 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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
@@ -606,24 +563,17 @@ class CI_DB_mysqli_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -633,17 +583,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -657,25 +604,19 @@ class CI_DB_mysqli_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
$cases = '';
-
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k.' = CASE '."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
+ $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
@@ -687,13 +628,12 @@ class CI_DB_mysqli_driver extends CI_DB {
* 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)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -703,31 +643,26 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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 = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
-
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -737,22 +672,15 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* 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
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
- return $sql;
+ return $sql.' LIMIT '.$limit
+ .($offset > 0 ? ' OFFSET '.$offset : '');
}
// --------------------------------------------------------------------
@@ -760,18 +688,15 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
- * @param resource
+ * @param object
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mysqli_close($conn_id);
}
-
}
-
/* End of file mysqli_driver.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 590efa939..7de036127 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Forge Class
*
@@ -39,13 +37,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
- return "CREATE DATABASE ".$name;
+ return 'CREATE DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -53,13 +50,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
- return "DROP DATABASE ".$name;
+ return 'DROP DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -67,68 +63,35 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ public function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ 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";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
-
- if (array_key_exists('TYPE', $attributes))
- {
- $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';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '')
+ .( ! empty($attributes['TYPE']) ? ' '.$attributes['TYPE'] : '')
+ .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -146,15 +109,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -163,15 +125,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
- $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $key_name = $this->db->protect_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -180,22 +139,20 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
- $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
-
- return $sql;
+ return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
}
// --------------------------------------------------------------------
@@ -203,12 +160,11 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -219,31 +175,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
* 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 array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
- {
- return $sql.$this->db->_protect_identifiers($fields);
- }
-
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
+ if ($alter_type === 'DROP')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.$this->db->protect_identifiers($fields);
}
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -253,18 +202,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
*
* 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)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file mysqli_forge.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 89dd4ded8..0a50cccac 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mysqli_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mysqli_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mysqli_fetch_field($this->result_id))
@@ -90,40 +85,36 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mysqli_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
- $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = $type;
- $F->default = $field->Default;
- $F->max_length = $length;
- $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
+ $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
+ $F->primary_key = (int) ($field->Key === 'PRI');
$retval[] = $F;
}
return $retval;
}
-
+
// --------------------------------------------------------------------
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_object($this->result_id))
{
@@ -141,10 +132,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return mysqli_data_seek($this->result_id, $n);
}
@@ -156,10 +146,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mysqli_fetch_assoc($this->result_id);
}
@@ -171,16 +160,14 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mysqli_fetch_object($this->result_id);
}
}
-
/* End of file mysqli_result.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_result.php */
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 76bd49e31..3fdc5c723 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SHOW DATABASES";
+ return 'SHOW DATABASES';
}
// --------------------------------------------------------------------
@@ -54,13 +51,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -70,13 +66,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -84,11 +79,10 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* MySQLi Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -96,4 +90,4 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
}
/* End of file mysqli_utility.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index c6621901b..6da6dc724 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -139,22 +139,6 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- public function db_set_charset($charset, $collation)
- {
- // this is done upon connect
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
* @access protected
@@ -398,10 +382,9 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Escape String
*
- * @access public
- * @param string
+ * @param string
* @param bool whether or not the string will be used in a LIKE condition
- * @return string
+ * @return string
*/
public function escape_str($str, $like = FALSE)
{
@@ -415,15 +398,14 @@ class CI_DB_oci8_driver extends CI_DB {
return $str;
}
- $str = remove_invisible_characters($str);
- $str = str_replace("'", "''", $str);
+ $str = str_replace("'", "''", remove_invisible_characters($str));
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -547,13 +529,11 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message string
*
- * @access protected
- * @return string
+ * @return string
*/
protected function _error_message()
{
- // If the error was during connection, no conn_id should be passed
- $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
+ $error = $this->_oci8_error_data();
return $error['message'];
}
@@ -562,19 +542,43 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message number
*
- * @access protected
- * @return integer
+ * @return string
*/
protected function _error_number()
{
- // Same as _error_message()
- $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
+ $error = $this->_oci8_error_data();
return $error['code'];
}
// --------------------------------------------------------------------
/**
+ * OCI8-specific method to get errors.
+ * Used by _error_message() and _error_code().
+ *
+ * @return array
+ */
+ protected function _oci8_error_data()
+ {
+ if (is_resource($this->curs_id))
+ {
+ return oci_error($this->curs_id);
+ }
+ elseif (is_resource($this->stmt_id))
+ {
+ return oci_error($this->stmt_id);
+ }
+ elseif (is_resource($this->conn_id))
+ {
+ return oci_error($this->conn_id);
+ }
+
+ return oci_error();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Escape the SQL Identifiers
*
* This function escapes column and table names
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 6ba39f0cd..abb660324 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -124,22 +124,6 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
* @access public
@@ -646,4 +630,4 @@ class CI_DB_odbc_driver extends CI_DB {
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index ba660856e..572e110ca 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -38,15 +38,27 @@
*/
class CI_DB_odbc_result extends CI_DB_result {
+ public $num_rows;
+
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
- return @odbc_num_rows($this->result_id);
+ if (is_int($this->num_rows))
+ {
+ return $this->num_rows;
+ }
+
+ // Work-around for ODBC subdrivers that don't support num_rows()
+ if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
+ {
+ $this->num_rows = count($this->result_array());
+ }
+
+ return $this->num_rows;
}
// --------------------------------------------------------------------
@@ -54,10 +66,9 @@ class CI_DB_odbc_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @odbc_num_fields($this->result_id);
}
@@ -69,15 +80,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ $num_fields = $this->num_fields();
+
+ if ($num_fields > 0)
{
- $field_names[] = odbc_field_name($this->result_id, $i);
+ for ($i = 1; $i <= $num_fields; $i++)
+ {
+ $field_names[] = odbc_field_name($this->result_id, $i);
+ }
}
return $field_names;
@@ -90,22 +105,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
{
- $F = new stdClass();
- $F->name = odbc_field_name($this->result_id, $i);
- $F->type = odbc_field_type($this->result_id, $i);
- $F->max_length = odbc_field_len($this->result_id, $i);
- $F->primary_key = 0;
- $F->default = '';
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
+ $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
+ $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
}
return $retval;
@@ -237,4 +249,4 @@ class CI_DB_odbc_result extends CI_DB_result {
/* End of file odbc_result.php */
-/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_result.php */
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 4f4f44ba7..90f0fd791 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -46,9 +46,10 @@ class CI_DB_pdo_driver extends CI_DB {
// the character used to excape - not necessary for PDO
var $_escape_char = '';
+
+ // clause and character used for LIKE escape sequences
var $_like_escape_str;
var $_like_escape_chr;
-
/**
* The syntax to count rows is slightly different across different
@@ -57,29 +58,36 @@ class CI_DB_pdo_driver extends CI_DB {
*/
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword;
-
+
+ // need to track the pdo DSN, driver and options
+ var $dsn;
+ var $pdodriver;
var $options = array();
function __construct($params)
{
parent::__construct($params);
-
+
+ if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2)
+ {
+ // If there is a minimum valid dsn string pattern found, we're done
+ // This is for general PDO users, who tend to have a full DSN string.
+ $this->pdodriver = end($match);
+ }
+ else
+ {
+ // Try to build a complete DSN string from params
+ $this->_connect_string($params);
+ }
+
// clause and character used for LIKE escape sequences
- if (strpos($this->hostname, 'mysql') !== FALSE)
+ // this one depends on the driver being used
+ if ($this->pdodriver == 'mysql')
{
$this->_like_escape_str = '';
$this->_like_escape_chr = '';
-
- //Prior to this version, the charset can't be set in the dsn
- if(is_php('5.3.6'))
- {
- $this->hostname .= ";charset={$this->char_set}";
- }
-
- //Set the charset with the connection options
- $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
}
- else if (strpos($this->hostname, 'odbc') !== FALSE)
+ elseif ($this->pdodriver == 'odbc')
{
$this->_like_escape_str = " {escape '%s'} ";
$this->_like_escape_chr = '!';
@@ -90,14 +98,94 @@ class CI_DB_pdo_driver extends CI_DB {
$this->_like_escape_chr = '!';
}
- if (strpos($this->hostname, 'sqlite') === FALSE)
+ $this->trans_enabled = FALSE;
+ $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ }
+
+ /**
+ * Connection String
+ *
+ * @access private
+ * @param array
+ * @return void
+ */
+ function _connect_string($params)
+ {
+ if (strpos($this->hostname, ':'))
{
- $this->hostname .= ";dbname=".$this->database;
+ // hostname generally would have this prototype
+ // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);';
+ // We need to get the prefix (pdodriver used by PDO).
+ $dsnarray = explode(':', $this->hostname);
+ $this->pdodriver = $dsnarray[0];
+
+ // End dsn with a semicolon for extra backward compability
+ // if database property was not empty.
+ if ( ! empty($this->database))
+ {
+ $this->dsn .= rtrim($this->hostname, ';').';';
+ }
}
-
- $this->trans_enabled = FALSE;
+ else
+ {
+ // Invalid DSN, display an error
+ if ( ! array_key_exists('pdodriver', $params))
+ {
+ show_error('Invalid DB Connection String for PDO');
+ }
- $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ // Assuming that the following DSN string format is used:
+ // $dsn = 'pdo://username:password@hostname:port/database?pdodriver=pgsql';
+ $this->dsn = $this->pdodriver.':';
+
+ // Add hostname to the DSN for databases that need it
+ if ( ! empty($this->hostname)
+ && strpos($this->hostname, ':') === FALSE
+ && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'host='.$this->hostname.';';
+ }
+
+ // Add a port to the DSN for databases that can use it
+ if ( ! empty($this->port) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'ibm', 'cubrid')))
+ {
+ $this->dsn .= 'port='.$this->port.';';
+ }
+ }
+
+ // Add the database name to the DSN, if needed
+ if (stripos($this->dsn, 'dbname') === FALSE
+ && in_array($this->pdodriver, array('4D', 'pgsql', 'mysql', 'firebird', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'dbname='.$this->database.';';
+ }
+ elseif (stripos($this->dsn, 'database') === FALSE && in_array($this->pdodriver, array('ibm', 'sqlsrv')))
+ {
+ if (stripos($this->dsn, 'dsn') === FALSE)
+ {
+ $this->dsn .= 'database='.$this->database.';';
+ }
+ }
+ elseif ($this->pdodriver === 'sqlite' && $this->dsn === 'sqlite:')
+ {
+ if ($this->database !== ':memory')
+ {
+ if ( ! file_exists($this->database))
+ {
+ show_error('Invalid DB Connection string for PDO SQLite');
+ }
+
+ $this->dsn .= (strpos($this->database, DIRECTORY_SEPARATOR) !== 0) ? DIRECTORY_SEPARATOR : '';
+ }
+
+ $this->dsn .= $this->database;
+ }
+
+ // Add charset to the DSN, if needed
+ if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci')))
+ {
+ $this->dsn .= 'charset='.$this->char_set.';';
+ }
}
/**
@@ -108,9 +196,9 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_connect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
-
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+
+ return $this->pdo_connect();
}
// --------------------------------------------------------------------
@@ -123,10 +211,44 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_pconnect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
- $this->options['PDO::ATTR_PERSISTENT'] = TRUE;
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+ $this->options[PDO::ATTR_PERSISTENT] = TRUE;
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ return $this->pdo_connect();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * PDO connection
+ *
+ * @access private called by the PDO driver class
+ * @return resource
+ */
+ function pdo_connect()
+ {
+ // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php
+ if ($this->pdodriver == 'mysql' && is_php('5.3.6'))
+ {
+ $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'";
+ }
+
+ // Connecting...
+ try
+ {
+ $db = new PDO($this->dsn, $this->username, $this->password, $this->options);
+ }
+ catch (PDOException $e)
+ {
+ if ($this->db_debug && empty($this->failover))
+ {
+ $this->display_error($e->getMessage(), '', TRUE);
+ }
+
+ return FALSE;
+ }
+
+ return $db;
}
// --------------------------------------------------------------------
@@ -146,6 +268,7 @@ class CI_DB_pdo_driver extends CI_DB {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
@@ -166,30 +289,13 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION);
+ return $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
}
// --------------------------------------------------------------------
@@ -204,6 +310,7 @@ class CI_DB_pdo_driver extends CI_DB {
function _execute($sql)
{
$sql = $this->_prep_query($sql);
+
$result_id = $this->conn_id->query($sql);
if (is_object($result_id))
@@ -231,6 +338,17 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _prep_query($sql)
{
+ if ($this->pdodriver === 'pgsql')
+ {
+ // Change the backtick(s) for Postgre
+ $sql = str_replace('`', '"', $sql);
+ }
+ elseif ($this->pdodriver === 'sqlite')
+ {
+ // Change the backtick(s) for SQLite
+ $sql = str_replace('`', '', $sql);
+ }
+
return $sql;
}
@@ -285,6 +403,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn->commit();
+
return $ret;
}
@@ -310,6 +429,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn_id->rollBack();
+
return $ret;
}
@@ -348,7 +468,9 @@ class CI_DB_pdo_driver extends CI_DB {
if ($like === TRUE)
{
$str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ array($this->_like_escape_chr.'%',
+ $this->_like_escape_chr.'_',
+ $this->_like_escape_chr.$this->_like_escape_chr),
$str);
}
@@ -372,31 +494,19 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
- *
- * @access public
- * @return integer
+ *
+ * @return int
*/
- function insert_id($name=NULL)
+ public function insert_id($name = NULL)
{
- //Convenience method for postgres insertid
- if (strpos($this->hostname, 'pgsql') !== FALSE)
+ if ($this->pdodriver === 'pgsql' && $name === NULL && $this->_version() >= '8.1')
{
- $v = $this->_version();
-
- $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
-
- if ($table == NULL && $v >= '8.1')
- {
- $sql='SELECT LASTVAL() as ins_id';
- }
- $query = $this->query($sql);
- $row = $query->row();
- return $row->ins_id;
- }
- else
- {
- return $this->conn_id->lastInsertId($name);
+ $query = $this->query('SELECT LASTVAL() AS ins_id');
+ $query = $query->row();
+ return $query->ins_id;
}
+
+ return $this->conn_id->lastInsertId($name);
}
// --------------------------------------------------------------------
@@ -418,7 +528,9 @@ class CI_DB_pdo_driver extends CI_DB {
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $sql = $this->_count_string.$this->_protect_identifiers('numrows').' FROM ';
+ $sql .= $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $query = $this->query($sql);
if ($query->num_rows() == 0)
{
@@ -427,6 +539,7 @@ class CI_DB_pdo_driver extends CI_DB {
$row = $query->row();
$this->_reset_select();
+
return (int) $row->numrows;
}
@@ -443,12 +556,19 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM `".$this->database."`";
+ if ($this->pdodriver == 'pgsql')
+ {
+ // Analog function to show all tables in postgre
+ $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'";
+ }
+ else
+ {
+ $sql = "SHOW TABLES FROM `".$this->database."`";
+ }
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
- //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
- return FALSE; // not currently supported
+ return FALSE;
}
return $sql;
@@ -467,7 +587,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$table;
+ return 'SHOW COLUMNS FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
@@ -483,7 +603,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$table;
+ return 'SELECT TOP 1 FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
@@ -497,6 +617,7 @@ class CI_DB_pdo_driver extends CI_DB {
function _error_message()
{
$error_array = $this->conn_id->errorInfo();
+
return $error_array[2];
}
@@ -544,8 +665,8 @@ class CI_DB_pdo_driver extends CI_DB {
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
-
+ $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ $str .= $this->_escape_char;
}
else
{
@@ -575,7 +696,7 @@ class CI_DB_pdo_driver extends CI_DB {
$tables = array($tables);
}
- return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')';
+ return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
@@ -593,7 +714,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -611,7 +732,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -636,14 +757,11 @@ class CI_DB_pdo_driver extends CI_DB {
$valstr[] = $key." = ".$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
+ $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+ $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : '';
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr);
+ $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : '';
$sql .= $orderby.$limit;
return $sql;
@@ -664,8 +782,8 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _update_batch($table, $values, $index, $where = NULL)
{
- $ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
+ $ids = array();
+ $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : '';
foreach ($values as $key => $val)
{
@@ -680,12 +798,13 @@ class CI_DB_pdo_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET ';
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
+
foreach ($v as $row)
{
$cases .= $row."\n";
@@ -695,7 +814,6 @@ class CI_DB_pdo_driver extends CI_DB {
}
$sql .= substr($cases, 0, -2);
-
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
return $sql;
@@ -739,19 +857,20 @@ class CI_DB_pdo_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
+ $conditions = "\nWHERE ";
$conditions .= implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
$conditions .= " AND ";
}
+
$conditions .= implode("\n", $like);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$this->_from_tables($table).$conditions.$limit;
}
// --------------------------------------------------------------------
@@ -769,27 +888,16 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _limit($sql, $limit, $offset)
{
- if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
+ if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite')
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
+ $offset = ($offset == 0) ? '' : $offset.', ';
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.'LIMIT '.$offset.$limit;
}
else
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
+ $sql .= 'LIMIT '.$limit;
+ $sql .= ($offset > 0) ? ' OFFSET '.$offset : '';
return $sql;
}
@@ -809,10 +917,7 @@ class CI_DB_pdo_driver extends CI_DB {
$this->conn_id = null;
}
-
}
-
-
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index 076415928..478b2dbfb 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -96,7 +96,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= '`'.$this->db->_escape_identifiers($table).'` (';
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -111,6 +111,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
+ $numeric = array('SERIAL', 'INTEGER');
$sql .= "\n\t".$this->db->_protect_identifiers($field);
@@ -118,7 +119,11 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if (array_key_exists('CONSTRAINT', $attributes))
{
- $sql .= '('.$attributes['CONSTRAINT'].')';
+ // Exception for Postgre numeric which not too happy with constraint within those type
+ if ( ! ($this->db->pdodriver == 'pgsql' && in_array($attributes['TYPE'], $numeric)))
+ {
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
@@ -219,7 +224,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
*/
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);
+ $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')
@@ -271,7 +276,6 @@ class CI_DB_pdo_forge extends CI_DB_forge {
return $sql;
}
-
}
/* End of file pdo_forge.php */
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 6b523b001..c333abc40 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -39,6 +39,16 @@
class CI_DB_pdo_result extends CI_DB_result {
/**
+ * @var bool Hold the flag whether a result handler already fetched before
+ */
+ protected $is_fetched = FALSE;
+
+ /**
+ * @var mixed Hold the fetched assoc array of a result handler
+ */
+ protected $result_assoc;
+
+ /**
* Number of rows in the result set
*
* @access public
@@ -46,7 +56,59 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
function num_rows()
{
- return $this->result_id->rowCount();
+ if (empty($this->result_id) OR ! is_object($this->result_id))
+ {
+ // invalid result handler
+ return 0;
+ }
+ elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0)
+ {
+ // If rowCount return something, we're done.
+ return $num_rows;
+ }
+
+ // Fetch the result, instead perform another extra query
+ return ($this->is_fetched && is_array($this->result_assoc)) ? count($this->result_assoc) : count($this->result_assoc());
+ }
+
+ /**
+ * Fetch the result handler
+ *
+ * @access public
+ * @return mixed
+ */
+ function result_assoc()
+ {
+ // If the result already fetched before, use that one
+ if (count($this->result_array) > 0 OR $this->is_fetched)
+ {
+ return $this->result_array();
+ }
+
+ // Define the output
+ $output = array('assoc', 'object');
+
+ // Fetch the result
+ foreach ($output as $type)
+ {
+ // Define the method and handler
+ $res_method = '_fetch_'.$type;
+ $res_handler = 'result_'.$type;
+
+ $this->$res_handler = array();
+ $this->_data_seek(0);
+
+ while ($row = $this->$res_method())
+ {
+ $this->{$res_handler}[] = $row;
+ }
+ }
+
+ // Save this as buffer and marked the fetch flag
+ $this->result_array = $this->result_assoc;
+ $this->is_fetched = TRUE;
+
+ return $this->result_assoc;
}
// --------------------------------------------------------------------
@@ -78,6 +140,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
@@ -110,6 +173,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
}
@@ -178,6 +242,5 @@ class CI_DB_pdo_result extends CI_DB_result {
}
-
/* End of file pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 42329bded..89541e5fa 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -147,22 +147,6 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
* @access public
@@ -712,4 +696,4 @@ class CI_DB_postgre_driver extends CI_DB {
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 28c3caecd..718501b20 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -141,22 +141,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Version number query string
*
* @access public
@@ -667,4 +651,4 @@ class CI_DB_sqlite_driver extends CI_DB {
/* End of file sqlite_driver.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 6fd52ef70..9b9038189 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -122,28 +122,23 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return $this->_execute('USE ' . $this->database);
- }
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
- // --------------------------------------------------------------------
+ if ($this->_execute('USE '.$database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
- /**
- * 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;
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -413,13 +408,18 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
- $error = array_shift(sqlsrv_errors());
- return !empty($error['message']) ? $error['message'] : null;
+ $error = sqlsrv_errors();
+ if ( ! is_array($error))
+ {
+ return '';
+ }
+
+ $error = array_shift($error);
+ return isset($error['message']) ? $error['message'] : '';
}
// --------------------------------------------------------------------
@@ -427,13 +427,25 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return string
*/
- function _error_number()
+ protected function _error_number()
{
- $error = array_shift(sqlsrv_errors());
- return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null;
+ $error = sqlsrv_errors();
+ if ( ! is_array($error))
+ {
+ return '';
+ }
+ elseif (isset($error['SQLSTATE']))
+ {
+ return isset($error['code']) ? $error['SQLSTATE'].'/'.$error['code'] : $error['SQLSTATE'];
+ }
+ elseif (isset($error['code']))
+ {
+ return $error['code'];
+ }
+
+ return '';
}
// --------------------------------------------------------------------
@@ -608,4 +620,4 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 4a1a79cc3..a8c59c2c0 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Download Helpers
*
@@ -47,73 +45,72 @@
* @access public
* @param string filename
* @param mixed the data to be downloaded
+ * @param bool wether to try and send the actual file MIME type
* @return void
*/
if ( ! function_exists('force_download'))
{
- function force_download($filename = '', $data = '')
+ function force_download($filename = '', $data = '', $set_mime = FALSE)
{
if ($filename == '' OR $data == '')
{
return FALSE;
}
- // Try to determine if the filename includes a file extension.
- // We need it in order to set the MIME type
- if (FALSE === strpos($filename, '.'))
+ // Set the default MIME type to send
+ $mime = 'application/octet-stream';
+
+ if ($set_mime === TRUE)
{
- return FALSE;
- }
+ /* If we're going to detect the MIME type,
+ * we'll need a file extension.
+ */
+ if (FALSE === strpos($filename, '.'))
+ {
+ return FALSE;
+ }
- // Grab the file extension
- $x = explode('.', $filename);
- $extension = end($x);
+ $extension = explode('.', $filename);
+ $extension = end($extension);
- // Load the mime types
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
- {
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
- }
- elseif (is_file(APPPATH.'config/mimes.php'))
- {
- include(APPPATH.'config/mimes.php');
- }
+ // Load the mime types
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ }
+ elseif (is_file(APPPATH.'config/mimes.php'))
+ {
+ include(APPPATH.'config/mimes.php');
+ }
- // Set a default mime if we can't find it
- if ( ! isset($mimes[$extension]))
- {
- $mime = 'application/octet-stream';
- }
- else
- {
- $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
+ // Only change the default MIME if we can find one
+ if (isset($mimes[$extension]))
+ {
+ $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
+ }
}
// Generate the server headers
- if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
+ header('Content-Type: "'.$mime.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header('Expires: 0');
+ header('Content-Transfer-Encoding: binary');
+ header('Content-Length: '.strlen($data));
+
+ // Internet Explorer-specific headers
+ if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header("Content-Transfer-Encoding: binary");
header('Pragma: public');
- header("Content-Length: ".strlen($data));
}
else
{
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
header('Pragma: no-cache');
- header("Content-Length: ".strlen($data));
}
exit($data);
}
}
-
/* End of file download_helper.php */
-/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/download_helper.php */
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 9b39b8c20..2d4b10e37 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -196,16 +196,16 @@ if ( ! function_exists('get_filenames'))
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
+ if (@is_dir($source_dir.$file) && $file[0] !== '.')
{
get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
}
- elseif (strncmp($file, '.', 1) !== 0)
+ elseif ($file[0] !== '.')
{
$_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
}
}
- closedir($source_dir);
+ closedir($fp);
return $_filedata;
}
@@ -249,17 +249,17 @@ if ( ! function_exists('get_dir_file_info'))
// foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE)
+ if (@is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
{
get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
}
- elseif (strncmp($file, '.', 1) !== 0)
+ elseif ($file[0] !== '.')
{
$_filedata[$file] = get_file_info($source_dir.$file);
$_filedata[$file]['relative_path'] = $relative_path;
}
}
- closedir($source_dir);
+ closedir($fp);
return $_filedata;
}
@@ -359,7 +359,7 @@ if ( ! function_exists('get_mime_by_extension'))
if ( ! is_array($mimes))
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
}
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 0bd1e112f..02c425b8a 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -34,7 +34,7 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
+ * @link http://codeigniter.com/user_guide/helpers/inflector_helper.html
*/
@@ -45,7 +45,6 @@
*
* Takes a plural word and makes it singular
*
- * @access public
* @param string
* @return str
*/
@@ -55,37 +54,51 @@ if ( ! function_exists('singular'))
{
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$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',
+ '/(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',
+ '/([ti])a$/' => '\1um',
+ '/(p)eople$/' => '\1\2erson',
+ '/(m)en$/' => '\1an',
+ '/(s)tatuses$/' => '\1\2tatus',
+ '/(c)hildren$/' => '\1\2hild',
+ '/(n)ews$/' => '\1\2ews',
+ '/([^us])s$/' => '\1',
);
- return preg_replace(array_keys($singular_values), $singular_values, $result);
+ foreach ($singular_rules as $rule => $replacement)
+ {
+ if (preg_match($rule, $result))
+ {
+ $result = preg_replace($rule, $replacement, $result);
+ break;
+ }
+ }
+
+ return $result;
}
}
@@ -96,7 +109,6 @@ if ( ! function_exists('singular'))
*
* Takes a singular word and makes it plural
*
- * @access public
* @param string
* @param bool
* @return str
@@ -104,32 +116,46 @@ if ( ! function_exists('singular'))
if ( ! function_exists('plural'))
{
function plural($str, $force = FALSE)
- {
+ {
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$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',
+ '/^(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',
);
-
- return preg_replace(array_keys($plural_rules), $plural_rules, $result);
+
+ foreach ($plural_rules as $rule => $replacement)
+ {
+ if (preg_match($rule, $result))
+ {
+ $result = preg_replace($rule, $replacement, $result);
+ break;
+ }
+ }
+
+ return $result;
}
}
@@ -140,7 +166,6 @@ if ( ! function_exists('plural'))
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
- * @access public
* @param string
* @return str
*/
@@ -159,7 +184,6 @@ if ( ! function_exists('camelize'))
*
* Takes multiple words separated by spaces and underscores them
*
- * @access public
* @param string
* @return str
*/
@@ -178,7 +202,6 @@ if ( ! function_exists('underscore'))
*
* Takes multiple words separated by the separator and changes them to spaces
*
- * @access public
* @param string $str
* @param string $separator
* @return str
@@ -191,5 +214,22 @@ if ( ! function_exists('humanize'))
}
}
+/**
+ * Checks if the given word has a plural version.
+ *
+ * @param string the word to check
+ * @return bool if the word is countable
+ */
+if ( ! function_exists('is_countable'))
+{
+ function is_countable($word)
+ {
+ return ! (in_array(strtolower(strval($word)), array(
+ 'equipment', 'information', 'rice', 'money',
+ 'species', 'series', 'fish', 'meta'
+ )));
+ }
+}
+
/* End of file inflector_helper.php */
-/* Location: ./system/helpers/inflector_helper.php */
+/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index f81c46210..c49348e6a 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -88,7 +88,7 @@ if ( ! function_exists('auto_typography'))
*
* @access public
* @param string
- * @param string
+ * @param string
* @return string
*/
if ( ! function_exists('entity_decode'))
@@ -101,4 +101,4 @@ if ( ! function_exists('entity_decode'))
}
/* End of file typography_helper.php */
-/* Location: ./system/helpers/typography_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/typography_helper.php */
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index c630ebea8..2cbcd9dbf 100755..100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -62,7 +62,7 @@ if ( ! function_exists('site_url'))
/**
* Base URL
- *
+ *
* 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.
@@ -198,7 +198,6 @@ if ( ! function_exists('anchor_popup'))
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
$title = (string) $title;
-
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
if ($title == '')
@@ -248,14 +247,12 @@ if ( ! function_exists('mailto'))
{
$title = (string) $title;
- if ($title == "")
+ if ($title == '')
{
$title = $email;
}
- $attributes = _parse_attributes($attributes);
-
- return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
+ return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
}
}
@@ -278,19 +275,16 @@ if ( ! function_exists('safe_mailto'))
{
$title = (string) $title;
- if ($title == "")
+ if ($title == '')
{
$title = $email;
}
- for ($i = 0; $i < 16; $i++)
- {
- $x[] = substr('<a href="mailto:', $i, 1);
- }
+ $x = str_split('<a href="mailto:', 1);
- for ($i = 0; $i < strlen($email); $i++)
+ for ($i = 0, $l = strlen($email); $i < $l; $i++)
{
- $x[] = "|".ord(substr($email, $i, 1));
+ $x[] = '|'.ord($email[$i]);
}
$x[] = '"';
@@ -302,18 +296,18 @@ if ( ! function_exists('safe_mailto'))
foreach ($attributes as $key => $val)
{
$x[] = ' '.$key.'="';
- for ($i = 0; $i < strlen($val); $i++)
+ for ($i = 0, $l = strlen($val); $i < $l; $i++)
{
- $x[] = "|".ord(substr($val, $i, 1));
+ $x[] = '|'.ord($val[$i]);
}
$x[] = '"';
}
}
else
{
- for ($i = 0; $i < strlen($attributes); $i++)
+ for ($i = 0, $l = strlen($attributes); $i < $l; $i++)
{
- $x[] = substr($attributes, $i, 1);
+ $x[] = $attributes[$i];
}
}
}
@@ -321,26 +315,28 @@ if ( ! function_exists('safe_mailto'))
$x[] = '>';
$temp = array();
- for ($i = 0; $i < strlen($title); $i++)
+ for ($i = 0, $l = strlen($title); $i < $l; $i++)
{
$ordinal = ord($title[$i]);
if ($ordinal < 128)
{
- $x[] = "|".$ordinal;
+ $x[] = '|'.$ordinal;
}
else
{
- if (count($temp) == 0)
+ if (count($temp) === 0)
{
$count = ($ordinal < 224) ? 2 : 3;
}
$temp[] = $ordinal;
- if (count($temp) == $count)
+ if (count($temp) === $count)
{
- $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
- $x[] = "|".$number;
+ $number = ($count === 3)
+ ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
+ : (($temp[0] % 32) * 64) + ($temp[1] % 64);
+ $x[] = '|'.$number;
$count = 1;
$temp = array();
}
@@ -356,8 +352,7 @@ if ( ! function_exists('safe_mailto'))
//<![CDATA[
var l=new Array();
<?php
- $i = 0;
- foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
+ for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?>
for (var i = l.length-1; i >= 0; i=i-1){
if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
@@ -391,49 +386,46 @@ if ( ! function_exists('auto_link'))
{
function auto_link($str, $type = 'both', $popup = FALSE)
{
- if ($type != 'email')
+ if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
{
- if (preg_match_all("#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
- {
- $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
+ $pop = ($popup) ? ' target="_blank" ' : '';
- for ($i = 0; $i < count($matches['0']); $i++)
+ for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
+ {
+ if (preg_match('|\.$|', $matches[6][$i]))
+ {
+ $period = '.';
+ $matches[6][$i] = substr($matches[6][$i], 0, -1);
+ }
+ else
{
$period = '';
- if (preg_match("|\.$|", $matches['6'][$i]))
- {
- $period = '.';
- $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
- }
-
- $str = str_replace($matches['0'][$i],
- $matches['1'][$i].'<a href="http'.
- $matches['4'][$i].'://'.
- $matches['5'][$i].
- $matches['6'][$i].'"'.$pop.'>http'.
- $matches['4'][$i].'://'.
- $matches['5'][$i].
- $matches['6'][$i].'</a>'.
- $period, $str);
}
+
+ $str = str_replace($matches[0][$i],
+ $matches[1][$i].'<a href="http'.$matches[4][$i].'://'
+ .$matches[5][$i].$matches[6][$i].'"'.$pop.'>http'
+ .$matches[4][$i].'://'.$matches[5][$i]
+ .$matches[6][$i].'</a>'.$period,
+ $str);
}
}
- if ($type != 'url')
+ if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches))
{
- if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
+ for ($i = 0, $c = count($matches); $i < $c; $i++)
{
- for ($i = 0; $i < count($matches['0']); $i++)
+ if (preg_match('|\.$|', $matches[3][$i]))
+ {
+ $period = '.';
+ $matches[3][$i] = substr($matches[3][$i], 0, -1);
+ }
+ else
{
$period = '';
- if (preg_match("|\.$|", $matches['3'][$i]))
- {
- $period = '.';
- $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
- }
-
- $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
}
+
+ $str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str);
}
}
@@ -456,7 +448,7 @@ if ( ! function_exists('prep_url'))
{
function prep_url($str = '')
{
- if ($str == 'http://' OR $str == '')
+ if ($str === 'http://' OR $str == '')
{
return '';
}
@@ -465,7 +457,7 @@ if ( ! function_exists('prep_url'))
if ( ! $url OR ! isset($url['scheme']))
{
- $str = 'http://'.$str;
+ return 'http://'.$str;
}
return $str;
@@ -490,7 +482,7 @@ if ( ! function_exists('url_title'))
{
function url_title($str, $separator = 'dash', $lowercase = FALSE)
{
- if ($separator == 'dash')
+ if ($separator === 'dash')
{
$search = '_';
$replace = '-';
@@ -513,10 +505,9 @@ if ( ! function_exists('url_title'))
);
$str = strip_tags($str);
-
foreach ($trans as $key => $val)
{
- $str = preg_replace("#".$key."#i", $val, $str);
+ $str = preg_replace('#'.$key.'#i', $val, $str);
}
if ($lowercase === TRUE)
@@ -552,16 +543,18 @@ if ( ! function_exists('redirect'))
}
// IIS environment likely? Use 'refresh' for better compatibility
- if (DIRECTORY_SEPARATOR != '/' && $method == 'auto')
+ if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
{
$method = 'refresh';
}
switch($method)
{
- case 'refresh' : header("Refresh:0;url=".$uri);
+ case 'refresh':
+ header('Refresh:0;url='.$uri);
break;
- default : header("Location: ".$uri, TRUE, $http_response_code);
+ default:
+ header('Location: '.$uri, TRUE, $http_response_code);
break;
}
exit;
@@ -604,13 +597,12 @@ if ( ! function_exists('_parse_attributes'))
if ($javascript == TRUE AND $att != '')
{
- $att = substr($att, 0, -1);
+ return substr($att, 0, -1);
}
return $att;
}
}
-
/* End of file url_helper.php */
-/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/url_helper.php */
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index b38dab479..5242193ac 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -56,28 +56,26 @@ if ( ! function_exists('xml_convert'))
// ampersands won't get messed up
$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
- if ($protect_all === TRUE)
+ if ($protect_all == TRUE)
{
- $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
+ $str = preg_replace('/&(\w+);/', "$temp\\1;", $str);
}
- $str = str_replace(array("&","<",">","\"", "'", "-"),
- array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
- $str);
+ $str = str_replace(array('&', '<', '>', '"', "'", '-'),
+ array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
+ $str);
// Decode the temp markers back to entities
- $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
+ $str = preg_replace('/$temp(\d+);/', '&#\\1;', $str);
- if ($protect_all === TRUE)
+ if ($protect_all == TRUE)
{
- $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
+ return preg_replace("/$temp(\w+);/", '&\\1;', $str);
}
return $str;
}
}
-// ------------------------------------------------------------------------
-
/* End of file xml_helper.php */
-/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/xml_helper.php */
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index 93993d07a..a3dd46978 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -68,6 +68,7 @@ class CI_Cache_apc extends CI_Driver {
*/
public function save($id, $data, $ttl = 60)
{
+ $ttl = (int) $ttl;
return apc_store($id, array($data, time(), $ttl), $ttl);
}
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 4a81b0422..a960730d7 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -99,7 +99,7 @@ class CI_Cache_file extends CI_Driver {
if (write_file($this->_cache_path.$id, serialize($contents)))
{
- @chmod($this->_cache_path.$id, 0777);
+ @chmod($this->_cache_path.$id, 0660);
return TRUE;
}
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index ba8d69be2..10b5362a5 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -329,13 +329,6 @@ class CI_Cart {
return FALSE;
}
- // Is the new quantity different than what is already saved in the cart?
- // If it's the same there's nothing to do
- if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'])
- {
- return FALSE;
- }
-
// Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 922107e9f..c8a5b41af 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Email Class
*
@@ -40,55 +38,55 @@
*/
class CI_Email {
- public $useragent = "CodeIgniter";
- public $mailpath = "/usr/sbin/sendmail"; // Sendmail path
- public $protocol = "mail"; // mail/sendmail/smtp
- public $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net
- public $smtp_user = ""; // SMTP Username
- public $smtp_pass = ""; // SMTP Password
- public $smtp_port = "25"; // SMTP Port
- public $smtp_timeout = 5; // SMTP Timeout in seconds
- public $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl.
- public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
- public $wrapchars = "76"; // Number of characters to wrap at.
- public $mailtype = "text"; // text/html Defines email formatting
- public $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
- public $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
- public $alt_message = ''; // Alternative message for HTML emails
- public $validate = FALSE; // TRUE/FALSE. Enables email validation
- public $priority = "3"; // Default priority (1 - 5)
- public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
- public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
+ public $useragent = 'CodeIgniter';
+ public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
+ public $protocol = 'mail'; // mail/sendmail/smtp
+ public $smtp_host = ''; // SMTP Server. Example: mail.earthlink.net
+ public $smtp_user = ''; // SMTP Username
+ public $smtp_pass = ''; // SMTP Password
+ public $smtp_port = 25; // SMTP Port
+ public $smtp_timeout = 5; // SMTP Timeout in seconds
+ public $smtp_crypto = ''; // SMTP Encryption. Can be null, tls or ssl.
+ public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
+ public $wrapchars = 76; // Number of characters to wrap at.
+ public $mailtype = 'text'; // text/html Defines email formatting
+ public $charset = 'utf-8'; // Default char set: iso-8859-1 or us-ascii
+ public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
+ public $alt_message = ''; // Alternative message for HTML emails
+ public $validate = FALSE; // TRUE/FALSE. Enables email validation
+ public $priority = 3; // Default priority (1 - 5)
+ public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
+ public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
// even on the receiving end think they need to muck with CRLFs, so using "\n", while
// distasteful, is the only thing that seems to work for all environments.
public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
- public $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature
+ public $bcc_batch_mode = FALSE; // TRUE/FALSE - Turns on/off Bcc batch feature
public $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
- private $_safe_mode = FALSE;
- private $_subject = "";
- private $_body = "";
- private $_finalbody = "";
- private $_alt_boundary = "";
- private $_atc_boundary = "";
- private $_header_str = "";
- private $_smtp_connect = "";
- private $_encoding = "8bit";
- private $_IP = FALSE;
- private $_smtp_auth = FALSE;
- private $_replyto_flag = FALSE;
- private $_debug_msg = array();
- private $_recipients = array();
- private $_cc_array = array();
- private $_bcc_array = array();
- private $_headers = array();
- private $_attach_name = array();
- private $_attach_type = array();
- private $_attach_disp = array();
- private $_protocols = array('mail', 'sendmail', 'smtp');
- private $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
- private $_bit_depths = array('7bit', '8bit');
- private $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
+ protected $_safe_mode = FALSE;
+ protected $_subject = '';
+ protected $_body = '';
+ protected $_finalbody = '';
+ protected $_alt_boundary = '';
+ protected $_atc_boundary = '';
+ protected $_header_str = '';
+ protected $_smtp_connect = '';
+ protected $_encoding = '8bit';
+ protected $_IP = FALSE;
+ protected $_smtp_auth = FALSE;
+ protected $_replyto_flag = FALSE;
+ protected $_debug_msg = array();
+ protected $_recipients = array();
+ protected $_cc_array = array();
+ protected $_bcc_array = array();
+ protected $_headers = array();
+ protected $_attach_name = array();
+ protected $_attach_type = array();
+ protected $_attach_disp = array();
+ protected $_protocols = array('mail', 'sendmail', 'smtp');
+ protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
+ protected $_bit_depths = array('7bit', '8bit');
+ protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
/**
* Constructor - Sets Email Preferences
@@ -103,11 +101,11 @@ class CI_Email {
}
else
{
- $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
- $this->_safe_mode = (bool) @ini_get("safe_mode");
+ $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_safe_mode = (bool) @ini_get('safe_mode');
}
- log_message('debug', "Email Class Initialized");
+ log_message('debug', 'Email Class Initialized');
}
// --------------------------------------------------------------------
@@ -115,7 +113,6 @@ class CI_Email {
/**
* Initialize preferences
*
- * @access public
* @param array
* @return void
*/
@@ -139,8 +136,8 @@ class CI_Email {
}
$this->clear();
- $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
- $this->_safe_mode = (bool) @ini_get("safe_mode");
+ $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_safe_mode = (bool) @ini_get('safe_mode');
return $this;
}
@@ -150,17 +147,16 @@ class CI_Email {
/**
* Initialize the Email Data
*
- * @access public
* @param bool
- * @return void
+ * @return object
*/
public function clear($clear_attachments = FALSE)
{
- $this->_subject = "";
- $this->_body = "";
- $this->_finalbody = "";
- $this->_header_str = "";
- $this->_replyto_flag = FALSE;
+ $this->_subject = '';
+ $this->_body = '';
+ $this->_finalbody = '';
+ $this->_header_str = '';
+ $this->_replyto_flag = FALSE;
$this->_recipients = array();
$this->_cc_array = array();
$this->_bcc_array = array();
@@ -185,14 +181,13 @@ class CI_Email {
/**
* Set FROM
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function from($from, $name = '')
{
- if (preg_match( '/\<(.*)\>/', $from, $match))
+ if (preg_match('/\<(.*)\>/', $from, $match))
{
$from = $match[1];
}
@@ -228,14 +223,13 @@ class CI_Email {
/**
* Set Reply-to
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function reply_to($replyto, $name = '')
{
- if (preg_match( '/\<(.*)\>/', $replyto, $match))
+ if (preg_match('/\<(.*)\>/', $replyto, $match))
{
$replyto = $match[1];
}
@@ -266,9 +260,8 @@ class CI_Email {
/**
* Set Recipients
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function to($to)
{
@@ -282,17 +275,17 @@ class CI_Email {
if ($this->_get_protocol() !== 'mail')
{
- $this->_set_header('To', implode(", ", $to));
+ $this->_set_header('To', implode(', ', $to));
}
switch ($this->_get_protocol())
{
- case 'smtp' :
+ case 'smtp':
$this->_recipients = $to;
break;
- case 'sendmail' :
- case 'mail' :
- $this->_recipients = implode(", ", $to);
+ case 'sendmail':
+ case 'mail':
+ $this->_recipients = implode(', ', $to);
break;
}
@@ -304,9 +297,8 @@ class CI_Email {
/**
* Set CC
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function cc($cc)
{
@@ -318,7 +310,7 @@ class CI_Email {
$this->validate_email($cc);
}
- $this->_set_header('Cc', implode(", ", $cc));
+ $this->_set_header('Cc', implode(', ', $cc));
if ($this->_get_protocol() === 'smtp')
{
@@ -333,10 +325,9 @@ class CI_Email {
/**
* Set BCC
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function bcc($bcc, $limit = '')
{
@@ -360,7 +351,7 @@ class CI_Email {
}
else
{
- $this->_set_header('Bcc', implode(", ", $bcc));
+ $this->_set_header('Bcc', implode(', ', $bcc));
}
return $this;
@@ -371,9 +362,8 @@ class CI_Email {
/**
* Set Email Subject
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function subject($subject)
{
@@ -387,13 +377,12 @@ class CI_Email {
/**
* Set Body
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function message($body)
{
- $this->_body = rtrim(str_replace("\r", "", $body));
+ $this->_body = rtrim(str_replace("\r", '', $body));
/* strip slashes only if magic quotes is ON
if we do it with magic quotes OFF, it strips real, user-inputted chars.
@@ -414,9 +403,8 @@ class CI_Email {
/**
* Assign file attachments
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function attach($filename, $disposition = '', $newname = NULL)
{
@@ -431,7 +419,6 @@ class CI_Email {
/**
* Add a Header Item
*
- * @access protected
* @param string
* @param string
* @return void
@@ -446,7 +433,6 @@ class CI_Email {
/**
* Convert a String to an Array
*
- * @access protected
* @param string
* @return array
*/
@@ -460,8 +446,7 @@ class CI_Email {
}
else
{
- $email = trim($email);
- settype($email, "array");
+ $email = (array) trim($email);
}
}
return $email;
@@ -472,9 +457,8 @@ class CI_Email {
/**
* Set Multipart Value
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_alt_message($str = '')
{
@@ -487,9 +471,8 @@ class CI_Email {
/**
* Set Mailtype
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_mailtype($type = 'text')
{
@@ -502,9 +485,8 @@ class CI_Email {
/**
* Set Wordwrap
*
- * @access public
* @param bool
- * @return void
+ * @return object
*/
public function set_wordwrap($wordwrap = TRUE)
{
@@ -517,13 +499,12 @@ class CI_Email {
/**
* Set Protocol
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_protocol($protocol = 'mail')
{
- $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
+ $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail';
return $this;
}
@@ -532,19 +513,12 @@ class CI_Email {
/**
* Set Priority
*
- * @access public
- * @param integer
- * @return void
+ * @param int
+ * @return object
*/
public function set_priority($n = 3)
{
- if ( ! is_numeric($n) OR $n < 1 OR $n > 5)
- {
- $this->priority = 3;
- return;
- }
-
- $this->priority = (int) $n;
+ $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
return $this;
}
@@ -553,9 +527,8 @@ class CI_Email {
/**
* Set Newline Character
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_newline($newline = "\n")
{
@@ -568,13 +541,12 @@ class CI_Email {
/**
* Set CRLF
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_crlf($crlf = "\n")
{
- $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf;
+ $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf;
return $this;
}
@@ -583,13 +555,12 @@ class CI_Email {
/**
* Set Message Boundary
*
- * @access protected
* @return void
*/
protected function _set_boundaries()
{
- $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
- $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
+ $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative
+ $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary
}
// --------------------------------------------------------------------
@@ -597,14 +568,12 @@ class CI_Email {
/**
* Get the Message ID
*
- * @access protected
* @return string
*/
protected function _get_message_id()
{
$from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
-
- return "<".uniqid('').strstr($from, '@').">";
+ return '<'.uniqid('').strstr($from, '@').'>';
}
// --------------------------------------------------------------------
@@ -612,14 +581,13 @@ class CI_Email {
/**
* Get Mail Protocol
*
- * @access protected
* @param bool
- * @return string
+ * @return mixed
*/
protected function _get_protocol($return = TRUE)
{
$this->protocol = strtolower($this->protocol);
- $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
+ in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail';
if ($return == TRUE)
{
@@ -632,13 +600,12 @@ class CI_Email {
/**
* Get Mail Encoding
*
- * @access protected
* @param bool
* @return string
*/
protected function _get_encoding($return = TRUE)
{
- $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
+ in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit';
foreach ($this->_base_charsets as $charset)
{
@@ -659,7 +626,6 @@ class CI_Email {
/**
* Get content type (text/html/attachment)
*
- * @access protected
* @return string
*/
protected function _get_content_type()
@@ -687,17 +653,16 @@ class CI_Email {
/**
* Set RFC 822 Date
*
- * @access protected
* @return string
*/
protected function _set_date()
{
- $timezone = date("Z");
+ $timezone = date('Z');
$operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
$timezone = abs($timezone);
$timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
- return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
+ return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
}
// --------------------------------------------------------------------
@@ -705,12 +670,11 @@ class CI_Email {
/**
* Mime message
*
- * @access protected
* @return string
*/
protected function _get_mime_message()
{
- return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
+ return 'This is a multi-part message in MIME format.'.$this->newline.'Your email application may not support this format.';
}
// --------------------------------------------------------------------
@@ -718,7 +682,6 @@ class CI_Email {
/**
* Validate Email Address
*
- * @access public
* @param string
* @return bool
*/
@@ -747,13 +710,12 @@ class CI_Email {
/**
* Email Validation
*
- * @access public
* @param string
* @return bool
*/
public function valid_email($address)
{
- return (bool) preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address);
+ return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address);
}
// --------------------------------------------------------------------
@@ -761,7 +723,6 @@ class CI_Email {
/**
* Clean Extended Email Address: Joe Smith <joe@smith.com>
*
- * @access public
* @param string
* @return string
*/
@@ -776,7 +737,7 @@ class CI_Email {
foreach ($email as $addy)
{
- $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy;
+ $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy;
}
return $clean_email;
@@ -792,12 +753,11 @@ class CI_Email {
* If the user hasn't specified his own alternative message
* it creates one by stripping the HTML
*
- * @access protected
* @return string
*/
protected function _get_alt_message()
{
- if ($this->alt_message != "")
+ if ($this->alt_message != '')
{
return $this->word_wrap($this->alt_message, '76');
}
@@ -818,9 +778,8 @@ class CI_Email {
/**
* Word Wrap
*
- * @access public
* @param string
- * @param integer
+ * @param int
* @return string
*/
public function word_wrap($str, $charlim = '')
@@ -911,8 +870,6 @@ class CI_Email {
/**
* Build final headers
*
- * @access protected
- * @param string
* @return string
*/
protected function _build_headers()
@@ -929,7 +886,6 @@ class CI_Email {
/**
* Write Headers as a string
*
- * @access protected
* @return void
*/
protected function _write_headers()
@@ -964,12 +920,11 @@ class CI_Email {
/**
* Build Final Body and attachments
*
- * @access protected
* @return void
*/
protected function _build_message()
{
- if ($this->wordwrap === TRUE AND $this->mailtype !== 'html')
+ if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
{
$this->_body = $this->word_wrap($this->_body);
}
@@ -1131,9 +1086,8 @@ class CI_Email {
* Prepares string for Quoted-Printable Content-Transfer-Encoding
* Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
*
- * @access protected
* @param string
- * @param integer
+ * @param int
* @return string
*/
protected function _prep_quoted_printable($str, $charlim = '')
@@ -1203,9 +1157,7 @@ class CI_Email {
}
// get rid of extra CRLF tacked onto the end
- $output = substr($output, 0, strlen($this->crlf) * -1);
-
- return $output;
+ return substr($output, 0, strlen($this->crlf) * -1);
}
// --------------------------------------------------------------------
@@ -1216,10 +1168,9 @@ class CI_Email {
* Performs "Q Encoding" on a string for use in email headers. It's related
* but not identical to quoted-printable, so it has its own method
*
- * @access public
- * @param str
- * @param bool // set to TRUE for processing From: headers
- * @return str
+ * @param string
+ * @param bool set to TRUE for processing From: headers
+ * @return string
*/
protected function _prep_q_encoding($str, $from = FALSE)
{
@@ -1275,9 +1226,7 @@ class CI_Email {
// wrap each line with the shebang, charset, and transfer encoding
// the preceding space on successive lines is required for header "folding"
- $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
-
- return $str;
+ return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
}
// --------------------------------------------------------------------
@@ -1285,7 +1234,6 @@ class CI_Email {
/**
* Send Email
*
- * @access public
* @return bool
*/
public function send()
@@ -1295,9 +1243,9 @@ class CI_Email {
$this->reply_to($this->_headers['From']);
}
- if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
- ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
- ( ! isset($this->_headers['Cc'])))
+ if ( ! isset($this->_recipients) && ! isset($this->_headers['To'])
+ && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc'])
+ && ! isset($this->_headers['Cc']))
{
$this->_set_error_message('lang:email_no_recipients');
return FALSE;
@@ -1305,44 +1253,40 @@ class CI_Email {
$this->_build_headers();
- if ($this->bcc_batch_mode AND count($this->_bcc_array) > $this->bcc_batch_size)
+ if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
{
return $this->batch_bcc_send();
}
$this->_build_message();
-
return $this->_spool_email();
}
// --------------------------------------------------------------------
/**
- * Batch Bcc Send. Sends groups of BCCs in batches
+ * Batch Bcc Send. Sends groups of BCCs in batches
*
- * @access public
- * @return bool
+ * @return void
*/
public function batch_bcc_send()
{
- $float = $this->bcc_batch_size -1;
-
- $set = "";
-
+ $float = $this->bcc_batch_size - 1;
+ $set = '';
$chunk = array();
for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
{
if (isset($this->_bcc_array[$i]))
{
- $set .= ", ".$this->_bcc_array[$i];
+ $set .= ', '.$this->_bcc_array[$i];
}
if ($i == $float)
{
$chunk[] = substr($set, 1);
$float += $this->bcc_batch_size;
- $set = "";
+ $set = '';
}
if ($i === $c-1)
@@ -1359,7 +1303,7 @@ class CI_Email {
if ($this->protocol !== 'smtp')
{
- $this->_set_header('Bcc', implode(", ", $bcc));
+ $this->_set_header('Bcc', implode(', ', $bcc));
}
else
{
@@ -1376,7 +1320,6 @@ class CI_Email {
/**
* Unwrap special elements
*
- * @access protected
* @return void
*/
protected function _unwrap_specials()
@@ -1389,7 +1332,6 @@ class CI_Email {
/**
* Strip line-breaks via callback
*
- * @access protected
* @return string
*/
protected function _remove_nl_callback($matches)
@@ -1407,7 +1349,6 @@ class CI_Email {
/**
* Spool mail to the mail server
*
- * @access protected
* @return bool
*/
protected function _spool_email()
@@ -1429,7 +1370,6 @@ class CI_Email {
/**
* Send using mail()
*
- * @access protected
* @return bool
*/
protected function _send_with_mail()
@@ -1451,7 +1391,6 @@ class CI_Email {
/**
* Send using Sendmail
*
- * @access protected
* @return bool
*/
protected function _send_with_sendmail()
@@ -1484,7 +1423,6 @@ class CI_Email {
/**
* Send using SMTP
*
- * @access protected
* @return bool
*/
protected function _send_with_smtp()
@@ -1553,7 +1491,6 @@ class CI_Email {
/**
* SMTP Connect
*
- * @access protected
* @param string
* @return string
*/
@@ -1597,7 +1534,6 @@ class CI_Email {
/**
* Send SMTP command
*
- * @access protected
* @param string
* @param string
* @return string
@@ -1670,7 +1606,6 @@ class CI_Email {
/**
* SMTP Authenticate
*
- * @access protected
* @return bool
*/
protected function _smtp_authenticate()
@@ -1680,7 +1615,7 @@ class CI_Email {
return TRUE;
}
- if ($this->smtp_user == "" AND $this->smtp_pass == "")
+ if ($this->smtp_user == '' && $this->smtp_pass == '')
{
$this->_set_error_message('lang:email_no_smtp_unpw');
return FALSE;
@@ -1724,7 +1659,6 @@ class CI_Email {
/**
* Send SMTP data
*
- * @access protected
* @return bool
*/
protected function _send_data($data)
@@ -1743,7 +1677,6 @@ class CI_Email {
/**
* Get SMTP data
*
- * @access protected
* @return string
*/
protected function _get_smtp_data()
@@ -1768,12 +1701,11 @@ class CI_Email {
/**
* Get Hostname
*
- * @access protected
* @return string
*/
protected function _get_hostname()
{
- return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
+ return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
}
// --------------------------------------------------------------------
@@ -1781,7 +1713,6 @@ class CI_Email {
/**
* Get IP
*
- * @access protected
* @return string
*/
protected function _get_ip()
@@ -1791,13 +1722,13 @@ class CI_Email {
return $this->_IP;
}
- $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
- $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
+ $cip = ( ! empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
+ $rip = ( ! empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : FALSE;
if ($cip) $this->_IP = $cip;
elseif ($rip) $this->_IP = $rip;
else
{
- $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
+ $fip = ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
if ($fip)
{
$this->_IP = $fip;
@@ -1810,7 +1741,7 @@ class CI_Email {
$this->_IP = end($x);
}
- if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
+ if ( ! preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->_IP))
{
$this->_IP = '0.0.0.0';
}
@@ -1823,7 +1754,6 @@ class CI_Email {
/**
* Get Debug Message
*
- * @access public
* @return string
*/
public function print_debugger()
@@ -1838,8 +1768,7 @@ class CI_Email {
}
}
- $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
- return $msg;
+ return $msg.'<pre>'.$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
}
// --------------------------------------------------------------------
@@ -1847,16 +1776,15 @@ class CI_Email {
/**
* Set Message
*
- * @access protected
* @param string
- * @return string
+ * @return void
*/
protected function _set_error_message($msg, $val = '')
{
$CI =& get_instance();
$CI->lang->load('email');
- if (substr($msg, 0, 5) !== 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5))))
+ if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
{
$this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
}
@@ -1871,13 +1799,13 @@ class CI_Email {
/**
* Mime Types
*
- * @access protected
* @param string
* @return string
*/
- protected function _mime_types($ext = "")
+ protected function _mime_types($ext = '')
{
- $mimes = array( 'hqx' => 'application/mac-binhex40',
+ $mimes = array(
+ 'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'doc' => 'application/msword',
'bin' => 'application/macbinary',
@@ -1966,11 +1894,10 @@ class CI_Email {
'eml' => 'message/rfc822'
);
- return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
+ return isset($mimes[strtolower($ext)]) ? $mimes[strtolower($ext)] : 'application/x-unknown-content-type';
}
}
-// END CI_Email class
/* End of file Email.php */
/* Location: ./system/libraries/Email.php */
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index e297576e6..0b0618991 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Encryption Class
*
@@ -46,15 +44,10 @@ class CI_Encrypt {
protected $_mcrypt_cipher;
protected $_mcrypt_mode;
- /**
- * Constructor
- *
- * Simply determines whether the mcrypt library exists.
- */
public function __construct()
{
$this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE;
- log_message('debug', "Encrypt Class Initialized");
+ log_message('debug', 'Encrypt Class Initialized');
}
// --------------------------------------------------------------------
@@ -95,7 +88,7 @@ class CI_Encrypt {
* Set the encryption key
*
* @param string
- * @return void
+ * @return object
*/
public function set_key($key = '')
{
@@ -122,18 +115,8 @@ class CI_Encrypt {
*/
public function encode($string, $key = '')
{
- $key = $this->get_key($key);
-
- if ($this->_mcrypt_exists === TRUE)
- {
- $enc = $this->mcrypt_encode($string, $key);
- }
- else
- {
- $enc = $this->_xor_encode($string, $key);
- }
-
- return base64_encode($enc);
+ $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_encode' : '_xor_encode';
+ return base64_encode($this->$method($string, $this->get_key($key)));
}
// --------------------------------------------------------------------
@@ -149,28 +132,13 @@ class CI_Encrypt {
*/
public function decode($string, $key = '')
{
- $key = $this->get_key($key);
-
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
{
return FALSE;
}
- $dec = base64_decode($string);
-
- if ($this->_mcrypt_exists === TRUE)
- {
- if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
- {
- return FALSE;
- }
- }
- else
- {
- $dec = $this->_xor_decode($dec, $key);
- }
-
- return $dec;
+ $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_decode' : '_xor_decode';
+ return $this->$method(base64_decode($string), $this->get_key($key));
}
// --------------------------------------------------------------------
@@ -197,6 +165,10 @@ class CI_Encrypt {
log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.');
return FALSE;
}
+ elseif (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
+ {
+ return FALSE;
+ }
// decode it first
// set mode temporarily to what it was when string was encoded with the legacy
@@ -205,14 +177,7 @@ class CI_Encrypt {
$this->set_mode($legacy_mode);
$key = $this->get_key($key);
-
- if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
- {
- return FALSE;
- }
-
$dec = base64_decode($string);
-
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
return FALSE;
@@ -242,17 +207,18 @@ class CI_Encrypt {
protected function _xor_encode($string, $key)
{
$rand = '';
- while (strlen($rand) < 32)
+ do
{
$rand .= mt_rand(0, mt_getrandmax());
}
+ while (strlen($rand) < 32);
$rand = $this->hash($rand);
$enc = '';
- for ($i = 0; $i < strlen($string); $i++)
+ for ($i = 0, $ls = strlen($string), $lr = strlen($rand); $i < $ls; $i++)
{
- $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
+ $enc .= $rand[($i % $lr)].($rand[($i % $lr)] ^ $string[$i]);
}
return $this->_xor_merge($enc, $key);
@@ -275,9 +241,9 @@ class CI_Encrypt {
$string = $this->_xor_merge($string, $key);
$dec = '';
- for ($i = 0; $i < strlen($string); $i++)
+ for ($i = 0, $l = strlen($string); $i < $l; $i++)
{
- $dec .= (substr($string, $i++, 1) ^ substr($string, $i, 1));
+ $dec .= ($string[$i++] ^ $string[$i]);
}
return $dec;
@@ -298,9 +264,9 @@ class CI_Encrypt {
{
$hash = $this->hash($key);
$str = '';
- for ($i = 0; $i < strlen($string); $i++)
+ for ($i = 0, $ls = strlen($string), $lh = strlen($hash); $i < $ls; $i++)
{
- $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
+ $str .= $string[$i] ^ $hash[($i % $lh)];
}
return $str;
@@ -359,18 +325,17 @@ class CI_Encrypt {
*/
protected function _add_cipher_noise($data, $key)
{
- $keyhash = $this->hash($key);
- $keylen = strlen($keyhash);
+ $key = $this->hash($key);
$str = '';
- for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
+ for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j)
{
- if ($j >= $keylen)
+ if ($j >= $lk)
{
$j = 0;
}
- $str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256);
+ $str .= chr((ord($data[$i]) + ord($key[$j])) % 256);
}
return $str;
@@ -389,22 +354,21 @@ class CI_Encrypt {
*/
protected function _remove_cipher_noise($data, $key)
{
- $keyhash = $this->hash($key);
- $keylen = strlen($keyhash);
+ $key = $this->hash($key);
$str = '';
- for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
+ for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j)
{
- if ($j >= $keylen)
+ if ($j >= $lk)
{
$j = 0;
}
- $temp = ord($data[$i]) - ord($keyhash[$j]);
+ $temp = ord($data[$i]) - ord($key[$j]);
if ($temp < 0)
{
- $temp = $temp + 256;
+ $temp += 256;
}
$str .= chr($temp);
@@ -435,7 +399,7 @@ class CI_Encrypt {
* @param constant
* @return string
*/
- function set_mode($mode)
+ public function set_mode($mode)
{
$this->_mcrypt_mode = $mode;
return $this;
@@ -452,7 +416,7 @@ class CI_Encrypt {
{
if ($this->_mcrypt_cipher == '')
{
- $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256;
+ return $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256;
}
return $this->_mcrypt_cipher;
@@ -469,7 +433,7 @@ class CI_Encrypt {
{
if ($this->_mcrypt_mode == '')
{
- $this->_mcrypt_mode = MCRYPT_MODE_CBC;
+ return $this->_mcrypt_mode = MCRYPT_MODE_CBC;
}
return $this->_mcrypt_mode;
@@ -481,11 +445,11 @@ class CI_Encrypt {
* Set the Hash type
*
* @param string
- * @return string
+ * @return void
*/
public function set_hash($type = 'sha1')
{
- $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type;
+ $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type;
}
// --------------------------------------------------------------------
@@ -498,11 +462,9 @@ class CI_Encrypt {
*/
public function hash($str)
{
- return ($this->_hash_type == 'sha1') ? sha1($str) : md5($str);
+ return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str);
}
}
-// END CI_Encrypt class
-
/* End of file Encrypt.php */
-/* Location: ./system/libraries/Encrypt.php */ \ No newline at end of file
+/* Location: ./system/libraries/Encrypt.php */
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 0a6a2af0d..2ee734ae6 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -703,11 +703,11 @@ class CI_Form_validation {
*
* @param string the field name
* @param string
- * @return void
+ * @return string
*/
public function set_value($field = '', $default = '')
{
- if ( ! isset($this->_field_data[$field]))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
return $default;
}
@@ -736,13 +736,9 @@ class CI_Form_validation {
*/
public function set_select($field = '', $value = '', $default = FALSE)
{
- if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
- {
- return ' selected="selected"';
- }
- return '';
+ return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : '';
}
$field = $this->_field_data[$field]['postdata'];
@@ -754,12 +750,9 @@ class CI_Form_validation {
return '';
}
}
- else
+ elseif (($field == '' OR $value == '') OR ($field != $value))
{
- if (($field == '' OR $value == '') OR ($field != $value))
- {
- return '';
- }
+ return '';
}
return ' selected="selected"';
@@ -779,13 +772,9 @@ class CI_Form_validation {
*/
public function set_radio($field = '', $value = '', $default = FALSE)
{
- if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
- {
- return ' checked="checked"';
- }
- return '';
+ return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : '';
}
$field = $this->_field_data[$field]['postdata'];
@@ -869,9 +858,7 @@ class CI_Form_validation {
return FALSE;
}
- $field = $_POST[$field];
-
- return ($str === $field);
+ return ($str === $_POST[$field]);
}
// --------------------------------------------------------------------
@@ -908,7 +895,7 @@ class CI_Form_validation {
*/
public function min_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
@@ -932,7 +919,7 @@ class CI_Form_validation {
*/
public function max_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
@@ -956,7 +943,7 @@ class CI_Form_validation {
*/
public function exact_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
@@ -1170,7 +1157,7 @@ class CI_Form_validation {
*/
public function is_natural_no_zero($str)
{
- return ($str != 0 AND preg_match('/^[0-9]+$/', $str));
+ return ($str != 0 && preg_match('/^[0-9]+$/', $str));
}
// --------------------------------------------------------------------
@@ -1217,7 +1204,7 @@ class CI_Form_validation {
return $data;
}
- return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));
+ return str_replace(array("'", '"', '<', '>'), array('&#39;', '&quot;', '&lt;', '&gt;'), stripslashes($data));
}
// --------------------------------------------------------------------
@@ -1283,7 +1270,6 @@ class CI_Form_validation {
}
}
-// END Form Validation Class
/* End of file Form_validation.php */
/* Location: ./system/libraries/Form_validation.php */
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index c86224ffb..9826eabdd 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Image Manipulation class
*
@@ -88,12 +86,6 @@ class CI_Image_lib {
protected $wm_use_drop_shadow = FALSE;
public $wm_use_truetype = FALSE;
- /**
- * Constructor
- *
- * @param string
- * @return void
- */
public function __construct($props = array())
{
if (count($props) > 0)
@@ -101,7 +93,7 @@ class CI_Image_lib {
$this->initialize($props);
}
- log_message('debug', "Image Lib Class Initialized");
+ log_message('debug', 'Image Lib Class Initialized');
}
// --------------------------------------------------------------------
@@ -158,9 +150,7 @@ class CI_Image_lib {
*/
public function initialize($props = array())
{
- /*
- * Convert array elements into class variables
- */
+ // Convert array elements into class variables
if (count($props) > 0)
{
foreach ($props as $key => $val)
@@ -195,25 +185,18 @@ class CI_Image_lib {
}
}
- /*
- * Is there a source image?
- *
- * If not, there's no reason to continue
- *
- */
+ // Is there a source image? If not, there's no reason to continue
if ($this->source_image == '')
{
$this->set_error('imglib_source_image_required');
return FALSE;
}
- /*
- * Is getimagesize() Available?
+ /* Is getimagesize() available?
*
* We use it to determine the image properties (width/height).
- * Note: We need to figure out how to determine image
+ * Note: We need to figure out how to determine image
* properties using ImageMagick and NetPBM
- *
*/
if ( ! function_exists('getimagesize'))
{
@@ -223,17 +206,15 @@ class CI_Image_lib {
$this->image_library = strtolower($this->image_library);
- /*
- * Set the full server path
+ /* Set the full server path
*
* The source image may or may not contain a path.
* Either way, we'll try use realpath to generate the
* full server path in order to more reliably read it.
- *
*/
- if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE)
+ if (function_exists('realpath') && @realpath($this->source_image) !== FALSE)
{
- $full_source_path = str_replace("\\", "/", realpath($this->source_image));
+ $full_source_path = str_replace('\\', '/', realpath($this->source_image));
}
else
{
@@ -255,64 +236,58 @@ class CI_Image_lib {
*
* If the user has set a "new_image" name it means
* we are making a copy of the source image. If not
- * it means we are altering the original. We'll
+ * it means we are altering the original. We'll
* set the destination filename and path accordingly.
- *
*/
if ($this->new_image == '')
{
$this->dest_image = $this->source_image;
$this->dest_folder = $this->source_folder;
}
+ elseif (strpos($this->new_image, '/') === FALSE)
+ {
+ $this->dest_folder = $this->source_folder;
+ $this->dest_image = $this->new_image;
+ }
else
{
- if (strpos($this->new_image, '/') === FALSE)
+ if (strpos($this->new_image, '/') === FALSE AND strpos($this->new_image, '\\') === FALSE)
{
- $this->dest_folder = $this->source_folder;
- $this->dest_image = $this->new_image;
+ $full_dest_path = str_replace('\\', '/', realpath($this->new_image));
}
else
{
- if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE)
- {
- $full_dest_path = str_replace("\\", "/", realpath($this->new_image));
- }
- else
- {
- $full_dest_path = $this->new_image;
- }
+ $full_dest_path = $this->new_image;
+ }
- // Is there a file name?
- if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path))
- {
- $this->dest_folder = $full_dest_path.'/';
- $this->dest_image = $this->source_image;
- }
- else
- {
- $x = explode('/', $full_dest_path);
- $this->dest_image = end($x);
- $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
- }
+ // Is there a file name?
+ if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path))
+ {
+ $this->dest_folder = $full_dest_path.'/';
+ $this->dest_image = $this->source_image;
+ }
+ else
+ {
+ $x = explode('/', $full_dest_path);
+ $this->dest_image = end($x);
+ $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
}
}
- /*
- * Compile the finalized filenames/paths
+ /* Compile the finalized filenames/paths
*
* We'll create two master strings containing the
* full server path to the source image and the
* full server path to the destination image.
* We'll also split the destination image name
* so we can insert the thumbnail marker if needed.
- *
*/
if ($this->create_thumb === FALSE OR $this->thumb_marker == '')
{
$this->thumb_marker = '';
}
- $xp = $this->explode_name($this->dest_image);
+ $xp = $this->explode_name($this->dest_image);
$filename = $xp['name'];
$file_ext = $xp['ext'];
@@ -320,54 +295,55 @@ class CI_Image_lib {
$this->full_src_path = $this->source_folder.$this->source_image;
$this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;
- /*
- * Should we maintain image proportions?
+ /* Should we maintain image proportions?
*
* When creating thumbs or copies, the target width/height
* might not be in correct proportion with the source
- * image's width/height. We'll recalculate it here.
- *
+ * image's width/height. We'll recalculate it here.
*/
- if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != ''))
+ if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0))
{
$this->image_reproportion();
}
- /*
- * Was a width and height specified?
- *
- * If the destination width/height was
- * not submitted we will use the values
- * from the actual file
+ /* Was a width and height specified?
*
+ * If the destination width/height was not submitted we
+ * will use the values from the actual file
*/
if ($this->width == '')
+ {
$this->width = $this->orig_width;
+ }
if ($this->height == '')
+ {
$this->height = $this->orig_height;
+ }
// Set the quality
- $this->quality = trim(str_replace("%", "", $this->quality));
+ $this->quality = trim(str_replace('%', '', $this->quality));
- if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality))
+ if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality))
+ {
$this->quality = 90;
+ }
// Set the x/y coordinates
- $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis;
- $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis;
+ $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis;
+ $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis;
// Watermark-related Stuff...
if ($this->wm_overlay_path != '')
{
- $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path));
+ $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path));
}
if ($this->wm_shadow_color != '')
{
$this->wm_use_drop_shadow = TRUE;
}
- elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '')
+ elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '')
{
$this->wm_use_drop_shadow = FALSE;
}
@@ -392,7 +368,7 @@ class CI_Image_lib {
*/
public function resize()
{
- $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
+ $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
return $this->$protocol('resize');
}
@@ -408,7 +384,7 @@ class CI_Image_lib {
*/
public function crop()
{
- $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
+ $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
return $this->$protocol('crop');
}
@@ -445,22 +421,16 @@ class CI_Image_lib {
$this->height = $this->orig_height;
}
-
// Choose resizing function
- if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
+ if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm')
{
$protocol = 'image_process_'.$this->image_library;
return $this->$protocol('rotate');
}
- if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt')
- {
- return $this->image_mirror_gd();
- }
- else
- {
- return $this->image_rotate_gd();
- }
+ return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
+ ? $this->image_mirror_gd()
+ : $this->image_rotate_gd();
}
// --------------------------------------------------------------------
@@ -479,9 +449,9 @@ class CI_Image_lib {
// If the target width/height match the source, AND if the new file name is not equal to the old file name
// we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
- if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height)
+ if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height)
{
- if ($this->source_image != $this->new_image AND @copy($this->full_src_path, $this->full_dst_path))
+ if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path))
{
@chmod($this->full_dst_path, FILE_WRITE_MODE);
}
@@ -492,7 +462,7 @@ class CI_Image_lib {
// Let's set up our values based on the action
if ($action == 'crop')
{
- // Reassign the source width/height if cropping
+ // Reassign the source width/height if cropping
$this->orig_width = $this->width;
$this->orig_height = $this->height;
@@ -516,14 +486,15 @@ class CI_Image_lib {
return FALSE;
}
- // Create The Image
- //
- // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
- // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
- // below should that ever prove inaccurate.
- //
- // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE)
- if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
+ /* Create the image
+ *
+ * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
+ * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
+ * below should that ever prove inaccurate.
+ *
+ * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE)
+ */
+ if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
@@ -544,21 +515,17 @@ class CI_Image_lib {
$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
- // Show the image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($dst_img);
}
- else
+ elseif ( ! $this->image_save_gd($dst_img)) // Or save it
{
- // Or save it
- if ( ! $this->image_save_gd($dst_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
@@ -587,42 +554,34 @@ class CI_Image_lib {
return FALSE;
}
- if ( ! preg_match("/convert$/i", $this->library_path))
+ if ( ! preg_match('/convert$/i', $this->library_path))
{
$this->library_path = rtrim($this->library_path, '/').'/convert';
}
// Execute the command
- $cmd = $this->library_path." -quality ".$this->quality;
+ $cmd = $this->library_path.' -quality '.$this->quality;
if ($action == 'crop')
{
- $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1';
}
elseif ($action == 'rotate')
{
- switch ($this->rotation_angle)
- {
- case 'hor' : $angle = '-flop';
- break;
- case 'vrt' : $angle = '-flip';
- break;
- default : $angle = '-rotate '.$this->rotation_angle;
- break;
- }
+ $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
+ ? '-flop' : '-rotate '.$this->rotation_angle;
- $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}
- else // Resize
+ else // Resize
{
- $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}
$retval = 1;
-
@exec($cmd, $output, $retval);
- // Did it work?
+ // Did it work?
if ($retval > 0)
{
$this->set_error('imglib_image_process_failed');
@@ -653,7 +612,7 @@ class CI_Image_lib {
return FALSE;
}
- // Build the resizing command
+ // Build the resizing command
switch ($this->image_type)
{
case 1 :
@@ -700,10 +659,9 @@ class CI_Image_lib {
$cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
$retval = 1;
-
@exec($cmd, $output, $retval);
- // Did it work?
+ // Did it work?
if ($retval > 0)
{
$this->set_error('imglib_image_process_failed');
@@ -714,7 +672,7 @@ class CI_Image_lib {
// If you try manipulating the original it fails so
// we have to rename the temp file.
copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
- unlink ($this->dest_folder.'netpbm.tmp');
+ unlink($this->dest_folder.'netpbm.tmp');
@chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
@@ -729,7 +687,7 @@ class CI_Image_lib {
*/
public function image_rotate_gd()
{
- // Create the image handle
+ // Create the image handle
if ( ! ($src_img = $this->image_create_gd()))
{
return FALSE;
@@ -742,29 +700,24 @@ class CI_Image_lib {
$white = imagecolorallocate($src_img, 255, 255, 255);
- // Rotate it!
+ // Rotate it!
$dst_img = imagerotate($src_img, $this->rotation_angle, $white);
- // Save the Image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($dst_img);
}
- else
+ elseif ( ! $this->image_save_gd($dst_img)) // ... or save it
{
- // Or save it
- if ( ! $this->image_save_gd($dst_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
// Set the file to 777
-
@chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
@@ -789,7 +742,7 @@ class CI_Image_lib {
$width = $this->orig_width;
$height = $this->orig_height;
- if ($this->rotation_angle == 'hor')
+ if ($this->rotation_angle === 'hor')
{
for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1)
{
@@ -824,21 +777,17 @@ class CI_Image_lib {
}
}
- // Show the image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
}
- else
+ elseif ( ! $this->image_save_gd($src_img)) // ... or save it
{
- // Or save it
- if ( ! $this->image_save_gd($src_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($src_img);
// Set the file to 777
@@ -860,14 +809,7 @@ class CI_Image_lib {
*/
public function watermark()
{
- if ($this->wm_type == 'overlay')
- {
- return $this->overlay_watermark();
- }
- else
- {
- return $this->text_watermark();
- }
+ return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
}
// --------------------------------------------------------------------
@@ -885,28 +827,28 @@ class CI_Image_lib {
return FALSE;
}
- // Fetch source image properties
+ // Fetch source image properties
$this->get_image_properties();
- // Fetch watermark image properties
- $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
+ // Fetch watermark image properties
+ $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
$wm_img_type = $props['image_type'];
- $wm_width = $props['width'];
- $wm_height = $props['height'];
+ $wm_width = $props['width'];
+ $wm_height = $props['height'];
- // Create two image resources
+ // Create two image resources
$wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
$src_img = $this->image_create_gd($this->full_src_path);
// Reverse the offset if necessary
// When the image is positioned at the bottom
// we don't want the vertical offset to push it
- // further down. We want the reverse, so we'll
- // invert the offset. Same with the horizontal
+ // further down. We want the reverse, so we'll
+ // invert the offset. Same with the horizontal
// offset when the image is at the right
- $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
- $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
+ $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
+ $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
if ($this->wm_vrt_alignment == 'B')
$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
@@ -914,34 +856,32 @@ class CI_Image_lib {
if ($this->wm_hor_alignment == 'R')
$this->wm_hor_offset = $this->wm_hor_offset * -1;
- // Set the base x and y axis values
+ // Set the base x and y axis values
$x_axis = $this->wm_hor_offset + $this->wm_padding;
$y_axis = $this->wm_vrt_offset + $this->wm_padding;
- // Set the vertical position
- switch ($this->wm_vrt_alignment)
+ // Set the vertical position
+ if ($this->wm_vrt_alignment === 'M')
{
- case 'T':
- break;
- case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
- break;
- case 'B': $y_axis += $this->orig_height - $wm_height;
- break;
+ $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
+ }
+ elseif ($this->wm_vrt_alignment === 'B')
+ {
+ $y_axis += $this->orig_height - $wm_height;
}
- // Set the horizontal position
- switch ($this->wm_hor_alignment)
+ // Set the horizontal position
+ if ($this->wm_hor_alignment === 'C')
{
- case 'L':
- break;
- case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
- break;
- case 'R': $x_axis += $this->orig_width - $wm_width;
- break;
+ $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
+ }
+ elseif ($this->wm_hor_alignment === 'R')
+ {
+ $x_axis += $this->orig_width - $wm_width;
}
// Build the finalized image
- if ($wm_img_type == 3 AND function_exists('imagealphablending'))
+ if ($wm_img_type == 3 && function_exists('imagealphablending'))
{
@imagealphablending($src_img, TRUE);
}
@@ -963,12 +903,12 @@ class CI_Image_lib {
imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
}
- // Output the image
+ // Output the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
}
- elseif ( ! $this->image_save_gd($src_img))
+ elseif ( ! $this->image_save_gd($src_img)) // ... or save it
{
return FALSE;
}
@@ -993,20 +933,20 @@ class CI_Image_lib {
return FALSE;
}
- if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path))
+ if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path))
{
$this->set_error('imglib_missing_font');
return FALSE;
}
- // Fetch source image properties
+ // Fetch source image properties
$this->get_image_properties();
// Reverse the vertical offset
// When the image is positioned at the bottom
// we don't want the vertical offset to push it
- // further down. We want the reverse, so we'll
- // invert the offset. Note: The horizontal
+ // further down. We want the reverse, so we'll
+ // invert the offset. Note: The horizontal
// offset flips itself automatically
if ($this->wm_vrt_alignment == 'B')
@@ -1039,49 +979,39 @@ class CI_Image_lib {
$x_axis = $this->wm_hor_offset + $this->wm_padding;
$y_axis = $this->wm_vrt_offset + $this->wm_padding;
- // Set verticle alignment
if ($this->wm_use_drop_shadow == FALSE)
$this->wm_shadow_distance = 0;
$this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
$this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
- switch ($this->wm_vrt_alignment)
+ // Set verticle alignment
+ if ($this->wm_vrt_alignment === 'M')
{
- case 'T':
- break;
- case 'M': $y_axis += ($this->orig_height/2)+($fontheight/2);
- break;
- case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2));
- break;
+ $y_axis += ($this->orig_height / 2) + ($fontheight / 2);
+ }
+ elseif ($this->wm_vrt_alignment === 'B')
+ {
+ $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2);
}
$x_shad = $x_axis + $this->wm_shadow_distance;
$y_shad = $y_axis + $this->wm_shadow_distance;
- // Set horizontal alignment
- switch ($this->wm_hor_alignment)
- {
- case 'L':
- break;
- case 'R':
- if ($this->wm_use_drop_shadow)
- {
- $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text));
- $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text));
- }
- break;
- case 'C':
- if ($this->wm_use_drop_shadow)
- {
- $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
- $x_axis += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
- }
- break;
- }
-
if ($this->wm_use_drop_shadow)
{
+ // Set horizontal alignment
+ if ($this->wm_hor_alignment === 'R')
+ {
+ $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text));
+ $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text));
+ }
+ elseif ($this->wm_hor_alignment === 'C')
+ {
+ $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
+ $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
+ }
+
/* Set RGB values for text and shadow
*
* First character is #, so we don't really need it.
@@ -1091,9 +1021,9 @@ class CI_Image_lib {
$txt_color = str_split(substr($this->wm_font_color, 1, 6), 2);
$txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2]));
$drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2);
- $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[2]), hexdec($drp_color[3]));
+ $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2]));
- // Add the text to the source image
+ // Add the text to the source image
if ($this->wm_use_truetype)
{
imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
@@ -1106,7 +1036,7 @@ class CI_Image_lib {
}
}
- // Output the final image
+ // Output the final image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
@@ -1250,8 +1180,8 @@ class CI_Image_lib {
*/
public function image_display_gd($resource)
{
- header("Content-Disposition: filename={$this->source_image};");
- header("Content-Type: {$this->mime_type}");
+ header('Content-Disposition: filename='.$this->source_image.';');
+ header('Content-Type: '.$this->mime_type);
header('Content-Transfer-Encoding: binary');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
@@ -1284,33 +1214,43 @@ class CI_Image_lib {
*/
public function image_reproportion()
{
- if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0)
- return;
-
- if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0)
- return;
-
- $new_width = ceil($this->orig_width*$this->height/$this->orig_height);
- $new_height = ceil($this->width*$this->orig_height/$this->orig_width);
-
- $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width));
-
- if ($this->master_dim != 'width' AND $this->master_dim != 'height')
+ if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0
+ OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height))
+ OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height))
{
- $this->master_dim = ($ratio < 0) ? 'width' : 'height';
+ return;
}
- if (($this->width != $new_width) AND ($this->height != $new_height))
+ // Sanitize so we don't call preg_match() anymore
+ $this->width = (int) $this->width;
+ $this->height = (int) $this->height;
+
+ if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
{
- if ($this->master_dim == 'height')
+ if ($this->width > 0 && $this->height > 0)
{
- $this->width = $new_width;
+ $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
+ ? 'width' : 'height';
}
else
{
- $this->height = $new_height;
+ $this->master_dim = ($this->height === 0) ? 'width' : 'height';
}
}
+ elseif (($this->master_dim === 'width' && $this->width === 0)
+ OR ($this->master_dim === 'height' && $this->height === 0))
+ {
+ return;
+ }
+
+ if ($this->master_dim === 'width')
+ {
+ $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
+ }
+ else
+ {
+ $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
+ }
}
// --------------------------------------------------------------------
@@ -1329,7 +1269,9 @@ class CI_Image_lib {
// find a way to determine this using IM or NetPBM
if ($path == '')
+ {
$path = $this->full_src_path;
+ }
if ( ! file_exists($path))
{
@@ -1367,15 +1309,15 @@ class CI_Image_lib {
* Size calculator
*
* This function takes a known width x height and
- * recalculates it to a new size. Only one
+ * recalculates it to a new size. Only one
* new variable needs to be known
*
* $props = array(
- * 'width' => $width,
- * 'height' => $height,
- * 'new_width' => 40,
- * 'new_height' => ''
- * );
+ * 'width' => $width,
+ * 'height' => $height,
+ * 'new_width' => 40,
+ * 'new_height' => ''
+ * );
*
* @param array
* @return array
@@ -1419,7 +1361,7 @@ class CI_Image_lib {
*
* This is a helper function that extracts the extension
* from the source_image. This function lets us deal with
- * source_images with multiple periods, like: my.cool.jpg
+ * source_images with multiple periods, like: my.cool.jpg
* It returns an associative array with two elements:
* $array['ext'] = '.jpg';
* $array['name'] = 'my.cool';
@@ -1449,7 +1391,7 @@ class CI_Image_lib {
/* As it is stated in the PHP manual, dl() is not always available
* and even if so - it could generate an E_WARNING message on failure
*/
- return (function_exists('dl') AND @dl('gd.so'));
+ return (function_exists('dl') && @dl('gd.so'));
}
return TRUE;
@@ -1467,9 +1409,7 @@ class CI_Image_lib {
if (function_exists('gd_info'))
{
$gd_version = @gd_info();
- $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']);
-
- return $gd_version;
+ return preg_replace('/\D/', '', $gd_version['GD Version']);
}
return FALSE;
@@ -1516,11 +1456,10 @@ class CI_Image_lib {
*/
public function display_errors($open = '<p>', $close = '</p>')
{
- return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : '';
+ return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
}
}
-// END Image_lib Class
/* End of file Image_lib.php */
/* Location: ./system/libraries/Image_lib.php */
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index c59151bad..35ac541e8 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -128,7 +128,7 @@ class CI_Pagination {
}
// Calculate the total number of pages
- $num_pages = ceil($this->total_rows / $this->per_page);
+ $num_pages = (int) ceil($this->total_rows / $this->per_page);
// Is there only one page? Hm... nothing more to do here then.
if ($num_pages === 1)
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 04103a4d9..66b39a6a2 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Session Class
*
@@ -67,7 +65,7 @@ class CI_Session {
*/
public function __construct($params = array())
{
- log_message('debug', "Session Class Initialized");
+ log_message('debug', 'Session Class Initialized');
// Set the super object to a local variable for use throughout the class
$this->CI =& get_instance();
@@ -93,14 +91,14 @@ class CI_Session {
$this->CI->load->library('encrypt');
}
- // Are we using a database? If so, load it
- if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
+ // Are we using a database? If so, load it
+ if ($this->sess_use_database === TRUE && $this->sess_table_name != '')
{
$this->CI->load->database();
}
- // Set the "now" time. Can either be GMT or server time, based on the
- // config prefs. We use this to set the "last activity" time
+ // Set the "now" time. Can either be GMT or server time, based on the
+ // config prefs. We use this to set the "last activity" time
$this->now = $this->_get_time();
// Set the session length. If the session expiration is
@@ -114,7 +112,7 @@ class CI_Session {
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
// Run the Session routine. If a session doesn't exist we'll
- // create a new one. If it does, we'll update it.
+ // create a new one. If it does, we'll update it.
if ( ! $this->sess_read())
{
$this->sess_create();
@@ -133,7 +131,7 @@ class CI_Session {
// Delete expired sessions if necessary
$this->_sess_gc();
- log_message('debug', "Session routines successfully run");
+ log_message('debug', 'Session routines successfully run');
}
// --------------------------------------------------------------------
@@ -166,7 +164,7 @@ class CI_Session {
$hash = substr($session, strlen($session)-32); // get last 32 chars
$session = substr($session, 0, strlen($session)-32);
- // Does the md5 hash match? This is to prevent manipulation of session data in userspace
+ // Does the md5 hash match? This is to prevent manipulation of session data in userspace
if ($hash !== md5($session.$this->encryption_key))
{
log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
@@ -179,7 +177,7 @@ class CI_Session {
$session = $this->_unserialize($session);
// Is the session data we unserialized an array with the correct format?
- if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity']))
+ if ( ! is_array($session) OR ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], $session['last_activity']))
{
$this->sess_destroy();
return FALSE;
@@ -192,15 +190,15 @@ class CI_Session {
return FALSE;
}
- // Does the IP Match?
- if ($this->sess_match_ip == TRUE AND $session['ip_address'] !== $this->CI->input->ip_address())
+ // Does the IP match?
+ if ($this->sess_match_ip == TRUE && $session['ip_address'] !== $this->CI->input->ip_address())
{
$this->sess_destroy();
return FALSE;
}
// Does the User Agent Match?
- if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
+ if ($this->sess_match_useragent == TRUE && trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
{
$this->sess_destroy();
return FALSE;
@@ -223,7 +221,7 @@ class CI_Session {
$query = $this->CI->db->get($this->sess_table_name);
- // No result? Kill it!
+ // No result? Kill it!
if ($query->num_rows() === 0)
{
$this->sess_destroy();
@@ -232,7 +230,7 @@ class CI_Session {
// Is there custom data? If so, add it to the main session array
$row = $query->row();
- if (isset($row->user_data) AND $row->user_data != '')
+ if (isset($row->user_data) && $row->user_data != '')
{
$custom_data = $this->_unserialize($row->user_data);
@@ -282,7 +280,7 @@ class CI_Session {
$cookie_userdata[$val] = $this->userdata[$val];
}
- // Did we find any custom data? If not, we turn the empty array into a string
+ // Did we find any custom data? If not, we turn the empty array into a string
// since there's no reason to serialize and store an empty array in the DB
if (count($custom_userdata) === 0)
{
@@ -298,7 +296,7 @@ class CI_Session {
$this->CI->db->where('session_id', $this->userdata['session_id']);
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
- // Write the cookie. Notice that we manually pass the cookie data array to the
+ // Write the cookie. Notice that we manually pass the cookie data array to the
// _set_cookie() function. Normally that function will store $this->userdata, but
// in this case that array contains custom data, which we do not want in the cookie.
$this->_set_cookie($cookie_userdata);
@@ -324,13 +322,12 @@ class CI_Session {
$sessid .= $this->CI->input->ip_address();
$this->userdata = array(
- 'session_id' => md5(uniqid($sessid, TRUE)),
- 'ip_address' => $this->CI->input->ip_address(),
- 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
- 'last_activity' => $this->now,
- 'user_data' => ''
- );
-
+ 'session_id' => md5(uniqid($sessid, TRUE)),
+ 'ip_address' => $this->CI->input->ip_address(),
+ 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
+ 'last_activity' => $this->now,
+ 'user_data' => ''
+ );
// Save the data to the DB if needed
if ($this->sess_use_database === TRUE)
@@ -357,6 +354,35 @@ class CI_Session {
return;
}
+ // _set_cookie() will handle this for us if we aren't using database sessions
+ // by pushing all userdata to the cookie.
+ $cookie_data = NULL;
+
+ /* Changing the session ID during an AJAX call causes problems,
+ * so we'll only update our last_activity
+ */
+ if ($this->CI->input->is_ajax_request())
+ {
+ $this->userdata['last_activity'] = $this->now;
+
+ // Update the session ID and last_activity field in the DB if needed
+ if ($this->sess_use_database === TRUE)
+ {
+ // set cookie explicitly to only have our session data
+ $cookie_data = array();
+ foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ {
+ $cookie_data[$val] = $this->userdata[$val];
+ }
+
+ $this->CI->db->query($this->CI->db->update_string($this->sess_table_name,
+ array('last_activity' => $this->userdata['last_activity']),
+ array('session_id' => $this->userdata['session_id'])));
+ }
+
+ return $this->_set_cookie($cookie_data);
+ }
+
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
@@ -374,10 +400,6 @@ class CI_Session {
$this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE));
$this->userdata['last_activity'] = $this->now;
- // _set_cookie() will handle this for us if we aren't using database sessions
- // by pushing all userdata to the cookie.
- $cookie_data = NULL;
-
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{
@@ -405,7 +427,7 @@ class CI_Session {
public function sess_destroy()
{
// Kill the session DB row
- if ($this->sess_use_database === TRUE AND isset($this->userdata['session_id']))
+ if ($this->sess_use_database === TRUE && isset($this->userdata['session_id']))
{
$this->CI->db->where('session_id', $this->userdata['session_id']);
$this->CI->db->delete($this->sess_table_name);
@@ -413,13 +435,13 @@ class CI_Session {
// Kill the cookie
setcookie(
- $this->sess_cookie_name,
- addslashes(serialize(array())),
- ($this->now - 31500000),
- $this->cookie_path,
- $this->cookie_domain,
- 0
- );
+ $this->sess_cookie_name,
+ addslashes(serialize(array())),
+ ($this->now - 31500000),
+ $this->cookie_path,
+ $this->cookie_domain,
+ 0
+ );
}
// --------------------------------------------------------------------
@@ -535,7 +557,7 @@ class CI_Session {
*/
public function keep_flashdata($key)
{
- // 'old' flashdata gets removed. Here we mark all
+ // 'old' flashdata gets removed. Here we mark all
// flashdata as 'new' to preserve it from _flashdata_sweep()
// Note the function will return FALSE if the $key
// provided cannot be found
@@ -586,7 +608,6 @@ class CI_Session {
*
* @return void
*/
-
protected function _flashdata_sweep()
{
$userdata = $this->all_userdata();
@@ -609,13 +630,9 @@ class CI_Session {
*/
protected function _get_time()
{
- if (strtolower($this->time_reference) === 'gmt')
- {
- $now = time();
- return mktime(gmdate('H', $now), gmdate('i', $now), gmdate('s', $now), gmdate('m', $now), gmdate('d', $now), gmdate('Y', $now));
- }
-
- return time();
+ return (strtolower($this->time_reference) === 'gmt')
+ ? mktime(gmdate('H'), gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y'))
+ : time();
}
// --------------------------------------------------------------------
@@ -649,13 +666,13 @@ class CI_Session {
// Set the cookie
setcookie(
- $this->sess_cookie_name,
- $cookie_data,
- $expire,
- $this->cookie_path,
- $this->cookie_domain,
- $this->cookie_secure
- );
+ $this->sess_cookie_name,
+ $cookie_data,
+ $expire,
+ $this->cookie_path,
+ $this->cookie_domain,
+ $this->cookie_secure
+ );
}
// --------------------------------------------------------------------
@@ -687,8 +704,11 @@ class CI_Session {
*
* This function converts any slashes found into a temporary marker
*
+ * @param string
+ * @param string
+ * @return void
*/
- function _escape_slashes(&$val, $key)
+ protected function _escape_slashes(&$val, $key)
{
if (is_string($val))
{
@@ -725,6 +745,9 @@ class CI_Session {
*
* This function converts any slash markers back into actual slashes
*
+ * @param string
+ * @param string
+ * @return void
*/
protected function _unescape_slashes(&$val, $key)
{
@@ -763,9 +786,7 @@ class CI_Session {
}
}
-
}
-// END Session Class
/* End of file Session.php */
/* Location: ./system/libraries/Session.php */
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 76f0d4fc5..46c73ef8b 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -144,7 +144,7 @@ class CI_Typography {
$process = TRUE;
$paragraph = FALSE;
- for ($i = 1, $c = count($chunks); $i <= $c; $i++)
+ for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i++)
{
// Are we dealing with a tag? If so, we'll skip the processing for this cycle.
// Well also set the "process" flag which allows us to skip <pre> tags and a few other things.
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 0c63886e7..ac29c1bdd 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -593,16 +593,17 @@ class CI_Upload {
/**
* Verify that the filetype is allowed
*
+ * @param bool
* @return bool
*/
public function is_allowed_filetype($ignore_mime = FALSE)
{
- if ($this->allowed_types == '*')
+ if ($this->allowed_types === '*')
{
return TRUE;
}
- if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
+ if ( ! is_array($this->allowed_types) OR count($this->allowed_types) === 0)
{
$this->set_error('upload_no_file_types');
return FALSE;
@@ -618,12 +619,9 @@ class CI_Upload {
// Images get some additional checks
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
- if (in_array($ext, $image_types))
+ if (in_array($ext, $image_types) && @getimagesize($this->file_temp) === FALSE)
{
- if (getimagesize($this->file_temp) === FALSE)
- {
- return FALSE;
- }
+ return FALSE;
}
if ($ignore_mime === TRUE)
@@ -640,7 +638,7 @@ class CI_Upload {
return TRUE;
}
}
- elseif ($mime == $this->file_type)
+ elseif ($mime === $this->file_type)
{
return TRUE;
}
@@ -960,7 +958,7 @@ class CI_Upload {
}
elseif (is_file(APPPATH.'config/mimes.php'))
{
- include(APPPATH.'config//mimes.php');
+ include(APPPATH.'config/mimes.php');
}
else
{
@@ -1026,47 +1024,104 @@ class CI_Upload {
*/
protected function _file_mime_type($file)
{
- // Use if the Fileinfo extension, if available (only versions above 5.3 support the FILEINFO_MIME_TYPE flag)
- if ( (float) substr(phpversion(), 0, 3) >= 5.3 && function_exists('finfo_file'))
+ // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
+ $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
+
+ /* Fileinfo extension - most reliable method
+ *
+ * Unfortunately, prior to PHP 5.3 - it's only available as a PECL extension and the
+ * more convenient FILEINFO_MIME_TYPE flag doesn't exist.
+ */
+ if (function_exists('finfo_file'))
{
- $finfo = new finfo(FILEINFO_MIME_TYPE);
- if ($finfo !== FALSE) // This is possible, if there is no magic MIME database file found on the system
+ $finfo = finfo_open(FILEINFO_MIME);
+ if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
{
- $file_type = $finfo->file($file['tmp_name']);
+ $mime = @finfo_file($finfo, $file['tmp_name']);
+ finfo_close($finfo);
/* According to the comments section of the PHP manual page,
* it is possible that this function returns an empty string
* for some files (e.g. if they don't exist in the magic MIME database)
*/
- if (strlen($file_type) > 1)
+ if (is_string($mime) && preg_match($regexp, $mime, $matches))
{
- $this->file_type = $file_type;
+ $this->file_type = $matches[1];
return;
}
}
}
- // Fall back to the deprecated mime_content_type(), if available
- if (function_exists('mime_content_type'))
- {
- $this->file_type = @mime_content_type($file['tmp_name']);
- return;
- }
-
- /* This is an ugly hack, but UNIX-type systems provide a native way to detect the file type,
- * which is still more secure than depending on the value of $_FILES[$field]['type'].
+ /* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
+ * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
+ * was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
+ * than mime_content_type() as well, hence the attempts to try calling the command line with
+ * three different functions.
*
* Notes:
- * - a 'W' in the substr() expression bellow, would mean that we're using Windows
- * - many system admins would disable the exec() function due to security concerns, hence the function_exists() check
+ * - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
+ * - many system admins would disable the exec(), shell_exec(), popen() and similar functions
+ * due to security concerns, hence the function_exists() checks
*/
- if (DIRECTORY_SEPARATOR !== '\\' && function_exists('exec'))
+ if (DIRECTORY_SEPARATOR !== '\\')
+ {
+ $cmd = 'file --brief --mime ' . escapeshellarg($file['tmp_name']) . ' 2>&1';
+
+ if (function_exists('exec'))
+ {
+ /* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
+ * However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites
+ * anything that could already be set for $mime previously. This effectively makes the second parameter a dummy
+ * value, which is only put to allow us to get the return status code.
+ */
+ $mime = @exec($cmd, $mime, $return_status);
+ if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+
+ if ( (bool) @ini_get('safe_mode') === FALSE && function_exists('shell_exec'))
+ {
+ $mime = @shell_exec($cmd);
+ if (strlen($mime) > 0)
+ {
+ $mime = explode("\n", trim($mime));
+ if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+ }
+
+ if (function_exists('popen'))
+ {
+ $proc = @popen($cmd, 'r');
+ if (is_resource($proc))
+ {
+ $mime = @fread($test, 512);
+ @pclose($proc);
+ if ($mime !== FALSE)
+ {
+ $mime = explode("\n", trim($mime));
+ if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ // Fall back to the deprecated mime_content_type(), if available (still better than $_FILES[$field]['type'])
+ if (function_exists('mime_content_type'))
{
- $output = array();
- @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
- if ($return_code === 0 && strlen($output[0]) > 0) // A return status code != 0 would mean failed execution
+ $this->file_type = @mime_content_type($file['tmp_name']);
+ if (strlen($this->file_type) > 0) // It's possible that mime_content_type() returns FALSE or an empty string
{
- $this->file_type = rtrim($output[0]);
return;
}
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 763f58b8f..0446c112d 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -28,15 +28,20 @@ Release Date: Not Released
- Added support for 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
- Added support for m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
- Added support for kmz and kml (Google Earth) files to mimes.php.
+ - Updated support for doc files in mimes.php.
- Added application/xml for xml and application/xml, text/xsl for xsl in mimes.php.
- Changed logger to only chmod when file is first created.
- Removed previously deprecated SHA1 Library.
+ - Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php.
+ Only entries in ``$autoload['libraries']`` are auto-loaded now.
- Helpers
- url_title() will now trim extra dashes from beginning and end.
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
- Changed humanize to include a second param for the separator.
+ - Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
+ - Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
- Database
@@ -45,13 +50,18 @@ Release Date: Not Released
get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Taking care of LIKE condition when used with MySQL UPDATE statement.
- Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - MySQLi driver now uses mysqli_get_server_info() for server version checking.
+ - MySQLi driver now supports persistent connections when running on PHP >= 5.3.
+ - Added dsn if the group connections in the config use PDO or any driver which need DSN.
+ - Improved PDO database support.
+ - An optional database name parameter was added db_select().
- Libraries
- Added max_filename_increment config setting for Upload library.
- CI_Loader::_ci_autoloader() is now a protected method.
- Modified valid_ip() to use PHP's filter_var() when possible (>= PHP 5.2) in the :doc:`Form Validation library <libraries/form_validation>`.
- - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname)
+ - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname)
- Cart library changes include:
- It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites.
- Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe"
@@ -61,22 +71,23 @@ Release Date: Not Released
- Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them.
- Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method
if they are set manually after initialization.
+ - If property maintain_ratio is set to TRUE, image_reproportion() now doesn't need both width and height to be specified.
- Minor speed optimizations and method & property visibility declarations in the Calendar Library.
- Removed SHA1 function in the :doc:`Encryption Library <libraries/encryption>`.
+ - Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library <libraries/security>`, which makes token regeneration optional.
- Core
- - Changed private functions in CI_URI to protected so MY_URI can
- override them.
+ - Changed private functions in CI_URI to protected so MY_URI can override them.
- Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
- - Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars()
+ - Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars().
+ - is_loaded() function from system/core/Commons.php now returns a reference.
Bug fixes for 3.0
------------------
- Unlink raised an error if cache file did not exist when you try to delete it.
-- Fixed a bug (#181) where a mis-spelling was in the form validation
- language file.
+- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#159, #163) that mishandled Active Record nested transactions because _trans_depth was not getting incremented.
- Fixed a bug (#737, #75) where pagination anchor class was not set properly when using initialize method.
- Fixed a bug (#419) - auto_link() now recognizes URLs that come after a word boundary.
@@ -93,12 +104,49 @@ Bug fixes for 3.0
- Fixed a bug in CI_Image_lib::gd_loaded() where it was possible for the script execution to end or a PHP E_WARNING message to be emitted.
- In Pagination library, when use_page_numbers=TRUE previous link and page 1 link do not have the same url
- Fixed a bug (#561) - Errors in :doc:`XML-RPC Library <libraries/xmlrpc>` were not properly escaped.
+- Fixed a bug (#904) - ``CI_Loader::initialize()`` caused a PHP Fatal error to be triggered if error level E_STRICT is used.
+- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
+- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
+- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
+- Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped.
+- Fixed a bug (#1070) - CI_DB_driver::initialize() didn't set a character set if a database is not selected.
+- Fixed a bug (#177) - CI_Form_validation::set_value() didn't set the default value if POST data is NULL.
+- Fixed a bug (#68, #414) - Oracle's escape_str() didn't properly escape LIKE wild characters.
+- Fixed a bug (#81) - ODBC's list_fields() and field_data() methods skipped the first column due to odbc_field_*() functions' index starting at 1 instead of 0.
+- Fixed a bug (#129) - ODBC's num_rows() returned -1 in some cases, due to not all subdrivers supporting the odbc_num_rows() function.
+- Fixed a bug (#153) - E_NOTICE being generated by getimagesize() in the :doc:`File Uploading Library <libraries/file_uploading>`.
+- Fixed a bug (#611) - SQLSRV's _error_message() and _error_number() methods used to issue warnings when there's no actual error.
+- Fixed a bug (#1036) - is_write_type() method in the :doc:`Database Library <database/index>` didn't return TRUE for RENAME and OPTIMIZE queries.
+- Fixed a bug in PDO's _version() method where it used to return the client version as opposed to the server one.
+- Fixed a bug in PDO's insert_id() method where it could've failed if it's used with Postgre versions prior to 8.1.
+- Fixed a bug in CUBRID's affected_rows() method where a connection resource was passed to cubrid_affected_rows() instead of a result.
+- Fixed a bug (#638) - db_set_charset() ignored its arguments and always used the configured charset and collation instead.
+- Fixed a bug (#413) - Oracle's _error_message() and _error_number() methods used to only return connection-related errors.
+
+Version 2.1.1
+=============
+Release Date: Not Released
+
+- General Changes
+ - Fixed support for docx, xlsx files in mimes.php.
+
+- Libraries
+ - Further improved MIME type detection in the :doc:`File Uploading Library <libraries/file_uploading>`.
+
+
+Bug fixes for 2.1.1
+-------------------
+
+- Fixed a bug (#697) - A wrong array key was used in the Upload library to check for mime-types.
+- Fixed a bug - form_open() compared $action against site_url() instead of base_url().
+- Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
+- Fixed a bug (#538) - Windows paths were ignored when using the :doc:`Image Manipulation Library <libraries/image_lib>` to create a new file.
Version 2.1.0
=============
-Release Date: Not Released
+Release Date: November 14, 2011
- General Changes
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 4f88c25ab..040e7e33f 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -28,6 +28,10 @@ prototype::
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
+If you use PDO as your dbdriver, you can specify the full DSN string describe a connection to the database like this::
+
+ $db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
+
You can also specify failovers for the situation when the main connection cannot connect for some reason.
These failovers can be specified by setting the failover for a connection like this::
diff --git a/user_guide_src/source/database/connecting.rst b/user_guide_src/source/database/connecting.rst
index a834cc0f7..fb4524116 100644
--- a/user_guide_src/source/database/connecting.rst
+++ b/user_guide_src/source/database/connecting.rst
@@ -122,6 +122,12 @@ return the database object.
| $DB1->result();
| etc...
+.. note:: You don't need to create separate database configurations if you
+ only need to use a different database on the same connection. You
+ can switch to a different database when you need to, like this:
+
+ | $this->db->db_select($database2_name);
+
Reconnecting / Keeping the Connection Alive
===========================================
diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst
index b3dc08871..d8bdd0531 100644
--- a/user_guide_src/source/general/styleguide.rst
+++ b/user_guide_src/source/general/styleguide.rst
@@ -441,6 +441,13 @@ same level as the control statement that "owns" them.
// ...
}
}
+
+ try {
+ // ...
+ }
+ catch() {
+ // ...
+ }
**CORRECT**::
@@ -470,6 +477,15 @@ same level as the control statement that "owns" them.
// ...
}
}
+
+ try
+ {
+ // ...
+ }
+ catch()
+ {
+ // ...
+ }
Bracket and Parenthetic Spacing
===============================
diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst
index 3126fcf36..6b390b559 100644
--- a/user_guide_src/source/general/urls.rst
+++ b/user_guide_src/source/general/urls.rst
@@ -39,20 +39,23 @@ By default, the **index.php** file will be included in your URLs::
example.com/index.php/news/article/my_article
-You can easily remove this file by using a .htaccess file with some
-simple rules. Here is an example of such a file, using the "negative"
-method in which everything is redirected except the specified items:
+If your Apache server has mod_rewrite enabled, you can easily remove this
+file by using a .htaccess file with some simple rules. Here is an example
+of such a file, using the "negative" method in which everything is redirected
+except the specified items:
::
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)$ /index.php/$1 [L]
+ RewriteRule ^(.*)$ index.php/$1 [L]
In the above example, any HTTP request other than those for existing
directories and existing files is treated as a request for your index.php file.
+.. note:: Note: These specific rules might not work for all server configurations.
+
Adding a URL Suffix
===================
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index 960485ae3..4c594ab17 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -15,6 +15,9 @@ Replace all files and directories in your "system" folder and replace
your index.php file. If any modifications were made to your index.php
they will need to be made fresh in this new one.
+.. note:: If you have any custom developed files in these folders please
+ make copies of them first.
+
Step 2: Change References to the SHA Library
============================================
@@ -23,6 +26,8 @@ Alter your code to use the native `sha1()` PHP function to generate a sha1 hash.
Additionally, the `sha1()` method in the :doc:`Encryption Library <../libraries/encryption>` has been removed.
+Step 3: Remove $autoload['core'] from your config/autoload.php
+==============================================================
-.. note:: If you have any custom developed files in these folders please
- make copies of them first.
+Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
+Move any entries that you might have listed there to `$autoload['libraries']` instead.
diff --git a/user_guide_src/source/libraries/security.rst b/user_guide_src/source/libraries/security.rst
index 8ee0c6e77..e7d25555f 100644
--- a/user_guide_src/source/libraries/security.rst
+++ b/user_guide_src/source/libraries/security.rst
@@ -85,6 +85,10 @@ If you use the :doc:`form helper <../helpers/form_helper>` the
form_open() function will automatically insert a hidden csrf field in
your forms.
+Tokens may be either regenerated on every submission (default) or kept the same throughout the life of the CSRF cookie. The default regeneration of tokens provides stricter security but may result in usability concerns as other tokens become invalid (back/forward navigation, multiple tabs/windows, asynchronous actions, etc). You may alter this behavior by editing the following config parameter::
+
+ $config['csrf_regeneration'] = TRUE;
+
Select URIs can be whitelisted from csrf protection (for example API
endpoints expecting externally POSTed content). You can add these URIs
by editing the 'csrf_exclude_uris' config parameter::
diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst
index c7f737951..708eaeb7b 100644
--- a/user_guide_src/source/tutorial/static_pages.rst
+++ b/user_guide_src/source/tutorial/static_pages.rst
@@ -97,7 +97,7 @@ page actually exists:
public function view($page = 'home')
{
- if ( ! file_exists('application/views/pages/'.$page.'.php'))
+ if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();