summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml18
-rw-r--r--application/config/autoload.php2
-rw-r--r--application/config/config.php4
-rw-r--r--application/config/constants.php2
-rw-r--r--application/config/database.php4
-rw-r--r--application/config/doctypes.php2
-rw-r--r--application/config/foreign_chars.php2
-rw-r--r--application/config/hooks.php2
-rw-r--r--application/config/memcached.php2
-rw-r--r--application/config/migration.php2
-rw-r--r--application/config/mimes.php8
-rw-r--r--application/config/profiler.php2
-rw-r--r--application/config/routes.php2
-rw-r--r--application/config/smileys.php2
-rw-r--r--application/config/user_agents.php2
-rw-r--r--application/controllers/welcome.php2
-rw-r--r--application/errors/error_404.php2
-rw-r--r--application/errors/error_db.php2
-rw-r--r--application/errors/error_general.php2
-rw-r--r--application/errors/error_php.php2
-rw-r--r--application/views/welcome_message.php2
-rw-r--r--index.php4
-rw-r--r--license.rst245
-rw-r--r--readme.rst12
-rwxr-xr-xsystem/core/Benchmark.php2
-rwxr-xr-xsystem/core/CodeIgniter.php2
-rw-r--r--system/core/Common.php36
-rwxr-xr-xsystem/core/Config.php6
-rw-r--r--system/core/Controller.php2
-rwxr-xr-xsystem/core/Exceptions.php2
-rwxr-xr-xsystem/core/Hooks.php2
-rwxr-xr-xsystem/core/Input.php130
-rwxr-xr-xsystem/core/Lang.php2
-rw-r--r--system/core/Loader.php15
-rwxr-xr-xsystem/core/Model.php2
-rwxr-xr-xsystem/core/Output.php2
-rwxr-xr-xsystem/core/Router.php2
-rwxr-xr-xsystem/core/Security.php55
-rwxr-xr-xsystem/core/URI.php24
-rw-r--r--system/core/Utf8.php2
-rwxr-xr-xsystem/database/DB.php25
-rw-r--r--system/database/DB_active_rec.php94
-rw-r--r--system/database/DB_cache.php4
-rw-r--r--system/database/DB_driver.php485
-rw-r--r--system/database/DB_forge.php6
-rw-r--r--system/database/DB_result.php10
-rw-r--r--system/database/DB_utility.php6
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php289
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php65
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php40
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php26
-rw-r--r--system/database/drivers/interbase/index.html10
-rw-r--r--system/database/drivers/interbase/interbase_driver.php548
-rw-r--r--system/database/drivers/interbase/interbase_forge.php243
-rw-r--r--system/database/drivers/interbase/interbase_result.php277
-rw-r--r--system/database/drivers/interbase/interbase_utility.php115
-rw-r--r--system/database/drivers/mssql/mssql_driver.php237
-rw-r--r--system/database/drivers/mssql/mssql_forge.php60
-rw-r--r--system/database/drivers/mssql/mssql_result.php40
-rw-r--r--system/database/drivers/mssql/mssql_utility.php28
-rw-r--r--system/database/drivers/mysql/mysql_driver.php98
-rw-r--r--system/database/drivers/mysql/mysql_forge.php18
-rw-r--r--system/database/drivers/mysql/mysql_result.php22
-rw-r--r--system/database/drivers/mysql/mysql_utility.php21
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php389
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php148
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php64
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php34
-rw-r--r--system/database/drivers/oci8/oci8_driver.php354
-rw-r--r--system/database/drivers/oci8/oci8_forge.php99
-rw-r--r--system/database/drivers/oci8/oci8_result.php53
-rw-r--r--system/database/drivers/oci8/oci8_utility.php27
-rw-r--r--system/database/drivers/odbc/odbc_driver.php215
-rw-r--r--system/database/drivers/odbc/odbc_forge.php52
-rw-r--r--system/database/drivers/odbc/odbc_result.php182
-rw-r--r--system/database/drivers/odbc/odbc_utility.php26
-rw-r--r--system/database/drivers/pdo/pdo_driver.php523
-rw-r--r--system/database/drivers/pdo/pdo_forge.php59
-rw-r--r--system/database/drivers/pdo/pdo_result.php160
-rw-r--r--system/database/drivers/pdo/pdo_utility.php26
-rw-r--r--system/database/drivers/postgre/postgre_driver.php308
-rw-r--r--system/database/drivers/postgre/postgre_forge.php60
-rw-r--r--system/database/drivers/postgre/postgre_result.php42
-rw-r--r--system/database/drivers/postgre/postgre_utility.php37
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php202
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php55
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php42
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php41
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php341
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php57
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php58
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php32
-rw-r--r--system/helpers/array_helper.php49
-rw-r--r--system/helpers/captcha_helper.php15
-rw-r--r--system/helpers/cookie_helper.php34
-rw-r--r--system/helpers/date_helper.php49
-rw-r--r--system/helpers/directory_helper.php20
-rw-r--r--system/helpers/download_helper.php89
-rw-r--r--system/helpers/email_helper.php2
-rw-r--r--system/helpers/file_helper.php2
-rw-r--r--system/helpers/form_helper.php29
-rw-r--r--system/helpers/html_helper.php2
-rw-r--r--system/helpers/inflector_helper.php153
-rw-r--r--system/helpers/language_helper.php2
-rw-r--r--system/helpers/number_helper.php2
-rw-r--r--system/helpers/path_helper.php20
-rw-r--r--system/helpers/security_helper.php18
-rw-r--r--system/helpers/smiley_helper.php2
-rw-r--r--system/helpers/string_helper.php2
-rw-r--r--system/helpers/text_helper.php24
-rw-r--r--system/helpers/typography_helper.php2
-rw-r--r--system/helpers/url_helper.php36
-rw-r--r--system/helpers/xml_helper.php2
-rw-r--r--system/language/english/calendar_lang.php2
-rw-r--r--system/language/english/date_lang.php2
-rw-r--r--system/language/english/db_lang.php2
-rw-r--r--system/language/english/email_lang.php2
-rw-r--r--system/language/english/form_validation_lang.php52
-rw-r--r--system/language/english/ftp_lang.php2
-rw-r--r--system/language/english/imglib_lang.php2
-rw-r--r--system/language/english/migration_lang.php2
-rw-r--r--system/language/english/number_lang.php2
-rw-r--r--system/language/english/profiler_lang.php2
-rw-r--r--system/language/english/unit_test_lang.php2
-rw-r--r--system/language/english/upload_lang.php4
-rw-r--r--system/libraries/Cache/Cache.php23
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php4
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php165
-rw-r--r--system/libraries/Calendar.php2
-rw-r--r--system/libraries/Cart.php9
-rw-r--r--system/libraries/Driver.php2
-rw-r--r--system/libraries/Email.php353
-rw-r--r--system/libraries/Encrypt.php2
-rw-r--r--system/libraries/Form_validation.php183
-rw-r--r--system/libraries/Ftp.php2
-rw-r--r--system/libraries/Image_lib.php437
-rw-r--r--system/libraries/Javascript.php2
-rw-r--r--system/libraries/Log.php2
-rw-r--r--system/libraries/Migration.php2
-rw-r--r--system/libraries/Pagination.php2
-rw-r--r--system/libraries/Parser.php2
-rw-r--r--system/libraries/Profiler.php14
-rw-r--r--system/libraries/Session.php174
-rw-r--r--system/libraries/Table.php24
-rw-r--r--system/libraries/Trackback.php4
-rw-r--r--system/libraries/Typography.php2
-rw-r--r--system/libraries/Unit_test.php2
-rw-r--r--system/libraries/Upload.php123
-rw-r--r--system/libraries/User_agent.php2
-rw-r--r--system/libraries/Xmlrpc.php2
-rw-r--r--system/libraries/Xmlrpcs.php2
-rw-r--r--system/libraries/Zip.php2
-rw-r--r--system/libraries/javascript/Jquery.php2
-rw-r--r--tests/Bootstrap.php21
-rw-r--r--tests/README.md164
-rw-r--r--tests/codeigniter/Setup_test.php13
-rw-r--r--tests/codeigniter/core/Common_test.php16
-rw-r--r--tests/codeigniter/core/Config_test.php93
-rw-r--r--tests/codeigniter/core/Lang_test.php31
-rw-r--r--tests/codeigniter/core/Loader_test.php271
-rw-r--r--tests/codeigniter/core/URI_test.php344
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php49
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php284
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php42
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php16
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php157
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php78
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php93
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php78
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php29
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php144
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php159
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php72
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php13
-rw-r--r--tests/codeigniter/libraries/Parser_test.php113
-rw-r--r--tests/codeigniter/libraries/Table_test.php344
-rw-r--r--tests/codeigniter/libraries/Typography_test.php191
-rw-r--r--tests/codeigniter/libraries/User_agent_test.php91
-rw-r--r--tests/lib/ci_testcase.php194
-rw-r--r--tests/lib/common.php132
-rw-r--r--tests/phpunit.xml38
-rw-r--r--user_guide_src/cilexer/cilexer/cilexer.py2
-rw-r--r--user_guide_src/source/_themes/eldocs/static/asset/css/common.css2
-rw-r--r--user_guide_src/source/changelog.rst107
-rw-r--r--user_guide_src/source/database/active_record.rst10
-rw-r--r--user_guide_src/source/database/configuration.rst4
-rw-r--r--user_guide_src/source/database/connecting.rst6
-rw-r--r--user_guide_src/source/database/helpers.rst6
-rw-r--r--user_guide_src/source/database/queries.rst17
-rw-r--r--user_guide_src/source/database/results.rst9
-rw-r--r--user_guide_src/source/database/utilities.rst6
-rw-r--r--user_guide_src/source/general/creating_libraries.rst16
-rw-r--r--user_guide_src/source/general/requirements.rst6
-rw-r--r--user_guide_src/source/helpers/date_helper.rst13
-rw-r--r--user_guide_src/source/helpers/form_helper.rst269
-rw-r--r--user_guide_src/source/helpers/path_helper.rst20
-rw-r--r--user_guide_src/source/helpers/security_helper.rst7
-rw-r--r--user_guide_src/source/helpers/string_helper.rst30
-rw-r--r--user_guide_src/source/installation/upgrade_200.rst2
-rw-r--r--user_guide_src/source/libraries/email.rst1
-rw-r--r--user_guide_src/source/libraries/form_validation.rst123
-rw-r--r--user_guide_src/source/libraries/input.rst16
-rw-r--r--user_guide_src/source/libraries/sessions.rst4
-rw-r--r--user_guide_src/source/libraries/table.rst2
-rw-r--r--user_guide_src/source/overview/at_a_glance.rst2
208 files changed, 8727 insertions, 4472 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..2584e8ac2
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: php
+
+php:
+ - 5.2
+ - 5.3
+ - 5.4
+
+before_script:
+ - pyrus channel-discover pear.php-tools.net
+ - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
+ - phpenv rehash
+
+script: phpunit --configuration tests/phpunit.xml
+
+branches:
+ only:
+ - develop
+ - master \ No newline at end of file
diff --git a/application/config/autoload.php b/application/config/autoload.php
index db49ca109..e8c999334 100644
--- a/application/config/autoload.php
+++ b/application/config/autoload.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/config.php b/application/config/config.php
index 17b854b29..2ffbb6693 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -297,12 +297,14 @@ $config['sess_time_to_update'] = 300;
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookies will only be set if a secure HTTPS connection exists.
+| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
*/
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
+$config['cookie_httponly'] = FALSE;
/*
|--------------------------------------------------------------------------
diff --git a/application/config/constants.php b/application/config/constants.php
index c7203e47d..fce101320 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/database.php b/application/config/database.php
index 7eac59b23..154638d1f 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -37,6 +37,7 @@
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
+| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
@@ -74,6 +75,7 @@
$active_group = 'default';
$active_record = TRUE;
+$db['default']['dsn'] = '';
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
diff --git a/application/config/doctypes.php b/application/config/doctypes.php
index 9cf4808a5..4598dc04d 100644
--- a/application/config/doctypes.php
+++ b/application/config/doctypes.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index 1ae0cef5f..d3713fe98 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/hooks.php b/application/config/hooks.php
index 80269df59..1b10fc27d 100644
--- a/application/config/hooks.php
+++ b/application/config/hooks.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/memcached.php b/application/config/memcached.php
index 2b1a77266..7166b70ba 100644
--- a/application/config/memcached.php
+++ b/application/config/memcached.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/migration.php b/application/config/migration.php
index 668c35740..e1ce1ae6f 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/mimes.php b/application/config/mimes.php
index 8c34fd298..7ec782b60 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -120,9 +120,9 @@ $mimes = array('hqx' => array('application/mac-binhex40', 'application/mac-binhe
'mov' => 'video/quicktime',
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
'movie' => 'video/x-sgi-movie',
- 'doc' => 'application/msword',
- 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ 'doc' => array('application/msword', 'application/vnd.ms-office'),
+ 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
+ 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
diff --git a/application/config/profiler.php b/application/config/profiler.php
index f95614241..53391892d 100644
--- a/application/config/profiler.php
+++ b/application/config/profiler.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/routes.php b/application/config/routes.php
index 53fc7e799..686573deb 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/smileys.php b/application/config/smileys.php
index 4132aed2f..8e3844a89 100644
--- a/application/config/smileys.php
+++ b/application/config/smileys.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/config/user_agents.php b/application/config/user_agents.php
index e7a689402..0baa25220 100644
--- a/application/config/user_agents.php
+++ b/application/config/user_agents.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php
index 5eb0e9625..2451d9776 100644
--- a/application/controllers/welcome.php
+++ b/application/controllers/welcome.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/errors/error_404.php b/application/errors/error_404.php
index 4dd8fc407..9af9e39de 100644
--- a/application/errors/error_404.php
+++ b/application/errors/error_404.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/errors/error_db.php b/application/errors/error_db.php
index 130ffc11d..81ff02adb 100644
--- a/application/errors/error_db.php
+++ b/application/errors/error_db.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/errors/error_general.php b/application/errors/error_general.php
index 2a844a8e2..8efcfd991 100644
--- a/application/errors/error_general.php
+++ b/application/errors/error_general.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index 8e293cd5e..42e5f5a28 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php
index acc36b6d4..0dd892441 100644
--- a/application/views/welcome_message.php
+++ b/application/views/welcome_message.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/index.php b/index.php
index 1712a7d66..5a1190112 100644
--- a/index.php
+++ b/index.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -218,6 +218,7 @@ if (defined('ENVIRONMENT'))
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
@@ -233,6 +234,7 @@ if (defined('ENVIRONMENT'))
{
if ( ! is_dir(APPPATH.'views/'))
{
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
diff --git a/license.rst b/license.rst
deleted file mode 100644
index 17179a95c..000000000
--- a/license.rst
+++ /dev/null
@@ -1,245 +0,0 @@
-###################################
-Open Software License ("OSL") v 3.0
-###################################
-
-This Open Software License (the "License") applies to any original work of
-authorship (the "Original Work") whose owner (the "Licensor") has placed the
-following licensing notice adjacent to the copyright notice for the Original
-Work:
-
-*Licensed under the Open Software License version 3.0*
-
-
-*****************************
-1) Grant of Copyright License
-*****************************
-
-Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable
-license, for the duration of the copyright, to do the following:
-
- *a)* to reproduce the Original Work in copies, either alone or as part of
- a collective work;
-
- *b)* to translate, adapt, alter, transform, modify, or arrange the
- Original Work, thereby creating derivative works ("Derivative Works")
- based upon the Original Work;
-
- *c)* to distribute or communicate copies of the Original Work and
- Derivative Works to the public, *with the proviso that copies of Original
- Work or Derivative Works that You distribute or communicate shall be
- licensed under this Open Software License*;
-
- *d)* to perform the Original Work publicly; and
-
- *e)* to display the Original Work publicly.
-
-
-**************************
-2) Grant of Patent License
-**************************
-
-Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable
-license, under patent claims owned or controlled by the Licensor that are
-embodied in the Original Work as furnished by the Licensor, for the duration
-of the patents, to make, use, sell, offer for sale, have made, and import the
-Original Work and Derivative Works.
-
-
-*******************************
-3) Grant of Source Code License
-*******************************
-
-The term "Source Code" means the preferred form of the Original Work for
-making modifications to it and all available documentation describing how to
-modify the Original Work. Licensor agrees to provide a machine-readable copy
-of the Source Code of the Original Work along with each copy of the Original
-Work that Licensor distributes. Licensor reserves the right to satisfy this
-obligation by placing a machine-readable copy of the Source Code in an
-information repository reasonably calculated to permit inexpensive and
-convenient access by You for as long as Licensor continues to distribute the
-Original Work.
-
-
-********************************
-4) Exclusions From License Grant
-********************************
-
-Neither the names of Licensor, nor the names of any contributors to the
-Original Work, nor any of their trademarks or service marks, may be used to
-endorse or promote products derived from this Original Work without express
-prior permission of the Licensor. Except as expressly stated herein, nothing
-in this License grants any license to Licensor's trademarks, copyrights,
-patents, trade secrets or any other intellectual property. No patent license
-is granted to make, use, sell, offer for sale, have made, or import
-embodiments of any patent claims other than the licensed claims defined in
-Section 2) No license is granted to the trademarks of Licensor even if such
-marks are included in the Original Work. Nothing in this License shall be
-interpreted to prohibit Licensor from licensing under terms different from
-this License any Original Work that Licensor otherwise would have a right to
-license.
-
-
-**********************
-5) External Deployment
-**********************
-
-The term "External Deployment" means the use, distribution, or communication
-of the Original Work or Derivative Works in any way such that the Original
-Work or Derivative Works may be used by anyone other than You, whether those
-works are distributed or communicated to those persons or made available as an
-application intended for use over a network. As an express condition for the
-grants of license hereunder, You must treat any External Deployment by You of
-the Original Work or a Derivative Work as a distribution under section 1(c).
-
-
-*********************
-6) Attribution Rights
-*********************
-
-You must retain, in the Source Code of any Derivative Works that You create,
-all copyright, patent, or trademark notices from the Source Code of the
-Original Work, as well as any notices of licensing and any descriptive text
-identified therein as an "Attribution Notice." You must cause the Source Code
-for any Derivative Works that You create to carry a prominent Attribution
-Notice reasonably calculated to inform recipients that You have modified the
-Original Work.
-
-
-****************************************************
-7) Warranty of Provenance and Disclaimer of Warranty
-****************************************************
-
-Licensor warrants that the copyright in and to the Original Work and the
-patent rights granted herein by Licensor are owned by the Licensor or are
-sublicensed to You under the terms of this License with the permission of the
-contributor(s) of those copyrights and patent rights. Except as expressly
-stated in the immediately preceding sentence, the Original Work is provided
-under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or
-implied, including, without limitation, the warranties of non-infringement,
-merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE
-QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY
-constitutes an essential part of this License. No license to the Original Work
-is granted by this License except under this disclaimer.
-
-
-**************************
-8) Limitation of Liability
-**************************
-
-Under no circumstances and under no legal theory, whether in tort (including
-negligence), contract, or otherwise, shall the Licensor be liable to anyone
-for any indirect, special, incidental, or consequential damages of any
-character arising as a result of this License or the use of the Original Work
-including, without limitation, damages for loss of goodwill, work stoppage,
-computer failure or malfunction, or any and all other commercial damages or
-losses. This limitation of liability shall not apply to the extent applicable
-law prohibits such limitation.
-
-
-*****************************
-9) Acceptance and Termination
-*****************************
-
-If, at any time, You expressly assented to this License, that assent indicates
-your clear and irrevocable acceptance of this License and all of its terms and
-conditions. If You distribute or communicate copies of the Original Work or a
-Derivative Work, You must make a reasonable effort under the circumstances to
-obtain the express assent of recipients to the terms of this License. This
-License conditions your rights to undertake the activities listed in Section
-1, including your right to create Derivative Works based upon the Original
-Work, and doing so without honoring these terms and conditions is prohibited
-by copyright law and international treaty. Nothing in this License is intended
-to affect copyright exceptions and limitations (including "fair use" or "fair
-dealing"). This License shall terminate immediately and You may no longer
-exercise any of the rights granted to You by this License upon your failure to
-honor the conditions in Section 1(c).
-
-
-*********************************
-10) Termination for Patent Action
-*********************************
-
-This License shall terminate automatically and You may no longer exercise any
-of the rights granted to You by this License as of the date You commence an
-action, including a cross-claim or counterclaim, against Licensor or any
-licensee alleging that the Original Work infringes a patent. This termination
-provision shall not apply for an action alleging patent infringement by
-combinations of the Original Work with other software or hardware.
-
-
-*****************************************
-11) Jurisdiction, Venue and Governing Law
-*****************************************
-
-Any action or suit relating to this License may be brought only in the courts
-of a jurisdiction wherein the Licensor resides or in which Licensor conducts
-its primary business, and under the laws of that jurisdiction excluding its
-conflict-of-law provisions. The application of the United Nations Convention
-on Contracts for the International Sale of Goods is expressly excluded. Any
-use of the Original Work outside the scope of this License or after its
-termination shall be subject to the requirements and penalties of copyright or
-patent law in the appropriate jurisdiction. This section shall survive the
-termination of this License.
-
-
-*******************
-12) Attorneys' Fees
-*******************
-
-In any action to enforce the terms of this License or seeking damages relating
-thereto, the prevailing party shall be entitled to recover its costs and
-expenses, including, without limitation, reasonable attorneys' fees and costs
-incurred in connection with such action, including any appeal of such action.
-This section shall survive the termination of this License.
-
-
-*****************
-13) Miscellaneous
-*****************
-
-If any provision of this License is held to be unenforceable, such provision
-shall be reformed only to the extent necessary to make it enforceable.
-
-
-***************************************
-14) Definition of "You" in This License
-***************************************
-
-"You" throughout this License, whether in upper or lower case, means an
-individual or a legal entity exercising rights under, and complying with all
-of the terms of, this License. For legal entities, "You" includes any entity
-that controls, is controlled by, or is under common control with you. For
-purposes of this definition, "control" means (i) the power, direct or
-indirect, to cause the direction or management of such entity, whether by
-contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
-outstanding shares, or (iii) beneficial ownership of such entity.
-
-
-****************
-15) Right to Use
-****************
-
-You may use the Original Work in all ways not otherwise restricted or
-conditioned by this License or by law, and Licensor promises not to interfere
-with or be responsible for such uses by You.
-
-
-********************************
-16) Modification of This License
-********************************
-
-This License is Copyright © 2005 Lawrence Rosen. Permission is granted to
-copy, distribute, or communicate this License without modification. Nothing in
-this License permits You to modify this License as applied to the Original
-Work or to Derivative Works. However, You may modify the text of this License
-and copy, distribute or communicate your modified version (the "Modified
-License") and apply it to other original works of authorship subject to the
-following conditions: (i) You may not indicate in any way that your Modified
-License is the "Open Software License" or "OSL" and you may not use those
-names in the name of your Modified License; (ii) You must replace the notice
-specified in the first paragraph above with the notice "Licensed under <insert
-your license name here>" or with a notice of your own that is not confusingly
-similar to the notice in this License; and (iii) You may not claim that your
-original works are open source software unless your Modified License has been
-approved by Open Source Initiative (OSI) and You comply with its license
-review and certification process. \ No newline at end of file
diff --git a/readme.rst b/readme.rst
index 26e04ceac..4707847c7 100644
--- a/readme.rst
+++ b/readme.rst
@@ -23,13 +23,13 @@ Changelog and New Features
**************************
You can find a list of all changes for each release in the `user
-guide change log <https://github.com/EllisLab/CodeIgniter/blob/develop/user_guide/changelog.html>`_.
+guide change log <https://github.com/EllisLab/CodeIgniter/blob/develop/user_guide_src/source/changelog.rst>`_.
*******************
Server Requirements
*******************
-- PHP version 5.1.6 or newer.
+- PHP version 5.2.4 or newer.
************
Installation
@@ -90,9 +90,9 @@ must also be updated for every change. Also PHPDoc blocks must be maintained.
Compatibility
=============
-CodeIgniter is compatible with PHP 5.1.6 so all code supplied must stick to
-this requirement. If PHP 5.2 or 5.3 functions or features are used then there
-must be a fallback for PHP 5.1.6.
+CodeIgniter is compatible with PHP 5.2.4 so all code supplied must stick to
+this requirement. If PHP 5.3 or 5.4 functions or features are used then there
+must be a fallback for PHP 5.2.4.
Branching
=========
@@ -193,4 +193,4 @@ Acknowledgement
***************
The EllisLab team and The Reactor Engineers would like to thank all the
-contributors to the CodeIgniter project and you, the CodeIgniter user. \ No newline at end of file
+contributors to the CodeIgniter project and you, the CodeIgniter user.
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index f4dfd3dab..f6b634deb 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 7af3c485d..a79a69590 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Common.php b/system/core/Common.php
index 2f9c4ff43..f20acafd4 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -56,7 +56,7 @@ if ( ! function_exists('is_php'))
function is_php($version = '5.0.0')
{
static $_is_php;
- $version = (string)$version;
+ $version = (string) $version;
if ( ! isset($_is_php[$version]))
{
@@ -84,7 +84,7 @@ if ( ! function_exists('is_really_writable'))
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
- if (DIRECTORY_SEPARATOR === '/' AND @ini_get('safe_mode') == FALSE)
+ if (DIRECTORY_SEPARATOR === '/' && (bool) @ini_get('safe_mode') === FALSE)
{
return is_writable($file);
}
@@ -120,7 +120,7 @@ if ( ! function_exists('is_really_writable'))
/**
* Class registry
*
-* This function acts as a singleton. If the requested class does not
+* This function acts as a singleton. If the requested class does not
* exist it is instantiated and set to a static variable. If it has
* previously been instantiated the variable is returned.
*
@@ -177,6 +177,7 @@ if ( ! function_exists('load_class'))
{
// Note: We use exit() rather then show_error() in order to avoid a
// self-referencing loop with the Excptions class
+ set_status_header(503);
exit('Unable to locate the specified class: '.$class.'.php');
}
@@ -191,7 +192,7 @@ if ( ! function_exists('load_class'))
// --------------------------------------------------------------------
/**
-* Keeps track of which libraries have been loaded. This function is
+* Keeps track of which libraries have been loaded. This function is
* called by the load_class() function above
*
* @access public
@@ -243,6 +244,7 @@ if ( ! function_exists('get_config'))
// Fetch the config file
if ( ! file_exists($file_path))
{
+ set_status_header(503);
exit('The configuration file does not exist.');
}
@@ -251,6 +253,7 @@ if ( ! function_exists('get_config'))
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
+ set_status_header(503);
exit('Your config file does not appear to be formatted correctly.');
}
@@ -434,7 +437,7 @@ if ( ! function_exists('set_status_header'))
show_error('Status codes must be numeric', 500);
}
- if (isset($stati[$code]) AND $text == '')
+ if (isset($stati[$code]) && $text == '')
{
$text = $stati[$code];
}
@@ -444,19 +447,19 @@ if ( ! function_exists('set_status_header'))
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
- $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
+ $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
if (strpos(php_sapi_name(), 'cgi') === 0)
{
- header("Status: {$code} {$text}", TRUE);
+ header('Status: '.$code.' '.$text, TRUE);
}
- elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')
+ elseif ($server_protocol === 'HTTP/1.0')
{
- header($server_protocol." {$code} {$text}", TRUE, $code);
+ header('HTTP/1.0 '.$code.' '.$text, TRUE, $code);
}
else
{
- header("HTTP/1.1 {$code} {$text}", TRUE, $code);
+ header('HTTP/1.1 '.$code.' '.$text, TRUE, $code);
}
}
}
@@ -561,14 +564,9 @@ if ( ! function_exists('html_escape'))
{
function html_escape($var)
{
- if (is_array($var))
- {
- return array_map('html_escape', $var);
- }
- else
- {
- return htmlspecialchars($var, ENT_QUOTES, config_item('charset'));
- }
+ return is_array($var)
+ ? array_map('html_escape', $var)
+ : htmlspecialchars($var, ENT_QUOTES, config_item('charset'));
}
}
diff --git a/system/core/Config.php b/system/core/Config.php
index 66369115a..91826bd41 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -76,11 +76,11 @@ class CI_Config {
log_message('debug', 'Config Class Initialized');
// Set the base_url automatically if none was provided
- if ($this->config['base_url'] == '')
+ if (empty($this->config['base_url']))
{
if (isset($_SERVER['HTTP_HOST']))
{
- $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
+ $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']);
}
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 0dc131701..05e1bf5bf 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index bf9901252..d7282b1f3 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index e1ac58e6e..493822f36 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Input.php b/system/core/Input.php
index 7a16e51ab..6e6885992 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Input Class
*
@@ -152,7 +150,7 @@ class CI_Input {
public function get($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
- if ($index === NULL AND ! empty($_GET))
+ if ($index === NULL && ! empty($_GET))
{
$get = array();
@@ -179,7 +177,7 @@ class CI_Input {
public function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
- if ($index === NULL AND ! empty($_POST))
+ if ($index === NULL && ! empty($_POST))
{
$post = array();
@@ -206,9 +204,9 @@ class CI_Input {
*/
public function get_post($index = '', $xss_clean = FALSE)
{
- return ( ! isset($_POST[$index]))
- ? $this->get($index, $xss_clean)
- : $this->post($index, $xss_clean);
+ return isset($_POST[$index])
+ ? $this->post($index, $xss_clean)
+ : $this->get($index, $xss_clean);
}
// --------------------------------------------------------------------
@@ -230,7 +228,7 @@ class CI_Input {
/**
* Set cookie
*
- * Accepts six parameter, or you can submit an associative
+ * Accepts seven parameters, or you can submit an associative
* array in the first parameter containing all the values.
*
* @param mixed
@@ -240,14 +238,15 @@ class CI_Input {
* @param string the cookie path
* @param string the cookie prefix
* @param bool true makes the cookie secure
+ * @param bool true makes the cookie accessible via http(s) only (no javascript)
* @return void
*/
- public function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
+ public function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
{
if (is_array($name))
{
// always leave 'name' in last place, as the loop will break otherwise, due to $$item
- foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item)
+ foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item)
{
if (isset($name[$item]))
{
@@ -256,22 +255,26 @@ class CI_Input {
}
}
- if ($prefix == '' AND config_item('cookie_prefix') != '')
+ if ($prefix == '' && config_item('cookie_prefix') != '')
{
$prefix = config_item('cookie_prefix');
}
- if ($domain == '' AND config_item('cookie_domain') != '')
+ if ($domain == '' && config_item('cookie_domain') != '')
{
$domain = config_item('cookie_domain');
}
- if ($path == '/' AND config_item('cookie_path') != '/')
+ if ($path == '/' && config_item('cookie_path') !== '/')
{
$path = config_item('cookie_path');
}
- if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+ if ($secure == FALSE && config_item('cookie_secure') != FALSE)
{
$secure = config_item('cookie_secure');
}
+ if ($httponly == FALSE && config_item('cookie_httponly') != FALSE)
+ {
+ $httponly = config_item('cookie_httponly');
+ }
if ( ! is_numeric($expire))
{
@@ -282,7 +285,7 @@ class CI_Input {
$expire = ($expire > 0) ? time() + $expire : 0;
}
- setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
+ setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly);
}
// --------------------------------------------------------------------
@@ -320,11 +323,11 @@ class CI_Input {
$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
}
- elseif ( ! $this->server('HTTP_CLIENT_IP') AND $this->server('REMOTE_ADDR'))
+ elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR'))
{
$this->ip_address = $_SERVER['REMOTE_ADDR'];
}
- elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
+ elseif ($this->server('REMOTE_ADDR') && $this->server('HTTP_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
@@ -368,36 +371,7 @@ class CI_Input {
*/
public function valid_ip($ip)
{
- // if php version >= 5.2, use filter_var to check validate ip.
- if (function_exists('filter_var'))
- {
- return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
- }
-
- $ip_segments = explode('.', $ip);
-
- // Always 4 segments needed
- if (count($ip_segments) !== 4)
- {
- return FALSE;
- }
- // IP can not start with 0
- if ($ip_segments[0][0] == '0')
- {
- return FALSE;
- }
- // Check each segment
- foreach ($ip_segments as $segment)
- {
- // IP segments must be digits and can not be
- // longer than 3 digits or greater then 255
- if ($segment == '' OR preg_match('/[^0-9]/', $segment) OR $segment > 255 OR strlen($segment) > 3)
- {
- return FALSE;
- }
- }
-
- return TRUE;
+ return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
// --------------------------------------------------------------------
@@ -414,7 +388,7 @@ class CI_Input {
return $this->user_agent;
}
- return $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
+ return $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : FALSE;
}
// --------------------------------------------------------------------
@@ -469,19 +443,16 @@ class CI_Input {
{
$_GET = array();
}
- else
+ elseif (is_array($_GET) && count($_GET) > 0)
{
- if (is_array($_GET) AND count($_GET) > 0)
+ foreach ($_GET as $key => $val)
{
- foreach ($_GET as $key => $val)
- {
- $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
- }
+ $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
}
// Clean $_POST Data
- if (is_array($_POST) AND count($_POST) > 0)
+ if (is_array($_POST) && count($_POST) > 0)
{
foreach ($_POST as $key => $val)
{
@@ -490,7 +461,7 @@ class CI_Input {
}
// Clean $_COOKIE Data
- if (is_array($_COOKIE) AND count($_COOKIE) > 0)
+ if (is_array($_COOKIE) && count($_COOKIE) > 0)
{
// Also get rid of specially treated cookies that might be set by a server
// or silly application, that are of no use to a CI application anyway
@@ -568,7 +539,7 @@ class CI_Input {
}
// Standardize newlines if needed
- if ($this->_standardize_newlines == TRUE AND strpos($str, "\r") !== FALSE)
+ if ($this->_standardize_newlines == TRUE && strpos($str, "\r") !== FALSE)
{
return str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
}
@@ -592,6 +563,7 @@ class CI_Input {
{
if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
{
+ set_status_header(503);
exit('Disallowed Key Characters.');
}
@@ -624,7 +596,7 @@ class CI_Input {
}
else
{
- $headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
+ $headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
foreach ($_SERVER as $key => $val)
{
@@ -654,9 +626,9 @@ class CI_Input {
*
* Returns the value of a single member of the headers class member
*
- * @param string array key for $this->headers
- * @param boolean XSS Clean or not
- * @return mixed FALSE on failure, string on success
+ * @param string array key for $this->headers
+ * @param bool XSS Clean or not
+ * @return mixed FALSE on failure, string on success
*/
public function get_request_header($index, $xss_clean = FALSE)
{
@@ -670,12 +642,9 @@ class CI_Input {
return FALSE;
}
- if ($xss_clean === TRUE)
- {
- return $this->security->xss_clean($this->headers[$index]);
- }
-
- return $this->headers[$index];
+ return ($xss_clean === TRUE)
+ ? $this->security->xss_clean($this->headers[$index])
+ : $this->headers[$index];
}
// --------------------------------------------------------------------
@@ -685,11 +654,11 @@ class CI_Input {
*
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header
*
- * @return boolean
+ * @return bool
*/
public function is_ajax_request()
{
- return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
+ return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}
// --------------------------------------------------------------------
@@ -699,11 +668,28 @@ class CI_Input {
*
* Test to see if a request was made from the command line
*
- * @return boolean
+ * @return bool
*/
public function is_cli_request()
{
- return (php_sapi_name() === 'cli') or defined('STDIN');
+ return (php_sapi_name() === 'cli' OR defined('STDIN'));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get Request Method
+ *
+ * Return the Request Method
+ *
+ * @param bool uppercase or lowercase
+ * @return bool
+ */
+ public function method($upper = FALSE)
+ {
+ return ($upper)
+ ? strtoupper($this->server('REQUEST_METHOD'))
+ : strtolower($this->server('REQUEST_METHOD'));
}
}
diff --git a/system/core/Lang.php b/system/core/Lang.php
index c40a6856e..9ef76f4d6 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 12daaa928..9b9cc2fef 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -615,13 +615,22 @@ class CI_Loader {
*
* Loads a driver library
*
- * @param string the name of the class
+ * @param mixed the name of the class or array of classes
* @param mixed the optional parameters
* @param string an optional object name
* @return void
*/
public function driver($library = '', $params = NULL, $object_name = NULL)
{
+ if (is_array($library))
+ {
+ foreach ($library as $driver)
+ {
+ $this->driver($driver);
+ }
+ return FALSE;
+ }
+
if ( ! class_exists('CI_Driver_Library'))
{
// we aren't instantiating an object here, that'll be done by the Library itself
@@ -833,7 +842,7 @@ class CI_Loader {
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
- if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
+ if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE && config_item('rewrite_short_tags') == TRUE)
{
echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
}
diff --git a/system/core/Model.php b/system/core/Model.php
index a595a6ae2..49b8d34e4 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Output.php b/system/core/Output.php
index abd8a0ea9..faebbbe72 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Router.php b/system/core/Router.php
index d21319565..b251abb4b 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/core/Security.php b/system/core/Security.php
index 1007f61f4..ac39ce97b 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Security Class
*
@@ -106,23 +104,27 @@ class CI_Security {
public function __construct()
{
- // CSRF config
- foreach(array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
+ // Is CSRF protection enabled?
+ if (config_item('csrf_protection') === TRUE)
{
- if (FALSE !== ($val = config_item($key)))
+ // CSRF config
+ foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
{
- $this->{'_'.$key} = $val;
+ if (FALSE !== ($val = config_item($key)))
+ {
+ $this->{'_'.$key} = $val;
+ }
}
- }
- // Append application specific cookie prefix
- if (config_item('cookie_prefix'))
- {
- $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
- }
+ // Append application specific cookie prefix
+ if (config_item('cookie_prefix'))
+ {
+ $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
+ }
- // Set the CSRF hash
- $this->_csrf_set_hash();
+ // Set the CSRF hash
+ $this->_csrf_set_hash();
+ }
log_message('debug', 'Security Class Initialized');
}
@@ -136,8 +138,8 @@ class CI_Security {
*/
public function csrf_verify()
{
- // If no POST data exists we will set the CSRF cookie
- if (count($_POST) === 0)
+ // If it's not a POST request we will set the CSRF cookie
+ if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST')
{
return $this->csrf_set_cookie();
}
@@ -189,12 +191,20 @@ class CI_Security {
$expire = time() + $this->_csrf_expire;
$secure_cookie = (bool) config_item('cookie_secure');
- if ($secure_cookie && ( ! isset($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] == 'off' OR ! $_SERVER['HTTPS']))
+ if ($secure_cookie && (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off'))
{
return FALSE;
}
- setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie);
+ setcookie(
+ $this->_csrf_cookie_name,
+ $this->_csrf_hash,
+ $expire,
+ config_item('cookie_path'),
+ config_item('cookie_domain'),
+ $secure_cookie,
+ config_item('cookie_httponly')
+ );
log_message('debug', 'CRSF cookie Set');
return $this;
@@ -358,7 +368,7 @@ class CI_Security {
foreach ($words as $word)
{
- $word = implode("\s*", str_split($word)) . "\s*";
+ $word = implode('\s*', str_split($word)).'\s*';
// We only want to do this when it is followed by a non-word character
// That way valid stuff like "dealer to" does not become "dealerto"
@@ -425,7 +435,6 @@ class CI_Security {
'\\1\\2&#40;\\3&#41;',
$str);
-
// Final clean up
// This adds a bit of extra precaution in case
// something got through the above filters
@@ -601,7 +610,7 @@ class CI_Security {
}
// find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes)
- preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is', $str, $matches, PREG_SET_ORDER);
+ preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
@@ -633,7 +642,7 @@ class CI_Security {
{
return '&lt;'.$matches[1].$matches[2].$matches[3] // encode opening brace
// encode captured opening or closing brace to prevent recursive vectors:
- . str_replace(array('>', '<'), array('&gt;', '&lt;'), $matches[4]);
+ .str_replace(array('>', '<'), array('&gt;', '&lt;'), $matches[4]);
}
// --------------------------------------------------------------------
diff --git a/system/core/URI.php b/system/core/URI.php
index b28ee198b..48bb7ae3c 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -22,7 +22,6 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
- * @filesource
*/
// ------------------------------------------------------------------------
@@ -93,7 +92,7 @@ class CI_URI {
if (strtoupper($this->config->item('uri_protocol')) === 'AUTO')
{
// Is the request coming from the command line?
- if (php_sapi_name() === 'cli' OR defined('STDIN'))
+ if ($this->_is_cli_request())
{
$this->_set_uri_string($this->_parse_cli_args());
return;
@@ -227,6 +226,21 @@ 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
+ */
+ protected function _is_cli_request()
+ {
+ return (php_sapi_name() == 'cli') OR defined('STDIN');
+ }
+
+
+ // --------------------------------------------------------------------
/**
* Parse cli arguments
@@ -444,9 +458,7 @@ class CI_URI {
return array();
}
- return function_exists('array_fill_keys')
- ? array_fill_keys($default, FALSE)
- : array_combine($default, array_fill(0, count($default), FALSE));
+ return array_fill_keys($default, FALSE);
}
$segments = array_slice($this->$segment_array(), ($n - 1));
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index 0e180d36f..ba3567453 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/database/DB.php b/system/database/DB.php
index ed6afd7ed..96e495515 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -37,11 +37,11 @@
function &DB($params = '', $active_record_override = NULL)
{
// Load the DB config file if a DSN string wasn't passed
- if (is_string($params) AND strpos($params, '://') === FALSE)
+ if (is_string($params) && strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
- AND ! file_exists($file_path = APPPATH.'config/database.php'))
+ && ! file_exists($file_path = APPPATH.'config/database.php'))
{
show_error('The configuration file database.php does not exist.');
}
@@ -74,23 +74,24 @@ function &DB($params = '', $active_record_override = NULL)
* parameter. DSNs must have this prototype:
* $dsn = 'driver://username:password@hostname/database';
*/
- if (($dns = @parse_url($params)) === FALSE)
+ if (($dsn = @parse_url($params)) === FALSE)
{
show_error('Invalid DB Connection String');
}
$params = array(
- 'dbdriver' => $dns['scheme'],
- 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
- 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
- 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
- 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
+ 'dbdriver' => $dsn['scheme'],
+ 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
+ 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
+ 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
+ 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
+ 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
);
// were additional config items set?
- if (isset($dns['query']))
+ if (isset($dsn['query']))
{
- parse_str($dns['query'], $extra);
+ parse_str($dsn['query'], $extra);
foreach ($extra as $key => $val)
{
// booleans please
@@ -157,4 +158,4 @@ function &DB($params = '', $active_record_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_active_rec.php b/system/database/DB_active_rec.php
index 424735157..fe591dda1 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -38,7 +38,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_active_record extends CI_DB_driver {
+abstract class CI_DB_active_record extends CI_DB_driver {
protected $return_delete_sql = FALSE;
protected $reset_delete_data = FALSE;
@@ -212,8 +212,9 @@ class CI_DB_active_record 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->protect_identifiers(trim($alias));
$this->ar_select[] = $sql;
+ $this->ar_no_escape[] = NULL;
if ($this->ar_caching === TRUE)
{
@@ -236,7 +237,8 @@ class CI_DB_active_record extends CI_DB_driver {
{
if (strpos($item, '.') !== FALSE)
{
- return end(explode('.', $item));
+ $item = explode('.', $item);
+ return end($item);
}
return $item;
@@ -278,7 +280,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
$v = trim($v);
$this->_track_aliases($v);
- $v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $v = $this->ar_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
@@ -294,7 +296,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Extract any aliases that might exist. We use this information
// in the _protect_identifiers to know whether to add a table prefix
$this->_track_aliases($val);
- $this->ar_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
@@ -340,13 +342,13 @@ class CI_DB_active_record extends CI_DB_driver {
$this->_track_aliases($table);
// Strip apart the condition and protect the identifiers
- if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
+ if (preg_match('/([\[\w\.]+)([\W\s]+)(.+)/', $cond, $match))
{
- $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
+ $cond = $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
}
// Assemble the JOIN statement
- $this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->ar_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
if ($this->ar_caching === TRUE)
{
@@ -432,7 +434,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($escape === TRUE)
{
- $k = $this->_protect_identifiers($k, FALSE, $escape);
+ $k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
@@ -443,7 +445,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $k = $this->_protect_identifiers($k, FALSE, $escape);
+ $k = $this->protect_identifiers($k, FALSE, $escape);
}
$this->ar_where[] = $prefix.$k.$v;
@@ -561,7 +563,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$prefix = (count($this->ar_where) === 0) ? '' : $type;
- $this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
+ $this->ar_where[] = $where_in = $prefix.$this->protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
if ($this->ar_caching === TRUE)
{
@@ -665,7 +667,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($field as $k => $v)
{
- $k = $this->_protect_identifiers($k);
+ $k = $this->protect_identifiers($k);
$prefix = (count($this->ar_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
@@ -826,7 +828,7 @@ class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_groupby[] = $val = $this->_protect_identifiers($val);
+ $this->ar_groupby[] = $val = $this->protect_identifiers($val);
if ($this->ar_caching === TRUE)
{
@@ -895,7 +897,7 @@ class CI_DB_active_record extends CI_DB_driver {
if ($escape === TRUE)
{
- $k = $this->_protect_identifiers($k);
+ $k = $this->protect_identifiers($k);
}
if ( ! $this->_has_operator($k))
@@ -950,7 +952,7 @@ class CI_DB_active_record extends CI_DB_driver {
$part = trim($part);
if ( ! in_array($part, $this->ar_aliased_tables))
{
- $part = $this->_protect_identifiers(trim($part));
+ $part = $this->protect_identifiers(trim($part));
}
$temp[] = $part;
@@ -962,7 +964,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($escape === TRUE)
{
- $orderby = $this->_protect_identifiers($orderby);
+ $orderby = $this->protect_identifiers($orderby);
}
}
@@ -1035,11 +1037,11 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($escape === FALSE)
{
- $this->ar_set[$this->_protect_identifiers($k)] = $v;
+ $this->ar_set[$this->protect_identifiers($k)] = $v;
}
else
{
- $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
+ $this->ar_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
}
}
@@ -1124,7 +1126,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->from($table);
}
- $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
+ $result = $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
$this->_reset_select();
if ($result->num_rows() === 0)
@@ -1210,7 +1212,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Batch this baby
for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
- $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
+ $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
}
$this->_reset_write();
@@ -1268,7 +1270,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($keys as $k)
{
- $this->ar_keys[] = $this->_protect_identifiers($k);
+ $this->ar_keys[] = $this->protect_identifiers($k);
}
return $this;
@@ -1294,9 +1296,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->_protect_identifiers(
- $this->ar_from[0], TRUE, NULL, FALSE
- ),
+ $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE),
array_keys($this->ar_set),
array_values($this->ar_set)
);
@@ -1334,9 +1334,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->_protect_identifiers(
- $this->ar_from[0], TRUE, NULL, FALSE
- ),
+ $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE),
array_keys($this->ar_set),
array_values($this->ar_set)
);
@@ -1413,7 +1411,7 @@ class CI_DB_active_record extends CI_DB_driver {
$table = $this->ar_from[0];
}
- $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
+ $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
$this->_reset_write();
return $this->query($sql);
}
@@ -1440,7 +1438,7 @@ class CI_DB_active_record extends CI_DB_driver {
return FALSE;
}
- $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
+ $sql = $this->_update($this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
if ($reset === TRUE)
{
@@ -1487,7 +1485,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit);
}
- $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
+ $sql = $this->_update($this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
$this->_reset_write();
return $this->query($sql);
}
@@ -1572,7 +1570,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Batch this baby
for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
- $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
+ $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->protect_identifiers($index), $this->ar_where));
}
$this->_reset_write();
@@ -1613,7 +1611,7 @@ class CI_DB_active_record extends CI_DB_driver {
$not[] = $k.'-'.$v;
}
- $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
+ $clean[$this->protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
if ($index_set == FALSE)
@@ -1650,7 +1648,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
}
$sql = $this->_delete($table);
@@ -1683,7 +1681,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
}
$sql = $this->_truncate($table);
@@ -1750,7 +1748,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
}
if ($where != '')
@@ -1893,7 +1891,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($this->ar_select as $key => $val)
{
$no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL;
- $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
+ $this->ar_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape);
}
$sql .= implode(', ', $this->ar_select);
@@ -2199,19 +2197,19 @@ class CI_DB_active_record extends CI_DB_driver {
protected function _reset_write()
{
$this->_reset_run(array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- )
- );
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
}
/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */
+/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 79651fcb0..58e6968c0 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -183,4 +183,4 @@ class CI_DB_Cache {
}
/* End of file DB_cache.php */
-/* Location: ./system/database/DB_cache.php */
+/* Location: ./system/database/DB_cache.php */ \ No newline at end of file
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 661b42ced..9f1a0b895 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Driver Class
*
@@ -40,57 +38,46 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_driver {
-
- var $username;
- var $password;
- var $hostname;
- var $database;
- var $dbdriver = 'mysql';
- var $dbprefix = '';
- var $char_set = 'utf8';
- var $dbcollat = 'utf8_general_ci';
- var $autoinit = TRUE; // Whether to automatically initialize the DB
- var $swap_pre = '';
- var $port = '';
- var $pconnect = FALSE;
- var $conn_id = FALSE;
- var $result_id = FALSE;
- var $db_debug = FALSE;
- var $benchmark = 0;
- var $query_count = 0;
- var $bind_marker = '?';
- var $save_queries = TRUE;
- var $queries = array();
- var $query_times = array();
- var $data_cache = array();
- var $trans_enabled = TRUE;
- var $trans_strict = TRUE;
- var $_trans_depth = 0;
- var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
- var $cache_on = FALSE;
- var $cachedir = '';
- var $cache_autodel = FALSE;
- var $CACHE; // The cache class object
-
- // Private variables
- var $_protect_identifiers = TRUE;
- var $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
-
- // These are use with Oracle
- var $stmt_id;
- var $curs_id;
- var $limit_used;
-
-
-
- /**
- * Constructor. Accepts one parameter containing the database
- * connection settings.
- *
- * @param array
- */
- function __construct($params)
+abstract class CI_DB_driver {
+
+ public $dsn;
+ public $username;
+ public $password;
+ public $hostname;
+ public $database;
+ public $dbdriver = 'mysql';
+ public $dbprefix = '';
+ public $char_set = 'utf8';
+ public $dbcollat = 'utf8_general_ci';
+ public $autoinit = TRUE; // Whether to automatically initialize the DB
+ public $swap_pre = '';
+ public $port = '';
+ public $pconnect = FALSE;
+ public $conn_id = FALSE;
+ public $result_id = FALSE;
+ public $db_debug = FALSE;
+ public $benchmark = 0;
+ public $query_count = 0;
+ public $bind_marker = '?';
+ public $save_queries = TRUE;
+ public $queries = array();
+ public $query_times = array();
+ public $data_cache = array();
+
+ public $trans_enabled = TRUE;
+ public $trans_strict = TRUE;
+ protected $_trans_depth = 0;
+ protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
+
+ public $cache_on = FALSE;
+ public $cachedir = '';
+ public $cache_autodel = FALSE;
+ public $CACHE; // The cache class object
+
+ protected $_protect_identifiers = TRUE;
+ protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
+
+ public function __construct($params)
{
if (is_array($params))
{
@@ -108,11 +95,9 @@ class CI_DB_driver {
/**
* Initialize Database Settings
*
- * @access private Called by the constructor
- * @param mixed
- * @return void
+ * @return bool
*/
- function initialize()
+ public function initialize()
{
// If an existing connection resource is available
// there is no need to connect and select the database
@@ -126,7 +111,7 @@ class CI_DB_driver {
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
- // No connection resource? Check if there is a failover else throw an error
+ // No connection resource? Check if there is a failover else throw an error
if ( ! $this->conn_id)
{
// Check if there is a failover set
@@ -168,31 +153,36 @@ class CI_DB_driver {
// ----------------------------------------------------------------
// Select the DB... assuming a database name is specified in the config file
- if ($this->database != '')
+ if ($this->database !== '' && ! $this->db_select())
{
- if ( ! $this->db_select())
- {
- log_message('error', 'Unable to select database: '.$this->database);
+ log_message('error', 'Unable to select database: '.$this->database);
- if ($this->db_debug)
- {
- $this->display_error('db_unable_to_select', $this->database);
- }
- return FALSE;
- }
- else
+ if ($this->db_debug)
{
- // We've selected the DB. Now we set the character set
- if ( ! $this->db_set_charset($this->char_set, $this->dbcollat))
- {
- return FALSE;
- }
-
- return TRUE;
+ $this->display_error('db_unable_to_select', $this->database);
}
+ return FALSE;
}
- return TRUE;
+ // Now we set the character set and that's all
+ return $this->db_set_charset($this->char_set);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Reconnect
+ *
+ * Keep / reestablish the db connection if no queries have been
+ * sent for a length of time exceeding the server's idle timeout.
+ *
+ * This is just a dummy method to allow drivers without such
+ * functionality to not declare it, while others will override it.
+ *
+ * @return void
+ */
+ public function reconnect()
+ {
}
// --------------------------------------------------------------------
@@ -200,20 +190,19 @@ class CI_DB_driver {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset)
{
- if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat))
+ if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset))
{
- log_message('error', 'Unable to set database connection charset: '.$this->char_set);
+ log_message('error', 'Unable to set database connection charset: '.$charset);
if ($this->db_debug)
{
- $this->display_error('db_unable_to_set_charset', $this->char_set);
+ $this->display_error('db_unable_to_set_charset', $charset);
}
return FALSE;
@@ -227,10 +216,9 @@ class CI_DB_driver {
/**
* The name of the platform in use (mysql, mssql, etc...)
*
- * @access public
* @return string
*/
- function platform()
+ public function platform()
{
return $this->dbdriver;
}
@@ -238,36 +226,40 @@ class CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Database Version Number. Returns a string containing the
- * version of the database being used
+ * Database version number
+ *
+ * Returns a string containing the version of the database being used.
+ * Most drivers will override this method.
*
- * @access public
* @return string
*/
- function version()
+ public function version()
{
- if (FALSE === ($sql = $this->_version()))
+ if (isset($this->data_cache['version']))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_unsupported_function');
- }
- return FALSE;
+ return $this->data_cache['version'];
}
- // Some DBs have functions that return the version, and don't run special
- // SQL queries per se. In these instances, just return the result.
- $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo');
-
- if (in_array($this->dbdriver, $driver_version_exceptions))
- {
- return $sql;
- }
- else
+ if (FALSE === ($sql = $this->_version()))
{
- $query = $this->query($sql);
- return $query->row('ver');
+ return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
}
+
+ $query = $this->query($sql);
+ $query = $query->row();
+ return $this->data_cache['version'] = $query->ver;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Version number query string
+ *
+ * @return string
+ */
+ protected function _version()
+ {
+ return 'SELECT VERSION() AS ver';
}
// --------------------------------------------------------------------
@@ -276,17 +268,16 @@ class CI_DB_driver {
* Execute the query
*
* Accepts an SQL string as input and returns a result object upon
- * successful execution of a "read" type query. Returns boolean TRUE
+ * successful execution of a "read" type query. Returns boolean TRUE
* upon successful execution of a "write" type query. Returns boolean
* FALSE upon failure, and if the $db_debug variable is set to TRUE
* will raise an error.
*
- * @access public
* @param string An SQL query string
* @param array An array of binding data
* @return mixed
*/
- function query($sql, $binds = FALSE, $return_object = TRUE)
+ public function query($sql, $binds = FALSE, $return_object = TRUE)
{
if ($sql == '')
{
@@ -305,7 +296,13 @@ class CI_DB_driver {
$sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql);
}
- // Is query caching enabled? If the query is a "read type"
+ // Compile binds if needed
+ if ($binds !== FALSE)
+ {
+ $sql = $this->compile_binds($sql, $binds);
+ }
+
+ // Is query caching enabled? If the query is a "read type"
// we will load the caching class and return the previously
// cached query if it exists
if ($this->cache_on == TRUE AND stristr($sql, 'SELECT'))
@@ -320,12 +317,6 @@ class CI_DB_driver {
}
}
- // Compile binds if needed
- if ($binds !== FALSE)
- {
- $sql = $this->compile_binds($sql, $binds);
- }
-
// Save the query for debugging
if ($this->save_queries == TRUE)
{
@@ -346,30 +337,28 @@ class CI_DB_driver {
// This will trigger a rollback if transactions are being used
$this->_trans_status = FALSE;
- // Grab the error number and message now, as we might run some
- // additional queries before displaying the error
- $error_no = $this->_error_number();
- $error_msg = $this->_error_message();
+ // Grab the error now, as we might run some additional queries before displaying the error
+ $error = $this->error();
// Log errors
- log_message('error', 'Query error: '.$error_msg);
+ log_message('error', 'Query error: '.$error['message']);
if ($this->db_debug)
{
// We call this function in order to roll-back queries
- // if transactions are enabled. If we don't call this here
+ // if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Display errors
return $this->display_error(
- array(
- 'Error Number: '.$error_no,
- $error_msg,
- $sql
- )
- );
+ array(
+ 'Error Number: '.$error['code'],
+ $error['message'],
+ $sql
+ )
+ );
}
return FALSE;
@@ -410,21 +399,9 @@ class CI_DB_driver {
}
// Load and instantiate the result driver
+ $driver = $this->load_rdriver();
+ $RES = new $driver($this);
- $driver = $this->load_rdriver();
- $RES = new $driver();
- $RES->conn_id = $this->conn_id;
- $RES->result_id = $this->result_id;
-
- if ($this->dbdriver == 'oci8')
- {
- $RES->stmt_id = $this->stmt_id;
- $RES->curs_id = NULL;
- $RES->limit_used = $this->limit_used;
- $this->stmt_id = FALSE;
- }
-
- // oci8 vars must be set before calling this
$RES->num_rows = $RES->num_rows();
// Is query caching enabled? If so, we'll serialize the
@@ -457,10 +434,9 @@ class CI_DB_driver {
/**
* Load the result drivers
*
- * @access public
* @return string the name of the result class
*/
- function load_rdriver()
+ public function load_rdriver()
{
$driver = 'CI_DB_'.$this->dbdriver.'_result';
@@ -477,15 +453,14 @@ class CI_DB_driver {
/**
* Simple Query
- * This is a simplified version of the query() function. Internally
+ * This is a simplified version of the query() function. Internally
* we only use it when running transaction commands since they do
* not require all the features of the main query() function.
*
- * @access public
* @param string the sql query
* @return mixed
*/
- function simple_query($sql)
+ public function simple_query($sql)
{
if ( ! $this->conn_id)
{
@@ -501,10 +476,9 @@ class CI_DB_driver {
* Disable Transactions
* This permits transactions to be disabled at run-time.
*
- * @access public
* @return void
*/
- function trans_off()
+ public function trans_off()
{
$this->trans_enabled = FALSE;
}
@@ -518,10 +492,9 @@ class CI_DB_driver {
* If strict mode is disabled, each group is treated autonomously, meaning
* a failure of one group will not affect any others
*
- * @access public
* @return void
*/
- function trans_strict($mode = TRUE)
+ public function trans_strict($mode = TRUE)
{
$this->trans_strict = is_bool($mode) ? $mode : TRUE;
}
@@ -531,10 +504,9 @@ class CI_DB_driver {
/**
* Start Transaction
*
- * @access public
* @return void
*/
- function trans_start($test_mode = FALSE)
+ public function trans_start($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -557,10 +529,9 @@ class CI_DB_driver {
/**
* Complete Transaction
*
- * @access public
* @return bool
*/
- function trans_complete()
+ public function trans_complete()
{
if ( ! $this->trans_enabled)
{
@@ -604,10 +575,9 @@ class CI_DB_driver {
/**
* Lets you retrieve the transaction flag to determine if it has failed
*
- * @access public
* @return bool
*/
- function trans_status()
+ public function trans_status()
{
return $this->_trans_status;
}
@@ -617,12 +587,11 @@ class CI_DB_driver {
/**
* Compile Bindings
*
- * @access public
* @param string the sql statement
* @param array an array of bind data
* @return string
*/
- function compile_binds($sql, $binds)
+ public function compile_binds($sql, $binds)
{
if (strpos($sql, $this->bind_marker) === FALSE)
{
@@ -660,17 +629,12 @@ class CI_DB_driver {
/**
* Determines if a query is a "write" type.
*
- * @access public
* @param string An SQL query string
- * @return boolean
+ * @return bool
*/
- function is_write_type($sql)
+ public function is_write_type($sql)
{
- if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
- {
- return FALSE;
- }
- return TRUE;
+ return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE|REINDEX)\s+/i', $sql);
}
// --------------------------------------------------------------------
@@ -678,11 +642,10 @@ class CI_DB_driver {
/**
* Calculate the aggregate query elapsed time
*
- * @access public
- * @param integer The number of decimal places
- * @return integer
+ * @param int The number of decimal places
+ * @return int
*/
- function elapsed_time($decimals = 6)
+ public function elapsed_time($decimals = 6)
{
return number_format($this->benchmark, $decimals);
}
@@ -692,10 +655,9 @@ class CI_DB_driver {
/**
* Returns the total number of queries
*
- * @access public
- * @return integer
+ * @return int
*/
- function total_queries()
+ public function total_queries()
{
return $this->query_count;
}
@@ -705,10 +667,9 @@ class CI_DB_driver {
/**
* Returns the last query that was executed
*
- * @access public
- * @return void
+ * @return string
*/
- function last_query()
+ public function last_query()
{
return end($this->queries);
}
@@ -721,13 +682,12 @@ class CI_DB_driver {
* Escapes data based on type
* Sets boolean and null types
*
- * @access public
* @param string
* @return mixed
*/
- function escape($str)
+ public function escape($str)
{
- if (is_string($str))
+ if (is_string($str) OR method_exists($str, '__toString'))
{
$str = "'".$this->escape_str($str)."'";
}
@@ -751,11 +711,10 @@ class CI_DB_driver {
* Calls the individual driver for platform
* specific escaping for LIKE conditions
*
- * @access public
* @param string
* @return mixed
*/
- function escape_like_str($str)
+ public function escape_like_str($str)
{
return $this->escape_str($str, TRUE);
}
@@ -765,14 +724,13 @@ class CI_DB_driver {
/**
* Primary
*
- * Retrieves the primary key. It assumes that the row in the first
+ * Retrieves the primary key. It assumes that the row in the first
* position is the primary key
*
- * @access public
* @param string the table name
* @return string
*/
- function primary($table = '')
+ public function primary($table = '')
{
$fields = $this->list_fields($table);
@@ -789,10 +747,9 @@ class CI_DB_driver {
/**
* Returns an array of table names
*
- * @access public
* @return array
*/
- function list_tables($constrain_by_prefix = FALSE)
+ public function list_tables($constrain_by_prefix = FALSE)
{
// Is there a cached result?
if (isset($this->data_cache['table_names']))
@@ -814,20 +771,23 @@ class CI_DB_driver {
if ($query->num_rows() > 0)
{
- foreach ($query->result_array() as $row)
+ $table = FALSE;
+ $rows = $query->result_array();
+ $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row))));
+
+ if ($key)
{
- if (isset($row['TABLE_NAME']))
- {
- $retval[] = $row['TABLE_NAME'];
- }
- else
- {
- $retval[] = array_shift($row);
- }
+ $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name';
+ }
+
+ foreach ($rows as $row)
+ {
+ $retval[] = ( ! $table) ? current($row) : $row[$table];
}
}
$this->data_cache['table_names'] = $retval;
+
return $this->data_cache['table_names'];
}
@@ -835,12 +795,12 @@ class CI_DB_driver {
/**
* Determine if a particular table exists
- * @access public
- * @return boolean
+ *
+ * @return bool
*/
- function table_exists($table_name)
+ public function table_exists($table_name)
{
- return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE;
+ return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
}
// --------------------------------------------------------------------
@@ -848,11 +808,10 @@ class CI_DB_driver {
/**
* Fetch MySQL Field Names
*
- * @access public
* @param string the table name
* @return array
*/
- function list_fields($table = '')
+ public function list_fields($table = '')
{
// Is there a cached result?
if (isset($this->data_cache['field_names'][$table]))
@@ -901,12 +860,12 @@ class CI_DB_driver {
/**
* Determine if a particular field exists
- * @access public
+ *
* @param string
* @param string
- * @return boolean
+ * @return bool
*/
- function field_exists($field_name, $table_name)
+ public function field_exists($field_name, $table_name)
{
return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE;
}
@@ -916,11 +875,10 @@ class CI_DB_driver {
/**
* Returns an object with field data
*
- * @access public
* @param string the table name
* @return object
*/
- function field_data($table = '')
+ public function field_data($table = '')
{
if ($table == '')
{
@@ -931,7 +889,7 @@ class CI_DB_driver {
return FALSE;
}
- $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
+ $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE)));
return $query->field_data();
}
@@ -941,12 +899,11 @@ class CI_DB_driver {
/**
* Generate an insert string
*
- * @access public
* @param string the table upon which the query will be performed
* @param array an associative array data of key/values
* @return string
*/
- function insert_string($table, $data)
+ public function insert_string($table, $data)
{
$fields = array();
$values = array();
@@ -957,7 +914,7 @@ class CI_DB_driver {
$values[] = $this->escape($val);
}
- return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
+ return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
}
// --------------------------------------------------------------------
@@ -965,23 +922,22 @@ class CI_DB_driver {
/**
* Generate an update string
*
- * @access public
* @param string the table upon which the query will be performed
* @param array an associative array data of key/values
* @param mixed the "where" statement
* @return string
*/
- function update_string($table, $data, $where)
+ public function update_string($table, $data, $where)
{
if ($where == '')
{
- return false;
+ return FALSE;
}
$fields = array();
foreach ($data as $key => $val)
{
- $fields[$this->_protect_identifiers($key)] = $this->escape($val);
+ $fields[$this->protect_identifiers($key)] = $this->escape($val);
}
if ( ! is_array($where))
@@ -994,7 +950,7 @@ class CI_DB_driver {
foreach ($where as $key => $val)
{
$prefix = (count($dest) == 0) ? '' : ' AND ';
- $key = $this->_protect_identifiers($key);
+ $key = $this->protect_identifiers($key);
if ($val !== '')
{
@@ -1010,7 +966,7 @@ class CI_DB_driver {
}
}
- return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
+ return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
}
// --------------------------------------------------------------------
@@ -1018,11 +974,10 @@ class CI_DB_driver {
/**
* Tests whether the string has an SQL operator
*
- * @access private
* @param string
* @return bool
*/
- function _has_operator($str)
+ protected function _has_operator($str)
{
$str = trim($str);
if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
@@ -1038,12 +993,11 @@ class CI_DB_driver {
/**
* Enables a native PHP function to be run, using a platform agnostic wrapper.
*
- * @access public
* @param string the function name
* @param mixed any parameters needed by the function
* @return mixed
*/
- function call_function($function)
+ public function call_function($function)
{
$driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
@@ -1080,11 +1034,10 @@ class CI_DB_driver {
/**
* Set Cache Directory Path
*
- * @access public
* @param string the path to the cache directory
* @return void
*/
- function cache_set_path($path = '')
+ public function cache_set_path($path = '')
{
$this->cachedir = $path;
}
@@ -1094,10 +1047,9 @@ class CI_DB_driver {
/**
* Enable Query Caching
*
- * @access public
- * @return void
+ * @return bool cache_on value
*/
- function cache_on()
+ public function cache_on()
{
$this->cache_on = TRUE;
return TRUE;
@@ -1108,10 +1060,9 @@ class CI_DB_driver {
/**
* Disable Query Caching
*
- * @access public
- * @return void
+ * @return bool cache_on value
*/
- function cache_off()
+ public function cache_off()
{
$this->cache_on = FALSE;
return FALSE;
@@ -1123,10 +1074,9 @@ class CI_DB_driver {
/**
* Delete the cache files associated with a particular URI
*
- * @access public
- * @return void
+ * @return bool
*/
- function cache_delete($segment_one = '', $segment_two = '')
+ public function cache_delete($segment_one = '', $segment_two = '')
{
if ( ! $this->_cache_init())
{
@@ -1140,10 +1090,9 @@ class CI_DB_driver {
/**
* Delete All cache files
*
- * @access public
- * @return void
+ * @return bool
*/
- function cache_delete_all()
+ public function cache_delete_all()
{
if ( ! $this->_cache_init())
{
@@ -1158,10 +1107,9 @@ class CI_DB_driver {
/**
* Initialize the Cache Class
*
- * @access private
- * @return void
+ * @return bool
*/
- function _cache_init()
+ protected function _cache_init()
{
if (is_object($this->CACHE) AND class_exists('CI_DB_Cache'))
{
@@ -1185,10 +1133,9 @@ class CI_DB_driver {
/**
* Close DB Connection
*
- * @access public
* @return void
*/
- function close()
+ public function close()
{
if (is_resource($this->conn_id) OR is_object($this->conn_id))
{
@@ -1202,13 +1149,12 @@ class CI_DB_driver {
/**
* Display an error message
*
- * @access public
* @param string the error message
* @param string any "swap" values
- * @param boolean whether to localize the message
+ * @param bool whether to localize the message
* @return string sends the application/error_db.php template
*/
- function display_error($error = '', $swap = '', $native = FALSE)
+ public function display_error($error = '', $swap = '', $native = FALSE)
{
$LANG =& load_class('Lang', 'core');
$LANG->load('db');
@@ -1252,27 +1198,11 @@ class CI_DB_driver {
/**
* Protect Identifiers
*
- * This function adds backticks if appropriate based on db type
- *
- * @access private
- * @param mixed the item to escape
- * @return mixed the item with backticks
- */
- function protect_identifiers($item, $prefix_single = FALSE)
- {
- return $this->_protect_identifiers($item, $prefix_single);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Protect Identifiers
- *
* This function is used extensively by the Active Record class, and by
* a couple functions in this class.
* It takes a column or table name (optionally with an alias) and inserts
* the table prefix onto it. Some logic is necessary in order to deal with
- * column names that include the path. Consider a query like this:
+ * column names that include the path. Consider a query like this:
*
* SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
*
@@ -1285,14 +1215,13 @@ class CI_DB_driver {
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
- * @access private
* @param string
* @param bool
* @param mixed
* @param bool
* @return string
*/
- function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
+ public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
{
if ( ! is_bool($protect_identifiers))
{
@@ -1302,10 +1231,9 @@ class CI_DB_driver {
if (is_array($item))
{
$escaped_array = array();
-
foreach ($item as $k => $v)
{
- $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v);
+ $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v);
}
return $escaped_array;
@@ -1325,7 +1253,7 @@ class CI_DB_driver {
// This is basically a bug fix for queries that use MAX, MIN, etc.
// If a parenthesis is found we know that we do not need to
- // escape the data or add a prefix. There's probably a more graceful
+ // escape the data or add a prefix. There's probably a more graceful
// way to deal with this, but I'm not thinking of it -- Rick
if (strpos($item, '(') !== FALSE)
{
@@ -1340,7 +1268,7 @@ class CI_DB_driver {
$parts = explode('.', $item);
// Does the first segment of the exploded item match
- // one of the aliases previously identified? If so,
+ // one of the aliases previously identified? If so,
// we have nothing more to do other than escape the item
if (in_array($parts[0], $this->ar_aliased_tables))
{
@@ -1359,7 +1287,7 @@ class CI_DB_driver {
return $item.$alias;
}
- // Is there a table prefix defined in the config file? If not, no need to do anything
+ // Is there a table prefix defined in the config file? If not, no need to do anything
if ($this->dbprefix != '')
{
// We now add the table prefix based on some logic.
@@ -1413,7 +1341,7 @@ class CI_DB_driver {
return $item.$alias;
}
- // Is there a table prefix? If not, no need to insert it
+ // Is there a table prefix? If not, no need to insert it
if ($this->dbprefix != '')
{
// Verify table prefix and replace if necessary
@@ -1437,9 +1365,18 @@ class CI_DB_driver {
return $item.$alias;
}
+ // --------------------------------------------------------------------
-}
+ /**
+ * Dummy method that allows Active Record class to be disabled
+ *
+ * This function is used extensively by every db driver.
+ *
+ * @return void
+ */
+ abstract protected function _reset_select();
+}
/* 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_forge.php b/system/database/DB_forge.php
index 336e9497d..34c502a99 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -34,7 +34,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_forge {
+abstract class CI_DB_forge {
public $fields = array();
public $keys = array();
@@ -346,4 +346,4 @@ class CI_DB_forge {
}
/* End of file DB_forge.php */
-/* Location: ./system/database/DB_forge.php */
+/* Location: ./system/database/DB_forge.php */ \ No newline at end of file
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 730443222..04f964fb1 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -47,6 +47,12 @@ class CI_DB_result {
public $num_rows = 0;
public $row_data = NULL;
+ public function __construct(&$driver_object)
+ {
+ $this->conn_id = $driver_object->conn_id;
+ $this->result_id = $driver_object->result_id;
+ }
+
/**
* Query result. Acts as a wrapper function for the following functions.
*
@@ -386,4 +392,4 @@ class CI_DB_result {
}
/* End of file DB_result.php */
-/* Location: ./system/database/DB_result.php */
+/* Location: ./system/database/DB_result.php */ \ No newline at end of file
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 4c881d8a1..642a004bd 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -32,7 +32,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_utility extends CI_DB_forge {
+abstract class CI_DB_utility extends CI_DB_forge {
public $db;
public $data_cache = array();
@@ -384,4 +384,4 @@ class CI_DB_utility extends CI_DB_forge {
}
/* End of file DB_utility.php */
-/* Location: ./system/database/DB_utility.php */
+/* Location: ./system/database/DB_utility.php */ \ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index cde719eae..bed3d8685 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CUBRID Database Adapter Class
*
@@ -42,79 +40,102 @@
*/
class CI_DB_cubrid_driver extends CI_DB {
- // Default CUBRID Broker port. Will be used unless user
- // explicitly specifies another one.
- const DEFAULT_PORT = 33000;
-
- var $dbdriver = 'cubrid';
+ public $dbdriver = 'cubrid';
// The character used for escaping - no need in CUBRID
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences - not used in CUBRID
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
+ protected $_like_escape_str = '';
+ protected $_like_escape_chr = '';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = 'SELECT COUNT(*) AS ';
- var $_random_keyword = ' RAND()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
- /**
- * Non-persistent database connection
- *
- * @access private called by the base class
- * @return resource
- */
- function db_connect()
- {
- // If no port is defined by the user, use the default value
- if ($this->port == '')
- {
- $this->port = self::DEFAULT_PORT;
- }
+ // CUBRID-specific properties
+ public $auto_commit = TRUE;
- $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
+ public function __construct($params)
+ {
+ parent::__construct($params);
- if ($conn)
+ if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
{
- // Check if a user wants to run queries in dry, i.e. run the
- // queries but not commit them.
- if (isset($this->auto_commit) && ! $this->auto_commit)
+ if (stripos($matches[2], 'autocommit=off') !== FALSE)
{
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
- }
- else
- {
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
- $this->auto_commit = TRUE;
+ $this->auto_commit = FALSE;
}
}
+ else
+ {
+ // If no port is defined by the user, use the default value
+ $this->port == '' OR $this->port = 33000;
+ }
+ }
- return $conn;
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
+ return $this->_cubrid_connect();
}
// --------------------------------------------------------------------
/**
* Persistent database connection
+ *
* In CUBRID persistent DB connection is supported natively in CUBRID
* engine which can be configured in the CUBRID Broker configuration
* file by setting the CCI_PCONNECT parameter to ON. In that case, all
* connections established between the client application and the
- * server will become persistent. This is calling the same
- * @cubrid_connect function will establish persisten connection
- * considering that the CCI_PCONNECT is ON.
+ * server will become persistent.
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return $this->db_connect();
+ return $this->_cubrid_connect(TRUE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * CUBRID connection
+ *
+ * A CUBRID-specific method to create a connection to the database.
+ * Except for determining if a persistent connection should be used,
+ * the rest of the logic is the same for db_connect() and db_pconnect().
+ *
+ * @param bool
+ * @return resource
+ */
+ protected function _cubrid_connect($persistent = FALSE)
+ {
+ if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches))
+ {
+ $_temp = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url';
+ $conn_id = ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '')
+ ? $_temp($this->dsn, $this->username, $this->password)
+ : $_temp($this->dsn);
+ }
+ else
+ {
+ $_temp = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect';
+ $conn_id = ($this->username !== '')
+ ? $_temp($this->hostname, $this->port, $this->database, $this->username, $this->password)
+ : $_temp($this->hostname, $this->port, $this->database);
+ }
+
+ return $conn_id;
}
// --------------------------------------------------------------------
@@ -125,10 +146,9 @@ class CI_DB_cubrid_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (cubrid_ping($this->conn_id) === FALSE)
{
@@ -141,10 +161,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// In CUBRID there is no need to select a database as the database
// is chosen at the connection time.
@@ -156,37 +175,15 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- // In CUBRID, there is no need to set charset or collation.
- // This is why returning true will allow the application continue
- // its normal process.
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Version number query string
+ * Database version number
*
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- // To obtain the CUBRID Server version, no need to run the SQL query.
- // CUBRID PHP API provides a function to determin this value.
- // This is why we also need to add 'cubrid' value to the list of
- // $driver_version_exceptions array in DB_driver class in
- // version() function.
- return cubrid_get_server_info($this->conn_id);
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = cubrid_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
@@ -194,42 +191,22 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
return @cubrid_query($sql, $this->conn_id);
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
- {
- // No need to prepare
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -260,10 +237,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -291,10 +267,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -322,12 +297,11 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -362,12 +336,11 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
- return @cubrid_affected_rows($this->conn_id);
+ return @cubrid_affected_rows();
}
// --------------------------------------------------------------------
@@ -375,10 +348,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @cubrid_insert_id($this->conn_id);
}
@@ -391,19 +363,17 @@ class CI_DB_cubrid_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified table
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
-
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
@@ -421,11 +391,10 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SHOW TABLES";
@@ -444,13 +413,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -460,11 +428,10 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
@@ -472,41 +439,27 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
- */
- function _error_message()
- {
- return cubrid_error($this->conn_id);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return cubrid_errno($this->conn_id);
+ return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id));
}
- // --------------------------------------------------------------------
-
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -545,11 +498,10 @@ class CI_DB_cubrid_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -566,13 +518,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
}
@@ -585,13 +536,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
return "REPLACE INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
}
@@ -603,13 +553,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES ".implode(', ', $values);
}
@@ -622,7 +571,6 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -630,7 +578,7 @@ class CI_DB_cubrid_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -658,13 +606,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
@@ -705,7 +652,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
-
/**
* Truncate statement
*
@@ -713,11 +659,10 @@ class CI_DB_cubrid_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return "TRUNCATE ".$table;
}
@@ -729,13 +674,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -763,13 +707,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
if ($offset == 0)
{
@@ -788,17 +731,15 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@cubrid_close($conn_id);
}
}
-
/* End of file cubrid_driver.php */
/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 85e740057..bbda484c4 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CUBRID Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _create_database($name)
+ public function _create_database($name)
{
// CUBRID does not allow to create a database in SQL. The GUI tools
// have to be used for this purpose.
@@ -55,11 +52,10 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
// CUBRID does not allow to drop a database in SQL. The GUI tools
// have to be used for this purpose.
@@ -71,16 +67,15 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ protected function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
@@ -93,11 +88,11 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t\"" . $this->db->_protect_identifiers($field) . "\"";
+ $sql .= "\n\t\"".$this->db->protect_identifiers($field).'"';
if (array_key_exists('NAME', $attributes))
{
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
+ $sql .= ' '.$this->db->protect_identifiers($attributes['NAME']).' ';
}
if (array_key_exists('TYPE', $attributes))
@@ -172,15 +167,14 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -197,10 +191,9 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
// If there is a PK defined
if (count($primary_keys) > 0)
{
- $key_name = "pk_" . $table . "_" .
- $this->db->_protect_identifiers(implode('_', $primary_keys));
-
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $key_name = 'pk_'.$table.'_'.$this->db->protect_identifiers(implode('_', $primary_keys));
+
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")";
}
@@ -210,15 +203,15 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
-
+
$sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")";
}
}
@@ -233,10 +226,9 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
}
@@ -249,28 +241,27 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
$sql .= $this->_process_fields($fields);
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -283,15 +274,13 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'RENAME TABLE '.$this->db->_protect_identifiers($table_name)." AS ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'RENAME TABLE '.$this->db->protect_identifiers($table_name).' AS '.$this->db->protect_identifiers($new_table_name);
}
}
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 4c0fede10..6a61a213d 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// --------------------------------------------------------------------
-
/**
* CUBRID Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @cubrid_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @cubrid_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
return cubrid_column_names($this->result_id);
}
@@ -84,10 +79,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
@@ -147,9 +141,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if(is_resource($this->result_id) ||
get_resource_type($this->result_id) == "Unknown" &&
@@ -169,10 +163,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return cubrid_data_seek($this->result_id, $n);
}
@@ -184,10 +177,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return cubrid_fetch_assoc($this->result_id);
}
@@ -199,16 +191,14 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return cubrid_fetch_object($this->result_id);
}
}
-
/* End of file cubrid_result.php */
/* Location: ./system/database/drivers/cubrid/cubrid_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index 750c0d8dd..dafd66146 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CUBRID Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
* @return array
*/
- function _list_databases()
+ public function _list_databases()
{
// CUBRID does not allow to see the list of all databases on the
// server. It is the way its architecture is designed. Every
@@ -66,12 +63,11 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
* @link http://www.cubrid.org/manual/840/en/Optimize%20Database
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table optimization can be performed using CUBRID Manager
@@ -86,12 +82,11 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
* @link http://www.cubrid.org/manual/840/en/Checking%20Database%20Consistency
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
// Not supported in CUBRID as of version 8.4.0. Database or
// table consistency can be checked using CUBRID Manager
@@ -103,11 +98,10 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
/**
* CUBRID Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table backup can be performed using CUBRID Manager
diff --git a/system/database/drivers/interbase/index.html b/system/database/drivers/interbase/index.html
new file mode 100644
index 000000000..c942a79ce
--- /dev/null
+++ b/system/database/drivers/interbase/index.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+ <title>403 Forbidden</title>
+</head>
+<body>
+
+<p>Directory access is forbidden.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
new file mode 100644
index 000000000..d8b6ae571
--- /dev/null
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -0,0 +1,548 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+/**
+ * Firebird/Interbase Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the active record
+ * class is being used or not.
+ *
+ * @package CodeIgniter
+ * @subpackage Drivers
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_interbase_driver extends CI_DB {
+
+ public $dbdriver = 'interbase';
+
+ // The character used to escape with
+ protected $_escape_char = '"';
+
+ // clause and character used for LIKE escape sequences
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
+
+ /**
+ * The syntax to count rows is slightly different across different
+ * database engines, so this string appears in each driver and is
+ * used for the count_all() and count_all_results() functions.
+ */
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' Random()'; // database specific random keyword
+
+ // Keeps track of the resource for the current transaction
+ protected $trans;
+
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
+ return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Persistent database connection
+ *
+ * @return resource
+ */
+ public function db_pconnect()
+ {
+ return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Select the database
+ *
+ * @return bool
+ */
+ public function db_select()
+ {
+ // Connection selects the database
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Database version number
+ *
+ * @return string
+ */
+ public function version()
+ {
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+
+ if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
+ {
+ $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
+
+ // Don't keep the service open
+ ibase_service_detach($service);
+ return $this->data_cache['version'];
+ }
+
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Execute the query
+ *
+ * @param string an SQL query
+ * @return resource
+ */
+ protected function _execute($sql)
+ {
+ return @ibase_query($this->conn_id, $sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Begin Transaction
+ *
+ * @return bool
+ */
+ public function trans_begin($test_mode = FALSE)
+ {
+ // When transactions are nested we only begin/commit/rollback the outermost ones
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
+ {
+ return TRUE;
+ }
+
+ // Reset the transaction failure flag.
+ // If the $test_mode flag is set to TRUE transactions will be rolled back
+ // even if the queries produce a successful result.
+ $this->_trans_failure = ($test_mode === TRUE);
+
+ $this->trans = @ibase_trans($this->conn_id);
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Commit Transaction
+ *
+ * @return bool
+ */
+ public function trans_commit()
+ {
+ // When transactions are nested we only begin/commit/rollback the outermost ones
+ if ( ! $this->trans_enabled OR $this->_trans->depth > 0)
+ {
+ return TRUE;
+ }
+
+ return @ibase_commit($this->trans);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Rollback Transaction
+ *
+ * @return bool
+ */
+ public function trans_rollback()
+ {
+ // When transactions are nested we only begin/commit/rollback the outermost ones
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
+ {
+ return TRUE;
+ }
+
+ return @ibase_rollback($this->trans);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Escape String
+ *
+ * @param string
+ * @param bool whether or not the string will be used in a LIKE condition
+ * @return string
+ */
+ public function escape_str($str, $like = FALSE)
+ {
+ if (is_array($str))
+ {
+ foreach ($str as $key => $val)
+ {
+ $str[$key] = $this->escape_str($val, $like);
+ }
+
+ return $str;
+ }
+
+ // escape LIKE condition wildcards
+ if ($like === TRUE)
+ {
+ 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;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Affected Rows
+ *
+ * @return int
+ */
+ public function affected_rows()
+ {
+ return @ibase_affected_rows($this->conn_id);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert ID
+ *
+ * @param string $generator_name
+ * @param int $inc_by
+ * @return int
+ */
+ public function insert_id($generator_name, $inc_by=0)
+ {
+ //If a generator hasn't been used before it will return 0
+ return ibase_gen_id('"'.$generator_name.'"', $inc_by);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * "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
+ *
+ * @param bool
+ * @return string
+ */
+ protected function _list_tables($prefix_limit = FALSE)
+ {
+ $sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
+
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ {
+ return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show column query
+ *
+ * Generates a platform-specific query string so that the column names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_columns($table = '')
+ {
+ return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = \''.$this->escape_str($table)."'";
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field data query
+ *
+ * Generates a platform-specific query so that the column data can be retrieved
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _field_data($table)
+ {
+ // Need to find a more efficient way to do this
+ // but Interbase/Firebird seems to lack the
+ // limit clause
+ return 'SELECT * FROM '.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Error
+ *
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
+ */
+ public function error()
+ {
+ return array('code' => ibase_errcode(), 'message' => ibase_errmsg());
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Escape the SQL Identifiers
+ *
+ * This public function escapes column and table names
+ *
+ * @param string
+ * @return string
+ */
+ protected function _escape_identifiers($item)
+ {
+ foreach ($this->_reserved_identifiers as $id)
+ {
+ if (strpos($item, '.'.$id) !== FALSE)
+ {
+ $item = str_replace('.', $this->_escape_char.'.', $item);
+
+ // remove duplicates if the user already included the escape
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
+ }
+ }
+
+ if (strpos($item, '.') !== FALSE)
+ {
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ }
+
+ // remove duplicates if the user already included the escape
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This public function implicitly groups FROM tables so there is no confusion
+ * about operator precedence in harmony with SQL standards
+ *
+ * @param array
+ * @return string
+ */
+ protected function _from_tables($tables)
+ {
+ if ( ! is_array($tables))
+ {
+ $tables = array($tables);
+ }
+
+ //Interbase/Firebird doesn't like grouped tables
+ return implode(', ', $tables);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert statement
+ *
+ * Generates a platform-specific insert string from the supplied data
+ *
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
+ */
+ protected function _insert($table, $keys, $values)
+ {
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update statement
+ *
+ * Generates a platform-specific update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @param array the orderby clause
+ * @param array the limit clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '');
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ * If the database does not support the truncate() command
+ * This public function maps to "DELETE FROM table"
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return $this->_delete($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param string the limit clause
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ if (count($where) > 0 OR count($like) > 0)
+ {
+ $conditions = "\nWHERE ".implode("\n", $where)
+ .((count($where) > 0 && count($like) > 0) ? ' AND ' : '')
+ .implode("\n", $like);
+ }
+ else
+ {
+ $conditions = '';
+ }
+
+ //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+
+ return 'DELETE FROM '.$table.' '.$conditions;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Limit string
+ *
+ * Generates a platform-specific LIMIT clause
+ *
+ * @param string the sql query string
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
+ * @return string
+ */
+ protected function _limit($sql, $limit, $offset)
+ {
+ // Limit clause depends on if Interbase or Firebird
+ if (stripos($this->version(), 'firebird') !== FALSE)
+ {
+ $select = 'FIRST '. (int) $limit
+ .($offset > 0 ? ' SKIP '. (int) $offset : '');
+ }
+ else
+ {
+ $select = 'ROWS '
+ .($offset > 0 ? (int) $offset.' TO '.($limit + $offset) : (int) $limit);
+ }
+
+ return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Close DB Connection
+ *
+ * @param resource
+ * @return void
+ */
+ protected function _close($conn_id)
+ {
+ @ibase_close($conn_id);
+ }
+
+}
+
+/* End of file interbase_driver.php */
+/* Location: ./system/database/drivers/interbase/interbase_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php
new file mode 100644
index 000000000..f46043569
--- /dev/null
+++ b/system/database/drivers/interbase/interbase_forge.php
@@ -0,0 +1,243 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Interbase/Firebird Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_interbase_forge extends CI_DB_forge {
+
+ /**
+ * Create database
+ *
+ * @param string the database name
+ * @return string
+ */
+ protected function _create_database($filename='')
+ {
+ // Firebird databases are flat files, so a path is required
+ // Hostname is needed for remote access
+ return 'CREATE DATABASE "'.$this->hostname.':'.$filename.'"';
+
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @param string the database name - not used in this driver
+ * - the current db is dropped
+ * @return bool
+ */
+ protected function _drop_database($name='')
+ {
+ return ibase_drop_db($this->conn_id);
+ }
+ // --------------------------------------------------------------------
+
+ /**
+ * Create Table
+ *
+ * @param string the table name
+ * @param array the fields
+ * @param mixed primary key(s)
+ * @param mixed key(s)
+ * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @return string
+ */
+ protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ {
+ $sql = 'CREATE TABLE ';
+
+ $sql .= $this->db->protect_identifiers($table)."(";
+ $current_field_count = 0;
+
+ foreach ($fields as $field => $attributes)
+ {
+ // Numeric field names aren't allowed in databases, so if the key is
+ // numeric, we know it was assigned by PHP and the developer manually
+ // entered the field information, so we'll simply add it to the list
+ if (is_numeric($field))
+ {
+ $sql .= "\n\t$attributes";
+ }
+ else
+ {
+ $attributes = array_change_key_case($attributes, CASE_UPPER);
+
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
+
+ $sql .= ' '.$attributes['TYPE'];
+
+ if (array_key_exists('CONSTRAINT', $attributes))
+ {
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
+
+ if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ {
+ $sql .= ' UNSIGNED';
+ }
+
+ if (array_key_exists('DEFAULT', $attributes))
+ {
+ $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ }
+
+ if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
+ {
+ $sql .= ' NULL';
+ }
+ else
+ {
+ $sql .= ' NOT NULL';
+ }
+
+ if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' AUTO_INCREMENT';
+ }
+ }
+
+ // don't add a comma on the end of the last field
+ if (++$current_field_count < count($fields))
+ {
+ $sql .= ',';
+ }
+ }
+
+ if (count($primary_keys) > 0)
+ {
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
+ $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ }
+
+ if (is_array($keys) && count($keys) > 0)
+ {
+ foreach ($keys as $key)
+ {
+ if (is_array($key))
+ {
+ $key = $this->db->protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
+ }
+ }
+
+ $sql .= "\n)";
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop Table
+ *
+ * @return string
+ */
+ protected function _drop_table($table)
+ {
+ return 'DROP TABLE '.$name;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Alter table query
+ *
+ * Generates a platform-specific query so that a table can be altered
+ * Called by add_column(), drop_column(), and column_alter(),
+ *
+ * @param string the ALTER type (ADD, DROP, CHANGE)
+ * @param string the column name
+ * @param string the table name
+ * @param string the column definition
+ * @param string the default value
+ * @param boolean should 'NOT NULL' be added
+ * @param string the field after which we should add the new field
+ * @return string
+ */
+ protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ {
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table)." $alter_type ".$this->db->protect_identifiers($column_name);
+
+ $sql .= " {$column_definition}";
+
+ if ($default_value != '')
+ {
+ $sql .= " DEFAULT \"{$default_value}\"";
+ }
+
+ if ($null === NULL)
+ {
+ $sql .= ' NULL';
+ }
+ else
+ {
+ $sql .= ' NOT NULL';
+ }
+
+ if ($after_field != '')
+ {
+ $sql .= ' AFTER ' . $this->db->protect_identifiers($after_field);
+ }
+
+ return $sql;
+
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ protected function _rename_table($table_name, $new_table_name)
+ {
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
+ }
+}
+
+/* End of file interbase_forge.php */
+/* Location: ./system/database/drivers/interbase/interbase_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php
new file mode 100644
index 000000000..fd4178dec
--- /dev/null
+++ b/system/database/drivers/interbase/interbase_result.php
@@ -0,0 +1,277 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+/**
+ * Interbase/Firebird Result Class
+ *
+ * This class extends the parent result class: CI_DB_result
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_interbase_result extends CI_DB_result {
+
+ public $num_rows;
+
+ /**
+ * Number of rows in the result set
+ *
+ * @return int
+ */
+ public function num_rows()
+ {
+ if (is_int($this->num_rows))
+ {
+ return $this->num_rows;
+ }
+
+ // Get the results so that you can get an accurate rowcount
+ $this->result();
+
+ return $this->num_rows;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Number of fields in the result set
+ *
+ * @return int
+ */
+ public function num_fields()
+ {
+ return @ibase_num_fields($this->result_id);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @return array
+ */
+ public function list_fields()
+ {
+ $field_names = array();
+ for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
+ {
+ $info = ibase_field_info($this->result_id, $i);
+ $field_names[] = $info['name'];
+ }
+
+ return $field_names;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field data
+ *
+ * Generates an array of objects containing field meta-data
+ *
+ * @return array
+ */
+ public function field_data()
+ {
+ $retval = array();
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
+ {
+ $info = ibase_field_info($this->result_id, $i);
+
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $info['name'];
+ $retval[$i]->type = $info['type'];
+ $retval[$i]->max_length = $info['length'];
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
+ }
+
+ return $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Free the result
+ *
+ * @return void
+ */
+ public function free_result()
+ {
+ @ibase_free_result($this->result_id);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Data Seek
+ *
+ * Moves the internal pointer to the desired offset. We call
+ * this internally before fetching results to make sure the
+ * result set starts at zero
+ *
+ * @return array
+ */
+ protected function _data_seek($n = 0)
+ {
+ // Interbase driver doesn't implement a suitable function
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - associative array
+ *
+ * Returns the result set as an array
+ *
+ * @return array
+ */
+ protected function _fetch_assoc()
+ {
+ if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
+ {
+ //Increment row count
+ $this->num_rows++;
+ }
+
+ return $row;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - object
+ *
+ * Returns the result set as an object
+ *
+ * @return object
+ */
+ protected function _fetch_object()
+ {
+ if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
+ {
+ //Increment row count
+ $this->num_rows++;
+ }
+
+ return $row;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Query result. "object" version.
+ *
+ * @return object
+ */
+ public function result_object()
+ {
+ if (count($this->result_object) === $this->num_rows)
+ {
+ return $this->result_object;
+ }
+
+ // Convert result array to object so that
+ // We don't have to get the result again
+ if (($c = count($this->result_array)) > 0)
+ {
+ for ($i = 0; $i < $c; $i++)
+ {
+ $this->result_object[$i] = (object) $this->result_array[$i];
+ }
+
+ return $this->result_object;
+ }
+
+ // In the event that query caching is on the result_id variable
+ // will return FALSE since there isn't a valid SQL resource so
+ // we'll simply return an empty array.
+ if ($this->result_id === FALSE)
+ {
+ return array();
+ }
+
+ $this->num_rows = 0;
+ while ($row = $this->_fetch_object())
+ {
+ $this->result_object[] = $row;
+ }
+
+ return $this->result_object;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Query result. "array" version.
+ *
+ * @return array
+ */
+ public function result_array()
+ {
+ if (count($this->result_array) === $this->num_rows)
+ {
+ return $this->result_array;
+ }
+
+ // Since the object and array are really similar, just case
+ // the result object to an array if need be
+ if (($c = count($this->result_object)) > 0)
+ {
+ for ($i = 0; $i < $c; $i++)
+ {
+ $this->result_array[$i] = (array) $this->result_object[$i];
+ }
+
+ return $this->result_array;
+ }
+
+ // In the event that query caching is on the result_id variable
+ // will return FALSE since there isn't a valid SQL resource so
+ // we'll simply return an empty array.
+ if ($this->result_id === FALSE)
+ {
+ return array();
+ }
+
+ $this->num_rows = 0;
+ while ($row = $this->_fetch_assoc())
+ {
+ $this->result_array[] = $row;
+ }
+
+ return $this->result_array;
+ }
+
+}
+
+/* End of file interbase_result.php */
+/* Location: ./system/database/drivers/interbase/interbase_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php
new file mode 100644
index 000000000..a88055ee0
--- /dev/null
+++ b/system/database/drivers/interbase/interbase_utility.php
@@ -0,0 +1,115 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Interbase/Firebird Utility Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_interbase_utility extends CI_DB_utility {
+
+ /**
+ * List databases
+ *
+ * I don't believe you can do a database listing with Firebird
+ * since each database is its own file. I suppose we could
+ * try reading a directory looking for Firebird files, but
+ * that doesn't seem like a terribly good idea
+ *
+ * @return bool
+ */
+ public function _list_databases()
+ {
+ if ($this->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Is optimization even supported in Interbase/Firebird?
+ *
+ * @param string the table name
+ * @return object
+ */
+ public function _optimize_table($table)
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Table repairs are not supported in Interbase/Firebird
+ *
+ * @param string the table name
+ * @return object
+ */
+ public function _repair_table($table)
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Interbase/Firebird Export
+ *
+ * @param string $filename
+ * @return mixed
+ */
+ public function backup($filename)
+ {
+ if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password))
+ {
+ $res = ibase_backup($service, $this->db->database, $filename.'.fbk');
+
+ //Close the service connection
+ ibase_service_detach($service);
+
+ return $res;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+}
+
+/* End of file interbase_utility.php */
+/* Location: ./system/database/drivers/interbase/interbase_utility.php */ \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2a1098932..f2933fe43 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MS SQL Database Adapter Class
*
@@ -42,30 +40,29 @@
*/
class CI_DB_mssql_driver extends CI_DB {
- var $dbdriver = 'mssql';
+ public $dbdriver = 'mssql';
// The character used for escaping
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " ESCAPE '%s' ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' ASC'; // not currently supported
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' ASC'; // not currently supported
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
if ($this->port != '')
{
@@ -80,10 +77,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
if ($this->port != '')
{
@@ -96,48 +92,27 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
- */
- function reconnect()
- {
- // not implemented in MSSQL
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
// Note: The brackets are required in the event that the DB name
// contains reserved characters
- return @mssql_select_db('['.$this->database.']', $this->conn_id);
- }
-
- // --------------------------------------------------------------------
+ if (@mssql_select_db('['.$database.']', $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
- /**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- // @todo - add support if needed
- return TRUE;
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -145,41 +120,22 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
return @mssql_query($sql, $this->conn_id);
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
- {
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -206,10 +162,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -231,10 +186,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -256,12 +210,11 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -294,10 +247,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mssql_rows_affected($this->conn_id);
}
@@ -305,14 +257,13 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Insert ID
- *
- * Returns the last id created in the Identity column.
- *
- * @access public
- * @return integer
- */
- function insert_id()
+ * Insert ID
+ *
+ * Returns the last id created in the Identity column.
+ *
+ * @return string
+ */
+ public function insert_id()
{
$ver = self::_parse_major_version($this->version());
$sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
@@ -324,16 +275,15 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Parse major version
- *
- * Grabs the major version number from the
- * database server version string passed in.
- *
- * @access private
- * @param string $version
- * @return int16 major version number
- */
- function _parse_major_version($version)
+ * Parse major version
+ *
+ * Grabs the major version number from the
+ * database server version string passed in.
+ *
+ * @param string $version
+ * @return int major version number
+ */
+ protected function _parse_major_version($version)
{
preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
return $ver_info[1]; // return the major version b/c that's all we're interested in.
@@ -342,14 +292,13 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Version number query string
- *
- * @access public
- * @return string
- */
- function _version()
+ * Version number query string
+ *
+ * @return string
+ */
+ protected function _version()
{
- return "SELECT @@VERSION AS ver";
+ return 'SELECT @@VERSION AS ver';
}
// --------------------------------------------------------------------
@@ -360,19 +309,17 @@ class CI_DB_mssql_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
@@ -390,11 +337,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
@@ -415,11 +361,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access private
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
}
@@ -431,11 +376,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT TOP 1 * FROM ".$table;
}
@@ -443,28 +387,18 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
- */
- function _error_message()
- {
- return mssql_get_last_message();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- // Are error numbers supported?
- return '';
+ $query = $this->query('SELECT @@ERROR AS code');
+ $query = $query->row();
+ return array('code' => $query->code, 'message' => mssql_get_last_message());
}
// --------------------------------------------------------------------
@@ -474,11 +408,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -517,11 +450,10 @@ class CI_DB_mssql_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -538,13 +470,12 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
@@ -556,7 +487,6 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -564,7 +494,7 @@ class CI_DB_mssql_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -594,11 +524,10 @@ class CI_DB_mssql_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return "TRUNCATE ".$table;
}
@@ -644,13 +573,12 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
$i = $limit + $offset;
@@ -662,18 +590,15 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mssql_close($conn_id);
}
}
-
-
/* End of file 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 dd8aa3448..2e3e314ed 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MS SQL Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_mssql_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
return "CREATE DATABASE ".$name;
}
@@ -53,11 +50,10 @@ class CI_DB_mssql_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
return "DROP DATABASE ".$name;
}
@@ -67,10 +63,10 @@ class CI_DB_mssql_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
- * @return bool
+ * @param string table name
+ * @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
return "DROP TABLE ".$this->db->_escape_identifiers($table);
}
@@ -80,15 +76,14 @@ class CI_DB_mssql_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
+ * @return string
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -100,7 +95,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
$sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
@@ -113,7 +108,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
@@ -156,7 +151,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
@@ -166,11 +161,11 @@ class CI_DB_mssql_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
@@ -190,19 +185,18 @@ class CI_DB_mssql_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -228,7 +222,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -242,16 +236,14 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
// I think this syntax will work, but can find little documentation on renaming tables in MSSQL
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index bba2e6243..2723f4614 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MS SQL Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mssql_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mssql_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mssql_fetch_field($this->result_id))
@@ -90,10 +85,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mssql_fetch_field($this->result_id))
@@ -116,9 +110,9 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -136,10 +130,9 @@ class CI_DB_mssql_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return mssql_data_seek($this->result_id, $n);
}
@@ -151,10 +144,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mssql_fetch_assoc($this->result_id);
}
@@ -166,16 +158,14 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mssql_fetch_object($this->result_id);
}
}
-
/* End of file mssql_result.php */
/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index be6ed5bb0..5c144330d 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MS SQL Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_mssql_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases
}
@@ -54,11 +51,10 @@ class CI_DB_mssql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
@@ -70,11 +66,10 @@ class CI_DB_mssql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
@@ -84,11 +79,10 @@ class CI_DB_mssql_utility extends CI_DB_utility {
/**
* MSSQL Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 067710ff0..bef4111c3 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -119,11 +119,23 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Select the database
*
+ * @param string database name
* @return bool
*/
- public function db_select()
+ public function db_select($database = '')
{
- return @mysql_select_db($this->database, $this->conn_id);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysql_select_db($database, $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -132,26 +144,25 @@ class CI_DB_mysql_driver extends CI_DB {
* Set client character set
*
* @param string
- * @param string
* @return bool
*/
- public function db_set_charset($charset, $collation)
+ protected function _db_set_charset($charset)
{
- return function_exists('mysql_set_charset')
- ? @mysql_set_charset($charset, $this->conn_id)
- : @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
+ return @mysql_set_charset($charset, $this->conn_id);
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Database version number
*
* @return string
*/
- protected function _version()
+ public function version()
{
- return 'SELECT version() AS ver';
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = @mysql_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
@@ -275,18 +286,7 @@ class CI_DB_mysql_driver extends CI_DB {
return $str;
}
- if (function_exists('mysql_real_escape_string') && is_resource($this->conn_id))
- {
- $str = mysql_real_escape_string($str, $this->conn_id);
- }
- elseif (function_exists('mysql_escape_string'))
- {
- $str = mysql_escape_string($str);
- }
- else
- {
- $str = addslashes($str);
- }
+ $str = is_resource($this->conn_id) ? mysql_real_escape_string($str, $this->conn_id) : addslashes($str);
// escape LIKE condition wildcards
if ($like === TRUE)
@@ -390,40 +390,50 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Field data query
- *
- * Generates a platform-specific query so that the column data can be retrieved
+ * Returns an object with field data
*
* @param string the table name
- * @return string
+ * @return object
*/
- public function _field_data($table)
+ public function field_data($table = '')
{
- return 'DESCRIBE '.$table;
- }
+ if ($table == '')
+ {
+ return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
+ }
- // --------------------------------------------------------------------
+ $query = $this->query('DESCRIBE '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $query->result_object();
- /**
- * The error message string
- *
- * @return string
- */
- protected function _error_message()
- {
- return mysql_error($this->conn_id);
+ $retval = array();
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches);
+
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->Field;
+ $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1];
+ $retval[$i]->default = $query[$i]->Default;
+ $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]);
+ $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------
/**
- * The error message number
+ * Error
*
- * @return int
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
*/
- protected function _error_number()
+ public function error()
{
- return mysql_errno($this->conn_id);
+ return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id));
}
// --------------------------------------------------------------------
@@ -691,4 +701,4 @@ class CI_DB_mysql_driver extends CI_DB {
}
/* 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/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index d3107134e..11172b41b 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -66,7 +66,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
* @param mixed the fields
* @return string
*/
- private function _process_fields($fields)
+ protected function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
@@ -147,11 +147,11 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
- $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
+ $key_name = $this->db->protect_identifiers(implode('_', $primary_keys));
$sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
@@ -161,12 +161,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
@@ -187,7 +187,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
*/
public function _drop_table($table)
{
- return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -237,4 +237,4 @@ class CI_DB_mysql_forge extends CI_DB_forge {
}
/* End of file mysql_forge.php */
-/* Location: ./system/database/drivers/mysql/mysql_forge.php */
+/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index 8f04a936d..f76076f4c 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -90,18 +90,14 @@ class CI_DB_mysql_result extends CI_DB_result {
public function field_data()
{
$retval = array();
- while ($field = mysql_fetch_object($this->result_id))
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
- preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
- $F->default = $field->Default;
- $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
- $F->primary_key = (int) ($field->Key === 'PRI');
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = mysql_field_name($this->result_id, $i);
+ $retval[$i]->type = mysql_field_type($this->result_id, $i);
+ $retval[$i]->max_length = mysql_field_len($this->result_id, $i);
+ $retval[$i]->primary_key = (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE) ? 0 : 1;
+ $retval[$i]->default = '';
}
return $retval;
@@ -170,4 +166,4 @@ class CI_DB_mysql_result extends CI_DB_result {
}
/* End of file mysql_result.php */
-/* Location: ./system/database/drivers/mysql/mysql_result.php */
+/* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 0e7c18e16..2d89cb9cb 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -56,7 +56,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*/
public function _optimize_table($table)
{
- return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -71,7 +71,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*/
public function _repair_table($table)
{
- return 'REPAIR TABLE '.$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -102,7 +102,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Get the table schema
- $query = $this->db->query('SHOW CREATE TABLE `'.$this->db->database.'`.`'.$table.'`');
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table));
// No result means the table name was invalid
if ($query === FALSE)
@@ -115,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
if ($add_drop == TRUE)
{
- $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
+ $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
}
$i = 0;
@@ -135,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Grab all the data from the current table
- $query = $this->db->query('SELECT * FROM '.$table);
+ $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
if ($query->num_rows() == 0)
{
@@ -157,7 +157,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
TRUE);
// Create a string of field names
- $field_str .= '`'.$field->name.'`, ';
+ $field_str .= $this->db->protect_identifiers($field->name).', ';
$i++;
}
@@ -192,15 +192,16 @@ class CI_DB_mysql_utility extends CI_DB_utility {
$val_str = preg_replace('/, $/' , '', $val_str);
// Build the INSERT string
- $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
}
- return $output.$newline.$newline;
+ $output .= $newline.$newline;
}
return $output;
}
+
}
/* End of file mysql_utility.php */
-/* Location: ./system/database/drivers/mysql/mysql_utility.php */
+/* Location: ./system/database/drivers/mysql/mysql_utility.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 aff62a37d..4c5d52127 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,10 +25,8 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
- * MySQLi Database Adapter Class - MySQLi only works with PHP 5
+ * MySQLi Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
@@ -42,52 +40,40 @@
*/
class CI_DB_mysqli_driver extends CI_DB {
- var $dbdriver = 'mysqli';
+ public $dbdriver = 'mysqli';
// The character used for escaping
- var $_escape_char = '`';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in MySQL
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
+ protected $_like_escape_str = '';
+ protected $_like_escape_chr = '';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' RAND()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
*/
- var $delete_hack = TRUE;
-
- // whether SET NAMES must be used to set the character set
- var $use_set_names;
-
- // --------------------------------------------------------------------
+ public $delete_hack = TRUE;
/**
* Non-persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_connect()
+ public function db_connect()
{
- if ($this->port != '')
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
- }
- else
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
- }
-
+ return ($this->port != '')
+ ? @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -95,12 +81,19 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return $this->db_connect();
+ // Persistent connection support was added in PHP 5.3.0
+ if ( ! is_php('5.3'))
+ {
+ return $this->db_connect();
+ }
+
+ return ($this->port != '')
+ ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -111,10 +104,9 @@ class CI_DB_mysqli_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (mysqli_ping($this->conn_id) === FALSE)
{
@@ -127,12 +119,23 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return @mysqli_select_db($this->conn_id, $this->database);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysqli_select_db($this->conn_id, $database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -140,29 +143,26 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Set client character set
*
- * @access private
- * @param string
* @param string
- * @return resource
+ * @return bool
*/
- function _db_set_charset($charset, $collation)
+ protected function _db_set_charset($charset)
{
- return function_exists('mysqli_set_charset')
- ? @mysqli_set_charset($this->conn_id, $charset)
- : @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'");
+ return @mysqli_set_charset($this->conn_id, $charset);
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Database version number
*
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- return "SELECT version() AS ver";
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = @mysqli_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
@@ -170,15 +170,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- $result = @mysqli_query($this->conn_id, $sql);
- return $result;
+ return @mysqli_query($this->conn_id, $this->_prep_query($sql));
}
// --------------------------------------------------------------------
@@ -188,20 +185,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
- // "DELETE FROM TABLE" returns 0 affected rows This hack modifies
- // the query so that it returns the number of affected rows
- if ($this->delete_hack === TRUE)
+ // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
+ // modifies the query so that it a proper number of affected rows is returned.
+ if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
{
- if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
- {
- $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
- }
+ return preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql);
}
return $sql;
@@ -212,18 +205,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -231,7 +218,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
@@ -243,18 +230,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -269,18 +250,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -295,12 +270,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -312,23 +286,12 @@ class CI_DB_mysqli_driver extends CI_DB {
return $str;
}
- if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
- {
- $str = mysqli_real_escape_string($this->conn_id, $str);
- }
- elseif (function_exists('mysql_escape_string'))
- {
- $str = mysql_escape_string($str);
- }
- else
- {
- $str = addslashes($str);
- }
+ $str = is_object($this->conn_id) ? mysqli_real_escape_string($this->conn_id, $str) : addslashes($str);
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -339,10 +302,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mysqli_affected_rows($this->conn_id);
}
@@ -352,10 +314,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @mysqli_insert_id($this->conn_id);
}
@@ -368,27 +329,25 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -399,16 +358,16 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -421,55 +380,61 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
/**
- * Field data query
- *
- * Generates a platform-specific query so that the column data can be retrieved
+ * Returns an object with field data
*
- * @access public
* @param string the table name
* @return object
*/
- function _field_data($table)
+ public function field_data($table = '')
{
- return "DESCRIBE ".$table;
- }
+ if ($table == '')
+ {
+ return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
+ }
- // --------------------------------------------------------------------
+ $query = $this->query('DESCRIBE '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $query->result_object();
- /**
- * The error message string
- *
- * @access private
- * @return string
- */
- function _error_message()
- {
- return mysqli_error($this->conn_id);
+ $retval = array();
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches);
+
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->Field;
+ $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1];
+ $retval[$i]->default = $query[$i]->Default;
+ $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]);
+ $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------
/**
- * The error message number
+ * Error
*
- * @access private
- * @return integer
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return mysqli_errno($this->conn_id);
+ return array('code' => mysqli_errno($this->conn_id), 'message' => mysqli_error($this->conn_id));
}
// --------------------------------------------------------------------
@@ -479,11 +444,10 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -494,24 +458,20 @@ class CI_DB_mysqli_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -522,11 +482,10 @@ class CI_DB_mysqli_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -543,15 +502,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -561,15 +519,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -580,17 +537,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
-
+
// --------------------------------------------------------------------
/**
@@ -598,7 +554,6 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -606,24 +561,17 @@ class CI_DB_mysqli_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -633,17 +581,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -657,25 +602,19 @@ class CI_DB_mysqli_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
$cases = '';
-
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k.' = CASE '."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
+ $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
@@ -687,13 +626,12 @@ class CI_DB_mysqli_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -703,31 +641,26 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
-
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -737,22 +670,15 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
- return $sql;
+ return $sql.' LIMIT '.$limit
+ .($offset > 0 ? ' OFFSET '.$offset : '');
}
// --------------------------------------------------------------------
@@ -760,18 +686,15 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
- * @param resource
+ * @param object
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mysqli_close($conn_id);
}
-
}
-
/* End of file mysqli_driver.php */
/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 590efa939..8cf0ae1fd 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Forge Class
*
@@ -39,13 +37,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
- return "CREATE DATABASE ".$name;
+ return 'CREATE DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -53,13 +50,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
- return "DROP DATABASE ".$name;
+ return 'DROP DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -67,68 +63,58 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ protected function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '')
+ ;
- if (array_key_exists('TYPE', $attributes))
+ if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- }
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
+ if ( ! empty($attributes['CONSTRAINT']))
+ {
+ switch (strtolower($attributes['TYPE']))
+ {
+ case 'decimal':
+ case 'float':
+ case 'numeric':
+ $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
+ break;
+ case 'enum':
+ case 'set':
+ $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
+ break;
+ default:
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
+ }
}
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= (( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -146,15 +132,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -163,15 +148,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
- $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $key_name = $this->db->protect_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -180,22 +162,20 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
- $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
-
- return $sql;
+ return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
}
// --------------------------------------------------------------------
@@ -203,12 +183,11 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -219,31 +198,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -253,15 +225,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 89dd4ded8..83d88aae3 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mysqli_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mysqli_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mysqli_fetch_field($this->result_id))
@@ -90,40 +85,33 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- while ($field = mysqli_fetch_object($this->result_id))
+ $field_data = mysqli_fetch_fields($this->result_id);
+ for ($i = 0, $c = count($field_data); $i < $c; $i++)
{
- preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
-
- $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
- $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = $type;
- $F->default = $field->Default;
- $F->max_length = $length;
- $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $field_data[$i]->name;
+ $retval[$i]->type = $field_data[$i]->type;
+ $retval[$i]->max_length = $field_data[$i]->max_length;
+ $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
+ $retval[$i]->default = '';
}
return $retval;
}
-
+
// --------------------------------------------------------------------
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_object($this->result_id))
{
@@ -141,10 +129,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return mysqli_data_seek($this->result_id, $n);
}
@@ -156,10 +143,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mysqli_fetch_assoc($this->result_id);
}
@@ -171,16 +157,14 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mysqli_fetch_object($this->result_id);
}
}
-
/* End of file mysqli_result.php */
/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 76bd49e31..4d7002e78 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SHOW DATABASES";
+ return 'SHOW DATABASES';
}
// --------------------------------------------------------------------
@@ -54,13 +51,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -70,13 +66,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -84,11 +79,10 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* MySQLi Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index c6621901b..3bc8c114c 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* oci8 Database Adapter Class
*
@@ -50,46 +48,125 @@
* @author Kelly McArdle
*
*/
-
class CI_DB_oci8_driver extends CI_DB {
- var $dbdriver = 'oci8';
+ public $dbdriver = 'oci8';
// The character used for excaping
- var $_escape_char = '"';
+ protected $_escape_char = '"';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " escape '%s' ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(1) AS ";
- var $_random_keyword = ' ASC'; // not currently supported
+ protected $_count_string = 'SELECT COUNT(1) AS ';
+ protected $_random_keyword = ' ASC'; // not currently supported
// Set "auto commit" by default
- var $_commit = OCI_COMMIT_ON_SUCCESS;
+ protected $_commit = OCI_COMMIT_ON_SUCCESS;
// need to track statement id and cursor id
- var $stmt_id;
- var $curs_id;
+ public $stmt_id;
+ public $curs_id;
// if we use a limit, we will add a field that will
// throw off num_fields later
- var $limit_used;
+ public $limit_used;
+
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ $valid_dsns = array(
+ 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
+ // Easy Connect string (Oracle 10g+)
+ 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
+ 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora)
+ );
+
+ /* Space characters don't have any effect when actually
+ * connecting, but can be a hassle while validating the DSN.
+ */
+ $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn);
+
+ if ($this->dsn !== '')
+ {
+ foreach ($valid_dsns as $regexp)
+ {
+ if (preg_match($regexp, $this->dsn))
+ {
+ return;
+ }
+ }
+ }
+
+ // Legacy support for TNS in the hostname configuration field
+ $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname);
+ if (preg_match($valid_dsns['tns'], $this->hostname))
+ {
+ $this->dsn = $this->hostname;
+ return;
+ }
+ elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE
+ && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== ''))
+ {
+ /* If the hostname field isn't empty, doesn't contain
+ * ':' and/or '/' and if port and/or database aren't
+ * empty, then the hostname field is most likely indeed
+ * just a hostname. Therefore we'll try and build an
+ * Easy Connect string from these 3 settings, assuming
+ * that the database field is a service name.
+ */
+ $this->dsn = $this->hostname
+ .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '')
+ .($this->database !== '' ? '/'.ltrim($this->database, '/') : '');
+
+ if (preg_match($valid_dsns['ec'], $this->dsn))
+ {
+ return;
+ }
+ }
+
+ /* At this point, we can only try and validate the hostname and
+ * database fields separately as DSNs.
+ */
+ if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname))
+ {
+ $this->dsn = $this->hostname;
+ return;
+ }
+
+ $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database);
+ foreach ($valid_dsns as $regexp)
+ {
+ if (preg_match($regexp, $this->database))
+ {
+ return;
+ }
+ }
+
+ /* Well - OK, an empty string should work as well.
+ * PHP will try to use environment variables to
+ * determine which Oracle instance to connect to.
+ */
+ $this->dsn = '';
+ }
/**
* Non-persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return resource
*/
public function db_connect()
{
- return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set);
+ return ( ! empty($this->char_set))
+ ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set)
+ : @oci_connect($this->username, $this->password, $this->dsn);
}
// --------------------------------------------------------------------
@@ -97,29 +174,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return resource
*/
public function db_pconnect()
{
- return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
- */
- public function reconnect()
- {
- // not implemented in oracle
- return;
+ return ( ! empty($this->char_set))
+ ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set)
+ : @oci_pconnect($this->username, $this->password, $this->dsn);
}
// --------------------------------------------------------------------
@@ -127,8 +188,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @return resource
*/
public function db_select()
{
@@ -139,30 +199,15 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- public function db_set_charset($charset, $collation)
- {
- // this is done upon connect
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Version number query string
+ * Database version number
*
- * @access protected
- * @return string
+ * @return string
*/
- protected function _version()
+ public function version()
{
- return oci_server_version($this->conn_id);
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = oci_server_version($this->conn_id);
}
// --------------------------------------------------------------------
@@ -170,9 +215,8 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Execute the query
*
- * @access protected called by the base class
- * @param string an SQL query
- * @return resource
+ * @param string an SQL query
+ * @return resource
*/
protected function _execute($sql)
{
@@ -187,41 +231,23 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Generate a statement ID
*
- * @access private
- * @param string an SQL query
- * @return none
+ * @param string an SQL query
+ * @return void
*/
- private function _set_stmt_id($sql)
+ protected function _set_stmt_id($sql)
{
if ( ! is_resource($this->stmt_id))
{
- $this->stmt_id = oci_parse($this->conn_id, $this->_prep_query($sql));
+ $this->stmt_id = oci_parse($this->conn_id, $sql);
}
}
// --------------------------------------------------------------------
/**
- * Prep the query
+ * Get cursor. Returns a cursor from the database
*
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- private function _prep_query($sql)
- {
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * getCursor. Returns a cursor from the datbase
- *
- * @access public
- * @return cursor id
+ * @return cursor id
*/
public function get_cursor()
{
@@ -234,11 +260,10 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Stored Procedure. Executes a stored procedure
*
- * @access public
- * @param package package stored procedure is in
- * @param procedure stored procedure to execute
- * @param params array of parameters
- * @return array
+ * @param string package stored procedure is in
+ * @param string stored procedure to execute
+ * @param array parameters
+ * @return object
*
* params array keys
*
@@ -287,10 +312,9 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Bind parameters
*
- * @access private
- * @return none
+ * @return void
*/
- private function _bind_params($params)
+ protected function _bind_params($params)
{
if ( ! is_array($params) OR ! is_resource($this->stmt_id))
{
@@ -316,7 +340,6 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -346,7 +369,6 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
public function trans_commit()
@@ -372,7 +394,6 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
public function trans_rollback()
@@ -398,10 +419,9 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Escape String
*
- * @access public
- * @param string
+ * @param string
* @param bool whether or not the string will be used in a LIKE condition
- * @return string
+ * @return string
*/
public function escape_str($str, $like = FALSE)
{
@@ -415,15 +435,14 @@ class CI_DB_oci8_driver extends CI_DB {
return $str;
}
- $str = remove_invisible_characters($str);
- $str = str_replace("'", "''", $str);
+ $str = str_replace("'", "''", remove_invisible_characters($str));
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -434,8 +453,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
public function affected_rows()
{
@@ -447,8 +465,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
public function insert_id()
{
@@ -464,9 +481,8 @@ class CI_DB_oci8_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
- * @param string
- * @return string
+ * @param string
+ * @return string
*/
public function count_all($table = '')
{
@@ -475,8 +491,7 @@ class CI_DB_oci8_driver extends CI_DB {
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query == FALSE)
{
return 0;
@@ -494,8 +509,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access protected
- * @param boolean
+ * @param bool
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -517,9 +531,8 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access protected
- * @param string the table name
- * @return string
+ * @param string the table name
+ * @return string
*/
protected function _list_columns($table = '')
{
@@ -533,9 +546,8 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
- * @param string the table name
- * @return object
+ * @param string the table name
+ * @return string
*/
protected function _field_data($table)
{
@@ -545,31 +557,32 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access protected
- * @return string
- */
- protected function _error_message()
- {
- // If the error was during connection, no conn_id should be passed
- $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
- return $error['message'];
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access protected
- * @return integer
+ * @return array
*/
- protected function _error_number()
+ public function error()
{
- // Same as _error_message()
- $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
- return $error['code'];
+ /* oci_error() returns an array that already contains the
+ * 'code' and 'message' keys, so we can just return it.
+ */
+ if (is_resource($this->curs_id))
+ {
+ return oci_error($this->curs_id);
+ }
+ elseif (is_resource($this->stmt_id))
+ {
+ return oci_error($this->stmt_id);
+ }
+ elseif (is_resource($this->conn_id))
+ {
+ return oci_error($this->conn_id);
+ }
+
+ return oci_error();
}
// --------------------------------------------------------------------
@@ -579,11 +592,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access protected
* @param string
* @return string
*/
- protected function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -622,9 +634,8 @@ class CI_DB_oci8_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access protected
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
protected function _from_tables($tables)
{
@@ -643,11 +654,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
- * @return string
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
*/
protected function _insert($table, $keys, $values)
{
@@ -661,10 +671,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
- * @return string
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
*/
protected function _insert_batch($table, $keys, $values)
{
@@ -688,7 +698,6 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access protected
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -725,7 +734,6 @@ class CI_DB_oci8_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access protected
* @param string the table name
* @return string
*/
@@ -741,7 +749,6 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access protected
* @param string the table name
* @param array the where clause
* @param string the limit clause
@@ -775,11 +782,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access protected
- * @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
- * @return string
+ * @param string the sql query string
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
+ * @return string
*/
protected function _limit($sql, $limit, $offset)
{
@@ -802,19 +808,15 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access protected
- * @param resource
- * @return void
+ * @param resource
+ * @return void
*/
protected function _close($conn_id)
{
@oci_close($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_forge.php b/system/database/drivers/oci8/oci8_forge.php
index b4a24cdca..8285a29d2 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Oracle Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_oci8_forge extends CI_DB_forge {
/**
* Create database
*
- * @access public
* @param string the database name
* @return bool
*/
- function _create_database($name)
+ public function _create_database($name)
{
return FALSE;
}
@@ -53,11 +50,10 @@ class CI_DB_oci8_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
return FALSE;
}
@@ -67,15 +63,14 @@ class CI_DB_oci8_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -84,54 +79,27 @@ class CI_DB_oci8_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->db->_escape_identifiers($table).' (';
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE']
+ .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL')
+ .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : '');
}
// don't add a comma on the end of the last field
@@ -143,8 +111,8 @@ class CI_DB_oci8_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) . ")";
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
+ $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -153,20 +121,18 @@ class CI_DB_oci8_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")";
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -174,10 +140,9 @@ class CI_DB_oci8_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
return FALSE;
}
@@ -190,19 +155,18 @@ class CI_DB_oci8_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -228,7 +192,7 @@ class CI_DB_oci8_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -242,18 +206,15 @@ class CI_DB_oci8_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
-
}
/* End of file oci8_forge.php */
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index 0f69fa9ef..c3f775730 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* oci8 Result Class
*
@@ -38,9 +36,18 @@
*/
class CI_DB_oci8_result extends CI_DB_result {
- var $stmt_id;
- var $curs_id;
- var $limit_used;
+ public $stmt_id;
+ public $curs_id;
+ public $limit_used;
+
+ public function __construct(&$driver_object)
+ {
+ parent::__construct($driver_object);
+ $this->stmt_id = $driver_object->stmt_id;
+ $this->curs_id = $driver_object->curs_id;
+ $this->limit_used = $driver_object->limit_used;
+ $driver_object->stmt_id = FALSE;
+ }
/**
* Number of rows in the result set.
@@ -48,9 +55,7 @@ class CI_DB_oci8_result extends CI_DB_result {
* Oracle doesn't have a graceful way to retun the number of rows
* so we have to use what amounts to a hack.
*
- *
- * @access public
- * @return integer
+ * @return int
*/
public function num_rows()
{
@@ -73,8 +78,7 @@ class CI_DB_oci8_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
public function num_fields()
{
@@ -96,7 +100,6 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
public function list_fields()
@@ -116,8 +119,7 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
- * @return array
+ * @return array
*/
public function field_data()
{
@@ -140,7 +142,7 @@ class CI_DB_oci8_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
public function free_result()
{
@@ -158,8 +160,7 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access protected
- * @return array
+ * @return array
*/
protected function _fetch_assoc()
{
@@ -174,8 +175,7 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access protected
- * @return object
+ * @return object
*/
protected function _fetch_object()
{
@@ -188,8 +188,7 @@ class CI_DB_oci8_result extends CI_DB_result {
/**
* Query result. "array" version.
*
- * @access public
- * @return array
+ * @return array
*/
public function result_array()
{
@@ -212,11 +211,10 @@ class CI_DB_oci8_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access protected
* @return array
*/
protected function _data_seek($n = 0)
@@ -226,6 +224,5 @@ class CI_DB_oci8_result extends CI_DB_result {
}
-
/* End of file oci8_result.php */
-/* Location: ./system/database/drivers/oci8/oci8_result.php */
+/* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index d60f98bc4..e303fb6cb 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Oracle Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_oci8_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
* @return bool
*/
- function _list_databases()
+ public function _list_databases()
{
return FALSE;
}
@@ -54,11 +51,10 @@ class CI_DB_oci8_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
return FALSE; // Is this supported in Oracle?
}
@@ -70,11 +66,10 @@ class CI_DB_oci8_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
return FALSE; // Is this supported in Oracle?
}
@@ -84,15 +79,15 @@ class CI_DB_oci8_utility extends CI_DB_utility {
/**
* Oracle Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
}
+
}
/* End of file oci8_utility.php */
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 6ba39f0cd..ad773117f 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* ODBC Database Adapter Class
*
@@ -42,40 +40,44 @@
*/
class CI_DB_odbc_driver extends CI_DB {
- var $dbdriver = 'odbc';
+ public $dbdriver = 'odbc';
// the character used to excape - not necessary for ODBC
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " {escape '%s'} ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " {escape '%s'} ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword;
-
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword;
- function __construct($params)
+ public function __construct($params)
{
parent::__construct($params);
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+
+ // Legacy support for DSN in the hostname field
+ if ($this->dsn == '')
+ {
+ $this->dsn = $this->hostname;
+ }
}
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
- return @odbc_connect($this->hostname, $this->username, $this->password);
+ return @odbc_connect($this->dsn, $this->username, $this->password);
}
// --------------------------------------------------------------------
@@ -83,28 +85,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
- {
- return @odbc_pconnect($this->hostname, $this->username, $this->password);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
- */
- function reconnect()
+ public function db_pconnect()
{
- // not implemented in odbc
+ return @odbc_pconnect($this->dsn, $this->username, $this->password);
}
// --------------------------------------------------------------------
@@ -112,10 +97,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// Not needed for ODBC
return TRUE;
@@ -124,72 +108,24 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- // @todo - add support if needed
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Version number query string
- *
- * @access public
- * @return string
- */
- function _version()
- {
- return "SELECT version() AS ver";
- }
-
- // --------------------------------------------------------------------
-
- /**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
return @odbc_exec($this->conn_id, $sql);
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
- {
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -215,10 +151,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -241,10 +176,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -267,12 +201,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -290,9 +223,9 @@ class CI_DB_odbc_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -303,10 +236,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @odbc_num_rows($this->conn_id);
}
@@ -316,12 +248,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return bool
*/
- function insert_id()
+ public function insert_id()
{
- return @odbc_insert_id($this->conn_id);
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -332,18 +263,17 @@ class CI_DB_odbc_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $this->query($this->_count_string . $this->protect_identifiers('numrows') . " FROM " . $this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
@@ -362,11 +292,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SHOW TABLES FROM `".$this->database."`";
@@ -386,11 +315,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SHOW COLUMNS FROM ".$table;
}
@@ -402,11 +330,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT TOP 1 FROM ".$table;
}
@@ -414,27 +341,16 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
- */
- function _error_message()
- {
- return odbc_errormsg($this->conn_id);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return odbc_error($this->conn_id);
+ return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
}
// --------------------------------------------------------------------
@@ -444,11 +360,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -487,11 +402,10 @@ class CI_DB_odbc_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -508,13 +422,12 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
@@ -526,7 +439,6 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -534,7 +446,7 @@ class CI_DB_odbc_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -564,11 +476,10 @@ class CI_DB_odbc_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return $this->_delete($table);
}
@@ -580,13 +491,12 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -614,13 +524,12 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
// Does ODBC doesn't use the LIMIT clause?
return $sql;
@@ -631,19 +540,15 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@odbc_close($conn_id);
}
-
}
-
-
/* End of file odbc_driver.php */
/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index e0ec687c8..486a8dd7f 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* ODBC Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _create_database()
+ public function _create_database()
{
// ODBC has no "create database" command since it's
// designed to connect to an existing database
@@ -59,11 +56,10 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
// ODBC has no "drop database" command since it's
// designed to connect to an existing database
@@ -79,15 +75,14 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -99,7 +94,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
$sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
@@ -112,7 +107,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
@@ -155,7 +150,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
@@ -165,11 +160,11 @@ class CI_DB_odbc_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
@@ -186,10 +181,9 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
// Not a supported ODBC feature
if ($this->db->db_debug)
@@ -207,19 +201,18 @@ class CI_DB_odbc_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -245,7 +238,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -260,18 +253,15 @@ class CI_DB_odbc_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
-
}
/* End of file odbc_forge.php */
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index ba660856e..30cc979ce 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* ODBC Result Class
*
@@ -38,15 +36,27 @@
*/
class CI_DB_odbc_result extends CI_DB_result {
+ public $num_rows;
+
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
- return @odbc_num_rows($this->result_id);
+ if (is_int($this->num_rows))
+ {
+ return $this->num_rows;
+ }
+
+ // Work-around for ODBC subdrivers that don't support num_rows()
+ if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
+ {
+ $this->num_rows = count($this->result_array());
+ }
+
+ return $this->num_rows;
}
// --------------------------------------------------------------------
@@ -54,10 +64,9 @@ class CI_DB_odbc_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @odbc_num_fields($this->result_id);
}
@@ -69,15 +78,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ $num_fields = $this->num_fields();
+
+ if ($num_fields > 0)
{
- $field_names[] = odbc_field_name($this->result_id, $i);
+ for ($i = 1; $i <= $num_fields; $i++)
+ {
+ $field_names[] = odbc_field_name($this->result_id, $i);
+ }
}
return $field_names;
@@ -90,22 +103,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
{
- $F = new stdClass();
- $F->name = odbc_field_name($this->result_id, $i);
- $F->type = odbc_field_type($this->result_id, $i);
- $F->max_length = odbc_field_len($this->result_id, $i);
- $F->primary_key = 0;
- $F->default = '';
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
+ $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
+ $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
}
return $retval;
@@ -116,9 +126,9 @@ class CI_DB_odbc_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -136,10 +146,9 @@ class CI_DB_odbc_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
- * @return array
+ * @return bool
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return FALSE;
}
@@ -151,12 +160,11 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
- if (function_exists('odbc_fetch_object'))
+ if (function_exists('odbc_fetch_array'))
{
return odbc_fetch_array($this->result_id);
}
@@ -173,10 +181,9 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
if (function_exists('odbc_fetch_object'))
{
@@ -188,6 +195,7 @@ class CI_DB_odbc_result extends CI_DB_result {
}
}
+ // --------------------------------------------------------------------
/**
* Result - object
@@ -195,21 +203,24 @@ class CI_DB_odbc_result extends CI_DB_result {
* subsititutes the odbc_fetch_object function when
* not available (odbc_fetch_object requires unixODBC)
*
- * @access private
* @return object
*/
- function _odbc_fetch_object(& $odbc_result) {
+ protected function _odbc_fetch_object(& $odbc_result)
+ {
$rs = array();
$rs_obj = FALSE;
- if (odbc_fetch_into($odbc_result, $rs)) {
- foreach ($rs as $k=>$v) {
- $field_name= odbc_field_name($odbc_result, $k+1);
+ if (odbc_fetch_into($odbc_result, $rs))
+ {
+ foreach ($rs as $k => $v)
+ {
+ $field_name = odbc_field_name($odbc_result, $k+1);
$rs_obj->$field_name = $v;
}
}
return $rs_obj;
}
+ // --------------------------------------------------------------------
/**
* Result - array
@@ -217,24 +228,95 @@ class CI_DB_odbc_result extends CI_DB_result {
* subsititutes the odbc_fetch_array function when
* not available (odbc_fetch_array requires unixODBC)
*
- * @access private
* @return array
*/
- function _odbc_fetch_array(& $odbc_result) {
+ protected function _odbc_fetch_array(& $odbc_result)
+ {
$rs = array();
$rs_assoc = FALSE;
- if (odbc_fetch_into($odbc_result, $rs)) {
- $rs_assoc=array();
- foreach ($rs as $k=>$v) {
- $field_name= odbc_field_name($odbc_result, $k+1);
+ if (odbc_fetch_into($odbc_result, $rs))
+ {
+ $rs_assoc = array();
+ foreach ($rs as $k => $v)
+ {
+ $field_name = odbc_field_name($odbc_result, $k+1);
$rs_assoc[$field_name] = $v;
}
}
return $rs_assoc;
}
-}
+ // --------------------------------------------------------------------
+
+ /**
+ * Query result. Array version.
+ *
+ * @return array
+ */
+ public function result_array()
+ {
+ if (count($this->result_array) > 0)
+ {
+ return $this->result_array;
+ }
+ elseif (($c = count($this->result_object)) > 0)
+ {
+ for ($i = 0; $i < $c; $i++)
+ {
+ $this->result_array[$i] = (array) $this->result_object[$i];
+ }
+ }
+ elseif ($this->result_id === FALSE)
+ {
+ return array();
+ }
+ else
+ {
+ while ($row = $this->_fetch_assoc())
+ {
+ $this->result_array[] = $row;
+ }
+ }
+
+ return $this->result_array;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Query result. Object version.
+ *
+ * @return array
+ */
+ public function result_object()
+ {
+ if (count($this->result_object) > 0)
+ {
+ return $this->result_object;
+ }
+ elseif (($c = count($this->result_array)) > 0)
+ {
+ for ($i = 0; $i < $c; $i++)
+ {
+ $this->result_object[$i] = (object) $this->result_array[$i];
+ }
+ }
+ elseif ($this->result_id === FALSE)
+ {
+ return array();
+ }
+ else
+ {
+ while ($row = $this->_fetch_object())
+ {
+ $this->result_object[] = $row;
+ }
+ }
+
+ return $this->result_object;
+ }
+}
/* End of file odbc_result.php */
/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index bae3fe853..65445e96c 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* ODBC Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_odbc_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
* @return bool
*/
- function _list_databases()
+ public function _list_databases()
{
// Not sure if ODBC lets you list all databases...
if ($this->db->db_debug)
@@ -59,11 +56,10 @@ class CI_DB_odbc_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
// Not a supported ODBC feature
if ($this->db->db_debug)
@@ -80,11 +76,10 @@ class CI_DB_odbc_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
// Not a supported ODBC feature
if ($this->db->db_debug)
@@ -99,11 +94,10 @@ class CI_DB_odbc_utility extends CI_DB_utility {
/**
* ODBC Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 4f4f44ba7..19338e30f 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* PDO Database Adapter Class
*
@@ -42,44 +40,51 @@
*/
class CI_DB_pdo_driver extends CI_DB {
- var $dbdriver = 'pdo';
+ public $dbdriver = 'pdo';
// the character used to excape - not necessary for PDO
- var $_escape_char = '';
- var $_like_escape_str;
- var $_like_escape_chr;
-
+ protected $_escape_char = '';
+
+ // clause and character used for LIKE escape sequences
+ protected $_like_escape_str;
+ protected $_like_escape_chr;
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword;
-
- var $options = array();
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword;
+
+ // need to track the pdo driver and options
+ public $pdodriver;
+ public $options = array();
- function __construct($params)
+ public function __construct($params)
{
parent::__construct($params);
-
+
+ if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2)
+ {
+ // If there is a minimum valid dsn string pattern found, we're done
+ // This is for general PDO users, who tend to have a full DSN string.
+ $this->pdodriver = end($match);
+ }
+ else
+ {
+ // Try to build a complete DSN string from params
+ $this->_connect_string($params);
+ }
+
// clause and character used for LIKE escape sequences
- if (strpos($this->hostname, 'mysql') !== FALSE)
+ // this one depends on the driver being used
+ if ($this->pdodriver == 'mysql')
{
$this->_like_escape_str = '';
$this->_like_escape_chr = '';
-
- //Prior to this version, the charset can't be set in the dsn
- if(is_php('5.3.6'))
- {
- $this->hostname .= ";charset={$this->char_set}";
- }
-
- //Set the charset with the connection options
- $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
}
- else if (strpos($this->hostname, 'odbc') !== FALSE)
+ elseif ($this->pdodriver == 'odbc')
{
$this->_like_escape_str = " {escape '%s'} ";
$this->_like_escape_chr = '!';
@@ -89,28 +94,106 @@ class CI_DB_pdo_driver extends CI_DB {
$this->_like_escape_str = " ESCAPE '%s' ";
$this->_like_escape_chr = '!';
}
-
- if (strpos($this->hostname, 'sqlite') === FALSE)
+
+ $this->trans_enabled = FALSE;
+ $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ }
+
+ /**
+ * Connection String
+ *
+ * @param array
+ * @return void
+ */
+ protected function _connect_string($params)
+ {
+ if (strpos($this->hostname, ':'))
{
- $this->hostname .= ";dbname=".$this->database;
+ // hostname generally would have this prototype
+ // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);';
+ // We need to get the prefix (pdodriver used by PDO).
+ $dsnarray = explode(':', $this->hostname);
+ $this->pdodriver = $dsnarray[0];
+
+ // End dsn with a semicolon for extra backward compability
+ // if database property was not empty.
+ if ( ! empty($this->database))
+ {
+ $this->dsn .= rtrim($this->hostname, ';').';';
+ }
}
-
- $this->trans_enabled = FALSE;
+ else
+ {
+ // Invalid DSN, display an error
+ if ( ! array_key_exists('pdodriver', $params))
+ {
+ show_error('Invalid DB Connection String for PDO');
+ }
- $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ // Assuming that the following DSN string format is used:
+ // $dsn = 'pdo://username:password@hostname:port/database?pdodriver=pgsql';
+ $this->dsn = $this->pdodriver.':';
+
+ // Add hostname to the DSN for databases that need it
+ if ( ! empty($this->hostname)
+ && strpos($this->hostname, ':') === FALSE
+ && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'host='.$this->hostname.';';
+ }
+
+ // Add a port to the DSN for databases that can use it
+ if ( ! empty($this->port) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'ibm', 'cubrid')))
+ {
+ $this->dsn .= 'port='.$this->port.';';
+ }
+ }
+
+ // Add the database name to the DSN, if needed
+ if (stripos($this->dsn, 'dbname') === FALSE
+ && in_array($this->pdodriver, array('4D', 'pgsql', 'mysql', 'firebird', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'dbname='.$this->database.';';
+ }
+ elseif (stripos($this->dsn, 'database') === FALSE && in_array($this->pdodriver, array('ibm', 'sqlsrv')))
+ {
+ if (stripos($this->dsn, 'dsn') === FALSE)
+ {
+ $this->dsn .= 'database='.$this->database.';';
+ }
+ }
+ elseif ($this->pdodriver === 'sqlite' && $this->dsn === 'sqlite:')
+ {
+ if ($this->database !== ':memory')
+ {
+ if ( ! file_exists($this->database))
+ {
+ show_error('Invalid DB Connection string for PDO SQLite');
+ }
+
+ $this->dsn .= (strpos($this->database, DIRECTORY_SEPARATOR) !== 0) ? DIRECTORY_SEPARATOR : '';
+ }
+
+ $this->dsn .= $this->database;
+ }
+
+ // Add charset to the DSN, if needed
+ if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci')))
+ {
+ $this->dsn .= 'charset='.$this->char_set.';';
+ }
}
/**
* Non-persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_connect()
+ public function db_connect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
-
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+
+ return $this->pdo_connect();
}
// --------------------------------------------------------------------
@@ -118,78 +201,74 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_pconnect()
+ public function db_pconnect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
- $this->options['PDO::ATTR_PERSISTENT'] = TRUE;
-
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+ $this->options[PDO::ATTR_PERSISTENT] = TRUE;
+
+ return $this->pdo_connect();
}
// --------------------------------------------------------------------
/**
- * Reconnect
+ * PDO connection
*
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
+ * @return object
*/
- function reconnect()
+ public function pdo_connect()
{
- if ($this->db->db_debug)
+ // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php
+ if ($this->pdodriver === 'mysql' && ! is_php('5.3.6'))
{
- return $this->db->display_error('db_unsuported_feature');
+ $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'";
}
- return FALSE;
- }
- // --------------------------------------------------------------------
+ // Connecting...
+ try
+ {
+ $db = new PDO($this->dsn, $this->username, $this->password, $this->options);
+ }
+ catch (PDOException $e)
+ {
+ if ($this->db_debug && empty($this->failover))
+ {
+ $this->display_error($e->getMessage(), '', TRUE);
+ }
- /**
- * Select the database
- *
- * @access private called by the base class
- * @return resource
- */
- function db_select()
- {
- // Not needed for PDO
- return TRUE;
+ return FALSE;
+ }
+
+ return $db;
}
// --------------------------------------------------------------------
/**
- * Set client character set
+ * Select the database
*
- * @access public
- * @param string
- * @param string
* @return resource
*/
- function db_set_charset($charset, $collation)
+ public function db_select()
{
- // @todo - add support if needed
+ // Not needed for PDO
return TRUE;
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Database version number
*
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION);
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
}
// --------------------------------------------------------------------
@@ -197,15 +276,15 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return object
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
$sql = $this->_prep_query($sql);
+
$result_id = $this->conn_id->query($sql);
-
+
if (is_object($result_id))
{
$this->affect_rows = $result_id->rowCount();
@@ -214,7 +293,7 @@ class CI_DB_pdo_driver extends CI_DB {
{
$this->affect_rows = 0;
}
-
+
return $result_id;
}
@@ -225,12 +304,22 @@ class CI_DB_pdo_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
+ if ($this->pdodriver === 'pgsql')
+ {
+ // Change the backtick(s) for Postgre
+ $sql = str_replace('`', '"', $sql);
+ }
+ elseif ($this->pdodriver === 'sqlite')
+ {
+ // Change the backtick(s) for SQLite
+ $sql = str_replace('`', '', $sql);
+ }
+
return $sql;
}
@@ -239,10 +328,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -268,10 +356,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -285,6 +372,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn->commit();
+
return $ret;
}
@@ -293,10 +381,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -310,6 +397,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn_id->rollBack();
+
return $ret;
}
@@ -318,12 +406,11 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -334,22 +421,22 @@ class CI_DB_pdo_driver extends CI_DB {
return $str;
}
-
+
//Escape the string
$str = $this->conn_id->quote($str);
-
+
//If there are duplicated quotes, trim them away
if (strpos($str, "'") === 0)
{
$str = substr($str, 1, -1);
}
-
+
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -360,10 +447,9 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return $this->affect_rows;
}
@@ -372,31 +458,19 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
- *
- * @access public
- * @return integer
+ *
+ * @return int
*/
- function insert_id($name=NULL)
+ public function insert_id($name = NULL)
{
- //Convenience method for postgres insertid
- if (strpos($this->hostname, 'pgsql') !== FALSE)
- {
- $v = $this->_version();
-
- $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
-
- if ($table == NULL && $v >= '8.1')
- {
- $sql='SELECT LASTVAL() as ins_id';
- }
- $query = $this->query($sql);
- $row = $query->row();
- return $row->ins_id;
- }
- else
+ if ($this->pdodriver === 'pgsql' && $name === NULL && $this->version() >= '8.1')
{
- return $this->conn_id->lastInsertId($name);
+ $query = $this->query('SELECT LASTVAL() AS ins_id');
+ $query = $query->row();
+ return $query->ins_id;
}
+
+ return $this->conn_id->lastInsertId($name);
}
// --------------------------------------------------------------------
@@ -407,7 +481,6 @@ class CI_DB_pdo_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
@@ -418,7 +491,8 @@ class CI_DB_pdo_driver extends CI_DB {
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $sql = $this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
+ $query = $this->query($sql);
if ($query->num_rows() == 0)
{
@@ -427,6 +501,7 @@ class CI_DB_pdo_driver extends CI_DB {
$row = $query->row();
$this->_reset_select();
+
return (int) $row->numrows;
}
@@ -437,18 +512,29 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM `".$this->database."`";
+ if ($this->pdodriver == 'pgsql')
+ {
+ // Analog function to show all tables in postgre
+ $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'";
+ }
+ elseif ($this->pdodriver == 'sqlite')
+ {
+ // Analog function to show all tables in sqlite
+ $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'";
+ }
+ else
+ {
+ $sql = "SHOW TABLES FROM `".$this->database."`";
+ }
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
- //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
- return FALSE; // not currently supported
+ return FALSE;
}
return $sql;
@@ -461,13 +547,12 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$table;
+ return 'SHOW COLUMNS FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
@@ -477,40 +562,57 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$table;
+ if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql')
+ {
+ // Analog function for mysql and postgre
+ return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1';
+ }
+ elseif ($this->pdodriver == 'oci')
+ {
+ // Analog function for oci
+ return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1';
+ }
+ elseif ($this->pdodriver == 'sqlite')
+ {
+ // Analog function for sqlite
+ return 'PRAGMA table_info('.$this->_from_tables($table).')';
+ }
+
+ return 'SELECT TOP 1 FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
*/
- function _error_message()
+ public function error()
{
- $error_array = $this->conn_id->errorInfo();
- return $error_array[2];
- }
+ $error = array('code' => '00000', 'message' => '');
+ $pdo_error = $this->conn_id->errorInfo();
- // --------------------------------------------------------------------
+ if (empty($pdo_error[0]))
+ {
+ return $error;
+ }
- /**
- * The error message number
- *
- * @access private
- * @return integer
- */
- function _error_number()
- {
- return $this->conn_id->errorCode();
+ $error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0];
+ if (isset($pdo_error[2]))
+ {
+ $error['message'] = $pdo_error[2];
+ }
+
+ return $error;
}
// --------------------------------------------------------------------
@@ -520,11 +622,10 @@ class CI_DB_pdo_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -544,8 +645,8 @@ class CI_DB_pdo_driver extends CI_DB {
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
-
+ $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ $str .= $this->_escape_char;
}
else
{
@@ -564,18 +665,17 @@ class CI_DB_pdo_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
- return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')';
+ return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
@@ -585,17 +685,16 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
-
+
// --------------------------------------------------------------------
/**
@@ -603,15 +702,14 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
- * @return string
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -621,7 +719,6 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -629,26 +726,23 @@ class CI_DB_pdo_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
+ $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+ $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : '';
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr);
+ $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : '';
$sql .= $orderby.$limit;
return $sql;
}
-
+
// --------------------------------------------------------------------
/**
@@ -656,16 +750,15 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
- $ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
+ $ids = array();
+ $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : '';
foreach ($values as $key => $val)
{
@@ -680,12 +773,13 @@ class CI_DB_pdo_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET ';
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
+
foreach ($v as $row)
{
$cases .= $row."\n";
@@ -695,13 +789,11 @@ class CI_DB_pdo_driver extends CI_DB {
}
$sql .= substr($cases, 0, -2);
-
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
return $sql;
}
-
// --------------------------------------------------------------------
/**
@@ -711,11 +803,10 @@ class CI_DB_pdo_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return $this->_delete($table);
}
@@ -727,31 +818,31 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
+ $conditions = "\nWHERE ";
$conditions .= implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
$conditions .= " AND ";
}
+
$conditions .= implode("\n", $like);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$this->_from_tables($table).$conditions.$limit;
}
// --------------------------------------------------------------------
@@ -761,36 +852,24 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
+ if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite')
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
+ $offset = ($offset == 0) ? '' : $offset.', ';
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.'LIMIT '.$offset.$limit;
}
else
{
- $sql .= "LIMIT ".$limit;
+ $sql .= 'LIMIT '.$limit;
+ $sql .= ($offset > 0) ? ' OFFSET '.$offset : '';
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
return $sql;
}
}
@@ -800,19 +879,15 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
$this->conn_id = null;
}
-
}
-
-
/* End of file 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_forge.php b/system/database/drivers/pdo/pdo_forge.php
index 076415928..6bff3542f 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* PDO Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_pdo_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _create_database()
+ public function _create_database()
{
// PDO has no "create database" command since it's
// designed to connect to an existing database
@@ -59,11 +56,10 @@ class CI_DB_pdo_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
// PDO has no "drop database" command since it's
// designed to connect to an existing database
@@ -79,15 +75,14 @@ class CI_DB_pdo_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -96,7 +91,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= '`'.$this->db->_escape_identifiers($table).'` (';
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -111,14 +106,19 @@ class CI_DB_pdo_forge extends CI_DB_forge {
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
+ $numeric = array('SERIAL', 'INTEGER');
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
- $sql .= '('.$attributes['CONSTRAINT'].')';
+ // Exception for Postgre numeric which not too happy with constraint within those type
+ if ( ! ($this->db->pdodriver == 'pgsql' && in_array($attributes['TYPE'], $numeric)))
+ {
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
@@ -155,7 +155,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
@@ -165,11 +165,11 @@ class CI_DB_pdo_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
@@ -186,10 +186,9 @@ class CI_DB_pdo_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
@@ -207,19 +206,18 @@ class CI_DB_pdo_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE `'.$this->db->protect_identifiers($table).'` '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -245,7 +243,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -260,18 +258,15 @@ class CI_DB_pdo_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
-
}
/* End of file pdo_forge.php */
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 6b523b001..5bbd85d75 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* PDO Result Class
*
@@ -39,14 +37,74 @@
class CI_DB_pdo_result extends CI_DB_result {
/**
+ * @var bool Hold the flag whether a result handler already fetched before
+ */
+ protected $is_fetched = FALSE;
+
+ /**
+ * @var mixed Hold the fetched assoc array of a result handler
+ */
+ protected $result_assoc;
+
+ /**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
- return $this->result_id->rowCount();
+ if (empty($this->result_id) OR ! is_object($this->result_id))
+ {
+ // invalid result handler
+ return 0;
+ }
+ elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0)
+ {
+ // If rowCount return something, we're done.
+ return $num_rows;
+ }
+
+ // Fetch the result, instead perform another extra query
+ return ($this->is_fetched && is_array($this->result_assoc)) ? count($this->result_assoc) : count($this->result_assoc());
+ }
+
+ /**
+ * Fetch the result handler
+ *
+ * @return mixed
+ */
+ public function result_assoc()
+ {
+ // If the result already fetched before, use that one
+ if (count($this->result_array) > 0 OR $this->is_fetched)
+ {
+ return $this->result_array();
+ }
+
+ // Define the output
+ $output = array('assoc', 'object');
+
+ // Fetch the result
+ foreach ($output as $type)
+ {
+ // Define the method and handler
+ $res_method = '_fetch_'.$type;
+ $res_handler = 'result_'.$type;
+
+ $this->$res_handler = array();
+ $this->_data_seek(0);
+
+ while ($row = $this->$res_method())
+ {
+ $this->{$res_handler}[] = $row;
+ }
+ }
+
+ // Save this as buffer and marked the fetch flag
+ $this->result_array = $this->result_assoc;
+ $this->is_fetched = TRUE;
+
+ return $this->result_assoc;
}
// --------------------------------------------------------------------
@@ -54,10 +112,9 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return $this->result_id->columnCount();
}
@@ -69,15 +126,15 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
- * @return array
+ * @return bool
*/
- function list_fields()
+ public function list_fields()
{
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
@@ -88,20 +145,58 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$data = array();
-
+
try
{
- for($i = 0; $i < $this->num_fields(); $i++)
+ if (strpos($this->result_id->queryString, 'PRAGMA') !== FALSE)
{
- $data[] = $this->result_id->getColumnMeta($i);
+ foreach ($this->result_array() as $field)
+ {
+ preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field['type'], $matches);
+
+ $F = new stdClass();
+ $F->name = $field['name'];
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = NULL;
+ $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
+ $F->primary_key = (int) $field['pk'];
+ $F->pdo_type = NULL;
+
+ $data[] = $F;
+ }
+ }
+ else
+ {
+ for($i = 0, $max = $this->num_fields(); $i < $max; $i++)
+ {
+ $field = $this->result_id->getColumnMeta($i);
+
+ $F = new stdClass();
+ $F->name = $field['name'];
+ $F->type = $field['native_type'];
+ $F->default = NULL;
+ $F->pdo_type = $field['pdo_type'];
+
+ if ($field['precision'] < 0)
+ {
+ $F->max_length = NULL;
+ $F->primary_key = 0;
+ }
+ else
+ {
+ $F->max_length = ($field['len'] > 255) ? 0 : $field['len'];
+ $F->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags']));
+ }
+
+ $data[] = $F;
+ }
}
-
+
return $data;
}
catch (Exception $e)
@@ -110,6 +205,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
}
@@ -119,9 +215,9 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_object($this->result_id))
{
@@ -134,14 +230,13 @@ class CI_DB_pdo_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
- * @return array
+ * @return bool
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return FALSE;
}
@@ -153,10 +248,9 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return $this->result_id->fetch(PDO::FETCH_ASSOC);
}
@@ -168,16 +262,14 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
- {
+ protected function _fetch_object()
+ {
return $this->result_id->fetchObject();
}
}
-
/* End of file pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php
index 971ec8803..86c798397 100644
--- a/system/database/drivers/pdo/pdo_utility.php
+++ b/system/database/drivers/pdo/pdo_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* PDO Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_pdo_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
* @return bool
*/
- function _list_databases()
+ public function _list_databases()
{
// Not sure if PDO lets you list all databases...
if ($this->db->db_debug)
@@ -59,11 +56,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
@@ -80,11 +76,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
@@ -99,11 +94,10 @@ class CI_DB_pdo_utility extends CI_DB_utility {
/**
* PDO Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 42329bded..3e2d05ce8 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Postgre Database Adapter Class
*
@@ -42,47 +40,81 @@
*/
class CI_DB_postgre_driver extends CI_DB {
- var $dbdriver = 'postgre';
+ public $dbdriver = 'postgre';
- var $_escape_char = '"';
+ protected $_escape_char = '"';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " ESCAPE '%s' ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' RANDOM()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RANDOM()'; // database specific random keyword
/**
- * Connection String
+ * Constructor
*
- * @access private
- * @return string
+ * Creates a DSN string to be used for db_connect() and db_pconnect()
+ *
+ * @return void
*/
- function _connect_string()
+ public function __construct($params)
{
- $components = array(
- 'hostname' => 'host',
- 'port' => 'port',
- 'database' => 'dbname',
- 'username' => 'user',
- 'password' => 'password'
- );
-
- $connect_string = "";
- foreach ($components as $key => $val)
+ parent::__construct($params);
+
+ if ( ! empty($this->dsn))
+ {
+ return;
+ }
+
+ $this->dsn === '' OR $this->dsn = '';
+
+ if (strpos($this->hostname, '/') !== FALSE)
+ {
+ // If UNIX sockets are used, we shouldn't set a port
+ $this->port = '';
+ }
+
+ $this->hostname === '' OR $this->dsn = 'host='.$this->hostname;
+
+ if ( ! empty($this->port) && ctype_digit($this->port))
+ {
+ $this->dsn .= 'host='.$this->port.' ';
+ }
+
+ if ($this->username !== '')
+ {
+ $this->dsn .= 'username='.$this->username.' ';
+
+ /* An empty password is valid!
+ *
+ * $db['password'] = NULL must be done in order to ignore it.
+ */
+ $this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
+ }
+
+ $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
+
+ /* We don't have these options as elements in our standard configuration
+ * array, but they might be set by parse_url() if the configuration was
+ * provided via string. Example:
+ *
+ * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
+ */
+ foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
{
- if (isset($this->$key) && $this->$key != '')
+ if (isset($this->$key) && is_string($this->key) && $this->key !== '')
{
- $connect_string .= " $val=".$this->$key;
+ $this->dsn .= $key."='".$this->key."' ";
}
}
- return trim($connect_string);
+
+ $this->dsn = rtrim($this->dsn);
}
// --------------------------------------------------------------------
@@ -90,12 +122,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
- return @pg_connect($this->_connect_string());
+ return @pg_connect($this->dsn);
}
// --------------------------------------------------------------------
@@ -103,12 +134,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return @pg_pconnect($this->_connect_string());
+ return @pg_pconnect($this->dsn);
}
// --------------------------------------------------------------------
@@ -119,10 +149,9 @@ class CI_DB_postgre_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (pg_ping($this->conn_id) === FALSE)
{
@@ -135,10 +164,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// Not needed for Postgre so we'll return TRUE
return TRUE;
@@ -149,28 +177,41 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
- * @param string
- * @param string
- * @return resource
+ * @param string
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ protected function _db_set_charset($charset)
{
- // @todo - add support if needed
- return TRUE;
+ return (pg_set_client_encoding($this->conn_id, $charset) === 0);
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Database version number
*
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- return "SELECT version() AS ver";
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+
+ if (($pg_version = pg_version($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ /* If PHP was compiled with PostgreSQL lib versions earlier
+ * than 7.4, pg_version() won't return the server version
+ * and so we'll have to fall back to running a query in
+ * order to get it.
+ */
+ return isset($pg_version['server'])
+ ? $this->data_cache['version'] = $pg_version['server']
+ : parent::version();
}
// --------------------------------------------------------------------
@@ -178,49 +219,25 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
return @pg_query($this->conn_id, $sql);
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
- {
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -228,9 +245,9 @@ class CI_DB_postgre_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
- return @pg_exec($this->conn_id, "begin");
+ return @pg_query($this->conn_id, 'BEGIN');
}
// --------------------------------------------------------------------
@@ -238,23 +255,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- return @pg_exec($this->conn_id, "commit");
+ return @pg_query($this->conn_id, 'COMMIT');
}
// --------------------------------------------------------------------
@@ -262,23 +273,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- return @pg_exec($this->conn_id, "rollback");
+ return @pg_query($this->conn_id, 'ROLLBACK');
}
// --------------------------------------------------------------------
@@ -286,12 +291,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -308,9 +312,9 @@ class CI_DB_postgre_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -321,10 +325,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @pg_affected_rows($this->result_id);
}
@@ -334,13 +337,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return string
*/
- function insert_id()
+ public function insert_id()
{
- $v = $this->_version();
- $v = $v['server'];
+ $v = $this->version();
$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
$column = func_num_args() > 1 ? func_get_arg(1) : NULL;
@@ -378,19 +379,17 @@ class CI_DB_postgre_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
@@ -408,11 +407,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
@@ -431,11 +429,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
}
@@ -447,11 +444,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
@@ -459,27 +455,16 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
- */
- function _error_message()
- {
- return pg_last_error($this->conn_id);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return '';
+ return array('code' => '', 'message' => pg_last_error($this->conn_id));
}
// --------------------------------------------------------------------
@@ -489,11 +474,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -532,11 +516,10 @@ class CI_DB_postgre_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -553,13 +536,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
@@ -571,13 +553,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
}
@@ -589,7 +570,6 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -597,23 +577,17 @@ class CI_DB_postgre_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
$sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
- $sql .= $orderby.$limit;
-
return $sql;
}
@@ -626,11 +600,10 @@ class CI_DB_postgre_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return "TRUNCATE ".$table;
}
@@ -642,13 +615,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -664,9 +636,7 @@ class CI_DB_postgre_driver extends CI_DB {
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return "DELETE FROM ".$table.$conditions;
}
// --------------------------------------------------------------------
@@ -675,13 +645,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
$sql .= "LIMIT ".$limit;
@@ -698,18 +667,15 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@pg_close($conn_id);
}
-
}
-
/* End of file postgre_driver.php */
/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 756fd347a..a72449820 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Postgre Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _create_database($name)
+ public function _create_database($name)
{
return "CREATE DATABASE ".$name;
}
@@ -53,29 +50,28 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
return "DROP DATABASE ".$name;
}
// --------------------------------------------------------------------
-
+
/**
* Process Fields
*
* @param mixed the fields
* @return string
*/
- function _process_fields($fields, $primary_keys=array())
+ protected function _process_fields($fields, $primary_keys=array())
{
$sql = '';
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
@@ -88,7 +84,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE);
@@ -168,7 +164,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= ',';
}
}
-
+
return $sql;
}
@@ -177,15 +173,14 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -203,10 +198,10 @@ class CI_DB_postgre_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- // Something seems to break when passing an array to _protect_identifiers()
+ // Something seems to break when passing an array to protect_identifiers()
foreach ($primary_keys as $index => $key)
{
- $primary_keys[$index] = $this->db->_protect_identifiers($key);
+ $primary_keys[$index] = $this->db->protect_identifiers($key);
}
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
@@ -220,11 +215,11 @@ class CI_DB_postgre_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
foreach ($key as $field)
@@ -241,8 +236,10 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Drop Table
+ *
+ * @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE";
}
@@ -255,7 +252,6 @@ class CI_DB_postgre_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
@@ -263,23 +259,23 @@ class CI_DB_postgre_forge extends CI_DB_forge {
* @param string the default value
* @param boolean should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
$sql .= $this->_process_fields($fields);
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -292,15 +288,13 @@ class CI_DB_postgre_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 9161bf955..8b22564b3 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Postgres Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @pg_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @pg_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
for ($i = 0; $i < $this->num_fields(); $i++)
@@ -90,10 +85,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
for ($i = 0; $i < $this->num_fields(); $i++)
@@ -116,9 +110,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -132,14 +126,13 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return pg_result_seek($this->result_id, $n);
}
@@ -151,10 +144,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return pg_fetch_assoc($this->result_id);
}
@@ -166,16 +158,14 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return pg_fetch_object($this->result_id);
}
}
-
/* End of file postgre_result.php */
/* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index dffd8c549..cf29201ff 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Postgre Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_postgre_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SELECT datname FROM pg_database";
+ return 'SELECT datname FROM pg_database';
}
// --------------------------------------------------------------------
@@ -52,15 +49,12 @@ class CI_DB_postgre_utility extends CI_DB_utility {
/**
* Optimize table query
*
- * Is table optimization supported in Postgre?
- *
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return FALSE;
+ return 'REINDEX TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -68,13 +62,10 @@ class CI_DB_postgre_utility extends CI_DB_utility {
/**
* Repair table query
*
- * Are table repairs supported in Postgre?
- *
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
return FALSE;
}
@@ -84,17 +75,15 @@ class CI_DB_postgre_utility extends CI_DB_utility {
/**
* Postgre Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
}
}
-
/* End of file postgre_utility.php */
/* Location: ./system/database/drivers/postgre/postgre_utility.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 28c3caecd..102c79bb3 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,10 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
-
-
/**
* SQLite Database Adapter Class
*
@@ -44,30 +40,29 @@
*/
class CI_DB_sqlite_driver extends CI_DB {
- var $dbdriver = 'sqlite';
+ public $dbdriver = 'sqlite';
// The character used to escape with - not needed for SQLite
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " ESCAPE '%s' ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' Random()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' Random()'; // database specific random keyword
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error))
{
@@ -89,10 +84,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error))
{
@@ -112,59 +106,27 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
- */
- function reconnect()
- {
- // not implemented in SQLite
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
- * @access private called by the base class
- * @return resource
- */
- function db_select()
- {
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
* @return resource
*/
- function db_set_charset($charset, $collation)
+ public function db_select()
{
- // @todo - add support if needed
return TRUE;
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Database version number
*
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- return sqlite_libversion();
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = sqlite_libversion();
}
// --------------------------------------------------------------------
@@ -172,41 +134,22 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
return @sqlite_query($this->conn_id, $sql);
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
- {
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -233,10 +176,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -258,10 +200,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -283,12 +224,11 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -305,9 +245,9 @@ class CI_DB_sqlite_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -318,10 +258,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return sqlite_changes($this->conn_id);
}
@@ -331,10 +270,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @sqlite_last_insert_rowid($this->conn_id);
}
@@ -347,19 +285,17 @@ class CI_DB_sqlite_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
@@ -377,11 +313,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT name from sqlite_master WHERE type='table'";
@@ -399,11 +334,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
- * @return string
+ * @return bool
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
// Not supported
return FALSE;
@@ -416,11 +350,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
@@ -428,27 +361,18 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
- */
- function _error_message()
- {
- return sqlite_error_string(sqlite_last_error($this->conn_id));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return sqlite_last_error($this->conn_id);
+ $error = array('code' => sqlite_last_error($this->conn_id));
+ $error['message'] = sqlite_error_string($error['code']);
+ return $error;
}
// --------------------------------------------------------------------
@@ -458,11 +382,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -501,11 +424,10 @@ class CI_DB_sqlite_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -522,13 +444,12 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
@@ -540,7 +461,6 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -548,7 +468,7 @@ class CI_DB_sqlite_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -578,11 +498,10 @@ class CI_DB_sqlite_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return $this->_delete($table);
}
@@ -594,13 +513,12 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -628,13 +546,12 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
if ($offset == 0)
{
@@ -653,18 +570,15 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@sqlite_close($conn_id);
}
-
}
-
/* End of file sqlite_driver.php */
/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 2b723be0b..068a556ed 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLite Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Create database
*
- * @access public
* @param string the database name
* @return bool
*/
- function _create_database()
+ public function _create_database()
{
// In SQLite, a database is created when you connect to the database.
// We'll return TRUE so that an error isn't generated
@@ -55,11 +52,10 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database))
{
@@ -71,25 +67,25 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
}
return TRUE;
}
+
// --------------------------------------------------------------------
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
// IF NOT EXISTS added to SQLite in 3.3.0
- if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE)
+ if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE)
{
$sql .= 'IF NOT EXISTS ';
}
@@ -110,7 +106,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
@@ -153,7 +149,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
@@ -163,11 +159,11 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
$sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
@@ -184,12 +180,9 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Drop Table
*
- * Unsupported feature in SQLite
- *
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
if ($this->db->db_debug)
{
@@ -206,19 +199,18 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -247,7 +239,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -261,16 +253,15 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
+
}
/* End of file sqlite_forge.php */
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 74c0dc549..b002aeff1 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLite Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @sqlite_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @sqlite_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
for ($i = 0; $i < $this->num_fields(); $i++)
@@ -90,10 +85,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
for ($i = 0; $i < $this->num_fields(); $i++)
@@ -116,9 +110,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
// Not implemented in SQLite
}
@@ -128,14 +122,13 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return sqlite_seek($this->result_id, $n);
}
@@ -147,10 +140,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return sqlite_fetch_array($this->result_id);
}
@@ -162,10 +154,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
if (function_exists('sqlite_fetch_object'))
{
@@ -186,6 +177,5 @@ class CI_DB_sqlite_result extends CI_DB_result {
}
-
/* End of file sqlite_result.php */
/* Location: ./system/database/drivers/sqlite/sqlite_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index f00687e38..c07004c54 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLite Utility Class
*
@@ -40,20 +38,15 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
* List databases
*
* I don't believe you can do a database listing with SQLite
- * since each database is its own file. I suppose we could
+ * since each database is its own file. I suppose we could
* try reading a directory looking for SQLite files, but
* that doesn't seem like a terribly good idea
*
- * @access private
* @return bool
*/
- function _list_databases()
+ public function _list_databases()
{
- if ($this->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return array();
+ return ($this->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -61,14 +54,12 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* Optimize table query
*
- * Is optimization even supported in SQLite?
- *
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
+ // Not supported
return FALSE;
}
@@ -77,14 +68,12 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* Repair table query
*
- * Are table repairs even supported in SQLite?
- *
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
+ // Not supported
return FALSE;
}
@@ -93,15 +82,15 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* SQLite Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
}
+
}
/* End of file sqlite_utility.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 6fd52ef70..9f2f88699 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLSRV Database Adapter Class
*
@@ -42,30 +40,29 @@
*/
class CI_DB_sqlsrv_driver extends CI_DB {
- var $dbdriver = 'sqlsrv';
+ public $dbdriver = 'sqlsrv';
// The character used for escaping
- var $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- var $_like_escape_str = " ESCAPE '%s' ";
- var $_like_escape_chr = '!';
+ protected $_like_escape_str = " ESCAPE '%s' ";
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' ASC'; // not currently supported
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' ASC'; // not currently supported
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect($pooling = false)
+ public function db_connect($pooling = FALSE)
{
// Check for a UTF-8 charset being passed as CI's default 'utf8'.
$character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set;
@@ -78,10 +75,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
'CharacterSet' => $character_set,
'ReturnDatesAsStrings' => 1
);
-
- // If the username and password are both empty, assume this is a
+
+ // If the username and password are both empty, assume this is a
// 'Windows Authentication Mode' connection.
- if(empty($connection['UID']) && empty($connection['PWD'])) {
+ if (empty($connection['UID']) && empty($connection['PWD']))
+ {
unset($connection['UID'], $connection['PWD']);
}
@@ -93,10 +91,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
return $this->db_connect(TRUE);
}
@@ -104,46 +101,25 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @access public
- * @return void
- */
- function reconnect()
- {
- // not implemented in MSSQL
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return $this->_execute('USE ' . $this->database);
- }
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
- // --------------------------------------------------------------------
+ if ($this->_execute('USE '.$database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
- /**
- * Set client character set
- *
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- // @todo - add support if needed
- return TRUE;
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -151,33 +127,16 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
- {
- $sql = $this->_prep_query($sql);
- return sqlsrv_query($this->conn_id, $sql, null, array(
- 'Scrollable' => SQLSRV_CURSOR_STATIC,
- 'SendStreamParamsAtExec' => true
- ));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
- *
- * @access private called by execute()
- * @param string an SQL query
- * @return string
- */
- function _prep_query($sql)
+ protected function _execute($sql)
{
- return $sql;
+ return sqlsrv_query($this->conn_id,
+ $sql,
+ NULL,
+ array('Scrollable'=> SQLSRV_CURSOR_STATIC, 'SendStreamParamsAtExec' => TRUE)
+ );
}
// --------------------------------------------------------------------
@@ -185,10 +144,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -214,10 +172,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -238,10 +195,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -262,12 +218,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
// Escape single quotes
return str_replace("'", "''", $str);
@@ -278,10 +233,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @sqlrv_rows_affected($this->conn_id);
}
@@ -289,31 +243,31 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Insert ID
- *
- * Returns the last id created in the Identity column.
- *
- * @access public
- * @return integer
- */
- function insert_id()
+ * Insert ID
+ *
+ * Returns the last id created in the Identity column.
+ *
+ * @return string
+ */
+ public function insert_id()
{
- return $this->query('select @@IDENTITY as insert_id')->row('insert_id');
+ $query = $this->query('SELECT @@IDENTITY AS insert_id');
+ $query = $query->row();
+ return $query->insert_id;
}
// --------------------------------------------------------------------
/**
- * Parse major version
- *
- * Grabs the major version number from the
- * database server version string passed in.
- *
- * @access private
- * @param string $version
- * @return int16 major version number
- */
- function _parse_major_version($version)
+ * Parse major version
+ *
+ * Grabs the major version number from the
+ * database server version string passed in.
+ *
+ * @param string $version
+ * @return int major version number
+ */
+ protected function _parse_major_version($version)
{
preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
return $ver_info[1]; // return the major version b/c that's all we're interested in.
@@ -322,15 +276,23 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Version number query string
- *
- * @access public
- * @return string
- */
- function _version()
+ * Database version number
+ *
+ * @return string
+ */
+ public function version()
{
- $info = sqlsrv_server_info($this->conn_id);
- return sprintf("select '%s' as ver", $info['SQLServerVersion']);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+
+ if (($info = sqlsrv_server_info($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $this->data_cache['version'] = $info['SQLServerVersion'];
}
// --------------------------------------------------------------------
@@ -341,23 +303,25 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
- return '0';
-
+ {
+ return 0;
+ }
+
$query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
-
if ($query->num_rows() == 0)
- return '0';
+ {
+ return 0;
+ }
$row = $query->row();
$this->_reset_select();
- return $row->numrows;
+ return (int) $row->numrows;
}
// --------------------------------------------------------------------
@@ -367,11 +331,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
}
@@ -383,13 +346,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access private
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'";
+ return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
}
// --------------------------------------------------------------------
@@ -399,71 +361,63 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
+ return 'SELECT TOP 1 * FROM '.$table;
}
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
*/
- function _error_message()
+ public function error()
{
- $error = array_shift(sqlsrv_errors());
- return !empty($error['message']) ? $error['message'] : null;
- }
+ $error = array('code' => '00000', 'message' => '');
+ $sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
- // --------------------------------------------------------------------
+ if ( ! is_array($sqlsrv_errors))
+ {
+ return $error;
+ }
- /**
- * The error message number
- *
- * @access private
- * @return integer
- */
- function _error_number()
- {
- $error = array_shift(sqlsrv_errors());
- return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null;
- }
+ $sqlsrv_error = array_shift($sqlsrv_errors);
+ if (isset($sqlsrv_error['SQLSTATE']))
+ {
+ $error['code'] = isset($sqlsrv_error['code']) ? $sqlsrv_error['SQLSTATE'].'/'.$sqlsrv_error['code'] : $sqlsrv_error['SQLSTATE'];
+ }
+ elseif (isset($sqlsrv_error['code']))
+ {
+ $error['code'] = $sqlsrv_error['code'];
+ }
- // --------------------------------------------------------------------
+ if (isset($sqlsrv_error['message']))
+ {
+ $error['message'] = $sqlsrv_error['message'];
+ }
- /**
- * Escape Table Name
- *
- * This function adds backticks if the table name has a period
- * in it. Some DBs will get cranky unless periods are escaped
- *
- * @access private
- * @param string the table name
- * @return string
- */
- function _escape_table($table)
- {
- return $table;
- }
+ return $error;
+ }
+ // --------------------------------------------------------------------
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
return $item;
}
@@ -476,11 +430,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -497,15 +450,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
- {
- return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ protected function _insert($table, $keys, $values)
+ {
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -515,7 +467,6 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -523,16 +474,16 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where)
+ protected function _update($table, $values, $where)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
-
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).' WHERE '.implode(' ', $where);
}
-
+
// --------------------------------------------------------------------
/**
@@ -542,11 +493,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return "TRUNCATE ".$table;
}
@@ -558,15 +508,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where)
+ protected function _delete($table, $where)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ return 'DELETE FROM '.$table.' WHERE '.implode(' ', $where);
}
// --------------------------------------------------------------------
@@ -576,17 +525,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $i = $limit + $offset;
-
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
}
// --------------------------------------------------------------------
@@ -594,18 +540,15 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@sqlsrv_close($conn_id);
}
}
-
-
-/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
+/* End of file 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 2a7766927..0dc7b5242 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLSRV Forge Class
*
@@ -39,11 +37,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
return "CREATE DATABASE ".$name;
}
@@ -53,11 +50,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
return "DROP DATABASE ".$name;
}
@@ -67,10 +63,9 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
return "DROP TABLE ".$this->db->_escape_identifiers($table);
}
@@ -80,15 +75,14 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -100,7 +94,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
$sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
@@ -113,7 +107,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
@@ -156,7 +150,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
@@ -166,11 +160,11 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
@@ -190,19 +184,18 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -228,7 +221,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if ($after_field != '')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
}
return $sql;
@@ -242,19 +235,17 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
// I think this syntax will work, but can find little documentation on renaming tables in MSSQL
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
-/* End of file mssql_forge.php */
-/* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file
+/* End of file sqlsrv_forge.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index 1ee19c2d1..10d790e4b 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLSRV Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @sqlsrv_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @sqlsrv_num_fields($this->result_id);
}
@@ -69,17 +65,16 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
+ foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
$field_names[] = $field['Name'];
}
-
+
return $field_names;
}
@@ -90,13 +85,12 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
+ foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
$F = new stdClass();
$F->name = $field['Name'];
@@ -104,10 +98,10 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
$F->max_length = $field['Size'];
$F->primary_key = 0;
$F->default = '';
-
+
$retval[] = $F;
}
-
+
return $retval;
}
@@ -116,9 +110,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -132,14 +126,13 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
- * @return array
+ * @return void
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
// Not implemented
}
@@ -151,10 +144,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
}
@@ -166,16 +158,14 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return sqlsrv_fetch_object($this->result_id);
}
}
-
-/* End of file mssql_result.php */
-/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file
+/* End of file sqlsrv_result.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index e96df96f9..5830c62de 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* SQLSRV Utility Class
*
@@ -39,10 +37,9 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases
}
@@ -54,11 +51,10 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
@@ -70,11 +66,10 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
return FALSE; // Is this supported in MS SQL?
}
@@ -84,11 +79,10 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
/**
* MSSQL Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -96,5 +90,5 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
}
-/* End of file mssql_utility.php */
-/* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file
+/* End of file sqlsrv_utility.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_utility.php */ \ No newline at end of file
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index c46c4d103..464d1d112 100644
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Array Helpers
*
@@ -45,7 +43,6 @@
* Lets you determine whether an array index is set and whether it has a value.
* If the element is empty it returns FALSE (or whatever you specify as the default value.)
*
- * @access public
* @param string
* @param array
* @param mixed
@@ -55,12 +52,7 @@ if ( ! function_exists('element'))
{
function element($item, $array, $default = FALSE)
{
- if ( ! isset($array[$item]) OR $array[$item] == "")
- {
- return $default;
- }
-
- return $array[$item];
+ return empty($array[$item]) ? $default : $array[$item];
}
}
@@ -69,7 +61,6 @@ if ( ! function_exists('element'))
/**
* Random Element - Takes an array as input and returns a random element
*
- * @access public
* @param array
* @return mixed depends on what the array contains
*/
@@ -77,12 +68,7 @@ if ( ! function_exists('random_element'))
{
function random_element($array)
{
- if ( ! is_array($array))
- {
- return $array;
- }
-
- return $array[array_rand($array)];
+ return is_array($array) ? $array[array_rand($array)] : $array;
}
}
@@ -91,10 +77,9 @@ if ( ! function_exists('random_element'))
/**
* Elements
*
- * Returns only the array items specified. Will return a default value if
+ * Returns only the array items specified. Will return a default value if
* it is not set.
*
- * @access public
* @param array
* @param array
* @param mixed
@@ -105,22 +90,12 @@ if ( ! function_exists('elements'))
function elements($items, $array, $default = FALSE)
{
$return = array();
-
- if ( ! is_array($items))
- {
- $items = array($items);
- }
-
+
+ is_array($items) OR $items = array($items);
+
foreach ($items as $item)
{
- if (isset($array[$item]))
- {
- $return[$item] = $array[$item];
- }
- else
- {
- $return[$item] = $default;
- }
+ $return[$item] = isset($array[$item]) ? $array[$item] : $default;
}
return $return;
@@ -128,4 +103,4 @@ if ( ! function_exists('elements'))
}
/* End of file array_helper.php */
-/* Location: ./system/helpers/array_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/array_helper.php */
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index 668b034d4..578796573 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -2,12 +2,12 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -94,16 +94,15 @@ if ( ! function_exists('create_captcha'))
// Remove old images
// -----------------------------------
- list($usec, $sec) = explode(" ", microtime());
- $now = ((float)$usec + (float)$sec);
+ $now = microtime(TRUE);
$current_dir = @opendir($img_path);
while ($filename = @readdir($current_dir))
{
- if ($filename != "." and $filename != ".." and $filename != "index.html")
+ if ($filename != '.' && $filename != '..' && $filename != 'index.html')
{
- $name = str_replace(".jpg", "", $filename);
+ $name = str_replace('.jpg', '', $filename);
if (($name + $expiration) < $now)
{
@@ -198,7 +197,7 @@ if ( ! function_exists('create_captcha'))
// Write the text
// -----------------------------------
- $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
+ $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext')) ? TRUE : FALSE;
if ($use_font == FALSE)
{
diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php
index 7b439c47f..ec8aa3250 100644
--- a/system/helpers/cookie_helper.php
+++ b/system/helpers/cookie_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Cookie Helpers
*
@@ -42,25 +40,26 @@
/**
* Set cookie
*
- * Accepts six parameter, or you can submit an associative
+ * Accepts seven parameters, or you can submit an associative
* array in the first parameter containing all the values.
*
- * @access public
* @param mixed
* @param string the value of the cookie
* @param string the number of seconds until expiration
* @param string the cookie domain. Usually: .yourdomain.com
* @param string the cookie path
* @param string the cookie prefix
+ * @param bool true makes the cookie secure
+ * @param bool true makes the cookie accessible via http(s) only (no javascript)
* @return void
*/
if ( ! function_exists('set_cookie'))
{
- function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
+ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
{
// Set the config file options
$CI =& get_instance();
- $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
+ $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly);
}
}
@@ -69,7 +68,6 @@ if ( ! function_exists('set_cookie'))
/**
* Fetch an item from the COOKIE array
*
- * @access public
* @param string
* @param bool
* @return mixed
@@ -79,14 +77,7 @@ if ( ! function_exists('get_cookie'))
function get_cookie($index = '', $xss_clean = FALSE)
{
$CI =& get_instance();
-
- $prefix = '';
-
- if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '')
- {
- $prefix = config_item('cookie_prefix');
- }
-
+ $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix');
return $CI->input->cookie($prefix.$index, $xss_clean);
}
}
@@ -97,7 +88,7 @@ if ( ! function_exists('get_cookie'))
* Delete a COOKIE
*
* @param mixed
- * @param string the cookie domain. Usually: .yourdomain.com
+ * @param string the cookie domain. Usually: .yourdomain.com
* @param string the cookie path
* @param string the cookie prefix
* @return void
@@ -110,6 +101,5 @@ if ( ! function_exists('delete_cookie'))
}
}
-
/* End of file cookie_helper.php */
-/* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/cookie_helper.php */
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 9e58d8630..d54553292 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -128,15 +128,16 @@ if ( ! function_exists('standard_date'))
function standard_date($fmt = 'DATE_RFC822', $time = '')
{
$formats = array(
- 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q',
+ 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%O',
'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC',
- 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q',
+ 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%O',
'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O',
'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC',
'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O',
'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_RFC2822' => '%D, %d %M %Y %H:%i:%s %O',
'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',
- 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q'
+ 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%O'
);
if ( ! isset($formats[$fmt]))
@@ -159,11 +160,12 @@ if ( ! function_exists('standard_date'))
* @access public
* @param integer a number of seconds
* @param integer Unix timestamp
- * @return integer
+ * @param integer a number of display units
+ * @return string
*/
if ( ! function_exists('timespan'))
{
- function timespan($seconds = 1, $time = '')
+ function timespan($seconds = 1, $time = '', $units = 7)
{
$CI =& get_instance();
$CI->lang->load('date');
@@ -178,24 +180,29 @@ if ( ! function_exists('timespan'))
$time = time();
}
+ if ( ! is_numeric($units))
+ {
+ $units = 7;
+ }
+
$seconds = ($time <= $seconds) ? 1 : $time - $seconds;
- $str = '';
+ $str = array();
$years = floor($seconds / 31557600);
if ($years > 0)
{
- $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
+ $str[] = $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year'));
}
$seconds -= $years * 31557600;
$months = floor($seconds / 2629743);
- if ($years > 0 OR $months > 0)
+ if (count($str) < $units && ($years > 0 OR $months > 0))
{
if ($months > 0)
{
- $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', ';
+ $str[] = $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month'));
}
$seconds -= $months * 2629743;
@@ -203,11 +210,11 @@ if ( ! function_exists('timespan'))
$weeks = floor($seconds / 604800);
- if ($years > 0 OR $months > 0 OR $weeks > 0)
+ if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0))
{
if ($weeks > 0)
{
- $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', ';
+ $str[] = $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week'));
}
$seconds -= $weeks * 604800;
@@ -215,11 +222,11 @@ if ( ! function_exists('timespan'))
$days = floor($seconds / 86400);
- if ($months > 0 OR $weeks > 0 OR $days > 0)
+ if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0))
{
if ($days > 0)
{
- $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', ';
+ $str[] = $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day'));
}
$seconds -= $days * 86400;
@@ -227,11 +234,11 @@ if ( ! function_exists('timespan'))
$hours = floor($seconds / 3600);
- if ($days > 0 OR $hours > 0)
+ if (count($str) < $units && ($days > 0 OR $hours > 0))
{
if ($hours > 0)
{
- $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', ';
+ $str[] = $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour'));
}
$seconds -= $hours * 3600;
@@ -239,22 +246,22 @@ if ( ! function_exists('timespan'))
$minutes = floor($seconds / 60);
- if ($days > 0 OR $hours > 0 OR $minutes > 0)
+ if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0))
{
if ($minutes > 0)
{
- $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', ';
+ $str[] = $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute'));
}
$seconds -= $minutes * 60;
}
- if ($str == '')
+ if (count($str) === 0)
{
- $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', ';
+ $str[] = $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second'));
}
- return substr(trim($str), 0, -1);
+ return implode(', ', $str);
}
}
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index be65b388d..d7ca13e85 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Directory Helpers
*
@@ -43,12 +41,11 @@
* Create a Directory Map
*
* Reads the specified directory and builds an array
- * representation of it. Sub-folders contained with the
+ * representation of it. Sub-folders contained with the
* directory will be mapped as well.
*
- * @access public
* @param string path to source
- * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
+ * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
* @return array
*/
if ( ! function_exists('directory_map'))
@@ -64,7 +61,7 @@ if ( ! function_exists('directory_map'))
while (FALSE !== ($file = readdir($fp)))
{
// Remove '.', '..', and hidden files [optional]
- if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.'))
+ if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] === '.'))
{
continue;
}
@@ -87,6 +84,5 @@ if ( ! function_exists('directory_map'))
}
}
-
/* End of file directory_helper.php */
-/* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/directory_helper.php */
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index aea948d81..96ff29dec 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Download Helpers
*
@@ -47,67 +45,84 @@
* @access public
* @param string filename
* @param mixed the data to be downloaded
+ * @param bool wether to try and send the actual file MIME type
* @return void
*/
if ( ! function_exists('force_download'))
{
- function force_download($filename = '', $data = '')
+ function force_download($filename = '', $data = '', $set_mime = FALSE)
{
if ($filename == '' OR $data == '')
{
return FALSE;
}
- // Try to determine if the filename includes a file extension.
- // We need it in order to set the MIME type
- if (FALSE === strpos($filename, '.'))
- {
- return FALSE;
- }
+ // Set the default MIME type to send
+ $mime = 'application/octet-stream';
- // Grab the file extension
$x = explode('.', $filename);
$extension = end($x);
- // Load the mime types
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if ($set_mime === TRUE)
{
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
- }
- elseif (is_file(APPPATH.'config/mimes.php'))
- {
- include(APPPATH.'config/mimes.php');
- }
+ if (count($x) === 1 OR $extension === '')
+ {
+ /* If we're going to detect the MIME type,
+ * we'll need a file extension.
+ */
+ return FALSE;
+ }
- // Set a default mime if we can't find it
- if ( ! isset($mimes[$extension]))
- {
- $mime = 'application/octet-stream';
+ // Load the mime types
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ }
+ elseif (is_file(APPPATH.'config/mimes.php'))
+ {
+ include(APPPATH.'config/mimes.php');
+ }
+
+ // Only change the default MIME if we can find one
+ if (isset($mimes[$extension]))
+ {
+ $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
+ }
}
- else
+
+ /* It was reported that browsers on Android 2.1 (and possibly older as well)
+ * need to have the filename extension upper-cased in order to be able to
+ * download it.
+ *
+ * Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
+ */
+ if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\s(1|2\.[01])/', $_SERVER['HTTP_USER_AGENT']))
{
- $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
+ $x[count($x) - 1] = strtoupper($extension);
+ $filename = implode('.', $x);
}
-
+
// Generate the server headers
- header('Content-Type: "'.$mime.'"');
+ header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
- header("Content-Transfer-Encoding: binary");
- header("Content-Length: ".strlen($data));
- header('Pragma: no-cache');
+ header('Content-Transfer-Encoding: binary');
+ header('Content-Length: '.strlen($data));
- // Internet Explorer-specific headers.
- if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
+ // Internet Explorer-specific headers
+ if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
+ else
+ {
+ header('Pragma: no-cache');
+ }
exit($data);
}
}
-
/* End of file download_helper.php */
-/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/download_helper.php */
diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php
index f184031a9..b87bce674 100644
--- a/system/helpers/email_helper.php
+++ b/system/helpers/email_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 2d4b10e37..3fd6b82e1 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index bed2cb297..37337d975 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -22,7 +22,6 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
- * @filesource
*/
// ------------------------------------------------------------------------
@@ -72,8 +71,8 @@ if ( ! function_exists('form_open'))
$form = '<form action="'.$action.'"'._attributes_to_string($attributes, TRUE).">\n";
- // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
- if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"')))
+ // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
+ if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"')))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
@@ -315,6 +314,28 @@ if ( ! function_exists('form_dropdown'))
{
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
+ // If name is really an array then we'll call the function again using the array
+ if (is_array($name) && isset($name['name']))
+ {
+
+ if ( ! isset($name['options']))
+ {
+ $name['options'] = array();
+ }
+
+ if ( ! isset($name['selected']))
+ {
+ $name['selected'] = array();
+ }
+
+ if ( ! isset($name['extra']))
+ {
+ $name['extra'] = '';
+ }
+
+ return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']);
+ }
+
if ( ! is_array($selected))
{
$selected = array($selected);
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 72970d9ca..b8c4f36f6 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 0bd1e112f..485806b20 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Inflector Helpers
*
@@ -34,10 +32,9 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
+ * @link http://codeigniter.com/user_guide/helpers/inflector_helper.html
*/
-
// --------------------------------------------------------------------
/**
@@ -45,7 +42,6 @@
*
* Takes a plural word and makes it singular
*
- * @access public
* @param string
* @return str
*/
@@ -55,37 +51,51 @@ if ( ! function_exists('singular'))
{
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$singular_rules = array(
- '/(matr)ices$/' => '\1ix',
- '/(vert|ind)ices$/' => '\1ex',
- '/^(ox)en/' => '\1',
- '/(alias)es$/' => '\1',
- '/([octop|vir])i$/' => '\1us',
- '/(cris|ax|test)es$/' => '\1is',
- '/(shoe)s$/' => '\1',
- '/(o)es$/' => '\1',
- '/(bus|campus)es$/' => '\1',
- '/([m|l])ice$/' => '\1ouse',
- '/(x|ch|ss|sh)es$/' => '\1',
- '/(m)ovies$/' => '\1\2ovie',
- '/(s)eries$/' => '\1\2eries',
- '/([^aeiouy]|qu)ies$/' => '\1y',
- '/([lr])ves$/' => '\1f',
- '/(tive)s$/' => '\1',
- '/(hive)s$/' => '\1',
- '/([^f])ves$/' => '\1fe',
- '/(^analy)ses$/' => '\1sis',
+ '/(matr)ices$/' => '\1ix',
+ '/(vert|ind)ices$/' => '\1ex',
+ '/^(ox)en/' => '\1',
+ '/(alias)es$/' => '\1',
+ '/([octop|vir])i$/' => '\1us',
+ '/(cris|ax|test)es$/' => '\1is',
+ '/(shoe)s$/' => '\1',
+ '/(o)es$/' => '\1',
+ '/(bus|campus)es$/' => '\1',
+ '/([m|l])ice$/' => '\1ouse',
+ '/(x|ch|ss|sh)es$/' => '\1',
+ '/(m)ovies$/' => '\1\2ovie',
+ '/(s)eries$/' => '\1\2eries',
+ '/([^aeiouy]|qu)ies$/' => '\1y',
+ '/([lr])ves$/' => '\1f',
+ '/(tive)s$/' => '\1',
+ '/(hive)s$/' => '\1',
+ '/([^f])ves$/' => '\1fe',
+ '/(^analy)ses$/' => '\1sis',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis',
- '/([ti])a$/' => '\1um',
- '/(p)eople$/' => '\1\2erson',
- '/(m)en$/' => '\1an',
- '/(s)tatuses$/' => '\1\2tatus',
- '/(c)hildren$/' => '\1\2hild',
- '/(n)ews$/' => '\1\2ews',
- '/([^u])s$/' => '\1',
+ '/([ti])a$/' => '\1um',
+ '/(p)eople$/' => '\1\2erson',
+ '/(m)en$/' => '\1an',
+ '/(s)tatuses$/' => '\1\2tatus',
+ '/(c)hildren$/' => '\1\2hild',
+ '/(n)ews$/' => '\1\2ews',
+ '/([^us])s$/' => '\1',
);
- return preg_replace(array_keys($singular_values), $singular_values, $result);
+ foreach ($singular_rules as $rule => $replacement)
+ {
+ if (preg_match($rule, $result))
+ {
+ $result = preg_replace($rule, $replacement, $result);
+ break;
+ }
+ }
+
+ return $result;
}
}
@@ -96,7 +106,6 @@ if ( ! function_exists('singular'))
*
* Takes a singular word and makes it plural
*
- * @access public
* @param string
* @param bool
* @return str
@@ -107,29 +116,43 @@ if ( ! function_exists('plural'))
{
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$plural_rules = array(
- '/^(ox)$/' => '\1\2en', // ox
- '/([m|l])ouse$/' => '\1ice', // mouse, louse
- '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
- '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
- '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
- '/(hive)$/' => '\1s', // archive, hive
- '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
- '/sis$/' => 'ses', // basis, diagnosis
- '/([ti])um$/' => '\1a', // datum, medium
- '/(p)erson$/' => '\1eople', // person, salesperson
- '/(m)an$/' => '\1en', // man, woman, spokesman
- '/(c)hild$/' => '\1hildren', // child
- '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
- '/(bu|campu)s$/' => '\1\2ses', // bus, campus
- '/(alias|status|virus)/' => '\1es', // alias
- '/(octop)us$/' => '\1i', // octopus
- '/(ax|cris|test)is$/' => '\1es', // axis, crisis
- '/s$/' => 's', // no change (compatibility)
- '/$/' => 's',
+ '/^(ox)$/' => '\1\2en', // ox
+ '/([m|l])ouse$/' => '\1ice', // mouse, louse
+ '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
+ '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
+ '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
+ '/(hive)$/' => '\1s', // archive, hive
+ '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
+ '/sis$/' => 'ses', // basis, diagnosis
+ '/([ti])um$/' => '\1a', // datum, medium
+ '/(p)erson$/' => '\1eople', // person, salesperson
+ '/(m)an$/' => '\1en', // man, woman, spokesman
+ '/(c)hild$/' => '\1hildren', // child
+ '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
+ '/(bu|campu)s$/' => '\1\2ses', // bus, campus
+ '/(alias|status|virus)$/' => '\1es', // alias
+ '/(octop)us$/' => '\1i', // octopus
+ '/(ax|cris|test)is$/' => '\1es', // axis, crisis
+ '/s$/' => 's', // no change (compatibility)
+ '/$/' => 's',
);
- return preg_replace(array_keys($plural_rules), $plural_rules, $result);
+ foreach ($plural_rules as $rule => $replacement)
+ {
+ if (preg_match($rule, $result))
+ {
+ $result = preg_replace($rule, $replacement, $result);
+ break;
+ }
+ }
+
+ return $result;
}
}
@@ -140,7 +163,6 @@ if ( ! function_exists('plural'))
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
- * @access public
* @param string
* @return str
*/
@@ -148,7 +170,7 @@ if ( ! function_exists('camelize'))
{
function camelize($str)
{
- return substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
+ return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
}
}
@@ -159,7 +181,6 @@ if ( ! function_exists('camelize'))
*
* Takes multiple words separated by spaces and underscores them
*
- * @access public
* @param string
* @return str
*/
@@ -178,7 +199,6 @@ if ( ! function_exists('underscore'))
*
* Takes multiple words separated by the separator and changes them to spaces
*
- * @access public
* @param string $str
* @param string $separator
* @return str
@@ -191,5 +211,22 @@ if ( ! function_exists('humanize'))
}
}
+/**
+ * Checks if the given word has a plural version.
+ *
+ * @param string the word to check
+ * @return bool if the word is countable
+ */
+if ( ! function_exists('is_countable'))
+{
+ function is_countable($word)
+ {
+ return ! (in_array(strtolower(strval($word)), array(
+ 'equipment', 'information', 'rice', 'money',
+ 'species', 'series', 'fish', 'meta'
+ )));
+ }
+}
+
/* End of file inflector_helper.php */
/* Location: ./system/helpers/inflector_helper.php */
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index a83580a97..1d66df59f 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php
index 331b468c6..b6c823d8b 100644
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index cd87a73eb..c31f0bdc5 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Path Helpers
*
@@ -51,28 +49,24 @@ if ( ! function_exists('set_realpath'))
{
function set_realpath($path, $check_existance = FALSE)
{
- // Security check to make sure the path is NOT a URL. No remote file inclusion!
- if (preg_match("#^(http:\/\/|https:\/\/|www\.|ftp|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $path))
+ // Security check to make sure the path is NOT a URL. No remote file inclusion!
+ if (preg_match('#^(http:\/\/|https:\/\/|www\.|ftp|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i', $path))
{
show_error('The path you submitted must be a local server path, not a URL');
}
// Resolve the path
- if (function_exists('realpath') AND @realpath($path) !== FALSE)
+ if (function_exists('realpath') && @realpath($path) !== FALSE)
{
$path = realpath($path);
}
-
- // Add a trailing slash
- $path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
-
- // Make sure the path exists
- if ($check_existance == TRUE && ! is_dir($path))
+ elseif ($check_existance && ! is_dir($path) && ! is_file($path))
{
show_error('Not a valid path: '.$path);
}
- return $path;
+ // Add a trailing slash, if this is a directory
+ return is_dir($path) ? rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $path;
}
}
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php
index 99fda561a..8c7adea46 100644
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Security Helpers
*
@@ -42,7 +40,6 @@
/**
* XSS Filtering
*
- * @access public
* @param string
* @param bool whether or not the content is an image file
* @return string
@@ -61,7 +58,6 @@ if ( ! function_exists('xss_clean'))
/**
* Sanitize Filename
*
- * @access public
* @param string
* @return string
*/
@@ -79,7 +75,6 @@ if ( ! function_exists('sanitize_filename'))
/**
* Hash encode a string
*
- * @access public
* @param string
* @return string
*/
@@ -87,7 +82,12 @@ if ( ! function_exists('do_hash'))
{
function do_hash($str, $type = 'sha1')
{
- return ($type === 'sha1') ? sha1($str) : md5($str);
+ if ( ! in_array(strtolower($type), hash_algos()))
+ {
+ $type = 'md5';
+ }
+
+ return hash($type, $str);
}
}
@@ -96,7 +96,6 @@ if ( ! function_exists('do_hash'))
/**
* Strip Image Tags
*
- * @access public
* @param string
* @return string
*/
@@ -104,7 +103,7 @@ if ( ! function_exists('strip_image_tags'))
{
function strip_image_tags($str)
{
- return preg_replace(array("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "#<img\s+.*?src\s*=\s*(.+?).*?\>#"), "\\1", $str);
+ return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
}
}
@@ -113,7 +112,6 @@ if ( ! function_exists('strip_image_tags'))
/**
* Convert PHP tags to entities
*
- * @access public
* @param string
* @return string
*/
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 700f4486c..cc903bc1c 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index 04d51c2f9..607a12bcb 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 842a31d75..7591bac5f 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -300,9 +300,9 @@ if ( ! function_exists('highlight_code'))
// Replace any existing PHP tags to temporary markers so they don't accidentally
// break the string out of PHP, and thus, thwart the highlighting.
-
$str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'),
- array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
+ array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ $str);
// The highlight_string function requires that the text be surrounded
// by PHP tags, which we will remove later
@@ -311,25 +311,15 @@ if ( ! function_exists('highlight_code'))
// All the magic happens here, baby!
$str = highlight_string($str, TRUE);
- // Prior to PHP 5, the highligh function used icky <font> tags
- // so we'll replace them with <span> tags.
-
- if (abs(PHP_VERSION) < 5)
- {
- $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
- $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
- }
-
// Remove our artificially added PHP, and the syntax highlighting that came with it
$str = preg_replace('/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i', '<span style="color: #$1">', $str);
$str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str);
$str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str);
// Replace our markers back to PHP tags.
- $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
- array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);
-
- return $str;
+ return str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'),
+ $str);
}
}
@@ -544,4 +534,4 @@ if ( ! function_exists('ellipsize'))
}
/* End of file text_helper.php */
-/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/text_helper.php */
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index c49348e6a..9b19c7c2d 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 2cbcd9dbf..2ae1fd37b 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -470,39 +470,35 @@ if ( ! function_exists('prep_url'))
* Create URL Title
*
* Takes a "title" string as input and creates a
- * human-friendly URL string with either a dash
- * or an underscore as the word separator.
+ * human-friendly URL string with a "separator" string
+ * as the word separator.
*
* @access public
* @param string the string
- * @param string the separator: dash, or underscore
+ * @param string the separator
* @return string
*/
if ( ! function_exists('url_title'))
{
- function url_title($str, $separator = 'dash', $lowercase = FALSE)
+ function url_title($str, $separator = '-', $lowercase = FALSE)
{
if ($separator === 'dash')
{
- $search = '_';
- $replace = '-';
+ $separator = '-';
}
- else
+ else if ($separator == 'underscore')
{
- $search = '-';
- $replace = '_';
+ $separator = '_';
}
+
+ $q_separator = preg_quote($separator);
$trans = array(
- '&\#\d+?;' => '',
- '&\S+?;' => '',
- '\s+' => $replace,
- '[^a-z0-9\-\._]' => '',
- $replace.'+' => $replace,
- $replace.'$' => $replace,
- '^'.$replace => $replace,
- '\.+$' => ''
- );
+ '&.+?;' => '',
+ '[^a-z0-9 _-]' => '',
+ '\s+' => $separator,
+ '('.$q_separator.')+' => $separator
+ );
$str = strip_tags($str);
foreach ($trans as $key => $val)
@@ -515,7 +511,7 @@ if ( ! function_exists('url_title'))
$str = strtolower($str);
}
- return trim(trim(stripslashes($str)), $replace);
+ return trim(trim($str, $separator));
}
}
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 5242193ac..f3ff5764c 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php
index bf61db039..2d477e6c8 100644
--- a/system/language/english/calendar_lang.php
+++ b/system/language/english/calendar_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php
index cd6cf39c4..533563700 100644
--- a/system/language/english/date_lang.php
+++ b/system/language/english/date_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index 2a91597df..a135d1aac 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php
index e0ef427a6..23296a244 100644
--- a/system/language/english/email_lang.php
+++ b/system/language/english/email_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 6afa37a29..6cf0b46f4 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,30 +25,32 @@
* @filesource
*/
-$lang['required'] = "The %s field is required.";
-$lang['isset'] = "The %s field must have a value.";
-$lang['valid_email'] = "The %s field must contain a valid email address.";
-$lang['valid_emails'] = "The %s field must contain all valid email addresses.";
-$lang['valid_url'] = "The %s field must contain a valid URL.";
-$lang['valid_ip'] = "The %s field must contain a valid IP.";
-$lang['min_length'] = "The %s field must be at least %s characters in length.";
-$lang['max_length'] = "The %s field cannot exceed %s characters in length.";
-$lang['exact_length'] = "The %s field must be exactly %s characters in length.";
-$lang['alpha'] = "The %s field may only contain alphabetical characters.";
-$lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters.";
-$lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes.";
-$lang['numeric'] = "The %s field must contain only numbers.";
-$lang['is_numeric'] = "The %s field must contain only numeric characters.";
-$lang['integer'] = "The %s field must contain an integer.";
-$lang['regex_match'] = "The %s field is not in the correct format.";
-$lang['matches'] = "The %s field does not match the %s field.";
-$lang['is_unique'] = "The %s field must contain a unique value.";
-$lang['is_natural'] = "The %s field must contain only positive numbers.";
-$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
-$lang['decimal'] = "The %s field must contain a decimal number.";
-$lang['less_than'] = "The %s field must contain a number less than %s.";
-$lang['greater_than'] = "The %s field must contain a number greater than %s.";
+$lang['required'] = "The %s field is required.";
+$lang['isset'] = "The %s field must have a value.";
+$lang['valid_email'] = "The %s field must contain a valid email address.";
+$lang['valid_emails'] = "The %s field must contain all valid email addresses.";
+$lang['valid_url'] = "The %s field must contain a valid URL.";
+$lang['valid_ip'] = "The %s field must contain a valid IP.";
+$lang['min_length'] = "The %s field must be at least %s characters in length.";
+$lang['max_length'] = "The %s field cannot exceed %s characters in length.";
+$lang['exact_length'] = "The %s field must be exactly %s characters in length.";
+$lang['alpha'] = "The %s field may only contain alphabetical characters.";
+$lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters.";
+$lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes.";
+$lang['numeric'] = "The %s field must contain only numbers.";
+$lang['is_numeric'] = "The %s field must contain only numeric characters.";
+$lang['integer'] = "The %s field must contain an integer.";
+$lang['regex_match'] = "The %s field is not in the correct format.";
+$lang['matches'] = "The %s field does not match the %s field.";
+$lang['is_unique'] = "The %s field must contain a unique value.";
+$lang['is_natural'] = "The %s field must contain only positive numbers.";
+$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
+$lang['decimal'] = "The %s field must contain a decimal number.";
+$lang['less_than'] = "The %s field must contain a number less than %s.";
+$lang['less_than_equal_to'] = "The %s field must contain a number less than or equal to %s.";
+$lang['greater_than'] = "The %s field must contain a number greater than %s.";
+$lang['greater_than_equal_to'] = "The %s field must contain a number greater than or equal to %s.";
/* End of file form_validation_lang.php */
-/* Location: ./system/language/english/form_validation_lang.php */ \ No newline at end of file
+/* Location: ./system/language/english/form_validation_lang.php */
diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php
index 18ca92713..4e39e43bf 100644
--- a/system/language/english/ftp_lang.php
+++ b/system/language/english/ftp_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php
index fbb92abfb..67ca94277 100644
--- a/system/language/english/imglib_lang.php
+++ b/system/language/english/imglib_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
index 9765562b5..2085cee2a 100644
--- a/system/language/english/migration_lang.php
+++ b/system/language/english/migration_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/number_lang.php b/system/language/english/number_lang.php
index 5dfd882ed..0c19ec614 100644
--- a/system/language/english/number_lang.php
+++ b/system/language/english/number_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php
index 1d10efa76..11d791272 100644
--- a/system/language/english/profiler_lang.php
+++ b/system/language/english/profiler_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php
index ed98439f4..3a8e14403 100644
--- a/system/language/english/unit_test_lang.php
+++ b/system/language/english/unit_test_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php
index a9a2fe74b..4fa8394ec 100644
--- a/system/language/english/upload_lang.php
+++ b/system/language/english/upload_lang.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -35,7 +35,7 @@ $lang['upload_stopped_by_extension'] = "The file upload was stopped by extension
$lang['upload_no_file_selected'] = "You did not select a file to upload.";
$lang['upload_invalid_filetype'] = "The filetype you are attempting to upload is not allowed.";
$lang['upload_invalid_filesize'] = "The file you are attempting to upload is larger than the permitted size.";
-$lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceedes the maximum height or width.";
+$lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceeds the maximum height or width.";
$lang['upload_destination_error'] = "A problem was encountered while attempting to move the uploaded file to the final destination.";
$lang['upload_no_filepath'] = "The upload path does not appear to be valid.";
$lang['upload_no_file_types'] = "You have not specified any allowed file types.";
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 2e78a6660..7642a5270 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -39,20 +39,17 @@
class CI_Cache extends CI_Driver_Library {
protected $valid_drivers = array(
- 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
- );
-
- protected $_cache_path = NULL; // Path of cache files (if file-based cache)
- protected $_adapter = 'dummy';
+ 'cache_apc',
+ 'cache_file',
+ 'cache_memcached',
+ 'cache_dummy',
+ 'cache_wincache'
+ );
+
+ protected $_cache_path = NULL; // Path of cache files (if file-based cache)
+ protected $_adapter = 'dummy';
protected $_backup_driver;
- // ------------------------------------------------------------------------
-
- /**
- * Constructor
- *
- * @param array
- */
public function __construct($config = array())
{
if ( ! empty($config))
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index a3dd46978..c387a30fc 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index fcd55da39..c9767e401 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 4a81b0422..c0be0def4 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -99,7 +99,7 @@ class CI_Cache_file extends CI_Driver {
if (write_file($this->_cache_path.$id, serialize($contents)))
{
- @chmod($this->_cache_path.$id, 0777);
+ @chmod($this->_cache_path.$id, 0660);
return TRUE;
}
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index ffe6f2ff7..b8f2d7e4c 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
new file mode 100644
index 000000000..df619d4e6
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -0,0 +1,165 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Wincache Caching Class
+ *
+ * Read more about Wincache functions here:
+ * http://www.php.net/manual/en/ref.wincache.php
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author Mike Murkovic
+ * @link
+ */
+
+class CI_Cache_wincache extends CI_Driver {
+
+ /**
+ * Get
+ *
+ * Look for a value in the cache. If it exists, return the data,
+ * if not, return FALSE
+ *
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
+ */
+ public function get($id)
+ {
+ $success = FALSE;
+ $data = wincache_ucache_get($id, $success);
+
+ // Success returned by reference from wincache_ucache_get()
+ return ($success) ? $data : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Save
+ *
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ * @return bool true on success/false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return wincache_ucache_set($id, $data, $ttl);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of the item in the cache
+ * @param bool true on success/false on failure
+ */
+ public function delete($id)
+ {
+ return wincache_ucache_delete($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the cache
+ *
+ * @return bool false on failure/true on success
+ */
+ public function clean()
+ {
+ return wincache_ucache_clear();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @return mixed array on success, false on failure
+ */
+ public function cache_info()
+ {
+ return wincache_ucache_info(TRUE);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed array on success/false on failure
+ */
+ public function get_metadata($id)
+ {
+ if ($stored = wincache_ucache_info(FALSE, $id))
+ {
+ $age = $stored['ucache_entries'][1]['age_seconds'];
+ $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
+ $hitcount = $stored['ucache_entries'][1]['hitcount'];
+
+ return array(
+ 'expire' => $ttl - $age,
+ 'hitcount' => $hitcount,
+ 'age' => $age,
+ 'ttl' => $ttl
+ );
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * is_supported()
+ *
+ * Check to see if WinCache is available on this system, bail if it isn't.
+ *
+ * @return bool
+ */
+ public function is_supported()
+ {
+ if ( ! extension_loaded('wincache'))
+ {
+ log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+}
+
+/* End of file Cache_wincache.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */
diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php
index a05a7babf..6c04de8a2 100644
--- a/system/libraries/Calendar.php
+++ b/system/libraries/Calendar.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index ba8d69be2..60a1e52fe 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -329,13 +329,6 @@ class CI_Cart {
return FALSE;
}
- // Is the new quantity different than what is already saved in the cart?
- // If it's the same there's nothing to do
- if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'])
- {
- return FALSE;
- }
-
// Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index 4e8944311..9a073b336 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 922107e9f..8f383c939 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Email Class
*
@@ -40,55 +38,56 @@
*/
class CI_Email {
- public $useragent = "CodeIgniter";
- public $mailpath = "/usr/sbin/sendmail"; // Sendmail path
- public $protocol = "mail"; // mail/sendmail/smtp
- public $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net
- public $smtp_user = ""; // SMTP Username
- public $smtp_pass = ""; // SMTP Password
- public $smtp_port = "25"; // SMTP Port
- public $smtp_timeout = 5; // SMTP Timeout in seconds
- public $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl.
- public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
- public $wrapchars = "76"; // Number of characters to wrap at.
- public $mailtype = "text"; // text/html Defines email formatting
- public $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
- public $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
- public $alt_message = ''; // Alternative message for HTML emails
- public $validate = FALSE; // TRUE/FALSE. Enables email validation
- public $priority = "3"; // Default priority (1 - 5)
- public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
- public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
+ public $useragent = 'CodeIgniter';
+ public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
+ public $protocol = 'mail'; // mail/sendmail/smtp
+ public $smtp_host = ''; // SMTP Server. Example: mail.earthlink.net
+ public $smtp_user = ''; // SMTP Username
+ public $smtp_pass = ''; // SMTP Password
+ public $smtp_port = 25; // SMTP Port
+ public $smtp_timeout = 5; // SMTP Timeout in seconds
+ public $smtp_crypto = ''; // SMTP Encryption. Can be null, tls or ssl.
+ public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
+ public $wrapchars = 76; // Number of characters to wrap at.
+ public $mailtype = 'text'; // text/html Defines email formatting
+ public $charset = 'utf-8'; // Default char set: iso-8859-1 or us-ascii
+ public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
+ public $alt_message = ''; // Alternative message for HTML emails
+ public $validate = FALSE; // TRUE/FALSE. Enables email validation
+ public $priority = 3; // Default priority (1 - 5)
+ public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
+ public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
// even on the receiving end think they need to muck with CRLFs, so using "\n", while
// distasteful, is the only thing that seems to work for all environments.
+ public $dsn = FALSE; // Delivery Status Notification
public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
- public $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature
+ public $bcc_batch_mode = FALSE; // TRUE/FALSE - Turns on/off Bcc batch feature
public $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
- private $_safe_mode = FALSE;
- private $_subject = "";
- private $_body = "";
- private $_finalbody = "";
- private $_alt_boundary = "";
- private $_atc_boundary = "";
- private $_header_str = "";
- private $_smtp_connect = "";
- private $_encoding = "8bit";
- private $_IP = FALSE;
- private $_smtp_auth = FALSE;
- private $_replyto_flag = FALSE;
- private $_debug_msg = array();
- private $_recipients = array();
- private $_cc_array = array();
- private $_bcc_array = array();
- private $_headers = array();
- private $_attach_name = array();
- private $_attach_type = array();
- private $_attach_disp = array();
- private $_protocols = array('mail', 'sendmail', 'smtp');
- private $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
- private $_bit_depths = array('7bit', '8bit');
- private $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
+ protected $_safe_mode = FALSE;
+ protected $_subject = '';
+ protected $_body = '';
+ protected $_finalbody = '';
+ protected $_alt_boundary = '';
+ protected $_atc_boundary = '';
+ protected $_header_str = '';
+ protected $_smtp_connect = '';
+ protected $_encoding = '8bit';
+ protected $_IP = FALSE;
+ protected $_smtp_auth = FALSE;
+ protected $_replyto_flag = FALSE;
+ protected $_debug_msg = array();
+ protected $_recipients = array();
+ protected $_cc_array = array();
+ protected $_bcc_array = array();
+ protected $_headers = array();
+ protected $_attach_name = array();
+ protected $_attach_type = array();
+ protected $_attach_disp = array();
+ protected $_protocols = array('mail', 'sendmail', 'smtp');
+ protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
+ protected $_bit_depths = array('7bit', '8bit');
+ protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
/**
* Constructor - Sets Email Preferences
@@ -103,11 +102,11 @@ class CI_Email {
}
else
{
- $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
- $this->_safe_mode = (bool) @ini_get("safe_mode");
+ $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_safe_mode = (bool) @ini_get('safe_mode');
}
- log_message('debug', "Email Class Initialized");
+ log_message('debug', 'Email Class Initialized');
}
// --------------------------------------------------------------------
@@ -115,7 +114,6 @@ class CI_Email {
/**
* Initialize preferences
*
- * @access public
* @param array
* @return void
*/
@@ -139,8 +137,8 @@ class CI_Email {
}
$this->clear();
- $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
- $this->_safe_mode = (bool) @ini_get("safe_mode");
+ $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_safe_mode = (bool) @ini_get('safe_mode');
return $this;
}
@@ -150,17 +148,16 @@ class CI_Email {
/**
* Initialize the Email Data
*
- * @access public
* @param bool
- * @return void
+ * @return object
*/
public function clear($clear_attachments = FALSE)
{
- $this->_subject = "";
- $this->_body = "";
- $this->_finalbody = "";
- $this->_header_str = "";
- $this->_replyto_flag = FALSE;
+ $this->_subject = '';
+ $this->_body = '';
+ $this->_finalbody = '';
+ $this->_header_str = '';
+ $this->_replyto_flag = FALSE;
$this->_recipients = array();
$this->_cc_array = array();
$this->_bcc_array = array();
@@ -185,14 +182,13 @@ class CI_Email {
/**
* Set FROM
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function from($from, $name = '')
{
- if (preg_match( '/\<(.*)\>/', $from, $match))
+ if (preg_match('/\<(.*)\>/', $from, $match))
{
$from = $match[1];
}
@@ -228,14 +224,13 @@ class CI_Email {
/**
* Set Reply-to
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function reply_to($replyto, $name = '')
{
- if (preg_match( '/\<(.*)\>/', $replyto, $match))
+ if (preg_match('/\<(.*)\>/', $replyto, $match))
{
$replyto = $match[1];
}
@@ -266,9 +261,8 @@ class CI_Email {
/**
* Set Recipients
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function to($to)
{
@@ -282,17 +276,17 @@ class CI_Email {
if ($this->_get_protocol() !== 'mail')
{
- $this->_set_header('To', implode(", ", $to));
+ $this->_set_header('To', implode(', ', $to));
}
switch ($this->_get_protocol())
{
- case 'smtp' :
+ case 'smtp':
$this->_recipients = $to;
break;
- case 'sendmail' :
- case 'mail' :
- $this->_recipients = implode(", ", $to);
+ case 'sendmail':
+ case 'mail':
+ $this->_recipients = implode(', ', $to);
break;
}
@@ -304,9 +298,8 @@ class CI_Email {
/**
* Set CC
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function cc($cc)
{
@@ -318,7 +311,7 @@ class CI_Email {
$this->validate_email($cc);
}
- $this->_set_header('Cc', implode(", ", $cc));
+ $this->_set_header('Cc', implode(', ', $cc));
if ($this->_get_protocol() === 'smtp')
{
@@ -333,10 +326,9 @@ class CI_Email {
/**
* Set BCC
*
- * @access public
* @param string
* @param string
- * @return void
+ * @return object
*/
public function bcc($bcc, $limit = '')
{
@@ -360,7 +352,7 @@ class CI_Email {
}
else
{
- $this->_set_header('Bcc', implode(", ", $bcc));
+ $this->_set_header('Bcc', implode(', ', $bcc));
}
return $this;
@@ -371,9 +363,8 @@ class CI_Email {
/**
* Set Email Subject
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function subject($subject)
{
@@ -387,13 +378,12 @@ class CI_Email {
/**
* Set Body
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function message($body)
{
- $this->_body = rtrim(str_replace("\r", "", $body));
+ $this->_body = rtrim(str_replace("\r", '', $body));
/* strip slashes only if magic quotes is ON
if we do it with magic quotes OFF, it strips real, user-inputted chars.
@@ -414,9 +404,8 @@ class CI_Email {
/**
* Assign file attachments
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function attach($filename, $disposition = '', $newname = NULL)
{
@@ -431,7 +420,6 @@ class CI_Email {
/**
* Add a Header Item
*
- * @access protected
* @param string
* @param string
* @return void
@@ -446,7 +434,6 @@ class CI_Email {
/**
* Convert a String to an Array
*
- * @access protected
* @param string
* @return array
*/
@@ -460,8 +447,7 @@ class CI_Email {
}
else
{
- $email = trim($email);
- settype($email, "array");
+ $email = (array) trim($email);
}
}
return $email;
@@ -472,9 +458,8 @@ class CI_Email {
/**
* Set Multipart Value
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_alt_message($str = '')
{
@@ -487,9 +472,8 @@ class CI_Email {
/**
* Set Mailtype
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_mailtype($type = 'text')
{
@@ -502,9 +486,8 @@ class CI_Email {
/**
* Set Wordwrap
*
- * @access public
* @param bool
- * @return void
+ * @return object
*/
public function set_wordwrap($wordwrap = TRUE)
{
@@ -517,13 +500,12 @@ class CI_Email {
/**
* Set Protocol
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_protocol($protocol = 'mail')
{
- $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
+ $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail';
return $this;
}
@@ -532,19 +514,12 @@ class CI_Email {
/**
* Set Priority
*
- * @access public
- * @param integer
- * @return void
+ * @param int
+ * @return object
*/
public function set_priority($n = 3)
{
- if ( ! is_numeric($n) OR $n < 1 OR $n > 5)
- {
- $this->priority = 3;
- return;
- }
-
- $this->priority = (int) $n;
+ $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
return $this;
}
@@ -553,9 +528,8 @@ class CI_Email {
/**
* Set Newline Character
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_newline($newline = "\n")
{
@@ -568,13 +542,12 @@ class CI_Email {
/**
* Set CRLF
*
- * @access public
* @param string
- * @return void
+ * @return object
*/
public function set_crlf($crlf = "\n")
{
- $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf;
+ $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf;
return $this;
}
@@ -583,13 +556,12 @@ class CI_Email {
/**
* Set Message Boundary
*
- * @access protected
* @return void
*/
protected function _set_boundaries()
{
- $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
- $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
+ $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative
+ $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary
}
// --------------------------------------------------------------------
@@ -597,14 +569,12 @@ class CI_Email {
/**
* Get the Message ID
*
- * @access protected
* @return string
*/
protected function _get_message_id()
{
$from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
-
- return "<".uniqid('').strstr($from, '@').">";
+ return '<'.uniqid('').strstr($from, '@').'>';
}
// --------------------------------------------------------------------
@@ -612,14 +582,13 @@ class CI_Email {
/**
* Get Mail Protocol
*
- * @access protected
* @param bool
- * @return string
+ * @return mixed
*/
protected function _get_protocol($return = TRUE)
{
$this->protocol = strtolower($this->protocol);
- $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
+ in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail';
if ($return == TRUE)
{
@@ -632,13 +601,12 @@ class CI_Email {
/**
* Get Mail Encoding
*
- * @access protected
* @param bool
* @return string
*/
protected function _get_encoding($return = TRUE)
{
- $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
+ in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit';
foreach ($this->_base_charsets as $charset)
{
@@ -659,7 +627,6 @@ class CI_Email {
/**
* Get content type (text/html/attachment)
*
- * @access protected
* @return string
*/
protected function _get_content_type()
@@ -687,17 +654,16 @@ class CI_Email {
/**
* Set RFC 822 Date
*
- * @access protected
* @return string
*/
protected function _set_date()
{
- $timezone = date("Z");
+ $timezone = date('Z');
$operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
$timezone = abs($timezone);
$timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
- return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
+ return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
}
// --------------------------------------------------------------------
@@ -705,12 +671,11 @@ class CI_Email {
/**
* Mime message
*
- * @access protected
* @return string
*/
protected function _get_mime_message()
{
- return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
+ return 'This is a multi-part message in MIME format.'.$this->newline.'Your email application may not support this format.';
}
// --------------------------------------------------------------------
@@ -718,7 +683,6 @@ class CI_Email {
/**
* Validate Email Address
*
- * @access public
* @param string
* @return bool
*/
@@ -747,13 +711,12 @@ class CI_Email {
/**
* Email Validation
*
- * @access public
* @param string
* @return bool
*/
public function valid_email($address)
{
- return (bool) preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address);
+ return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address);
}
// --------------------------------------------------------------------
@@ -761,7 +724,6 @@ class CI_Email {
/**
* Clean Extended Email Address: Joe Smith <joe@smith.com>
*
- * @access public
* @param string
* @return string
*/
@@ -776,7 +738,7 @@ class CI_Email {
foreach ($email as $addy)
{
- $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy;
+ $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy;
}
return $clean_email;
@@ -792,12 +754,11 @@ class CI_Email {
* If the user hasn't specified his own alternative message
* it creates one by stripping the HTML
*
- * @access protected
* @return string
*/
protected function _get_alt_message()
{
- if ($this->alt_message != "")
+ if ($this->alt_message != '')
{
return $this->word_wrap($this->alt_message, '76');
}
@@ -818,9 +779,8 @@ class CI_Email {
/**
* Word Wrap
*
- * @access public
* @param string
- * @param integer
+ * @param int
* @return string
*/
public function word_wrap($str, $charlim = '')
@@ -911,8 +871,6 @@ class CI_Email {
/**
* Build final headers
*
- * @access protected
- * @param string
* @return string
*/
protected function _build_headers()
@@ -929,7 +887,6 @@ class CI_Email {
/**
* Write Headers as a string
*
- * @access protected
* @return void
*/
protected function _write_headers()
@@ -964,12 +921,11 @@ class CI_Email {
/**
* Build Final Body and attachments
*
- * @access protected
* @return void
*/
protected function _build_message()
{
- if ($this->wordwrap === TRUE AND $this->mailtype !== 'html')
+ if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
{
$this->_body = $this->word_wrap($this->_body);
}
@@ -1131,9 +1087,8 @@ class CI_Email {
* Prepares string for Quoted-Printable Content-Transfer-Encoding
* Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
*
- * @access protected
* @param string
- * @param integer
+ * @param int
* @return string
*/
protected function _prep_quoted_printable($str, $charlim = '')
@@ -1203,9 +1158,7 @@ class CI_Email {
}
// get rid of extra CRLF tacked onto the end
- $output = substr($output, 0, strlen($this->crlf) * -1);
-
- return $output;
+ return substr($output, 0, strlen($this->crlf) * -1);
}
// --------------------------------------------------------------------
@@ -1216,10 +1169,9 @@ class CI_Email {
* Performs "Q Encoding" on a string for use in email headers. It's related
* but not identical to quoted-printable, so it has its own method
*
- * @access public
- * @param str
- * @param bool // set to TRUE for processing From: headers
- * @return str
+ * @param string
+ * @param bool set to TRUE for processing From: headers
+ * @return string
*/
protected function _prep_q_encoding($str, $from = FALSE)
{
@@ -1275,9 +1227,7 @@ class CI_Email {
// wrap each line with the shebang, charset, and transfer encoding
// the preceding space on successive lines is required for header "folding"
- $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
-
- return $str;
+ return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
}
// --------------------------------------------------------------------
@@ -1285,7 +1235,6 @@ class CI_Email {
/**
* Send Email
*
- * @access public
* @return bool
*/
public function send()
@@ -1295,9 +1244,9 @@ class CI_Email {
$this->reply_to($this->_headers['From']);
}
- if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
- ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
- ( ! isset($this->_headers['Cc'])))
+ if ( ! isset($this->_recipients) && ! isset($this->_headers['To'])
+ && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc'])
+ && ! isset($this->_headers['Cc']))
{
$this->_set_error_message('lang:email_no_recipients');
return FALSE;
@@ -1305,44 +1254,40 @@ class CI_Email {
$this->_build_headers();
- if ($this->bcc_batch_mode AND count($this->_bcc_array) > $this->bcc_batch_size)
+ if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
{
return $this->batch_bcc_send();
}
$this->_build_message();
-
return $this->_spool_email();
}
// --------------------------------------------------------------------
/**
- * Batch Bcc Send. Sends groups of BCCs in batches
+ * Batch Bcc Send. Sends groups of BCCs in batches
*
- * @access public
- * @return bool
+ * @return void
*/
public function batch_bcc_send()
{
- $float = $this->bcc_batch_size -1;
-
- $set = "";
-
+ $float = $this->bcc_batch_size - 1;
+ $set = '';
$chunk = array();
for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
{
if (isset($this->_bcc_array[$i]))
{
- $set .= ", ".$this->_bcc_array[$i];
+ $set .= ', '.$this->_bcc_array[$i];
}
if ($i == $float)
{
$chunk[] = substr($set, 1);
$float += $this->bcc_batch_size;
- $set = "";
+ $set = '';
}
if ($i === $c-1)
@@ -1359,7 +1304,7 @@ class CI_Email {
if ($this->protocol !== 'smtp')
{
- $this->_set_header('Bcc', implode(", ", $bcc));
+ $this->_set_header('Bcc', implode(', ', $bcc));
}
else
{
@@ -1376,7 +1321,6 @@ class CI_Email {
/**
* Unwrap special elements
*
- * @access protected
* @return void
*/
protected function _unwrap_specials()
@@ -1389,7 +1333,6 @@ class CI_Email {
/**
* Strip line-breaks via callback
*
- * @access protected
* @return string
*/
protected function _remove_nl_callback($matches)
@@ -1407,7 +1350,6 @@ class CI_Email {
/**
* Spool mail to the mail server
*
- * @access protected
* @return bool
*/
protected function _spool_email()
@@ -1418,6 +1360,7 @@ class CI_Email {
if ( ! $this->$method())
{
$this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
+ return FALSE;
}
$this->_set_error_message('lang:email_sent', $this->_get_protocol());
@@ -1429,7 +1372,6 @@ class CI_Email {
/**
* Send using mail()
*
- * @access protected
* @return bool
*/
protected function _send_with_mail()
@@ -1451,7 +1393,6 @@ class CI_Email {
/**
* Send using Sendmail
*
- * @access protected
* @return bool
*/
protected function _send_with_sendmail()
@@ -1484,7 +1425,6 @@ class CI_Email {
/**
* Send using SMTP
*
- * @access protected
* @return bool
*/
protected function _send_with_smtp()
@@ -1495,8 +1435,10 @@ class CI_Email {
return FALSE;
}
- $this->_smtp_connect();
- $this->_smtp_authenticate();
+ if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate())
+ {
+ return FALSE;
+ }
$this->_send_command('from', $this->clean_email($this->_headers['From']));
@@ -1553,7 +1495,6 @@ class CI_Email {
/**
* SMTP Connect
*
- * @access protected
* @param string
* @return string
*/
@@ -1597,7 +1538,6 @@ class CI_Email {
/**
* Send SMTP command
*
- * @access protected
* @param string
* @param string
* @return string
@@ -1628,9 +1568,15 @@ class CI_Email {
$resp = 250;
break;
case 'to' :
-
- $this->_send_data('RCPT TO:<'.$data.'>');
-
+
+ if ($this->dsn)
+ {
+ $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data);
+ }
+ else
+ {
+ $this->_send_data('RCPT TO:<'.$data.'>');
+ }
$resp = 250;
break;
case 'data' :
@@ -1670,7 +1616,6 @@ class CI_Email {
/**
* SMTP Authenticate
*
- * @access protected
* @return bool
*/
protected function _smtp_authenticate()
@@ -1680,7 +1625,7 @@ class CI_Email {
return TRUE;
}
- if ($this->smtp_user == "" AND $this->smtp_pass == "")
+ if ($this->smtp_user == '' && $this->smtp_pass == '')
{
$this->_set_error_message('lang:email_no_smtp_unpw');
return FALSE;
@@ -1724,7 +1669,6 @@ class CI_Email {
/**
* Send SMTP data
*
- * @access protected
* @return bool
*/
protected function _send_data($data)
@@ -1743,7 +1687,6 @@ class CI_Email {
/**
* Get SMTP data
*
- * @access protected
* @return string
*/
protected function _get_smtp_data()
@@ -1768,12 +1711,11 @@ class CI_Email {
/**
* Get Hostname
*
- * @access protected
* @return string
*/
protected function _get_hostname()
{
- return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
+ return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
}
// --------------------------------------------------------------------
@@ -1781,7 +1723,6 @@ class CI_Email {
/**
* Get IP
*
- * @access protected
* @return string
*/
protected function _get_ip()
@@ -1791,13 +1732,13 @@ class CI_Email {
return $this->_IP;
}
- $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
- $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
+ $cip = ( ! empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
+ $rip = ( ! empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : FALSE;
if ($cip) $this->_IP = $cip;
elseif ($rip) $this->_IP = $rip;
else
{
- $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
+ $fip = ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
if ($fip)
{
$this->_IP = $fip;
@@ -1810,7 +1751,7 @@ class CI_Email {
$this->_IP = end($x);
}
- if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
+ if ( ! preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->_IP))
{
$this->_IP = '0.0.0.0';
}
@@ -1823,7 +1764,6 @@ class CI_Email {
/**
* Get Debug Message
*
- * @access public
* @return string
*/
public function print_debugger()
@@ -1838,8 +1778,7 @@ class CI_Email {
}
}
- $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
- return $msg;
+ return $msg.'<pre>'.$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
}
// --------------------------------------------------------------------
@@ -1847,16 +1786,15 @@ class CI_Email {
/**
* Set Message
*
- * @access protected
* @param string
- * @return string
+ * @return void
*/
protected function _set_error_message($msg, $val = '')
{
$CI =& get_instance();
$CI->lang->load('email');
- if (substr($msg, 0, 5) !== 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5))))
+ if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
{
$this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
}
@@ -1871,13 +1809,13 @@ class CI_Email {
/**
* Mime Types
*
- * @access protected
* @param string
* @return string
*/
- protected function _mime_types($ext = "")
+ protected function _mime_types($ext = '')
{
- $mimes = array( 'hqx' => 'application/mac-binhex40',
+ $mimes = array(
+ 'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'doc' => 'application/msword',
'bin' => 'application/macbinary',
@@ -1966,11 +1904,10 @@ class CI_Email {
'eml' => 'message/rfc822'
);
- return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
+ return isset($mimes[strtolower($ext)]) ? $mimes[strtolower($ext)] : 'application/x-unknown-content-type';
}
}
-// END CI_Email class
/* End of file Email.php */
/* Location: ./system/libraries/Email.php */
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 0b0618991..b29eb470e 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 0a6a2af0d..3e0c72e84 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -47,14 +47,24 @@ class CI_Form_validation {
protected $_error_suffix = '</p>';
protected $error_string = '';
protected $_safe_form_data = FALSE;
+ protected $validation_data = array();
- /**
- * Constructor
- */
public function __construct($rules = array())
{
$this->CI =& get_instance();
+ // applies delimiters set in config file.
+ if (isset($rules['error_prefix']))
+ {
+ $this->_error_prefix = $rules['error_prefix'];
+ unset($rules['error_prefix']);
+ }
+ if (isset($rules['error_suffix']))
+ {
+ $this->_error_suffix = $rules['error_suffix'];
+ unset($rules['error_suffix']);
+ }
+
// Validation rules can be stored in a config file.
$this->_config_rules = $rules;
@@ -62,12 +72,12 @@ class CI_Form_validation {
$this->CI->load->helper('form');
// Set the character encoding in MB.
- if (function_exists('mb_internal_encoding'))
+ if (MB_ENABLED === TRUE)
{
mb_internal_encoding($this->CI->config->item('charset'));
}
- log_message('debug', "Form Validation Class Initialized");
+ log_message('debug', 'Form Validation Class Initialized');
}
// --------------------------------------------------------------------
@@ -85,12 +95,13 @@ class CI_Form_validation {
public function set_rules($field, $label = '', $rules = '')
{
// No reason to set rules if we have no POST data
- if (count($_POST) === 0)
+ // or a validation array has not been specified
+ if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
{
return $this;
}
- // If an array was passed via the first parameter instead of indidual string
+ // If an array was passed via the first parameter instead of individual string
// values we cycle through it and recursively call this function.
if (is_array($field))
{
@@ -162,10 +173,33 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * By default, form validation uses the $_POST array to validate
+ *
+ * If an array is set through this method, then this array will
+ * be used instead of the $_POST array
+ *
+ * Note that if you are validating multiple arrays, then the
+ * reset_validation() function should be called after validating
+ * each array due to the limitations of CI's singleton
+ *
+ * @param array $data
+ * @return void
+ */
+ public function set_data($data = '')
+ {
+ if ( ! empty($data) && is_array($data))
+ {
+ $this->validation_data = $data;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Set Error Message
*
* Lets users set their own error messages on the fly. Note: The key
- * name has to match the function name that it corresponds to.
+ * name has to match the function name that it corresponds to.
*
* @param string
* @param string
@@ -235,6 +269,20 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Get Array of Error Messages
+ *
+ * Returns the error messages as an array
+ *
+ * @return array
+ */
+ public function error_array()
+ {
+ return $this->_error_array;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Error String
*
* Returns the error messages as a string, wrapped in the error delimiters
@@ -286,7 +334,8 @@ class CI_Form_validation {
public function run($group = '')
{
// Do we even have any data to process? Mm?
- if (count($_POST) === 0)
+ $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
+ if (count($validation_array) === 0)
{
return FALSE;
}
@@ -328,18 +377,18 @@ class CI_Form_validation {
// corresponding $_POST item and test for errors
foreach ($this->_field_data as $field => $row)
{
- // Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
+ // Fetch the data from the corresponding $_POST or validation array and cache it in the _field_data array.
// Depending on whether the field name is an array or a string will determine where we get it from.
if ($row['is_array'] === TRUE)
{
- $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
+ $this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']);
}
else
{
- if (isset($_POST[$field]) AND $_POST[$field] != "")
+ if (isset($validation_array[$field]) AND $validation_array[$field] != "")
{
- $this->_field_data[$field]['postdata'] = $_POST[$field];
+ $this->_field_data[$field]['postdata'] = $validation_array[$field];
}
}
@@ -703,11 +752,11 @@ class CI_Form_validation {
*
* @param string the field name
* @param string
- * @return void
+ * @return string
*/
public function set_value($field = '', $default = '')
{
- if ( ! isset($this->_field_data[$field]))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
return $default;
}
@@ -736,13 +785,9 @@ class CI_Form_validation {
*/
public function set_select($field = '', $value = '', $default = FALSE)
{
- if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
- {
- return ' selected="selected"';
- }
- return '';
+ return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : '';
}
$field = $this->_field_data[$field]['postdata'];
@@ -754,12 +799,9 @@ class CI_Form_validation {
return '';
}
}
- else
+ elseif (($field == '' OR $value == '') OR ($field != $value))
{
- if (($field == '' OR $value == '') OR ($field != $value))
- {
- return '';
- }
+ return '';
}
return ' selected="selected"';
@@ -779,13 +821,9 @@ class CI_Form_validation {
*/
public function set_radio($field = '', $value = '', $default = FALSE)
{
- if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
+ if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
- {
- return ' checked="checked"';
- }
- return '';
+ return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : '';
}
$field = $this->_field_data[$field]['postdata'];
@@ -864,14 +902,13 @@ class CI_Form_validation {
*/
public function matches($str, $field)
{
- if ( ! isset($_POST[$field]))
+ $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
+ if ( ! isset($validation_array[$field]))
{
return FALSE;
}
- $field = $_POST[$field];
-
- return ($str === $field);
+ return ($str === $validation_array[$field]);
}
// --------------------------------------------------------------------
@@ -908,12 +945,12 @@ class CI_Form_validation {
*/
public function min_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
- if (function_exists('mb_strlen'))
+ if (MB_ENABLED === TRUE)
{
return ! (mb_strlen($str) < $val);
}
@@ -932,12 +969,12 @@ class CI_Form_validation {
*/
public function max_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
- if (function_exists('mb_strlen'))
+ if (MB_ENABLED === TRUE)
{
return ! (mb_strlen($str) > $val);
}
@@ -956,12 +993,12 @@ class CI_Form_validation {
*/
public function exact_length($str, $val)
{
- if (preg_match("/[^0-9]/", $val))
+ if (preg_match('/[^0-9]/', $val))
{
return FALSE;
}
- if (function_exists('mb_strlen'))
+ if (MB_ENABLED === TRUE)
{
return (mb_strlen($str) == $val);
}
@@ -1116,7 +1153,7 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
- * Greather than
+ * Greater than
*
* @param string
* @return bool
@@ -1133,6 +1170,23 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Equal to or Greater than
+ *
+ * @param string
+ * @return bool
+ */
+ public function greater_than_equal_to($str, $min)
+ {
+ if ( ! is_numeric($str))
+ {
+ return FALSE;
+ }
+ return $str >= $min;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Less than
*
* @param string
@@ -1150,6 +1204,23 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Equal to or Less than
+ *
+ * @param string
+ * @return bool
+ */
+ public function less_than_equal_to($str, $max)
+ {
+ if ( ! is_numeric($str))
+ {
+ return FALSE;
+ }
+ return $str <= $max;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Is a Natural number (0,1,2,3, etc.)
*
* @param string
@@ -1170,7 +1241,7 @@ class CI_Form_validation {
*/
public function is_natural_no_zero($str)
{
- return ($str != 0 AND preg_match('/^[0-9]+$/', $str));
+ return ($str != 0 && preg_match('/^[0-9]+$/', $str));
}
// --------------------------------------------------------------------
@@ -1217,7 +1288,7 @@ class CI_Form_validation {
return $data;
}
- return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));
+ return str_replace(array("'", '"', '<', '>'), array('&#39;', '&quot;', '&lt;', '&gt;'), stripslashes($data));
}
// --------------------------------------------------------------------
@@ -1282,8 +1353,26 @@ class CI_Form_validation {
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Reset validation vars
+ *
+ * Prevents subsequent validation routines from being affected by the
+ * results of any previous validation routine due to the CI singleton.
+ *
+ * @return void
+ */
+ public function reset_validation()
+ {
+ $this->_field_data = array();
+ $this->_config_rules = array();
+ $this->_error_array = array();
+ $this->_error_messages = array();
+ $this->error_string = '';
+ }
+
}
-// END Form Validation Class
/* End of file Form_validation.php */
/* Location: ./system/libraries/Form_validation.php */
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index ab395b0a0..4d96c00cc 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index a226ae8f8..86b77bf07 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Image Manipulation class
*
@@ -88,12 +86,6 @@ class CI_Image_lib {
protected $wm_use_drop_shadow = FALSE;
public $wm_use_truetype = FALSE;
- /**
- * Constructor
- *
- * @param string
- * @return void
- */
public function __construct($props = array())
{
if (count($props) > 0)
@@ -101,7 +93,7 @@ class CI_Image_lib {
$this->initialize($props);
}
- log_message('debug', "Image Lib Class Initialized");
+ log_message('debug', 'Image Lib Class Initialized');
}
// --------------------------------------------------------------------
@@ -158,9 +150,7 @@ class CI_Image_lib {
*/
public function initialize($props = array())
{
- /*
- * Convert array elements into class variables
- */
+ // Convert array elements into class variables
if (count($props) > 0)
{
foreach ($props as $key => $val)
@@ -195,25 +185,18 @@ class CI_Image_lib {
}
}
- /*
- * Is there a source image?
- *
- * If not, there's no reason to continue
- *
- */
+ // Is there a source image? If not, there's no reason to continue
if ($this->source_image == '')
{
$this->set_error('imglib_source_image_required');
return FALSE;
}
- /*
- * Is getimagesize() Available?
+ /* Is getimagesize() available?
*
* We use it to determine the image properties (width/height).
- * Note: We need to figure out how to determine image
+ * Note: We need to figure out how to determine image
* properties using ImageMagick and NetPBM
- *
*/
if ( ! function_exists('getimagesize'))
{
@@ -223,17 +206,15 @@ class CI_Image_lib {
$this->image_library = strtolower($this->image_library);
- /*
- * Set the full server path
+ /* Set the full server path
*
* The source image may or may not contain a path.
* Either way, we'll try use realpath to generate the
* full server path in order to more reliably read it.
- *
*/
- if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE)
+ if (function_exists('realpath') && @realpath($this->source_image) !== FALSE)
{
- $full_source_path = str_replace("\\", "/", realpath($this->source_image));
+ $full_source_path = str_replace('\\', '/', realpath($this->source_image));
}
else
{
@@ -255,64 +236,58 @@ class CI_Image_lib {
*
* If the user has set a "new_image" name it means
* we are making a copy of the source image. If not
- * it means we are altering the original. We'll
+ * it means we are altering the original. We'll
* set the destination filename and path accordingly.
- *
*/
if ($this->new_image == '')
{
$this->dest_image = $this->source_image;
$this->dest_folder = $this->source_folder;
}
+ elseif (strpos($this->new_image, '/') === FALSE)
+ {
+ $this->dest_folder = $this->source_folder;
+ $this->dest_image = $this->new_image;
+ }
else
{
- if (strpos($this->new_image, '/') === FALSE)
+ if (strpos($this->new_image, '/') === FALSE AND strpos($this->new_image, '\\') === FALSE)
{
- $this->dest_folder = $this->source_folder;
- $this->dest_image = $this->new_image;
+ $full_dest_path = str_replace('\\', '/', realpath($this->new_image));
}
else
{
- if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE)
- {
- $full_dest_path = str_replace("\\", "/", realpath($this->new_image));
- }
- else
- {
- $full_dest_path = $this->new_image;
- }
+ $full_dest_path = $this->new_image;
+ }
- // Is there a file name?
- if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path))
- {
- $this->dest_folder = $full_dest_path.'/';
- $this->dest_image = $this->source_image;
- }
- else
- {
- $x = explode('/', $full_dest_path);
- $this->dest_image = end($x);
- $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
- }
+ // Is there a file name?
+ if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path))
+ {
+ $this->dest_folder = $full_dest_path.'/';
+ $this->dest_image = $this->source_image;
+ }
+ else
+ {
+ $x = explode('/', $full_dest_path);
+ $this->dest_image = end($x);
+ $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
}
}
- /*
- * Compile the finalized filenames/paths
+ /* Compile the finalized filenames/paths
*
* We'll create two master strings containing the
* full server path to the source image and the
* full server path to the destination image.
* We'll also split the destination image name
* so we can insert the thumbnail marker if needed.
- *
*/
if ($this->create_thumb === FALSE OR $this->thumb_marker == '')
{
$this->thumb_marker = '';
}
- $xp = $this->explode_name($this->dest_image);
+ $xp = $this->explode_name($this->dest_image);
$filename = $xp['name'];
$file_ext = $xp['ext'];
@@ -320,54 +295,55 @@ class CI_Image_lib {
$this->full_src_path = $this->source_folder.$this->source_image;
$this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;
- /*
- * Should we maintain image proportions?
+ /* Should we maintain image proportions?
*
* When creating thumbs or copies, the target width/height
* might not be in correct proportion with the source
- * image's width/height. We'll recalculate it here.
- *
+ * image's width/height. We'll recalculate it here.
*/
- if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != ''))
+ if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0))
{
$this->image_reproportion();
}
- /*
- * Was a width and height specified?
- *
- * If the destination width/height was
- * not submitted we will use the values
- * from the actual file
+ /* Was a width and height specified?
*
+ * If the destination width/height was not submitted we
+ * will use the values from the actual file
*/
if ($this->width == '')
+ {
$this->width = $this->orig_width;
+ }
if ($this->height == '')
+ {
$this->height = $this->orig_height;
+ }
// Set the quality
- $this->quality = trim(str_replace("%", "", $this->quality));
+ $this->quality = trim(str_replace('%', '', $this->quality));
- if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality))
+ if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality))
+ {
$this->quality = 90;
+ }
// Set the x/y coordinates
- $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis;
- $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis;
+ $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis;
+ $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis;
// Watermark-related Stuff...
if ($this->wm_overlay_path != '')
{
- $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path));
+ $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path));
}
if ($this->wm_shadow_color != '')
{
$this->wm_use_drop_shadow = TRUE;
}
- elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '')
+ elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '')
{
$this->wm_use_drop_shadow = FALSE;
}
@@ -445,22 +421,16 @@ class CI_Image_lib {
$this->height = $this->orig_height;
}
-
// Choose resizing function
- if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
+ if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm')
{
$protocol = 'image_process_'.$this->image_library;
return $this->$protocol('rotate');
}
- if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt')
- {
- return $this->image_mirror_gd();
- }
- else
- {
- return $this->image_rotate_gd();
- }
+ return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
+ ? $this->image_mirror_gd()
+ : $this->image_rotate_gd();
}
// --------------------------------------------------------------------
@@ -479,9 +449,9 @@ class CI_Image_lib {
// If the target width/height match the source, AND if the new file name is not equal to the old file name
// we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
- if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height)
+ if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height)
{
- if ($this->source_image != $this->new_image AND @copy($this->full_src_path, $this->full_dst_path))
+ if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path))
{
@chmod($this->full_dst_path, FILE_WRITE_MODE);
}
@@ -492,7 +462,7 @@ class CI_Image_lib {
// Let's set up our values based on the action
if ($action == 'crop')
{
- // Reassign the source width/height if cropping
+ // Reassign the source width/height if cropping
$this->orig_width = $this->width;
$this->orig_height = $this->height;
@@ -516,14 +486,15 @@ class CI_Image_lib {
return FALSE;
}
- // Create The Image
- //
- // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
- // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
- // below should that ever prove inaccurate.
- //
- // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE)
- if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
+ /* Create the image
+ *
+ * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
+ * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
+ * below should that ever prove inaccurate.
+ *
+ * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE)
+ */
+ if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
@@ -544,21 +515,17 @@ class CI_Image_lib {
$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
- // Show the image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($dst_img);
}
- else
+ elseif ( ! $this->image_save_gd($dst_img)) // Or save it
{
- // Or save it
- if ( ! $this->image_save_gd($dst_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
@@ -587,42 +554,34 @@ class CI_Image_lib {
return FALSE;
}
- if ( ! preg_match("/convert$/i", $this->library_path))
+ if ( ! preg_match('/convert$/i', $this->library_path))
{
$this->library_path = rtrim($this->library_path, '/').'/convert';
}
// Execute the command
- $cmd = $this->library_path." -quality ".$this->quality;
+ $cmd = $this->library_path.' -quality '.$this->quality;
if ($action == 'crop')
{
- $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1';
}
elseif ($action == 'rotate')
{
- switch ($this->rotation_angle)
- {
- case 'hor' : $angle = '-flop';
- break;
- case 'vrt' : $angle = '-flip';
- break;
- default : $angle = '-rotate '.$this->rotation_angle;
- break;
- }
+ $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
+ ? '-flop' : '-rotate '.$this->rotation_angle;
- $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}
- else // Resize
+ else // Resize
{
- $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
+ $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}
$retval = 1;
-
@exec($cmd, $output, $retval);
- // Did it work?
+ // Did it work?
if ($retval > 0)
{
$this->set_error('imglib_image_process_failed');
@@ -653,7 +612,7 @@ class CI_Image_lib {
return FALSE;
}
- // Build the resizing command
+ // Build the resizing command
switch ($this->image_type)
{
case 1 :
@@ -700,10 +659,9 @@ class CI_Image_lib {
$cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
$retval = 1;
-
@exec($cmd, $output, $retval);
- // Did it work?
+ // Did it work?
if ($retval > 0)
{
$this->set_error('imglib_image_process_failed');
@@ -714,7 +672,7 @@ class CI_Image_lib {
// If you try manipulating the original it fails so
// we have to rename the temp file.
copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
- unlink ($this->dest_folder.'netpbm.tmp');
+ unlink($this->dest_folder.'netpbm.tmp');
@chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
@@ -729,7 +687,7 @@ class CI_Image_lib {
*/
public function image_rotate_gd()
{
- // Create the image handle
+ // Create the image handle
if ( ! ($src_img = $this->image_create_gd()))
{
return FALSE;
@@ -742,29 +700,24 @@ class CI_Image_lib {
$white = imagecolorallocate($src_img, 255, 255, 255);
- // Rotate it!
+ // Rotate it!
$dst_img = imagerotate($src_img, $this->rotation_angle, $white);
- // Save the Image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($dst_img);
}
- else
+ elseif ( ! $this->image_save_gd($dst_img)) // ... or save it
{
- // Or save it
- if ( ! $this->image_save_gd($dst_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
// Set the file to 777
-
@chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
@@ -789,7 +742,7 @@ class CI_Image_lib {
$width = $this->orig_width;
$height = $this->orig_height;
- if ($this->rotation_angle == 'hor')
+ if ($this->rotation_angle === 'hor')
{
for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1)
{
@@ -824,21 +777,17 @@ class CI_Image_lib {
}
}
- // Show the image
+ // Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
}
- else
+ elseif ( ! $this->image_save_gd($src_img)) // ... or save it
{
- // Or save it
- if ( ! $this->image_save_gd($src_img))
- {
- return FALSE;
- }
+ return FALSE;
}
- // Kill the file handles
+ // Kill the file handles
imagedestroy($src_img);
// Set the file to 777
@@ -860,14 +809,7 @@ class CI_Image_lib {
*/
public function watermark()
{
- if ($this->wm_type == 'overlay')
- {
- return $this->overlay_watermark();
- }
- else
- {
- return $this->text_watermark();
- }
+ return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
}
// --------------------------------------------------------------------
@@ -885,28 +827,28 @@ class CI_Image_lib {
return FALSE;
}
- // Fetch source image properties
+ // Fetch source image properties
$this->get_image_properties();
- // Fetch watermark image properties
- $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
+ // Fetch watermark image properties
+ $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
$wm_img_type = $props['image_type'];
- $wm_width = $props['width'];
- $wm_height = $props['height'];
+ $wm_width = $props['width'];
+ $wm_height = $props['height'];
- // Create two image resources
+ // Create two image resources
$wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
$src_img = $this->image_create_gd($this->full_src_path);
// Reverse the offset if necessary
// When the image is positioned at the bottom
// we don't want the vertical offset to push it
- // further down. We want the reverse, so we'll
- // invert the offset. Same with the horizontal
+ // further down. We want the reverse, so we'll
+ // invert the offset. Same with the horizontal
// offset when the image is at the right
- $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
- $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
+ $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
+ $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
if ($this->wm_vrt_alignment == 'B')
$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
@@ -914,34 +856,32 @@ class CI_Image_lib {
if ($this->wm_hor_alignment == 'R')
$this->wm_hor_offset = $this->wm_hor_offset * -1;
- // Set the base x and y axis values
+ // Set the base x and y axis values
$x_axis = $this->wm_hor_offset + $this->wm_padding;
$y_axis = $this->wm_vrt_offset + $this->wm_padding;
- // Set the vertical position
- switch ($this->wm_vrt_alignment)
+ // Set the vertical position
+ if ($this->wm_vrt_alignment === 'M')
{
- case 'T':
- break;
- case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
- break;
- case 'B': $y_axis += $this->orig_height - $wm_height;
- break;
+ $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
+ }
+ elseif ($this->wm_vrt_alignment === 'B')
+ {
+ $y_axis += $this->orig_height - $wm_height;
}
- // Set the horizontal position
- switch ($this->wm_hor_alignment)
+ // Set the horizontal position
+ if ($this->wm_hor_alignment === 'C')
{
- case 'L':
- break;
- case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
- break;
- case 'R': $x_axis += $this->orig_width - $wm_width;
- break;
+ $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
+ }
+ elseif ($this->wm_hor_alignment === 'R')
+ {
+ $x_axis += $this->orig_width - $wm_width;
}
// Build the finalized image
- if ($wm_img_type == 3 AND function_exists('imagealphablending'))
+ if ($wm_img_type == 3 && function_exists('imagealphablending'))
{
@imagealphablending($src_img, TRUE);
}
@@ -963,12 +903,12 @@ class CI_Image_lib {
imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
}
- // Output the image
+ // Output the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
}
- elseif ( ! $this->image_save_gd($src_img))
+ elseif ( ! $this->image_save_gd($src_img)) // ... or save it
{
return FALSE;
}
@@ -993,20 +933,20 @@ class CI_Image_lib {
return FALSE;
}
- if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path))
+ if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path))
{
$this->set_error('imglib_missing_font');
return FALSE;
}
- // Fetch source image properties
+ // Fetch source image properties
$this->get_image_properties();
// Reverse the vertical offset
// When the image is positioned at the bottom
// we don't want the vertical offset to push it
- // further down. We want the reverse, so we'll
- // invert the offset. Note: The horizontal
+ // further down. We want the reverse, so we'll
+ // invert the offset. Note: The horizontal
// offset flips itself automatically
if ($this->wm_vrt_alignment == 'B')
@@ -1039,49 +979,39 @@ class CI_Image_lib {
$x_axis = $this->wm_hor_offset + $this->wm_padding;
$y_axis = $this->wm_vrt_offset + $this->wm_padding;
- // Set verticle alignment
if ($this->wm_use_drop_shadow == FALSE)
$this->wm_shadow_distance = 0;
$this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
$this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
- switch ($this->wm_vrt_alignment)
+ // Set verticle alignment
+ if ($this->wm_vrt_alignment === 'M')
{
- case 'T':
- break;
- case 'M': $y_axis += ($this->orig_height/2)+($fontheight/2);
- break;
- case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2));
- break;
+ $y_axis += ($this->orig_height / 2) + ($fontheight / 2);
+ }
+ elseif ($this->wm_vrt_alignment === 'B')
+ {
+ $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2);
}
$x_shad = $x_axis + $this->wm_shadow_distance;
$y_shad = $y_axis + $this->wm_shadow_distance;
- // Set horizontal alignment
- switch ($this->wm_hor_alignment)
- {
- case 'L':
- break;
- case 'R':
- if ($this->wm_use_drop_shadow)
- {
- $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text));
- $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text));
- }
- break;
- case 'C':
- if ($this->wm_use_drop_shadow)
- {
- $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
- $x_axis += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
- }
- break;
- }
-
if ($this->wm_use_drop_shadow)
{
+ // Set horizontal alignment
+ if ($this->wm_hor_alignment === 'R')
+ {
+ $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text));
+ $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text));
+ }
+ elseif ($this->wm_hor_alignment === 'C')
+ {
+ $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
+ $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
+ }
+
/* Set RGB values for text and shadow
*
* First character is #, so we don't really need it.
@@ -1093,7 +1023,7 @@ class CI_Image_lib {
$drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2);
$drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2]));
- // Add the text to the source image
+ // Add the text to the source image
if ($this->wm_use_truetype)
{
imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
@@ -1106,7 +1036,7 @@ class CI_Image_lib {
}
}
- // Output the final image
+ // Output the final image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($src_img);
@@ -1250,8 +1180,8 @@ class CI_Image_lib {
*/
public function image_display_gd($resource)
{
- header("Content-Disposition: filename={$this->source_image};");
- header("Content-Type: {$this->mime_type}");
+ header('Content-Disposition: filename='.$this->source_image.';');
+ header('Content-Type: '.$this->mime_type);
header('Content-Transfer-Encoding: binary');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
@@ -1284,33 +1214,43 @@ class CI_Image_lib {
*/
public function image_reproportion()
{
- if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0)
- return;
-
- if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0)
- return;
-
- $new_width = ceil($this->orig_width*$this->height/$this->orig_height);
- $new_height = ceil($this->width*$this->orig_height/$this->orig_width);
-
- $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width));
-
- if ($this->master_dim != 'width' AND $this->master_dim != 'height')
+ if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0
+ OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height))
+ OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height))
{
- $this->master_dim = ($ratio < 0) ? 'width' : 'height';
+ return;
}
- if (($this->width != $new_width) AND ($this->height != $new_height))
+ // Sanitize so we don't call preg_match() anymore
+ $this->width = (int) $this->width;
+ $this->height = (int) $this->height;
+
+ if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
{
- if ($this->master_dim == 'height')
+ if ($this->width > 0 && $this->height > 0)
{
- $this->width = $new_width;
+ $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
+ ? 'width' : 'height';
}
else
{
- $this->height = $new_height;
+ $this->master_dim = ($this->height === 0) ? 'width' : 'height';
}
}
+ elseif (($this->master_dim === 'width' && $this->width === 0)
+ OR ($this->master_dim === 'height' && $this->height === 0))
+ {
+ return;
+ }
+
+ if ($this->master_dim === 'width')
+ {
+ $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
+ }
+ else
+ {
+ $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
+ }
}
// --------------------------------------------------------------------
@@ -1329,7 +1269,9 @@ class CI_Image_lib {
// find a way to determine this using IM or NetPBM
if ($path == '')
+ {
$path = $this->full_src_path;
+ }
if ( ! file_exists($path))
{
@@ -1367,15 +1309,15 @@ class CI_Image_lib {
* Size calculator
*
* This function takes a known width x height and
- * recalculates it to a new size. Only one
+ * recalculates it to a new size. Only one
* new variable needs to be known
*
* $props = array(
- * 'width' => $width,
- * 'height' => $height,
- * 'new_width' => 40,
- * 'new_height' => ''
- * );
+ * 'width' => $width,
+ * 'height' => $height,
+ * 'new_width' => 40,
+ * 'new_height' => ''
+ * );
*
* @param array
* @return array
@@ -1419,7 +1361,7 @@ class CI_Image_lib {
*
* This is a helper function that extracts the extension
* from the source_image. This function lets us deal with
- * source_images with multiple periods, like: my.cool.jpg
+ * source_images with multiple periods, like: my.cool.jpg
* It returns an associative array with two elements:
* $array['ext'] = '.jpg';
* $array['name'] = 'my.cool';
@@ -1449,7 +1391,7 @@ class CI_Image_lib {
/* As it is stated in the PHP manual, dl() is not always available
* and even if so - it could generate an E_WARNING message on failure
*/
- return (function_exists('dl') AND @dl('gd.so'));
+ return (function_exists('dl') && @dl('gd.so'));
}
return TRUE;
@@ -1467,9 +1409,7 @@ class CI_Image_lib {
if (function_exists('gd_info'))
{
$gd_version = @gd_info();
- $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']);
-
- return $gd_version;
+ return preg_replace('/\D/', '', $gd_version['GD Version']);
}
return FALSE;
@@ -1516,11 +1456,10 @@ class CI_Image_lib {
*/
public function display_errors($open = '<p>', $close = '</p>')
{
- return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : '';
+ return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
}
}
-// END Image_lib Class
/* End of file Image_lib.php */
/* Location: ./system/libraries/Image_lib.php */
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 33df6007a..9ba93000b 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index 944173fdd..955277acc 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index d07097223..c045ac0e2 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 35ac541e8..86b8d79fa 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index 321248277..290e17fc0 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 89c616543..d84e5d3fc 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -270,7 +270,7 @@ class CI_Profiler {
}
$output .= "<tr><td style='width:50%;color:#000;background-color:#ddd;padding:5px'>&#36;_GET[".$key."]&nbsp;&nbsp; </td><td style='width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;'>"
- . (is_array($val) ? "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>" : htmlspecialchars(stripslashes($val)))
+ . ((is_array($val) OR is_object($val)) ? "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>" : htmlspecialchars(stripslashes($val)))
. "</td></tr>\n";
}
@@ -311,7 +311,7 @@ class CI_Profiler {
}
$output .= "<tr><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>&#36;_POST[".$key."]&nbsp;&nbsp; </td><td style='width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;'>";
- if (is_array($val))
+ if (is_array($val) OR is_object($val))
{
$output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "</pre>";
}
@@ -426,9 +426,9 @@ class CI_Profiler {
. '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_config').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>'
. "\n\n\n<table style='width:100%; display:none' id='ci_profiler_config_table'>\n";
- foreach ($this->CI->config->config as $config=>$val)
+ foreach ($this->CI->config->config as $config => $val)
{
- if (is_array($val))
+ if (is_array($val) OR is_object($val))
{
$val = print_r($val, TRUE);
}
@@ -459,7 +459,7 @@ class CI_Profiler {
foreach ($this->CI->session->all_userdata() as $key => $val)
{
- if (is_array($val) || is_object($val))
+ if (is_array($val) OR is_object($val))
{
$val = print_r($val, TRUE);
}
@@ -501,7 +501,5 @@ class CI_Profiler {
}
}
-// END CI_Profiler class
-
/* End of file Profiler.php */
/* Location: ./system/libraries/Profiler.php */
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 04103a4d9..3a80c1626 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Session Class
*
@@ -50,6 +48,7 @@ class CI_Session {
public $cookie_path = '';
public $cookie_domain = '';
public $cookie_secure = FALSE;
+ public $cookie_httponly = FALSE;
public $sess_time_to_update = 300;
public $encryption_key = '';
public $flashdata_key = 'flash';
@@ -67,14 +66,14 @@ class CI_Session {
*/
public function __construct($params = array())
{
- log_message('debug', "Session Class Initialized");
+ log_message('debug', 'Session Class Initialized');
// Set the super object to a local variable for use throughout the class
$this->CI =& get_instance();
// Set all the session preferences, which can either be set
// manually via the $params array above or via the config file
- foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
+ foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
{
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
}
@@ -93,14 +92,14 @@ class CI_Session {
$this->CI->load->library('encrypt');
}
- // Are we using a database? If so, load it
- if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
+ // Are we using a database? If so, load it
+ if ($this->sess_use_database === TRUE && $this->sess_table_name != '')
{
$this->CI->load->database();
}
- // Set the "now" time. Can either be GMT or server time, based on the
- // config prefs. We use this to set the "last activity" time
+ // Set the "now" time. Can either be GMT or server time, based on the
+ // config prefs. We use this to set the "last activity" time
$this->now = $this->_get_time();
// Set the session length. If the session expiration is
@@ -114,7 +113,7 @@ class CI_Session {
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
// Run the Session routine. If a session doesn't exist we'll
- // create a new one. If it does, we'll update it.
+ // create a new one. If it does, we'll update it.
if ( ! $this->sess_read())
{
$this->sess_create();
@@ -133,7 +132,7 @@ class CI_Session {
// Delete expired sessions if necessary
$this->_sess_gc();
- log_message('debug', "Session routines successfully run");
+ log_message('debug', 'Session routines successfully run');
}
// --------------------------------------------------------------------
@@ -166,7 +165,7 @@ class CI_Session {
$hash = substr($session, strlen($session)-32); // get last 32 chars
$session = substr($session, 0, strlen($session)-32);
- // Does the md5 hash match? This is to prevent manipulation of session data in userspace
+ // Does the md5 hash match? This is to prevent manipulation of session data in userspace
if ($hash !== md5($session.$this->encryption_key))
{
log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
@@ -179,7 +178,7 @@ class CI_Session {
$session = $this->_unserialize($session);
// Is the session data we unserialized an array with the correct format?
- if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity']))
+ if ( ! is_array($session) OR ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], $session['last_activity']))
{
$this->sess_destroy();
return FALSE;
@@ -192,15 +191,15 @@ class CI_Session {
return FALSE;
}
- // Does the IP Match?
- if ($this->sess_match_ip == TRUE AND $session['ip_address'] !== $this->CI->input->ip_address())
+ // Does the IP match?
+ if ($this->sess_match_ip == TRUE && $session['ip_address'] !== $this->CI->input->ip_address())
{
$this->sess_destroy();
return FALSE;
}
// Does the User Agent Match?
- if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
+ if ($this->sess_match_useragent == TRUE && trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
{
$this->sess_destroy();
return FALSE;
@@ -221,9 +220,9 @@ class CI_Session {
$this->CI->db->where('user_agent', $session['user_agent']);
}
- $query = $this->CI->db->get($this->sess_table_name);
+ $query = $this->CI->db->limit(1)->get($this->sess_table_name);
- // No result? Kill it!
+ // No result? Kill it!
if ($query->num_rows() === 0)
{
$this->sess_destroy();
@@ -232,7 +231,7 @@ class CI_Session {
// Is there custom data? If so, add it to the main session array
$row = $query->row();
- if (isset($row->user_data) AND $row->user_data != '')
+ if (isset($row->user_data) && $row->user_data != '')
{
$custom_data = $this->_unserialize($row->user_data);
@@ -282,7 +281,7 @@ class CI_Session {
$cookie_userdata[$val] = $this->userdata[$val];
}
- // Did we find any custom data? If not, we turn the empty array into a string
+ // Did we find any custom data? If not, we turn the empty array into a string
// since there's no reason to serialize and store an empty array in the DB
if (count($custom_userdata) === 0)
{
@@ -298,7 +297,7 @@ class CI_Session {
$this->CI->db->where('session_id', $this->userdata['session_id']);
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
- // Write the cookie. Notice that we manually pass the cookie data array to the
+ // Write the cookie. Notice that we manually pass the cookie data array to the
// _set_cookie() function. Normally that function will store $this->userdata, but
// in this case that array contains custom data, which we do not want in the cookie.
$this->_set_cookie($cookie_userdata);
@@ -324,13 +323,12 @@ class CI_Session {
$sessid .= $this->CI->input->ip_address();
$this->userdata = array(
- 'session_id' => md5(uniqid($sessid, TRUE)),
- 'ip_address' => $this->CI->input->ip_address(),
- 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
- 'last_activity' => $this->now,
- 'user_data' => ''
- );
-
+ 'session_id' => md5(uniqid($sessid, TRUE)),
+ 'ip_address' => $this->CI->input->ip_address(),
+ 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
+ 'last_activity' => $this->now,
+ 'user_data' => ''
+ );
// Save the data to the DB if needed
if ($this->sess_use_database === TRUE)
@@ -357,6 +355,35 @@ class CI_Session {
return;
}
+ // _set_cookie() will handle this for us if we aren't using database sessions
+ // by pushing all userdata to the cookie.
+ $cookie_data = NULL;
+
+ /* Changing the session ID during an AJAX call causes problems,
+ * so we'll only update our last_activity
+ */
+ if ($this->CI->input->is_ajax_request())
+ {
+ $this->userdata['last_activity'] = $this->now;
+
+ // Update the session ID and last_activity field in the DB if needed
+ if ($this->sess_use_database === TRUE)
+ {
+ // set cookie explicitly to only have our session data
+ $cookie_data = array();
+ foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ {
+ $cookie_data[$val] = $this->userdata[$val];
+ }
+
+ $this->CI->db->query($this->CI->db->update_string($this->sess_table_name,
+ array('last_activity' => $this->userdata['last_activity']),
+ array('session_id' => $this->userdata['session_id'])));
+ }
+
+ return $this->_set_cookie($cookie_data);
+ }
+
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
@@ -374,10 +401,6 @@ class CI_Session {
$this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE));
$this->userdata['last_activity'] = $this->now;
- // _set_cookie() will handle this for us if we aren't using database sessions
- // by pushing all userdata to the cookie.
- $cookie_data = NULL;
-
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{
@@ -405,7 +428,7 @@ class CI_Session {
public function sess_destroy()
{
// Kill the session DB row
- if ($this->sess_use_database === TRUE AND isset($this->userdata['session_id']))
+ if ($this->sess_use_database === TRUE && isset($this->userdata['session_id']))
{
$this->CI->db->where('session_id', $this->userdata['session_id']);
$this->CI->db->delete($this->sess_table_name);
@@ -413,13 +436,13 @@ class CI_Session {
// Kill the cookie
setcookie(
- $this->sess_cookie_name,
- addslashes(serialize(array())),
- ($this->now - 31500000),
- $this->cookie_path,
- $this->cookie_domain,
- 0
- );
+ $this->sess_cookie_name,
+ addslashes(serialize(array())),
+ ($this->now - 31500000),
+ $this->cookie_path,
+ $this->cookie_domain,
+ 0
+ );
}
// --------------------------------------------------------------------
@@ -432,7 +455,7 @@ class CI_Session {
*/
public function userdata($item)
{
- return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item];
+ return isset($this->userdata[$item]) ? $this->userdata[$item] : FALSE;
}
// --------------------------------------------------------------------
@@ -446,6 +469,29 @@ class CI_Session {
{
return $this->userdata;
}
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Fetch all flashdata
+ *
+ * @return array
+ */
+ public function all_flashdata()
+ {
+ $out = array();
+
+ // loop through all userdata
+ foreach ($this->all_userdata() as $key => $val)
+ {
+ // if it contains flashdata, add it
+ if (strpos($key, 'flash:old:') !== FALSE)
+ {
+ $out[$key] = $val;
+ }
+ }
+ return $out;
+ }
// --------------------------------------------------------------------
@@ -535,7 +581,7 @@ class CI_Session {
*/
public function keep_flashdata($key)
{
- // 'old' flashdata gets removed. Here we mark all
+ // 'old' flashdata gets removed. Here we mark all
// flashdata as 'new' to preserve it from _flashdata_sweep()
// Note the function will return FALSE if the $key
// provided cannot be found
@@ -586,7 +632,6 @@ class CI_Session {
*
* @return void
*/
-
protected function _flashdata_sweep()
{
$userdata = $this->all_userdata();
@@ -609,13 +654,9 @@ class CI_Session {
*/
protected function _get_time()
{
- if (strtolower($this->time_reference) === 'gmt')
- {
- $now = time();
- return mktime(gmdate('H', $now), gmdate('i', $now), gmdate('s', $now), gmdate('m', $now), gmdate('d', $now), gmdate('Y', $now));
- }
-
- return time();
+ return (strtolower($this->time_reference) === 'gmt')
+ ? mktime(gmdate('H'), gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y'))
+ : time();
}
// --------------------------------------------------------------------
@@ -649,13 +690,14 @@ class CI_Session {
// Set the cookie
setcookie(
- $this->sess_cookie_name,
- $cookie_data,
- $expire,
- $this->cookie_path,
- $this->cookie_domain,
- $this->cookie_secure
- );
+ $this->sess_cookie_name,
+ $cookie_data,
+ $expire,
+ $this->cookie_path,
+ $this->cookie_domain,
+ $this->cookie_secure,
+ $this->cookie_httponly
+ );
}
// --------------------------------------------------------------------
@@ -687,8 +729,11 @@ class CI_Session {
*
* This function converts any slashes found into a temporary marker
*
+ * @param string
+ * @param string
+ * @return void
*/
- function _escape_slashes(&$val, $key)
+ protected function _escape_slashes(&$val, $key)
{
if (is_string($val))
{
@@ -709,7 +754,7 @@ class CI_Session {
*/
protected function _unserialize($data)
{
- $data = @unserialize(strip_slashes($data));
+ $data = @unserialize(strip_slashes(trim($data)));
if (is_array($data))
{
@@ -717,14 +762,19 @@ class CI_Session {
return $data;
}
- return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
+ return is_string($data) ? str_replace('{{slash}}', '\\', $data) : $data;
}
+ // --------------------------------------------------------------------
+
/**
* Unescape slashes
*
* This function converts any slash markers back into actual slashes
*
+ * @param string
+ * @param string
+ * @return void
*/
protected function _unescape_slashes(&$val, $key)
{
@@ -756,16 +806,14 @@ class CI_Session {
{
$expire = $this->now - $this->sess_expiration;
- $this->CI->db->where("last_activity < {$expire}");
+ $this->CI->db->where('last_activity < '.$expire);
$this->CI->db->delete($this->sess_table_name);
log_message('debug', 'Session garbage collection performed.');
}
}
-
}
-// END Session Class
/* End of file Session.php */
/* Location: ./system/libraries/Session.php */
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index fb154e50f..11a4858a9 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* HTML Table Generating Class
*
@@ -49,9 +47,21 @@ class CI_Table {
public $empty_cells = '';
public $function = FALSE;
- public function __construct()
+ /**
+ * Set the template from the table config file if it exists
+ *
+ * @param array $config (default: array())
+ * @return void
+ */
+ public function __construct($config = array())
{
- log_message('debug', "Table Class Initialized");
+ log_message('debug', 'Table Class Initialized');
+
+ // initialize config
+ foreach ($config as $key => $val)
+ {
+ $this->template[$key] = $val;
+ }
}
// --------------------------------------------------------------------
@@ -102,7 +112,7 @@ class CI_Table {
*/
public function make_columns($array = array(), $col_limit = 0)
{
- if ( ! is_array($array) OR count($array) === 0)
+ if ( ! is_array($array) OR count($array) === 0 OR ! is_int($col_limit))
{
return FALSE;
}
@@ -395,7 +405,7 @@ class CI_Table {
// First generate the headings from the table column names
if (count($this->heading) === 0)
{
- if ( ! method_exists($query, 'list_fields'))
+ if ( ! is_callable(array($query, 'list_fields')))
{
return FALSE;
}
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index 79a009133..be1de6f3f 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -141,7 +141,7 @@ class CI_Trackback {
$this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset']));
- if ($val != 'url' && function_exists('mb_convert_encoding'))
+ if ($val != 'url' && MB_ENABLED === TRUE)
{
$_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']);
}
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 46c73ef8b..65e30b089 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 38d767c69..2eb8df356 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 0c63886e7..42664a587 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -1,8 +1,8 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -593,16 +593,17 @@ class CI_Upload {
/**
* Verify that the filetype is allowed
*
+ * @param bool
* @return bool
*/
public function is_allowed_filetype($ignore_mime = FALSE)
{
- if ($this->allowed_types == '*')
+ if ($this->allowed_types === '*')
{
return TRUE;
}
- if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
+ if ( ! is_array($this->allowed_types) OR count($this->allowed_types) === 0)
{
$this->set_error('upload_no_file_types');
return FALSE;
@@ -618,12 +619,9 @@ class CI_Upload {
// Images get some additional checks
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
- if (in_array($ext, $image_types))
+ if (in_array($ext, $image_types) && @getimagesize($this->file_temp) === FALSE)
{
- if (getimagesize($this->file_temp) === FALSE)
- {
- return FALSE;
- }
+ return FALSE;
}
if ($ignore_mime === TRUE)
@@ -640,7 +638,7 @@ class CI_Upload {
return TRUE;
}
}
- elseif ($mime == $this->file_type)
+ elseif ($mime === $this->file_type)
{
return TRUE;
}
@@ -960,7 +958,7 @@ class CI_Upload {
}
elseif (is_file(APPPATH.'config/mimes.php'))
{
- include(APPPATH.'config//mimes.php');
+ include(APPPATH.'config/mimes.php');
}
else
{
@@ -1026,47 +1024,104 @@ class CI_Upload {
*/
protected function _file_mime_type($file)
{
- // Use if the Fileinfo extension, if available (only versions above 5.3 support the FILEINFO_MIME_TYPE flag)
- if ( (float) substr(phpversion(), 0, 3) >= 5.3 && function_exists('finfo_file'))
+ // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
+ $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
+
+ /* Fileinfo extension - most reliable method
+ *
+ * Unfortunately, prior to PHP 5.3 - it's only available as a PECL extension and the
+ * more convenient FILEINFO_MIME_TYPE flag doesn't exist.
+ */
+ if (function_exists('finfo_file'))
{
- $finfo = new finfo(FILEINFO_MIME_TYPE);
- if ($finfo !== FALSE) // This is possible, if there is no magic MIME database file found on the system
+ $finfo = finfo_open(FILEINFO_MIME);
+ if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
{
- $file_type = $finfo->file($file['tmp_name']);
+ $mime = @finfo_file($finfo, $file['tmp_name']);
+ finfo_close($finfo);
/* According to the comments section of the PHP manual page,
* it is possible that this function returns an empty string
* for some files (e.g. if they don't exist in the magic MIME database)
*/
- if (strlen($file_type) > 1)
+ if (is_string($mime) && preg_match($regexp, $mime, $matches))
{
- $this->file_type = $file_type;
+ $this->file_type = $matches[1];
return;
}
}
}
- // Fall back to the deprecated mime_content_type(), if available
- if (function_exists('mime_content_type'))
- {
- $this->file_type = @mime_content_type($file['tmp_name']);
- return;
- }
-
- /* This is an ugly hack, but UNIX-type systems provide a native way to detect the file type,
- * which is still more secure than depending on the value of $_FILES[$field]['type'].
+ /* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
+ * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
+ * was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
+ * than mime_content_type() as well, hence the attempts to try calling the command line with
+ * three different functions.
*
* Notes:
- * - a 'W' in the substr() expression bellow, would mean that we're using Windows
- * - many system admins would disable the exec() function due to security concerns, hence the function_exists() check
+ * - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
+ * - many system admins would disable the exec(), shell_exec(), popen() and similar functions
+ * due to security concerns, hence the function_exists() checks
*/
- if (DIRECTORY_SEPARATOR !== '\\' && function_exists('exec'))
+ if (DIRECTORY_SEPARATOR !== '\\')
+ {
+ $cmd = 'file --brief --mime ' . escapeshellarg($file['tmp_name']) . ' 2>&1';
+
+ if (function_exists('exec'))
+ {
+ /* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
+ * However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites
+ * anything that could already be set for $mime previously. This effectively makes the second parameter a dummy
+ * value, which is only put to allow us to get the return status code.
+ */
+ $mime = @exec($cmd, $mime, $return_status);
+ if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+
+ if ( (bool) @ini_get('safe_mode') === FALSE && function_exists('shell_exec'))
+ {
+ $mime = @shell_exec($cmd);
+ if (strlen($mime) > 0)
+ {
+ $mime = explode("\n", trim($mime));
+ if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+ }
+
+ if (function_exists('popen'))
+ {
+ $proc = @popen($cmd, 'r');
+ if (is_resource($proc))
+ {
+ $mime = @fread($proc, 512);
+ @pclose($proc);
+ if ($mime !== FALSE)
+ {
+ $mime = explode("\n", trim($mime));
+ if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ // Fall back to the deprecated mime_content_type(), if available (still better than $_FILES[$field]['type'])
+ if (function_exists('mime_content_type'))
{
- $output = array();
- @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
- if ($return_code === 0 && strlen($output[0]) > 0) // A return status code != 0 would mean failed execution
+ $this->file_type = @mime_content_type($file['tmp_name']);
+ if (strlen($this->file_type) > 0) // It's possible that mime_content_type() returns FALSE or an empty string
{
- $this->file_type = rtrim($output[0]);
return;
}
}
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index cd644c00d..9109edd0f 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index 730a0fc49..32e2e523b 100644
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 355d43f29..fc41444bc 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 50e84920e..e33eb4e5a 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php
index 03574c66e..f30d7c639 100644
--- a/system/libraries/javascript/Jquery.php
+++ b/system/libraries/javascript/Jquery.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
new file mode 100644
index 000000000..39c24b219
--- /dev/null
+++ b/tests/Bootstrap.php
@@ -0,0 +1,21 @@
+<?php
+
+// Errors on full!
+ini_set('display_errors', 1);
+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.'');
+
+
+// Prep our test environment
+require_once $dir.'/lib/common.php';
+require_once $dir.'/lib/ci_testcase.php';
+
+unset($dir); \ No newline at end of file
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 000000000..6d83c34d8
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,164 @@
+# 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
+
+### Introduction:
+
+This is the preliminary CodeIgniter testing documentation. It
+will cover both internal as well as external APIs and the reasoning
+behind their implemenation, where appropriate. As with all CodeIgniter
+documentation, this file should maintain a mostly human readable
+format to facilitate clean api design. [see http://arrenbrecht.ch/testing/]
+
+*First public draft: everything is subject to change*
+
+### Requirements
+
+PHP Unit >= 3.5.6
+
+ pear channel-discover pear.phpunit.de
+ pear install phpunit/PHPUnit
+
+vfsStream
+
+ pear channel-discover pear.php-tools.net
+ pear install pat/vfsStream-alpha
+
+#### Installation of PEAR and PHPUnit on Ubuntu
+
+ Installation on Ubuntu requires a few steps. Depending on your setup you may
+ need to use 'sudo' to install these. Mileage may vary but these steps are a
+ good start.
+
+ # Install the PEAR package
+ sudo apt-get install php-pear
+
+ # Add a few sources to PEAR
+ pear channel-discover pear.phpunit.de
+ pear channel-discover pear.symfony-project.com
+ pear channel-discover components.ez.no
+ pear channel-discover pear.php-tools.net
+
+ # Finally install PHPUnit and vfsStream (including dependencies)
+ pear install --alldeps phpunit/PHPUnit
+ pear install --alldeps pat/vfsStream-alpha
+
+ # Finally, run 'phpunit' from within the ./tests directory
+ # and you should be on your way!
+
+## Test Suites:
+
+CodeIgniter bootstraps a request very directly, with very flat class
+hierarchy. As a result, there is no main CodeIgniter class until the
+controller is instantiated.
+
+This has forced the core classes to be relatively decoupled, which is
+a good thing. However, it makes that portion of code relatively hard
+to test.
+
+Right now that means we'll probably have two core test suites, along
+with a base for application and package tests. That gives us:
+
+1. Bootstrap Test - test common.php and sanity check codeigniter.php [in planning]
+2. System Test - test core components in relative isolation [in development]
+3. Application Test - bootstrapping for application/tests [not started]
+4. Package Test - bootstrapping for <package>/tests [not started]
+
+### CI_TestCase Documentation
+
+Test cases should extend CI_TestCase. This internally extends
+PHPUnit\_Framework\_TestCase, so you have access to all of your
+usual PHPUnit methods.
+
+We need to provide a simple way to modify the globals and the
+common function output. We also need to be able to mock up
+the super object as we please.
+
+Current API is *not stable*. Names and implementations will change.
+
+ $this->ci_set_config($key, $val)
+
+Set the global config variables. If key is an array, it will
+replace the entire config array. They are _not_ merged.
+
+ $this->ci_instance($obj)
+
+Set the object to use as the "super object", in a lot
+of cases this will be a simple stdClass with the attributes
+you need it to have. If no parameter, will return the instance.
+
+ $this->ci_instance_var($name, $val)
+
+Add an attribute to the super object. This is useful if you
+set up a simple instance in setUp and then need to add different
+class mockups to your super object.
+
+ $this->ci_core_class($name)
+
+Get the _class name_ of a core class, so that you can instantiate
+it. The variable is returned by reference and is tied to the correct
+$GLOBALS key. For example:
+
+ $cfg =& $this->ci_core_class('cfg'); // returns 'CI_Config'
+ $cfg = new $cfg; // instantiates config and overwrites the CFG global
+
+ $this->ci_set_core_class($name, $obj)
+
+An alternative way to set one of the core globals.
+
+ $this->ci_get_config() __internal__
+
+Returns the global config array. Internal as you shouldn't need to
+call this (you're setting it, after all). Used internally to make
+CI's get_config() work.
+
+ CI_TestCase::instance() __internal__
+
+Returns an instance of the current test case. We force phpunit to
+run with backup-globals enabled, so this will always be the instance
+of the currently running test class.
+
+### Going forward
+
+#### 1. Bootstrap Test
+
+Testing common.php should be pretty simple. Include the file, and test the
+functions. May require some tweaking so that we can grab the statics from all
+methods (see is_loaded()). Testing the actual CodeIgniter.php file will most
+likely be an output test for the default view, with some object checking after
+the file runs. Needs consideration.
+
+#### 2. System Test
+
+Testing the core system relies on being able to isolate the core components
+as much as possible. A few of them access other core classes as globals. These
+should be mocked up and easy to manipulate.
+
+All functions in common.php should be a minimal implementation, or and mapped
+to a method in the test's parent class to gives us full control of their output.
+
+#### 3. Application Test:
+
+Not sure yet, needs to handle:
+
+- Libraries
+- Helpers
+- Models
+- MY_* files
+- Controllers (uh...?)
+- Views? (watir, selenium, cucumber?)
+- Database Testing
+
+#### 4. Package Test:
+
+I don't have a clue how this will work.
+
+Needs to be able to handle packages
+that are used multiple times within the application (i.e. EE/Pyro modules)
+as well as packages that are used by multiple applications (library distributions)
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
new file mode 100644
index 000000000..550245f2f
--- /dev/null
+++ b/tests/codeigniter/Setup_test.php
@@ -0,0 +1,13 @@
+<?php
+
+class Setup_test extends PHPUnit_Framework_TestCase {
+
+ function test_nonsense()
+ {
+ $this->markTestIncomplete('not implemented');
+ // ensure that our bootstrapped test environment
+ // is a good representation of an isolated CI install
+ //die('here');
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
new file mode 100644
index 000000000..cec12982d
--- /dev/null
+++ b/tests/codeigniter/core/Common_test.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once(BASEPATH.'helpers/email_helper.php');
+
+class Common_test extends CI_TestCase
+{
+
+ // ------------------------------------------------------------------------
+
+ public function test_is_php()
+ {
+ $this->assertEquals(TRUE, is_php('1.2.0'));
+ $this->assertEquals(FALSE, is_php('9999.9.9'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
new file mode 100644
index 000000000..30f0cc61d
--- /dev/null
+++ b/tests/codeigniter/core/Config_test.php
@@ -0,0 +1,93 @@
+<?php
+
+class Config_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $cls =& $this->ci_core_class('cfg');
+
+ // set predictable config values
+ $this->ci_set_config(array(
+ 'index_page' => 'index.php',
+ 'base_url' => 'http://example.com/',
+ 'subclass_prefix' => 'MY_'
+ ));
+
+ $this->config = new $cls;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_item()
+ {
+ $this->assertEquals('http://example.com/', $this->config->item('base_url'));
+
+ // Bad Config value
+ $this->assertFalse($this->config->item('no_good_item'));
+
+ // Index
+ $this->assertFalse($this->config->item('no_good_item', 'bad_index'));
+ $this->assertFalse($this->config->item('no_good_item', 'default'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_item()
+ {
+ $this->assertFalse($this->config->item('not_yet_set'));
+
+ $this->config->set_item('not_yet_set', 'is set');
+
+ $this->assertEquals('is set', $this->config->item('not_yet_set'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_slash_item()
+ {
+ // Bad Config value
+ $this->assertFalse($this->config->slash_item('no_good_item'));
+
+ $this->assertEquals('http://example.com/', $this->config->slash_item('base_url'));
+
+ $this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_site_url()
+ {
+ $this->assertEquals('http://example.com/index.php', $this->config->site_url());
+
+ $base_url = $this->config->item('base_url');
+
+ $this->config->set_item('base_url', '');
+
+ $q_string = $this->config->item('enable_query_strings');
+
+ $this->config->set_item('enable_query_strings', FALSE);
+
+ $this->assertEquals('index.php/test', $this->config->site_url('test'));
+ $this->assertEquals('index.php/test/1', $this->config->site_url(array('test', '1')));
+
+ $this->config->set_item('enable_query_strings', TRUE);
+
+ $this->assertEquals('index.php?test', $this->config->site_url('test'));
+ $this->assertEquals('index.php?0=test&1=1', $this->config->site_url(array('test', '1')));
+
+ $this->config->set_item('base_url', $base_url);
+
+ $this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test'));
+
+ // back to home base
+ $this->config->set_item('enable_query_strings', $q_string);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_system_url()
+ {
+ $this->assertEquals('http://example.com/system/', $this->config->system_url());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
new file mode 100644
index 000000000..a414f0ace
--- /dev/null
+++ b/tests/codeigniter/core/Lang_test.php
@@ -0,0 +1,31 @@
+<?php
+
+class Lang_test extends CI_TestCase {
+
+ protected $lang;
+
+ public function set_up()
+ {
+ $loader_cls = $this->ci_core_class('load');
+ $this->ci_instance_var('load', new $loader_cls);
+
+ $cls = $this->ci_core_class('lang');
+ $this->lang = new $cls;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_load()
+ {
+ $this->assertTrue($this->lang->load('profiler', 'english'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_line()
+ {
+ $this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
new file mode 100644
index 000000000..b86fd3477
--- /dev/null
+++ b/tests/codeigniter/core/Loader_test.php
@@ -0,0 +1,271 @@
+<?php
+
+require_once 'vfsStream/vfsStream.php';
+require_once BASEPATH.'/core/Loader.php';
+
+class Extended_Loader extends CI_Loader {
+
+ /**
+ * Since we use paths to load up models, views, etc, we need the ability to
+ * mock up the file system so when core tests are run, we aren't mucking
+ * in the application directory. this will give finer grained control over
+ * these tests. So yeah, while this looks odd, I need to overwrite protected
+ * class vars in the loader. So here we go...
+ *
+ * @covers CI_Loader::__construct()
+ */
+ public function __construct()
+ {
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('application'));
+
+ $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot());
+ $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot());
+ $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot());
+ $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot());
+
+ $this->_ci_ob_level = ob_get_level();
+ $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH);
+ $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH);
+ $this->_ci_model_paths = array(vfsStream::url('application').'/');
+ $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE);
+ }
+}
+
+
+class Loader_test extends CI_TestCase {
+
+ private $ci_obj;
+
+ public function set_up()
+ {
+ // Instantiate a new loader
+ $this->load = new Extended_Loader();
+
+ // mock up a ci instance
+ $this->ci_obj = new StdClass;
+
+ // Fix get_instance()
+ $this->ci_instance($this->ci_obj);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_library()
+ {
+ $this->_setup_config_mock();
+
+ // Test loading as an array.
+ $this->assertNull($this->load->library(array('table')));
+ $this->assertTrue(class_exists('CI_Table'), 'Table class exists');
+ $this->assertAttributeInstanceOf('CI_Table', 'table', $this->ci_obj);
+
+ // Test no lib given
+ $this->assertEquals(FALSE, $this->load->library());
+
+ // Test a string given to params
+ $this->assertEquals(NULL, $this->load->library('table', ' '));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_load_library_in_application_dir()
+ {
+ $this->_setup_config_mock();
+
+ $content = '<?php class Super_test_library {} ';
+
+ $model = vfsStream::newFile('Super_test_library.php')->withContent($content)
+ ->at($this->load->libs_dir);
+
+ $this->assertNull($this->load->library('super_test_library'));
+
+ // Was the model class instantiated.
+ $this->assertTrue(class_exists('Super_test_library'));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _setup_config_mock()
+ {
+ // Mock up a config object until we
+ // figure out how to test the library configs
+ $config = $this->getMock('CI_Config', NULL, array(), '', FALSE);
+ $config->expects($this->any())
+ ->method('load')
+ ->will($this->returnValue(TRUE));
+
+ // Add the mock to our stdClass
+ $this->ci_instance_var('config', $config);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_non_existent_model()
+ {
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php'
+ );
+
+ $this->load->model('ci_test_nonexistent_model.php');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * @coverts CI_Loader::model
+ */
+ public function test_models()
+ {
+ $this->ci_set_core_class('model', 'CI_Model');
+
+ $content = '<?php class Unit_test_model extends CI_Model {} ';
+
+ $model = vfsStream::newFile('unit_test_model.php')->withContent($content)
+ ->at($this->load->models_dir);
+
+ $this->assertNull($this->load->model('unit_test_model'));
+
+ // Was the model class instantiated.
+ $this->assertTrue(class_exists('Unit_test_model'));
+
+ // Test no model given
+ $this->assertNull($this->load->model(''));
+ }
+
+ // --------------------------------------------------------------------
+
+ // public function testDatabase()
+ // {
+ // $this->assertEquals(NULL, $this->load->database());
+ // $this->assertEquals(NULL, $this->load->dbutil());
+ // }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * @coverts CI_Loader::view
+ */
+ public function test_load_view()
+ {
+ $this->ci_set_core_class('output', 'CI_Output');
+
+ $content = 'This is my test page. <?php echo $hello; ?>';
+ $view = vfsStream::newFile('unit_test_view.php')->withContent($content)
+ ->at($this->load->views_dir);
+
+ // Use the optional return parameter in this test, so the view is not
+ // run through the output class.
+ $this->assertEquals('This is my test page. World!',
+ $this->load->view('unit_test_view', array('hello' => "World!"), TRUE));
+
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * @coverts CI_Loader::view
+ */
+ public function test_non_existent_view()
+ {
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php'
+ );
+
+ $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_file()
+ {
+ $content = 'Here is a test file, which we will load now.';
+ $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)
+ ->at($this->load->views_dir);
+
+ // Just like load->view(), take the output class out of the mix here.
+ $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php',
+ TRUE);
+
+ $this->assertEquals($content, $load);
+
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: Unable to load the requested file: ci_test_file_not_exists'
+ );
+
+ $this->load->file('ci_test_file_not_exists', TRUE);
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_vars()
+ {
+ $vars = array(
+ 'foo' => 'bar'
+ );
+
+ $this->assertNull($this->load->vars($vars));
+ $this->assertNull($this->load->vars('foo', 'bar'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_helper()
+ {
+ $this->assertEquals(NULL, $this->load->helper('array'));
+
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: Unable to load the requested file: helpers/bad_helper.php'
+ );
+
+ $this->load->helper('bad');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_loading_multiple_helpers()
+ {
+ $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string')));
+ }
+
+ // --------------------------------------------------------------------
+
+ // public function testLanguage()
+ // {
+ // $this->assertEquals(NULL, $this->load->language('test'));
+ // }
+
+ // --------------------------------------------------------------------
+
+ public function test_load_config()
+ {
+ $this->_setup_config_mock();
+
+ $this->assertNull($this->load->config('config', FALSE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_load_bad_config()
+ {
+ $this->_setup_config_mock();
+
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: The configuration file foobar.php does not exist.'
+ );
+
+ $this->load->config('foobar', FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+
+
+
+}
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
new file mode 100644
index 000000000..40252aa14
--- /dev/null
+++ b/tests/codeigniter/core/URI_test.php
@@ -0,0 +1,344 @@
+<?php
+
+require BASEPATH.'core/URI.php';
+
+/**
+ * Extend the URI class
+ * - override contructor
+ * - override CLI detection
+ */
+class URI_extended extends CI_URI {
+
+ public function __construct()
+ {
+ $test = CI_TestCase::instance();
+ $cls =& $test->ci_core_class('cfg');
+
+ // set predictable config values
+ $test->ci_set_config(array(
+ 'index_page' => 'index.php',
+ 'base_url' => 'http://example.com/',
+ 'subclass_prefix' => 'MY_'
+ ));
+
+ $this->config = new $cls;
+
+ }
+
+ protected function _is_cli_request()
+ {
+ return FALSE;
+ }
+}
+
+class URI_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->uri = new URI_extended();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_uri_string()
+ {
+ // Slashes get killed
+ $this->uri->_set_uri_string('/');
+
+ $a = '';
+ $b =& $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ $this->uri->_set_uri_string('nice/uri');
+
+ $a = 'nice/uri';
+
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_fetch_uri_string()
+ {
+ define('SELF', 'index.php');
+
+ // uri_protocol: AUTO
+ $this->uri->config->set_item('uri_protocol', 'AUTO');
+
+ // Test a variety of request uris
+ $requests = array(
+ '/index.php/controller/method' => 'controller/method',
+ '/index.php?/controller/method' => 'controller/method',
+ '/index.php?/controller/method/?var=foo' => 'controller/method'
+ );
+
+ foreach($requests as $request => $expected)
+ {
+ $_SERVER['SCRIPT_NAME'] = '/index.php';
+ $_SERVER['REQUEST_URI'] = $request;
+
+ $this->uri->_fetch_uri_string();
+ $this->assertEquals($expected, $this->uri->uri_string );
+ }
+
+ // Test a subfolder
+ $_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
+ $_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = 'controller/method';
+ $b = $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // death to request uri
+ unset($_SERVER['REQUEST_URI']);
+
+ // life to path info
+ $_SERVER['PATH_INFO'] = '/controller/method/';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = '/controller/method/';
+ $b =& $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // death to path info
+ // At this point your server must be seriously drunk
+ unset($_SERVER['PATH_INFO']);
+
+ $_SERVER['QUERY_STRING'] = '/controller/method/';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = '/controller/method/';
+ $b = $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // At this point your server is a labotomy victim
+
+ unset($_SERVER['QUERY_STRING']);
+
+ $_GET['/controller/method/'] = '';
+
+ $this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $b);
+
+ // Test coverage implies that these will work
+ // uri_protocol: REQUEST_URI
+ // uri_protocol: CLI
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_explode_segments()
+ {
+ // Lets test the function's ability to clean up this mess
+ $uris = array(
+ 'test/uri' => array('test', 'uri'),
+ '/test2/uri2' => array('test2', 'uri2'),
+ '//test3/test3///' => array('test3', 'test3')
+ );
+
+ foreach($uris as $uri => $a)
+ {
+ $this->uri->segments = array();
+ $this->uri->uri_string = $uri;
+ $this->uri->_explode_segments();
+
+ $b = $this->uri->segments;
+
+ $this->assertEquals($a, $b);
+ }
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_filter_uri()
+ {
+ $this->uri->config->set_item('enable_query_strings', FALSE);
+ $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
+
+ $str_in = 'abc01239~%.:_-';
+ $str = $this->uri->_filter_uri($str_in);
+
+ $this->assertEquals($str, $str_in);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_filter_uri_escaping()
+ {
+ // ensure escaping even if dodgey characters are permitted
+
+ $this->uri->config->set_item('enable_query_strings', FALSE);
+ $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$');
+
+ $str = $this->uri->_filter_uri('$destroy_app(foo)');
+
+ $this->assertEquals($str, '&#36;destroy_app&#40;foo&#41;');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_filter_uri_throws_error()
+ {
+ $this->setExpectedException('RuntimeException');
+
+ $this->uri->config->set_item('enable_query_strings', FALSE);
+ $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
+ $this->uri->_filter_uri('$this()');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_remove_url_suffix()
+ {
+ $this->uri->config->set_item('url_suffix', '.html');
+
+ $this->uri->uri_string = 'controller/method/index.html';
+ $this->uri->_remove_url_suffix();
+
+ $this->assertEquals($this->uri->uri_string, 'controller/method/index');
+
+ $this->uri->uri_string = 'controller/method/index.htmlify.html';
+ $this->uri->_remove_url_suffix();
+
+ $this->assertEquals($this->uri->uri_string, 'controller/method/index.htmlify');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_segment()
+ {
+ $this->uri->segments = array(1 => 'controller');
+ $this->assertEquals($this->uri->segment(1), 'controller');
+ $this->assertEquals($this->uri->segment(2, 'default'), 'default');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_rsegment()
+ {
+ $this->uri->rsegments = array(1 => 'method');
+ $this->assertEquals($this->uri->rsegment(1), 'method');
+ $this->assertEquals($this->uri->rsegment(2, 'default'), 'default');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_uri_to_assoc()
+ {
+ $this->uri->segments = array('a', '1', 'b', '2', 'c', '3');
+
+ $a = array('a' => '1', 'b' => '2', 'c' => '3');
+ $b = $this->uri->uri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $a = array('b' => '2', 'c' => '3');
+ $b = $this->uri->uri_to_assoc(3);
+ $this->assertEquals($a, $b);
+
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->segments = array('a', '1', 'b', '2', 'c');
+
+ $a = array('a' => '1', 'b' => '2', 'c' => FALSE);
+ $b = $this->uri->uri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->segments = array('a', '1');
+
+ // test default
+ $a = array('a' => '1', 'b' => FALSE);
+ $b = $this->uri->uri_to_assoc(1, array('a', 'b'));
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_ruri_to_assoc()
+ {
+ $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
+
+ $a = array('x' => '1', 'y' => '2', 'z' => '3');
+ $b = $this->uri->ruri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $a = array('y' => '2', 'z' => '3');
+ $b = $this->uri->ruri_to_assoc(3);
+ $this->assertEquals($a, $b);
+
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->rsegments = array('x', '1', 'y', '2', 'z');
+
+ $a = array('x' => '1', 'y' => '2', 'z' => FALSE);
+ $b = $this->uri->ruri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->rsegments = array('x', '1');
+
+ // test default
+ $a = array('x' => '1', 'y' => FALSE);
+ $b = $this->uri->ruri_to_assoc(1, array('x', 'y'));
+ $this->assertEquals($a, $b);
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_assoc_to_uri()
+ {
+ $this->uri->config->set_item('uri_string_slashes', 'none');
+
+ $arr = array('a' => 1, 'b' => 2);
+ $a = 'a/1/b/2';
+ $b = $this->uri->assoc_to_uri($arr);
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_slash_segment()
+ {
+ $this->uri->segments[1] = 'segment';
+ $this->uri->rsegments[1] = 'segment';
+
+ $a = '/segment/';
+ $b = $this->uri->slash_segment(1, 'both');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'both');
+ $this->assertEquals($a, $b);
+
+ $a = '/segment';
+ $b = $this->uri->slash_segment(1, 'leading');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'leading');
+ $this->assertEquals($a, $b);
+
+ $a = 'segment/';
+ $b = $this->uri->slash_segment(1, 'trailing');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'trailing');
+ $this->assertEquals($a, $b);
+ }
+
+
+}
+// END URI_test Class
+
+/* End of file URI_test.php */
+/* Location: ./tests/core/URI_test.php */
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
new file mode 100644
index 000000000..62559de83
--- /dev/null
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -0,0 +1,49 @@
+<?php
+
+// OLD TEST FORMAT: DO NOT COPY
+
+require_once(BASEPATH.'helpers/array_helper.php');
+
+class Array_helper_test extends CI_TestCase
+{
+ public function set_up()
+ {
+ $this->my_array = array(
+ 'foo' => 'bar',
+ 'sally' => 'jim',
+ 'maggie' => 'bessie',
+ 'herb' => 'cook'
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_element_with_existing_item()
+ {
+ $this->assertEquals(FALSE, element('testing', $this->my_array));
+
+ $this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
+
+ $this->assertEquals('bar', element('foo', $this->my_array));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_random_element()
+ {
+ // Send a string, not an array to random_element
+ $this->assertEquals('my string', random_element('my string'));
+
+ // Test sending an array
+ $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_elements()
+ {
+ $this->assertEquals(TRUE, is_array(elements('test', $this->my_array)));
+ $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array)));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
new file mode 100644
index 000000000..662d16485
--- /dev/null
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -0,0 +1,284 @@
+<?php
+require_once BASEPATH.'helpers/date_helper.php';
+
+class Date_helper_test extends CI_TestCase
+{
+ // ------------------------------------------------------------------------
+
+ public function test_now_local()
+ {
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $config->expects($this->any())
+ ->method('item')
+ ->will($this->returnValue('local'));
+
+ // Add the stub to our test instance
+ $this->ci_instance_var('config', $config);
+
+ $expected = time();
+ $test = now();
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_now_gmt()
+ {
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $config->expects($this->any())
+ ->method('item')
+ ->will($this->returnValue('gmt'));
+
+ // Add the stub to our stdClass
+ $this->ci_instance_var('config', $config);
+
+ $t = time();
+ $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
+ $test = now();
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mdate()
+ {
+ $time = time();
+ $expected = date("Y-m-d - h:i a", $time);
+ $test = mdate("%Y-%m-%d - %h:%i %a", $time);
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc822()
+ {
+ $time = time();
+ $format = 'DATE_RFC822';
+ $expected = date("D, d M y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_atom()
+ {
+ $time = time();
+ $format = 'DATE_ATOM';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_cookie()
+ {
+ $time = time();
+ $format = 'DATE_COOKIE';
+ $expected = date("l, d-M-y H:i:s \U\T\C", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_iso8601()
+ {
+ $time = time();
+ $format = 'DATE_ISO8601';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc850()
+ {
+ $time = time();
+ $format = 'DATE_RFC850';
+ $expected = date("l, d-M-y H:i:s \U\T\C", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1036()
+ {
+ $time = time();
+ $format = 'DATE_RFC1036';
+ $expected = date("D, d M y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1123()
+ {
+ $time = time();
+ $format = 'DATE_RFC1123';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc2822()
+ {
+ $time = time();
+ $format = 'DATE_RFC2822';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rss()
+ {
+ $time = time();
+ $format = 'DATE_RSS';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_w3c()
+ {
+ $time = time();
+ $format = 'DATE_W3C';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_timespan()
+ {
+ $loader_cls = $this->ci_core_class('load');
+ $this->ci_instance_var('load', new $loader_cls);
+
+ $lang_cls = $this->ci_core_class('lang');
+ $this->ci_instance_var('lang', new $lang_cls);
+
+ $this->assertEquals('1 Second', timespan(time(), time()+1));
+ $this->assertEquals('1 Minute', timespan(time(), time()+60));
+ $this->assertEquals('1 Hour', timespan(time(), time()+3600));
+ $this->assertEquals('2 Hours', timespan(time(), time()+7200));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_days_in_month()
+ {
+ $this->assertEquals(30, days_in_month(06, 2005));
+ $this->assertEquals(28, days_in_month(02, 2011));
+ $this->assertEquals(29, days_in_month(02, 2012));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_local_to_gmt()
+ {
+ $t = time();
+ $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
+ $this->assertEquals($expected, local_to_gmt($t));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_gmt_to_local()
+ {
+ $timestamp = '1140153693';
+ $timezone = 'UM8';
+ $daylight_saving = TRUE;
+
+ $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mysql_to_unix()
+ {
+ $time = time();
+ $this->assertEquals($time,
+ mysql_to_unix(date("Y-m-d H:i:s", $time)));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_unix_to_human()
+ {
+ $time = time();
+ $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time));
+ $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us'));
+ $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_human_to_unix()
+ {
+ $date = '2000-12-31 10:00:00 PM';
+ $expected = strtotime($date);
+ $this->assertEquals($expected, human_to_unix($date));
+ $this->assertFalse(human_to_unix());
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_timezones()
+ {
+ $zones = array(
+ 'UM12' => -12,
+ 'UM11' => -11,
+ 'UM10' => -10,
+ 'UM95' => -9.5,
+ 'UM9' => -9,
+ 'UM8' => -8,
+ 'UM7' => -7,
+ 'UM6' => -6,
+ 'UM5' => -5,
+ 'UM45' => -4.5,
+ 'UM4' => -4,
+ 'UM35' => -3.5,
+ 'UM3' => -3,
+ 'UM2' => -2,
+ 'UM1' => -1,
+ 'UTC' => 0,
+ 'UP1' => +1,
+ 'UP2' => +2,
+ 'UP3' => +3,
+ 'UP35' => +3.5,
+ 'UP4' => +4,
+ 'UP45' => +4.5,
+ 'UP5' => +5,
+ 'UP55' => +5.5,
+ 'UP575' => +5.75,
+ 'UP6' => +6,
+ 'UP65' => +6.5,
+ 'UP7' => +7,
+ 'UP8' => +8,
+ 'UP875' => +8.75,
+ 'UP9' => +9,
+ 'UP95' => +9.5,
+ 'UP10' => +10,
+ 'UP105' => +10.5,
+ 'UP11' => +11,
+ 'UP115' => +11.5,
+ 'UP12' => +12,
+ 'UP1275' => +12.75,
+ 'UP13' => +13,
+ 'UP14' => +14
+ );
+
+ foreach ($zones AS $test => $expected)
+ {
+ $this->assertEquals($expected, timezones($test));
+ }
+
+ $this->assertArrayHasKey('UP3', timezones());
+ $this->assertEquals(0, timezones('non_existant'));
+ }
+}
+
+/* End of file date_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
new file mode 100644
index 000000000..3fae81b82
--- /dev/null
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -0,0 +1,42 @@
+<?php
+
+require_once 'vfsStream/vfsStream.php';
+require BASEPATH.'helpers/directory_helper.php';
+
+class Directory_helper_test extends CI_TestCase
+{
+ public function set_up()
+ {
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
+
+ $this->_test_dir = vfsStreamWrapper::getRoot();
+ }
+
+ public function test_directory_map()
+ {
+ $structure = array('libraries' => array('benchmark.html' => '', 'database' =>
+ array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => ''));
+
+ vfsStream::create($structure, $this->_test_dir);
+
+ // test default recursive behavior
+ $expected = array('libraries' => array('benchmark.html', 'database' =>
+ array('active_record.html', 'binds.html'), 'email.html'));
+
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
+
+ // test recursion depth behavior
+ $expected = array('libraries');
+
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1));
+
+ // test detection of hidden files
+ $expected = array('libraries' => array('benchmark.html', 'database' =>
+ array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt'));
+
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
+ }
+}
+
+/* End of file directory_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php
new file mode 100644
index 000000000..7324e8109
--- /dev/null
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once(BASEPATH.'helpers/email_helper.php');
+
+class Email_helper_test extends CI_TestCase
+{
+
+ public function test_valid_email()
+ {
+ $this->assertEquals(FALSE, valid_email('test'));
+ $this->assertEquals(FALSE, valid_email('test@test@test.com'));
+ $this->assertEquals(TRUE, valid_email('test@test.com'));
+ $this->assertEquals(TRUE, valid_email('my.test@test.com'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
new file mode 100644
index 000000000..a596a0375
--- /dev/null
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -0,0 +1,157 @@
+<?php
+
+require_once 'vfsStream/vfsStream.php';
+require BASEPATH.'helpers/file_helper.php';
+
+class File_helper_Test extends CI_TestCase
+{
+ public function set_up()
+ {
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
+
+ $this->_test_dir = vfsStreamWrapper::getRoot();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_read_file()
+ {
+ $this->assertFalse(read_file('does_not_exist'));
+
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+
+ $file = vfsStream::newFile('my_file.txt')->withContent($content)
+ ->at($this->_test_dir);
+
+ $this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_octal_permissions()
+ {
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+
+ $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('777', octal_permissions($file->getPermissions()));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * More tests should happen here, since I'm not hitting the whole function.
+ */
+ public function test_symbolic_permissions()
+ {
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+
+ $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_mime_by_extension()
+ {
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+
+ $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('text/plain',
+ get_mime_by_extension(vfsStream::url('my_file.txt')));
+
+ // Test a mime with an array, such as png
+ $file = vfsStream::newFile('foo.png')->at($this->_test_dir);
+
+ $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
+
+ // Test a file not in the mimes array
+ $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir);
+
+ $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar')));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_file_info()
+ {
+ // Test Bad File
+ $this->assertFalse(get_file_info('i_am_bad_boo'));
+
+ // Test the rest
+
+ // First pass in an array
+ $vals = array(
+ 'name', 'server_path', 'size', 'date',
+ 'readable', 'writable', 'executable', 'fileperms'
+ );
+
+ $this->_test_get_file_info($vals);
+
+ // Test passing in vals as a string.
+ $vals = 'name, server_path, size, date, readable, writable, executable, fileperms';
+ $this->_test_get_file_info($vals);
+ }
+
+ private function _test_get_file_info($vals)
+ {
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ $last_modified = time() - 86400;
+
+ $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
+ ->lastModified($last_modified)
+ ->at($this->_test_dir);
+
+ $ret_values = array(
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
+ 'readable' => TRUE,
+ 'writable' => TRUE,
+ 'executable' => TRUE,
+ 'fileperms' => 33279
+ );
+
+ $info = get_file_info(vfsStream::url('my_file.txt'), $vals);
+
+ foreach ($info as $k => $v)
+ {
+ $this->assertEquals($ret_values[$k], $v);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ // Skipping for now, as it's not implemented in vfsStreamWrapper
+ // flock(): vfsStreamWrapper::stream_lock is not implemented!
+
+ // public function test_write_file()
+ // {
+ // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
+ // {
+ // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
+ // }
+ //
+ // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ //
+ // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
+ // ->lastModified(time() - 86400)
+ // ->at($this->_test_dir);
+ //
+ // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
+ //
+ // }
+
+ // --------------------------------------------------------------------
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php
new file mode 100644
index 000000000..553fc2bb1
--- /dev/null
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -0,0 +1,78 @@
+<?php
+
+require_once(BASEPATH.'helpers/html_helper.php');
+
+class Html_helper_test extends CI_TestCase
+{
+
+ // ------------------------------------------------------------------------
+
+ public function test_br()
+ {
+ $this->assertEquals('<br /><br />', br(2));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_heading()
+ {
+ $this->assertEquals('<h1>foobar</h1>', heading('foobar'));
+ $this->assertEquals('<h2 class="bar">foobar</h2>', heading('foobar', 2, 'class="bar"'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_Ul()
+ {
+ $expect = <<<EOH
+<ul>
+ <li>foo</li>
+ <li>bar</li>
+</ul>
+
+EOH;
+
+ $expect = ltrim($expect);
+
+ $list = array('foo', 'bar');
+
+ $this->assertEquals($expect, ul($list));
+
+
+ $expect = <<<EOH
+<ul class="test">
+ <li>foo</li>
+ <li>bar</li>
+</ul>
+
+EOH;
+
+ $expect = ltrim($expect);
+
+ $list = array('foo', 'bar');
+
+ $this->assertEquals($expect, ul($list, 'class="test"'));
+
+ $this->assertEquals($expect, ul($list, array('class' => 'test')));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_NBS()
+ {
+ $this->assertEquals('&nbsp;&nbsp;&nbsp;', nbs(3));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_meta()
+ {
+ $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
+
+ $expect = "<meta name=\"foo\" content=\"\" />\n";
+
+ $this->assertEquals($expect, meta(array('name' => 'foo')));
+
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php
new file mode 100644
index 000000000..472e28adb
--- /dev/null
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -0,0 +1,93 @@
+<?php
+
+require_once(BASEPATH.'helpers/inflector_helper.php');
+
+class Inflector_helper_test extends CI_TestCase {
+
+
+ public function test_singular()
+ {
+ $strs = array(
+ 'tellies' => 'telly',
+ 'smellies' => 'smelly',
+ 'abjectnesses' => 'abjectness',
+ 'smells' => 'smell',
+ 'equipment' => 'equipment'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, singular($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_plural()
+ {
+ $strs = array(
+ 'telly' => 'tellies',
+ 'smelly' => 'smellies',
+ 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses
+ 'smell' => 'smells',
+ 'witch' => 'witches',
+ 'equipment' => 'equipment'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, plural($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_camelize()
+ {
+ $strs = array(
+ 'this is the string' => 'thisIsTheString',
+ 'this is another one' => 'thisIsAnotherOne',
+ 'i-am-playing-a-trick' => 'i-am-playing-a-trick',
+ 'what_do_you_think-yo?' => 'whatDoYouThink-yo?',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, camelize($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_underscore()
+ {
+ $strs = array(
+ 'this is the string' => 'this_is_the_string',
+ 'this is another one' => 'this_is_another_one',
+ 'i-am-playing-a-trick' => 'i-am-playing-a-trick',
+ 'what_do_you_think-yo?' => 'what_do_you_think-yo?',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, underscore($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_humanize()
+ {
+ $strs = array(
+ 'this_is_the_string' => 'This Is The String',
+ 'this_is_another_one' => 'This Is Another One',
+ 'i-am-playing-a-trick' => 'I-am-playing-a-trick',
+ 'what_do_you_think-yo?' => 'What Do You Think-yo?',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, humanize($str));
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php
new file mode 100644
index 000000000..3322b2475
--- /dev/null
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -0,0 +1,78 @@
+<?php
+
+require_once BASEPATH.'helpers/number_helper.php';
+
+class Number_helper_test extends CI_TestCase
+{
+
+ public function set_up()
+ {
+ // Grab the core lang class
+ $lang_cls = $this->ci_core_class('lang');
+
+ // Mock away load, too much going on in there,
+ // we'll just check for the expected parameter
+
+ $lang = $this->getMock($lang_cls, array('load'));
+ $lang->expects($this->once())
+ ->method('load')
+ ->with($this->equalTo('number'));
+
+ // Assign the proper language array
+
+ $lang->language = $this->_get_lang('number');
+
+ // We don't have a controller, so just create
+ // a cheap class to act as our super object.
+ // Make sure it has a lang attribute.
+
+ $obj = new StdClass;
+ $obj->lang = $lang;
+ $this->ci_instance($obj);
+ }
+
+ // Quick helper to actually grab the language
+ // file. Consider moving this to ci_testcase?
+ public function _get_lang($name)
+ {
+ require BASEPATH.'language/english/'.$name.'_lang.php';
+ return $lang;
+ }
+
+ public function test_byte_format()
+ {
+ $this->assertEquals('456 Bytes', byte_format(456));
+ }
+
+ public function test_kb_format()
+ {
+ $this->assertEquals('4.5 KB', byte_format(4567));
+ }
+
+ public function test_kb_format_medium()
+ {
+ $this->assertEquals('44.6 KB', byte_format(45678));
+ }
+
+ public function test_kb_format_large()
+ {
+ $this->assertEquals('446.1 KB', byte_format(456789));
+ }
+
+ public function test_mb_format()
+ {
+ $this->assertEquals('3.3 MB', byte_format(3456789));
+ }
+
+ public function test_gb_format()
+ {
+ $this->assertEquals('1.8 GB', byte_format(1932735283.2));
+ }
+
+ public function test_tb_format()
+ {
+ $this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
+ }
+}
+
+// EOF \ No newline at end of file
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
new file mode 100644
index 000000000..2e6cc6391
--- /dev/null
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -0,0 +1,29 @@
+<?php
+
+require BASEPATH . 'helpers/path_helper.php';
+
+class Path_helper_test extends CI_TestCase
+{
+ public function test_set_realpath()
+ {
+ $expected = getcwd() . DIRECTORY_SEPARATOR;
+ $this->assertEquals($expected, set_realpath(getcwd()));
+ }
+
+ public function test_set_realpath_nonexistent_directory()
+ {
+ $expected = '/path/to/nowhere';
+ $this->assertEquals($expected, set_realpath('/path/to/nowhere', FALSE));
+ }
+
+ public function test_set_realpath_error_trigger()
+ {
+ $this->setExpectedException(
+ 'RuntimeException', 'CI Error: Not a valid path: /path/to/nowhere'
+ );
+
+ set_realpath('/path/to/nowhere', TRUE);
+ }
+}
+
+/* End of file path_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
new file mode 100644
index 000000000..a884d6284
--- /dev/null
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -0,0 +1,144 @@
+<?php
+
+require_once(BASEPATH.'helpers/string_helper.php');
+
+class String_helper_test extends CI_TestCase
+{
+ public function test_strip_slashes()
+ {
+ $expected = array(
+ "Is your name O'reilly?",
+ "No, my name is O'connor."
+ );
+
+ $str = array(
+ "Is your name O\'reilly?",
+ "No, my name is O\'connor."
+ );
+
+ $this->assertEquals($expected, strip_slashes($str));
+ }
+
+ public function test_trim_slashes()
+ {
+ $strs = array(
+ '//Slashes//\/' => 'Slashes//\\',
+ '/var/www/html/' => 'var/www/html'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, trim_slashes($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_strip_quotes()
+ {
+ $strs = array(
+ '"me oh my!"' => 'me oh my!',
+ "it's a winner!" => 'its a winner!',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, strip_quotes($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_quotes_to_entities()
+ {
+ $strs = array(
+ '"me oh my!"' => '&quot;me oh my!&quot;',
+ "it's a winner!" => 'it&#39;s a winner!',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, quotes_to_entities($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_reduce_double_slashes()
+ {
+ $strs = array(
+ 'http://codeigniter.com' => 'http://codeigniter.com',
+ '//var/www/html/example.com/' => '/var/www/html/example.com/',
+ '/var/www/html//index.php' => '/var/www/html/index.php'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, reduce_double_slashes($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_reduce_multiples()
+ {
+ $strs = array(
+ 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy',
+ 'Ringo, John, Paul,,' => 'Ringo, John, Paul,'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, reduce_multiples($str));
+ }
+
+ $strs = array(
+ 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy',
+ 'Ringo, John, Paul,,' => 'Ringo, John, Paul'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, reduce_multiples($str, ',', TRUE));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_repeater()
+ {
+ $strs = array(
+ 'a' => 'aaaaaaaaaa',
+ '&nbsp;' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+ '<br>' => '<br><br><br><br><br><br><br><br><br><br>'
+
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, repeater($str, 10));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_random_string()
+ {
+ $this->assertEquals(16, strlen(random_string('alnum', 16)));
+ $this->assertEquals(32, strlen(random_string('unique', 16)));
+ $this->assertInternalType('string', random_string('numeric', 16));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_increment_string()
+ {
+ $this->assertEquals('my-test_1', increment_string('my-test'));
+ $this->assertEquals('my-test-1', increment_string('my-test', '-'));
+ $this->assertEquals('file_5', increment_string('file_4'));
+ $this->assertEquals('file-5', increment_string('file-4', '-'));
+ $this->assertEquals('file-5', increment_string('file-4', '-'));
+ $this->assertEquals('file-1', increment_string('file', '-', '1'));
+ $this->assertEquals(124, increment_string('123', ''));
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
new file mode 100644
index 000000000..a0866e638
--- /dev/null
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -0,0 +1,159 @@
+<?php
+
+require_once(BASEPATH.'helpers/text_helper.php');
+
+class Text_helper_test extends CI_TestCase
+{
+ private $_long_string;
+
+ public function set_up()
+ {
+ $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_word_limiter()
+ {
+ $this->assertEquals('Once upon a time,&#8230;', word_limiter($this->_long_string, 4));
+ $this->assertEquals('Once upon a time,&hellip;', word_limiter($this->_long_string, 4, '&hellip;'));
+ $this->assertEquals('', word_limiter('', 4));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_character_limiter()
+ {
+ $this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
+ $this->assertEquals('Once upon a time, a&hellip;', character_limiter($this->_long_string, 20, '&hellip;'));
+ $this->assertEquals('Short', character_limiter('Short', 20));
+ $this->assertEquals('Short', character_limiter('Short', 5));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_ascii_to_entities()
+ {
+ $strs = array(
+ '“‘ “test”' => '&#8220;&#8216; &#8220;test&#8221;',
+ '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, ascii_to_entities($str));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_entities_to_ascii()
+ {
+ $strs = array(
+ '&#8220;&#8216; &#8220;test&#8221;' => '“‘ “test”',
+ '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;' => '†¥¨ˆøåß∂ƒ©˙∆˚¬'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, entities_to_ascii($str));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ function test_convert_accented_characters()
+ {
+ $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ'));
+ $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_censored_words()
+ {
+ $censored = array('boob', 'nerd', 'ass', 'fart');
+
+ $strs = array(
+ 'Ted bobbled the ball' => 'Ted bobbled the ball',
+ 'Jake is a nerdo' => 'Jake is a nerdo',
+ 'The borg will assimilate you' => 'The borg will assimilate you',
+ 'Did Mary Fart?' => 'Did Mary $*#?',
+ 'Jake is really a boob' => 'Jake is really a $*#'
+ );
+
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, word_censor($str, $censored, '$*#'));
+ }
+
+ // test censored words being sent as a string
+ $this->assertEquals('test', word_censor('test', 'test'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_highlight_code()
+ {
+ $code = '<?php var_dump($this); ?>';
+ $expect = "<code><span style=\"color: #000000\">\n<span style=\"color: #0000BB\">&lt;?php&nbsp;var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">);&nbsp;</span><span style=\"color: #0000BB\">?&gt;&nbsp;</span>\n</span>\n</code>";
+
+ $this->assertEquals($expect, highlight_code($code));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_highlight_phrase()
+ {
+ $strs = array(
+ 'this is a phrase' => '<strong>this is</strong> a phrase',
+ 'this is another' => '<strong>this is</strong> another',
+ 'Gimme a test, Sally' => 'Gimme a test, Sally',
+ 'Or tell me what this is' => 'Or tell me what <strong>this is</strong>',
+ '' => ''
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, highlight_phrase($str, 'this is'));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_ellipsizing()
+ {
+ $strs = array(
+ '0' => array(
+ 'this is my string' => '&hellip; my string',
+ "here's another one" => '&hellip;nother one',
+ 'this one is just a bit longer' => '&hellip;bit longer',
+ 'short' => 'short'
+ ),
+ '.5' => array(
+ 'this is my string' => 'this &hellip;tring',
+ "here's another one" => "here'&hellip;r one",
+ 'this one is just a bit longer' => 'this &hellip;onger',
+ 'short' => 'short'
+ ),
+ '1' => array(
+ 'this is my string' => 'this is my&hellip;',
+ "here's another one" => "here's ano&hellip;",
+ 'this one is just a bit longer' => 'this one i&hellip;',
+ 'short' => 'short'
+ ),
+ );
+
+ foreach ($strs as $pos => $s)
+ {
+ foreach ($s as $str => $expect)
+ {
+ $this->assertEquals($expect, ellipsize($str, 10, $pos));
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
new file mode 100644
index 000000000..51a8cc7c0
--- /dev/null
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -0,0 +1,72 @@
+<?php
+
+require_once(BASEPATH.'helpers/url_helper.php');
+
+class Url_helper_test extends CI_TestCase
+{
+ public function test_url_title()
+ {
+ $words = array(
+ 'foo bar /' => 'foo-bar',
+ '\ testing 12' => 'testing-12'
+ );
+
+ foreach ($words as $in => $out)
+ {
+ $this->assertEquals($out, url_title($in, 'dash', TRUE));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_url_title_extra_dashes()
+ {
+ $words = array(
+ '_foo bar_' => 'foo_bar',
+ '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS'
+ );
+
+ foreach ($words as $in => $out)
+ {
+ $this->assertEquals($out, url_title($in, 'underscore'));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_prep_url()
+ {
+ $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com'));
+ $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_auto_link_url()
+ {
+ $strings = array(
+ 'www.codeigniter.com test' => '<a href="http://www.codeigniter.com">http://www.codeigniter.com</a> test',
+ 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test',
+ '<br />www.google.com' => '<br /><a href="http://www.google.com">http://www.google.com</a>',
+ );
+
+ foreach ($strings as $in => $out)
+ {
+ $this->assertEquals($out, auto_link($in, 'url'));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_pull_675()
+ {
+ $strings = array(
+ '<br />www.google.com' => '<br /><a href="http://www.google.com">http://www.google.com</a>',
+ );
+
+ foreach ($strings as $in => $out)
+ {
+ $this->assertEquals($out, auto_link($in, 'url'));
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php
new file mode 100644
index 000000000..49f49e166
--- /dev/null
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -0,0 +1,13 @@
+<?php
+
+require_once(BASEPATH.'helpers/xml_helper.php');
+
+class Xml_helper_test extends CI_TestCase
+{
+
+ public function test_xml_convert()
+ {
+ $this->assertEquals('&lt;tag&gt;my &amp; test &#45; &lt;/tag&gt;', xml_convert('<tag>my & test - </tag>'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
new file mode 100644
index 000000000..b4580a4b1
--- /dev/null
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -0,0 +1,113 @@
+<?php
+
+require BASEPATH.'libraries/Parser.php';
+
+class Parser_test extends CI_TestCase
+{
+
+ public function set_up()
+ {
+ $obj = new StdClass;
+ $obj->parser = new CI_Parser();
+
+ $this->ci_instance($obj);
+
+ $this->parser = $obj->parser;
+ }
+ // --------------------------------------------------------------------
+
+ public function test_set_delimiters()
+ {
+ // Make sure default delimiters are there
+ $this->assertEquals('{', $this->parser->l_delim);
+ $this->assertEquals('}', $this->parser->r_delim);
+
+ // Change them to square brackets
+ $this->parser->set_delimiters('[', ']');
+
+ // Make sure they changed
+ $this->assertEquals('[', $this->parser->l_delim);
+ $this->assertEquals(']', $this->parser->r_delim);
+
+ // Reset them
+ $this->parser->set_delimiters();
+
+ // Make sure default delimiters are there
+ $this->assertEquals('{', $this->parser->l_delim);
+ $this->assertEquals('}', $this->parser->r_delim);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_parse_simple_string()
+ {
+ $data = array(
+ 'title' => 'Page Title',
+ 'body' => 'Lorem ipsum dolor sit amet.'
+ );
+
+ $template = "{title}\n{body}";
+
+ $result = implode("\n", $data);
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_parse()
+ {
+ $this->_parse_no_template();
+ $this->_parse_var_pair();
+ $this->_mismatched_var_pair();
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _parse_no_template()
+ {
+ $this->assertFalse($this->parser->parse_string('', '', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _parse_var_pair()
+ {
+ $data = array(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
+
+ $result = "Super Heroes\nyes\nno";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _mismatched_var_pair()
+ {
+ $data = array(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}";
+
+ $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
new file mode 100644
index 000000000..0208a465a
--- /dev/null
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -0,0 +1,344 @@
+<?php
+
+require BASEPATH.'libraries/Table.php';
+
+class Table_test extends CI_TestCase
+{
+
+ public function set_up()
+ {
+ $obj = new StdClass;
+ $obj->table = new CI_table();
+
+ $this->ci_instance($obj);
+
+ $this->table = $obj->table;
+ }
+
+
+ // Setter Methods
+ // --------------------------------------------------------------------
+
+ public function test_set_template()
+ {
+ $this->assertFalse($this->table->set_template('not an array'));
+
+ $template = array(
+ 'a' => 'b'
+ );
+
+ $this->table->set_template($template);
+ $this->assertEquals($template, $this->table->template);
+ }
+
+ public function test_set_empty()
+ {
+ $this->table->set_empty('nada');
+ $this->assertEquals('nada', $this->table->empty_cells);
+ }
+
+ public function test_set_caption()
+ {
+ $this->table->set_caption('awesome cap');
+ $this->assertEquals('awesome cap', $this->table->caption);
+ }
+
+
+ /*
+ * @depends testPrepArgs
+ */
+ public function test_set_heading()
+ {
+ // uses _prep_args internally, so we'll just do a quick
+ // check to verify that func_get_args and prep_args are
+ // being called.
+
+ $this->table->set_heading('name', 'color', 'size');
+
+ $this->assertEquals(
+ array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'size')
+ ),
+ $this->table->heading
+ );
+ }
+
+
+ /*
+ * @depends testPrepArgs
+ */
+ public function test_add_row()
+ {
+ // uses _prep_args internally, so we'll just do a quick
+ // check to verify that func_get_args and prep_args are
+ // being called.
+
+ $this->table->add_row('my', 'pony', 'sings');
+ $this->table->add_row('your', 'pony', 'stinks');
+ $this->table->add_row('my pony', '>', 'your pony');
+
+ $this->assertEquals(count($this->table->rows), 3);
+
+ $this->assertEquals(
+ array(
+ array('data' => 'your'),
+ array('data' => 'pony'),
+ array('data' => 'stinks')
+ ),
+ $this->table->rows[1]
+ );
+ }
+
+
+ // Uility Methods
+ // --------------------------------------------------------------------
+
+ public function test_prep_args()
+ {
+ $expected = array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'size')
+ );
+
+ // test what would be discreet args,
+ // basically means a single array as the calling method
+ // will use func_get_args()
+
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_prep_args');
+
+ $method->setAccessible(true);
+
+ $this->assertEquals(
+ $expected,
+ $method->invokeArgs(
+ $this->table, array(array('name', 'color', 'size'), 'discreet')
+ )
+ );
+
+ // test what would be a single array argument. Again, nested
+ // due to func_get_args on calling methods
+ $this->assertEquals(
+ $expected,
+ $method->invokeArgs(
+ $this->table, array(array('name', 'color', 'size'), 'array')
+ )
+ );
+
+
+ // with cell attributes
+
+ // need to add that new argument row to our expected outcome
+ $expected[] = array('data' => 'weight', 'class' => 'awesome');
+
+ $this->assertEquals(
+ $expected,
+ $method->invokeArgs(
+ $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes')
+ )
+ );
+ }
+
+ public function test_default_template_keys()
+ {
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_default_template');
+
+ $method->setAccessible(true);
+
+ $deft_template = $method->invoke($this->table);
+ $keys = array(
+ 'table_open',
+ 'thead_open', 'thead_close',
+ 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end',
+ 'tbody_open', 'tbody_close',
+ 'row_start', 'row_end', 'cell_start', 'cell_end',
+ 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
+ 'table_close'
+ );
+
+ foreach ($keys as $key)
+ {
+ $this->assertArrayHasKey($key, $deft_template);
+ }
+ }
+
+ public function test_compile_template()
+ {
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_compile_template');
+
+ $method->setAccessible(true);
+
+ $this->assertFalse($this->table->set_template('invalid_junk'));
+
+ // non default key
+ $this->table->set_template(array('nonsense' => 'foo'));
+ $method->invoke($this->table);
+
+ $this->assertArrayHasKey('nonsense', $this->table->template);
+ $this->assertEquals('foo', $this->table->template['nonsense']);
+
+ // override default
+ $this->table->set_template(array('table_close' => '</table junk>'));
+ $method->invoke($this->table);
+
+ $this->assertArrayHasKey('table_close', $this->table->template);
+ $this->assertEquals('</table junk>', $this->table->template['table_close']);
+ }
+
+ public function test_make_columns()
+ {
+ // Test bogus parameters
+ $this->assertFalse($this->table->make_columns('invalid_junk'));
+ $this->assertFalse($this->table->make_columns(array()));
+ $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5'));
+
+
+ // Now on to the actual column creation
+
+ $five_values = array(
+ 'Laura', 'Red', '15',
+ 'Katie', 'Blue'
+ );
+
+ // No column count - no changes to the array
+ $this->assertEquals(
+ $five_values,
+ $this->table->make_columns($five_values)
+ );
+
+ // Column count of 3 leaves us with one &nbsp;
+ $this->assertEquals(
+ array(
+ array('Laura', 'Red', '15'),
+ array('Katie', 'Blue', '&nbsp;')
+ ),
+ $this->table->make_columns($five_values, 3)
+ );
+ }
+
+ public function test_clear()
+ {
+ $this->table->set_heading('Name', 'Color', 'Size');
+
+ // Make columns changes auto_heading
+ $rows = $this->table->make_columns(array(
+ 'Laura', 'Red', '15',
+ 'Katie', 'Blue'
+ ), 3);
+
+ foreach ($rows as $row)
+ {
+ $this->table->add_row($row);
+ }
+
+ $this->assertFalse($this->table->auto_heading);
+ $this->assertEquals(count($this->table->heading), 3);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $this->table->clear();
+
+ $this->assertTrue($this->table->auto_heading);
+ $this->assertEmpty($this->table->heading);
+ $this->assertEmpty($this->table->rows);
+ }
+
+
+ public function test_set_from_array()
+ {
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_set_from_array');
+
+ $method->setAccessible(true);
+
+ $this->assertFalse($method->invokeArgs($this->table, array('bogus')));
+ $this->assertFalse($method->invoke($this->table, array()));
+
+ $data = array(
+ array('name', 'color', 'number'),
+ array('Laura', 'Red', '22'),
+ array('Katie', 'Blue')
+ );
+
+ $method->invokeArgs($this->table, array($data, FALSE));
+ $this->assertEmpty($this->table->heading);
+
+ $this->table->clear();
+
+ $expected_heading = array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'number')
+ );
+
+ $expected_second = array(
+ array('data' => 'Katie'),
+ array('data' => 'Blue'),
+ );
+
+ $method->invokeArgs($this->table, array($data));
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $this->assertEquals(
+ $expected_heading,
+ $this->table->heading
+ );
+
+ $this->assertEquals(
+ $expected_second,
+ $this->table->rows[1]
+ );
+ }
+
+ function test_set_from_object()
+ {
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_set_from_object');
+
+ $method->setAccessible(true);
+
+ // Make a stub of query instance
+ $query = new CI_TestCase();
+ $query->list_fields = function(){
+ return array('name', 'email');
+ };
+ $query->result_array = function(){
+ return array(
+ array('name' => 'John Doe', 'email' => 'john@doe.com'),
+ array('name' => 'Foo Bar', 'email' => 'foo@bar.com'),
+ );
+ };
+ $query->num_rows = function(){
+ return 2;
+ };
+
+ $expected_heading = array(
+ array('data' => 'name'),
+ array('data' => 'email')
+ );
+
+ $expected_second = array(
+ 'name' => array('data' => 'Foo Bar'),
+ 'email' => array('data' => 'foo@bar.com'),
+ );
+
+ $method->invokeArgs($this->table, array($query));
+
+ $this->assertEquals(
+ $expected_heading,
+ $this->table->heading
+ );
+
+ $this->assertEquals(
+ $expected_second,
+ $this->table->rows[1]
+ );
+ }
+
+ // Test main generate method
+ // --------------------------------------------------------------------
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
new file mode 100644
index 000000000..a0533bae0
--- /dev/null
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -0,0 +1,191 @@
+<?php
+
+require BASEPATH.'libraries/Typography.php';
+
+class Typography_test extends CI_TestCase
+{
+
+ public function set_up()
+ {
+ $obj = new StdClass;
+ $obj->type = new CI_Typography();
+
+ $this->ci_instance($obj);
+
+ $this->type = $obj->type;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Tests the format_characters() function.
+ *
+ * this can and should grow.
+ */
+ public function test_format_characters()
+ {
+ $strs = array(
+ '"double quotes"' => '&#8220;double quotes&#8221;',
+ '"testing" in "theory" that is' => '&#8220;testing&#8221; in &#8220;theory&#8221; that is',
+ "Here's what I'm" => 'Here&#8217;s what I&#8217;m',
+ '&' => '&amp;',
+ '&amp;' => '&amp;',
+ '&nbsp;' => '&nbsp;',
+ '--' => '&#8212;',
+ 'foo...' => 'foo&#8230;',
+ 'foo..' => 'foo..',
+ 'foo...bar.' => 'foo&#8230;bar.',
+ 'test. new' => 'test.&nbsp; new',
+ );
+
+ foreach ($strs as $str => $expected)
+ {
+ $this->assertEquals($expected, $this->type->format_characters($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_nl2br_except_pre()
+ {
+ $str = <<<EOH
+Hello, I'm a happy string with some new lines.
+
+I like to skip.
+
+Jump
+
+and sing.
+
+<pre>
+I am inside a pre tag. Please don't mess with me.
+
+k?
+</pre>
+
+That's my story and I'm sticking to it.
+
+The End.
+EOH;
+
+ $expected = <<<EOH
+Hello, I'm a happy string with some new lines. <br />
+<br />
+I like to skip.<br />
+<br />
+Jump<br />
+<br />
+and sing.<br />
+<br />
+<pre>
+I am inside a pre tag. Please don't mess with me.
+
+k?
+</pre><br />
+<br />
+That's my story and I'm sticking to it.<br />
+<br />
+The End.
+EOH;
+
+ $this->assertEquals($expected,
+ $this->type->nl2br_except_pre($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_auto_typography()
+ {
+ $this->_blank_string();
+ $this->_standardize_new_lines();
+ $this->_reduce_linebreaks();
+ $this->_remove_comments();
+ $this->_protect_pre();
+ $this->_no_opening_block();
+ $this->_protect_braced_quotes();
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _blank_string()
+ {
+ // Test blank string
+ $this->assertEquals('', $this->type->auto_typography(''));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _standardize_new_lines()
+ {
+ $strs = array(
+ "My string\rhas return characters" => "<p>My string<br />\nhas return characters</p>",
+ 'This one does not!' => '<p>This one does not!</p>'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _reduce_linebreaks()
+ {
+ $str = "This has way too many linebreaks.\n\n\n\nSee?";
+ $expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
+
+ $this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _remove_comments()
+ {
+ $str = '<!-- I can haz comments? --> But no!';
+ $expect = '<p><!-- I can haz comments? -->&nbsp; But no!</p>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _protect_pre()
+ {
+ $str = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+ $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _no_opening_block()
+ {
+ $str = 'My Sentence<pre>var_dump($this);</pre>';
+ $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function _protect_braced_quotes()
+ {
+ $this->type->protect_braced_quotes = TRUE;
+
+ $str = 'Test {parse="foobar"}';
+ $expect = '<p>Test {parse="foobar"}</p>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+
+ $this->type->protect_braced_quotes = FALSE;
+
+ $str = 'Test {parse="foobar"}';
+ $expect = '<p>Test {parse=&#8220;foobar&#8221;}</p>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+
+
+ }
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php
new file mode 100644
index 000000000..6f9e87196
--- /dev/null
+++ b/tests/codeigniter/libraries/User_agent_test.php
@@ -0,0 +1,91 @@
+<?php
+
+require BASEPATH.'libraries/User_agent.php';
+
+// This class needs some work...
+
+class UserAgent_test extends CI_TestCase
+{
+ protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
+ protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7';
+
+ public function set_up()
+ {
+ // set a baseline user agent
+ $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
+
+ $obj = new StdClass;
+ $obj->agent = new CI_User_agent();
+
+ $this->ci_instance($obj);
+
+ $this->agent = $obj->agent;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_accept_lang()
+ {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
+ $this->assertTrue($this->agent->accept_lang());
+ unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ $this->assertTrue($this->agent->accept_lang('en'));
+ $this->assertFalse($this->agent->accept_lang('fr'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_mobile()
+ {
+ // Mobile Not Set
+ $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
+ $this->assertEquals('', $this->agent->mobile());
+ unset($_SERVER['HTTP_USER_AGENT']);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_util_is_functions()
+ {
+ $this->assertTrue($this->agent->is_browser());
+ $this->assertFalse($this->agent->is_robot());
+ $this->assertFalse($this->agent->is_mobile());
+ $this->assertFalse($this->agent->is_referral());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_agent_string()
+ {
+ $this->assertEquals($this->_user_agent, $this->agent->agent_string());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_browser_info()
+ {
+ $this->assertEquals('Mac OS X', $this->agent->platform());
+ $this->assertEquals('Safari', $this->agent->browser());
+ $this->assertEquals('533.20.27', $this->agent->version());
+ $this->assertEquals('', $this->agent->robot());
+ $this->assertEquals('', $this->agent->referrer());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_charsets()
+ {
+ $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
+
+ $charsets = $this->agent->charsets();
+
+ $this->assertEquals('utf8', $charsets[0]);
+
+ unset($_SERVER['HTTP_ACCEPT_CHARSET']);
+
+ $this->assertFalse($this->agent->accept_charset());
+ }
+
+ // --------------------------------------------------------------------
+
+} \ No newline at end of file
diff --git a/tests/lib/ci_testcase.php b/tests/lib/ci_testcase.php
new file mode 100644
index 000000000..afccee017
--- /dev/null
+++ b/tests/lib/ci_testcase.php
@@ -0,0 +1,194 @@
+<?php
+
+
+// Need a way to change dependencies (core libs and laoded libs)
+// Need a way to set the CI class
+
+class CI_TestCase extends PHPUnit_Framework_TestCase {
+
+ protected $ci_config;
+ protected $ci_instance;
+ protected static $ci_test_instance;
+
+ private $global_map = array(
+ 'benchmark' => 'bm',
+ 'config' => 'cfg',
+ 'hooks' => 'ext',
+ 'utf8' => 'uni',
+ 'router' => 'rtr',
+ 'output' => 'out',
+ 'security' => 'sec',
+ 'input' => 'in',
+ 'lang' => 'lang',
+ // @todo the loader is an edge case
+ 'loader' => 'load',
+ 'model' => 'model'
+ );
+
+ // --------------------------------------------------------------------
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->ci_config = array();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function setUp()
+ {
+ if (method_exists($this, 'set_up'))
+ {
+ $this->set_up();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function tearDown()
+ {
+ if (method_exists($this, 'tear_down'))
+ {
+ $this->tear_down();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_set_config($key, $val = '')
+ {
+ if (is_array($key))
+ {
+ $this->ci_config = $key;
+ }
+ else
+ {
+ $this->ci_config[$key] = $val;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance($obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance;
+ }
+
+ $this->ci_instance = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance_var($name, $obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance->$name;
+ }
+
+ $this->ci_instance->$name =& $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Grab a core class
+ *
+ * Loads the correct core class without extensions
+ * and returns a reference to the class name in the
+ * globals array with the correct key. This way the
+ * test can modify the variable it assigns to and
+ * still maintain the global.
+ */
+ function &ci_core_class($name)
+ {
+ $name = strtolower($name);
+
+ if (isset($this->global_map[$name]))
+ {
+ $class_name = ucfirst($name);
+ $global_name = $this->global_map[$name];
+ }
+ elseif (in_array($name, $this->global_map))
+ {
+ $class_name = ucfirst(array_search($name, $this->global_map));
+ $global_name = $name;
+ }
+ else
+ {
+ throw new Exception('Not a valid core class.');
+ }
+
+ if ( ! class_exists('CI_'.$class_name))
+ {
+ require_once BASEPATH.'core/'.$class_name.'.php';
+ }
+
+ $GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
+ return $GLOBALS[strtoupper($global_name)];
+ }
+
+ // --------------------------------------------------------------------
+
+ // convenience function for global mocks
+ function ci_set_core_class($name, $obj)
+ {
+ $orig =& $this->ci_core_class($name);
+ $orig = $obj;
+ }
+
+ // --------------------------------------------------------------------
+ // Internals
+ // --------------------------------------------------------------------
+
+ /**
+ * Overwrite runBare
+ *
+ * PHPUnit instantiates the test classes before
+ * running them individually. So right before a test
+ * runs we set our instance. Normally this step would
+ * happen in setUp, but someone is bound to forget to
+ * call the parent method and debugging this is no fun.
+ */
+ public function runBare()
+ {
+ self::$ci_test_instance = $this;
+ parent::runBare();
+ }
+
+ // --------------------------------------------------------------------
+
+ public static function instance()
+ {
+ return self::$ci_test_instance;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_get_config()
+ {
+ return $this->ci_config;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * This overload is useful to create a stub, that need to have a specific method.
+ */
+ function __call($method, $args)
+ {
+ if ($this->{$method} instanceof Closure)
+ {
+ return call_user_func_array($this->{$method},$args);
+ }
+ else
+ {
+ return parent::__call($method, $args);
+ }
+ }
+}
+
+// EOF \ No newline at end of file
diff --git a/tests/lib/common.php b/tests/lib/common.php
new file mode 100644
index 000000000..4a832587d
--- /dev/null
+++ b/tests/lib/common.php
@@ -0,0 +1,132 @@
+<?php
+
+// Set up the global CI functions in their most minimal core representation
+
+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;
+}
+
+function config_item($item)
+{
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
+}
+
+// --------------------------------------------------------------------
+
+function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+{
+ 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;
+}
+
+// This is sort of meh. Should probably be mocked up with
+// controllable output, so that we can test some of our
+// security code. The function itself will be tested in the
+// bootstrap testsuite.
+// --------------------------------------------------------------------
+
+function remove_invisible_characters($str, $url_encoded = TRUE)
+{
+ $non_displayables = array();
+
+ // every control character except newline (dec 10)
+ // carriage return (dec 13), and horizontal tab (dec 09)
+
+ 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);
+
+ return $str;
+}
+
+
+// Clean up error messages
+// --------------------------------------------------------------------
+
+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)
+{
+ throw new RuntimeException('CI Error: 404');
+}
+
+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')
+{
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+}
+
+function is_really_writable($file)
+{
+ return is_writable($file);
+}
+
+function is_loaded()
+{
+ throw new Exception('Bad Isolation: mock up environment');
+}
+
+function log_message($level = 'error', $message, $php_error = FALSE)
+{
+ return TRUE;
+}
+
+function set_status_header($code = 200, $text = '')
+{
+ return TRUE;
+}
+
+// EOF
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 000000000..abb9881b9
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <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>
+ <!-- We'll worry about these later ...
+ <directory suffix="test.php">codeigniter/libraries</directory>
+ <directory suffix="test.php">codeigniter/helpers</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>
+ <whitelist>
+ <!--
+ <directory suffix=".php">'../system/core'</directory>
+ -->
+ </whitelist>
+ </filters>
+</phpunit> \ No newline at end of file
diff --git a/user_guide_src/cilexer/cilexer/cilexer.py b/user_guide_src/cilexer/cilexer/cilexer.py
index 713268e9c..1c41f2aa0 100644
--- a/user_guide_src/cilexer/cilexer/cilexer.py
+++ b/user_guide_src/cilexer/cilexer/cilexer.py
@@ -1,7 +1,7 @@
# CodeIgniter
# http://codeigniter.com
#
-# An open source application development framework for PHP 5.1.6 or newer
+# An open source application development framework for PHP 5.2.4 or newer
#
# NOTICE OF LICENSE
#
diff --git a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css
index b9e28aec0..66768bac6 100644
--- a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css
+++ b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css
@@ -2,7 +2,7 @@
CodeIgniter
http://codeigniter.com
-An open source application development framework for PHP 5.1.6 or newer
+An open source application development framework for PHP 5.2.4 or newer
NOTICE OF LICENSE
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index ec3570393..34d6a0b63 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -19,6 +19,7 @@ Release Date: Not Released
- General Changes
+ - PHP 5.1.6 is no longer supported. CodeIgniter now requires PHP 5.2.4.
- Added an optional backtrace to php-error template.
- Added Android to the list of user agents.
- Added Windows 7 to the list of user platforms.
@@ -28,6 +29,7 @@ Release Date: Not Released
- Added support for 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
- Added support for m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
- Added support for kmz and kml (Google Earth) files to mimes.php.
+ - Updated support for doc files in mimes.php.
- Added application/xml for xml and application/xml, text/xsl for xsl in mimes.php.
- Changed logger to only chmod when file is first created.
- Removed previously deprecated SHA1 Library.
@@ -40,6 +42,13 @@ Release Date: Not Released
- url_title() will now trim extra dashes from beginning and end.
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
- Changed humanize to include a second param for the separator.
+ - Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
+ - Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
+ - Added an optional third parameter to ``timespan()`` that constrains the number of time units displayed.
+ - Added a work-around in force_download() for a bug Android <= 2.1, where the filename extension needs to be in uppercase.
+ - form_dropdown() will now also take an array for unity with other form helpers.
+ - 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.
- Database
@@ -48,13 +57,32 @@ Release Date: Not Released
get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Taking care of LIKE condition when used with MySQL UPDATE statement.
- Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - MySQLi driver now uses mysqli_get_server_info() for server version checking.
+ - MySQLi driver now supports persistent connections when running on PHP >= 5.3.
+ - Added 'dsn' 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 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.
+ - Improved support of the PostgreSQL driver, including:
+ - 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 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 _protect_identifiers() to it instead - it was just an alias.
+ - MySQL and MySQLi drivers now require at least MySQL version 5.1.
+ - db_set_charset() now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1).
+ - Added DSN string support for CUBRID.
+ - Added persistent connections support for CUBRID.
+ - Added DSN string support (Easy Connect and TNS) for Oracle.
- Libraries
- Added max_filename_increment config setting for Upload library.
- CI_Loader::_ci_autoloader() is now a protected method.
- - Modified valid_ip() to use PHP's filter_var() when possible (>= PHP 5.2) in the :doc:`Form Validation library <libraries/form_validation>`.
- - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname)
+ - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname)
- Cart library changes include:
- It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites.
- Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe"
@@ -64,9 +92,19 @@ Release Date: Not Released
- Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them.
- Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method
if they are set manually after initialization.
+ - If property maintain_ratio is set to TRUE, image_reproportion() now doesn't need both width and height to be specified.
- Minor speed optimizations and method & property visibility declarations in the Calendar Library.
- Removed SHA1 function in the :doc:`Encryption Library <libraries/encryption>`.
- Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library <libraries/security>`, which makes token regeneration optional.
+ - Added all_flashdata() method to session class. Returns an associative array of only flashdata.
+ - Allowed for setting table class defaults in a config file.
+ - Form Validation library now allows setting of error delimiters in the config file via $config['error_prefix'] and $config['error_suffix'].
+ - Added function error_array() to return all error messages as an array in the Form_validation class.
+ - Added function set_data() to Form_validation library, which can be used in place of the default $_POST array.
+ - Added function reset_validation() to form validation library, which resets internal validation variables in case of multiple validation routines.
+ - Changed the Session library to select only one row when using database sessions.
+ - Added a Wincache driver to the `Caching Library <libraries/caching>`.
+ - Added dsn (delivery status notification) option to the :doc:`Email Library <libraries/email>`.
- Core
@@ -74,13 +112,16 @@ Release Date: Not Released
- Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
- Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars().
- is_loaded() function from system/core/Commons.php now returns a reference.
+ - $config['rewrite_short_tags'] now has no effect when using PHP 5.4 as *<?=* will always be available.
+ - Added method() to CI_Input to retrieve $_SERVER['REQUEST_METHOD'].
+ - Modified valid_ip() to use PHP's filter_var() in the :doc:`Input Library <libraries/input>`.
+ - Added support for HTTP-Only cookies with new config option ``cookie_httponly`` (default FALSE).
Bug fixes for 3.0
------------------
- Unlink raised an error if cache file did not exist when you try to delete it.
-- Fixed a bug (#181) where a mis-spelling was in the form validation
- language file.
+- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#159, #163) that mishandled Active Record nested transactions because _trans_depth was not getting incremented.
- Fixed a bug (#737, #75) where pagination anchor class was not set properly when using initialize method.
- Fixed a bug (#419) - auto_link() now recognizes URLs that come after a word boundary.
@@ -98,11 +139,63 @@ Bug fixes for 3.0
- In Pagination library, when use_page_numbers=TRUE previous link and page 1 link do not have the same url
- Fixed a bug (#561) - Errors in :doc:`XML-RPC Library <libraries/xmlrpc>` were not properly escaped.
- Fixed a bug (#904) - ``CI_Loader::initialize()`` caused a PHP Fatal error to be triggered if error level E_STRICT is used.
+- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
+- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
+- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
+- Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped.
+- Fixed a bug (#1070) - CI_DB_driver::initialize() didn't set a character set if a database is not selected.
+- Fixed a bug (#177) - CI_Form_validation::set_value() didn't set the default value if POST data is NULL.
+- Fixed a bug (#68, #414) - Oracle's escape_str() didn't properly escape LIKE wild characters.
+- Fixed a bug (#81) - ODBC's list_fields() and field_data() methods skipped the first column due to odbc_field_*() functions' index starting at 1 instead of 0.
+- Fixed a bug (#129) - ODBC's num_rows() returned -1 in some cases, due to not all subdrivers supporting the odbc_num_rows() function.
+- Fixed a bug (#153) - E_NOTICE being generated by getimagesize() in the :doc:`File Uploading Library <libraries/file_uploading>`.
+- Fixed a bug (#611) - SQLSRV's error 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 in PDO's _version() method where it used to return the client version as opposed to the server one.
+- Fixed a bug in PDO's insert_id() method where it could've failed if it's used with Postgre versions prior to 8.1.
+- Fixed a bug in CUBRID's affected_rows() method where a connection resource was passed to cubrid_affected_rows() instead of a result.
+- Fixed a bug (#638) - db_set_charset() ignored its arguments and always used the configured charset instead.
+- Fixed a bug (#413) - Oracle's error handling methods used to only return connection-related errors.
+- Fixed a bug (#804) - Profiler library was trying to handle objects as strings in some cases, resulting in warnings being issued by htmlspecialchars().
+- Fixed a bug (#1101) - MySQL/MySQLi result method field_data() was implemented as if it was handling a DESCRIBE result instead of the actual result set.
+- Fixed a bug in Oracle's :doc:`Database Forge Class <database/forge>` method _create_table() where it failed with AUTO_INCREMENT as it's not supported.
+- Fixed a bug (#1080) - When using the SMTP protocol, the :doc:`Email Library <libraries/email>` send() method was returning TRUE even if the connection/authentication against the server failed.
+- 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 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.
+
+Version 2.1.1
+=============
+
+Release Date: Not Released
+
+- General Changes
+ - Fixed support for docx, xlsx files in mimes.php.
+
+- Libraries
+ - Further improved MIME type detection in the :doc:`File Uploading Library <libraries/file_uploading>`.
+
+- Helpers
+ - url_title() performance and output improved. You can now use any string as the word delimiter, but 'dash' and 'underscore' are still supported.
+
+Bug fixes for 2.1.1
+-------------------
+
+- Fixed a bug (#697) - A wrong array key was used in the Upload library to check for mime-types.
+- Fixed a bug - form_open() compared $action against site_url() instead of base_url().
+- Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
+- Fixed a bug (#538) - Windows paths were ignored when using the :doc:`Image Manipulation Library <libraries/image_lib>` to create a new file.
+- 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
Version 2.1.0
=============
-Release Date: Not Released
+Release Date: November 14, 2011
- General Changes
@@ -160,11 +253,9 @@ Release Date: Not Released
override them.
- Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
-
Bug fixes for 2.1.0
-------------------
-
- Fixed #378 Robots identified as regular browsers by the User Agent
class.
- If a config class was loaded first then a library with the same name
@@ -1163,7 +1254,7 @@ Bug fixes for 1.6.3
- Added a language key for valid_emails in validation_lang.php.
- Amended fixes for bug (#3419) with parsing DSN database connections.
-- Moved the _has_operators() function (#4535) into DB_driver from
+- Moved the _has_operator() function (#4535) into DB_driver from
DB_active_rec.
- Fixed a syntax error in upload_lang.php.
- Fixed a bug (#4542) with a regular expression in the Image library.
diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst
index c04e67d2a..e328c11e2 100644
--- a/user_guide_src/source/database/active_record.rst
+++ b/user_guide_src/source/database/active_record.rst
@@ -68,7 +68,7 @@ Example::
// Produces string: SELECT * FROM mytable
The second parameter enables you to set whether or not the active record query
-will be reset (by default it will be&mdash;just like `$this->db->get()`)::
+will be reset (by default it will be just like `$this->db->get()`)::
echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
// Produces string: SELECT * FROM mytable LIMIT 20, 10
@@ -533,7 +533,7 @@ Query grouping
**************
Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow
-you to create queries with complex WHERE clauses. Nested groups are supported. Example:
+you to create queries with complex WHERE clauses. Nested groups are supported. Example::
$this->db->select('*')->from('my_table')
->group_start()
@@ -921,9 +921,9 @@ Method chaining allows you to simplify your syntax by connecting
multiple functions. Consider this example::
$query = $this->db->select('title')
- ->where('id', $id)
- ->limit(10, 20)
- ->get('mytable');
+ ->where('id', $id)
+ ->limit(10, 20)
+ ->get('mytable');
.. _ar-caching:
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 4f88c25ab..040e7e33f 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -28,6 +28,10 @@ prototype::
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
+If you use PDO as your dbdriver, you can specify the full DSN string describe a connection to the database like this::
+
+ $db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
+
You can also specify failovers for the situation when the main connection cannot connect for some reason.
These failovers can be specified by setting the failover for a connection like this::
diff --git a/user_guide_src/source/database/connecting.rst b/user_guide_src/source/database/connecting.rst
index a834cc0f7..fb4524116 100644
--- a/user_guide_src/source/database/connecting.rst
+++ b/user_guide_src/source/database/connecting.rst
@@ -122,6 +122,12 @@ return the database object.
| $DB1->result();
| etc...
+.. note:: You don't need to create separate database configurations if you
+ only need to use a different database on the same connection. You
+ can switch to a different database when you need to, like this:
+
+ | $this->db->db_select($database2_name);
+
Reconnecting / Keeping the Connection Alive
===========================================
diff --git a/user_guide_src/source/database/helpers.rst b/user_guide_src/source/database/helpers.rst
index 7ea19e9f6..e8a5ac801 100644
--- a/user_guide_src/source/database/helpers.rst
+++ b/user_guide_src/source/database/helpers.rst
@@ -7,9 +7,9 @@ $this->db->insert_id()
The insert ID number when performing database inserts.
-.. note:: If using the PDO driver with PostgreSQL, this function requires
- a $name parameter, which specifies the appropriate sequence to check
- for the insert id.
+.. note:: If using the PDO driver with PostgreSQL, or using the Interbase
+ driver, this function requires a $name parameter, which specifies the
+ appropriate sequence to check for the insert id.
$this->db->affected_rows()
===========================
diff --git a/user_guide_src/source/database/queries.rst b/user_guide_src/source/database/queries.rst
index 971d5d61d..15a73614a 100644
--- a/user_guide_src/source/database/queries.rst
+++ b/user_guide_src/source/database/queries.rst
@@ -112,3 +112,20 @@ The secondary benefit of using binds is that the values are
automatically escaped, producing safer queries. You don't have to
remember to manually escape data; the engine does it automatically for
you.
+
+***************
+Handling Errors
+***************
+
+$this->db->error();
+===================
+
+If you need to get the last error that has occured, the error() method
+will return an array containing its code and message. Here's a quick
+example::
+
+ if ( ! $this->db->simple_query('SELECT `example_field` FROM `example_table`'))
+ {
+ $error = $this->db->error(); // Has keys 'code' and 'message'
+ }
+
diff --git a/user_guide_src/source/database/results.rst b/user_guide_src/source/database/results.rst
index 4f93c794d..865345762 100644
--- a/user_guide_src/source/database/results.rst
+++ b/user_guide_src/source/database/results.rst
@@ -150,6 +150,12 @@ is the variable that the query result object is assigned to::
echo $query->num_rows();
+.. note::
+ Not all database drivers have a native way of getting the total
+ number of rows for a result set. When this is the case, all of
+ the data is prefetched and count() is manually called on the
+ resulting array in order to achieve the same functionality.
+
$query->num_fields()
=====================
@@ -182,5 +188,4 @@ Example::
$row = $query2->row();
echo $row->name;
- $query2->free_result();// The $query2 result object will no longer be available
-
+ $query2->free_result(); // The $query2 result object will no longer be available
diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst
index b0920109f..3805ffb87 100644
--- a/user_guide_src/source/database/utilities.rst
+++ b/user_guide_src/source/database/utilities.rst
@@ -161,7 +161,11 @@ $this->dbutil->backup()
Permits you to backup your full database or individual tables. The
backup data can be compressed in either Zip or Gzip format.
-.. note:: This features is only available for MySQL databases.
+.. note:: This features is only available for MySQL and Interbase/Firebird databases.
+
+.. note:: For Interbase/Firebird databases, the backup file name is the only parameter.
+
+ Eg. $this->dbutil->backup('db_backup_filename');
.. note:: Due to the limited execution time and memory available to PHP,
backing up very large databases may not be possible. If your database is
diff --git a/user_guide_src/source/general/creating_libraries.rst b/user_guide_src/source/general/creating_libraries.rst
index bc545b483..673fbd4bb 100644
--- a/user_guide_src/source/general/creating_libraries.rst
+++ b/user_guide_src/source/general/creating_libraries.rst
@@ -188,17 +188,23 @@ application/libraries/MY_Email.php, and declare your class with::
}
-Note: If you need to use a constructor in your class make sure you
+If you need to use a constructor in your class make sure you
extend the parent constructor::
class MY_Email extends CI_Email {
- public function __construct()
- {
- parent::__construct();
- }
+ public function __construct($config = array())
+ {
+ parent::__construct($config);
+ }
+
}
+.. note::
+ Not all of the libraries have the same (or any) parameters
+ in their constructor. Take a look at the library that you're
+ extending first to see how it should be implemented.
+
Loading Your Sub-class
----------------------
diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst
index 38623557d..05e87961a 100644
--- a/user_guide_src/source/general/requirements.rst
+++ b/user_guide_src/source/general/requirements.rst
@@ -2,7 +2,7 @@
Server Requirements
###################
-- `PHP <http://www.php.net/>`_ version 5.1.6 or newer.
+- `PHP <http://www.php.net/>`_ version 5.2.4 or newer.
- A Database is required for most web application programming. Current
- supported databases are MySQL (4.1+), MySQLi, MS SQL, Postgres, Oracle,
- SQLite, ODBC and CUBRID. \ No newline at end of file
+ supported databases are MySQL (5.1+), MySQLi, MS SQL, SQLSRV, Oracle,
+ PostgreSQL, SQLite, CUBRID, Interbase, ODBC and PDO.
diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst
index ad06dd628..b21d147bd 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -255,14 +255,16 @@ Formats a unix timestamp so that is appears similar to this
The first parameter must contain a Unix timestamp. The second parameter
must contain a timestamp that is greater that the first timestamp. If
-the second parameter empty, the current time will be used. The most
-common purpose for this function is to show how much time has elapsed
-from some point in time in the past to now.
+the second parameter empty, the current time will be used. The third
+parameter is optional and limits the number of time units to display.
+The most common purpose for this function is to show how much time has
+elapsed from some point in time in the past to now.
-.. php:method:: timespan($seconds = 1, $time = '')
+.. php:method:: timespan($seconds = 1, $time = '', $units = '')
:param integer $seconds: a number of seconds
:param string $time: Unix timestamp
+ :param integer $units: a number of time units to display
:returns: string
Example
@@ -271,7 +273,8 @@ Example
$post_date = '1079621429';
$now = time();
- echo timespan($post_date, $now);
+ $units = 2;
+ echo timespan($post_date, $now, $units);
.. note:: The text generated by this function is found in the following language
file: language/<your_lang>/date_lang.php
diff --git a/user_guide_src/source/helpers/form_helper.rst b/user_guide_src/source/helpers/form_helper.rst
index 3794e0835..a110f3c14 100644
--- a/user_guide_src/source/helpers/form_helper.rst
+++ b/user_guide_src/source/helpers/form_helper.rst
@@ -45,7 +45,7 @@ parameter, like this
::
- $attributes = array('class' => 'email', 'id' => 'myform');
+ $attributes = array('class' => 'email', 'id' => 'myform');
echo form_open('email/send', $attributes);
The above example would create a form similar to this
@@ -61,15 +61,15 @@ Hidden fields can be added by passing an associative array to the third paramete
::
- $hidden = array('username' => 'Joe', 'member_id' => '234');
+ $hidden = array('username' => 'Joe', 'member_id' => '234');
echo form_open('email/send', '', $hidden);
The above example would create a form similar to this
::
- <form method="post" accept-charset="utf-8" action="http://example.com/index.php/email/send">
- <input type="hidden" name="username" value="Joe" />
+ <form method="post" accept-charset="utf-8" action="http://example.com/index.php/email/send">
+ <input type="hidden" name="username" value="Joe" />
<input type="hidden" name="member_id" value="234" />
form_open_multipart()
@@ -87,28 +87,67 @@ name/value string to create one field
::
- form_hidden('username', 'johndoe');
+ form_hidden('username', 'johndoe');
// Would produce: <input type="hidden" name="username" value="johndoe" />
Or you can submit an associative array to create multiple fields
::
- $data = array(               
- 'name'  => 'John Doe',               
- 'email' => 'john@example.com',               
- 'url'   => 'http://example.com'             
- );
-
- echo form_hidden($data);
-
+ $data = array(
+ 'name'  => 'John Doe',
+ 'email' => 'john@example.com',
+ 'url'   => 'http://example.com'
+ );
+
+ echo form_hidden($data);
+
/*
- Would produce:
- <input type="hidden" name="name" value="John Doe" />
- <input type="hidden" name="email" value="john@example.com" />
+ Would produce:
+ <input type="hidden" name="name" value="John Doe" />
+ <input type="hidden" name="email" value="john@example.com" />
<input type="hidden" name="url" value="http://example.com" />
*/
+Or pass an associative array to the value field.
+
+::
+
+ $data = array(
+ 'name'  => 'John Doe',
+ 'email' => 'john@example.com',
+ 'url'   => 'http://example.com'
+ );
+
+ echo form_hidden('my_array', $data);
+
+ /*
+ Would produce:
+ <input type="hidden" name="my_array[name]" value="John Doe" />
+ <input type="hidden" name="my_array[email]" value="john@example.com" />
+ <input type="hidden" name="my_array[url]" value="http://example.com" />
+ */
+
+If you want to create hidden input fields with extra attributes
+
+::
+
+ $data = array(
+ 'type'        => 'hidden',
+ 'name'        => 'email',
+ 'id'          => 'hiddenemail',
+ 'value'       => 'john@example.com',
+ 'class'       => 'hiddenemail'
+ );
+
+ echo form_input($data);
+
+ /*
+ Would produce:
+
+ <input type="hidden" name="email" value="john@example.com" id="hiddenemail" class="hiddenemail" />
+ */
+
form_input()
============
@@ -124,21 +163,21 @@ form to contain
::
- $data = array(               
- 'name'        => 'username',               
- 'id'          => 'username',               
- 'value'       => 'johndoe',               
- 'maxlength'   => '100',               
- 'size'        => '50',               
- 'style'       => 'width:50%',             
- );
-
+ $data = array(
+ 'name'        => 'username',
+ 'id'          => 'username',
+ 'value'       => 'johndoe',
+ 'maxlength'   => '100',
+ 'size'        => '50',
+ 'style'       => 'width:50%'
+ );
+
echo form_input($data);
-
+
/*
Would produce:
-
- <input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" />
+
+ <input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
*/
If you would like your form to contain some additional data, like
@@ -146,7 +185,7 @@ Javascript, you can pass it as a string in the third parameter
::
- $js = 'onClick="some_function()"';
+ $js = 'onClick="some_function()"';
echo form_input('username', 'johndoe', $js);
form_password()
@@ -176,37 +215,37 @@ multiple select for you. Example
::
- $options = array(                   
- 'small'  => 'Small Shirt',                   
- 'med'    => 'Medium Shirt',                   
- 'large'   => 'Large Shirt',                   
- 'xlarge' => 'Extra Large Shirt',                 
- );
-
- $shirts_on_sale = array('small', 'large');
- echo form_dropdown('shirts', $options, 'large');
-
+ $options = array(
+ 'small'  => 'Small Shirt',
+ 'med'    => 'Medium Shirt',
+ 'large'   => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
+ );
+
+ $shirts_on_sale = array('small', 'large');
+ echo form_dropdown('shirts', $options, 'large');
+
/*
- Would produce:
-
- <select name="shirts">
- <option value="small">Small Shirt</option>
- <option value="med">Medium Shirt</option>
- <option value="large" selected="selected">Large Shirt</option>
- <option value="xlarge">Extra Large Shirt</option>
+ Would produce:
+
+ <select name="shirts">
+ <option value="small">Small Shirt</option>
+ <option value="med">Medium Shirt</option>
+ <option value="large" selected="selected">Large Shirt</option>
+ <option value="xlarge">Extra Large Shirt</option>
</select>
*/
-
+
echo form_dropdown('shirts', $options, $shirts_on_sale);
-
+
/*
- Would produce:
-
- <select name="shirts" multiple="multiple">
- <option value="small" selected="selected">Small Shirt</option>
- <option value="med">Medium Shirt</option>
- <option value="large" selected="selected">Large Shirt</option>
- <option value="xlarge">Extra Large Shirt</option>
+ Would produce:
+
+ <select name="shirts" multiple="multiple">
+ <option value="small" selected="selected">Small Shirt</option>
+ <option value="med">Medium Shirt</option>
+ <option value="large" selected="selected">Large Shirt</option>
+ <option value="xlarge">Extra Large Shirt</option>
</select>
*/
@@ -216,7 +255,7 @@ parameter
::
- $js = 'id="shirts" onChange="some_function();"';
+ $js = 'id="shirts" onChange="some_function();"';
echo form_dropdown('shirts', $options, 'large', $js);
If the array passed as $options is a multidimensional array,
@@ -240,38 +279,38 @@ Lets you generate fieldset/legend fields.
::
- echo form_fieldset('Address Information');
- echo "<p>fieldset content here</p>\n";
+ echo form_fieldset('Address Information');
+ echo "<p>fieldset content here</p>\n";
echo form_fieldset_close();
-
+
/*
Produces:
- <fieldset>
- <legend>Address Information</legend>
- <p>form content here</p>
+ <fieldset>
+ <legend>Address Information</legend>
+ <p>form content here</p>
</fieldset>
*/
-
+
Similar to other functions, you can submit an associative array in the
second parameter if you prefer to set additional attributes.
::
$attributes = array(
- 'id' => 'address_info',
+ 'id' => 'address_info',
'class' => 'address_info'
- );
-
- echo form_fieldset('Address Information', $attributes);
- echo "<p>fieldset content here</p>\n";
- echo form_fieldset_close();
-
+ );
+
+ echo form_fieldset('Address Information', $attributes);
+ echo "<p>fieldset content here</p>\n";
+ echo form_fieldset_close();
+
/*
- Produces:
-
- <fieldset id="address_info" class="address_info">
- <legend>Address Information</legend>
- <p>form content here</p>
+ Produces:
+
+ <fieldset id="address_info" class="address_info">
+ <legend>Address Information</legend>
+ <p>form content here</p>
</fieldset>
*/
@@ -284,9 +323,9 @@ the tag. For example
::
- $string = "</div></div>";
- echo form_fieldset_close($string);
- // Would produce: </fieldset> </div></div>
+ $string = "</div></div>";
+ echo form_fieldset_close($string);
+ // Would produce: </fieldset></div></div>
form_checkbox()
===============
@@ -295,7 +334,7 @@ Lets you generate a checkbox field. Simple example
::
- echo form_checkbox('newsletter', 'accept', TRUE);
+ echo form_checkbox('newsletter', 'accept', TRUE);
// Would produce: <input type="checkbox" name="newsletter" value="accept" checked="checked" />
The third parameter contains a boolean TRUE/FALSE to determine whether
@@ -306,15 +345,15 @@ array of attributes to the function
::
- $data = array(     
- 'name'        => 'newsletter',     
- 'id'          => 'newsletter',     
- 'value'       => 'accept',     
- 'checked'     => TRUE,     
- 'style'       => 'margin:10px',     
- );
-
- echo form_checkbox($data);
+ $data = array(
+ 'name'        => 'newsletter',
+ 'id'          => 'newsletter',
+ 'value'       => 'accept',
+ 'checked'     => TRUE,
+ 'style'       => 'margin:10px',
+ );
+
+ echo form_checkbox($data);
// Would produce: <input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />
As with other functions, if you would like the tag to contain additional
@@ -323,7 +362,7 @@ parameter
::
- $js = 'onClick="some_function()"';
+ $js = 'onClick="some_function()"';
echo form_checkbox('newsletter', 'accept', TRUE, $js)
form_radio()
@@ -339,7 +378,7 @@ Lets you generate a standard submit button. Simple example
::
- echo form_submit('mysubmit', 'Submit Post!');
+ echo form_submit('mysubmit', 'Submit Post!');
// Would produce: <input type="submit" name="mysubmit" value="Submit Post!" />
Similar to other functions, you can submit an associative array in the
@@ -353,7 +392,7 @@ Lets you generate a <label>. Simple example
::
- echo form_label('What is your Name', 'username');
+ echo form_label('What is your Name', 'username');
// Would produce: <label for="username">What is your Name</label>
Similar to other functions, you can submit an associative array in the
@@ -361,12 +400,12 @@ third parameter if you prefer to set additional attributes.
::
- $attributes = array(     
- 'class' => 'mycustomclass',     
+ $attributes = array(
+ 'class' => 'mycustomclass',
'style' => 'color: #000;'
- );
-
- echo form_label('What is your Name', 'username', $attributes);
+ );
+
+ echo form_label('What is your Name', 'username', $attributes);
// Would produce: <label for="username" class="mycustomclass" style="color: #000;">What is your Name</label>
@@ -384,7 +423,7 @@ button name and content in the first and second parameter
::
- echo form_button('name','content');
+ echo form_button('name','content');
// Would produce <button name="name" type="button">Content</button>
Or you can pass an associative array containing any data you wish your
@@ -392,15 +431,15 @@ form to contain:
::
- $data = array(     
- 'name' => 'button',     
- 'id' => 'button',     
- 'value' => 'true',     
- 'type' => 'reset',     
- 'content' => 'Reset'
- );
-
- echo form_button($data);
+ $data = array(
+ 'name' => 'button',
+ 'id' => 'button',
+ 'value' => 'true',
+ 'type' => 'reset',
+ 'content' => 'Reset'
+ );
+
+ echo form_button($data);
// Would produce: <button name="button" id="button" value="true" type="reset">Reset</button>
If you would like your form to contain some additional data, like
@@ -408,7 +447,7 @@ JavaScript, you can pass it as a string in the third parameter:
::
- $js = 'onClick="some_function()"';
+ $js = 'onClick="some_function()"';
echo form_button('mybutton', 'Click Me', $js);
form_close()
@@ -420,8 +459,8 @@ the tag. For example
::
- $string = "</div></div>";
- echo form_close($string);
+ $string = "</div></div>";
+ echo form_close($string);
// Would produce: </form> </div></div>
form_prep()
@@ -432,7 +471,7 @@ elements without breaking out of the form. Consider this example
::
- $string = 'Here is a string containing "quoted" text.';
+ $string = 'Here is a string containing "quoted" text.';
<input type="text" name="myform" value="$string" />
Since the above string contains a set of quotes it will cause the form
@@ -475,9 +514,9 @@ Example
::
<select name="myselect">
- <option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
- <option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
- <option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
+ <option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
+ <option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
+ <option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
</select>
set_checkbox()
@@ -490,7 +529,7 @@ lets you set an item as the default (use boolean TRUE/FALSE). Example
::
- <input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> />
+ <input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> />
<input type="checkbox" name="mycheck" value="2" <?php echo set_checkbox('mycheck', '2'); ?> />
set_radio()
@@ -501,6 +540,6 @@ This function is identical to the **set_checkbox()** function above.
::
- <input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
+ <input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />
diff --git a/user_guide_src/source/helpers/path_helper.rst b/user_guide_src/source/helpers/path_helper.rst
index 1a70af458..847f5a08b 100644
--- a/user_guide_src/source/helpers/path_helper.rst
+++ b/user_guide_src/source/helpers/path_helper.rst
@@ -28,10 +28,16 @@ cannot be resolved.
::
- $directory = '/etc/passwd';
- echo set_realpath($directory); // returns "/etc/passwd"
- $non_existent_directory = '/path/to/nowhere';
- echo set_realpath($non_existent_directory, TRUE); // returns an error, as the path could not be resolved
- echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere"
-
-
+ $file = '/etc/php5/apache2/php.ini';
+ echo set_realpath($file); // returns "/etc/php5/apache2/php.ini"
+
+ $non_existent_file = '/path/to/non-exist-file.txt';
+ echo set_realpath($non_existent_file, TRUE); // shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_file, FALSE); // returns "/path/to/non-exist-file.txt"
+
+ $directory = '/etc/php5';
+ echo set_realpath($directory); // returns "/etc/php5/"
+
+ $non_existent_directory = '/path/to/nowhere';
+ echo set_realpath($non_existent_directory, TRUE); // shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere"
diff --git a/user_guide_src/source/helpers/security_helper.rst b/user_guide_src/source/helpers/security_helper.rst
index 01018c61a..b1bcf2b4a 100644
--- a/user_guide_src/source/helpers/security_helper.rst
+++ b/user_guide_src/source/helpers/security_helper.rst
@@ -34,8 +34,9 @@ More info can be found there.
do_hash()
=========
-Permits you to create SHA1 or MD5 one way hashes suitable for encrypting
-passwords. Will create SHA1 by default. Examples
+Permits you to create one way hashes suitable for encrypting
+passwords. Will create SHA1 by default. See `hash_algos() <http://php.net/function.hash_algos>`_
+for a full list of supported algorithms.
::
@@ -43,7 +44,7 @@ passwords. Will create SHA1 by default. Examples
$str = do_hash($str, 'md5'); // MD5
.. note:: This function was formerly named dohash(), which has been
- deprecated in favor of `do_hash()`.
+ removed in favor of `do_hash()`.
strip_image_tags()
==================
diff --git a/user_guide_src/source/helpers/string_helper.rst b/user_guide_src/source/helpers/string_helper.rst
index dc70e461a..2d23fb00c 100644
--- a/user_guide_src/source/helpers/string_helper.rst
+++ b/user_guide_src/source/helpers/string_helper.rst
@@ -108,6 +108,36 @@ found in http://. Example
$string = "http://example.com//index.php";
echo reduce_double_slashes($string); // results in "http://example.com/index.php"
+strip_slashes()
+===============
+
+Removes any slashes from a string. Example
+
+::
+
+ $str = "Is your name O\'reilly?";
+ echo strip_slashes($str); // results in Is your name O'reilly?
+
+You can also use an array. Example
+
+::
+
+ $str = array(
+ 'question'  => 'Is your name O\'reilly?',
+ 'answer' => 'No, my name is O\'connor.'
+ );
+
+ $str = strip_slashes($str);
+
+The above will return the following array:
+
+::
+
+ array(
+ 'question'  => "Is your name O'reilly?",
+ 'answer' => "No, my name is O'connor."
+ );
+
trim_slashes()
==============
diff --git a/user_guide_src/source/installation/upgrade_200.rst b/user_guide_src/source/installation/upgrade_200.rst
index 0bcbd5c99..b39f4fd23 100644
--- a/user_guide_src/source/installation/upgrade_200.rst
+++ b/user_guide_src/source/installation/upgrade_200.rst
@@ -102,7 +102,7 @@ Please refer to the :ref:`2.0.0 Change Log <2.0.0-changelog>` for full
details, but here are some of the larger changes that are more likely to
impact your code:
-- CodeIgniter now requires PHP 5.1.6.
+- CodeIgniter now requires PHP 5.2.4.
- Scaffolding has been removed.
- The CAPTCHA plugin in now a :doc:`helper </helpers/captcha_helper>`.
- The JavaScript calendar plugin was removed.
diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst
index 27b704dae..d7e40f5c4 100644
--- a/user_guide_src/source/libraries/email.rst
+++ b/user_guide_src/source/libraries/email.rst
@@ -104,6 +104,7 @@ Preference Default Value Options Descript
**newline** \\n "\\r\\n" or "\\n" or "\\r" Newline character. (Use "\\r\\n" to comply with RFC 822).
**bcc_batch_mode** FALSE TRUE or FALSE (boolean) Enable BCC Batch Mode.
**bcc_batch_size** 200 None Number of emails in each BCC batch.
+**dsn** FALSE TRUE or FALSE (boolean) Enable notify message from server
=================== ====================== ============================ =======================================================================
Email Function Reference
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index e7875bc22..5d7368ccb 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -523,7 +523,7 @@ Changing the Error Delimiters
By default, the Form Validation class adds a paragraph tag (<p>) around
each error message shown. You can either change these delimiters
-globally or individually.
+globally, individually, or change the defaults in a config file.
#. **Changing delimiters Globally**
To globally change the error delimiters, in your controller function,
@@ -543,6 +543,12 @@ globally or individually.
<?php echo validation_errors('<div class="error">', '</div>'); ?>
+#. **Set delimiters in a config file**
+ You can add your error delimiters in application/config/form_validation.php as follows::
+
+ $config['error_prefix'] = '<div class="error_prefix">';
+ $config['error_suffix'] = '</div>';
+
Showing Errors Individually
===========================
@@ -579,7 +585,30 @@ must supply it as an array to the function. Example::
For more info please see the :ref:`using-arrays-as-field-names` section below.
-.. _saving-groups:
+Validating an Array (other than $_POST)
+=======================================
+
+Sometimes you may want to validate an array that does not originate from $_POST data.
+
+In this case, you can specify the array to be validated::
+
+ $data = array(
+ 'username' => 'johndoe',
+ 'password' => 'mypassword',
+ 'passconf' => 'mypassword'
+ );
+
+ $this->form_validation->set_data($data);
+
+Creating validation rules, running the validation and retrieving error messages works the same whether you are
+validating $_POST data or an array.
+
+**Important Note:** If you want to validate more than one array during a single execution, then you should
+call the reset_validation() function before setting up rules and validating the new array.
+
+For more info please see the :ref:`function-reference` section below.
+
+-.. _saving-groups:
************************************************
Saving Sets of Validation Rules to a Config File
@@ -823,34 +852,40 @@ Rule Reference
The following is a list of all the native rules that are available to
use:
-======================= ========== ============================================================================================= =======================
-Rule Parameter Description Example
-======================= ========== ============================================================================================= =======================
-**required** No Returns FALSE if the form element is empty.
-**matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
-**is_unique** Yes Returns FALSE if the form element is not unique to the is_unique[table.field]
- table and field name in the parameter. is_unique[table.field]
-**max_length** Yes Returns FALSE if the form element is longer then the parameter value. max_length[12]
-**exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8]
-**greater_than** Yes Returns FALSE if the form element is less than the parameter value or not numeric. greater_than[8]
-**less_than** Yes Returns FALSE if the form element is greater than the parameter value or not numeric. less_than[8]
-**alpha** No Returns FALSE if the form element contains anything other than alphabetical characters.
-**alpha_numeric** No Returns FALSE if the form element contains anything other than alpha-numeric characters.
-**alpha_dash** No Returns FALSE if the form element contains anything other than alpha-numeric characters,
- underscores or dashes.
-**numeric** No Returns FALSE if the form element contains anything other than numeric characters.
-**integer** No Returns FALSE if the form element contains anything other than an integer.
-**decimal** Yes Returns FALSE if the form element is not exactly the parameter value.
-**is_natural** No Returns FALSE if the form element contains anything other than a natural number:
- 0, 1, 2, 3, etc.
-**is_natural_no_zero** No Returns FALSE if the form element contains anything other than a natural
- number, but not zero: 1, 2, 3, etc.
-**is_unique** Yes Returns FALSE if the form element is not unique in a database table. is_unique[table.field]
-**valid_email** No Returns FALSE if the form element does not contain a valid email address.
-**valid_emails** No Returns FALSE if any value provided in a comma separated list is not a valid email.
-**valid_ip** No Returns FALSE if the supplied IP is not valid.
-**valid_base64** No Returns FALSE if the supplied string contains anything other than valid Base64 characters.
-======================= ========== ============================================================================================= =======================
+========================= ========== ============================================================================================= =======================
+Rule Parameter Description Example
+========================= ========== ============================================================================================= =======================
+**required** No Returns FALSE if the form element is empty.
+**matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
+**is_unique** Yes Returns FALSE if the form element is not unique to the is_unique[table.field]
+ table and field name in the parameter. is_unique[table.field]
+**max_length** Yes Returns FALSE if the form element is longer then the parameter value. max_length[12]
+**exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8]
+**greater_than** Yes Returns FALSE if the form element is less than or equal to the parameter value or not greater_than[8]
+ numeric.
+**greater_than_equal_to** Yes Returns FALSE if the form element is less than the parameter value, greater_than_equal_to[8]
+ or not numeric.
+**less_than** Yes Returns FALSE if the form element is greater than or equal to the parameter value or less_than[8]
+ not numeric.
+**less_than_equal_to** Yes Returns FALSE if the form element is greater than the parameter value, less_than_equal_to[8]
+ or not numeric.
+**alpha** No Returns FALSE if the form element contains anything other than alphabetical characters.
+**alpha_numeric** No Returns FALSE if the form element contains anything other than alpha-numeric characters.
+**alpha_dash** No Returns FALSE if the form element contains anything other than alpha-numeric characters,
+ underscores or dashes.
+**numeric** No Returns FALSE if the form element contains anything other than numeric characters.
+**integer** No Returns FALSE if the form element contains anything other than an integer.
+**decimal** No Returns FALSE if the form element contains anything other than a decimal number.
+**is_natural** No Returns FALSE if the form element contains anything other than a natural number:
+ 0, 1, 2, 3, etc.
+**is_natural_no_zero** No Returns FALSE if the form element contains anything other than a natural
+ number, but not zero: 1, 2, 3, etc.
+**is_unique** Yes Returns FALSE if the form element is not unique in a database table. is_unique[table.field]
+**valid_email** No Returns FALSE if the form element does not contain a valid email address.
+**valid_emails** No Returns FALSE if any value provided in a comma separated list is not a valid email.
+**valid_ip** No Returns FALSE if the supplied IP is not valid.
+**valid_base64** No Returns FALSE if the supplied string contains anything other than valid Base64 characters.
+========================= ========== ============================================================================================= =======================
.. note:: These rules can also be called as discrete functions. For
example::
@@ -930,6 +965,33 @@ $this->form_validation->set_message();
Permits you to set custom error messages. See :ref:`setting-error-messages`
+$this->form_validation->set_data();
+========================================
+
+ .. php:method:: set_data ($data = '')
+
+ :param array $data: The data to validate
+
+ Permits you to set an array for validation, instead of using the default
+ $_POST array.
+
+$this->form_validation->reset_validation();
+========================================
+
+ .. php:method:: reset_validation ()
+
+ Permits you to reset the validation when you validate more than one array.
+ This function should be called before validating each new array.
+
+$this->form_validation->error_array();
+========================================
+
+ .. php:method:: error_array ()
+
+ :rtype: Array
+
+ Returns the error messages as an array.
+
.. _helper-functions:
****************
@@ -1011,4 +1073,3 @@ This function is identical to the **set_checkbox()** function above.
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />
-
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index bcf117358..1f2ea650a 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -99,7 +99,7 @@ The function returns FALSE (boolean) if there are no items in the POST.
::
- $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
+ $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$this->input->post(); // returns all POST items without XSS filter
$this->input->get()
@@ -119,9 +119,9 @@ The function returns FALSE (boolean) if there are no items in the GET.
::
- $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
+ $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
$this->input->get(); // returns all GET items without XSS filtering
-
+
$this->input->get_post()
=========================
@@ -298,3 +298,13 @@ see if PHP is being run on the command line.
$this->input->is_cli_request()
+$this->input->method();
+=====================================
+
+Returns the $_SERVER['REQUEST_METHOD'], optional set uppercase or lowercase (default lowercase).
+
+::
+
+ echo $this->input->method(TRUE); // Outputs: POST
+ echo $this->input->method(FALSE); // Outputs: post
+ echo $this->input->method(); // Outputs: post
diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst
index ef32f5d71..e8332ee97 100644
--- a/user_guide_src/source/libraries/sessions.rst
+++ b/user_guide_src/source/libraries/sessions.rst
@@ -209,6 +209,10 @@ set_userdata().
To read a flashdata variable::
$this->session->flashdata('item');
+
+An array of all flashdata can be retrieved as follows::
+
+ $this->session->all_flashdata();
If you find that you need to preserve a flashdata variable through an
diff --git a/user_guide_src/source/libraries/table.rst b/user_guide_src/source/libraries/table.rst
index 9bc3f3423..6a808abc2 100644
--- a/user_guide_src/source/libraries/table.rst
+++ b/user_guide_src/source/libraries/table.rst
@@ -116,6 +116,8 @@ example, only the table opening tag is being changed::
$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );
$this->table->set_template($tmpl);
+
+You can also set defaults for these in a config file.
******************
Function Reference
diff --git a/user_guide_src/source/overview/at_a_glance.rst b/user_guide_src/source/overview/at_a_glance.rst
index 31f0b4dd9..6dcfdbb14 100644
--- a/user_guide_src/source/overview/at_a_glance.rst
+++ b/user_guide_src/source/overview/at_a_glance.rst
@@ -41,7 +41,7 @@ CodeIgniter Uses M-V-C
CodeIgniter uses the Model-View-Controller approach, which allows great
separation between logic and presentation. This is particularly good for
projects in which designers are working with your template files, as the
-code these file contain will be minimized. We describe MVC in more
+code these files contain will be minimized. We describe MVC in more
detail on its own page.
CodeIgniter Generates Clean URLs