summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml10
-rw-r--r--application/config/routes.php2
-rw-r--r--application/views/errors/error_404.php (renamed from application/errors/error_404.php)0
-rw-r--r--application/views/errors/error_db.php (renamed from application/errors/error_db.php)0
-rw-r--r--application/views/errors/error_general.php (renamed from application/errors/error_general.php)0
-rw-r--r--application/views/errors/error_php.php (renamed from application/errors/error_php.php)5
-rw-r--r--application/views/errors/index.html (renamed from application/errors/index.html)0
-rw-r--r--composer.json5
-rwxr-xr-xsystem/core/Benchmark.php6
-rwxr-xr-xsystem/core/CodeIgniter.php23
-rw-r--r--system/core/Common.php16
-rwxr-xr-xsystem/core/Config.php27
-rw-r--r--system/core/Controller.php7
-rwxr-xr-xsystem/core/Exceptions.php14
-rwxr-xr-xsystem/core/Hooks.php6
-rwxr-xr-xsystem/core/Input.php35
-rwxr-xr-xsystem/core/Lang.php4
-rw-r--r--system/core/Loader.php35
-rwxr-xr-xsystem/core/Model.php3
-rwxr-xr-xsystem/core/Output.php18
-rwxr-xr-xsystem/core/Router.php25
-rwxr-xr-xsystem/core/Security.php19
-rwxr-xr-xsystem/core/URI.php81
-rw-r--r--system/core/Utf8.php4
-rwxr-xr-xsystem/database/DB.php9
-rw-r--r--system/database/DB_driver.php50
-rw-r--r--system/database/DB_query_builder.php43
-rw-r--r--system/database/DB_result.php28
-rw-r--r--system/database/DB_utility.php4
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php38
-rw-r--r--system/database/drivers/interbase/interbase_driver.php34
-rw-r--r--system/database/drivers/mssql/mssql_driver.php36
-rw-r--r--system/database/drivers/mssql/mssql_forge.php39
-rw-r--r--system/database/drivers/mysql/mysql_driver.php42
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php41
-rw-r--r--system/database/drivers/oci8/oci8_driver.php36
-rw-r--r--system/database/drivers/oci8/oci8_result.php16
-rw-r--r--system/database/drivers/odbc/odbc_driver.php37
-rw-r--r--system/database/drivers/pdo/pdo_driver.php53
-rw-r--r--system/database/drivers/pdo/pdo_result.php19
-rw-r--r--system/database/drivers/postgre/postgre_driver.php170
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php36
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php27
-rw-r--r--system/database/drivers/sqlite3/sqlite3_result.php16
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php46
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php39
-rw-r--r--system/helpers/date_helper.php65
-rw-r--r--system/helpers/download_helper.php2
-rw-r--r--system/helpers/form_helper.php1
-rw-r--r--system/helpers/html_helper.php8
-rw-r--r--system/helpers/inflector_helper.php98
-rw-r--r--system/helpers/language_helper.php18
-rw-r--r--system/helpers/number_helper.php13
-rw-r--r--system/helpers/path_helper.php14
-rw-r--r--system/helpers/security_helper.php63
-rw-r--r--system/helpers/smiley_helper.php103
-rw-r--r--system/helpers/string_helper.php204
-rw-r--r--system/helpers/text_helper.php172
-rw-r--r--system/helpers/typography_helper.php47
-rw-r--r--system/helpers/url_helper.php272
-rw-r--r--system/helpers/xml_helper.php14
-rw-r--r--system/libraries/Cache/Cache.php4
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php4
-rw-r--r--system/libraries/Calendar.php41
-rw-r--r--system/libraries/Cart.php33
-rw-r--r--system/libraries/Driver.php8
-rw-r--r--system/libraries/Email.php206
-rw-r--r--system/libraries/Encrypt.php12
-rw-r--r--system/libraries/Form_validation.php60
-rw-r--r--system/libraries/Ftp.php2
-rw-r--r--system/libraries/Image_lib.php252
-rw-r--r--system/libraries/Log.php18
-rw-r--r--system/libraries/Migration.php13
-rw-r--r--system/libraries/Pagination.php1
-rw-r--r--system/libraries/Parser.php26
-rw-r--r--system/libraries/Profiler.php1
-rw-r--r--system/libraries/Session.php7
-rw-r--r--system/libraries/Table.php16
-rw-r--r--system/libraries/Typography.php4
-rw-r--r--system/libraries/Unit_test.php4
-rw-r--r--system/libraries/Upload.php6
-rw-r--r--system/libraries/Xmlrpcs.php9
-rw-r--r--system/libraries/Zip.php12
-rw-r--r--system/libraries/javascript/Jquery.php66
-rw-r--r--tests/Bootstrap.php27
-rw-r--r--tests/README.md8
-rw-r--r--tests/codeigniter/Setup_test.php10
-rw-r--r--tests/codeigniter/core/Benchmark_test.php42
-rw-r--r--tests/codeigniter/core/Input_test.php146
-rw-r--r--tests/codeigniter/core/Security_test.php105
-rw-r--r--tests/codeigniter/database/DB_driver_test.php4
-rw-r--r--tests/codeigniter/database/DB_test.php4
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php44
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php72
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php34
-rw-r--r--tests/codeigniter/database/query_builder/empty_test.php39
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php67
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php51
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php53
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php5
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php38
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php90
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php49
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php55
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php16
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php61
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php71
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php144
-rw-r--r--tests/codeigniter/libraries/Table_test.php24
-rw-r--r--tests/mocks/autoloader.php5
-rw-r--r--tests/mocks/core/benchmark.php3
-rw-r--r--tests/mocks/core/common.php167
-rw-r--r--tests/mocks/core/input.php31
-rw-r--r--tests/mocks/core/security.php30
-rw-r--r--tests/mocks/core/utf8.php27
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin17408 -> 19456 bytes
-rw-r--r--tests/mocks/database/schema/skeleton.php49
-rw-r--r--tests/mocks/libraries/table.php2
-rw-r--r--tests/travis/mysql.phpunit.xml19
-rw-r--r--tests/travis/pdo/mysql.phpunit.xml19
-rw-r--r--tests/travis/pdo/pgsql.phpunit.xml19
-rw-r--r--tests/travis/pdo/sqlite.phpunit.xml19
-rw-r--r--tests/travis/pgsql.phpunit.xml19
-rw-r--r--tests/travis/sqlite.phpunit.xml19
-rw-r--r--user_guide_src/source/changelog.rst76
-rw-r--r--user_guide_src/source/database/results.rst20
-rw-r--r--user_guide_src/source/installation/upgrade_200.rst9
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst7
-rw-r--r--user_guide_src/source/libraries/config.rst12
-rw-r--r--user_guide_src/source/libraries/input.rst17
-rw-r--r--user_guide_src/source/libraries/uri.rst2
132 files changed, 3003 insertions, 1932 deletions
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..31b74b13b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,16 +13,14 @@ env:
- DB=pdo/sqlite
before_script:
- - pyrus channel-discover pear.php-tools.net
- - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
- - phpenv rehash
+ - curl -s http://getcomposer.org/installer | php
+ - php composer.phar install
- sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
-script: phpunit --configuration tests/travis/$DB.phpunit.xml
+script: phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- - develop
- - master \ No newline at end of file
+ - develop \ No newline at end of file
diff --git a/application/config/routes.php b/application/config/routes.php
index 474bda969..001198615 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -64,7 +64,7 @@
|
*/
-$route['default_controller'] = "welcome";
+$route['default_controller'] = 'welcome';
$route['404_override'] = '';
/* End of file routes.php */
diff --git a/application/errors/error_404.php b/application/views/errors/error_404.php
index c19bedfcd..c19bedfcd 100644
--- a/application/errors/error_404.php
+++ b/application/views/errors/error_404.php
diff --git a/application/errors/error_db.php b/application/views/errors/error_db.php
index 3b244e094..3b244e094 100644
--- a/application/errors/error_db.php
+++ b/application/views/errors/error_db.php
diff --git a/application/errors/error_general.php b/application/views/errors/error_general.php
index c88afe168..c88afe168 100644
--- a/application/errors/error_general.php
+++ b/application/views/errors/error_general.php
diff --git a/application/errors/error_php.php b/application/views/errors/error_php.php
index 3855720de..b76dc8a9e 100644
--- a/application/errors/error_php.php
+++ b/application/views/errors/error_php.php
@@ -40,12 +40,15 @@
<p>Backtrace: </p>
<?php foreach(debug_backtrace() as $error): ?>
- <?php if(isset($error['file']) && ! stristr($error['file'], SYSDIR)): ?>
+ <?php if(isset($error['file']) &&
+ strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
+
<p style="margin-left:10px">
File: <?php echo $error['file'] ?><br />
Line: <?php echo $error['line'] ?><br />
Function: <?php echo $error['function'] ?>
</p>
+
<?php endif ?>
<?php endforeach ?></p>
diff --git a/application/errors/index.html b/application/views/errors/index.html
index c942a79ce..c942a79ce 100644
--- a/application/errors/index.html
+++ b/application/views/errors/index.html
diff --git a/composer.json b/composer.json
new file mode 100644
index 000000000..fa6dc02e4
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,5 @@
+{
+ "require": {
+ "mikey179/vfsStream": "*"
+ }
+} \ No newline at end of file
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index c17e95a19..bb630f40b 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -25,13 +25,11 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Benchmark Class
*
* This class enables you to mark points and calculate the time difference
- * between them. Memory consumption can also be displayed.
+ * between them. Memory consumption can also be displayed.
*
* @package CodeIgniter
* @subpackage Libraries
@@ -119,4 +117,4 @@ class CI_Benchmark {
}
/* End of file Benchmark.php */
-/* Location: ./system/core/Benchmark.php */
+/* Location: ./system/core/Benchmark.php */ \ No newline at end of file
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 349f9f2d0..c8245fcfa 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -31,7 +31,7 @@
* Loads the base classes and executes the request.
*
* @package CodeIgniter
- * @subpackage codeigniter
+ * @subpackage CodeIgniter
* @category Front-controller
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/
@@ -101,17 +101,6 @@
/*
* ------------------------------------------------------
- * Set a liberal script execution time limit
- * ------------------------------------------------------
- */
- 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
- {
- @set_time_limit(300);
- }
-
-/*
- * ------------------------------------------------------
* Start the timer... tick tock tick tock...
* ------------------------------------------------------
*/
@@ -393,15 +382,5 @@
*/
$EXT->call_hook('post_system');
-/*
- * ------------------------------------------------------
- * Close the DB connection if one exists
- * ------------------------------------------------------
- */
- if (class_exists('CI_DB') && isset($CI->db) && ! $CI->db->pconnect)
- {
- $CI->db->close();
- }
-
/* End of file CodeIgniter.php */
/* Location: ./system/core/CodeIgniter.php */ \ No newline at end of file
diff --git a/system/core/Common.php b/system/core/Common.php
index 15082a101..159cc0d2b 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -31,7 +31,7 @@
* Loads the base classes and executes the request.
*
* @package CodeIgniter
- * @subpackage codeigniter
+ * @subpackage CodeIgniter
* @category Common Functions
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/
@@ -57,7 +57,7 @@ if ( ! function_exists('is_php'))
if ( ! isset($_is_php[$version]))
{
- $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;
+ $_is_php[$version] = (version_compare(PHP_VERSION, $version) >= 0);
}
return $_is_php[$version];
@@ -491,16 +491,6 @@ if ( ! function_exists('_exception_handler'))
*/
function _exception_handler($severity, $message, $filepath, $line)
{
- // We don't bother with "strict" notices since they tend to fill up
- // the log file with excess information that isn't normally very helpful.
- // For example, if you are running PHP 5 and you use version 4 style
- // class functions (without prefixes like "public", "private", etc.)
- // you'll get notices telling you that these have been deprecated.
- if ($severity == E_STRICT)
- {
- return;
- }
-
$_error =& load_class('Exceptions', 'core');
// Should we display the error? We'll get the current error_reporting
@@ -510,7 +500,7 @@ if ( ! function_exists('_exception_handler'))
$_error->show_php_error($severity, $message, $filepath, $line);
}
- // Should we log the error? No? We're done...
+ // Should we log the error? No? We're done...
if (config_item('log_threshold') == 0)
{
return;
diff --git a/system/core/Config.php b/system/core/Config.php
index 9cebe6c86..c07ffa591 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Config Class
*
@@ -46,14 +44,14 @@ class CI_Config {
* @var array
*/
public $config = array();
-
+
/**
* List of all loaded config files
*
* @var array
*/
public $is_loaded = array();
-
+
/**
* List of paths to search when trying to load a config file.
* This must be public as it's used by the Loader class.
@@ -77,9 +75,9 @@ class CI_Config {
{
if (isset($_SERVER['HTTP_HOST']))
{
- $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']);
+ $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
{
@@ -96,9 +94,9 @@ class CI_Config {
* Load Config File
*
* @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 loaded correctly
+ * @param bool if configuration values should be loaded into their own section
+ * @param bool true if errors should just return false, false if an error message should be displayed
+ * @return bool if the file was loaded correctly
*/
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
@@ -254,8 +252,8 @@ class CI_Config {
* Base URL
* Returns base_url [. uri_string]
*
- * @param string $uri
- * @return string
+ * @param string $uri
+ * @return string
*/
public function base_url($uri = '')
{
@@ -267,8 +265,8 @@ class CI_Config {
/**
* Build URI string for use in Config::site_url() and Config::base_url()
*
- * @param mixed $uri
- * @return string
+ * @param mixed $uri
+ * @return string
*/
protected function _uri_string($uri)
{
@@ -345,6 +343,7 @@ class CI_Config {
}
}
}
+
}
/* End of file Config.php */
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 1f69146d0..491414807 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -48,6 +48,8 @@ class CI_Controller {
/**
* Set up controller properties and methods
+ *
+ * @return void
*/
public function __construct()
{
@@ -67,14 +69,15 @@ class CI_Controller {
}
/**
- * Return the CI object
+ * Return the CI object
*
- * @return object
+ * @return object
*/
public static function &get_instance()
{
return self::$instance;
}
+
}
/* End of file Controller.php */
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 2e9f0c766..8c32085fe 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -65,6 +65,8 @@ class CI_Exceptions {
/**
* Initialize execption class
+ *
+ * @return void
*/
public function __construct()
{
@@ -87,7 +89,7 @@ class CI_Exceptions {
*/
public function log_exception($severity, $message, $filepath, $line)
{
- $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
+ $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
}
@@ -127,21 +129,21 @@ class CI_Exceptions {
* @param string the heading
* @param string the message
* @param string the template name
- * @param int the status code
+ * @param int the status code
* @return string
*/
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
set_status_header($status_code);
- $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
+ $message = '<p>'.implode('</p><p>', is_array($message) ? $message : array($message)).'</p>';
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.$template.'.php');
+ include(APPPATH.'views/errors/'.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
@@ -160,7 +162,7 @@ class CI_Exceptions {
*/
public function show_php_error($severity, $message, $filepath, $line)
{
- $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
+ $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
$filepath = str_replace('\\', '/', $filepath);
// For safety reasons we do not show the full file path
@@ -175,7 +177,7 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.'error_php.php');
+ include(APPPATH.'views/errors/error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index b42ecbe20..5bbb0009a 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -44,14 +44,14 @@ class CI_Hooks {
* @var bool
*/
public $enabled = FALSE;
-
+
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
public $hooks = array();
-
+
/**
* Determines wether hook is in progress, used to prevent infinte loops
*
@@ -152,7 +152,7 @@ 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)
+ if ($this->in_progress === TRUE)
{
return;
}
diff --git a/system/core/Input.php b/system/core/Input.php
index fc2a550bc..97be9e690 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -44,28 +44,28 @@ class CI_Input {
* @var string
*/
public $ip_address = FALSE;
-
+
/**
* user agent (web browser) being used by the current user
*
* @var string
*/
public $user_agent = FALSE;
-
+
/**
* If FALSE, then $_GET will be set to an empty array
*
* @var bool
*/
protected $_allow_get_array = TRUE;
-
+
/**
* If TRUE, then newlines are standardized
*
* @var bool
*/
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
@@ -73,7 +73,7 @@ class CI_Input {
* @var bool
*/
protected $_enable_xss = FALSE;
-
+
/**
* Enables a CSRF cookie token to be set.
* Set automatically based on config setting
@@ -81,7 +81,7 @@ class CI_Input {
* @var bool
*/
protected $_enable_csrf = FALSE;
-
+
/**
* List of all HTTP request headers
*
@@ -94,6 +94,8 @@ class CI_Input {
*
* Sets whether to globally enable the XSS processing
* and whether to allow the $_GET array
+ *
+ * @return void
*/
public function __construct()
{
@@ -133,7 +135,7 @@ class CI_Input {
{
if ( ! isset($array[$index]))
{
- return FALSE;
+ return NULL;
}
if ($xss_clean === TRUE)
@@ -438,15 +440,7 @@ class CI_Input {
// This is effectively the same as register_globals = off
foreach (array($_GET, $_POST, $_COOKIE) as $global)
{
- if ( ! is_array($global))
- {
- if ( ! in_array($global, $protected))
- {
- global $$global;
- $$global = NULL;
- }
- }
- else
+ if (is_array($global))
{
foreach ($global as $key => $val)
{
@@ -457,6 +451,11 @@ class CI_Input {
}
}
}
+ elseif ( ! in_array($global, $protected))
+ {
+ global $$global;
+ $$global = NULL;
+ }
}
// Is $_GET data allowed? If not we'll set the $_GET to an empty array
@@ -605,7 +604,7 @@ class CI_Input {
* In Apache, you can simply call apache_request_headers(), however for
* people running other webservers the function is undefined.
*
- * @param bool XSS cleaning
+ * @param bool XSS cleaning
* @return array
*/
public function request_headers($xss_clean = FALSE)
@@ -660,7 +659,7 @@ class CI_Input {
if ( ! isset($this->headers[$index]))
{
- return FALSE;
+ return NULL;
}
return ($xss_clean === TRUE)
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 5cb0cad71..73c9127ac 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -65,14 +65,14 @@ class CI_Lang {
/**
* Load a language file
*
- * @param mixed the name of the language file to be loaded. Can be an array
+ * @param mixed the name of the language file to be loaded
* @param string the language (english, etc.)
* @param bool return loaded array of translations
* @param bool add suffix to $langfile
* @param string alternative path to look for language file
* @return mixed
*/
- public 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);
diff --git a/system/core/Loader.php b/system/core/Loader.php
index bf7f6cb02..3eb09e6ab 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -32,8 +32,8 @@
*
* @package CodeIgniter
* @subpackage Libraries
- * @author EllisLab Dev Team
* @category Loader
+ * @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/loader.html
*/
class CI_Loader {
@@ -45,77 +45,77 @@ class CI_Loader {
* @var int
*/
protected $_ci_ob_level;
-
+
/**
* List of paths to load views from
*
* @var array
*/
protected $_ci_view_paths = array();
-
+
/**
* List of paths to load libraries from
*
* @var array
*/
protected $_ci_library_paths = array();
-
+
/**
* List of paths to load models from
*
* @var array
*/
protected $_ci_model_paths = array();
-
+
/**
* List of paths to load helpers from
*
* @var array
*/
protected $_ci_helper_paths = array();
-
+
/**
* List of loaded base classes
*
* @var array
*/
protected $_base_classes = array(); // Set by the controller class
-
+
/**
* List of cached variables
*
* @var array
*/
protected $_ci_cached_vars = array();
-
+
/**
* List of loaded classes
*
* @var array
*/
protected $_ci_classes = array();
-
+
/**
* List of loaded files
*
* @var array
*/
protected $_ci_loaded_files = array();
-
+
/**
* List of loaded models
*
* @var array
*/
protected $_ci_models = array();
-
+
/**
* List of loaded helpers
*
* @var array
*/
protected $_ci_helpers = array();
-
+
/**
* List of class name mappings
*
@@ -130,6 +130,8 @@ class CI_Loader {
* Constructor
*
* Sets the path to the view files and gets the initial output buffering level
+ *
+ * @return void
*/
public function __construct()
{
@@ -178,12 +180,7 @@ class CI_Loader {
*/
public function is_loaded($class)
{
- if (isset($this->_ci_classes[$class]))
- {
- return $this->_ci_classes[$class];
- }
-
- return FALSE;
+ return isset($this->_ci_classes[$class]) ? $this->_ci_classes[$class] : FALSE;
}
// --------------------------------------------------------------------
@@ -1263,4 +1260,4 @@ class CI_Loader {
}
/* End of file Loader.php */
-/* Location: ./system/core/Loader.php */
+/* Location: ./system/core/Loader.php */ \ No newline at end of file
diff --git a/system/core/Model.php b/system/core/Model.php
index 7c9971970..9bc9f879f 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -38,6 +38,8 @@ class CI_Model {
/**
* Initialize CI_Model Class
+ *
+ * @return void
*/
public function __construct()
{
@@ -57,6 +59,7 @@ class CI_Model {
$CI =& get_instance();
return $CI->$key;
}
+
}
/* End of file Model.php */
diff --git a/system/core/Output.php b/system/core/Output.php
index 513c657a6..c8feb4e67 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -44,49 +44,49 @@ class CI_Output {
* @var string
*/
public $final_output;
-
+
/**
* Cache expiration time
*
* @var int
*/
public $cache_expiration = 0;
-
+
/**
* List of server headers
*
* @var array
*/
public $headers = array();
-
+
/**
* List of mime types
*
* @var array
*/
public $mime_types = array();
-
+
/**
* Determines wether profiler is enabled
*
* @var book
*/
public $enable_profiler = FALSE;
-
+
/**
* Determines if output compression is enabled
*
* @var bool
*/
protected $_zlib_oc = FALSE;
-
+
/**
* List of profiler sections
*
* @var array
*/
protected $_profiler_sections = array();
-
+
/**
* Whether or not to parse variables like {elapsed_time} and {memory_usage}
*
@@ -96,6 +96,8 @@ class CI_Output {
/**
* Set up Output class
+ *
+ * @return void
*/
public function __construct()
{
@@ -177,7 +179,7 @@ class CI_Output {
*
* Lets you set a server header which will be outputted with the final display.
*
- * Note: If a file is cached, headers will not be sent. We need to figure out
+ * 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...
*
* @param string
diff --git a/system/core/Router.php b/system/core/Router.php
index 9314052fe..5ea13797b 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -32,8 +32,8 @@
*
* @package CodeIgniter
* @subpackage Libraries
- * @author EllisLab Dev Team
* @category Libraries
+ * @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/general/routing.html
*/
class CI_Router {
@@ -44,42 +44,42 @@ class CI_Router {
* @var object
*/
public $config;
-
+
/**
* List of routes
*
* @var array
*/
public $routes = array();
-
+
/**
* List of error routes
*
* @var array
*/
public $error_routes = array();
-
+
/**
* Current class name
*
* @var string
*/
- public $class = '';
-
+ public $class = '';
+
/**
* Current method name
*
* @var string
*/
public $method = 'index';
-
+
/**
* Sub-directory that contains the requested controller class
*
* @var string
*/
public $directory = '';
-
+
/**
* Default controller (and method if specific)
*
@@ -91,6 +91,8 @@ class CI_Router {
* Constructor
*
* Runs the route mapping function.
+ *
+ * @return void
*/
public function __construct()
{
@@ -433,12 +435,7 @@ class CI_Router {
*/
public function fetch_method()
{
- if ($this->method == $this->fetch_class())
- {
- return 'index';
- }
-
- return $this->method;
+ return ($this->method == $this->fetch_class()) ? 'index' : $this->method;
}
// --------------------------------------------------------------------
diff --git a/system/core/Security.php b/system/core/Security.php
index c82b69ff9..9b7ba5799 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -102,9 +102,11 @@ class CI_Security {
'Redirect\s+302',
"([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?"
);
-
+
/**
* Initialize security class
+ *
+ * @return void
*/
public function __construct()
{
@@ -189,6 +191,7 @@ class CI_Security {
* Set Cross Site Request Forgery Protection Cookie
*
* @return object
+ * @codeCoverageIgnore
*/
public function csrf_set_cookie()
{
@@ -201,11 +204,11 @@ class CI_Security {
}
setcookie(
- $this->_csrf_cookie_name,
- $this->_csrf_hash,
- $expire,
- config_item('cookie_path'),
- config_item('cookie_domain'),
+ $this->_csrf_cookie_name,
+ $this->_csrf_hash,
+ $expire,
+ config_item('cookie_path'),
+ config_item('cookie_domain'),
$secure_cookie,
config_item('cookie_httponly')
);
@@ -626,7 +629,7 @@ 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 $3$5$6$7', $str, -1, $count);
+ $str = preg_replace('/<(\/?[^><]+?)([^A-Za-z<>\-])(.*?)('.implode('|', $attribs).')(.*?)([\s><])([><]*)/i', '<$1 $3$5$6$7', $str, -1, $count);
}
} while ($count);
@@ -829,7 +832,7 @@ class CI_Security {
// each page load since a page could contain embedded
// sub-pages causing this feature to fail
if (isset($_COOKIE[$this->_csrf_cookie_name]) &&
- $_COOKIE[$this->_csrf_cookie_name] != '')
+ preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1)
{
return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
}
diff --git a/system/core/URI.php b/system/core/URI.php
index cf82c5838..a9432e05d 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -22,6 +22,7 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
+ * @filesource
*/
/**
@@ -43,21 +44,21 @@ class CI_URI {
* @var array
*/
public $keyval = array();
-
+
/**
* Current uri string
*
* @var string
*/
public $uri_string;
-
+
/**
* List of uri segments
*
* @var array
*/
public $segments = array();
-
+
/**
* Re-indexed list of uri segments
* Starts at 1 instead of 0
@@ -72,6 +73,8 @@ class CI_URI {
* Simply globalizes the $RTR object. The front
* loads the Router class early on so it's not available
* normally as other classes are.
+ *
+ * @return void
*/
public function __construct()
{
@@ -148,7 +151,7 @@ class CI_URI {
return;
}
- $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
+ $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri);
$this->_set_uri_string($path);
}
@@ -181,7 +184,7 @@ class CI_URI {
*/
protected function _detect_uri()
{
- if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
+ if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
{
return '';
}
@@ -227,20 +230,19 @@ class CI_URI {
}
// --------------------------------------------------------------------
-
+
/**
* Is cli Request?
*
* Duplicate of function from the Input class to test to see if a request was made from the command line
*
- * @return boolean
+ * @return bool
*/
protected function _is_cli_request()
{
- return (php_sapi_name() == 'cli') OR defined('STDIN');
+ return (php_sapi_name() === 'cli') OR defined('STDIN');
}
-
// --------------------------------------------------------------------
/**
@@ -253,7 +255,7 @@ class CI_URI {
protected function _parse_cli_args()
{
$args = array_slice($_SERVER['argv'], 1);
- return $args ? '/' . implode('/', $args) : '';
+ return $args ? '/'.implode('/', $args) : '';
}
// --------------------------------------------------------------------
@@ -327,7 +329,7 @@ class CI_URI {
}
// --------------------------------------------------------------------
-
+
/**
* Re-index Segments
*
@@ -355,13 +357,13 @@ class CI_URI {
*
* This function returns the URI segment based on the number provided.
*
- * @param integer
- * @param bool
+ * @param int
+ * @param mixed
* @return string
*/
- public function segment($n, $no_result = FALSE)
+ public function segment($n, $no_result = NULL)
{
- return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
+ return isset($this->segments[$n]) ? $this->segments[$n] : $no_result;
}
// --------------------------------------------------------------------
@@ -370,16 +372,16 @@ class CI_URI {
* Fetch a URI "routed" Segment
*
* This function returns the re-routed URI segment (assuming routing rules are used)
- * based on the number provided. If there is no routing this function returns the
+ * based on the number provided. If there is no routing this function returns the
* same result as $this->segment()
*
- * @param integer
- * @param bool
+ * @param int
+ * @param mixed
* @return string
*/
- public function rsegment($n, $no_result = FALSE)
+ public function rsegment($n, $no_result = NULL)
{
- return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
+ return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result;
}
// --------------------------------------------------------------------
@@ -400,7 +402,7 @@ class CI_URI {
* gender => male
* )
*
- * @param integer the starting segment number
+ * @param int the starting segment number
* @param array an array of default values
* @return array
*/
@@ -408,13 +410,13 @@ class CI_URI {
{
return $this->_uri_to_assoc($n, $default, 'segment');
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Identical to above only it uses the re-routed segment array
*
- * @param integer the starting segment number
+ * @param int the starting segment number
* @param array an array of default values
* @return array
*/
@@ -428,7 +430,7 @@ class CI_URI {
/**
* Generate a key value pair from the URI string or Re-routed URI string
*
- * @param integer the starting segment number
+ * @param int the starting segment number
* @param array an array of default values
* @param string which array we should use
* @return array
@@ -458,12 +460,9 @@ class CI_URI {
if ($this->$total_segments() < $n)
{
- if (count($default) === 0)
- {
- return array();
- }
-
- return array_fill_keys($default, FALSE);
+ return (count($default) === 0)
+ ? array()
+ : array_fill_keys($default, NULL);
}
$segments = array_slice($this->$segment_array(), ($n - 1));
@@ -478,7 +477,7 @@ class CI_URI {
}
else
{
- $retval[$seg] = FALSE;
+ $retval[$seg] = NULL;
$lastval = $seg;
}
@@ -491,7 +490,7 @@ class CI_URI {
{
if ( ! array_key_exists($val, $retval))
{
- $retval[$val] = FALSE;
+ $retval[$val] = NULL;
}
}
}
@@ -512,7 +511,7 @@ class CI_URI {
public function assoc_to_uri($array)
{
$temp = array();
- foreach ((array)$array as $key => $val)
+ foreach ((array) $array as $key => $val)
{
$temp[] = $key;
$temp[] = $val;
@@ -526,7 +525,7 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash
*
- * @param integer
+ * @param int
* @param string
* @return string
*/
@@ -540,7 +539,7 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash
*
- * @param integer
+ * @param int
* @param string
* @return string
*/
@@ -554,7 +553,7 @@ class CI_URI {
/**
* Fetch a URI Segment and add a trailing slash - helper function
*
- * @param integer
+ * @param int
* @param string
* @param string
* @return string
@@ -604,7 +603,7 @@ class CI_URI {
/**
* Total number of segments
*
- * @return integer
+ * @return int
*/
public function total_segments()
{
@@ -616,7 +615,7 @@ class CI_URI {
/**
* Total number of routed segments
*
- * @return integer
+ * @return int
*/
public function total_rsegments()
{
@@ -645,10 +644,10 @@ class CI_URI {
*/
public function ruri_string()
{
- return '/'.implode('/', $this->rsegment_array());
+ return implode('/', $this->rsegment_array());
}
}
/* End of file URI.php */
-/* Location: ./system/core/URI.php */
+/* Location: ./system/core/URI.php */ \ No newline at end of file
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index 122020aea..a6faa84ec 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -42,6 +42,8 @@ class CI_Utf8 {
* Constructor
*
* Determines if UTF-8 support is to be enabled
+ *
+ * @return void
*/
public function __construct()
{
@@ -124,7 +126,7 @@ class CI_Utf8 {
* Attempts to convert a string to UTF-8
*
* @param string
- * @param string - input encoding
+ * @param string input encoding
* @return string
*/
public function convert_to_utf8($str, $encoding)
diff --git a/system/database/DB.php b/system/database/DB.php
index b28439b29..1fe44c0e5 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -118,6 +118,13 @@ function &DB($params = '', $query_builder_override = NULL)
{
$query_builder = $query_builder_override;
}
+ // Backwards compatibility work-around for keeping the
+ // $active_record config variable working. Should be
+ // removed in v3.1
+ elseif ( ! isset($query_builder) && isset($active_record))
+ {
+ $query_builder = $active_record;
+ }
require_once(BASEPATH.'database/DB_driver.php');
@@ -159,4 +166,4 @@ function &DB($params = '', $query_builder_override = NULL)
}
/* End of file DB.php */
-/* Location: ./system/database/DB.php */
+/* Location: ./system/database/DB.php */ \ No newline at end of file
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index ef77b594e..bbb7b7a80 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -742,6 +742,35 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * "Count All" query
+ *
+ * Generates a platform-specific query string that counts all records in
+ * the specified database
+ *
+ * @param string
+ * @return int
+ */
+ public function count_all($table = '')
+ {
+ if ($table == '')
+ {
+ return 0;
+ }
+
+ $query = $this->query($this->_count_string.$this->escape_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
+ if ($query->num_rows() == 0)
+ {
+ return 0;
+ }
+
+ $query = $query->row();
+ $this->_reset_select();
+ return (int) $query->numrows;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Returns an array of table names
*
* @return array
@@ -1152,7 +1181,7 @@ abstract class CI_DB_driver {
{
if ($this->conn_id)
{
- $this->_close($this->conn_id);
+ $this->_close();
$this->conn_id = FALSE;
}
}
@@ -1160,6 +1189,20 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * Close DB Connection
+ *
+ * This method would be overriden by most of the drivers.
+ *
+ * @return void
+ */
+ protected function _close()
+ {
+ $this->conn_id = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Display an error message
*
* @param string the error message
@@ -1381,8 +1424,7 @@ abstract class CI_DB_driver {
/**
* Dummy method that allows Query Builder class to be disabled
- *
- * This function is used extensively by every db driver.
+ * and keep count_all() working.
*
* @return void
*/
@@ -1393,4 +1435,4 @@ abstract class CI_DB_driver {
}
/* End of file DB_driver.php */
-/* Location: ./system/database/DB_driver.php */
+/* Location: ./system/database/DB_driver.php */ \ No newline at end of file
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index d0af66de1..cee4354e9 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -211,8 +211,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$alias = $this->_create_alias_from_table(trim($select));
}
- $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->protect_identifiers(trim($alias));
-
+ $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->escape_identifiers(trim($alias));
+
$this->qb_select[] = $sql;
$this->qb_no_escape[] = NULL;
@@ -256,7 +256,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function distinct($val = TRUE)
{
- $this->qb_distinct = (is_bool($val)) ? $val : TRUE;
+ $this->qb_distinct = is_bool($val) ? $val : TRUE;
return $this;
}
@@ -272,7 +272,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function from($from)
{
- foreach ((array)$from as $val)
+ foreach ((array) $from as $val)
{
if (strpos($val, ',') !== FALSE)
{
@@ -1111,6 +1111,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return $result;
}
+ // --------------------------------------------------------------------
+
/**
* "Count All Results" query
*
@@ -1139,6 +1141,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$row = $result->row();
return (int) $row->numrows;
}
+
// --------------------------------------------------------------------
/**
@@ -1401,16 +1404,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table != '')
{
- if ( ! isset($this->qb_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
+ $this->qb_from[0] = $table;
}
- else
+ elseif ( ! isset($this->qb_from[0]))
{
- $this->qb_from[0] = $table;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
return TRUE;
@@ -1600,16 +1600,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table != '')
{
- if ( ! isset($this->qb_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
+ $this->qb_from[0] = $table;
}
- else
+ elseif ( ! isset($this->qb_from[0]))
{
- $this->qb_from[0] = $table;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
return TRUE;
@@ -1696,15 +1693,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$index_set = TRUE;
}
- else
- {
- $not[] = $k.'-'.$v;
- }
$clean[$this->protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
- if ($index_set == FALSE)
+ if ($index_set === FALSE)
{
return $this->display_error('db_batch_missing_index');
}
@@ -2102,7 +2095,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param object
* @return array
*/
- public function _object_to_array($object)
+ protected function _object_to_array($object)
{
if ( ! is_object($object))
{
@@ -2132,7 +2125,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param object
* @return array
*/
- public function _object_to_array_batch($object)
+ protected function _object_to_array_batch($object)
{
if ( ! is_object($object))
{
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 196febe2c..334e08c72 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -242,7 +242,7 @@ class CI_DB_result {
$result = $this->custom_result_object($type);
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if ($n != $this->current_row && isset($result[$n]))
@@ -253,6 +253,8 @@ class CI_DB_result {
return $result[$this->current_row];
}
+ // --------------------------------------------------------------------
+
/**
* Returns a single result row - object version
*
@@ -263,7 +265,7 @@ class CI_DB_result {
$result = $this->result_object();
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if ($n != $this->current_row && isset($result[$n]))
@@ -286,7 +288,7 @@ class CI_DB_result {
$result = $this->result_array();
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if ($n != $this->current_row && isset($result[$n]))
@@ -307,7 +309,7 @@ class CI_DB_result {
public function first_row($type = 'object')
{
$result = $this->result($type);
- return (count($result) === 0) ? $result : $result[0];
+ return (count($result) === 0) ? NULL : $result[0];
}
// --------------------------------------------------------------------
@@ -320,7 +322,7 @@ class CI_DB_result {
public function last_row($type = 'object')
{
$result = $this->result($type);
- return (count($result) === 0) ? $result : $result[count($result) - 1];
+ return (count($result) === 0) ? NULL : $result[count($result) - 1];
}
// --------------------------------------------------------------------
@@ -335,7 +337,7 @@ class CI_DB_result {
$result = $this->result($type);
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if (isset($result[$this->current_row + 1]))
@@ -358,7 +360,7 @@ class CI_DB_result {
$result = $this->result($type);
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if (isset($result[$this->current_row - 1]))
@@ -371,6 +373,18 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
+ * Returns an unbuffered row and move pointer to next row
+ *
+ * @return mixed either a result object or array
+ */
+ public function unbuffered_row($type = 'object')
+ {
+ return ($type !== 'array') ? $this->_fetch_object() : $this->_fetch_assoc();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* The following functions are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
* is used. When caching is enabled we do not load the other driver.
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 587dfdc01..cb97ff448 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -212,7 +212,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
$out = rtrim($out).$newline;
// Next blast through the result array and build out the rows
- foreach ($query->result_array() as $row)
+ while ($row = $query->unbuffered_row('array'))
{
foreach ($row as $item)
{
@@ -258,7 +258,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
// Generate the result
$xml = '<'.$root.'>'.$newline;
- foreach ($query->result_array() as $row)
+ while ($row = $query->unbuffered_row())
{
$xml .= $tab.'<'.$element.'>'.$newline;
foreach ($row as $key => $val)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 1373faa88..817dfdc98 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -329,35 +329,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified table
- *
- * @param string
- * @return int
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -485,7 +456,7 @@ class CI_DB_cubrid_driver extends CI_DB {
}
// --------------------------------------------------------------------
-
+
/**
* Limit string
*
@@ -506,15 +477,14 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @cubrid_close($conn_id);
+ @cubrid_close($this->conn_id);
}
}
/* End of file cubrid_driver.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
index 1b18de803..49d3cda87 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -244,35 +244,6 @@ class CI_DB_interbase_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -472,12 +443,11 @@ class CI_DB_interbase_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @ibase_close($conn_id);
+ @ibase_close($this->conn_id);
}
}
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index f60ec8168..342ff2647 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -304,35 +304,6 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -523,15 +494,14 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @mssql_close($conn_id);
+ @mssql_close($this->conn_id);
}
}
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 8f8e7c5b9..bbf2d9685 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -48,16 +48,13 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*/
protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
- $sql = 'CREATE TABLE ';
+ $sql = ($if_not_exists === TRUE)
+ ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
+ : '';
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
+ $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
- $sql .= $this->db->escape_identifiers($table).' (';
$current_field_count = 0;
-
foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
@@ -65,15 +62,13 @@ class CI_DB_mssql_forge extends CI_DB_forge {
// 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);
-
- $sql .= ' '.$attributes['TYPE'];
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
@@ -115,7 +110,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
$primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -131,13 +126,11 @@ class CI_DB_mssql_forge extends CI_DB_forge {
$key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -167,21 +160,14 @@ class CI_DB_mssql_forge extends CI_DB_forge {
return $sql;
}
- $sql .= " $column_definition";
+ $sql .= " ".$column_definition;
if ($default_value != '')
{
- $sql .= " DEFAULT \"$default_value\"";
+ $sql .= " DEFAULT '".$default_value."'";
}
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ($null === NULL) ? ' NULL' : ' NOT NULL';
if ($after_field != '')
{
@@ -189,7 +175,6 @@ class CI_DB_mssql_forge extends CI_DB_forge {
}
return $sql;
-
}
}
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 32c51865d..7a1a7b9a2 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -47,7 +47,7 @@ class CI_DB_mysql_driver extends CI_DB {
// clause and character used for LIKE escape sequences - not used in MySQL
protected $_like_escape_str = '';
- protected $_like_escape_chr = '';
+ protected $_like_escape_chr = '\\';
/**
* The syntax to count rows is slightly different across different
@@ -291,7 +291,9 @@ class CI_DB_mysql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- return str_replace(array('%', '_'), array('\\%', '\\_'), $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;
@@ -324,35 +326,6 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -520,15 +493,14 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @mysql_close($conn_id);
+ @mysql_close($this->conn_id);
}
}
/* End of file mysql_driver.php */
-/* Location: ./system/database/drivers/mysql/mysql_driver.php */
+/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index e2684e4f2..dd544f686 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -47,7 +47,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// clause and character used for LIKE escape sequences - not used in MySQL
protected $_like_escape_str = '';
- protected $_like_escape_chr = '';
+ protected $_like_escape_chr = '\\';
/**
* The syntax to count rows is slightly different across different
@@ -291,7 +291,9 @@ class CI_DB_mysqli_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- return str_replace(array('%', '_'), array('\\%', '\\_'), $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;
@@ -324,35 +326,6 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -523,16 +496,14 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param object
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
$this->conn_id->close();
- $this->conn_id = FALSE;
}
}
/* End of file mysqli_driver.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
+/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 33a89df94..b979c8a17 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -455,35 +455,6 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- 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));
- if ($query == FALSE)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -671,15 +642,14 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @oci_close($conn_id);
+ @oci_close($this->conn_id);
}
}
/* End of file oci8_driver.php */
-/* Location: ./system/database/drivers/oci8/oci8_driver.php */
+/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index 7b05e0a43..6fb6c81f1 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -419,7 +419,7 @@ class CI_DB_oci8_result extends CI_DB_result {
OR $n < $this->current_row)
{
// No such row exists
- return array();
+ return NULL;
}
// Get the next row index that would actually need to be fetched
@@ -460,7 +460,7 @@ class CI_DB_oci8_result extends CI_DB_result {
$this->num_rows = 0;
}
- return array();
+ return NULL;
}
$this->current_row = $n;
@@ -507,7 +507,7 @@ class CI_DB_oci8_result extends CI_DB_result {
return (object) $row;
}
- return array();
+ return NULL;
}
// --------------------------------------------------------------------
@@ -539,19 +539,19 @@ class CI_DB_oci8_result extends CI_DB_result {
}
else
{
- return array();
+ return NULL;
}
}
elseif ( ! class_exists($class_name)) // No such class exists
{
- return array();
+ return NULL;
}
$row = $this->row_array($n);
- // An array would mean that the row doesn't exist
- if (is_array($row))
+ // A non-array would mean that the row doesn't exist
+ if ( ! is_array($row))
{
- return $row;
+ return NULL;
}
// Convert to the desired class and return
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index e36f2d233..98fd806a8 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -245,36 +245,6 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
-
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -402,15 +372,14 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @odbc_close($conn_id);
+ @odbc_close($this->conn_id);
}
}
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 89e69676d..ec7f3e19b 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -79,13 +79,13 @@ class CI_DB_pdo_driver extends CI_DB {
// clause and character used for LIKE escape sequences
// this one depends on the driver being used
- if ($this->pdodriver == 'mysql')
+ if ($this->pdodriver === 'mysql')
{
$this->_escape_char = '`';
$this->_like_escape_str = '';
- $this->_like_escape_chr = '';
+ $this->_like_escape_chr = '\\';
}
- elseif ($this->pdodriver == 'odbc')
+ elseif ($this->pdodriver === 'odbc')
{
$this->_like_escape_str = " {escape '%s'} ";
}
@@ -409,38 +409,6 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $sql = $this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
- $query = $this->query($sql);
-
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
-
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -667,20 +635,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
}
- // --------------------------------------------------------------------
-
- /**
- * Close DB Connection
- *
- * @param object
- * @return void
- */
- protected function _close($conn_id)
- {
- $this->conn_id = NULL;
- }
-
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 19aee1dfc..0b8937cc5 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -84,19 +84,14 @@ class CI_DB_pdo_result extends CI_DB_result {
// Define the output
$output = array('assoc', 'object');
+ // Initial value
+ $this->result_assoc = array() and $this->result_object = array();
+
// Fetch the result
- foreach ($output as $type)
+ while ($row = $this->_fetch_assoc())
{
- // Define the method and handler
- $res_method = '_fetch_'.$type;
- $res_handler = 'result_'.$type;
-
- $this->$res_handler = array();
-
- while ($row = $this->$res_method())
- {
- $this->{$res_handler}[] = $row;
- }
+ $this->result_assoc[] = $row;
+ $this->result_object[] = (object) $row;
}
// Save this as buffer and marked the fetch flag
@@ -249,7 +244,7 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
protected function _fetch_object()
{
- return $this->result_id->fetchObject();
+ return $this->result_id->fetch(PDO::FETCH_OBJ);
}
}
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 84bf768ee..c2a188416 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -311,6 +311,27 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * "Smart" Escape String
+ *
+ * Escapes data based on type
+ * Sets boolean and null types
+ *
+ * @param string
+ * @return mixed
+ */
+ public function escape($str)
+ {
+ if (is_bool($str))
+ {
+ return ($str) ? 'TRUE' : 'FALSE';
+ }
+
+ return parent::escape($str);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Affected Rows
*
* @return int
@@ -369,35 +390,6 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -518,6 +510,47 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ protected function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ foreach ($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach (array_keys($val) as $field)
+ {
+ if ($field != $index)
+ {
+ $final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k.' = (CASE '.$k."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
+
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
@@ -558,17 +591,88 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Where
+ *
+ * Called by where() or or_where()
+ *
+ * @param mixed
+ * @param mixed
+ * @param string
+ * @return object
+ *
+ */
+ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
+ {
+ $type = $this->_group_get_type($type);
+
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ // If the escape value was not set will will base it on the global setting
+ if ( ! is_bool($escape))
+ {
+ $escape = $this->_protect_identifiers;
+ }
+
+ foreach ($key as $k => $v)
+ {
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+
+ if (is_null($v) && ! $this->_has_operator($k))
+ {
+ // value appears not to have been set, assign the test to IS NULL
+ $k .= ' IS NULL';
+ }
+
+ if ( ! is_null($v))
+ {
+ if ($escape === TRUE)
+ {
+ $k = $this->protect_identifiers($k, FALSE, $escape);
+ $v = ' '.$this->escape($v);
+ }
+ elseif (is_bool($v))
+ {
+ $v = ($v ? ' TRUE' : ' FALSE');
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' = ';
+ }
+ }
+ else
+ {
+ $k = $this->protect_identifiers($k, FALSE, $escape);
+ }
+
+ $this->qb_where[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_where[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'where';
+ }
+
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @pg_close($conn_id);
+ @pg_close($this->conn_id);
}
}
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 551704f83..d8b869c2e 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -268,35 +268,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- 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));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -450,15 +421,14 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @sqlite_close($conn_id);
+ @sqlite_close($this->conn_id);
}
}
/* End of file sqlite_driver.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
+/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index d22f6a442..ea4cf2d4f 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -245,30 +245,6 @@ class CI_DB_sqlite3_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $result = $this->conn_id->querySingle($this->_count_string.$this->protect_identifiers('numrows')
- .' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
-
- return empty($result) ? 0 : (int) $result;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -417,10 +393,9 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param object (ignored)
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
$this->conn_id->close();
}
diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php
index d83d6b2cd..946b36557 100644
--- a/system/database/drivers/sqlite3/sqlite3_result.php
+++ b/system/database/drivers/sqlite3/sqlite3_result.php
@@ -386,7 +386,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
OR count($this->result_array) > 0 OR $n < $this->current_row)
{
// No such row exists
- return array();
+ return NULL;
}
// Get the next row index that would actually need to be fetched
@@ -427,7 +427,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
$this->num_rows = 0;
}
- return array();
+ return NULL;
}
$this->current_row = $n;
@@ -469,7 +469,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
return (object) $row;
}
- return array();
+ return NULL;
}
// --------------------------------------------------------------------
@@ -501,19 +501,19 @@ class CI_DB_sqlite3_result extends CI_DB_result {
}
else
{
- return array();
+ return NULL;
}
}
elseif ( ! class_exists($class_name)) // No such class exists
{
- return array();
+ return NULL;
}
$row = $this->row_array($n);
- // An array would mean that the row doesn't exist
- if (is_array($row))
+ // A non-array would mean that the row doesn't exist
+ if ( ! is_array($row))
{
- return $row;
+ return NULL;
}
// Convert to the desired class and return
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 8cc500f55..961066da7 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -132,11 +132,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _execute($sql)
{
- return sqlsrv_query($this->conn_id,
- $sql,
- NULL,
- array('Scrollable'=> SQLSRV_CURSOR_STATIC, 'SendStreamParamsAtExec' => TRUE)
- );
+ return (is_write_type($sql) && stripos($sql, 'INSERT') === FALSE)
+ ? sqlsrv_query($this->conn_id, $sql)
+ : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => SQLSRV_CURSOR_STATIC));
}
// --------------------------------------------------------------------
@@ -237,7 +235,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
public function affected_rows()
{
- return @sqlrv_rows_affected($this->conn_id);
+ return sqlrv_rows_affected($this->result_id);
}
// --------------------------------------------------------------------
@@ -281,35 +279,6 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -510,15 +479,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @sqlsrv_close($conn_id);
+ @sqlsrv_close($this->conn_id);
}
}
/* End of file sqlsrv_driver.php */
-/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index e9143b269..c817c2c5d 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -48,16 +48,13 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/
protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
- $sql = 'CREATE TABLE ';
+ $sql = ($if_not_exists === TRUE)
+ ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
+ : '';
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
+ $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
- $sql .= $this->db->escape_identifiers($table).' (';
$current_field_count = 0;
-
foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
@@ -65,15 +62,13 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
// 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);
-
- $sql .= ' '.$attributes['TYPE'];
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
@@ -115,7 +110,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
$primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -131,13 +126,11 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
$key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -167,21 +160,14 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
return $sql;
}
- $sql .= " $column_definition";
+ $sql .= ' '.$column_definition;
if ($default_value != '')
{
- $sql .= " DEFAULT \"$default_value\"";
+ $sql .= " DEFAULT '".$default_value."'";
}
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ($null === NULL) ? ' NULL' : ' NOT NULL';
if ($after_field != '')
{
@@ -189,7 +175,6 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
}
return $sql;
-
}
}
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 531d1d32f..5f0427f7d 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -100,7 +100,7 @@ if ( ! function_exists('mdate'))
$datestr = str_replace(
'%\\',
'',
- preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)
+ preg_replace('/([a-z]+?){1}/i', '\\\\\\1', $datestr)
);
return date($datestr, $time);
@@ -316,12 +316,12 @@ if ( ! function_exists('local_to_gmt'))
}
return mktime(
- gmdate("H", $time),
- gmdate("i", $time),
- gmdate("s", $time),
- gmdate("m", $time),
- gmdate("d", $time),
- gmdate("Y", $time)
+ gmdate('H', $time),
+ gmdate('i', $time),
+ gmdate('s', $time),
+ gmdate('m', $time),
+ gmdate('d', $time),
+ gmdate('Y', $time)
);
}
}
@@ -452,8 +452,7 @@ if ( ! function_exists('human_to_unix'))
return FALSE;
}
- $datestr = trim($datestr);
- $datestr = preg_replace("/\040+/", ' ', $datestr);
+ $datestr = preg_replace('/\040+/', ' ', trim($datestr));
if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr))
{
@@ -462,20 +461,20 @@ if ( ! function_exists('human_to_unix'))
$split = explode(' ', $datestr);
- $ex = explode("-", $split['0']);
+ $ex = explode('-', $split['0']);
- $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0'];
- $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
- $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
+ $year = (strlen($ex[0]) === 2) ? '20'.$ex[0] : $ex[0];
+ $month = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1];
+ $day = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2];
- $ex = explode(":", $split['1']);
+ $ex = explode(':', $split['1']);
- $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0'];
- $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
+ $hour = (strlen($ex[0]) === 1) ? '0'.$ex[0] : $ex[0];
+ $min = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1];
- if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2']))
+ if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex[2]))
{
- $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
+ $sec = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2];
}
else
{
@@ -485,11 +484,11 @@ if ( ! function_exists('human_to_unix'))
if (isset($split['2']))
{
- $ampm = strtolower($split['2']);
+ $ampm = strtolower($split[2]);
if (substr($ampm, 0, 1) === 'p' && $hour < 12)
{
- $hour = $hour + 12;
+ $hour += 12;
}
if (substr($ampm, 0, 1) === 'a' && $hour == 12)
@@ -497,7 +496,7 @@ if ( ! function_exists('human_to_unix'))
$hour = '00';
}
- if (strlen($hour) == 1)
+ if (strlen($hour) === 1)
{
$hour = '0'.$hour;
}
@@ -529,7 +528,7 @@ if ( ! function_exists('nice_date'))
// Date like: YYYYMM
if (preg_match('/^\d{6}$/', $bad_date))
{
- if (in_array(substr($bad_date, 0, 2),array('19', '20')))
+ if (in_array(substr($bad_date, 0, 2), array('19', '20')))
{
$year = substr($bad_date, 0, 4);
$month = substr($bad_date, 4, 2);
@@ -540,24 +539,24 @@ if ( ! function_exists('nice_date'))
$year = substr($bad_date, 2, 4);
}
- return date($format, strtotime($year . '-' . $month . '-01'));
+ return date($format, strtotime($year.'-'.$month.'-01'));
}
// Date Like: YYYYMMDD
- if (preg_match('/^\d{8}$/',$bad_date))
+ if (preg_match('/^\d{8}$/', $bad_date))
{
$month = substr($bad_date, 0, 2);
$day = substr($bad_date, 2, 2);
$year = substr($bad_date, 4, 4);
- return date($format, strtotime($month . '/01/' . $year));
+ return date($format, strtotime($month.'/01/'.$year));
}
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between)
- if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/',$bad_date))
+ if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/', $bad_date))
{
list($m, $d, $y) = explode('-', $bad_date);
- return date($format, strtotime("{$y}-{$m}-{$d}"));
+ return date($format, strtotime($y.'-'.$m.'-'.$d));
}
// Any other kind of string, when converted into UNIX time,
@@ -565,7 +564,7 @@ if ( ! function_exists('nice_date'))
// return "Invalid Date".
if (date('U', strtotime($bad_date)) == '0')
{
- return "Invalid Date";
+ return 'Invalid Date';
}
// It's probably a valid-ish date format already
@@ -587,7 +586,7 @@ if ( ! function_exists('timezone_menu'))
* @param string menu name
* @return string
*/
- function timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
+ function timezone_menu($default = 'UTC', $class = '', $name = 'timezones')
{
$CI =& get_instance();
$CI->lang->load('date');
@@ -605,13 +604,11 @@ if ( ! function_exists('timezone_menu'))
foreach (timezones() as $key => $val)
{
- $selected = ($default == $key) ? " selected='selected'" : '';
- $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n";
+ $selected = ($default == $key) ? ' selected="selected"' : '';
+ $menu .= '<option value="'.$key.'"'.$selected.'>'.$CI->lang->line($key)."</option>\n";
}
- $menu .= "</select>";
-
- return $menu;
+ return $menu.'</select>';
}
}
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 97e6986b0..470b61ede 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -100,7 +100,7 @@ if ( ! function_exists('force_download'))
$x[count($x) - 1] = strtoupper($extension);
$filename = implode('.', $x);
}
-
+
// Clean output buffer
ob_clean();
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index b246d72f3..eca6c5f1e 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -184,7 +184,6 @@ if ( ! function_exists('form_input'))
// ------------------------------------------------------------------------
-
if ( ! function_exists('form_password'))
{
/**
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 124f58009..92a6db477 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -379,10 +379,10 @@ if ( ! function_exists('meta'))
$str = '';
foreach ($name as $meta)
{
- $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
- $name = ( ! isset($meta['name'])) ? '' : $meta['name'];
- $content = ( ! isset($meta['content'])) ? '' : $meta['content'];
- $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline'];
+ $type = ( ! isset($meta['type']) OR $meta['type'] === 'name') ? 'name' : 'http-equiv';
+ $name = isset($meta['name']) ? $meta['name'] : '';
+ $content = isset($meta['content']) ? $meta['content'] : '';
+ $newline = isset($meta['newline']) ? $meta['newline'] : "\n";
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
}
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index feeaf57d7..647d840e4 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -37,16 +37,16 @@
// --------------------------------------------------------------------
-/**
- * Singular
- *
- * Takes a plural word and makes it singular
- *
- * @param string
- * @return str
- */
if ( ! function_exists('singular'))
{
+ /**
+ * Singular
+ *
+ * Takes a plural word and makes it singular
+ *
+ * @param string
+ * @return string
+ */
function singular($str)
{
$result = strval($str);
@@ -101,17 +101,17 @@ if ( ! function_exists('singular'))
// --------------------------------------------------------------------
-/**
- * Plural
- *
- * Takes a singular word and makes it plural
- *
- * @param string
- * @param bool
- * @return str
- */
if ( ! function_exists('plural'))
{
+ /**
+ * Plural
+ *
+ * Takes a singular word and makes it plural
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function plural($str, $force = FALSE)
{
$result = strval($str);
@@ -158,16 +158,16 @@ if ( ! function_exists('plural'))
// --------------------------------------------------------------------
-/**
- * Camelize
- *
- * Takes multiple words separated by spaces or underscores and camelizes them
- *
- * @param string
- * @return str
- */
if ( ! function_exists('camelize'))
{
+ /**
+ * Camelize
+ *
+ * Takes multiple words separated by spaces or underscores and camelizes them
+ *
+ * @param string
+ * @return string
+ */
function camelize($str)
{
return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
@@ -176,16 +176,16 @@ if ( ! function_exists('camelize'))
// --------------------------------------------------------------------
-/**
- * Underscore
- *
- * Takes multiple words separated by spaces and underscores them
- *
- * @param string
- * @return str
- */
if ( ! function_exists('underscore'))
{
+ /**
+ * Underscore
+ *
+ * Takes multiple words separated by spaces and underscores them
+ *
+ * @param string
+ * @return string
+ */
function underscore($str)
{
return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
@@ -194,31 +194,33 @@ if ( ! function_exists('underscore'))
// --------------------------------------------------------------------
-/**
- * Humanize
- *
- * Takes multiple words separated by the separator and changes them to spaces
- *
- * @param string $str
- * @param string $separator
- * @return str
- */
if ( ! function_exists('humanize'))
{
+ /**
+ * Humanize
+ *
+ * Takes multiple words separated by the separator and changes them to spaces
+ *
+ * @param string $str
+ * @param string $separator
+ * @return string
+ */
function humanize($str, $separator = '_')
{
return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str))));
}
}
-/**
- * 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'))
{
+ /**
+ * Checks if the given word has a plural version.
+ *
+ * @param string the word to check
+ * @return bool if the word is countable
+ */
function is_countable($word)
{
return ! in_array(strtolower(strval($word)),
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index b31c97107..34f030716 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -37,17 +37,17 @@
// ------------------------------------------------------------------------
-/**
- * Lang
- *
- * Fetches a language variable and optionally outputs a form label
- *
- * @param string the language line
- * @param string the id of the form element
- * @return string
- */
if ( ! function_exists('lang'))
{
+ /**
+ * Lang
+ *
+ * Fetches a language variable and optionally outputs a form label
+ *
+ * @param string the language line
+ * @param string the id of the form element
+ * @return string
+ */
function lang($line, $id = '')
{
$CI =& get_instance();
diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php
index 40da6e7bf..e49f2f7a0 100644
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -37,14 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Formats a numbers as bytes, based on size, and adds the appropriate suffix
- *
- * @param mixed // will be cast as int
- * @return string
- */
if ( ! function_exists('byte_format'))
{
+ /**
+ * Formats a numbers as bytes, based on size, and adds the appropriate suffix
+ *
+ * @param mixed will be cast as int
+ * @param int
+ * @return string
+ */
function byte_format($num, $precision = 1)
{
$CI =& get_instance();
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 6ee99072c..13410545c 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Set Realpath
- *
- * @param string
- * @param bool checks to see if the path exists
- * @return string
- */
if ( ! function_exists('set_realpath'))
{
+ /**
+ * Set Realpath
+ *
+ * @param string
+ * @param bool checks to see if the path exists
+ * @return string
+ */
function set_realpath($path, $check_existance = FALSE)
{
// Security check to make sure the path is NOT a URL. No remote file inclusion!
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php
index d6f134c9f..6187a4a7a 100644
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * XSS Filtering
- *
- * @param string
- * @param bool whether or not the content is an image file
- * @return string
- */
if ( ! function_exists('xss_clean'))
{
+ /**
+ * XSS Filtering
+ *
+ * @param string
+ * @param bool whether or not the content is an image file
+ * @return string
+ */
function xss_clean($str, $is_image = FALSE)
{
$CI =& get_instance();
@@ -55,14 +55,14 @@ if ( ! function_exists('xss_clean'))
// ------------------------------------------------------------------------
-/**
- * Sanitize Filename
- *
- * @param string
- * @return string
- */
if ( ! function_exists('sanitize_filename'))
{
+ /**
+ * Sanitize Filename
+ *
+ * @param string
+ * @return string
+ */
function sanitize_filename($filename)
{
$CI =& get_instance();
@@ -72,14 +72,15 @@ if ( ! function_exists('sanitize_filename'))
// --------------------------------------------------------------------
-/**
- * Hash encode a string
- *
- * @param string
- * @return string
- */
if ( ! function_exists('do_hash'))
{
+ /**
+ * Hash encode a string
+ *
+ * @param string
+ * @param string
+ * @return string
+ */
function do_hash($str, $type = 'sha1')
{
if ( ! in_array(strtolower($type), hash_algos()))
@@ -93,14 +94,14 @@ if ( ! function_exists('do_hash'))
// ------------------------------------------------------------------------
-/**
- * Strip Image Tags
- *
- * @param string
- * @return string
- */
if ( ! function_exists('strip_image_tags'))
{
+ /**
+ * Strip Image Tags
+ *
+ * @param string
+ * @return string
+ */
function strip_image_tags($str)
{
return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
@@ -109,14 +110,14 @@ if ( ! function_exists('strip_image_tags'))
// ------------------------------------------------------------------------
-/**
- * Convert PHP tags to entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('encode_php_tags'))
{
+ /**
+ * Convert PHP tags to entities
+ *
+ * @param string
+ * @return string
+ */
function encode_php_tags($str)
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 638100e9c..5e6de08af 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -37,18 +37,19 @@
// ------------------------------------------------------------------------
-/**
- * Smiley Javascript
- *
- * Returns the javascript required for the smiley insertion. Optionally takes
- * an array of aliases to loosely couple the smiley array to the view.
- *
- * @param mixed alias name or array of alias->field_id pairs
- * @param string field_id if alias name was passed in
- * @return array
- */
if ( ! function_exists('smiley_js'))
{
+ /**
+ * Smiley Javascript
+ *
+ * Returns the javascript required for the smiley insertion. Optionally takes
+ * an array of aliases to loosely couple the smiley array to the view.
+ *
+ * @param mixed alias name or array of alias->field_id pairs
+ * @param string field_id if alias name was passed in
+ * @param bool
+ * @return array
+ */
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
{
static $do_setup = TRUE;
@@ -118,17 +119,20 @@ EOF;
// ------------------------------------------------------------------------
-/**
- * Get Clickable Smileys
- *
- * Returns an array of image tag links that can be clicked to be inserted
- * into a form field.
- *
- * @param string the URL to the folder containing the smiley images
- * @return array
- */
+
if ( ! function_exists('get_clickable_smileys'))
{
+ /**
+ * Get Clickable Smileys
+ *
+ * Returns an array of image tag links that can be clicked to be inserted
+ * into a form field.
+ *
+ * @param string the URL to the folder containing the smiley images
+ * @param array
+ * @param array
+ * @return array
+ */
function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
{
// For backward compatibility with js_insert_smiley
@@ -166,17 +170,18 @@ if ( ! function_exists('get_clickable_smileys'))
// ------------------------------------------------------------------------
-/**
- * Parse Smileys
- *
- * Takes a string as input and swaps any contained smileys for the actual image
- *
- * @param string the text to be parsed
- * @param string the URL to the folder containing the smiley images
- * @return string
- */
if ( ! function_exists('parse_smileys'))
{
+ /**
+ * Parse Smileys
+ *
+ * Takes a string as input and swaps any contained smileys for the actual image
+ *
+ * @param string the text to be parsed
+ * @param string the URL to the folder containing the smiley images
+ * @param array
+ * @return string
+ */
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
if ($image_url == '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
@@ -198,15 +203,15 @@ if ( ! function_exists('parse_smileys'))
// ------------------------------------------------------------------------
-/**
- * Get Smiley Array
- *
- * Fetches the config/smiley.php file
- *
- * @return mixed
- */
if ( ! function_exists('_get_smiley_array'))
{
+ /**
+ * Get Smiley Array
+ *
+ * Fetches the config/smiley.php file
+ *
+ * @return mixed
+ */
function _get_smiley_array()
{
if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
@@ -222,33 +227,5 @@ if ( ! function_exists('_get_smiley_array'))
}
}
-// ------------------------------------------------------------------------
-
-/**
- * JS Insert Smiley
- *
- * Generates the javascript function needed to insert smileys into a form field
- *
- * DEPRECATED as of version 1.7.2, use smiley_js instead
- *
- * @param string form name
- * @param string field name
- * @return string
- */
-if ( ! function_exists('js_insert_smiley'))
-{
- function js_insert_smiley($form_name = '', $form_field = '')
- {
- return <<<EOF
-<script type="text/javascript">
- function insert_smiley(smiley)
- {
- document.{$form_name}.{$form_field}.value += " " + smiley;
- }
-</script>
-EOF;
- }
-}
-
/* End of file smiley_helper.php */
/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index a6a6b485d..0c47d440a 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -37,22 +37,22 @@
// ------------------------------------------------------------------------
-/**
- * Trim Slashes
- *
- * Removes any leading/trailing slashes from a string:
- *
- * /this/that/theother/
- *
- * becomes:
- *
- * this/that/theother
- *
- * @param string
- * @return string
- */
if ( ! function_exists('trim_slashes'))
{
+ /**
+ * Trim Slashes
+ *
+ * Removes any leading/trailing slashes from a string:
+ *
+ * /this/that/theother/
+ *
+ * becomes:
+ *
+ * this/that/theother
+ *
+ * @param string
+ * @return string
+ */
function trim_slashes($str)
{
return trim($str, '/');
@@ -61,16 +61,16 @@ if ( ! function_exists('trim_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Slashes
- *
- * Removes slashes contained in a string or in an array
- *
- * @param mixed string or array
- * @return mixed string or array
- */
if ( ! function_exists('strip_slashes'))
{
+ /**
+ * Strip Slashes
+ *
+ * Removes slashes contained in a string or in an array
+ *
+ * @param mixed string or array
+ * @return mixed string or array
+ */
function strip_slashes($str)
{
if ( ! is_array($str))
@@ -89,16 +89,16 @@ if ( ! function_exists('strip_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Quotes
- *
- * Removes single and double quotes from a string
- *
- * @param string
- * @return string
- */
if ( ! function_exists('strip_quotes'))
{
+ /**
+ * Strip Quotes
+ *
+ * Removes single and double quotes from a string
+ *
+ * @param string
+ * @return string
+ */
function strip_quotes($str)
{
return str_replace(array('"', "'"), '', $str);
@@ -107,16 +107,16 @@ if ( ! function_exists('strip_quotes'))
// ------------------------------------------------------------------------
-/**
- * Quotes to Entities
- *
- * Converts single and double quotes to entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('quotes_to_entities'))
{
+ /**
+ * Quotes to Entities
+ *
+ * Converts single and double quotes to entities
+ *
+ * @param string
+ * @return string
+ */
function quotes_to_entities($str)
{
return str_replace(array("\'","\"","'",'"'), array("&#39;","&quot;","&#39;","&quot;"), $str);
@@ -125,23 +125,23 @@ if ( ! function_exists('quotes_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Reduce Double Slashes
- *
- * Converts double slashes in a string to a single slash,
- * except those found in http://
- *
- * http://www.some-site.com//index.php
- *
- * becomes:
- *
- * http://www.some-site.com/index.php
- *
- * @param string
- * @return string
- */
if ( ! function_exists('reduce_double_slashes'))
{
+ /**
+ * Reduce Double Slashes
+ *
+ * Converts double slashes in a string to a single slash,
+ * except those found in http://
+ *
+ * http://www.some-site.com//index.php
+ *
+ * becomes:
+ *
+ * http://www.some-site.com/index.php
+ *
+ * @param string
+ * @return string
+ */
function reduce_double_slashes($str)
{
return preg_replace('#(^|[^:])//+#', '\\1/', $str);
@@ -150,24 +150,24 @@ if ( ! function_exists('reduce_double_slashes'))
// ------------------------------------------------------------------------
-/**
- * Reduce Multiples
- *
- * Reduces multiple instances of a particular character. Example:
- *
- * Fred, Bill,, Joe, Jimmy
- *
- * becomes:
- *
- * Fred, Bill, Joe, Jimmy
- *
- * @param string
- * @param string the character you wish to reduce
- * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
- * @return string
- */
if ( ! function_exists('reduce_multiples'))
{
+ /**
+ * Reduce Multiples
+ *
+ * Reduces multiple instances of a particular character. Example:
+ *
+ * Fred, Bill,, Joe, Jimmy
+ *
+ * becomes:
+ *
+ * Fred, Bill, Joe, Jimmy
+ *
+ * @param string
+ * @param string the character you wish to reduce
+ * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
+ * @return string
+ */
function reduce_multiples($str, $character = ',', $trim = FALSE)
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
@@ -177,17 +177,17 @@ if ( ! function_exists('reduce_multiples'))
// ------------------------------------------------------------------------
-/**
- * Create a Random String
- *
- * Useful for generating passwords or hashes.
- *
- * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
- * @param int number of characters
- * @return string
- */
if ( ! function_exists('random_string'))
{
+ /**
+ * Create a Random String
+ *
+ * Useful for generating passwords or hashes.
+ *
+ * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
+ * @param int number of characters
+ * @return string
+ */
function random_string($type = 'alnum', $len = 8)
{
switch ($type)
@@ -226,16 +226,16 @@ if ( ! function_exists('random_string'))
// ------------------------------------------------------------------------
-/**
- * Add's _1 to a string or increment the ending number to allow _2, _3, etc
- *
- * @param string required
- * @param string What should the duplicate number be appended with
- * @param string Which number should be used for the first dupe increment
- * @return string
- */
if ( ! function_exists('increment_string'))
{
+ /**
+ * Add's _1 to a string or increment the ending number to allow _2, _3, etc
+ *
+ * @param string required
+ * @param string What should the duplicate number be appended with
+ * @param string Which number should be used for the first dupe increment
+ * @return string
+ */
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
@@ -245,17 +245,17 @@ if ( ! function_exists('increment_string'))
// ------------------------------------------------------------------------
-/**
- * Alternator
- *
- * Allows strings to be alternated. See docs...
- *
- * @param string (as many parameters as needed)
- * @return string
- */
if ( ! function_exists('alternator'))
{
- function alternator()
+ /**
+ * Alternator
+ *
+ * Allows strings to be alternated. See docs...
+ *
+ * @param string (as many parameters as needed)
+ * @return string
+ */
+ function alternator($args)
{
static $i;
@@ -271,15 +271,15 @@ if ( ! function_exists('alternator'))
// ------------------------------------------------------------------------
-/**
- * Repeater function
- *
- * @param string
- * @param int number of repeats
- * @return string
- */
if ( ! function_exists('repeater'))
{
+ /**
+ * Repeater function
+ *
+ * @param string
+ * @param int number of repeats
+ * @return string
+ */
function repeater($data, $num = 1)
{
return ($num > 0) ? str_repeat($data, $num) : '';
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index c1c0eb947..e4451ae81 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -37,18 +37,18 @@
// ------------------------------------------------------------------------
-/**
- * Word Limiter
- *
- * Limits a string to X number of words.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('word_limiter'))
{
+ /**
+ * Word Limiter
+ *
+ * Limits a string to X number of words.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function word_limiter($str, $limit = 100, $end_char = '&#8230;')
{
if (trim($str) == '')
@@ -69,19 +69,19 @@ if ( ! function_exists('word_limiter'))
// ------------------------------------------------------------------------
-/**
- * Character Limiter
- *
- * Limits the string based on the character count. Preserves complete words
- * so the character count may not be exactly as specified.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('character_limiter'))
{
+ /**
+ * Character Limiter
+ *
+ * Limits the string based on the character count. Preserves complete words
+ * so the character count may not be exactly as specified.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function character_limiter($str, $n = 500, $end_char = '&#8230;')
{
if (strlen($str) < $n)
@@ -112,16 +112,16 @@ if ( ! function_exists('character_limiter'))
// ------------------------------------------------------------------------
-/**
- * High ASCII to Entities
- *
- * Converts High ascii text and MS Word special characters to character entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('ascii_to_entities'))
{
+ /**
+ * High ASCII to Entities
+ *
+ * Converts High ascii text and MS Word special characters to character entities
+ *
+ * @param string
+ * @return string
+ */
function ascii_to_entities($str)
{
$count = 1;
@@ -174,17 +174,17 @@ if ( ! function_exists('ascii_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Entities to ASCII
- *
- * Converts character entities back to ASCII
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('entities_to_ascii'))
{
+ /**
+ * Entities to ASCII
+ *
+ * Converts character entities back to ASCII
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function entities_to_ascii($str, $all = TRUE)
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
@@ -227,20 +227,20 @@ if ( ! function_exists('entities_to_ascii'))
// ------------------------------------------------------------------------
-/**
- * Word Censoring Function
- *
- * Supply a string and an array of disallowed words and any
- * matched words will be converted to #### or to the replacement
- * word you've submitted.
- *
- * @param string the text string
- * @param string the array of censoered words
- * @param string the optional replacement value
- * @return string
- */
if ( ! function_exists('word_censor'))
{
+ /**
+ * Word Censoring Function
+ *
+ * Supply a string and an array of disallowed words and any
+ * matched words will be converted to #### or to the replacement
+ * word you've submitted.
+ *
+ * @param string the text string
+ * @param string the array of censoered words
+ * @param string the optional replacement value
+ * @return string
+ */
function word_censor($str, $censored, $replacement = '')
{
if ( ! is_array($censored))
@@ -274,16 +274,16 @@ if ( ! function_exists('word_censor'))
// ------------------------------------------------------------------------
-/**
- * Code Highlighter
- *
- * Colorizes code strings
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('highlight_code'))
{
+ /**
+ * Code Highlighter
+ *
+ * Colorizes code strings
+ *
+ * @param string the text string
+ * @return string
+ */
function highlight_code($str)
{
/* The highlight string function encodes and highlights
@@ -323,19 +323,19 @@ if ( ! function_exists('highlight_code'))
// ------------------------------------------------------------------------
-/**
- * Phrase Highlighter
- *
- * Highlights a phrase within a text string
- *
- * @param string the text string
- * @param string the phrase you'd like to highlight
- * @param string the openging tag to precede the phrase with
- * @param string the closing tag to end the phrase with
- * @return string
- */
if ( ! function_exists('highlight_phrase'))
{
+ /**
+ * Phrase Highlighter
+ *
+ * Highlights a phrase within a text string
+ *
+ * @param string the text string
+ * @param string the phrase you'd like to highlight
+ * @param string the openging tag to precede the phrase with
+ * @param string the closing tag to end the phrase with
+ * @return string
+ */
function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
{
if ($str == '')
@@ -354,14 +354,14 @@ if ( ! function_exists('highlight_phrase'))
// ------------------------------------------------------------------------
-/**
- * Convert Accented Foreign Characters to ASCII
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('convert_accented_characters'))
{
+ /**
+ * Convert Accented Foreign Characters to ASCII
+ *
+ * @param string the text string
+ * @return string
+ */
function convert_accented_characters($str)
{
global $foreign_characters;
@@ -490,19 +490,19 @@ if ( ! function_exists('word_wrap'))
// ------------------------------------------------------------------------
-/**
- * Ellipsize String
- *
- * This function will strip tags from a string, split it at its max_length and ellipsize
- *
- * @param string string to ellipsize
- * @param int max length of string
- * @param mixed int (1|0) or float, .5, .2, etc for position to split
- * @param string ellipsis ; Default '...'
- * @return string ellipsized string
- */
if ( ! function_exists('ellipsize'))
{
+ /**
+ * Ellipsize String
+ *
+ * This function will strip tags from a string, split it at its max_length and ellipsize
+ *
+ * @param string string to ellipsize
+ * @param int max length of string
+ * @param mixed int (1|0) or float, .5, .2, etc for position to split
+ * @param string ellipsis ; Default '...'
+ * @return string ellipsized string
+ */
function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
{
// Strip tags
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 7a3db5d6b..af9d16a89 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -37,14 +37,14 @@
// ------------------------------------------------------------------------
-/**
- * Convert newlines to HTML line breaks except within PRE tags
- *
- * @param string
- * @return string
- */
if ( ! function_exists('nl2br_except_pre'))
{
+ /**
+ * Convert newlines to HTML line breaks except within PRE tags
+ *
+ * @param string
+ * @return string
+ */
function nl2br_except_pre($str)
{
$CI =& get_instance();
@@ -55,16 +55,16 @@ if ( ! function_exists('nl2br_except_pre'))
// ------------------------------------------------------------------------
-/**
- * Auto Typography Wrapper Function
- *
- * @param string
- * @param bool whether to allow javascript event handlers
- * @param bool whether to reduce multiple instances of double newlines to two
- * @return string
- */
if ( ! function_exists('auto_typography'))
{
+ /**
+ * Auto Typography Wrapper Function
+ *
+ * @param string
+ * @param bool whether to allow javascript event handlers
+ * @param bool whether to reduce multiple instances of double newlines to two
+ * @return string
+ */
function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE)
{
$CI =& get_instance();
@@ -73,20 +73,19 @@ if ( ! function_exists('auto_typography'))
}
}
-
// --------------------------------------------------------------------
-/**
- * HTML Entities Decode
- *
- * This function is a replacement for html_entity_decode()
- *
- * @param string
- * @param string
- * @return string
- */
if ( ! function_exists('entity_decode'))
{
+ /**
+ * HTML Entities Decode
+ *
+ * This function is a replacement for html_entity_decode()
+ *
+ * @param string
+ * @param string
+ * @return string
+ */
function entity_decode($str, $charset = NULL)
{
global $SEC;
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 5576c2748..0e933c18e 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -37,17 +37,17 @@
// ------------------------------------------------------------------------
-/**
- * Site URL
- *
- * Create a local URL based on your basepath. Segments can be passed via the
- * first parameter either as a string or an array.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('site_url'))
{
+ /**
+ * Site URL
+ *
+ * Create a local URL based on your basepath. Segments can be passed via the
+ * first parameter either as a string or an array.
+ *
+ * @param string
+ * @return string
+ */
function site_url($uri = '')
{
$CI =& get_instance();
@@ -57,18 +57,18 @@ 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.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('base_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.
+ *
+ * @param string
+ * @return string
+ */
function base_url($uri = '')
{
$CI =& get_instance();
@@ -78,16 +78,16 @@ if ( ! function_exists('base_url'))
// ------------------------------------------------------------------------
-/**
- * Current URL
- *
- * Returns the full URL (including segments) of the page where this
- * function is placed
- *
- * @return string
- */
if ( ! function_exists('current_url'))
{
+ /**
+ * Current URL
+ *
+ * Returns the full URL (including segments) of the page where this
+ * function is placed
+ *
+ * @return string
+ */
function current_url()
{
$CI =& get_instance();
@@ -96,15 +96,16 @@ if ( ! function_exists('current_url'))
}
// ------------------------------------------------------------------------
-/**
- * URL String
- *
- * Returns the URI segments.
- *
- * @return string
- */
+
if ( ! function_exists('uri_string'))
{
+ /**
+ * URL String
+ *
+ * Returns the URI segments.
+ *
+ * @return string
+ */
function uri_string()
{
$CI =& get_instance();
@@ -114,15 +115,15 @@ if ( ! function_exists('uri_string'))
// ------------------------------------------------------------------------
-/**
- * Index page
- *
- * Returns the "index_page" from your config file
- *
- * @return string
- */
if ( ! function_exists('index_page'))
{
+ /**
+ * Index page
+ *
+ * Returns the "index_page" from your config file
+ *
+ * @return string
+ */
function index_page()
{
$CI =& get_instance();
@@ -132,18 +133,18 @@ if ( ! function_exists('index_page'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link
- *
- * Creates an anchor based on the local URL.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor'))
{
+ /**
+ * Anchor Link
+ *
+ * Creates an anchor based on the local URL.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
@@ -173,19 +174,19 @@ if ( ! function_exists('anchor'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link - Pop-up version
- *
- * Creates an anchor based on the local URL. The link
- * opens a new window based on the attributes specified.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor_popup'))
{
+ /**
+ * Anchor Link - Pop-up version
+ *
+ * Creates an anchor based on the local URL. The link
+ * opens a new window based on the attributes specified.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
$title = (string) $title;
@@ -198,7 +199,7 @@ if ( ! function_exists('anchor_popup'))
if ($attributes === FALSE)
{
- return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title.'</a>';
+ return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank');\">".$title.'</a>';
}
if ( ! is_array($attributes))
@@ -217,22 +218,22 @@ if ( ! function_exists('anchor_popup'))
$attributes = _parse_attributes($attributes);
}
- return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"".$attributes.'>'.$title.'</a>';
+ return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"".$attributes.'>'.$title.'</a>';
}
}
// ------------------------------------------------------------------------
-/**
- * Mailto Link
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('mailto'))
{
+ /**
+ * Mailto Link
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
@@ -248,18 +249,18 @@ if ( ! function_exists('mailto'))
// ------------------------------------------------------------------------
-/**
- * Encoded Mailto Link
- *
- * Create a spam-protected mailto link written in Javascript
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('safe_mailto'))
{
+ /**
+ * Encoded Mailto Link
+ *
+ * Create a spam-protected mailto link written in Javascript
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function safe_mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
@@ -357,21 +358,21 @@ if ( ! function_exists('safe_mailto'))
// ------------------------------------------------------------------------
-/**
- * Auto-linker
- *
- * Automatically links URL and Email addresses.
- * Note: There's a bit of extra code here to deal with
- * URLs or emails that end in a period. We'll strip these
- * off and add them after the link.
- *
- * @param string the string
- * @param string the type: email, url, or both
- * @param bool whether to create pop-up links
- * @return string
- */
if ( ! function_exists('auto_link'))
{
+ /**
+ * Auto-linker
+ *
+ * Automatically links URL and Email addresses.
+ * Note: There's a bit of extra code here to deal with
+ * URLs or emails that end in a period. We'll strip these
+ * off and add them after the link.
+ *
+ * @param string the string
+ * @param string the type: email, url, or both
+ * @param bool whether to create pop-up links
+ * @return string
+ */
function auto_link($str, $type = 'both', $popup = FALSE)
{
if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
@@ -423,16 +424,16 @@ if ( ! function_exists('auto_link'))
// ------------------------------------------------------------------------
-/**
- * Prep URL
- *
- * Simply adds the http:// part if no scheme is included
- *
- * @param string the URL
- * @return string
- */
if ( ! function_exists('prep_url'))
{
+ /**
+ * Prep URL
+ *
+ * Simply adds the http:// part if no scheme is included
+ *
+ * @param string the URL
+ * @return string
+ */
function prep_url($str = '')
{
if ($str === 'http://' OR $str == '')
@@ -453,20 +454,20 @@ if ( ! function_exists('prep_url'))
// ------------------------------------------------------------------------
-/**
- * Create URL Title
- *
- * Takes a "title" string as input and creates a
- * human-friendly URL string with a "separator" string
- * as the word separator.
- *
- * @param string the string
- * @param string the separator
- * @param bool
- * @return string
- */
if ( ! function_exists('url_title'))
{
+ /**
+ * Create URL Title
+ *
+ * Takes a "title" string as input and creates a
+ * human-friendly URL string with a "separator" string
+ * as the word separator.
+ *
+ * @param string the string
+ * @param string the separator
+ * @param bool
+ * @return string
+ */
function url_title($str, $separator = '-', $lowercase = FALSE)
{
if ($separator === 'dash')
@@ -504,19 +505,20 @@ if ( ! function_exists('url_title'))
// ------------------------------------------------------------------------
-/**
- * Header Redirect
- *
- * Header redirect in two flavors
- * For very fine grained control over headers, you could use the Output
- * Library's set_header() function.
- *
- * @param string the URL
- * @param string the method: location or refresh
- * @return string
- */
if ( ! function_exists('redirect'))
{
+ /**
+ * Header Redirect
+ *
+ * Header redirect in two flavors
+ * For very fine grained control over headers, you could use the Output
+ * Library's set_header() function.
+ *
+ * @param string the URL
+ * @param string the method: location or refresh
+ * @param int
+ * @return string
+ */
function redirect($uri = '', $method = 'auto', $http_response_code = 302)
{
if ( ! preg_match('#^https?://#i', $uri))
@@ -545,17 +547,17 @@ if ( ! function_exists('redirect'))
// ------------------------------------------------------------------------
-/**
- * Parse out the attributes
- *
- * Some of the functions use this
- *
- * @param array
- * @param bool
- * @return string
- */
if ( ! function_exists('_parse_attributes'))
{
+ /**
+ * Parse out the attributes
+ *
+ * Some of the functions use this
+ *
+ * @param array
+ * @param bool
+ * @return string
+ */
function _parse_attributes($attributes, $javascript = FALSE)
{
if (is_string($attributes))
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 67fd34b97..958c633dd 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Convert Reserved XML characters to Entities
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('xml_convert'))
{
+ /**
+ * Convert Reserved XML characters to Entities
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function xml_convert($str, $protect_all = FALSE)
{
$temp = '__TEMP_AMPERSANDS__';
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 0493d5a6e..ba732ee8e 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -55,14 +55,14 @@ class CI_Cache extends CI_Driver_Library {
* @var string
*/
protected $_cache_path = NULL;
-
+
/**
* Reference to the driver
*
* @var mixed
*/
protected $_adapter = 'dummy';
-
+
/**
* Fallback driver
*
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index ec4195278..f0eb8bdf7 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -45,6 +45,8 @@ class CI_Cache_file extends CI_Driver {
/**
* Initialize file-based cache
+ *
+ * @return void
*/
public function __construct()
{
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 813df4b1c..1df149c2d 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -77,7 +77,7 @@ class CI_Cache_memcached extends CI_Driver {
* @param string unique identifier
* @param mixed data being cached
* @param int time to live
- * @return bool true on success, false on failure
+ * @return bool true on success, false on failure
*/
public function save($id, $data, $ttl = 60)
{
@@ -99,7 +99,7 @@ class CI_Cache_memcached extends CI_Driver {
* Delete from Cache
*
* @param mixed key to be deleted.
- * @return bool true on success, false on failure
+ * @return bool true on success, false on failure
*/
public function delete($id)
{
diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php
index 4db754f5e..92f372b20 100644
--- a/system/libraries/Calendar.php
+++ b/system/libraries/Calendar.php
@@ -44,55 +44,55 @@ class CI_Calendar {
* @var object
*/
protected $CI;
-
+
/**
* Current local time
*
* @var int
*/
public $local_time;
-
+
/**
* Calendar layout template
*
* @var string
*/
public $template = '';
-
+
/**
* Day of the week to start the calendar on
*
* @var string
*/
public $start_day = 'sunday';
-
+
/**
* How to display months
*
* @var string
*/
public $month_type = 'long';
-
+
/**
* How to display names of days
*
* @var string
*/
public $day_type = 'abr';
-
+
/**
* Whether to show next/prev month links
*
* @var bool
*/
- public $show_next_prev = FALSE;
-
+ public $show_next_prev = FALSE;
+
/**
* Url base to use for next/prev month links
*
* @var bool
*/
- public $next_prev_url = '';
+ public $next_prev_url = '';
/**
* Constructor
@@ -187,7 +187,7 @@ class CI_Calendar {
// Set the starting day of the week
$start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6);
- $start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day];
+ $start_day = isset($start_days[$this->start_day]) ? $start_days[$this->start_day] : 0;
// Set the starting day number
$local_date = mktime(12, 0, 0, $month, 1, $year);
@@ -290,9 +290,7 @@ class CI_Calendar {
$out .= "\n".$this->temp['cal_row_end']."\n";
}
- $out .= "\n".$this->temp['table_close'];
-
- return $out;
+ return $out .= "\n".$this->temp['table_close'];
}
// --------------------------------------------------------------------
@@ -317,14 +315,9 @@ class CI_Calendar {
$month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december');
}
- $month = $month_names[$month];
-
- if ($this->CI->lang->line($month) === FALSE)
- {
- return ucfirst(substr($month, 4));
- }
-
- return $this->CI->lang->line($month);
+ return ($this->CI->lang->line($month_names[$month]) === FALSE)
+ ? ucfirst(substr($month_names[$month], 4))
+ : $this->CI->lang->line($month_names[$month]);
}
// --------------------------------------------------------------------
@@ -345,11 +338,11 @@ class CI_Calendar {
$this->day_type = $day_type;
}
- if ($this->day_type == 'long')
+ if ($this->day_type === 'long')
{
$day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
}
- elseif ($this->day_type == 'short')
+ elseif ($this->day_type === 'short')
{
$day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
}
@@ -448,7 +441,7 @@ class CI_Calendar {
*/
public function default_template()
{
- return array (
+ return array(
'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
'heading_row_start' => '<tr>',
'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index eee123584..827050310 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -39,11 +39,11 @@ class CI_Cart {
/**
* These are the regular expression rules that we use to validate the product ID and product name
* alpha-numeric, dashes, underscores, or periods
- *
+ *
* @var string
*/
public $product_id_rules = '\.a-z0-9_-';
-
+
/**
* These are the regular expression rules that we use to validate the product ID and product name
* alpha-numeric, dashes, underscores, colons or periods
@@ -51,7 +51,7 @@ class CI_Cart {
* @var string
*/
public $product_name_rules = '\.\:\-_ a-z0-9';
-
+
/**
* only allow safe product names
*
@@ -62,14 +62,14 @@ class CI_Cart {
// --------------------------------------------------------------------------
// Protected variables. Do not change!
// --------------------------------------------------------------------------
-
+
/**
* Reference to CodeIgniter instance
*
* @var object
*/
protected $CI;
-
+
/**
* Contents of the cart
*
@@ -83,6 +83,7 @@ class CI_Cart {
* The constructor loads the Session class, used to store the shopping cart contents.
*
* @param array
+ * @return void
*/
public function __construct($params = array())
{
@@ -180,7 +181,7 @@ class CI_Cart {
// --------------------------------------------------------------------
// Does the $items array contain an id, quantity, price, and name? These are required
- if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name']))
+ if ( ! isset($items['id'], $items['qty'], $items['price'], $items['name']))
{
log_message('error', 'The cart array must contain a product ID, quantity, price, and name.');
return FALSE;
@@ -244,7 +245,7 @@ class CI_Cart {
// This becomes the unique "row ID"
if (isset($items['options']) && count($items['options']) > 0)
{
- $rowid = md5($items['id'].implode('', $items['options']));
+ $rowid = md5($items['id'].serialize($items['options']));
}
else
{
@@ -341,7 +342,7 @@ class CI_Cart {
protected function _update($items = array())
{
// Without these array indexes there is nothing we can do
- if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']]))
+ if ( ! isset($items['qty'], $items['rowid'], $this->_cart_contents[$items['rowid']]))
{
return FALSE;
}
@@ -383,7 +384,7 @@ class CI_Cart {
foreach ($this->_cart_contents as $key => $val)
{
// We make sure the array contains the proper indexes
- if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty']))
+ if ( ! is_array($val) OR ! isset($val['price'], $val['qty']))
{
continue;
}
@@ -393,7 +394,7 @@ class CI_Cart {
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
}
- // Is our cart empty? If so we delete it from the session
+ // Is our cart empty? If so we delete it from the session
if (count($this->_cart_contents) <= 2)
{
$this->CI->session->unset_userdata('cart_contents');
@@ -489,7 +490,7 @@ class CI_Cart {
*/
public function has_options($rowid = '')
{
- return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0) ? TRUE : FALSE;
+ return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0);
}
// --------------------------------------------------------------------
@@ -519,15 +520,7 @@ class CI_Cart {
*/
public function format_number($n = '')
{
- if ($n == '')
- {
- return '';
- }
-
- // Remove anything that isn't a number or decimal point.
- $n = (float) $n;
-
- return number_format($n, 2, '.', ',');
+ return ($n == '') ? '' : number_format( (float) $n, 2, '.', ',');
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index b1fff154d..c79698c7b 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -45,7 +45,7 @@ class CI_Driver_Library {
* @var array
*/
protected $valid_drivers = array();
-
+
/**
* Name of the current class - usually the driver class
*
@@ -57,8 +57,8 @@ class CI_Driver_Library {
* The first time a child is used it won't exist, so we instantiate it
* subsequents calls will go straight to the proper child.
*
- * @param mixed $child
- * @return mixed
+ * @param mixed $child
+ * @return mixed
*/
public function __get($child)
{
@@ -145,7 +145,7 @@ class CI_Driver {
* @var array
*/
protected $_methods = array();
-
+
/**
* List of properties in the parent class
*
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 103c3cb25..56d60c802 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -93,6 +93,8 @@ class CI_Email {
* Constructor - Sets Email Preferences
*
* The constructor can be passed an array of config values
+ *
+ * @return void
*/
public function __construct($config = array())
{
@@ -303,8 +305,7 @@ class CI_Email {
*/
public function cc($cc)
{
- $cc = $this->_str_to_array($cc);
- $cc = $this->clean_email($cc);
+ $cc = $this->clean_email($this->_str_to_array($cc));
if ($this->validate)
{
@@ -338,8 +339,7 @@ class CI_Email {
$this->bcc_batch_size = $limit;
}
- $bcc = $this->_str_to_array($bcc);
- $bcc = $this->clean_email($bcc);
+ $bcc = $this->clean_email($this->_str_to_array($bcc));
if ($this->validate)
{
@@ -441,15 +441,11 @@ class CI_Email {
{
if ( ! is_array($email))
{
- if (strpos($email, ',') !== FALSE)
- {
- $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY);
- }
- else
- {
- $email = (array) trim($email);
- }
+ return (strpos($email, ',') !== FALSE)
+ ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY)
+ : (array) trim($email);
}
+
return $email;
}
@@ -477,7 +473,7 @@ class CI_Email {
*/
public function set_mailtype($type = 'text')
{
- $this->mailtype = ($type == 'html') ? 'html' : 'text';
+ $this->mailtype = ($type === 'html') ? 'html' : 'text';
return $this;
}
@@ -574,7 +570,7 @@ class CI_Email {
protected function _get_message_id()
{
$from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
- return '<'.uniqid('').strstr($from, '@').'>';
+ return '<'.uniqid('').strstr($from, '@').'>';
}
// --------------------------------------------------------------------
@@ -631,13 +627,9 @@ class CI_Email {
*/
protected function _get_content_type()
{
- if ($this->mailtype === 'html' && count($this->_attach_name) === 0)
- {
- return 'html';
- }
- elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0)
+ if ($this->mailtype === 'html')
{
- return 'html-attach';
+ return (count($this->_attach_name) == 0) ? 'html' : 'html-attach';
}
elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
{
@@ -731,7 +723,7 @@ class CI_Email {
{
if ( ! is_array($email))
{
- return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email;
+ return preg_match('/\<(.*)\>/', $email, $match) ? $match[1] : $email;
}
$clean_email = array();
@@ -763,7 +755,7 @@ class CI_Email {
return $this->word_wrap($this->alt_message, '76');
}
- $body = (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) ? $match[1] : $this->_body;
+ $body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body;
$body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
for ($i = 20; $i >= 3; $i--)
@@ -788,11 +780,11 @@ class CI_Email {
// Se the character limit
if ($charlim == '')
{
- $charlim = ($this->wrapchars == "") ? 76 : $this->wrapchars;
+ $charlim = ($this->wrapchars == '') ? 76 : $this->wrapchars;
}
// Reduce multiple spaces
- $str = preg_replace("| +|", " ", $str);
+ $str = preg_replace('| +|', ' ', $str);
// Standardize newlines
if (strpos($str, "\r") !== FALSE)
@@ -803,22 +795,22 @@ class CI_Email {
// If the current word is surrounded by {unwrap} tags we'll
// strip the entire chunk and replace it with a marker.
$unwrap = array();
- if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
+ if (preg_match_all('|(\{unwrap\}.+?\{/unwrap\})|s', $str, $matches))
{
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
$unwrap[] = $matches[1][$i];
- $str = str_replace($matches[1][$i], "{{unwrapped".$i."}}", $str);
+ $str = str_replace($matches[1][$i], '{{unwrapped'.$i.'}}', $str);
}
}
// Use PHP's native public function to do the initial wordwrap.
// We set the cut flag to FALSE so that any individual words that are
- // too long get left alone. In the next step we'll deal with them.
+ // too long get left alone. In the next step we'll deal with them.
$str = wordwrap($str, $charlim, "\n", FALSE);
// Split the string into individual lines of text and cycle through them
- $output = "";
+ $output = '';
foreach (explode("\n", $str) as $line)
{
// Is the line within the allowed character count?
@@ -833,7 +825,7 @@ class CI_Email {
do
{
// If the over-length word is a URL we won't wrap it
- if (preg_match("!\[url.+\]|://|wwww.!", $line))
+ if (preg_match('!\[url.+\]|://|wwww.!', $line))
{
break;
}
@@ -859,7 +851,7 @@ class CI_Email {
{
foreach ($unwrap as $key => $val)
{
- $output = str_replace("{{unwrapped".$key."}}", $val, $output);
+ $output = str_replace('{{unwrapped'.$key.'}}', $val, $output);
}
}
@@ -898,15 +890,15 @@ class CI_Email {
}
reset($this->_headers);
- $this->_header_str = "";
+ $this->_header_str = '';
foreach ($this->_headers as $key => $val)
{
$val = trim($val);
- if ($val != "")
+ if ($val != '')
{
- $this->_header_str .= $key.": ".$val.$this->newline;
+ $this->_header_str .= $key.': '.$val.$this->newline;
}
}
@@ -940,8 +932,8 @@ class CI_Email {
{
case 'plain' :
- $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: " . $this->_get_encoding();
+ $hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: '.$this->_get_encoding();
if ($this->_get_protocol() === 'mail')
{
@@ -959,25 +951,25 @@ class CI_Email {
if ($this->send_multipart === FALSE)
{
- $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: quoted-printable";
+ $hdr .= 'Content-Type: text/html; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: quoted-printable';
}
else
{
- $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
+ $hdr .= 'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline;
- $body .= $this->_get_mime_message() . $this->newline . $this->newline
- . "--" . $this->_alt_boundary . $this->newline
+ $body .= $this->_get_mime_message().$this->newline.$this->newline
+ .'--'.$this->_alt_boundary.$this->newline
- . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
- . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
+ .'Content-Type: text/plain; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
+ .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline
- . "Content-Type: text/html; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
+ .'Content-Type: text/html; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline;
}
- $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
+ $this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline;
if ($this->_get_protocol() === 'mail')
@@ -986,59 +978,59 @@ class CI_Email {
}
else
{
- $this->_finalbody = $hdr . $this->_finalbody;
+ $this->_finalbody = $hdr.$this->_finalbody;
}
if ($this->send_multipart !== FALSE)
{
- $this->_finalbody .= "--" . $this->_alt_boundary . "--";
+ $this->_finalbody .= '--'.$this->_alt_boundary.'--';
}
return;
case 'plain-attach' :
- $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
+ $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'.$this->newline.$this->newline;
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
}
- $body .= $this->_get_mime_message() . $this->newline . $this->newline
- . "--" . $this->_atc_boundary . $this->newline
+ $body .= $this->_get_mime_message().$this->newline.$this->newline
+ .'--'.$this->_atc_boundary.$this->newline
- . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
+ .'Content-Type: text/plain; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
- . $this->_body . $this->newline . $this->newline;
+ .$this->_body.$this->newline.$this->newline;
break;
case 'html-attach' :
- $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
+ $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'.$this->newline.$this->newline;
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
}
- $body .= $this->_get_mime_message() . $this->newline . $this->newline
- . "--" . $this->_atc_boundary . $this->newline
+ $body .= $this->_get_mime_message().$this->newline.$this->newline
+ .'--'.$this->_atc_boundary.$this->newline
- . "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline
- . "--" . $this->_alt_boundary . $this->newline
+ .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline
+ .'--'.$this->_alt_boundary.$this->newline
- . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
- . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
+ .'Content-Type: text/plain; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
+ .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline
- . "Content-Type: text/html; charset=" . $this->charset . $this->newline
- . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline
+ .'Content-Type: text/html; charset='.$this->charset.$this->newline
+ .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline
- . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline
- . "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
+ .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline
+ .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline;
break;
}
@@ -1047,7 +1039,7 @@ class CI_Email {
for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
{
$filename = $this->_attach_name[$i][0];
- $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
+ $basename = is_null($this->_attach_name[$i][1]) ? basename($filename) : $this->_attach_name[$i][1];
$ctype = $this->_attach_type[$i];
$file_content = '';
@@ -1075,17 +1067,18 @@ class CI_Email {
{
$file_content =& $this->_attach_content[$i];
}
- $attachment[$z++] = "--".$this->_atc_boundary.$this->newline
- . "Content-type: ".$ctype."; "
- . "name=\"".$basename."\"".$this->newline
- . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
- . "Content-Transfer-Encoding: base64".$this->newline;
+
+ $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline
+ .'Content-type: '.$ctype.'; '
+ .'name="'.$basename.'"'.$this->newline
+ .'Content-Disposition: '.$this->_attach_disp[$i].';'.$this->newline
+ .'Content-Transfer-Encoding: base64'.$this->newline;
$attachment[$z++] = chunk_split(base64_encode($file_content));
}
- $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
- $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr . $body;
+ $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--';
+ $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$body;
return;
}
@@ -1112,7 +1105,7 @@ class CI_Email {
}
// Reduce multiple spaces & remove nulls
- $str = preg_replace(array("| +|", '/\x00+/'), array(' ', ''), $str);
+ $str = preg_replace(array('| +|', '/\x00+/'), array(' ', ''), $str);
// Standardize newlines
if (strpos($str, "\r") !== FALSE)
@@ -1233,11 +1226,9 @@ class CI_Email {
$temp .= $char;
}
- $str = $output.$temp;
-
// wrap each line with the shebang, charset, and transfer encoding
// the preceding space on successive lines is required for header "folding"
- return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
+ return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $output.$temp));
}
// --------------------------------------------------------------------
@@ -1335,7 +1326,7 @@ class CI_Email {
*/
protected function _unwrap_specials()
{
- $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
+ $this->_finalbody = preg_replace_callback('/\{unwrap\}(.*?)\{\/unwrap\}/si', array($this, '_remove_nl_callback'), $this->_finalbody);
}
// --------------------------------------------------------------------
@@ -1366,10 +1357,10 @@ class CI_Email {
{
$this->_unwrap_specials();
- $method = '_send_with_' . $this->_get_protocol();
+ $method = '_send_with_'.$this->_get_protocol();
if ( ! $this->$method())
{
- $this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
+ $this->_set_error_message('lang:email_send_failure_'.($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
return FALSE;
}
@@ -1394,7 +1385,7 @@ class CI_Email {
{
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
- return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']));
+ return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['From']));
}
}
@@ -1407,7 +1398,7 @@ class CI_Email {
*/
protected function _send_with_sendmail()
{
- $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
+ $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t', 'w');
if ($fp === FALSE OR $fp === NULL)
{
@@ -1461,7 +1452,7 @@ class CI_Email {
{
foreach ($this->_cc_array as $val)
{
- if ($val != "")
+ if ($val != '')
{
$this->_send_command('to', $val);
}
@@ -1472,7 +1463,7 @@ class CI_Email {
{
foreach ($this->_bcc_array as $val)
{
- if ($val != "")
+ if ($val != '')
{
$this->_send_command('to', $val);
}
@@ -1482,7 +1473,7 @@ class CI_Email {
$this->_send_command('data');
// perform dot transformation on any lines that begin with a dot
- $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody));
+ $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody));
$this->_send_data('.');
@@ -1513,14 +1504,14 @@ class CI_Email {
$ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
- $this->smtp_port,
- $errno,
- $errstr,
- $this->smtp_timeout);
+ $this->smtp_port,
+ $errno,
+ $errstr,
+ $this->smtp_timeout);
if ( ! is_resource($this->_smtp_connect))
{
- $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
+ $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr);
return FALSE;
}
@@ -1558,27 +1549,29 @@ class CI_Email {
{
case 'hello' :
- if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
- $this->_send_data('EHLO '.$this->_get_hostname());
- else
- $this->_send_data('HELO '.$this->_get_hostname());
+ if ($this->_smtp_auth OR $this->_get_encoding() === '8bit')
+ {
+ $this->_send_data('EHLO '.$this->_get_hostname());
+ }
+ else
+ {
+ $this->_send_data('HELO '.$this->_get_hostname());
+ }
$resp = 250;
break;
case 'starttls' :
$this->_send_data('STARTTLS');
-
$resp = 220;
break;
case 'from' :
$this->_send_data('MAIL FROM:<'.$data.'>');
-
$resp = 250;
break;
- case 'to' :
-
+ case 'to' :
+
if ($this->dsn)
{
$this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data);
@@ -1587,25 +1580,24 @@ class CI_Email {
{
$this->_send_data('RCPT TO:<'.$data.'>');
}
+
$resp = 250;
break;
case 'data' :
$this->_send_data('DATA');
-
$resp = 354;
break;
case 'quit' :
$this->_send_data('QUIT');
-
$resp = 221;
break;
}
$reply = $this->_get_smtp_data();
- $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
+ $this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
if (substr($reply, 0, 3) != $resp)
{
@@ -1701,13 +1693,13 @@ class CI_Email {
*/
protected function _get_smtp_data()
{
- $data = "";
+ $data = '';
while ($str = fgets($this->_smtp_connect, 512))
{
$data .= $str;
- if ($str[3] == " ")
+ if ($str[3] == ' ')
{
break;
}
@@ -1806,11 +1798,11 @@ class CI_Email {
if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
{
- $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
+ $this->_debug_msg[] = str_replace('%s', $val, $msg).'<br />';
}
else
{
- $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
+ $this->_debug_msg[] = str_replace('%s', $val, $line).'<br />';
}
}
@@ -1921,4 +1913,4 @@ class CI_Email {
}
/* End of file Email.php */
-/* Location: ./system/libraries/Email.php */
+/* Location: ./system/libraries/Email.php */ \ No newline at end of file
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 17437c1ca..751557fab 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -44,28 +44,28 @@ class CI_Encrypt {
* @var string
*/
public $encryption_key = '';
-
+
/**
* Type of hash operation
- *
+ *
* @var string
*/
protected $_hash_type = 'sha1';
-
+
/**
* Flag for the existance of mcrypt
*
* @var bool
*/
protected $_mcrypt_exists = FALSE;
-
+
/**
* Current cipher to be used with mcrypt
*
* @var string
*/
protected $_mcrypt_cipher;
-
+
/**
* Method for encrypting/decrypting data
*
@@ -75,6 +75,8 @@ class CI_Encrypt {
/**
* Initialize Encryption class
+ *
+ * @return void
*/
public function __construct()
{
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c396580be..67cbfd1a0 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -42,63 +42,63 @@ class CI_Form_validation {
* @var object
*/
protected $CI;
-
+
/**
* Validation data for the current form submission
*
* @var array
*/
- protected $_field_data = array();
-
+ protected $_field_data = array();
+
/**
* Validation rules for the current form
*
* @var array
*/
- protected $_config_rules = array();
-
+ protected $_config_rules = array();
+
/**
* Array of validation errors
*
* @var array
*/
protected $_error_array = array();
-
+
/**
* Array of custom error messages
*
* @var array
*/
protected $_error_messages = array();
-
+
/**
* Start tag for error wrapping
*
* @var string
*/
protected $_error_prefix = '<p>';
-
+
/**
* End tag for error wrapping
- *
+ *
* @var string
*/
protected $_error_suffix = '</p>';
-
+
/**
* Custom error message
*
* @var string
*/
protected $error_string = '';
-
+
/**
* Whether the form data has been validated as safe
*
* @var bool
*/
protected $_safe_form_data = FALSE;
-
+
/**
* Custom data to validate
*
@@ -109,7 +109,8 @@ class CI_Form_validation {
/**
* Initialize Form_Validation class
*
- * @param array $rules
+ * @param array $rules
+ * @return void
*/
public function __construct($rules = array())
{
@@ -222,13 +223,13 @@ class CI_Form_validation {
// Build our master array
$this->_field_data[$field] = array(
- 'field' => $field,
- 'label' => $label,
- 'rules' => $rules,
- 'is_array' => $is_array,
- 'keys' => $indexes,
- 'postdata' => NULL,
- 'error' => ''
+ 'field' => $field,
+ 'label' => $label,
+ 'rules' => $rules,
+ 'is_array' => $is_array,
+ 'keys' => $indexes,
+ 'postdata' => NULL,
+ 'error' => ''
);
return $this;
@@ -595,16 +596,13 @@ class CI_Form_validation {
// Set the message type
$type = in_array('required', $rules) ? 'required' : 'isset';
- if ( ! isset($this->_error_messages[$type]))
+ if (isset($this->_error_messages[$type]))
{
- if (FALSE === ($line = $this->CI->lang->line($type)))
- {
- $line = 'The field was not set';
- }
+ $line = $this->_error_messages[$type];
}
- else
+ elseif (FALSE === ($line = $this->CI->lang->line($type)))
{
- $line = $this->_error_messages[$type];
+ $line = 'The field was not set';
}
// Build the error message
@@ -956,12 +954,8 @@ class CI_Form_validation {
public function matches($str, $field)
{
$validation_array = empty($this->validation_data) ? $_POST : $this->validation_data;
- if ( ! isset($validation_array[$field]))
- {
- return FALSE;
- }
- return ($str === $validation_array[$field]);
+ return isset($validation_array[$field]) ? ($str === $validation_array[$field]) : FALSE;
}
// --------------------------------------------------------------------
@@ -1276,7 +1270,7 @@ class CI_Form_validation {
*/
public function valid_base64($str)
{
- return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
+ return ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index 8aa1650d2..3cfe1b2b6 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -44,7 +44,6 @@ class CI_FTP {
public $debug = FALSE;
public $conn_id = FALSE;
-
public function __construct($config = array())
{
if (count($config) > 0)
@@ -539,7 +538,6 @@ class CI_FTP {
return FALSE;
}
-
// --------------------------------------------------------------------
/**
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 24695049c..0cb189445 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -38,321 +38,321 @@ class CI_Image_lib {
/**
* PHP extension/library to use for image manipulation
- * Can be: imagemagick, netpbm, gd, gd2
+ * Can be: imagemagick, netpbm, gd, gd2
*
* @var string
*/
public $image_library = 'gd2';
-
+
/**
* Path to the graphic library (if applicable)
*
* @var string
*/
public $library_path = '';
-
+
/**
* Whether to send to browser or write to disk
*
* @var bool
*/
public $dynamic_output = FALSE;
-
+
/**
* Path to original image
*
* @var string
*/
public $source_image = '';
-
+
/**
* Path to the modified image
*
* @var string
*/
- public $new_image = '';
-
+ public $new_image = '';
+
/**
* Image width
*
* @var int
*/
- public $width = '';
-
+ public $width = '';
+
/**
* Image height
*
* @var int
*/
- public $height = '';
-
+ public $height = '';
+
/**
* Quality percentage of new image
*
* @var int
*/
- public $quality = '90';
-
+ public $quality = 90;
+
/**
* Whether to create a thumbnail
*
* @var bool
*/
public $create_thumb = FALSE;
-
+
/**
* String to add to thumbnail version of image
*
* @var string
*/
public $thumb_marker = '_thumb';
-
+
/**
* Whether to maintain aspect ratio when resizing or use hard values
*
* @var bool
*/
public $maintain_ratio = TRUE;
-
+
/**
* auto, height, or width. Determines what to use as the master dimension
*
* @var string
*/
- public $master_dim = 'auto';
-
+ public $master_dim = 'auto';
+
/**
* Angle at to rotate image
*
* @var string
*/
public $rotation_angle = '';
-
+
/**
* X Coordinate for manipulation of the current image
*
* @var int
*/
- public $x_axis = '';
-
+ public $x_axis = '';
+
/**
* Y Coordinate for manipulation of the current image
*
* @var int
*/
- public $y_axis = '';
+ public $y_axis = '';
// --------------------------------------------------------------------------
// Watermark Vars
// --------------------------------------------------------------------------
-
+
/**
* Watermark text if graphic is not used
*
* @var string
*/
public $wm_text = '';
-
+
/**
* Type of watermarking. Options: text/overlay
*
* @var string
*/
public $wm_type = 'text';
-
+
/**
* Default transparency for watermark
- *
+ *
* @var int
*/
public $wm_x_transp = 4;
-
+
/**
* Default transparency for watermark
*
* @var int
*/
public $wm_y_transp = 4;
-
+
/**
* Watermark image path
- *
+ *
* @var string
*/
- public $wm_overlay_path = '';
-
+ public $wm_overlay_path = '';
+
/**
* TT font
*
* @var string
*/
public $wm_font_path = '';
-
+
/**
* Font size (different versions of GD will either use points or pixels)
*
* @var int
*/
public $wm_font_size = 17;
-
+
/**
* Vertical alignment: T M B
*
* @var string
*/
public $wm_vrt_alignment = 'B';
-
+
/**
* Horizontal alignment: L R C
*
* @var string
*/
public $wm_hor_alignment = 'C';
-
+
/**
* Padding around text
*
* @var int
*/
public $wm_padding = 0;
-
+
/**
* Lets you push text to the right
*
* @var int
*/
public $wm_hor_offset = 0;
-
+
/**
* Lets you push text down
*
* @var int
*/
public $wm_vrt_offset = 0;
-
+
/**
* Text color
*
* @var string
*/
- protected $wm_font_color = '#ffffff';
-
+ protected $wm_font_color = '#ffffff';
+
/**
* Dropshadow color
*
* @var string
*/
- protected $wm_shadow_color = '';
-
+ protected $wm_shadow_color = '';
+
/**
* Dropshadow distance
*
* @var int
*/
public $wm_shadow_distance = 2;
-
+
/**
* Image opacity: 1 - 100 Only works with image
*
* @var int
*/
- public $wm_opacity = 50;
+ public $wm_opacity = 50;
// --------------------------------------------------------------------------
// Private Vars
// --------------------------------------------------------------------------
-
+
/**
* Source image folder
*
* @var string
*/
public $source_folder = '';
-
+
/**
* Destination image folder
*
* @var string
*/
public $dest_folder = '';
-
+
/**
* Image mime-type
*
* @var string
*/
- public $mime_type = '';
-
+ public $mime_type = '';
+
/**
- * Original image width
+ * Original image width
*
* @var int
*/
- public $orig_width = '';
-
+ public $orig_width = '';
+
/**
* Original image height
*
* @var int
*/
public $orig_height = '';
-
+
/**
* Image format
- *
+ *
* @var string
*/
- public $image_type = '';
-
+ public $image_type = '';
+
/**
* Size of current image
*
* @var string
*/
- public $size_str = '';
-
+ public $size_str = '';
+
/**
* Full path to source image
*
* @var string
*/
public $full_src_path = '';
-
+
/**
* Full path to destination image
*
* @var string
*/
public $full_dst_path = '';
-
+
/**
* Name of function to create image
*
* @var string
*/
- public $create_fnc = 'imagecreatetruecolor';
-
+ public $create_fnc = 'imagecreatetruecolor';
+
/**
* Name of function to copy image
*
* @var string
*/
- public $copy_fnc = 'imagecopyresampled';
-
+ public $copy_fnc = 'imagecopyresampled';
+
/**
* Error messages
*
* @var array
*/
- public $error_msg = array();
-
+ public $error_msg = array();
+
/**
* Whether to have a drop shadow on watermark
*
* @var bool
*/
protected $wm_use_drop_shadow = FALSE;
-
+
/**
* Whether to use truetype fonts
*
@@ -364,6 +364,7 @@ class CI_Image_lib {
* Initialize Image Library
*
* @param array $props
+ * @return void
*/
public function __construct($props = array())
{
@@ -395,7 +396,7 @@ class CI_Image_lib {
$this->image_library = 'gd2';
$this->dynamic_output = FALSE;
- $this->quality = '90';
+ $this->quality = 90;
$this->create_thumb = FALSE;
$this->thumb_marker = '_thumb';
$this->maintain_ratio = TRUE;
@@ -895,16 +896,16 @@ class CI_Image_lib {
switch ($this->image_type)
{
case 1 :
- $cmd_in = 'giftopnm';
- $cmd_out = 'ppmtogif';
+ $cmd_in = 'giftopnm';
+ $cmd_out = 'ppmtogif';
break;
case 2 :
- $cmd_in = 'jpegtopnm';
- $cmd_out = 'ppmtojpeg';
+ $cmd_in = 'jpegtopnm';
+ $cmd_out = 'ppmtojpeg';
break;
case 3 :
- $cmd_in = 'pngtopnm';
- $cmd_out = 'ppmtopng';
+ $cmd_in = 'pngtopnm';
+ $cmd_out = 'ppmtopng';
break;
}
@@ -916,15 +917,15 @@ class CI_Image_lib {
{
switch ($this->rotation_angle)
{
- case 90 : $angle = 'r270';
+ case 90: $angle = 'r270';
break;
- case 180 : $angle = 'r180';
+ case 180: $angle = 'r180';
break;
- case 270 : $angle = 'r90';
+ case 270: $angle = 'r90';
break;
- case 'vrt' : $angle = 'tb';
+ case 'vrt': $angle = 'tb';
break;
- case 'hor' : $angle = 'lr';
+ case 'hor': $angle = 'lr';
break;
}
@@ -1401,49 +1402,49 @@ class CI_Image_lib {
{
switch ($this->image_type)
{
- case 1 :
- if ( ! function_exists('imagegif'))
- {
- $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
- return FALSE;
- }
+ case 1:
+ if ( ! function_exists('imagegif'))
+ {
+ $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
+ return FALSE;
+ }
- if ( ! @imagegif($resource, $this->full_dst_path))
- {
- $this->set_error('imglib_save_failed');
- return FALSE;
- }
- break;
- case 2 :
- if ( ! function_exists('imagejpeg'))
- {
- $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
- return FALSE;
- }
+ if ( ! @imagegif($resource, $this->full_dst_path))
+ {
+ $this->set_error('imglib_save_failed');
+ return FALSE;
+ }
+ break;
+ case 2:
+ if ( ! function_exists('imagejpeg'))
+ {
+ $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
+ return FALSE;
+ }
- if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
- {
- $this->set_error('imglib_save_failed');
- return FALSE;
- }
- break;
- case 3 :
- if ( ! function_exists('imagepng'))
- {
- $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
- return FALSE;
- }
+ if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
+ {
+ $this->set_error('imglib_save_failed');
+ return FALSE;
+ }
+ break;
+ case 3:
+ if ( ! function_exists('imagepng'))
+ {
+ $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
+ return FALSE;
+ }
- if ( ! @imagepng($resource, $this->full_dst_path))
- {
- $this->set_error('imglib_save_failed');
- return FALSE;
- }
- break;
- default :
- $this->set_error(array('imglib_unsupported_imagecreate'));
- return FALSE;
- break;
+ if ( ! @imagepng($resource, $this->full_dst_path))
+ {
+ $this->set_error('imglib_save_failed');
+ return FALSE;
+ }
+ break;
+ default:
+ $this->set_error(array('imglib_unsupported_imagecreate'));
+ return FALSE;
+ break;
}
return TRUE;
@@ -1466,13 +1467,13 @@ class CI_Image_lib {
switch ($this->image_type)
{
- case 1 : imagegif($resource);
+ case 1 : imagegif($resource);
break;
- case 2 : imagejpeg($resource, '', $this->quality);
+ case 2 : imagejpeg($resource, '', $this->quality);
break;
- case 3 : imagepng($resource);
+ case 3 : imagepng($resource);
break;
- default : echo 'Unable to display the image';
+ default: echo 'Unable to display the image';
break;
}
}
@@ -1613,8 +1614,10 @@ class CI_Image_lib {
foreach ($allowed as $item)
{
- if ( ! isset($vals[$item]) OR $vals[$item] == '')
+ if (empty($vals[$item]))
+ {
$vals[$item] = 0;
+ }
}
if ($vals['width'] == 0 OR $vals['height'] == 0)
@@ -1712,7 +1715,6 @@ class CI_Image_lib {
{
foreach ($msg as $val)
{
-
$msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);
$this->error_msg[] = $msg;
log_message('error', $msg);
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index c10363a2e..51ce43dc7 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -42,42 +42,42 @@ class CI_Log {
* @var string
*/
protected $_log_path;
-
+
/**
* Level of logging
*
* @var int
*/
protected $_threshold = 1;
-
+
/**
* Highest level of logging
*
* @var int
*/
protected $_threshold_max = 0;
-
+
/**
* Array of threshold levels to log
*
* @var array
*/
protected $_threshold_array = array();
-
+
/**
* Format of timestamp for log files
*
* @var string
*/
protected $_date_fmt = 'Y-m-d H:i:s';
-
+
/**
* Whether or not the logger can write to the log files
*
* @var bool
*/
protected $_enabled = TRUE;
-
+
/**
* Predefined logging levels
*
@@ -88,7 +88,7 @@ class CI_Log {
/**
* Initialize Logging class
*
- * @return void
+ * @return void
*/
public function __construct()
{
@@ -151,7 +151,7 @@ class CI_Log {
if ( ! file_exists($filepath))
{
$newfile = TRUE;
- $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
+ $message .= '<'."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
}
if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
@@ -159,7 +159,7 @@ class CI_Log {
return FALSE;
}
- $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
+ $message .= $level.' '.($level === 'INFO' ? ' -' : '-').' '.date($this->_date_fmt).' --> '.$msg."\n";
flock($fp, LOCK_EX);
fwrite($fp, $message);
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index ce4683fc1..0a88e6926 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -45,28 +45,28 @@ class CI_Migration {
* @var bool
*/
protected $_migration_enabled = FALSE;
-
+
/**
* Path to migration classes
*
* @var string
*/
protected $_migration_path = NULL;
-
+
/**
* Current migration version
*
* @var mixed
*/
protected $_migration_version = 0;
-
+
/**
* Database table with migration info
*
* @var string
*/
protected $_migration_table = 'migrations';
-
+
/**
* Whether to automatically run migrations
*
@@ -85,6 +85,7 @@ class CI_Migration {
* Initialize Migration Class
*
* @param array
+ * @return void
*/
public function __construct($config = array())
{
@@ -96,7 +97,7 @@ class CI_Migration {
foreach ($config as $key => $val)
{
- $this->{'_' . $key} = $val;
+ $this->{'_'.$key} = $val;
}
log_message('debug', 'Migrations class initialized');
@@ -340,7 +341,6 @@ class CI_Migration {
}
sort($files);
-
return $files;
}
@@ -384,6 +384,7 @@ class CI_Migration {
{
return get_instance()->$var;
}
+
}
/* End of file Migration.php */
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 3d2911813..58f86fa17 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -73,6 +73,7 @@ class CI_Pagination {
* Constructor
*
* @param array initialization parameters
+ * @return void
*/
public function __construct($params = array())
{
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index c40f339b4..a0b60ed97 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -42,14 +42,14 @@ class CI_Parser {
* @var string
*/
public $l_delim = '{';
-
+
/**
* Right delimeter character for psuedo vars
*
* @var string
*/
public $r_delim = '}';
-
+
/**
* Reference to CodeIgniter instance
*
@@ -116,14 +116,9 @@ class CI_Parser {
foreach ($data as $key => $val)
{
- if (is_array($val))
- {
- $template = $this->_parse_pair($key, $val, $template);
- }
- else
- {
- $template = $this->_parse_single($key, (string)$val, $template);
- }
+ $template = is_array($val)
+ ? $this->_parse_pair($key, $val, $template)
+ : $template = $this->_parse_single($key, (string) $val, $template);
}
if ($return == FALSE)
@@ -189,14 +184,9 @@ class CI_Parser {
$temp = $match[1];
foreach ($row as $key => $val)
{
- if ( ! is_array($val))
- {
- $temp = $this->_parse_single($key, $val, $temp);
- }
- else
- {
- $temp = $this->_parse_pair($key, $val, $temp);
- }
+ $temp = is_array($val)
+ ? $this->_parse_pair($key, $val, $temp)
+ : $this->_parse_single($key, $val, $temp);
}
$str .= $temp;
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 1e86f3c61..e219d20f2 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -527,6 +527,7 @@ class CI_Profiler {
return $output.'</div>';
}
+
}
/* End of file Profiler.php */
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 3195f0a91..4d6aa0ce8 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -190,6 +190,7 @@ class CI_Session {
* whenever the class is instantiated.
*
* @param array
+ * @return void
*/
public function __construct($params = array())
{
@@ -275,7 +276,7 @@ class CI_Session {
$session = $this->CI->input->cookie($this->sess_cookie_name);
// No cookie? Goodbye cruel world!...
- if ($session === FALSE)
+ if ($session === NULL)
{
log_message('debug', 'A session cookie was not found.');
return FALSE;
@@ -585,7 +586,7 @@ class CI_Session {
*/
public function userdata($item)
{
- return isset($this->userdata[$item]) ? $this->userdata[$item] : FALSE;
+ return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL;
}
// --------------------------------------------------------------------
@@ -714,7 +715,7 @@ class CI_Session {
{
// '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
+ // Note the function will return NULL if the $key
// provided cannot be found
$value = $this->userdata($this->flashdata_key.':old:'.$key);
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index 236129531..f844d6435 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -44,49 +44,49 @@ class CI_Table {
* @var array
*/
public $rows = array();
-
+
/**
* Data for table heading
*
* @var array
*/
public $heading = array();
-
+
/**
* Whether or not to automatically create the table header
*
* @var bool
*/
public $auto_heading = TRUE;
-
+
/**
* Table caption
*
* @var string
*/
public $caption = NULL;
-
+
/**
- * Table layout template
+ * Table layout template
*
* @var array
*/
public $template = NULL;
-
+
/**
* Newline setting
*
* @var string
*/
public $newline = "\n";
-
+
/**
* Contents of empty cells
*
* @var string
*/
public $empty_cells = '';
-
+
/**
* Callback for custom table layout
*
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 50bd12486..6aaa993ae 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -38,7 +38,7 @@ class CI_Typography {
/**
* Block level elements that should not be wrapped inside <p> tags
- *
+ *
* @var string
*/
public $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
@@ -52,7 +52,7 @@ class CI_Typography {
/**
* Tags we want the parser to completely ignore when splitting the string.
- *
+ *
* @var string
*/
public $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 0f6e2dfdd..6ec2dcd5d 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -350,11 +350,11 @@ class CI_Unit_test {
*/
function is_true($test)
{
- return (is_bool($test) && $test === TRUE);
+ return ($test === TRUE);
}
function is_false($test)
{
- return (is_bool($test) && $test === FALSE);
+ return ($test === FALSE);
}
/* End of file Unit_test.php */
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 24d4bd4d0..7456e922a 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -747,6 +747,8 @@ class CI_Upload {
';',
'?',
'/',
+ '!',
+ '#',
'%20',
'%22',
'%3c', // <
@@ -1036,7 +1038,7 @@ class CI_Upload {
*/
if (DIRECTORY_SEPARATOR !== '\\')
{
- $cmd = 'file --brief --mime ' . escapeshellarg($file['tmp_name']) . ' 2>&1';
+ $cmd = 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1';
if (function_exists('exec'))
{
@@ -1103,4 +1105,4 @@ class CI_Upload {
}
/* End of file Upload.php */
-/* Location: ./system/libraries/Upload.php */
+/* Location: ./system/libraries/Upload.php */ \ No newline at end of file
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index f0c5b48e7..1853906ea 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -54,21 +54,21 @@ class CI_Xmlrpcs extends CI_Xmlrpc
* @var array
*/
public $methods = array();
-
+
/**
* Debug Message
*
* @var string
*/
public $debug_msg = '';
-
+
/**
* XML RPC Server methods
*
* @var array
*/
public $system_methods = array();
-
+
/**
* Configuration object
*
@@ -79,7 +79,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc
/**
* Initialize XMLRPC class
*
- * @param array $config
+ * @param array $config
+ * @return void
*/
public function __construct($config = array())
{
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 86d0787b2..e0dc637ad 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -48,35 +48,35 @@ class CI_Zip {
* @var string
*/
public $zipdata = '';
-
+
/**
* Zip data for a directory in string form
*
* @var string
*/
public $directory = '';
-
+
/**
* Number of files/folder in zip file
*
* @var int
*/
public $entries = 0;
-
+
/**
* Number of files in zip
*
* @var int
*/
public $file_num = 0;
-
+
/**
* relative offset of local header
*
* @var int
*/
public $offset = 0;
-
+
/**
* Reference to time at init
*
@@ -87,7 +87,7 @@ class CI_Zip {
/**
* Initialize zip compression class
*
- * @return void
+ * @return void
*/
public function __construct()
{
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php
index f30d7c639..3c9ae1867 100644
--- a/system/libraries/javascript/Jquery.php
+++ b/system/libraries/javascript/Jquery.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Jquery Class
*
@@ -57,7 +55,7 @@ class CI_Jquery extends CI_Javascript {
$this->script();
}
- log_message('debug', "Jquery Class Initialized");
+ log_message('debug', 'Jquery Class Initialized');
}
// --------------------------------------------------------------------
@@ -115,7 +113,7 @@ class CI_Jquery extends CI_Javascript {
if ($ret_false)
{
- $js[] = "return false;";
+ $js[] = 'return false;';
}
return $this->_add_event($element, $js, 'click');
@@ -183,7 +181,7 @@ class CI_Jquery extends CI_Javascript {
*/
protected function _hover($element = 'this', $over, $out)
{
- $event = "\n\t$(" . $this->_prep_element($element) . ").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n";
+ $event = "\n\t$(".$this->_prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n";
$this->jquery_code_for_compile[] = $event;
@@ -322,7 +320,7 @@ class CI_Jquery extends CI_Javascript {
foreach ($array_js as $js)
{
- $this->jquery_code_for_compile[] = "\t$js\n";
+ $this->jquery_code_for_compile[] = "\t".$js."\n";
}
}
@@ -389,7 +387,7 @@ class CI_Jquery extends CI_Javascript {
protected function _addClass($element = 'this', $class='')
{
$element = $this->_prep_element($element);
- return "$({$element}).addClass(\"$class\");";
+ return '$('.$element.').addClass("'.$class.'");';
}
// --------------------------------------------------------------------
@@ -411,9 +409,9 @@ class CI_Jquery extends CI_Javascript {
$animations = "\t\t\t";
- foreach ($params as $param=>$value)
+ foreach ($params as $param => $value)
{
- $animations .= $param.': \''.$value.'\', ';
+ $animations .= $param.": '".$value."', ";
}
$animations = substr($animations, 0, -2); // remove the last ", "
@@ -428,7 +426,7 @@ class CI_Jquery extends CI_Javascript {
$extra = ', '.$extra;
}
- return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
+ return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');';
}
// --------------------------------------------------------------------
@@ -478,7 +476,7 @@ class CI_Jquery extends CI_Javascript {
$callback = ", function(){\n{$callback}\n}";
}
- return "$({$element}).fadeOut({$speed}{$callback});";
+ return '$('.$element.').fadeOut('.$speed.$callback.');';
}
// --------------------------------------------------------------------
@@ -519,7 +517,7 @@ class CI_Jquery extends CI_Javascript {
protected function _removeClass($element = 'this', $class='')
{
$element = $this->_prep_element($element);
- return "$({$element}).removeClass(\"$class\");";
+ return '$('.$element.').removeClass("'.$class.'");';
}
// --------------------------------------------------------------------
@@ -544,7 +542,7 @@ class CI_Jquery extends CI_Javascript {
$callback = ", function(){\n{$callback}\n}";
}
- return "$({$element}).slideUp({$speed}{$callback});";
+ return '$('.$element.').slideUp('.$speed.$callback.');';
}
// --------------------------------------------------------------------
@@ -569,7 +567,7 @@ class CI_Jquery extends CI_Javascript {
$callback = ", function(){\n{$callback}\n}";
}
- return "$({$element}).slideDown({$speed}{$callback});";
+ return '$('.$element.').slideDown('.$speed.$callback.');';
}
// --------------------------------------------------------------------
@@ -594,7 +592,7 @@ class CI_Jquery extends CI_Javascript {
$callback = ", function(){\n{$callback}\n}";
}
- return "$({$element}).slideToggle({$speed}{$callback});";
+ return '$('.$element.').slideToggle('.$speed.$callback.');';
}
// --------------------------------------------------------------------
@@ -610,7 +608,7 @@ class CI_Jquery extends CI_Javascript {
protected function _toggle($element = 'this')
{
$element = $this->_prep_element($element);
- return "$({$element}).toggle();";
+ return '$('.$element.').toggle();';
}
// --------------------------------------------------------------------
@@ -626,7 +624,7 @@ class CI_Jquery extends CI_Javascript {
protected function _toggleClass($element = 'this', $class='')
{
$element = $this->_prep_element($element);
- return "$({$element}).toggleClass(\"$class\");";
+ return '$('.$element.').toggleClass("'.$class.'");';
}
// --------------------------------------------------------------------
@@ -651,7 +649,7 @@ class CI_Jquery extends CI_Javascript {
$callback = ", function(){\n{$callback}\n}";
}
- return "$({$element}).show({$speed}{$callback});";
+ return '$('.$element.').show('.$speed.$callback.');';
}
// --------------------------------------------------------------------
@@ -676,22 +674,22 @@ class CI_Jquery extends CI_Javascript {
// ajaxStart and ajaxStop are better choices here... but this is a stop gap
if ($this->CI->config->item('javascript_ajax_img') == '')
{
- $loading_notifier = "Loading...";
+ $loading_notifier = 'Loading...';
}
else
{
- $loading_notifier = '<img src=\''.$this->CI->config->slash_item('base_url').$this->CI->config->item('javascript_ajax_img').'\' alt=\'Loading\' />';
+ $loading_notifier = '<img src="'.$this->CI->config->slash_item('base_url').$this->CI->config->item('javascript_ajax_img').'" alt="Loading" />';
}
- $updater = "$($container).empty();\n" // anything that was in... get it out
- . "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image
+ $updater = '$('.$container.").empty();\n" // anything that was in... get it out
+ ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
$request_options = '';
if ($options != '')
{
$request_options .= ', {'
- . (is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'")
- . '}';
+ .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
+ .'}';
}
return $updater."\t\t$($container).load('$controller'$request_options);";
@@ -746,7 +744,7 @@ class CI_Jquery extends CI_Javascript {
$corner_style = '"'.$corner_style.'"';
}
- return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");";
+ return '$('.$this->_prep_element($element).').corner('.$corner_style.');';
}
// --------------------------------------------------------------------
@@ -821,16 +819,16 @@ class CI_Jquery extends CI_Javascript {
$sort_options = array();
foreach ($options as $k=>$v)
{
- $sort_options[] = "\n\t\t".$k.': '.$v."";
+ $sort_options[] = "\n\t\t".$k.': '.$v;
}
- $sort_options = implode(",", $sort_options);
+ $sort_options = implode(',', $sort_options);
}
else
{
$sort_options = '';
}
- return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});";
+ return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});";
}
// --------------------------------------------------------------------
@@ -844,7 +842,7 @@ class CI_Jquery extends CI_Javascript {
*/
public function tablesorter($table = '', $options = '')
{
- $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n";
+ $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n";
}
// --------------------------------------------------------------------
@@ -869,7 +867,7 @@ class CI_Jquery extends CI_Javascript {
}
- $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n";
+ $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
$this->jquery_code_for_compile[] = $event;
return $event;
}
@@ -898,8 +896,8 @@ class CI_Jquery extends CI_Javascript {
// Inline references
$script = '$(document).ready(function() {'."\n"
- . implode('', $this->jquery_code_for_compile)
- . '});';
+ .implode('', $this->jquery_code_for_compile)
+ .'});';
$output = ($script_tags === FALSE) ? $script : $this->inline($script);
@@ -998,7 +996,7 @@ class CI_Jquery extends CI_Javascript {
{
return '"'.$speed.'"';
}
- elseif (preg_match("/[^0-9]/", $speed))
+ elseif (preg_match('/[^0-9]/', $speed))
{
return '';
}
@@ -1009,4 +1007,4 @@ class CI_Jquery extends CI_Javascript {
}
/* End of file Jquery.php */
-/* Location: ./system/libraries/Jquery.php */
+/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
index 9f89d1be8..5216038c6 100644
--- a/tests/Bootstrap.php
+++ b/tests/Bootstrap.php
@@ -7,13 +7,30 @@ error_reporting(E_ALL | E_STRICT);
$dir = realpath(dirname(__FILE__));
// Path constants
-define('PROJECT_BASE', realpath($dir.'/../').'/');
-define('BASEPATH', PROJECT_BASE.'system/');
-define('APPPATH', PROJECT_BASE.'application/');
-define('VIEWPATH', PROJECT_BASE.'');
+defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/');
+defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/');
+defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/');
+defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.'');
+
+// Get vfsStream either via PEAR or composer
+foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
+{
+ if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.php'))
+ {
+ require_once 'vfsStream/vfsStream.php';
+ break;
+ }
+}
+
+if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.php'))
+{
+ include_once PROJECT_BASE.'vendor/autoload.php';
+ class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
+ class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
+ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
+}
// Prep our test environment
-require_once 'vfsStream/vfsStream.php';
include_once $dir.'/mocks/core/common.php';
include_once $dir.'/mocks/autoloader.php';
spl_autoload_register('autoload');
diff --git a/tests/README.md b/tests/README.md
index 6d83c34d8..c8fc608e8 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -1,12 +1,6 @@
# CodeIgniter Unit Tests #
-Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter)
-
-*Do not merge to default until these issues have been addressed*
-
-- Clean up naming conventions
-- Figure out config stuff
-- Figure out database testing
+Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=develop)](http://travis-ci.org/EllisLab/CodeIgniter)
### Introduction:
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
index 550245f2f..b48e32bfb 100644
--- a/tests/codeigniter/Setup_test.php
+++ b/tests/codeigniter/Setup_test.php
@@ -2,12 +2,12 @@
class Setup_test extends PHPUnit_Framework_TestCase {
- function test_nonsense()
+ function test_bootstrap_constants()
{
- $this->markTestIncomplete('not implemented');
- // ensure that our bootstrapped test environment
- // is a good representation of an isolated CI install
- //die('here');
+ $this->assertTrue(defined('PROJECT_BASE'));
+ $this->assertTrue(defined('BASEPATH'));
+ $this->assertTrue(defined('APPPATH'));
+ $this->assertTrue(defined('VIEWPATH'));
}
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
new file mode 100644
index 000000000..109b38821
--- /dev/null
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -0,0 +1,42 @@
+<?php
+
+class Benchmark_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->benchmark = new Mock_Core_Benchmark();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_mark()
+ {
+ $this->assertEmpty($this->benchmark->marker);
+
+ $this->benchmark->mark('code_start');
+
+ $this->assertEquals(1, count($this->benchmark->marker));
+ $this->assertArrayHasKey('code_start', $this->benchmark->marker);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_elapsed_time()
+ {
+ $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time());
+ $this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
+
+ $this->benchmark->mark('code_start');
+ sleep(1);
+ $this->benchmark->mark('code_end');
+
+ $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_memory_usage()
+ {
+ $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
new file mode 100644
index 000000000..a066d9960
--- /dev/null
+++ b/tests/codeigniter/core/Input_test.php
@@ -0,0 +1,146 @@
+<?php
+
+class Input_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ // Set server variable to GET as default, since this will leave unset in STDIN env
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+
+ // Set config for Input class
+ $this->ci_set_config('allow_get_array', TRUE);
+ $this->ci_set_config('global_xss_filtering', FALSE);
+ $this->ci_set_config('csrf_protection', FALSE);
+
+ $security = new Mock_Core_Security();
+ $utf8 = new Mock_Core_Utf8();
+
+ $this->input = new Mock_Core_Input($security, $utf8);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_not_exists()
+ {
+ $this->assertEmpty($this->input->get());
+ $this->assertEmpty($this->input->get('foo'));
+
+ $this->assertTrue( ! $this->input->get());
+ $this->assertTrue( ! $this->input->get('foo'));
+
+ // Test we're getting empty results
+ $this->assertTrue($this->input->get() == NULL);
+ $this->assertTrue($this->input->get('foo') == NULL);
+
+ // Test new 3.0 behaviour for non existant results (used to be FALSE)
+ $this->assertTrue($this->input->get() === NULL);
+ $this->assertTrue($this->input->get('foo') === NULL);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_exist()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_GET['foo'] = 'bar';
+
+ $this->assertArrayHasKey('foo', $this->input->get());
+ $this->assertEquals('bar', $this->input->get('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_exist_with_xss_clean()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_GET['harm'] = "Hello, i try to <script>alert('Hack');</script> your site";
+
+ $this->assertArrayHasKey('harm', $this->input->get());
+ $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->get('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $this->input->get('harm', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_not_exists()
+ {
+ $this->assertEmpty($this->input->post());
+ $this->assertEmpty($this->input->post('foo'));
+
+ $this->assertTrue( ! $this->input->post());
+ $this->assertTrue( ! $this->input->post('foo'));
+
+ $this->assertTrue($this->input->post() == NULL);
+ $this->assertTrue($this->input->post('foo') == NULL);
+
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_exist()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['foo'] = 'bar';
+
+ $this->assertArrayHasKey('foo', $this->input->post());
+ $this->assertEquals('bar', $this->input->post('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_exist_with_xss_clean()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['harm'] = "Hello, i try to <script>alert('Hack');</script> your site";
+
+ $this->assertArrayHasKey('harm', $this->input->post());
+ $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->post('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $this->input->post('harm', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_post()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['foo'] = 'bar';
+
+ $this->assertEquals('bar', $this->input->get_post('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_cookie()
+ {
+ $_COOKIE['foo'] = 'bar';
+
+ $this->assertEquals('bar', $this->input->cookie('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_server()
+ {
+ $this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_fetch_from_array()
+ {
+ $data = array(
+ 'foo' => 'bar',
+ 'harm' => 'Hello, i try to <script>alert(\'Hack\');</script> your site',
+ );
+
+ $foo = $this->input->fetch_from_array($data, 'foo');
+ $harm = $this->input->fetch_from_array($data, 'harm');
+ $harmless = $this->input->fetch_from_array($data, 'harm', TRUE);
+
+ $this->assertEquals('bar', $foo);
+ $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $harm);
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
new file mode 100644
index 000000000..b2f8c69d2
--- /dev/null
+++ b/tests/codeigniter/core/Security_test.php
@@ -0,0 +1,105 @@
+<?php
+
+class Security_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ // Set cookie for security test
+ $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE));
+
+ // Set config for Security class
+ $this->ci_set_config('csrf_protection', TRUE);
+ $this->ci_set_config('csrf_token_name', 'ci_csrf_token');
+ $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie');
+
+ $this->security = new Mock_Core_Security();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+
+ $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify_invalid()
+ {
+ // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+
+ $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed');
+
+ $this->security->csrf_verify();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify_valid()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash;
+
+ $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_csrf_hash()
+ {
+ $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_csrf_token_name()
+ {
+ $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_xss_clean()
+ {
+ $harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
+
+ $harmless_string = $this->security->xss_clean($harm_string);
+
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_string);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_xss_hash()
+ {
+ $this->assertEmpty($this->security->xss_hash);
+
+ // Perform hash
+ $this->security->xss_hash();
+
+ $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_entity_decode()
+ {
+ $encoded = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
+ $decoded = $this->security->entity_decode($encoded);
+
+ $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_sanitize_filename()
+ {
+ $filename = './<!--foo-->';
+ $safe_filename = $this->security->sanitize_filename($filename);
+
+ $this->assertEquals('foo', $safe_filename);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
index fb40f0608..9e16e29b4 100644
--- a/tests/codeigniter/database/DB_driver_test.php
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -2,8 +2,6 @@
class DB_driver_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_initialize()
{
$config = Mock_Database_DB::config(DB_DRIVER);
@@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase {
{
return new Mock_Database_Drivers_Postgre($config);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
index 9b93e223d..d5c0dea08 100644
--- a/tests/codeigniter/database/DB_test.php
+++ b/tests/codeigniter/database/DB_test.php
@@ -2,8 +2,6 @@
class DB_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_db_invalid()
{
$connection = new Mock_Database_DB(array(
@@ -45,5 +43,5 @@ class DB_test extends CI_TestCase {
$this->assertTrue($db instanceof CI_DB);
$this->assertTrue($db instanceof CI_DB_Driver);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php
new file mode 100644
index 000000000..5e691692d
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -0,0 +1,44 @@
+<?php
+
+class Count_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_count_all()
+ {
+ $job_count = $this->db->count_all('job');
+
+ // Check the result
+ $this->assertEquals(4, $job_count);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_count_all_results()
+ {
+ $job_count = $this->db->like('name', 'ian')
+ ->count_all_results('job');
+
+ // Check the result
+ $this->assertEquals(2, $job_count);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php
new file mode 100644
index 000000000..84ea7616f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -0,0 +1,72 @@
+<?php
+
+class Delete_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_delete()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Developer', $job1->name);
+
+ // Do the delete
+ $this->db->delete('job', array('id' => 1));
+
+ // Check the record
+ $job1 = $this->db->where('id', 1)
+ ->get('job');
+
+ $this->assertEmpty($job1->result_array());
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_delete_several_tables()
+ {
+ // Check initial record
+ $user4 = $this->db->where('id', 4)
+ ->get('user')
+ ->row();
+
+ $job4 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Musician', $job4->name);
+ $this->assertEquals('Chris Martin', $user4->name);
+
+ // Do the delete
+ $this->db->delete(array('job', 'user'), array('id' => 4));
+
+ // Check the record
+ $job4 = $this->db->where('id', 4)->get('job');
+ $user4 = $this->db->where('id', 4)->get('user');
+
+ $this->assertEmpty($job4->result_array());
+ $this->assertEmpty($user4->result_array());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php
new file mode 100644
index 000000000..925eadb19
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -0,0 +1,34 @@
+<?php
+
+class Distinct_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_distinct()
+ {
+ $users = $this->db->select('country')
+ ->distinct()
+ ->get('user')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($users));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php
new file mode 100644
index 000000000..d1f56285f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/empty_test.php
@@ -0,0 +1,39 @@
+<?php
+
+class Empty_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_empty_table()
+ {
+ // Check initial record
+ $jobs = $this->db->get('job')->result_array();
+
+ $this->assertEquals(4, count($jobs));
+
+ // Do the empty
+ $this->db->empty_table('job');
+
+ // Check the record
+ $jobs = $this->db->get('job');
+
+ $this->assertEmpty($jobs->result_array());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
new file mode 100644
index 000000000..5d575a37b
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -0,0 +1,67 @@
+<?php
+
+class Escape_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_percent_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\%foo');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($res));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_backslash_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\\');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($res));
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php
new file mode 100644
index 000000000..95ae4dfdb
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -0,0 +1,51 @@
+<?php
+
+class From_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_from_simple()
+ {
+ $jobs = $this->db->from('job')
+ ->get()
+ ->result_array();
+
+ // Check items
+ $this->assertEquals(4, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_from_with_where()
+ {
+ $job1 = $this->db->from('job')
+ ->where('id', 1)
+ ->get()
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
new file mode 100644
index 000000000..7d8abc33f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -0,0 +1,53 @@
+<?php
+
+class Group_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_group_by()
+ {
+ $jobs = $this->db->select('name')
+ ->from('job')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_having_by()
+ {
+ $jobs = $this->db->select('name')
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 53ce23c19..8ba60e242 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -30,11 +30,10 @@ class Insert_test extends CI_TestCase {
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
- $jobs = $this->db->get('job')->result_array();
- $job1 = $jobs[0];
+ $job1 = $this->db->get('job')->row();
// Check the result
- $this->assertEquals('Grocery Sales', $job1['name']);
+ $this->assertEquals('Grocery Sales', $job1->name);
}
diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php
new file mode 100644
index 000000000..e05329d67
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -0,0 +1,38 @@
+<?php
+
+class Join_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_join_simple()
+ {
+ $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name')
+ ->from('job')
+ ->join('user', 'user.id = job.id')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals('1', $job_user[0]['job_id']);
+ $this->assertEquals('1', $job_user[0]['user_id']);
+ $this->assertEquals('Derek Jones', $job_user[0]['user_name']);
+ $this->assertEquals('Developer', $job_user[0]['job_name']);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
new file mode 100644
index 000000000..df98c713f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -0,0 +1,90 @@
+<?php
+
+class Like_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_like()
+ {
+ $job1 = $this->db->like('name', 'veloper')
+ ->get('job')
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_or_like()
+ {
+ $jobs = $this->db->like('name', 'ian')
+ ->or_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Politician', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_not_like()
+ {
+ $jobs = $this->db->not_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_or_not_like()
+ {
+ $jobs = $this->db->like('name', 'an')
+ ->or_not_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php
new file mode 100644
index 000000000..704f3b651
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -0,0 +1,49 @@
+<?php
+
+class Limit_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_limit()
+ {
+ $jobs = $this->db->limit(2)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_limit_and_offset()
+ {
+ $jobs = $this->db->limit(2, 2)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Accountant', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php
new file mode 100644
index 000000000..01aa1c2b4
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -0,0 +1,55 @@
+<?php
+
+class Order_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_order_ascending()
+ {
+ $jobs = $this->db->order_by('name', 'asc')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ $this->assertEquals('Accountant', $jobs[0]['name']);
+ $this->assertEquals('Developer', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ $this->assertEquals('Politician', $jobs[3]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_order_descending()
+ {
+ $jobs = $this->db->order_by('name', 'desc')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ $this->assertEquals('Developer', $jobs[2]['name']);
+ $this->assertEquals('Accountant', $jobs[3]['name']);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index dbf432a7c..0d299ed16 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -41,10 +41,10 @@ class Select_test extends CI_TestCase {
{
$job_min = $this->db->select_min('id')
->get('job')
- ->result_array();
+ ->row();
// Minimum id was 1
- $this->assertEquals('1', $job_min[0]['id']);
+ $this->assertEquals('1', $job_min->id);
}
// ------------------------------------------------------------------------
@@ -56,10 +56,10 @@ class Select_test extends CI_TestCase {
{
$job_max = $this->db->select_max('id')
->get('job')
- ->result_array();
+ ->row();
// Maximum id was 4
- $this->assertEquals('4', $job_max[0]['id']);
+ $this->assertEquals('4', $job_max->id);
}
// ------------------------------------------------------------------------
@@ -71,10 +71,10 @@ class Select_test extends CI_TestCase {
{
$job_avg = $this->db->select_avg('id')
->get('job')
- ->result_array();
+ ->row();
// Average should be 2.5
- $this->assertEquals('2.5', $job_avg[0]['id']);
+ $this->assertEquals('2.5', $job_avg->id);
}
// ------------------------------------------------------------------------
@@ -86,10 +86,10 @@ class Select_test extends CI_TestCase {
{
$job_sum = $this->db->select_sum('id')
->get('job')
- ->result_array();
+ ->row();
// Sum of ids should be 10
- $this->assertEquals('10', $job_sum[0]['id']);
+ $this->assertEquals('10', $job_sum->id);
}
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php
new file mode 100644
index 000000000..2a9c8a91e
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -0,0 +1,61 @@
+<?php
+
+class Truncate_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_truncate()
+ {
+ // Check initial record
+ $jobs = $this->db->get('job')->result_array();
+
+ $this->assertEquals(4, count($jobs));
+
+ // Do the empty
+ $this->db->truncate('job');
+
+ // Check the record
+ $jobs = $this->db->get('job');
+
+ $this->assertEmpty($jobs->result_array());
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_truncate_with_from()
+ {
+ // Check initial record
+ $users = $this->db->get('user')->result_array();
+
+ $this->assertEquals(4, count($users));
+
+ // Do the empty
+ $this->db->from('user')
+ ->truncate();
+
+ // Check the record
+ $users = $this->db->get('user');
+
+ $this->assertEmpty($users->result_array());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php
new file mode 100644
index 000000000..f5bbffd4f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -0,0 +1,71 @@
+<?php
+
+class Update_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_update()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Developer', $job1->name);
+
+ // Do the update
+ $job_data = array('name' => 'Programmer');
+
+ $this->db->where('id', 1)
+ ->update('job', $job_data);
+
+ // Check updated record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Programmer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_update_with_set()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Musician', $job1->name);
+
+ // Do the update
+ $this->db->set('name', 'Vocalist');
+ $this->db->update('job', NULL, 'id = 4');
+
+ // Check updated record
+ $job1 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Vocalist', $job1->name);
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php
new file mode 100644
index 000000000..607eaa076
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -0,0 +1,144 @@
+<?php
+
+class Where_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_simple_key_value()
+ {
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_custom_key_value()
+ {
+ $jobs = $this->db->where('id !=', 1)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_associative_array()
+ {
+ $where = array('id >' => 2, 'name !=' => 'Accountant');
+ $jobs = $this->db->where($where)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($jobs));
+
+ // Should be Musician
+ $job = current($jobs);
+
+ $this->assertEquals('Musician', $job['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_custom_string()
+ {
+ $where = "id > 2 AND name != 'Accountant'";
+ $jobs = $this->db->where($where)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($jobs));
+
+ // Should be Musician
+ $job = current($jobs);
+
+ $this->assertEquals('Musician', $job['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_or()
+ {
+ $jobs = $this->db->where('name !=', 'Accountant')
+ ->or_where('id >', 3)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Politician', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_in()
+ {
+ $jobs = $this->db->where_in('name', array('Politician', 'Accountant'))
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_not_in()
+ {
+ $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant'))
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index 13f338c6b..f5133de1e 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -291,6 +291,26 @@ class Table_test extends CI_TestCase {
);
}
- // Test main generate method
- // --------------------------------------------------------------------
+ function test_generate()
+ {
+ // Prepare the data
+ $data = array(
+ array('Name', 'Color', 'Size'),
+ array('Fred', 'Blue', 'Small'),
+ array('Mary', 'Red', 'Large'),
+ array('John', 'Green', 'Medium')
+ );
+
+ $table = $this->table->generate($data);
+
+ // Test the table header
+ $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
+
+ // Test the first entry
+ $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
+ }
} \ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index f1bdb5d6f..441c88944 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -6,7 +6,6 @@
//
// Prototype :
//
-// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
@@ -23,7 +22,7 @@ function autoload($class)
);
$ci_libraries = array(
- 'Calendar', 'Cart', 'Driver',
+ 'Calendar', 'Cart', 'Driver_Library',
'Email', 'Encrypt', 'Form_validation',
'Ftp', 'Image_lib', 'Javascript',
'Log', 'Migration', 'Pagination',
@@ -51,7 +50,7 @@ function autoload($class)
elseif (in_array($subclass, $ci_libraries))
{
$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
- $class = $subclass;
+ $class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass;
}
elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
{
diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php
new file mode 100644
index 000000000..d92be21db
--- /dev/null
+++ b/tests/mocks/core/benchmark.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Core_Benchmark extends CI_Benchmark {} \ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
index fc94d7fff..e74576626 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -2,53 +2,65 @@
// Set up the global CI functions in their most minimal core representation
-function &get_instance()
+if ( ! function_exists('get_instance'))
{
- $test = CI_TestCase::instance();
- $instance = $test->ci_instance();
- return $instance;
+ function &get_instance()
+ {
+ $test = CI_TestCase::instance();
+ $instance = $test->ci_instance();
+ return $instance;
+ }
}
// --------------------------------------------------------------------
-function &get_config() {
- $test = CI_TestCase::instance();
- $config = $test->ci_get_config();
-
- return $config;
+if ( ! function_exists('get_config'))
+{
+ function &get_config() {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+
+ return $config;
+ }
}
-function config_item($item)
+if ( ! function_exists('config_item'))
{
- $config =& get_config();
-
- if ( ! isset($config[$item]))
+ function config_item($item)
{
- return FALSE;
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
}
-
- return $config[$item];
}
// --------------------------------------------------------------------
-function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+if ( ! function_exists('load_class'))
{
- if ($directory != 'core' OR $prefix != 'CI_')
- {
- throw new Exception('Not Implemented: Non-core load_class()');
- }
-
- $test = CI_TestCase::instance();
-
- $obj =& $test->ci_core_class($class);
-
- if (is_string($obj))
+ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
- throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.'');
+ if ($directory != 'core' OR $prefix != 'CI_')
+ {
+ throw new Exception('Not Implemented: Non-core load_class()');
+ }
+
+ $test = CI_TestCase::instance();
+
+ $obj =& $test->ci_core_class($class);
+
+ if (is_string($obj))
+ {
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.'');
+ }
+
+ return $obj;
}
-
- return $obj;
}
// This is sort of meh. Should probably be mocked up with
@@ -57,76 +69,103 @@ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
// bootstrap testsuite.
// --------------------------------------------------------------------
-function remove_invisible_characters($str, $url_encoded = TRUE)
+if ( ! function_exists('remove_invisible_characters'))
{
- $non_displayables = array();
-
- // every control character except newline (dec 10)
- // carriage return (dec 13), and horizontal tab (dec 09)
-
- if ($url_encoded)
+ function remove_invisible_characters($str, $url_encoded = TRUE)
{
- $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
+ $non_displayables = array();
+
+ // 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
- {
- $str = preg_replace($non_displayables, '', $str, -1, $count);
- }
- while ($count);
+ do
+ {
+ $str = preg_replace($non_displayables, '', $str, -1, $count);
+ }
+ while ($count);
- return $str;
+ return $str;
+ }
}
// Clean up error messages
// --------------------------------------------------------------------
-function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+if ( ! function_exists('show_error'))
{
- throw new RuntimeException('CI Error: '.$message);
+ function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+ {
+ throw new RuntimeException('CI Error: '.$message);
+ }
}
-function show_404($page = '', $log_error = TRUE)
+if ( ! function_exists('show_404'))
{
- throw new RuntimeException('CI Error: 404');
+ function show_404($page = '', $log_error = TRUE)
+ {
+ throw new RuntimeException('CI Error: 404');
+ }
}
-function _exception_handler($severity, $message, $filepath, $line)
+if ( ! function_exists('_exception_handler'))
{
- throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ function _exception_handler($severity, $message, $filepath, $line)
+ {
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ }
}
// We assume a few things about our environment ...
// --------------------------------------------------------------------
-function is_php($version = '5.0.0')
+if ( ! function_exists('is_php'))
{
- return ! (version_compare(PHP_VERSION, $version) < 0);
+ function is_php($version = '5.0.0')
+ {
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+ }
}
-function is_really_writable($file)
+if ( ! function_exists('is_really_writable'))
{
- return is_writable($file);
+ function is_really_writable($file)
+ {
+ return is_writable($file);
+ }
}
-function is_loaded()
+if ( ! function_exists('is_loaded'))
{
- throw new Exception('Bad Isolation: mock up environment');
+ function is_loaded()
+ {
+ throw new Exception('Bad Isolation: mock up environment');
+ }
}
-function log_message($level = 'error', $message, $php_error = FALSE)
+if ( ! function_exists('log_message'))
{
- return TRUE;
+ function log_message($level = 'error', $message, $php_error = FALSE)
+ {
+ return TRUE;
+ }
}
-function set_status_header($code = 200, $text = '')
+if ( ! function_exists('set_status_header'))
{
- return TRUE;
+ function set_status_header($code = 200, $text = '')
+ {
+ return TRUE;
+ }
}
// EOF \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
new file mode 100644
index 000000000..8a337d2ef
--- /dev/null
+++ b/tests/mocks/core/input.php
@@ -0,0 +1,31 @@
+<?php
+
+class Mock_Core_Input extends CI_Input {
+
+ /**
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
+ * the same process within CI_Input class constructor.
+ *
+ * @covers CI_Input::__construct()
+ */
+ public function __construct($security, $utf8)
+ {
+ $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);
+
+ // Assign Security and Utf8 classes
+ $this->security = $security;
+ $this->uni = $utf8;
+
+ // Sanitize global arrays
+ $this->_sanitize_globals();
+ }
+
+ public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
+ {
+ return parent::_fetch_from_array($array, $index, $xss_clean);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
new file mode 100644
index 000000000..d7ea0e6bd
--- /dev/null
+++ b/tests/mocks/core/security.php
@@ -0,0 +1,30 @@
+<?php
+
+class Mock_Core_Security extends CI_Security {
+
+ public function csrf_set_cookie()
+ {
+ // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
+ // we superseded set_cookie with directly set the cookie variable,
+ // @see : ./tests/codeigniter/core/Security_test.php, line 8
+ return $this;
+ }
+
+ // Overide inaccesible protected properties
+ public function __get($property)
+ {
+ return isset($this->{'_'.$property}) ? $this->{'_'.$property} : NULL;
+ }
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
new file mode 100644
index 000000000..b77d717e7
--- /dev/null
+++ b/tests/mocks/core/utf8.php
@@ -0,0 +1,27 @@
+<?php
+
+class Mock_Core_Utf8 extends CI_Utf8 {
+
+ /**
+ * We need to define several constants as
+ * the same process within CI_Utf8 class constructor.
+ *
+ * @covers CI_Utf8::__construct()
+ */
+ public function __construct()
+ {
+ defined('UTF8_ENABLED') or define('UTF8_ENABLED', TRUE);
+
+ if (extension_loaded('mbstring'))
+ {
+ defined('MB_ENABLED') or define('MB_ENABLED', TRUE);
+ mb_internal_encoding('UTF-8');
+ }
+ else
+ {
+ defined('MB_ENABLED') or define('MB_ENABLED', FALSE);
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 86d868af2..44dcef9ec 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index a3d5bac65..05499f82f 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -50,6 +50,28 @@ class Mock_Database_Schema_Skeleton {
*/
public static function create_tables()
{
+ // User Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'email' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 100,
+ ),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
+
// Job Table
static::$forge->add_field(array(
'id' => array(
@@ -66,6 +88,23 @@ class Mock_Database_Schema_Skeleton {
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+
+ // Misc Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'key' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'value' => array(
+ 'type' => 'TEXT',
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
}
/**
@@ -77,12 +116,22 @@ class Mock_Database_Schema_Skeleton {
{
// Job Data
$data = array(
+ 'user' => array(
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'),
+ ),
'job' => array(
array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
),
+ 'misc' => array(
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'),
+ ),
);
foreach ($data as $table => $dummy_data)
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 1a6ff8d35..97fbb30bd 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -2,7 +2,7 @@
class Mock_Libraries_Table extends CI_Table {
- // Overide inaccesible private or protected method
+ // Overide inaccesible protected method
public function __call($method, $params)
{
if (is_callable(array($this, '_'.$method)))
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index e9556f758..38c8eba48 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
index 69eece24f..c3113a66f 100644
--- a/tests/travis/pdo/mysql.phpunit.xml
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
- <directory suffix="test.php">../../codeigniter/database</directory>
+ <directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
index e68c3e028..232025523 100644
--- a/tests/travis/pdo/pgsql.phpunit.xml
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
- <directory suffix="test.php">../../codeigniter/database</directory>
+ <directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
index 1871f6221..3d1256721 100644
--- a/tests/travis/pdo/sqlite.phpunit.xml
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
- <directory suffix="test.php">../../codeigniter/database</directory>
+ <directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index ad8aeded2..51e433d76 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 628370e93..701165734 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -14,19 +14,12 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- <directory suffix=".php">PROJECT_BASE.'tests'</directory>
- <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index d457a3fbc..3989b52d2 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -9,8 +9,7 @@ Release Date: Not Released
- License
- - CodeIgniter has been relicensed with the Open Software License (3.0),
- eliminating its old proprietary licensing.
+ - CodeIgniter has been relicensed with the Open Software License (3.0), eliminating its old proprietary licensing.
- All system files are licensed with OSL 3.0.
- Config, error, and sample files shipped in the application folder are
@@ -38,12 +37,15 @@ Release Date: Not Released
Only entries in ``$autoload['libraries']`` are auto-loaded now.
- Added some more doctypes.
- Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
+ - Moved error templates to "application/views/errors"
+ - Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per Env.
- Helpers
+ - create_captcha() accepts additional colors parameter, allowing for color customization
- 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.
+ - 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).
- Added an optional third parameter to ``timespan()`` that constrains the number of time units displayed.
@@ -52,24 +54,21 @@ Release Date: Not Released
- set_realpath() can now also handle file paths as opposed to just directories.
- do_hash() now uses PHP's native hash() function, supporting more algorithms.
- Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
+ - Removed deprecated helper function ``js_insert_smiley()`` from smiley helper.
- Database
- - Renamed the Active Record class to Query Builder to remove confusion with
- the Active Record design pattern
- - Added new :doc:`Query Builder <database/query_builder>` methods that return
+ - Renamed the Active Record class to Query Builder to remove confusion with the Active Record design pattern.
- Added the ability to insert objects with insert_batch() in :doc:`Query Builder <database/query_builder>`.
- - Added new :doc:`Query Builder <database/query_builder>` methods that return
- the SQL string of queries without executing them: get_compiled_select(),
- get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- - Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - Added new :doc:`Query Builder <database/query_builder>` methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
+ - Adding $escape parameter to the order_by() method, this enables ordering by custom fields.
- Improved support for the MySQLi driver, including:
- OOP style of the PHP extension is now used, instead of the procedural aliases.
- Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
- Added persistent connections support for PHP >= 5.3.
- Added 'dsn' configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
- Improved PDO database support.
- - Added Interbase/Firebird database support via the "interbase" driver
+ - Added Interbase/Firebird database support via the "interbase" driver.
- Added an optional database name parameter to db_select().
- Replaced the _error_message() and _error_number() methods with error(), that returns an array containing the last database error code and message.
- Improved version() implementation so that drivers that have a native function to get the version number don't have to be defined in the core DB_driver class.
@@ -77,6 +76,8 @@ Release Date: Not Released
- pg_version() is now used to get the database version number, when possible.
- Added db_set_charset() support.
- Added _optimize_table() support for the :doc:`Database Utility Class <database/utilities>` (rebuilds table indexes).
+ - Added boolean data type support in escape().
+ - Added update_batch() support.
- Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction.
- Removed limit() and order_by() support for UPDATE and DELETE queries in PostgreSQL driver. Postgres does not support those features.
- Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias.
@@ -100,6 +101,7 @@ Release Date: Not Released
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`.
- Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility <database/utilities>`.
- Improved CUBRID support for list_databases() in :doc:`Database Utility <database/utilities>` (until now only the currently used database was returned).
+ - Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory).
- Libraries
@@ -107,17 +109,15 @@ Release Date: Not Released
- CI_Loader::_ci_autoloader() is now a protected method.
- Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname).
- Added possibility to send attachment as buffer string in Email::attach() as $this->email->attach($buffer, $disposition, $newname, $mime).
- - Cart library changes include:
+ - :doc:`Cart library <libraries/cart>` 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"
- - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatability
+ - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe".
+ - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatibility.
- :doc:`Image Manipulation library <libraries/image_lib>` changes include:
- The initialize() method now only sets existing class properties.
- 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.
+ - 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.
- :doc:`Form Validation library <libraries/form_validation>` changes include:
@@ -150,26 +150,26 @@ Release Date: Not Released
Bug fixes for 3.0
------------------
-- Unlink raised an error if cache file did not exist when you try to delete it.
+- Fixed a bug where ``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 (#159, #163) that mishandled Active Record nested transactions because _trans_depth was not getting incremented.
+- Fixed a bug (#159, #163) that mishandled Query Builder 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.
- Fixed a bug (#724) - is_unique in form validation now checks that you are connected to a database.
-- Fixed a bug (#647) - _get_mod_time() in Zip library no longer generates stat failed errors
-- Fixed a bug (#608) - Fixes an issue with the Image_lib class not clearing properties completely
-- Fixed bugs (#157 and #174) - the Image_lib clear() function now resets all variables to their default values.
+- Fixed a bug (#647) - _get_mod_time() in Zip library no longer generates stat failed errors.
+- Fixed a bug (#608) - Fixes an issue with the Image_lib class not clearing properties completely.
+- Fixed a bug (#157, #174) - the Image_lib clear() function now resets all variables to their default values.
- Fixed a bug where using $this->dbforge->create_table() with PostgreSQL database could lead to fetching whole table.
- Fixed a bug (#795) - Fixed form method and accept-charset when passing an empty array.
-- Fixed a bug (#797) - timespan was using incorrect seconds for year and month.
+- Fixed a bug (#797) - timespan() was using incorrect seconds for year and month.
- Fixed a bug in CI_Cart::contents() where if called without a TRUE (or equal) parameter, it would fail due to a typo.
-- Fixed a bug (#696) - make oci_execute calls inside num_rows non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed.
-- Fixed a bug (#406) - sqlsrv DB driver not reuturning resource on <samp>db_pconnect()</samp>.
+- Fixed a bug (#696) - make oci_execute() calls inside num_rows() non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed.
+- Fixed a bug (#406) - sqlsrv DB driver not returning resource on ``db_pconnect()``.
- 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 in the :doc:`Pagination library <libraries/pagination>` where when use_page_numbers=TRUE previous link and page 1 link did 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 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.
@@ -180,7 +180,7 @@ Bug fixes for 3.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 handling 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 (#1036) - is_write_type() method in the :doc:`Database Library <database/index>` didn't return TRUE for RENAME 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.
@@ -193,18 +193,18 @@ Bug fixes for 3.0
- Fixed a bug (#499) - a CSRF cookie was created even with CSRF protection being disabled.
- Fixed a bug (#306) - ODBC's insert_id() method was calling non-existent function odbc_insert_id(), which resulted in a fatal error.
- Fixed a bug in Oracle's DB_result class where the cursor id passed to it was always NULL.
-- Fixed a bug (#64) - Regular expression in DB_active_rec.php failed to handle queries containing SQL bracket delimiters in the join condition.
+- Fixed a bug (#64) - Regular expression in DB_query_builder.php failed to handle queries containing SQL bracket delimiters in the join condition.
- Fixed a bug in the :doc:`Session Library <libraries/sessions>` where a PHP E_NOTICE error was triggered by _unserialize() due to results from databases such as MSSQL and Oracle being space-padded on the right.
- Fixed a bug (#501) - set_rules() to check if the request method is not 'POST' before aborting, instead of depending on count($_POST) in the :doc:`Form Validation Library <libraries/form_validation>`.
- Fixed a bug (#940) - csrf_verify() used to set the CSRF cookie while processing a POST request with no actual POST data, which resulted in validating a request that should be considered invalid.
-- Fixed a bug in PostgreSQL's escape_str() where it didn't properly escape LIKE wild characters.
+- Fixed a bug (#136) - PostgreSQL, MySQL and MySQLi's escape_str() method didn't properly escape LIKE wild characters.
- Fixed a bug in the library loader where some PHP versions wouldn't execute the class constructor.
- Fixed a bug (#88) - An unexisting property was used for configuration of the Memcache cache driver.
- Fixed a bug (#14) - create_database() method in the :doc:`Database Forge Library <database/forge>` didn't utilize the configured database character set.
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library <database/caching>` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library <libraries/trackback>` method validate_url() where it didn't actually do anything, due to input not being passed by reference.
- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found.
-- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories
+- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories.
- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library <libraries/zip>` wasn't compatible with Windows.
- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it.
- Fixed a bug in MSSQL and SQLSrv's _truncate() where the TABLE keyword was missing.
@@ -214,9 +214,15 @@ Bug fixes for 3.0
- Fixed a bug in SQLSRV's delete() method where like() and limit() conditions were ignored.
- Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
- Fixed a bug (#128) - :doc:`Language Library <libraries/language>` did not correctly keep track of loaded language files.
-- Fixed a bug (#1242) - Added Windows path compatibility to function read_dir of ZIP library
+- Fixed a bug (#1242) - Added Windows path compatibility to function read_dir of ZIP library.
- Fixed a bug (#1314) - sess_destroy() did not destroy userdata.
-- Fixed a bug (#1349) - get_extension() in the `File Uploading Library <libraries/file_uploading>` returned the original filename when it didn't have an actual extension.
+- Fixed a bug (#1349) - get_extension() in the :doc:`File Uploading Library <libraries/file_uploading>` returned the original filename when it didn't have an actual extension.
+- Fixed a bug (#1273) - E_NOTICE being generated by :doc:`Query Builder <database/query_builder>`'s set_update_batch() method.
+- Fixed a bug (#44, #110) - :doc:`Upload library <libraries/file_uploading>`'s clean_file_name() method didn't clear '!' and '#' characters.
+- Fixed a bug (#121) - ``CI_DB_result::row()`` returned an array when there's no actual result to be returned.
+- Fixed a bug (#319) - SQLSRV's affected_rows() method failed due to a scrollable cursor being created for write-type queries.
+- Fixed a bug (#356) - PostgreSQL driver didn't have an _update_batch() method, which resulted in fatal error being triggered when update_batch() is used with it.
+- Fixed a bug (#862) - create_table() failed on SQLSRV/MSSQL when used with 'IF NOT EXISTS'.
Version 2.1.1
=============
@@ -239,7 +245,9 @@ Bug fixes for 2.1.1
- 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.
-- Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found
+- Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
+- Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
+- Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite.
Version 2.1.0
=============
diff --git a/user_guide_src/source/database/results.rst b/user_guide_src/source/database/results.rst
index 865345762..ac4fc3733 100644
--- a/user_guide_src/source/database/results.rst
+++ b/user_guide_src/source/database/results.rst
@@ -136,6 +136,26 @@ parameter:
| **$row = $query->next_row('array')**
| **$row = $query->previous_row('array')**
+.. note:: all the functions above will load the whole result into memory (prefetching) use unbuffered_row() for processing large result sets.
+
+unbuffered_row($type)
+=====
+
+This function returns a single result row without prefetching the whole result in memory as row() does.
+If your query has more than one row, it returns the current row and moves the internal data pointer ahead.
+The result is returned as $type could be 'object' (default) or 'array' that will return an associative array.
+
+
+
+ $query = $this->db->query("YOUR QUERY");
+
+ while ($row = $query->unbuffered_row())
+ {
+ echo $row->title;
+ echo $row->name;
+ echo $row->body;
+ }
+
***********************
Result Helper Functions
***********************
diff --git a/user_guide_src/source/installation/upgrade_200.rst b/user_guide_src/source/installation/upgrade_200.rst
index b39f4fd23..29f44bd9e 100644
--- a/user_guide_src/source/installation/upgrade_200.rst
+++ b/user_guide_src/source/installation/upgrade_200.rst
@@ -87,7 +87,14 @@ All native CodeIgniter classes now use the PHP 5 \__construct()
convention. Please update extended libraries to call
parent::\__construct().
-Step 8: Update your user guide
+Step 8: Move any core extensions to application/core
+====================================================
+
+Any extensions to core classes (e.g. MY_Controller.php) in your
+application/libraries folder must be moved to the new
+application/core folder.
+
+Step 9: Update your user guide
==============================
Please replace your local copy of the user guide with the new version,
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index e434e8d45..63c4227dc 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -40,4 +40,9 @@ need to rename the `$active_record` variable to `$query_builder`.
$active_group = 'default';
// $active_record = TRUE;
- $query_builder = TRUE; \ No newline at end of file
+ $query_builder = TRUE;
+
+Step 5: Move your errors folder
+===============================
+
+In version 3.0.0, the errors folder has been moved from "application/errors" to "application/views/errors". \ No newline at end of file
diff --git a/user_guide_src/source/libraries/config.rst b/user_guide_src/source/libraries/config.rst
index c81cad7b3..08d9c2905 100644
--- a/user_guide_src/source/libraries/config.rst
+++ b/user_guide_src/source/libraries/config.rst
@@ -149,11 +149,13 @@ folders:
- Your own custom configuration files
.. note::
- CodeIgniter always tries to load the configuration files for
- the current environment first. If the file does not exist, the global
- config file (i.e., the one in application/config/) is loaded. This means
- you are not obligated to place **all** of your configuration files in an
- environment folder − only the files that change per environment.
+ CodeIgniter always loads the global config file first (i.e., the one in application/config/),
+ then tries to load the configuration files for the current environment.
+ This means you are not obligated to place **all** of your configuration files in an
+ environment folder. Only the files that change per environment. Additionally you don't
+ have to copy **all** the config items in the environment config file. Only the config items
+ that you wish to change for your environment. The config items declared in your environment
+ folders always overwrite those in your global config files.
Helper Functions
================
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index 1f2ea650a..432bac3c7 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -18,7 +18,7 @@ The security filtering function is called automatically when a new
:doc:`controller <../general/controllers>` is invoked. It does the
following:
-- If $config['allow_get_array'] is FALSE(default is TRUE), destroys
+- If $config['allow_get_array'] is FALSE (default is TRUE), destroys
the global GET array.
- Destroys all global variables in the event register_globals is
turned on.
@@ -53,14 +53,7 @@ false (boolean) if not. This lets you conveniently use data without
having to test whether an item exists first. In other words, normally
you might do something like this::
- if ( ! isset($_POST['something']))
- {
- $something = FALSE;
- }
- else
- {
- $something = $_POST['something'];
- }
+ $something = isset($_POST['something']) ? $_POST['something'] : NULL;
With CodeIgniter's built in functions you can simply do this::
@@ -95,7 +88,7 @@ To return an array of all POST items call without any parameters.
To return all POST items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns FALSE (boolean) if there are no items in the POST.
+The function returns NULL if there are no items in the POST.
::
@@ -115,7 +108,7 @@ To return an array of all GET items call without any parameters.
To return all GET items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns FALSE (boolean) if there are no items in the GET.
+The function returns NULL if there are no items in the GET.
::
@@ -210,7 +203,7 @@ the cookie you are looking for (including any prefixes)::
cookie('some_cookie');
-The function returns FALSE (boolean) if the item you are attempting to
+The function returns NULL if the item you are attempting to
retrieve does not exist.
The second optional parameter lets you run the data through the XSS
diff --git a/user_guide_src/source/libraries/uri.rst b/user_guide_src/source/libraries/uri.rst
index ee60b77d7..cdd76e322 100644
--- a/user_guide_src/source/libraries/uri.rst
+++ b/user_guide_src/source/libraries/uri.rst
@@ -25,7 +25,7 @@ The segment numbers would be this:
#. metro
#. crime_is_up
-By default the function returns FALSE (boolean) if the segment does not
+By default the function returns NULL if the segment does not
exist. There is an optional second parameter that permits you to set
your own default value if the segment is missing. For example, this
would tell the function to return the number zero in the event of