summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--.travis.yml14
-rw-r--r--DCO.txt25
-rw-r--r--application/.htaccess7
-rw-r--r--application/cache/.htaccess7
-rw-r--r--application/config/autoload.php29
-rw-r--r--application/config/config.php38
-rw-r--r--application/config/constants.php16
-rw-r--r--application/config/database.php9
-rw-r--r--application/config/foreign_chars.php24
-rw-r--r--application/config/migration.php2
-rw-r--r--application/config/mimes.php264
-rw-r--r--application/config/routes.php2
-rw-r--r--application/config/user_agents.php14
-rw-r--r--application/views/errors/error_404.php (renamed from application/errors/error_404.php)8
-rw-r--r--application/views/errors/error_db.php (renamed from application/errors/error_db.php)8
-rw-r--r--application/views/errors/error_general.php (renamed from application/errors/error_general.php)8
-rw-r--r--application/views/errors/error_php.php (renamed from application/errors/error_php.php)0
-rw-r--r--application/views/errors/index.html (renamed from application/errors/index.html)0
-rw-r--r--application/views/welcome_message.php15
-rw-r--r--composer.json8
-rw-r--r--contributing.md92
-rw-r--r--index.php87
-rw-r--r--readme.rst134
-rw-r--r--system/.htaccess7
-rw-r--r--[-rwxr-xr-x]system/core/Benchmark.php2
-rw-r--r--[-rwxr-xr-x]system/core/CodeIgniter.php29
-rw-r--r--system/core/Common.php140
-rw-r--r--[-rwxr-xr-x]system/core/Config.php58
-rw-r--r--[-rwxr-xr-x]system/core/Exceptions.php4
-rw-r--r--[-rwxr-xr-x]system/core/Hooks.php6
-rw-r--r--[-rwxr-xr-x]system/core/Input.php73
-rw-r--r--[-rwxr-xr-x]system/core/Lang.php18
-rw-r--r--system/core/Loader.php87
-rw-r--r--[-rwxr-xr-x]system/core/Model.php0
-rw-r--r--[-rwxr-xr-x]system/core/Output.php237
-rw-r--r--[-rwxr-xr-x]system/core/Router.php4
-rw-r--r--[-rwxr-xr-x]system/core/Security.php36
-rw-r--r--[-rwxr-xr-x]system/core/URI.php68
-rw-r--r--system/core/Utf8.php2
-rw-r--r--[-rwxr-xr-x]system/database/DB.php56
-rw-r--r--system/database/DB_cache.php10
-rw-r--r--system/database/DB_driver.php356
-rw-r--r--system/database/DB_forge.php76
-rw-r--r--system/database/DB_query_builder.php425
-rw-r--r--system/database/DB_result.php197
-rw-r--r--system/database/DB_utility.php21
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php94
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php45
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php10
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php6
-rw-r--r--system/database/drivers/ibase/ibase_driver.php (renamed from system/database/drivers/interbase/interbase_driver.php)81
-rw-r--r--system/database/drivers/ibase/ibase_forge.php (renamed from system/database/drivers/interbase/interbase_forge.php)96
-rw-r--r--system/database/drivers/ibase/ibase_result.php (renamed from system/database/drivers/interbase/interbase_result.php)135
-rw-r--r--system/database/drivers/ibase/ibase_utility.php (renamed from system/database/drivers/interbase/interbase_utility.php)6
-rw-r--r--system/database/drivers/ibase/index.html (renamed from system/database/drivers/interbase/index.html)0
-rw-r--r--system/database/drivers/mssql/mssql_driver.php207
-rw-r--r--system/database/drivers/mssql/mssql_forge.php88
-rw-r--r--system/database/drivers/mssql/mssql_result.php33
-rw-r--r--system/database/drivers/mssql/mssql_utility.php2
-rw-r--r--system/database/drivers/mysql/mysql_driver.php128
-rw-r--r--system/database/drivers/mysql/mysql_forge.php44
-rw-r--r--system/database/drivers/mysql/mysql_result.php29
-rw-r--r--system/database/drivers/mysql/mysql_utility.php12
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php138
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php45
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php10
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php119
-rw-r--r--system/database/drivers/oci8/oci8_driver.php73
-rw-r--r--system/database/drivers/oci8/oci8_forge.php41
-rw-r--r--system/database/drivers/oci8/oci8_result.php479
-rw-r--r--system/database/drivers/odbc/odbc_driver.php104
-rw-r--r--system/database/drivers/odbc/odbc_forge.php81
-rw-r--r--system/database/drivers/odbc/odbc_result.php174
-rw-r--r--system/database/drivers/pdo/pdo_driver.php392
-rw-r--r--system/database/drivers/pdo/pdo_forge.php82
-rw-r--r--system/database/drivers/pdo/pdo_result.php72
-rw-r--r--system/database/drivers/pdo/subdrivers/index.html10
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_4d_driver.php223
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php185
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php265
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php262
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php262
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_informix_driver.php271
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php213
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_oci_driver.php230
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php267
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php341
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php167
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php299
-rw-r--r--system/database/drivers/postgre/postgre_driver.php145
-rw-r--r--system/database/drivers/postgre/postgre_forge.php56
-rw-r--r--system/database/drivers/postgre/postgre_result.php10
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php131
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php99
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php16
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php100
-rw-r--r--system/database/drivers/sqlite3/sqlite3_forge.php56
-rw-r--r--system/database/drivers/sqlite3/sqlite3_result.php464
-rw-r--r--system/database/drivers/sqlite3/sqlite3_utility.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php143
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php92
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php18
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php4
-rw-r--r--system/helpers/array_helper.php10
-rw-r--r--system/helpers/captcha_helper.php12
-rw-r--r--system/helpers/date_helper.php221
-rw-r--r--system/helpers/directory_helper.php2
-rw-r--r--system/helpers/download_helper.php18
-rw-r--r--system/helpers/email_helper.php4
-rw-r--r--system/helpers/file_helper.php67
-rw-r--r--system/helpers/form_helper.php48
-rw-r--r--system/helpers/html_helper.php34
-rw-r--r--system/helpers/inflector_helper.php98
-rw-r--r--system/helpers/language_helper.php20
-rw-r--r--system/helpers/number_helper.php13
-rw-r--r--system/helpers/path_helper.php18
-rw-r--r--system/helpers/security_helper.php72
-rw-r--r--system/helpers/smiley_helper.php107
-rw-r--r--system/helpers/string_helper.php206
-rw-r--r--system/helpers/text_helper.php185
-rw-r--r--system/helpers/typography_helper.php51
-rw-r--r--system/helpers/url_helper.php351
-rw-r--r--system/helpers/xml_helper.php18
-rw-r--r--system/language/english/calendar_lang.php95
-rw-r--r--system/language/english/date_lang.php33
-rw-r--r--system/language/english/db_lang.php4
-rw-r--r--system/language/english/email_lang.php41
-rw-r--r--system/language/english/form_validation_lang.php57
-rw-r--r--system/language/english/ftp_lang.php29
-rw-r--r--system/language/english/imglib_lang.php41
-rw-r--r--system/language/english/migration_lang.php18
-rw-r--r--system/language/english/number_lang.php14
-rw-r--r--system/language/english/profiler_lang.php4
-rw-r--r--system/language/english/unit_test_lang.php5
-rw-r--r--system/language/english/upload_lang.php37
-rw-r--r--system/libraries/Cache/Cache.php43
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php14
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php236
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php2
-rw-r--r--system/libraries/Calendar.php18
-rw-r--r--system/libraries/Cart.php4
-rw-r--r--system/libraries/Driver.php24
-rw-r--r--system/libraries/Email.php248
-rw-r--r--system/libraries/Encrypt.php16
-rw-r--r--system/libraries/Form_validation.php99
-rw-r--r--system/libraries/Ftp.php32
-rw-r--r--system/libraries/Image_lib.php118
-rw-r--r--system/libraries/Javascript.php6
-rw-r--r--system/libraries/Log.php4
-rw-r--r--system/libraries/Migration.php10
-rw-r--r--system/libraries/Pagination.php173
-rw-r--r--system/libraries/Parser.php4
-rw-r--r--system/libraries/Profiler.php14
-rw-r--r--system/libraries/Session.php952
-rwxr-xr-xsystem/libraries/Session/Session.php689
-rwxr-xr-xsystem/libraries/Session/drivers/Session_cookie.php824
-rwxr-xr-xsystem/libraries/Session/drivers/Session_native.php232
-rw-r--r--system/libraries/Table.php10
-rw-r--r--system/libraries/Trackback.php12
-rw-r--r--system/libraries/Typography.php8
-rw-r--r--system/libraries/Unit_test.php31
-rw-r--r--system/libraries/Upload.php97
-rwxr-xr-x[-rw-r--r--]system/libraries/Xmlrpc.php87
-rw-r--r--system/libraries/Xmlrpcs.php28
-rw-r--r--system/libraries/Zip.php2
-rw-r--r--system/libraries/javascript/Jquery.php30
-rw-r--r--tests/Bootstrap.php27
-rw-r--r--tests/README.md8
-rw-r--r--tests/codeigniter/Setup_test.php6
-rw-r--r--tests/codeigniter/core/Benchmark_test.php11
-rw-r--r--tests/codeigniter/core/Common_test.php37
-rw-r--r--tests/codeigniter/core/Config_test.php38
-rw-r--r--tests/codeigniter/core/Input_test.php57
-rw-r--r--tests/codeigniter/core/Lang_test.php17
-rw-r--r--tests/codeigniter/core/Loader_test.php132
-rw-r--r--tests/codeigniter/core/Security_test.php49
-rw-r--r--tests/codeigniter/core/URI_test.php230
-rw-r--r--tests/codeigniter/database/DB_driver_test.php4
-rw-r--r--tests/codeigniter/database/DB_test.php4
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php16
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php9
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php68
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php18
-rw-r--r--tests/codeigniter/database/query_builder/get_test.php8
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php8
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php22
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php2
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php6
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php28
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php22
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php151
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php49
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php2
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php143
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php112
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php43
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php31
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php37
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php5
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php76
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php1
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php4
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php204
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php72
-rw-r--r--tests/codeigniter/libraries/Parser_test.php61
-rw-r--r--tests/codeigniter/libraries/Session_test.php405
-rw-r--r--tests/codeigniter/libraries/Table_test.php169
-rw-r--r--tests/codeigniter/libraries/Typography_test.php40
-rw-r--r--tests/codeigniter/libraries/Upload_test.php270
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php6
-rw-r--r--tests/mocks/autoloader.php46
-rw-r--r--tests/mocks/ci_testcase.php84
-rw-r--r--tests/mocks/core/common.php171
-rw-r--r--tests/mocks/core/input.php6
-rw-r--r--tests/mocks/core/lang.php15
-rw-r--r--tests/mocks/core/loader.php7
-rw-r--r--tests/mocks/core/security.php2
-rw-r--r--tests/mocks/core/uri.php9
-rw-r--r--tests/mocks/core/utf8.php11
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin19456 -> 19456 bytes
-rw-r--r--tests/mocks/database/config/mysql.php10
-rw-r--r--tests/mocks/database/config/pdo/mysql.php18
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php14
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php14
-rw-r--r--tests/mocks/database/config/pgsql.php10
-rw-r--r--tests/mocks/database/config/sqlite.php10
-rw-r--r--tests/mocks/database/db.php26
-rw-r--r--tests/mocks/database/db/driver.php7
-rw-r--r--tests/mocks/database/db/querybuilder.php9
-rw-r--r--tests/mocks/database/drivers/mysql.php9
-rw-r--r--tests/mocks/database/drivers/pdo.php8
-rw-r--r--tests/mocks/database/drivers/postgre.php9
-rw-r--r--tests/mocks/database/drivers/sqlite.php9
-rw-r--r--tests/mocks/database/schema/skeleton.php55
-rw-r--r--tests/mocks/libraries/calendar.php25
-rw-r--r--tests/mocks/libraries/encrypt.php16
-rw-r--r--tests/mocks/libraries/session.php43
-rw-r--r--tests/mocks/libraries/table.php3
-rw-r--r--tests/mocks/libraries/upload.php3
-rw-r--r--tests/mocks/uploads/ci_logo.gifbin0 -> 3270 bytes
-rw-r--r--tests/phpunit.xml25
-rw-r--r--tests/travis/mysql.phpunit.xml11
-rw-r--r--tests/travis/pdo/mysql.phpunit.xml11
-rw-r--r--tests/travis/pdo/pgsql.phpunit.xml11
-rw-r--r--tests/travis/pdo/sqlite.phpunit.xml11
-rw-r--r--tests/travis/pgsql.phpunit.xml11
-rw-r--r--tests/travis/sqlite.phpunit.xml11
-rw-r--r--user_guide_src/source/DCO.rst27
-rw-r--r--user_guide_src/source/_themes/eldocs/layout.html68
-rw-r--r--user_guide_src/source/_themes/eldocs/searchbox.html21
-rw-r--r--user_guide_src/source/_themes/eldocs/static/asset/css/common.css87
-rw-r--r--user_guide_src/source/changelog.rst371
-rw-r--r--user_guide_src/source/conf.py1
-rw-r--r--user_guide_src/source/contributing/index.rst105
-rw-r--r--user_guide_src/source/database/configuration.rst129
-rw-r--r--user_guide_src/source/database/connecting.rst34
-rw-r--r--user_guide_src/source/database/queries.rst30
-rw-r--r--user_guide_src/source/database/query_builder.rst18
-rw-r--r--user_guide_src/source/database/results.rst20
-rw-r--r--user_guide_src/source/general/common_functions.rst5
-rw-r--r--user_guide_src/source/general/core_classes.rst1
-rw-r--r--user_guide_src/source/general/environments.rst10
-rw-r--r--user_guide_src/source/general/models.rst75
-rw-r--r--user_guide_src/source/general/requirements.rst5
-rw-r--r--user_guide_src/source/general/reserved_names.rst2
-rw-r--r--user_guide_src/source/general/welcome.rst32
-rw-r--r--user_guide_src/source/helpers/array_helper.rst34
-rw-r--r--user_guide_src/source/helpers/captcha_helper.rst2
-rw-r--r--user_guide_src/source/helpers/date_helper.rst231
-rw-r--r--user_guide_src/source/helpers/file_helper.rst3
-rw-r--r--user_guide_src/source/helpers/form_helper.rst4
-rw-r--r--user_guide_src/source/helpers/security_helper.rst6
-rw-r--r--user_guide_src/source/helpers/string_helper.rst3
-rw-r--r--user_guide_src/source/helpers/url_helper.rst45
-rw-r--r--user_guide_src/source/images/codeigniter_1.7.1_library_reference.pngbin111744 -> 111747 bytes
-rw-r--r--user_guide_src/source/index.rst136
-rw-r--r--user_guide_src/source/installation/downloads.rst8
-rw-r--r--user_guide_src/source/installation/upgrade_200.rst9
-rw-r--r--user_guide_src/source/installation/upgrade_210.rst16
-rw-r--r--user_guide_src/source/installation/upgrade_211.rst33
-rw-r--r--user_guide_src/source/installation/upgrade_212.rst22
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst163
-rw-r--r--user_guide_src/source/installation/upgrading.rst3
-rw-r--r--user_guide_src/source/libraries/config.rst12
-rw-r--r--user_guide_src/source/libraries/email.rst23
-rw-r--r--user_guide_src/source/libraries/encryption.rst2
-rw-r--r--user_guide_src/source/libraries/file_uploading.rst8
-rw-r--r--user_guide_src/source/libraries/form_validation.rst24
-rw-r--r--user_guide_src/source/libraries/ftp.rst5
-rw-r--r--user_guide_src/source/libraries/image_lib.rst23
-rw-r--r--user_guide_src/source/libraries/input.rst58
-rw-r--r--user_guide_src/source/libraries/loader.rst79
-rw-r--r--user_guide_src/source/libraries/migration.rst134
-rw-r--r--user_guide_src/source/libraries/output.rst4
-rw-r--r--user_guide_src/source/libraries/pagination.rst67
-rw-r--r--user_guide_src/source/libraries/sessions.rst340
-rw-r--r--user_guide_src/source/libraries/trackback.rst2
-rw-r--r--user_guide_src/source/libraries/uri.rst4
-rw-r--r--user_guide_src/source/license_afl.rst (renamed from license_afl.rst)0
-rw-r--r--user_guide_src/source/overview/cheatsheets.rst15
309 files changed, 13656 insertions, 8335 deletions
diff --git a/.gitignore b/.gitignore
index 11fb6d67c..a035c2b27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,5 @@ application/logs/*
user_guide_src/build/*
user_guide_src/cilexer/build/*
user_guide_src/cilexer/dist/*
-user_guide_src/cilexer/pycilexer.egg-info/* \ No newline at end of file
+user_guide_src/cilexer/pycilexer.egg-info/*
+/vendor/ \ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..62acf05e5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,11 @@ language: php
php:
- 5.3
- 5.4
+
+services:
+ - mysql
+ - postgresql
+ - sqlite
env:
- DB=mysql
@@ -13,16 +18,15 @@ env:
- DB=pdo/sqlite
before_script:
- - pyrus channel-discover pear.php-tools.net
- - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
- - phpenv rehash
+ - curl -s http://getcomposer.org/installer | php
+ - php composer.phar install
- sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
-script: phpunit --configuration tests/travis/$DB.phpunit.xml
+script: phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master \ No newline at end of file
+ - /^feature\/.+$/ \ No newline at end of file
diff --git a/DCO.txt b/DCO.txt
new file mode 100644
index 000000000..a404c0d38
--- /dev/null
+++ b/DCO.txt
@@ -0,0 +1,25 @@
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(1) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(2) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(3) The contribution was provided directly to me by some other
+ person who certified (1), (2) or (3) and I have not modified
+ it.
+
+(4) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
diff --git a/application/.htaccess b/application/.htaccess
index 14249c50b..6c63ed4c4 100644
--- a/application/.htaccess
+++ b/application/.htaccess
@@ -1 +1,6 @@
-Deny from all \ No newline at end of file
+<IfModule authz_core_module>
+ Require all denied
+</IfModule>
+<IfModule !authz_core_module>
+ Deny from all
+</IfModule> \ No newline at end of file
diff --git a/application/cache/.htaccess b/application/cache/.htaccess
index 3418e55a6..6c63ed4c4 100644
--- a/application/cache/.htaccess
+++ b/application/cache/.htaccess
@@ -1 +1,6 @@
-deny from all \ No newline at end of file
+<IfModule authz_core_module>
+ Require all denied
+</IfModule>
+<IfModule !authz_core_module>
+ Deny from all
+</IfModule> \ No newline at end of file
diff --git a/application/config/autoload.php b/application/config/autoload.php
index b3e63cbf6..ff153fb48 100644
--- a/application/config/autoload.php
+++ b/application/config/autoload.php
@@ -46,10 +46,11 @@
|
| 1. Packages
| 2. Libraries
-| 3. Helper files
-| 4. Custom config files
-| 5. Language files
-| 6. Models
+| 3. Drivers
+| 4. Helper files
+| 5. Custom config files
+| 6. Language files
+| 7. Models
|
*/
@@ -75,7 +76,7 @@ $autoload['packages'] = array();
|
| Prototype:
|
-| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
+| $autoload['libraries'] = array('database', 'email', 'xmlrpc');
*/
$autoload['libraries'] = array();
@@ -83,6 +84,22 @@ $autoload['libraries'] = array();
/*
| -------------------------------------------------------------------
+| Auto-load Drivers
+| -------------------------------------------------------------------
+| These classes are located in the system/libraries folder or in your
+| application/libraries folder within their own subdirectory. They
+| offer multiple interchangeable driver options.
+|
+| Prototype:
+|
+| $autoload['drivers'] = array('session', 'cache');
+*/
+
+$autoload['drivers'] = array();
+
+
+/*
+| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
@@ -139,4 +156,4 @@ $autoload['model'] = array();
/* End of file autoload.php */
-/* Location: ./application/config/autoload.php */ \ No newline at end of file
+/* Location: ./application/config/autoload.php */
diff --git a/application/config/config.php b/application/config/config.php
index 2628885f0..eaccbf75e 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -204,7 +204,7 @@ $config['directory_trigger'] = 'd'; // experimental not currently in use
| 4 = All Messages
|
| You can also pass in a array with threshold levels to show individual error types
-|
+|
| array(2) = Debug Messages, without Error Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
@@ -253,7 +253,7 @@ $config['cache_path'] = '';
|
| If you use the Encryption class or the Session class you
| MUST set an encryption key. See the user guide for info.
-|
+|
| http://codeigniter.com/user_guide/libraries/encryption.html
| http://codeigniter.com/user_guide/libraries/sessions.html
|
@@ -265,6 +265,9 @@ $config['encryption_key'] = '';
| Session Variables
|--------------------------------------------------------------------------
|
+| 'sess_driver' = the driver to load: cookie (Classic), native (PHP sessions),
+| or your custom driver name
+| 'sess_valid_drivers' = additional valid drivers which may be loaded
| 'sess_cookie_name' = the name you want for the cookie
| 'sess_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration.
@@ -278,6 +281,8 @@ $config['encryption_key'] = '';
| 'sess_time_to_update' = how many seconds between CI refreshing Session Information
|
*/
+$config['sess_driver'] = 'cookie';
+$config['sess_valid_drivers'] = array();
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
@@ -297,12 +302,12 @@ $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)
+| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
*/
-$config['cookie_prefix'] = "";
-$config['cookie_domain'] = "";
-$config['cookie_path'] = "/";
+$config['cookie_prefix'] = '';
+$config['cookie_domain'] = '';
+$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
@@ -359,13 +364,25 @@ $config['compress_output'] = FALSE;
/*
|--------------------------------------------------------------------------
+| Minify
+|--------------------------------------------------------------------------
+|
+| Removes extra characters (usually unnecessary spaces) from your
+| output for faster page load speeds. Makes your outputted HTML source
+| code less readable.
+|
+*/
+$config['minify_output'] = FALSE;
+
+/*
+|--------------------------------------------------------------------------
| Master Time Reference
|--------------------------------------------------------------------------
|
-| Options are 'local' or 'gmt'. This pref tells the system whether to use
-| your server's local time as the master 'now' reference, or convert it to
-| GMT. See the 'date helper' page of the user guide for information
-| regarding date handling.
+| Options are 'local' or any PHP supported timezone. This preference tells
+| the system whether to use your server's local time as the master 'now'
+| reference, or convert it to the configured one timezone. See the 'date
+| helper' page of the user guide for information regarding date handling.
|
*/
$config['time_reference'] = 'local';
@@ -398,5 +415,6 @@ $config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
+
/* End of file config.php */
/* Location: ./application/config/config.php */
diff --git a/application/config/constants.php b/application/config/constants.php
index d22d2963e..62a18e761 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -52,14 +52,14 @@ define('DIR_WRITE_MODE', 0777);
|
*/
-define('FOPEN_READ', 'rb');
-define('FOPEN_READ_WRITE', 'r+b');
-define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
-define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
-define('FOPEN_WRITE_CREATE', 'ab');
-define('FOPEN_READ_WRITE_CREATE', 'a+b');
-define('FOPEN_WRITE_CREATE_STRICT', 'xb');
-define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
+define('FOPEN_READ', 'rb');
+define('FOPEN_READ_WRITE', 'r+b');
+define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
+define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
+define('FOPEN_WRITE_CREATE', 'ab');
+define('FOPEN_READ_WRITE_CREATE', 'a+b');
+define('FOPEN_WRITE_CREATE_STRICT', 'xb');
+define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
/*
|--------------------------------------------------------------------------
diff --git a/application/config/database.php b/application/config/database.php
index 19498735c..4c5cad03f 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -42,8 +42,9 @@
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
-| ['dbdriver'] The database type. e.g.: mysql. Currently supported:
-| cubrid, interbase, mssql, mysql, mysqli, oci8,
+| ['dbdriver'] The database driver. e.g.: mysqli.
+ Currently supported:
+| cubrid, ibase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Query Builder class
@@ -62,6 +63,7 @@
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
+| ['compress'] Whether or not to use client compression (only MySQL and MySQLi)
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
@@ -84,7 +86,7 @@ $db['default'] = array(
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
- 'pconnect' => FALSE,
+ 'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
@@ -92,6 +94,7 @@ $db['default'] = array(
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
+ 'compress' => TRUE,
'stricton' => FALSE,
'failover' => array()
);
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index 41de123da..6614caa31 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -40,20 +40,20 @@ $foreign_characters = array(
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
- '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά/' => 'A',
- '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά/' => 'a',
+ '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ/' => 'A',
+ '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ/' => 'a',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
'/Ð|Ď|Đ|Δ/' => 'Dj',
'/ð|ď|đ|δ/' => 'dj',
- '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ/' => 'E',
- '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε/' => 'e',
+ '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ/' => 'E',
+ '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ/' => 'e',
'/Ĝ|Ğ|Ġ|Ģ|Γ/' => 'G',
'/ĝ|ğ|ġ|ģ|γ/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
- '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ/' => 'I',
- '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ/' => 'i',
+ '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị/' => 'I',
+ '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
'/Ķ|Κ/' => 'K',
@@ -62,18 +62,18 @@ $foreign_characters = array(
'/ĺ|ļ|ľ|ŀ|ł|λ/' => 'l',
'/Ñ|Ń|Ņ|Ň|Ν/' => 'N',
'/ñ|ń|ņ|ň|ʼn|ν/' => 'n',
- '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ/' => 'O',
- '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ/' => 'o',
+ '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ/' => 'O',
+ '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ/' => 'o',
'/Ŕ|Ŗ|Ř|Ρ/' => 'R',
'/ŕ|ŗ|ř|ρ/' => 'r',
'/Ś|Ŝ|Ş|Ș|Š|Σ/' => 'S',
'/ś|ŝ|ş|ș|š|ſ|σ|ς/' => 's',
'/Ț|Ţ|Ť|Ŧ|τ/' => 'T',
'/ț|ţ|ť|ŧ/' => 't',
- '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U',
- '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ/' => 'u',
- '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ/' => 'Y',
- '/ý|ÿ|ŷ/' => 'y',
+ '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự/' => 'U',
+ '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự/' => 'u',
+ '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ/' => 'Y',
+ '/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ/' => 'y',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž|Ζ/' => 'Z',
diff --git a/application/config/migration.php b/application/config/migration.php
index 88e398243..7645ade7c 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -44,7 +44,7 @@ $config['migration_enabled'] = FALSE;
|
| This is the name of the table that will store the current migrations state.
| When migrations runs it will store in a database table which migration
-| level the system is at. It then compares the migration level in the this
+| level the system is at. It then compares the migration level in this
| table to the $config['migration_version'] if they are not the same it
| will migrate up. This must be set.
|
diff --git a/application/config/mimes.php b/application/config/mimes.php
index 02e12c011..90ffe61ff 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -34,136 +34,140 @@
|
*/
-$mimes = array(
- 'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
- 'cpt' => 'application/mac-compactpro',
- 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
- 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
- 'dms' => 'application/octet-stream',
- 'lha' => 'application/octet-stream',
- 'lzh' => 'application/octet-stream',
- 'exe' => array('application/octet-stream', 'application/x-msdownload'),
- 'class' => 'application/octet-stream',
- 'psd' => 'application/x-photoshop',
- 'so' => 'application/octet-stream',
- 'sea' => 'application/octet-stream',
- 'dll' => 'application/octet-stream',
- 'oda' => 'application/oda',
- 'pdf' => array('application/pdf', 'application/x-download'),
- 'ai' => 'application/postscript',
- 'eps' => 'application/postscript',
- 'ps' => 'application/postscript',
- 'smi' => 'application/smil',
- 'smil' => 'application/smil',
- 'mif' => 'application/vnd.mif',
- 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
- 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
- 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- 'wbxml' => 'application/wbxml',
- 'wmlc' => 'application/wmlc',
- 'dcr' => 'application/x-director',
- 'dir' => 'application/x-director',
- 'dxr' => 'application/x-director',
- 'dvi' => 'application/x-dvi',
- 'gtar' => 'application/x-gtar',
- 'gz' => 'application/x-gzip',
- 'gzip' => 'application/x-gzip',
- 'php' => 'application/x-httpd-php',
- 'php4' => 'application/x-httpd-php',
- 'php3' => 'application/x-httpd-php',
- 'phtml' => 'application/x-httpd-php',
- 'phps' => 'application/x-httpd-php-source',
- 'js' => 'application/x-javascript',
- 'swf' => 'application/x-shockwave-flash',
- 'sit' => 'application/x-stuffit',
- 'tar' => 'application/x-tar',
- 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
- 'xhtml' => 'application/xhtml+xml',
- 'xht' => 'application/xhtml+xml',
- 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
- 'mid' => 'audio/midi',
- 'midi' => 'audio/midi',
- 'mpga' => 'audio/mpeg',
- 'mp2' => 'audio/mpeg',
- 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
- 'aif' => array('audio/x-aiff', 'audio/aiff'),
- 'aiff' => array('audio/x-aiff', 'audio/aiff'),
- 'aifc' => 'audio/x-aiff',
- 'ram' => 'audio/x-pn-realaudio',
- 'rm' => 'audio/x-pn-realaudio',
- 'rpm' => 'audio/x-pn-realaudio-plugin',
- 'ra' => 'audio/x-realaudio',
- 'rv' => 'video/vnd.rn-realvideo',
- 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
- 'bmp' => array('image/bmp', 'image/x-windows-bmp'),
- 'gif' => 'image/gif',
- 'jpeg' => array('image/jpeg', 'image/pjpeg'),
- 'jpg' => array('image/jpeg', 'image/pjpeg'),
- 'jpe' => array('image/jpeg', 'image/pjpeg'),
- 'png' => array('image/png', 'image/x-png'),
- 'tiff' => 'image/tiff',
- 'tif' => 'image/tiff',
- 'css' => 'text/css',
- 'html' => 'text/html',
- 'htm' => 'text/html',
- 'shtml' => 'text/html',
- 'txt' => 'text/plain',
- 'text' => 'text/plain',
- 'log' => array('text/plain', 'text/x-log'),
- 'rtx' => 'text/richtext',
- 'rtf' => 'text/rtf',
- 'xml' => array('application/xml', 'text/xml'),
- 'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
- 'mpeg' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
- 'mpe' => 'video/mpeg',
- 'qt' => 'video/quicktime',
- 'mov' => 'video/quicktime',
- 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
- 'movie' => 'video/x-sgi-movie',
- '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',
- 'json' => array('application/json', 'text/json'),
- 'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
- 'p10' => array('application/x-pkcs10', 'application/pkcs10'),
- 'p12' => 'application/x-pkcs12',
- 'p7a' => 'application/x-pkcs7-signature',
- 'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
- 'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
- 'p7r' => 'application/x-pkcs7-certreqresp',
- 'p7s' => 'application/pkcs7-signature',
- 'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
- 'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
- 'der' => 'application/x-x509-ca-cert',
- 'kdb' => 'application/octet-stream',
- 'pgp' => 'application/pgp',
- 'gpg' => 'application/gpg-keys',
- 'sst' => 'application/octet-stream',
- 'csr' => 'application/octet-stream',
- 'rsa' => 'application/x-pkcs7',
- 'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
- '3g2' => 'video/3gpp2',
- '3gp' => 'video/3gp',
- 'mp4' => 'video/mp4',
- 'm4a' => 'audio/x-m4a',
- 'f4v' => 'video/mp4',
- 'aac' => 'audio/x-acc',
- 'm4u' => 'application/vnd.mpegurl',
- 'm3u' => 'text/plain',
- 'xspf' => 'application/xspf+xml',
- 'vlc' => 'application/videolan',
- 'wmv' => 'video/x-ms-wmv',
- 'au' => 'audio/x-au',
- 'ac3' => 'audio/ac3',
- 'flac' => 'audio/x-flac',
- 'ogg' => 'audio/ogg',
- 'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
- 'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml')
- );
+return array(
+ 'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
+ 'cpt' => 'application/mac-compactpro',
+ 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
+ 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
+ 'dms' => 'application/octet-stream',
+ 'lha' => 'application/octet-stream',
+ 'lzh' => 'application/octet-stream',
+ 'exe' => array('application/octet-stream', 'application/x-msdownload'),
+ 'class' => 'application/octet-stream',
+ 'psd' => 'application/x-photoshop',
+ 'so' => 'application/octet-stream',
+ 'sea' => 'application/octet-stream',
+ 'dll' => 'application/octet-stream',
+ 'oda' => 'application/oda',
+ 'pdf' => array('application/pdf', 'application/x-download', 'binary/octet-stream'),
+ 'ai' => 'application/postscript',
+ 'eps' => 'application/postscript',
+ 'ps' => 'application/postscript',
+ 'smi' => 'application/smil',
+ 'smil' => 'application/smil',
+ 'mif' => 'application/vnd.mif',
+ 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
+ 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
+ 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ 'wbxml' => 'application/wbxml',
+ 'wmlc' => 'application/wmlc',
+ 'dcr' => 'application/x-director',
+ 'dir' => 'application/x-director',
+ 'dxr' => 'application/x-director',
+ 'dvi' => 'application/x-dvi',
+ 'gtar' => 'application/x-gtar',
+ 'gz' => 'application/x-gzip',
+ 'gzip' => 'application/x-gzip',
+ 'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
+ 'php4' => 'application/x-httpd-php',
+ 'php3' => 'application/x-httpd-php',
+ 'phtml' => 'application/x-httpd-php',
+ 'phps' => 'application/x-httpd-php-source',
+ 'js' => 'application/x-javascript',
+ 'swf' => 'application/x-shockwave-flash',
+ 'sit' => 'application/x-stuffit',
+ 'tar' => 'application/x-tar',
+ 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
+ 'xhtml' => 'application/xhtml+xml',
+ 'xht' => 'application/xhtml+xml',
+ 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
+ 'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
+ 'mid' => 'audio/midi',
+ 'midi' => 'audio/midi',
+ 'mpga' => 'audio/mpeg',
+ 'mp2' => 'audio/mpeg',
+ 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
+ 'aif' => array('audio/x-aiff', 'audio/aiff'),
+ 'aiff' => array('audio/x-aiff', 'audio/aiff'),
+ 'aifc' => 'audio/x-aiff',
+ 'ram' => 'audio/x-pn-realaudio',
+ 'rm' => 'audio/x-pn-realaudio',
+ 'rpm' => 'audio/x-pn-realaudio-plugin',
+ 'ra' => 'audio/x-realaudio',
+ 'rv' => 'video/vnd.rn-realvideo',
+ 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
+ 'bmp' => array('image/bmp', 'image/x-windows-bmp'),
+ 'gif' => 'image/gif',
+ 'jpeg' => array('image/jpeg', 'image/pjpeg'),
+ 'jpg' => array('image/jpeg', 'image/pjpeg'),
+ 'jpe' => array('image/jpeg', 'image/pjpeg'),
+ 'png' => array('image/png', 'image/x-png'),
+ 'tiff' => 'image/tiff',
+ 'tif' => 'image/tiff',
+ 'css' => 'text/css',
+ 'html' => 'text/html',
+ 'htm' => 'text/html',
+ 'shtml' => 'text/html',
+ 'txt' => 'text/plain',
+ 'text' => 'text/plain',
+ 'log' => array('text/plain', 'text/x-log'),
+ 'rtx' => 'text/richtext',
+ 'rtf' => 'text/rtf',
+ 'xml' => array('application/xml', 'text/xml'),
+ 'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
+ 'mpeg' => 'video/mpeg',
+ 'mpg' => 'video/mpeg',
+ 'mpe' => 'video/mpeg',
+ 'qt' => 'video/quicktime',
+ 'mov' => 'video/quicktime',
+ 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
+ 'movie' => 'video/x-sgi-movie',
+ 'doc' => array('application/msword', 'application/vnd.ms-office'),
+ 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
+ 'dot' => array('application/msword', 'application/vnd.ms-office'),
+ 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
+ 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword'),
+ 'word' => array('application/msword', 'application/octet-stream'),
+ 'xl' => 'application/excel',
+ 'eml' => 'message/rfc822',
+ 'json' => array('application/json', 'text/json'),
+ 'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
+ 'p10' => array('application/x-pkcs10', 'application/pkcs10'),
+ 'p12' => 'application/x-pkcs12',
+ 'p7a' => 'application/x-pkcs7-signature',
+ 'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
+ 'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
+ 'p7r' => 'application/x-pkcs7-certreqresp',
+ 'p7s' => 'application/pkcs7-signature',
+ 'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
+ 'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
+ 'der' => 'application/x-x509-ca-cert',
+ 'kdb' => 'application/octet-stream',
+ 'pgp' => 'application/pgp',
+ 'gpg' => 'application/gpg-keys',
+ 'sst' => 'application/octet-stream',
+ 'csr' => 'application/octet-stream',
+ 'rsa' => 'application/x-pkcs7',
+ 'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
+ '3g2' => 'video/3gpp2',
+ '3gp' => 'video/3gp',
+ 'mp4' => 'video/mp4',
+ 'm4a' => 'audio/x-m4a',
+ 'f4v' => 'video/mp4',
+ 'aac' => 'audio/x-acc',
+ 'm4u' => 'application/vnd.mpegurl',
+ 'm3u' => 'text/plain',
+ 'xspf' => 'application/xspf+xml',
+ 'vlc' => 'application/videolan',
+ 'wmv' => 'video/x-ms-wmv',
+ 'au' => 'audio/x-au',
+ 'ac3' => 'audio/ac3',
+ 'flac' => 'audio/x-flac',
+ 'ogg' => 'audio/ogg',
+ 'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
+ 'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
+ 'ics' => 'text/calendar'
+);
/* End of file mimes.php */
/* Location: ./application/config/mimes.php */ \ No newline at end of file
diff --git a/application/config/routes.php b/application/config/routes.php
index 474bda969..001198615 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -64,7 +64,7 @@
|
*/
-$route['default_controller'] = "welcome";
+$route['default_controller'] = 'welcome';
$route['404_override'] = '';
/* End of file routes.php */
diff --git a/application/config/user_agents.php b/application/config/user_agents.php
index 76114616b..78e4c8c7d 100644
--- a/application/config/user_agents.php
+++ b/application/config/user_agents.php
@@ -29,14 +29,14 @@
| -------------------------------------------------------------------
| USER AGENT TYPES
| -------------------------------------------------------------------
-| This file contains four arrays of user agent data. It is used by the
+| This file contains four arrays of user agent data. It is used by the
| User Agent Class to help identify browser, platform, robot, and
-| mobile device data. The array keys are used to identify the device
+| mobile device data. The array keys are used to identify the device
| and the array values are used to set the actual name of the item.
-|
*/
$platforms = array(
+ 'windows nt 6.2' => 'Windows 8',
'windows nt 6.1' => 'Windows 7',
'windows nt 6.0' => 'Windows Vista',
'windows nt 5.2' => 'Windows 2003',
@@ -147,6 +147,7 @@ $mobiles = array(
'ipaq' => 'HP iPaq',
'mot-' => 'Motorola',
'playstation portable' => 'PlayStation Portable',
+ 'playstation 3' => 'PlayStation 3',
'hiptop' => 'Danger Hiptop',
'nec-' => 'NEC',
'panasonic' => 'Panasonic',
@@ -156,10 +157,10 @@ $mobiles = array(
'spv' => 'SPV',
'zte' => 'ZTE',
'sendo' => 'Sendo',
- 'dsi' => 'Nintendo DSi',
- 'ds' => 'Nintendo DS',
+ 'nintendo dsi' => 'Nintendo DSi',
+ 'nintendo ds' => 'Nintendo DS',
+ 'nintendo 3ds' => 'Nintendo 3DS',
'wii' => 'Nintendo Wii',
- '3ds' => 'Nintendo 3DS',
'open web' => 'Open Web',
'openweb' => 'OpenWeb',
@@ -179,6 +180,7 @@ $mobiles = array(
'operamini' => 'Opera Mini',
'opera mini' => 'Opera Mini',
'opera mobi' => 'Opera Mobile',
+ 'fennec' => 'Firefox Mobile',
// Other
'digital paths' => 'Digital Paths',
diff --git a/application/errors/error_404.php b/application/views/errors/error_404.php
index c19bedfcd..fe48fd524 100644
--- a/application/errors/error_404.php
+++ b/application/views/errors/error_404.php
@@ -31,9 +31,9 @@
<title>404 Page Not Found</title>
<style type="text/css">
-::selection{ background-color: #E13300; color: white; }
-::moz-selection{ background-color: #E13300; color: white; }
-::webkit-selection{ background-color: #E13300; color: white; }
+::selection { background-color: #E13300; color: white; }
+::-moz-selection { background-color: #E13300; color: white; }
+::-webkit-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
@@ -73,6 +73,8 @@ code {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
+ -moz-box-shadow: 0 0 8px #D0D0D0;
+ -webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
diff --git a/application/errors/error_db.php b/application/views/errors/error_db.php
index 3b244e094..76ca6df7a 100644
--- a/application/errors/error_db.php
+++ b/application/views/errors/error_db.php
@@ -31,9 +31,9 @@
<title>Database Error</title>
<style type="text/css">
-::selection{ background-color: #E13300; color: white; }
-::moz-selection{ background-color: #E13300; color: white; }
-::webkit-selection{ background-color: #E13300; color: white; }
+::selection { background-color: #E13300; color: white; }
+::-moz-selection { background-color: #E13300; color: white; }
+::-webkit-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
@@ -73,6 +73,8 @@ code {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
+ -moz-box-shadow: 0 0 8px #D0D0D0;
+ -webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
diff --git a/application/errors/error_general.php b/application/views/errors/error_general.php
index c88afe168..e9baf1665 100644
--- a/application/errors/error_general.php
+++ b/application/views/errors/error_general.php
@@ -31,9 +31,9 @@
<title>Error</title>
<style type="text/css">
-::selection{ background-color: #E13300; color: white; }
-::moz-selection{ background-color: #E13300; color: white; }
-::webkit-selection{ background-color: #E13300; color: white; }
+::selection { background-color: #E13300; color: white; }
+::-moz-selection { background-color: #E13300; color: white; }
+::-webkit-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
@@ -73,6 +73,8 @@ code {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
+ -moz-box-shadow: 0 0 8px #D0D0D0;
+ -webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
diff --git a/application/errors/error_php.php b/application/views/errors/error_php.php
index b76dc8a9e..b76dc8a9e 100644
--- a/application/errors/error_php.php
+++ b/application/views/errors/error_php.php
diff --git a/application/errors/index.html b/application/views/errors/index.html
index c942a79ce..c942a79ce 100644
--- a/application/errors/index.html
+++ b/application/views/errors/index.html
diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php
index 45360da60..d227f82d1 100644
--- a/application/views/welcome_message.php
+++ b/application/views/welcome_message.php
@@ -32,9 +32,9 @@
<style type="text/css">
- ::selection{ background-color: #E13300; color: white; }
- ::moz-selection{ background-color: #E13300; color: white; }
- ::webkit-selection{ background-color: #E13300; color: white; }
+ ::selection { background-color: #E13300; color: white; }
+ ::-moz-selection { background-color: #E13300; color: white; }
+ ::-webkit-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
@@ -70,11 +70,11 @@
padding: 12px 10px 12px 10px;
}
- #body{
+ #body {
margin: 0 15px 0 15px;
}
- p.footer{
+ p.footer {
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
@@ -83,9 +83,10 @@
margin: 20px 0 0 0;
}
- #container{
+ #container {
margin: 10px;
border: 1px solid #D0D0D0;
+ -moz-box-shadow: 0 0 8px #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
</style>
@@ -107,7 +108,7 @@
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
- <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT == 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
+ <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>
</body>
diff --git a/composer.json b/composer.json
new file mode 100644
index 000000000..dc098acc3
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,8 @@
+{
+ "require": {
+ "mikey179/vfsStream": "*"
+ },
+ "require-dev": {
+ "EHER/PHPUnit": "*"
+ }
+} \ No newline at end of file
diff --git a/contributing.md b/contributing.md
new file mode 100644
index 000000000..f3f94fbc8
--- /dev/null
+++ b/contributing.md
@@ -0,0 +1,92 @@
+# Contributing to CodeIgniter
+
+
+CodeIgniter is a community driven project and accepts contributions of code and documentation from the community. These contributions are made in the form of Issues or [Pull Requests](http://help.github.com/send-pull-requests/) on the [EllisLab CodeIgniter repository](https://github.com/EllisLab/CodeIgniter>) on GitHub.
+
+Issues are a quick way to point out a bug. If you find a bug or documentation error in CodeIgniter then please check a few things first:
+
+1. There is not already an open Issue
+2. The issue has already been fixed (check the develop branch, or look for closed Issues)
+3. Is it something really obvious that you fix it yourself?
+
+Reporting issues is helpful but an even better approach is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git.
+
+## Guidelines
+
+Before we look into how, here are the guidelines. If your Pull Requests fail
+to pass these guidelines it will be declined and you will need to re-submit
+when you’ve made the changes. This might sound a bit tough, but it is required
+for us to maintain quality of the code-base.
+
+### PHP Style
+
+All code must meet the [Style Guide](http://codeigniter.com/user_guide/general/styleguide.html), which is
+essentially the [Allman indent style](http://en.wikipedia.org/wiki/Indent_style#Allman_style), underscores and readable operators. This makes certain that all code is the same format as the existing code and means it will be as readable as possible.
+
+### Documentation
+
+If you change anything that requires a change to documentation then you will need to add it. New classes, methods, parameters, changing default values, etc are all things that will require a change to documentation. The change-log must also be updated for every change. Also PHPDoc blocks must be maintained.
+
+### Compatibility
+
+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
+
+CodeIgniter uses the [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/) branching model which requires all pull requests to be sent to the "develop" branch. This is
+where the next planned version will be developed. The "master" branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g: an emergency security patch) can be applied to master to create a new version, without worrying about other features holding it up. For this reason all commits need to be made to "develop" and any sent to "master" will be closed automatically. If you have multiple changes to submit, please place all changes into their own branch on your fork.
+
+One thing at a time: A pull request should only contain one change. That does not mean only one commit, but one change - however many commits it took. The reason for this is that if you change X and Y but send a pull request for both at the same time, we might really want X but disagree with Y, meaning we cannot merge the request. Using the Git-Flow branching model you can create new branches for both of these features and send two requests.
+
+### Signing
+
+You must sign your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open source project. git makes this trivial as you merely have to use `--signoff` on your commits to your CodeIgniter fork.
+
+`git commit --signoff`
+
+or simply
+
+`git commit -s`
+
+This will sign your commits with the information setup in your git config, e.g.
+
+`Signed-off-by: John Q Public <john.public@example.com>`
+
+If you are using [Tower](http://www.git-tower.com/) there is a "Sign-Off" checkbox in the commit window. You could even alias git commit to use the `-s` flag so you don’t have to think about it.
+
+By signing your work in this manner, you certify to a "Developer's Certificate of Origin". The current version of this certificate is in the `DCO.txt` file in the root of this repository.
+
+
+## How-to Guide
+
+There are two ways to make changes, the easy way and the hard way. Either way you will need to [create a GitHub account](https://github.com/signup/free).
+
+Easy way GitHub allows in-line editing of files for making simple typo changes and quick-fixes. This is not the best way as you are unable to test the code works. If you do this you could be introducing syntax errors, etc, but for a Git-phobic user this is good for a quick-fix.
+
+Hard way The best way to contribute is to "clone" your fork of CodeIgniter to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it".
+
+1. Set up Git (Windows, Mac & Linux)
+2. Go to the CodeIgniter repo
+3. Fork it
+4. Clone your CodeIgniter repo: git@github.com:<your-name>/CodeIgniter.git
+5. Checkout the "develop" branch At this point you are ready to start making changes.
+6. Fix existing bugs on the Issue tracker after taking a look to see nobody else is working on them.
+7. Commit the files
+8. Push your develop branch to your fork
+9. Send a pull request [http://help.github.com/send-pull-requests/](http://help.github.com/send-pull-requests/)
+
+The Reactor Engineers will now be alerted about the change and at least one of the team will respond. If your change fails to meet the guidelines it will be bounced, or feedback will be provided to help you improve it.
+
+Once the Reactor Engineer handling your pull request is happy with it they will post it to the internal EllisLab discussion area to be double checked by the other Engineers and EllisLab developers. If nobody has a problem with the change then it will be merged into develop and will be part of the next release. Keeping your fork up-to-date
+
+Unlike systems like Subversion, Git can have multiple remotes. A remote is the name for a URL of a Git repository. By default your fork will have a remote named "origin" which points to your fork, but you can add another remote named "codeigniter" which points to `git://github.com/EllisLab/CodeIgniter.git`. This is a read-only remote but you can pull from this develop branch to update your own.
+
+If you are using command-line you can do the following:
+
+1. `git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git`
+2. `git pull codeigniter develop`
+3. `git push origin develop`
+
+Now your fork is up to date. This should be done regularly, or before you send a pull request at least. \ No newline at end of file
diff --git a/index.php b/index.php
index 5a1190112..107a2095b 100644
--- a/index.php
+++ b/index.php
@@ -42,7 +42,8 @@
*
* NOTE: If you change these, also change the error_reporting() code below
*/
- define('ENVIRONMENT', 'development');
+ define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
+
/*
*---------------------------------------------------------------
* ERROR REPORTING
@@ -51,21 +52,22 @@
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
-
-if (defined('ENVIRONMENT'))
+switch (ENVIRONMENT)
{
- switch (ENVIRONMENT)
- {
- case 'development':
- error_reporting(-1);
- break;
- case 'testing':
- case 'production':
- error_reporting(0);
- break;
- default:
- exit('The application environment is not set correctly.');
- }
+ case 'development':
+ error_reporting(-1);
+ ini_set('display_errors', 1);
+ break;
+
+ case 'testing':
+ case 'production':
+ error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
+ ini_set('display_errors', 0);
+ break;
+
+ default:
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
+ exit('The application environment is not set correctly.');
}
/*
@@ -133,7 +135,7 @@ if (defined('ENVIRONMENT'))
// if your controller is not in a sub-folder within the "controllers" folder
// $routing['directory'] = '';
- // The controller class file name. Example: Mycontroller
+ // The controller class file name. Example: mycontroller
// $routing['controller'] = '';
// The controller function you wish to be called.
@@ -174,17 +176,20 @@ if (defined('ENVIRONMENT'))
chdir(dirname(__FILE__));
}
- if (realpath($system_path) !== FALSE)
+ if (($_temp = realpath($system_path)) !== FALSE)
{
- $system_path = realpath($system_path).'/';
+ $system_path = $_temp.'/';
+ }
+ else
+ {
+ // Ensure there's a trailing slash
+ $system_path = rtrim($system_path, '/').'/';
}
-
- // ensure there's a trailing slash
- $system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME));
}
@@ -196,10 +201,6 @@ if (defined('ENVIRONMENT'))
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
- // The PHP file extension
- // this global constant is deprecated.
- define('EXT', '.php');
-
// Path to the system folder
define('BASEPATH', str_replace('\\', '/', $system_path));
@@ -212,13 +213,18 @@ if (defined('ENVIRONMENT'))
// The path to the "application" folder
if (is_dir($application_folder))
{
+ if (($_temp = realpath($application_folder)) !== FALSE)
+ {
+ $application_folder = $_temp;
+ }
+
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
- header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ 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);
}
@@ -226,21 +232,34 @@ if (defined('ENVIRONMENT'))
}
// The path to the "views" folder
- if (is_dir($view_folder))
+ if ( ! is_dir($view_folder))
{
- define ('VIEWPATH', $view_folder .'/');
- }
- else
- {
- if ( ! is_dir(APPPATH.'views/'))
+ if ( ! empty($view_folder) && is_dir(APPPATH.$view_folder.'/'))
{
- header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ $view_folder = APPPATH.$view_folder;
+ }
+ elseif ( ! 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);
}
+ else
+ {
+ $view_folder = APPPATH.'views';
+ }
+ }
- define ('VIEWPATH', APPPATH.'views/' );
+ if (($_temp = realpath($view_folder)) !== FALSE)
+ {
+ $view_folder = realpath($view_folder).'/';
+ }
+ else
+ {
+ $view_folder = rtrim($view_folder, '/').'/';
}
+ define('VIEWPATH', $view_folder);
+
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
diff --git a/readme.rst b/readme.rst
index 4707847c7..8628645c6 100644
--- a/readme.rst
+++ b/readme.rst
@@ -38,138 +38,6 @@ Installation
Please see the `installation section <http://codeigniter.com/user_guide/installation/index.html>`_
of the CodeIgniter User Guide.
-************
-Contributing
-************
-
-CodeIgniter is a community driven project and accepts contributions of code
-and documentation from the community. These contributions are made in the form
-of Issues or `Pull Requests <http://help.github.com/send-pull-requests/>`_ on
-the `EllisLab CodeIgniter repository
-<https://github.com/EllisLab/CodeIgniter>`_ on GitHub.
-
-Issues are a quick way to point out a bug. If you find a bug or documentation
-error in CodeIgniter then please check a few things first:
-
-- There is not already an open Issue
-- The issue has already been fixed (check the develop branch, or look for
- closed Issues)
-- Is it something really obvious that you fix it yourself?
-
-Reporting issues is helpful but an even better approach is to send a Pull
-Request, which is done by "Forking" the main repository and committing to your
-own copy. This will require you to use the version control system called Git.
-
-**********
-Guidelines
-**********
-
-Before we look into how, here are the guidelines. If your Pull Requests fail
-to pass these guidelines it will be declined and you will need to re-submit
-when you’ve made the changes. This might sound a bit tough, but it is required
-for us to maintain quality of the code-base.
-
-PHP Style
-=========
-
-All code must meet the `Style Guide
-<http://codeigniter.com/user_guide/general/styleguide.html>`_, which is
-essentially the `Allman indent style
-<http://en.wikipedia.org/wiki/Indent_style#Allman_style>`_, underscores and
-readable operators. This makes certain that all code is the same format as the
-existing code and means it will be as readable as possible.
-
-Documentation
-=============
-
-If you change anything that requires a change to documentation then you will
-need to add it. New classes, methods, parameters, changing default values, etc
-are all things that will require a change to documentation. The change-log
-must also be updated for every change. Also PHPDoc blocks must be maintained.
-
-Compatibility
-=============
-
-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
-=========
-
-CodeIgniter uses the `Git-Flow
-<http://nvie.com/posts/a-successful-git-branching-model/>`_ branching model
-which requires all pull requests to be sent to the "develop" branch. This is
-where the next planned version will be developed. The "master" branch will
-always contain the latest stable version and is kept clean so a "hotfix" (e.g:
-an emergency security patch) can be applied to master to create a new version,
-without worrying about other features holding it up. For this reason all
-commits need to be made to "develop" and any sent to "master" will be closed
-automatically. If you have multiple changes to submit, please place all
-changes into their own branch on your fork.
-
-One thing at a time: A pull request should only contain one change. That does
-not mean only one commit, but one change - however many commits it took. The
-reason for this is that if you change X and Y but send a pull request for both
-at the same time, we might really want X but disagree with Y, meaning we
-cannot merge the request. Using the Git-Flow branching model you can create
-new branches for both of these features and send two requests.
-
-************
-How-to Guide
-************
-
-There are two ways to make changes, the easy way and the hard way. Either way
-you will need to `create a GitHub account <https://github.com/signup/free>`_.
-
-Easy way GitHub allows in-line editing of files for making simple typo changes
-and quick-fixes. This is not the best way as you are unable to test the code
-works. If you do this you could be introducing syntax errors, etc, but for a
-Git-phobic user this is good for a quick-fix.
-
-Hard way The best way to contribute is to "clone" your fork of CodeIgniter to
-your development area. That sounds like some jargon, but "forking" on GitHub
-means "making a copy of that repo to your account" and "cloning" means
-"copying that code to your environment so you can work on it".
-
-#. Set up Git (Windows, Mac & Linux)
-#. Go to the CodeIgniter repo
-#. Fork it
-#. Clone your CodeIgniter repo: git@github.com:<your-name>/CodeIgniter.git
-#. Checkout the "develop" branch At this point you are ready to start making
- changes.
-#. Fix existing bugs on the Issue tracker after taking a look to see nobody
- else is working on them.
-#. Commit the files
-#. Push your develop branch to your fork
-#. Send a pull request http://help.github.com/send-pull-requests/
-
-The Reactor Engineers will now be alerted about the change and at least one of
-the team will respond. If your change fails to meet the guidelines it will be
-bounced, or feedback will be provided to help you improve it.
-
-Once the Reactor Engineer handling your pull request is happy with it they
-will post it to the internal EllisLab discussion area to be double checked by
-the other Engineers and EllisLab developers. If nobody has a problem with the
-change then it will be merged into develop and will be part of the next
-release. Keeping your fork up-to-date
-
-Unlike systems like Subversion, Git can have multiple remotes. A remote is the
-name for a URL of a Git repository. By default your fork will have a remote
-named "origin" which points to your fork, but you can add another remote named
-"codeigniter" which points to git://github.com/EllisLab/CodeIgniter.git. This
-is a read-only remote but you can pull from this develop branch to update your
-own.
-
-If you are using command-line you can do the following:
-
-#. git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git
-#. git pull codeigniter develop
-#. git push origin develop
-
-Now your fork is up to date. This should be done regularly, or before you send
-a pull request at least.
-
*******
License
*******
@@ -183,8 +51,6 @@ Resources
- `User Guide <http://codeigniter.com/user_guide/>`_
- `Community Forums <http://codeigniter.com/forums/>`_
-- `User
- Voice <http://codeigniter.uservoice.com/forums/40508-codeigniter-reactor>`_
- `Community Wiki <http://codeigniter.com/wiki/>`_
- `Community IRC <http://codeigniter.com/irc/>`_
diff --git a/system/.htaccess b/system/.htaccess
index 14249c50b..6c63ed4c4 100644
--- a/system/.htaccess
+++ b/system/.htaccess
@@ -1 +1,6 @@
-Deny from all \ No newline at end of file
+<IfModule authz_core_module>
+ Require all denied
+</IfModule>
+<IfModule !authz_core_module>
+ Deny from all
+</IfModule> \ No newline at end of file
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index bb630f40b..2fabdf46e 100755..100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -79,7 +79,7 @@ class CI_Benchmark {
*/
public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
{
- if ($point1 == '')
+ if ($point1 === '')
{
return '{elapsed_time}';
}
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 00db6e13a..8159b19f5 100755..100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -73,9 +73,9 @@
*/
set_error_handler('_exception_handler');
- if ( ! is_php('5.3'))
+ if ( ! is_php('5.4'))
{
- @set_magic_quotes_runtime(0); // Kill magic quotes
+ @ini_set('magic_quotes_runtime', 0); // Kill magic quotes
}
/*
@@ -94,24 +94,13 @@
* Note: Since the config file data is cached it doesn't
* hurt to load it here.
*/
- if (isset($assign_to_config['subclass_prefix']) && $assign_to_config['subclass_prefix'] != '')
+ if ( ! empty($assign_to_config['subclass_prefix']))
{
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
}
/*
* ------------------------------------------------------
- * Set a liberal script execution time limit
- * ------------------------------------------------------
- */
- if (function_exists('set_time_limit') && @ini_get('safe_mode') == 0
- && php_sapi_name() !== 'cli') // Do not override the Time Limit value if running from Command Line
- {
- @set_time_limit(300);
- }
-
-/*
- * ------------------------------------------------------
* Start the timer... tick tock tick tock...
* ------------------------------------------------------
*/
@@ -193,7 +182,7 @@
* ------------------------------------------------------
*/
if ($EXT->call_hook('cache_override') === FALSE
- && $OUT->_display_cache($CFG, $URI) == TRUE)
+ && $OUT->_display_cache($CFG, $URI) === TRUE)
{
exit;
}
@@ -393,15 +382,5 @@
*/
$EXT->call_hook('post_system');
-/*
- * ------------------------------------------------------
- * Close the DB connection if one exists
- * ------------------------------------------------------
- */
- if (class_exists('CI_DB') && isset($CI->db) && ! $CI->db->pconnect)
- {
- $CI->db->close();
- }
-
/* End of file CodeIgniter.php */
/* Location: ./system/core/CodeIgniter.php */ \ No newline at end of file
diff --git a/system/core/Common.php b/system/core/Common.php
index 8b897776f..981af4559 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -44,13 +44,13 @@ if ( ! function_exists('is_php'))
/**
* Determines if the current version of PHP is greater then the supplied value
*
- * Since there are a few places where we conditionally test for PHP > 5
+ * Since there are a few places where we conditionally test for PHP > 5.3
* we'll set a static variable.
*
* @param string
* @return bool TRUE if the current version is $version or higher
*/
- function is_php($version = '5.0.0')
+ function is_php($version = '5.3.0')
{
static $_is_php;
$version = (string) $version;
@@ -172,7 +172,7 @@ if ( ! function_exists('load_class'))
if ($name === FALSE)
{
// Note: We use exit() rather then show_error() in order to avoid a
- // self-referencing loop with the Excptions class
+ // self-referencing loop with the Exceptions class
set_status_header(503);
exit('Unable to locate the specified class: '.$class.'.php');
}
@@ -200,7 +200,7 @@ if ( ! function_exists('is_loaded'))
{
static $_is_loaded = array();
- if ($class != '')
+ if ($class !== '')
{
$_is_loaded[strtolower($class)] = $class;
}
@@ -231,21 +231,25 @@ if ( ! function_exists('get_config'))
return $_config[0];
}
- // Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+ $file_path = APPPATH.'config/config.php';
+ $found = FALSE;
+ if (file_exists($file_path))
{
- $file_path = APPPATH.'config/config.php';
+ $found = TRUE;
+ require($file_path);
}
- // Fetch the config file
- if ( ! file_exists($file_path))
+ // Is the config file in the environment folder?
+ if (defined('ENVIRONMENT') && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+ {
+ require($file_path);
+ }
+ elseif ( ! $found)
{
set_status_header(503);
exit('The configuration file does not exist.');
}
- require($file_path);
-
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
@@ -300,6 +304,32 @@ if ( ! function_exists('config_item'))
// ------------------------------------------------------------------------
+if ( ! function_exists('get_mimes'))
+{
+ /**
+ * Returns the MIME types array from config/mimes.php
+ *
+ * @return array
+ */
+ function &get_mimes()
+ {
+ static $_mimes = array();
+
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ {
+ $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ }
+ elseif (is_file(APPPATH.'config/mimes.php'))
+ {
+ $_mimes = include(APPPATH.'config/mimes.php');
+ }
+
+ return $_mimes;
+ }
+}
+
+// ------------------------------------------------------------------------
+
if ( ! function_exists('show_error'))
{
/**
@@ -366,7 +396,7 @@ if ( ! function_exists('log_message'))
{
static $_log;
- if (config_item('log_threshold') == 0)
+ if (config_item('log_threshold') === 0)
{
return;
}
@@ -401,6 +431,7 @@ if ( ! function_exists('set_status_header'))
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
+ 303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
@@ -432,19 +463,23 @@ if ( ! function_exists('set_status_header'))
505 => 'HTTP Version Not Supported'
);
- if ($code == '' OR ! is_numeric($code))
+ if (empty($code) OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}
- if (isset($stati[$code]) && $text == '')
- {
- $text = $stati[$code];
- }
+ is_int($code) OR $code = (int) $code;
- if ($text == '')
+ if (empty($text))
{
- show_error('No status text available. Please check your status code number or supply your own message text.', 500);
+ if (isset($stati[$code]))
+ {
+ $text = $stati[$code];
+ }
+ else
+ {
+ 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;
@@ -453,13 +488,9 @@ if ( ! function_exists('set_status_header'))
{
header('Status: '.$code.' '.$text, TRUE);
}
- elseif ($server_protocol === 'HTTP/1.0')
- {
- header('HTTP/1.0 '.$code.' '.$text, TRUE, $code);
- }
else
{
- header('HTTP/1.1 '.$code.' '.$text, TRUE, $code);
+ header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code);
}
}
}
@@ -487,29 +518,19 @@ if ( ! function_exists('_exception_handler'))
*/
function _exception_handler($severity, $message, $filepath, $line)
{
- // We don't bother with "strict" notices since they tend to fill up
- // the log file with excess information that isn't normally very helpful.
- // For example, if you are running PHP 5 and you use version 4 style
- // class functions (without prefixes like "public", "private", etc.)
- // you'll get notices telling you that these have been deprecated.
- if ($severity == E_STRICT)
- {
- return;
- }
-
$_error =& load_class('Exceptions', 'core');
- // Should we display the error? We'll get the current error_reporting
+ // Should we ignore the error? We'll get the current error_reporting
// level and add its bits with the severity bits to find out.
- if (($severity & error_reporting()) == $severity)
+ if (($severity & error_reporting()) !== $severity)
{
- $_error->show_php_error($severity, $message, $filepath, $line);
+ return;
}
- // Should we log the error? No? We're done...
- if (config_item('log_threshold') == 0)
+ // Should we display the error?
+ if ((bool) ini_get('display_errors') === TRUE)
{
- return;
+ $_error->show_php_error($severity, $message, $filepath, $line);
}
$_error->log_exception($severity, $message, $filepath, $line);
@@ -572,5 +593,44 @@ if ( ! function_exists('html_escape'))
}
}
+// ------------------------------------------------------------------------
+
+if ( ! function_exists('_stringify_attributes'))
+{
+ /**
+ * Stringify attributes for use in HTML tags.
+ *
+ * Helper function used to convert a string, array, or object
+ * of attributes to a string.
+ *
+ * @param mixed string, array, object
+ * @param bool
+ * @return string
+ */
+ function _stringify_attributes($attributes, $js = FALSE)
+ {
+ $atts = NULL;
+
+ if (empty($attributes))
+ {
+ return $atts;
+ }
+
+ if (is_string($attributes))
+ {
+ return ' '.$attributes;
+ }
+
+ $attributes = (array) $attributes;
+
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"';
+ }
+
+ return rtrim($atts, ',');
+ }
+}
+
/* End of file Common.php */
/* Location: ./system/core/Common.php */ \ No newline at end of file
diff --git a/system/core/Config.php b/system/core/Config.php
index c07ffa591..8e4f998ef 100755..100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -43,7 +43,7 @@ class CI_Config {
*
* @var array
*/
- public $config = array();
+ public $config = array();
/**
* List of all loaded config files
@@ -100,15 +100,15 @@ class CI_Config {
*/
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
- $file = ($file == '') ? 'config' : str_replace('.php', '', $file);
+ $file = ($file === '') ? 'config' : str_replace('.php', '', $file);
$found = $loaded = FALSE;
+ $check_locations = defined('ENVIRONMENT')
+ ? array(ENVIRONMENT.'/'.$file, $file)
+ : array($file);
+
foreach ($this->_config_paths as $path)
{
- $check_locations = defined('ENVIRONMENT')
- ? array(ENVIRONMENT.'/'.$file, $file)
- : array($file);
-
foreach ($check_locations as $location)
{
$file_path = $path.'config/'.$location.'.php';
@@ -172,7 +172,7 @@ class CI_Config {
{
return FALSE;
}
- show_error('The configuration file '.$file.'.php'.' does not exist.');
+ show_error('The configuration file '.$file.'.php does not exist.');
}
return TRUE;
@@ -211,7 +211,7 @@ class CI_Config {
{
return FALSE;
}
- elseif (trim($this->config[$item]) == '')
+ elseif (trim($this->config[$item]) === '')
{
return '';
}
@@ -225,25 +225,39 @@ class CI_Config {
* Site URL
* Returns base_url . index_page [. uri_string]
*
- * @param string the URI string
+ * @param mixed the URI string or an array of segments
* @return string
*/
public function site_url($uri = '')
{
- if ($uri == '')
+ if (empty($uri))
{
return $this->slash_item('base_url').$this->item('index_page');
}
- if ($this->item('enable_query_strings') == FALSE)
+ $uri = $this->_uri_string($uri);
+
+ if ($this->item('enable_query_strings') === FALSE)
{
- $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
- return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
+ $suffix = ($this->item('url_suffix') === FALSE) ? '' : $this->item('url_suffix');
+
+ if ($suffix !== '' && ($offset = strpos($uri, '?')) !== FALSE)
+ {
+ $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
+ }
+ else
+ {
+ $uri .= $suffix;
+ }
+
+ return $this->slash_item('base_url').$this->slash_item('index_page').$uri;
}
- else
+ elseif (strpos($uri, '?') === FALSE)
{
- return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
+ $uri = '?'.$uri;
}
+
+ return $this->slash_item('base_url').$this->item('index_page').$uri;
}
// -------------------------------------------------------------
@@ -257,7 +271,7 @@ class CI_Config {
*/
public function base_url($uri = '')
{
- return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
+ return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/');
}
// -------------------------------------------------------------
@@ -270,7 +284,7 @@ class CI_Config {
*/
protected function _uri_string($uri)
{
- if ($this->item('enable_query_strings') == FALSE)
+ if ($this->item('enable_query_strings') === FALSE)
{
if (is_array($uri))
{
@@ -280,15 +294,7 @@ class CI_Config {
}
elseif (is_array($uri))
{
- $i = 0;
- $str = '';
- foreach ($uri as $key => $val)
- {
- $prefix = ($i === 0) ? '' : '&';
- $str .= $prefix.$key.'='.$val;
- $i++;
- }
- return $str;
+ return http_build_query($uri);
}
return $uri;
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 965a717ad..bd9178dbd 100755..100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -143,7 +143,7 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.$template.'.php');
+ include(VIEWPATH.'errors/'.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
@@ -177,7 +177,7 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/error_php.php');
+ include(VIEWPATH.'errors/error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 5bbb0009a..afbf4b453 100755..100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -39,7 +39,7 @@
class CI_Hooks {
/**
- * Determines wether hooks are enabled
+ * Determines whether hooks are enabled
*
* @var bool
*/
@@ -53,7 +53,7 @@ class CI_Hooks {
public $hooks = array();
/**
- * Determines wether hook is in progress, used to prevent infinte loops
+ * Determines whether hook is in progress, used to prevent infinte loops
*
* @var bool
*/
@@ -72,7 +72,7 @@ class CI_Hooks {
// If hooks are not enabled in the config file
// there is nothing else to do
- if ($CFG->item('enable_hooks') == FALSE)
+ if ($CFG->item('enable_hooks') === FALSE)
{
return;
}
diff --git a/system/core/Input.php b/system/core/Input.php
index e916ac66d..657fce625 100755..100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -135,7 +135,7 @@ class CI_Input {
{
if ( ! isset($array[$index]))
{
- return FALSE;
+ return NULL;
}
if ($xss_clean === TRUE)
@@ -263,23 +263,27 @@ class CI_Input {
}
}
- if ($prefix == '' && config_item('cookie_prefix') != '')
+ if ($prefix === '' && config_item('cookie_prefix') !== '')
{
$prefix = config_item('cookie_prefix');
}
+
if ($domain == '' && config_item('cookie_domain') != '')
{
$domain = config_item('cookie_domain');
}
- if ($path == '/' && config_item('cookie_path') !== '/')
+
+ if ($path === '/' && config_item('cookie_path') !== '/')
{
$path = config_item('cookie_path');
}
- if ($secure == FALSE && 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)
+
+ if ($httponly === FALSE && config_item('cookie_httponly') !== FALSE)
{
$httponly = config_item('cookie_httponly');
}
@@ -326,10 +330,37 @@ class CI_Input {
if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
{
+ $has_ranges = strpos($proxies, '/') !== FALSE;
$proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
$proxies = is_array($proxies) ? $proxies : array($proxies);
- $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
+ if ($has_ranges)
+ {
+ $long_ip = ip2long($_SERVER['REMOTE_ADDR']);
+ $bit_32 = 1 << 32;
+
+ // Go through each of the IP Addresses to check for and
+ // test against range notation
+ foreach ($proxies as $ip)
+ {
+ list($address, $mask_length) = explode('/', $ip, 2);
+
+ // Generate the bitmask for a 32 bit IP Address
+ $bitmask = $bit_32 - (1 << (32 - (int) $mask_length));
+ if (($long_ip & $bitmask) === $address)
+ {
+ $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ break;
+ }
+ }
+
+ }
+ else
+ {
+ $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies)
+ ? $_SERVER['HTTP_X_FORWARDED_FOR']
+ : $_SERVER['REMOTE_ADDR'];
+ }
}
elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR'))
{
@@ -356,7 +387,7 @@ class CI_Input {
if (strpos($this->ip_address, ',') !== FALSE)
{
$x = explode(',', $this->ip_address);
- $this->ip_address = trim(end($x));
+ $this->ip_address = trim($x[0]);
}
if ( ! $this->valid_ip($this->ip_address))
@@ -372,14 +403,26 @@ class CI_Input {
/**
* Validate IP Address
*
- * Updated version suggested by Geert De Deckere
- *
* @param string
+ * @param string 'ipv4' or 'ipv6'
* @return bool
*/
- public function valid_ip($ip)
+ public function valid_ip($ip, $which = '')
{
- return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
+ switch (strtolower($which))
+ {
+ case 'ipv4':
+ $which = FILTER_FLAG_IPV4;
+ break;
+ case 'ipv6':
+ $which = FILTER_FLAG_IPV6;
+ break;
+ default:
+ $which = NULL;
+ break;
+ }
+
+ return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
}
// --------------------------------------------------------------------
@@ -459,7 +502,7 @@ class CI_Input {
}
// Is $_GET data allowed? If not we'll set the $_GET to an empty array
- if ($this->_allow_get_array == FALSE)
+ if ($this->_allow_get_array === FALSE)
{
$_GET = array();
}
@@ -502,7 +545,7 @@ class CI_Input {
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
// CSRF Protection check
- if ($this->_enable_csrf == TRUE)
+ if ($this->_enable_csrf === TRUE)
{
$this->security->csrf_verify();
}
@@ -559,7 +602,7 @@ class CI_Input {
}
// Standardize newlines if needed
- if ($this->_standardize_newlines == TRUE && 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);
}
@@ -659,7 +702,7 @@ class CI_Input {
if ( ! isset($this->headers[$index]))
{
- return FALSE;
+ return NULL;
}
return ($xss_clean === TRUE)
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 5cb0cad71..3001f1b13 100755..100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -65,37 +65,37 @@ class CI_Lang {
/**
* Load a language file
*
- * @param mixed the name of the language file to be loaded. Can be an array
+ * @param mixed the name of the language file to be loaded
* @param string the language (english, etc.)
* @param bool return loaded array of translations
* @param bool add suffix to $langfile
* @param string alternative path to look for language file
* @return mixed
*/
- public function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
+ public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
$langfile = str_replace('.php', '', $langfile);
- if ($add_suffix == TRUE)
+ if ($add_suffix === TRUE)
{
$langfile = str_replace('_lang', '', $langfile).'_lang';
}
$langfile .= '.php';
- if ($idiom == '')
+ if ($idiom === '')
{
$config =& get_config();
$idiom = ( ! empty($config['language'])) ? $config['language'] : 'english';
}
- if ($return == FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
+ if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
{
return;
}
// Determine where the language file is and load it
- if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile))
+ if ($alt_path !== '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile))
{
include($alt_path.'language/'.$idiom.'/'.$langfile);
}
@@ -124,14 +124,14 @@ class CI_Lang {
{
log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
- if ($return == TRUE)
+ if ($return === TRUE)
{
return array();
}
return;
}
- if ($return == TRUE)
+ if ($return === TRUE)
{
return $lang;
}
@@ -153,7 +153,7 @@ class CI_Lang {
*/
public function line($line = '')
{
- $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
+ $value = ($line === '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
// Because killer robots like unicorns!
if ($value === FALSE)
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 3eb09e6ab..75e93608a 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -208,7 +208,7 @@ class CI_Loader {
return;
}
- if ($library == '' OR isset($this->_base_classes[$library]))
+ if ($library === '' OR isset($this->_base_classes[$library]))
{
return FALSE;
}
@@ -237,14 +237,14 @@ class CI_Loader {
{
if (is_array($model))
{
- foreach ($model as $babe)
+ foreach ($model as $class)
{
- $this->model($babe);
+ $this->model($class);
}
return;
}
- if ($model == '')
+ if ($model === '')
{
return;
}
@@ -261,7 +261,7 @@ class CI_Loader {
$model = substr($model, $last_slash);
}
- if ($name == '')
+ if (empty($name))
{
$name = $model;
}
@@ -329,7 +329,7 @@ class CI_Loader {
$CI =& get_instance();
// Do we even need to load the database class?
- if (class_exists('CI_DB') && $return == FALSE && $query_builder == NULL && isset($CI->db) && is_object($CI->db))
+ if (class_exists('CI_DB') && $return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db))
{
return FALSE;
}
@@ -409,8 +409,8 @@ class CI_Loader {
* 1. The name of the "view" file to be included.
* 2. An associative array of data to be extracted for use in the view.
* 3. TRUE/FALSE - whether to return the data or load it. In
- * some cases it's advantageous to be able to return data so that
- * a developer can process it in some way.
+ * some cases it's advantageous to be able to return data so that
+ * a developer can process it in some way.
*
* @param string
* @param array
@@ -452,7 +452,7 @@ class CI_Loader {
*/
public function vars($vars = array(), $val = '')
{
- if ($val != '' && is_string($vars))
+ if ($val !== '' && is_string($vars))
{
$vars = array($vars => $val);
}
@@ -633,16 +633,10 @@ class CI_Loader {
{
$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
- require BASEPATH.'libraries/Driver.php';
+ return;
}
- if ($library == '')
+ if ($library === '')
{
return FALSE;
}
@@ -668,7 +662,7 @@ class CI_Loader {
* @param bool
* @return void
*/
- public function add_package_path($path, $view_cascade=TRUE)
+ public function add_package_path($path, $view_cascade = TRUE)
{
$path = rtrim($path, '/').'/';
@@ -714,7 +708,7 @@ class CI_Loader {
{
$config =& $this->_ci_get_component('config');
- if ($path == '')
+ if ($path === '')
{
array_shift($this->_ci_library_paths);
array_shift($this->_ci_model_paths);
@@ -775,7 +769,7 @@ class CI_Loader {
$file_exists = FALSE;
// Set the path to the requested file
- if ($_ci_path != '')
+ if (is_string($_ci_path) && $_ci_path !== '')
{
$_ci_x = explode('/', $_ci_path);
$_ci_file = end($_ci_x);
@@ -783,13 +777,13 @@ class CI_Loader {
else
{
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
- $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;
+ $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
- foreach ($this->_ci_view_paths as $view_file => $cascade)
+ foreach ($this->_ci_view_paths as $_ci_view_file => $cascade)
{
- if (file_exists($view_file.$_ci_file))
+ if (file_exists($_ci_view_file.$_ci_file))
{
- $_ci_path = $view_file.$_ci_file;
+ $_ci_path = $_ci_view_file.$_ci_file;
$file_exists = TRUE;
break;
}
@@ -820,7 +814,7 @@ class CI_Loader {
/*
* Extract and cache variables
*
- * You can either set variables using the dedicated $this->load_vars()
+ * You can either set variables using the dedicated $this->load->vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
@@ -837,17 +831,17 @@ class CI_Loader {
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
* 2. So that the final rendered template can be post-processed by
- * the output class. Why do we need post processing? For one thing,
- * in order to show the elapsed page load time. Unless we can
- * intercept the content right before it's sent to the browser and
- * then stop the timer it won't be accurate.
+ * the output class. Why do we need post processing? For one thing,
+ * in order to show the elapsed page load time. Unless we can
+ * intercept the content right before it's sent to the browser and
+ * then stop the timer it won't be accurate.
*/
ob_start();
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
- if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE && 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))));
}
@@ -915,6 +909,13 @@ class CI_Loader {
// Get the filename from the path
$class = substr($class, $last_slash);
+
+ // Check for match and driver base class
+ if (strtolower(trim($subdir, '/')) == strtolower($class) && ! class_exists('CI_Driver_Library'))
+ {
+ // We aren't instantiating an object here, just making the base class available
+ require BASEPATH.'libraries/Driver.php';
+ }
}
// We'll test for both lowercase and capitalized versions of the file name
@@ -996,19 +997,24 @@ class CI_Loader {
$this->_ci_loaded_files[] = $filepath;
return $this->_ci_init_class($class, '', $params, $object_name);
}
-
} // END FOREACH
// One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
- if ($subdir == '')
+ if ($subdir === '')
{
$path = strtolower($class).'/'.$class;
- return $this->_ci_load_class($path, $params);
+ return $this->_ci_load_class($path, $params, $object_name);
+ }
+ else if (ucfirst($subdir) != $subdir)
+ {
+ // Lowercase subdir failed - retry capitalized
+ $path = ucfirst($subdir).$class;
+ return $this->_ci_load_class($path, $params, $object_name);
}
// If we got this far we were unable to find the requested class.
// We do not issue errors if the load call failed due to a duplicate request
- if ($is_duplicate == FALSE)
+ if ($is_duplicate === FALSE)
{
log_message('error', 'Unable to load the requested class: '.$class);
show_error('Unable to load the requested class: '.$class);
@@ -1067,7 +1073,7 @@ class CI_Loader {
}
}
- if ($prefix == '')
+ if ($prefix === '')
{
if (class_exists('CI_'.$class))
{
@@ -1091,7 +1097,7 @@ class CI_Loader {
if ( ! class_exists($name))
{
log_message('error', 'Non-existent class: '.$name);
- show_error('Non-existent class: '.$class);
+ show_error('Non-existent class: '.$name);
}
// Set the variable name we will assign the class to
@@ -1193,6 +1199,15 @@ class CI_Loader {
}
}
+ // Autoload drivers
+ if (isset($autoload['drivers']))
+ {
+ foreach ($autoload['drivers'] as $item)
+ {
+ $this->driver($item);
+ }
+ }
+
// Autoload models
if (isset($autoload['model']))
{
diff --git a/system/core/Model.php b/system/core/Model.php
index 9bc9f879f..9bc9f879f 100755..100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
diff --git a/system/core/Output.php b/system/core/Output.php
index c8feb4e67..052367ed6 100755..100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -64,10 +64,17 @@ class CI_Output {
*
* @var array
*/
- public $mime_types = array();
+ public $mimes = array();
/**
- * Determines wether profiler is enabled
+ * Mime-type for the current page
+ *
+ * @var string
+ */
+ protected $mime_type = 'text/html';
+
+ /**
+ * Determines whether profiler is enabled
*
* @var book
*/
@@ -78,7 +85,7 @@ class CI_Output {
*
* @var bool
*/
- protected $_zlib_oc = FALSE;
+ protected $_zlib_oc = FALSE;
/**
* List of profiler sections
@@ -101,20 +108,11 @@ class CI_Output {
*/
public function __construct()
{
- $this->_zlib_oc = @ini_get('zlib.output_compression');
+ $this->_zlib_oc = (bool) @ini_get('zlib.output_compression');
// Get mime types for later
- if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
- {
- include APPPATH.'config/'.ENVIRONMENT.'/mimes.php';
- }
- else
- {
- include APPPATH.'config/mimes.php';
- }
+ $this->mimes =& get_mimes();
-
- $this->mime_types = $mimes;
log_message('debug', 'Output Class Initialized');
}
@@ -183,7 +181,7 @@ class CI_Output {
* how to permit header data to be saved with the cache data...
*
* @param string
- * @param bool
+ * @param bool
* @return void
*/
public function set_header($header, $replace = TRUE)
@@ -192,7 +190,7 @@ class CI_Output {
// but it will not modify the content-length header to compensate for
// the reduction, causing the browser to hang waiting for more data.
// We'll just skip content-length in those cases.
- if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0)
+ if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0)
{
return;
}
@@ -209,16 +207,16 @@ class CI_Output {
* @param string extension of the file we're outputting
* @return void
*/
- public function set_content_type($mime_type)
+ public function set_content_type($mime_type, $charset = NULL)
{
if (strpos($mime_type, '/') === FALSE)
{
$extension = ltrim($mime_type, '.');
// Is this extension supported?
- if (isset($this->mime_types[$extension]))
+ if (isset($this->mimes[$extension]))
{
- $mime_type =& $this->mime_types[$extension];
+ $mime_type =& $this->mimes[$extension];
if (is_array($mime_type))
{
@@ -227,7 +225,15 @@ class CI_Output {
}
}
- $header = 'Content-Type: '.$mime_type;
+ $this->mime_type = $mime_type;
+
+ if (empty($charset))
+ {
+ $charset = config_item('charset');
+ }
+
+ $header = 'Content-Type: '.$mime_type
+ .(empty($charset) ? NULL : '; charset='.strtolower($charset));
$this->headers[] = array($header, TRUE);
return $this;
@@ -295,6 +301,12 @@ class CI_Output {
*/
public function set_profiler_sections($sections)
{
+ if (isset($sections['query_toggle_count']))
+ {
+ $this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count'];
+ unset($sections['query_toggle_count']);
+ }
+
foreach ($sections as $section => $enable)
{
$this->_profiler_sections[$section] = ($enable !== FALSE);
@@ -330,7 +342,7 @@ class CI_Output {
* with any server headers and profile data. It also stops the
* benchmark timer so the page rendering speed and memory usage can be shown.
*
- * @param string
+ * @param string
* @return mixed
*/
public function _display($output = '')
@@ -349,13 +361,22 @@ class CI_Output {
// --------------------------------------------------------------------
// Set the output data
- if ($output == '')
+ if ($output === '')
{
$output =& $this->final_output;
}
// --------------------------------------------------------------------
+ // Is minify requested?
+ if ($CFG->item('minify_output') === TRUE)
+ {
+ $output = $this->minify($output, $this->mime_type);
+ }
+
+
+ // --------------------------------------------------------------------
+
// Do we need to write a cache file? Only if the controller does not have its
// own _output() method and we are not dealing with a cache file, which we
// can determine by the existence of the $CI object above
@@ -373,7 +394,7 @@ class CI_Output {
if ($this->parse_exec_vars === TRUE)
{
- $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0';
+ $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB';
$output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
}
@@ -381,7 +402,7 @@ class CI_Output {
// --------------------------------------------------------------------
// Is compression requested?
- if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE
+ if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc === FALSE
&& extension_loaded('zlib')
&& isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
{
@@ -416,7 +437,7 @@ class CI_Output {
// Do we need to generate profile data?
// If so, load the Profile class and run it.
- if ($this->enable_profiler == TRUE)
+ if ($this->enable_profiler === TRUE)
{
$CI->load->library('profiler');
if ( ! empty($this->_profiler_sections))
@@ -453,14 +474,14 @@ class CI_Output {
/**
* Write a Cache File
*
- * @param string
+ * @param string
* @return void
*/
public function _write_cache($output)
{
$CI =& get_instance();
$path = $CI->config->item('cache_path');
- $cache_path = ($path == '') ? APPPATH.'cache/' : $path;
+ $cache_path = ($path === '') ? APPPATH.'cache/' : $path;
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
@@ -496,6 +517,9 @@ class CI_Output {
@chmod($cache_path, FILE_WRITE_MODE);
log_message('debug', 'Cache file written: '.$cache_path);
+
+ // Send HTTP cache-control headers to browser to match file cache settings.
+ $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
}
// --------------------------------------------------------------------
@@ -503,13 +527,13 @@ class CI_Output {
/**
* Update/serve a cached file
*
- * @param object config class
- * @param object uri class
- * @return void
+ * @param object config class
+ * @param object uri class
+ * @return bool
*/
public function _display_cache(&$CFG, &$URI)
{
- $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
+ $cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path');
// Build the file path. The file name is an MD5 hash of the full URI
$uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
@@ -528,25 +552,168 @@ class CI_Output {
fclose($fp);
// Strip out the embedded timestamp
- if ( ! preg_match('/(\d+TS--->)/', $cache, $match))
+ if ( ! preg_match('/^(\d+)TS--->/', $cache, $match))
{
return FALSE;
}
- // Has the file expired? If so we'll delete it.
- if (time() >= trim(str_replace('TS--->', '', $match[1])) && is_really_writable($cache_path))
+ $last_modified = filemtime($cache_path);
+ $expire = $match[1];
+
+ // Has the file expired?
+ if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path))
{
+ // If so we'll delete it.
@unlink($filepath);
log_message('debug', 'Cache file has expired. File deleted.');
return FALSE;
}
+ else
+ {
+ // Or else send the HTTP cache control headers.
+ $this->set_cache_header($last_modified, $expire);
+ }
// Display the cache
- $this->_display(str_replace($match[0], '', $cache));
+ $this->_display(substr($cache, strlen($match[0])));
log_message('debug', 'Cache file is current. Sending it to browser.');
return TRUE;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Set the HTTP headers to match the server-side file cache settings
+ * in order to reduce bandwidth.
+ *
+ * @param int timestamp of when the page was last modified
+ * @param int timestamp of when should the requested page expire from cache
+ * @return void
+ */
+ public function set_cache_header($last_modified, $expiration)
+ {
+ $max_age = $expiration - $_SERVER['REQUEST_TIME'];
+
+ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
+ {
+ $this->set_status_header(304);
+ exit;
+ }
+ else
+ {
+ header('Pragma: public');
+ header('Cache-Control: max-age=' . $max_age . ', public');
+ header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
+ header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Reduce excessive size of HTML content.
+ *
+ * @param string
+ * @param string
+ * @return string
+ */
+ public function minify($output, $type = 'text/html')
+ {
+ switch ($type)
+ {
+ case 'text/html':
+
+ $size_before = strlen($output);
+
+ if ($size_before === 0)
+ {
+ return '';
+ }
+
+ // Find all the <pre>,<code>,<textarea>, and <javascript> tags
+ // We'll want to return them to this unprocessed state later.
+ preg_match_all('{<pre.+</pre>}msU', $output, $pres_clean);
+ preg_match_all('{<code.+</code>}msU', $output, $codes_clean);
+ preg_match_all('{<textarea.+</textarea>}msU', $output, $textareas_clean);
+ preg_match_all('{<script.+</script>}msU', $output, $javascript_clean);
+
+ // Minify the CSS in all the <style> tags.
+ preg_match_all('{<style.+</style>}msU', $output, $style_clean);
+ foreach ($style_clean[0] as $s)
+ {
+ $output = str_replace($s, $this->minify($s, 'text/css'), $output);
+ }
+
+ // Minify the javascript in <script> tags.
+ foreach ($javascript_clean[0] as $s)
+ {
+ $javascript_mini[] = $this->minify($s, 'text/javascript');
+ }
+
+ // Replace multiple spaces with a single space.
+ $output = preg_replace('!\s{2,}!', ' ', $output);
+
+ // Remove comments (non-MSIE conditionals)
+ $output = preg_replace('{\s*<!--[^\[].*-->\s*}msU', '', $output);
+
+ // Remove spaces around block-level elements.
+ $output = preg_replace('/\s*(<\/?(html|head|title|meta|script|link|style|body|h[1-6]|div|p|br)[^>]*>)\s*/is', '$1', $output);
+
+ // Replace mangled <pre> etc. tags with unprocessed ones.
+
+ if ( ! empty($pres_clean))
+ {
+ preg_match_all('{<pre.+</pre>}msU', $output, $pres_messed);
+ $output = str_replace($pres_messed[0], $pres_clean[0], $output);
+ }
+
+ if ( ! empty($codes_clean))
+ {
+ preg_match_all('{<code.+</code>}msU', $output, $codes_messed);
+ $output = str_replace($codes_messed[0], $codes_clean[0], $output);
+ }
+
+ if ( ! empty($codes_clean))
+ {
+ preg_match_all('{<textarea.+</textarea>}msU', $output, $textareas_messed);
+ $output = str_replace($textareas_messed[0], $textareas_clean[0], $output);
+ }
+
+ if (isset($javascript_mini))
+ {
+ preg_match_all('{<script.+</script>}msU', $output, $javascript_messed);
+ $output = str_replace($javascript_messed[0], $javascript_mini, $output);
+ }
+
+ $size_removed = $size_before - strlen($output);
+ $savings_percent = round(($size_removed / $size_before * 100));
+
+ log_message('debug', 'Minifier shaved '.($size_removed / 1000).'KB ('.$savings_percent.'%) off final HTML output.');
+
+ break;
+
+ case 'text/css':
+
+ //Remove CSS comments
+ $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $output);
+
+ // Remove spaces around curly brackets, colons,
+ // semi-colons, parenthesis, commas
+ $output = preg_replace('!\s*(:|;|,|}|{|\(|\))\s*!', '$1', $output);
+
+ break;
+
+ case 'text/javascript':
+
+ // Currently leaves JavaScript untouched.
+ break;
+
+ default: break;
+ }
+
+ return $output;
+ }
+
}
/* End of file Output.php */
diff --git a/system/core/Router.php b/system/core/Router.php
index 5ea13797b..5bc053045 100755..100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -435,7 +435,7 @@ class CI_Router {
*/
public function fetch_method()
{
- return ($this->method == $this->fetch_class()) ? 'index' : $this->method;
+ return ($this->method === $this->fetch_class()) ? 'index' : $this->method;
}
// --------------------------------------------------------------------
@@ -483,7 +483,7 @@ class CI_Router {
$this->set_directory($routing['directory']);
}
- if (isset($routing['controller']) && $routing['controller'] != '')
+ if ( ! empty($routing['controller']))
{
$this->set_class($routing['controller']);
}
diff --git a/system/core/Security.php b/system/core/Security.php
index 81b6602ae..b22d2cf19 100755..100644
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -162,7 +162,7 @@ class CI_Security {
// Do the tokens exist in both the _POST and _COOKIE arrays?
if ( ! isset($_POST[$this->_csrf_token_name]) OR ! isset($_COOKIE[$this->_csrf_cookie_name])
- OR $_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) // Do the tokens match?
+ OR $_POST[$this->_csrf_token_name] !== $_COOKIE[$this->_csrf_cookie_name]) // Do the tokens match?
{
$this->csrf_show_error();
}
@@ -191,6 +191,7 @@ class CI_Security {
* Set Cross Site Request Forgery Protection Cookie
*
* @return object
+ * @codeCoverageIgnore
*/
public function csrf_set_cookie()
{
@@ -394,20 +395,20 @@ class CI_Security {
if (preg_match('/<a/i', $str))
{
- $str = preg_replace_callback('#<a\s+([^>]*?)(>|$)#si', array($this, '_js_link_removal'), $str);
+ $str = preg_replace_callback('#<a\s+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str);
}
if (preg_match('/<img/i', $str))
{
- $str = preg_replace_callback('#<img\s+([^>]*?)(\s?/?>|$)#si', array($this, '_js_img_removal'), $str);
+ $str = preg_replace_callback('#<img\s+([^>]*?)(?:\s?/?>|$)#si', array($this, '_js_img_removal'), $str);
}
- if (preg_match('/(script|xss)/i', $str))
+ if (preg_match('/script|xss/i', $str))
{
- $str = preg_replace('#<(/*)(script|xss)(.*?)\>#si', '[removed]', $str);
+ $str = preg_replace('#</*(?:script|xss).*?>#si', '[removed]', $str);
}
}
- while($original != $str);
+ while ($original !== $str);
unset($original);
@@ -474,7 +475,7 @@ class CI_Security {
*/
public function xss_hash()
{
- if ($this->_xss_hash == '')
+ if ($this->_xss_hash === '')
{
mt_srand();
$this->_xss_hash = md5(time() + mt_rand(0, 1999999999));
@@ -560,6 +561,19 @@ class CI_Security {
// ----------------------------------------------------------------
/**
+ * Strip Image Tags
+ *
+ * @param string
+ * @return string
+ */
+ public function strip_image_tags($str)
+ {
+ return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
+ }
+
+ // ----------------------------------------------------------------
+
+ /**
* Compact Exploded Words
*
* Callback function for xss_clean() to remove whitespace from
@@ -669,7 +683,7 @@ class CI_Security {
protected function _js_link_removal($match)
{
return str_replace($match[1],
- preg_replace('#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si',
+ preg_replace('#href=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
@@ -692,7 +706,7 @@ class CI_Security {
protected function _js_img_removal($match)
{
return str_replace($match[1],
- preg_replace('#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
+ preg_replace('#src=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
@@ -824,14 +838,14 @@ class CI_Security {
*/
protected function _csrf_set_hash()
{
- if ($this->_csrf_hash == '')
+ if ($this->_csrf_hash === '')
{
// If the cookie exists we will use it's value.
// We don't necessarily want to regenerate it with
// each page load since a page could contain embedded
// sub-pages causing this feature to fail
if (isset($_COOKIE[$this->_csrf_cookie_name]) &&
- $_COOKIE[$this->_csrf_cookie_name] != '')
+ preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1)
{
return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
}
diff --git a/system/core/URI.php b/system/core/URI.php
index e66cb6dc5..6a8b1a5ac 100755..100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -111,23 +111,23 @@ class CI_URI {
// Is there a PATH_INFO variable?
// Note: some servers seem to have trouble with getenv() so we'll test it two ways
- $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
- if (trim($path, '/') != '' && $path !== '/'.SELF)
+ $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
+ if (trim($path, '/') !== '' && $path !== '/'.SELF)
{
$this->_set_uri_string($path);
return;
}
// No PATH_INFO?... What about QUERY_STRING?
- $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
- if (trim($path, '/') != '')
+ $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+ if (trim($path, '/') !== '')
{
$this->_set_uri_string($path);
return;
}
// As a last ditch effort lets try using the $_GET array
- if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '')
+ if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') !== '')
{
$this->_set_uri_string(key($_GET));
return;
@@ -163,7 +163,7 @@ class CI_URI {
* @param string
* @return void
*/
- public function _set_uri_string($str)
+ protected function _set_uri_string($str)
{
// Filter out control characters
$str = remove_invisible_characters($str, FALSE);
@@ -177,8 +177,8 @@ class CI_URI {
/**
* Detects the URI
*
- * This function will detect the URI automatically and fix the query string
- * if necessary.
+ * This function will detect the URI automatically
+ * and fix the query string if necessary.
*
* @return string
*/
@@ -189,23 +189,27 @@ class CI_URI {
return '';
}
- $uri = $_SERVER['REQUEST_URI'];
- if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
+ if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
{
- $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
+ $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
}
- elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
+ elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
- $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
+ $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])));
+ }
+ else
+ {
+ $uri = $_SERVER['REQUEST_URI'];
}
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
- if (strncmp($uri, '?/', 2) === 0)
+ if (strpos($uri, '?/') === 0)
{
$uri = substr($uri, 2);
}
- $parts = preg_split('#\?#i', $uri, 2);
+
+ $parts = explode('?', $uri, 2);
$uri = $parts[0];
if (isset($parts[1]))
{
@@ -218,12 +222,12 @@ class CI_URI {
$_GET = array();
}
- if ($uri == '/' OR empty($uri))
+ if ($uri === '/' OR empty($uri))
{
return '/';
}
- $uri = parse_url($uri, PHP_URL_PATH);
+ $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH);
// Do some final cleaning of the URI and return it
return str_replace(array('//', '../'), '/', trim($uri, '/'));
@@ -270,11 +274,11 @@ class CI_URI {
*/
public function _filter_uri($str)
{
- if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
+ if ($str !== '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') === FALSE)
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
- if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
+ if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', urldecode($str)))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
@@ -298,9 +302,11 @@ class CI_URI {
*/
public function _remove_url_suffix()
{
- if ($this->config->item('url_suffix') != '')
+ $suffix = (string) $this->config->item('url_suffix');
+
+ if ($suffix !== '' && ($offset = strrpos($this->uri_string, $suffix)) !== FALSE)
{
- $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string);
+ $this->uri_string = substr_replace($this->uri_string, '', $offset, strlen($suffix));
}
}
@@ -321,7 +327,7 @@ class CI_URI {
// Filter segments for security
$val = trim($this->_filter_uri($val));
- if ($val != '')
+ if ($val !== '')
{
$this->segments[] = $val;
}
@@ -358,10 +364,10 @@ class CI_URI {
* This function returns the URI segment based on the number provided.
*
* @param int
- * @param bool
+ * @param mixed
* @return string
*/
- public function segment($n, $no_result = FALSE)
+ public function segment($n, $no_result = NULL)
{
return isset($this->segments[$n]) ? $this->segments[$n] : $no_result;
}
@@ -376,10 +382,10 @@ class CI_URI {
* same result as $this->segment()
*
* @param int
- * @param bool
+ * @param mixed
* @return string
*/
- public function rsegment($n, $no_result = FALSE)
+ public function rsegment($n, $no_result = NULL)
{
return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result;
}
@@ -462,7 +468,7 @@ class CI_URI {
{
return (count($default) === 0)
? array()
- : array_fill_keys($default, FALSE);
+ : array_fill_keys($default, NULL);
}
$segments = array_slice($this->$segment_array(), ($n - 1));
@@ -477,7 +483,7 @@ class CI_URI {
}
else
{
- $retval[$seg] = FALSE;
+ $retval[$seg] = NULL;
$lastval = $seg;
}
@@ -490,7 +496,7 @@ class CI_URI {
{
if ( ! array_key_exists($val, $retval))
{
- $retval[$val] = FALSE;
+ $retval[$val] = NULL;
}
}
}
@@ -511,7 +517,7 @@ class CI_URI {
public function assoc_to_uri($array)
{
$temp = array();
- foreach ( (array) $array as $key => $val)
+ foreach ((array) $array as $key => $val)
{
$temp[] = $key;
$temp[] = $val;
@@ -644,7 +650,7 @@ class CI_URI {
*/
public function ruri_string()
{
- return '/'.implode('/', $this->rsegment_array());
+ return implode('/', $this->rsegment_array());
}
}
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index a6faa84ec..0a7ec501c 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -54,7 +54,7 @@ class CI_Utf8 {
if (
@preg_match('/./u', 'é') === 1 // PCRE must support UTF-8
&& function_exists('iconv') // iconv must be installed
- && @ini_get('mbstring.func_overload') != 1 // Multibyte string function overloading cannot be enabled
+ && (bool) @ini_get('mbstring.func_overload') !== TRUE // Multibyte string function overloading cannot be enabled
&& $CFG->item('charset') === 'UTF-8' // Application charset must be UTF-8
)
{
diff --git a/system/database/DB.php b/system/database/DB.php
index b28439b29..d751325ce 100755..100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -29,8 +29,8 @@
* Initialize the database
*
* @category Database
- * @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
* @param string
* @param bool Determines if query builder should be used or not
*/
@@ -47,13 +47,28 @@ function &DB($params = '', $query_builder_override = NULL)
}
include($file_path);
+ //make packages contain database config files
+ foreach(get_instance()->load->get_package_paths() as $path)
+ {
+ if ($path !== APPPATH)
+ {
+ if (file_exists ($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
+ {
+ include ($file_path);
+ }
+ elseif ( file_exists ($file_path = $path.'config/database.php'))
+ {
+ include ($file_path);
+ }
+ }
+ }
if ( ! isset($db) OR count($db) === 0)
{
show_error('No database connection settings were found in the database config file.');
}
- if ($params != '')
+ if ($params !== '')
{
$active_group = $params;
}
@@ -106,7 +121,7 @@ function &DB($params = '', $query_builder_override = NULL)
}
// No DB specified yet? Beat them senseless...
- if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
+ if (empty($params['dbdriver']))
{
show_error('You have not selected a database type to connect to.');
}
@@ -118,10 +133,17 @@ function &DB($params = '', $query_builder_override = NULL)
{
$query_builder = $query_builder_override;
}
+ // Backwards compatibility work-around for keeping the
+ // $active_record config variable working. Should be
+ // removed in v3.1
+ elseif ( ! isset($query_builder) && isset($active_record))
+ {
+ $query_builder = $active_record;
+ }
require_once(BASEPATH.'database/DB_driver.php');
- if ( ! isset($query_builder) OR $query_builder == TRUE)
+ if ( ! isset($query_builder) OR $query_builder === TRUE)
{
require_once(BASEPATH.'database/DB_query_builder.php');
if ( ! class_exists('CI_DB'))
@@ -137,7 +159,10 @@ function &DB($params = '', $query_builder_override = NULL)
// Load the DB driver
$driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php';
- if ( ! file_exists($driver_file)) show_error('Invalid DB driver');
+ if ( ! file_exists($driver_file))
+ {
+ show_error('Invalid DB driver');
+ }
require_once($driver_file);
@@ -145,12 +170,25 @@ function &DB($params = '', $query_builder_override = NULL)
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
$DB = new $driver($params);
- if ($DB->autoinit == TRUE)
+ // Check for a subdriver
+ if ( ! empty($DB->subdriver))
+ {
+ $driver_file = BASEPATH.'database/drivers/'.$DB->dbdriver.'/subdrivers/'.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php';
+
+ if (file_exists($driver_file))
+ {
+ require_once($driver_file);
+ $driver = 'CI_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver';
+ $DB = new $driver($params);
+ }
+ }
+
+ if ($DB->autoinit === TRUE)
{
$DB->initialize();
}
- if (isset($params['stricton']) && $params['stricton'] == TRUE)
+ if ( ! empty($params['stricton']))
{
$DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"');
}
@@ -159,4 +197,4 @@ function &DB($params = '', $query_builder_override = NULL)
}
/* End of file DB.php */
-/* Location: ./system/database/DB.php */
+/* Location: ./system/database/DB.php */ \ No newline at end of file
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index ff942856b..ba9110382 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -55,9 +55,9 @@ class CI_DB_Cache {
*/
public function check_path($path = '')
{
- if ($path == '')
+ if ($path === '')
{
- if ($this->db->cachedir == '')
+ if ($this->db->cachedir === '')
{
return $this->db->cache_off();
}
@@ -99,7 +99,7 @@ class CI_DB_Cache {
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
- if (FALSE === ($cachedata = read_file($filepath)))
+ if (FALSE === ($cachedata = file_get_contents($filepath)))
{
return FALSE;
}
@@ -154,12 +154,12 @@ class CI_DB_Cache {
*/
public function delete($segment_one = '', $segment_two = '')
{
- if ($segment_one == '')
+ if ($segment_one === '')
{
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
}
- if ($segment_two == '')
+ if ($segment_two === '')
{
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index ef77b594e..b12042bde 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -45,11 +45,13 @@ abstract class CI_DB_driver {
public $password;
public $hostname;
public $database;
- public $dbdriver = 'mysql';
+ public $dbdriver = 'mysqli';
+ public $subdriver;
public $dbprefix = '';
public $char_set = 'utf8';
public $dbcollat = 'utf8_general_ci';
public $autoinit = TRUE; // Whether to automatically initialize the DB
+ public $compress = TRUE;
public $swap_pre = '';
public $port = '';
public $pconnect = FALSE;
@@ -77,6 +79,23 @@ abstract class CI_DB_driver {
protected $_protect_identifiers = TRUE;
protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
+ // 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 ';
+
+ /**
+ * Constructor
+ *
+ * @param array
+ * @return void
+ */
public function __construct($params)
{
if (is_array($params))
@@ -113,7 +132,7 @@ abstract 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();
+ $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
if ( ! $this->conn_id)
@@ -131,7 +150,7 @@ abstract class CI_DB_driver {
}
// Try to connect
- $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
+ $this->conn_id = ($this->pconnect === FALSE) ? $this->db_connect() : $this->db_pconnect();
// If a connection is made break the foreach loop
if ($this->conn_id)
@@ -295,17 +314,21 @@ abstract class CI_DB_driver {
* @param array An array of binding data
* @return mixed
*/
- public function query($sql, $binds = FALSE, $return_object = TRUE)
+ public function query($sql, $binds = FALSE, $return_object = NULL)
{
- if ($sql == '')
+ if ($sql === '')
{
log_message('error', 'Invalid query: '.$sql);
return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
}
+ elseif ( ! is_bool($return_object))
+ {
+ $return_object = ! $this->is_write_type($sql);
+ }
// Verify table prefix and replace if necessary
- if ($this->dbprefix != '' && $this->swap_pre != '' && $this->dbprefix != $this->swap_pre)
+ if ($this->dbprefix !== '' && $this->swap_pre !== '' && $this->dbprefix !== $this->swap_pre)
{
$sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql);
}
@@ -319,7 +342,7 @@ abstract class CI_DB_driver {
// 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 && stripos($sql, 'SELECT') !== FALSE && $this->_cache_init())
+ if ($this->cache_on === TRUE && $return_object === TRUE && $this->_cache_init())
{
$this->load_rdriver();
if (FALSE !== ($cache = $this->CACHE->read($sql)))
@@ -328,8 +351,8 @@ abstract class CI_DB_driver {
}
}
- // Save the query for debugging
- if ($this->save_queries == TRUE)
+ // Save the query for debugging
+ if ($this->save_queries === TRUE)
{
$this->queries[] = $sql;
}
@@ -340,7 +363,7 @@ abstract class CI_DB_driver {
// Run the Query
if (FALSE === ($this->result_id = $this->simple_query($sql)))
{
- if ($this->save_queries == TRUE)
+ if ($this->save_queries === TRUE)
{
$this->query_times[] = 0;
}
@@ -352,7 +375,7 @@ abstract class CI_DB_driver {
$error = $this->error();
// Log errors
- log_message('error', 'Query error: '.$error['message']);
+ log_message('error', 'Query error: '.$error['message'].' - Invalid query: '.$sql);
if ($this->db_debug)
{
@@ -373,7 +396,7 @@ abstract class CI_DB_driver {
$time_end = microtime(TRUE);
$this->benchmark += $time_end - $time_start;
- if ($this->save_queries == TRUE)
+ if ($this->save_queries === TRUE)
{
$this->query_times[] = $time_end - $time_start;
}
@@ -381,13 +404,11 @@ abstract class CI_DB_driver {
// Increment the query counter
$this->query_count++;
- // Was the query a "write" type?
- // If so we'll simply return true
- if ($this->is_write_type($sql) === TRUE)
+ // Will we have a result object instantiated? If not - we'll simply return TRUE
+ if ($return_object !== TRUE)
{
- // If caching is enabled we'll auto-cleanup any
- // existing files related to this particular URI
- if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init())
+ // If caching is enabled we'll auto-cleanup any existing files related to this particular URI
+ if ($this->cache_on === TRUE && $this->cache_autodel === TRUE && $this->_cache_init())
{
$this->CACHE->delete();
}
@@ -396,8 +417,6 @@ abstract class CI_DB_driver {
}
// Return TRUE if we don't need to create a result object
- // Currently only the Oracle driver uses this when stored
- // procedures are used
if ($return_object !== TRUE)
{
return TRUE;
@@ -409,7 +428,7 @@ abstract class CI_DB_driver {
// Is query caching enabled? If so, we'll serialize the
// result object and save it to a cache file.
- if ($this->cache_on == TRUE && $this->_cache_init())
+ if ($this->cache_on === TRUE && $this->_cache_init())
{
// We'll create a new instance of the result object
// only without the platform specific driver since
@@ -596,35 +615,53 @@ abstract class CI_DB_driver {
*/
public function compile_binds($sql, $binds)
{
- if (strpos($sql, $this->bind_marker) === FALSE)
+ if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
{
return $sql;
}
-
- if ( ! is_array($binds))
+ elseif ( ! is_array($binds))
{
$binds = array($binds);
+ $bind_count = 1;
+ }
+ else
+ {
+ // Make sure we're using numeric keys
+ $binds = array_values($binds);
+ $bind_count = count($binds);
}
- // Get the sql segments around the bind markers
- $segments = explode($this->bind_marker, $sql);
+ // We'll need the marker length later
+ $ml = strlen($this->bind_marker);
- // The count of bind should be 1 less then the count of segments
- // If there are more bind arguments trim it down
- if (count($binds) >= count($segments))
+ // Make sure not to replace a chunk inside a string that happens to match the bind marker
+ if ($c = preg_match_all("/'[^']*'/i", $sql, $matches))
{
- $binds = array_slice($binds, 0, count($segments)-1);
+ $c = preg_match_all('/'.preg_quote($this->bind_marker).'/i',
+ str_replace($matches[0],
+ str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]),
+ $sql, $c),
+ $matches, PREG_OFFSET_CAPTURE);
+
+ // Bind values' count must match the count of markers in the query
+ if ($bind_count !== $c)
+ {
+ return $sql;
+ }
+ }
+ elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker).'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count)
+ {
+ return $sql;
}
- // Construct the binded query
- $result = $segments[0];
- $i = 0;
- foreach ($binds as $bind)
+ do
{
- $result .= $this->escape($bind).$segments[++$i];
+ $c--;
+ $sql = substr_replace($sql, $this->escape($binds[$c]), $matches[0][$c][1], $ml);
}
+ while ($c !== 0);
- return $result;
+ return $sql;
}
// --------------------------------------------------------------------
@@ -637,7 +674,7 @@ abstract class CI_DB_driver {
*/
public function is_write_type($sql)
{
- return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql);
+ return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql);
}
// --------------------------------------------------------------------
@@ -742,6 +779,35 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * "Count All" query
+ *
+ * Generates a platform-specific query string that counts all records in
+ * the specified database
+ *
+ * @param string
+ * @return int
+ */
+ public function count_all($table = '')
+ {
+ if ($table === '')
+ {
+ return 0;
+ }
+
+ $query = $this->query($this->_count_string.$this->escape_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
+ if ($query->num_rows() === 0)
+ {
+ return 0;
+ }
+
+ $query = $query->row();
+ $this->_reset_select();
+ return (int) $query->numrows;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Returns an array of table names
*
* @return array
@@ -808,7 +874,7 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Fetch MySQL Field Names
+ * Fetch Field Names
*
* @param string the table name
* @return array
@@ -821,7 +887,7 @@ abstract class CI_DB_driver {
return $this->data_cache['field_names'][$table];
}
- if ($table == '')
+ if ($table === '')
{
return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
}
@@ -889,7 +955,7 @@ abstract class CI_DB_driver {
*/
public function field_data($table = '')
{
- if ($table == '')
+ if ($table === '')
{
return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
}
@@ -905,34 +971,57 @@ abstract class CI_DB_driver {
*
* This function escapes column and table names
*
- * @param string
- * @return string
+ * @param mixed
+ * @return mixed
*/
public function escape_identifiers($item)
{
- if ($this->_escape_char == '')
+ if ($this->_escape_char === '' OR empty($item))
{
return $item;
}
-
- foreach ($this->_reserved_identifiers as $id)
+ elseif (is_array($item))
{
- if (strpos($item, '.'.$id) !== FALSE)
+ foreach ($item as $key => $value)
{
- $item = str_replace('.', $this->_escape_char.'.', $item);
+ $item[$key] = $this->escape_identifiers($value);
+ }
+
+ return $item;
+ }
+ // Avoid breaking functions and literal values inside queries
+ elseif (ctype_digit($item) OR $item[0] === "'" OR ($this->_escape_char !== '"' && $item[0] === '"') OR strpos($item, '(') !== FALSE)
+ {
+ return $item;
+ }
+
+ static $preg_ec = array();
- // remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
+ if (empty($preg_ec))
+ {
+ if (is_array($this->_escape_char))
+ {
+ $preg_ec = array(
+ preg_quote($this->_escape_char[0]), preg_quote($this->_escape_char[1]),
+ $this->_escape_char[0], $this->_escape_char[1]
+ );
+ }
+ else
+ {
+ $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char);
+ $preg_ec[2] = $preg_ec[3] = $this->_escape_char;
}
}
- if (strpos($item, '.') !== FALSE)
+ foreach ($this->_reserved_identifiers as $id)
{
- $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ if (strpos($item, '.'.$id) !== FALSE)
+ {
+ return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $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);
+ return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
}
// --------------------------------------------------------------------
@@ -960,6 +1049,23 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * 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).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Generate an update string
*
* @param string the table upon which the query will be performed
@@ -969,7 +1075,7 @@ abstract class CI_DB_driver {
*/
public function update_string($table, $data, $where)
{
- if ($where == '')
+ if ($where === '')
{
return FALSE;
}
@@ -989,7 +1095,7 @@ abstract class CI_DB_driver {
$dest = array();
foreach ($where as $key => $val)
{
- $prefix = (count($dest) == 0) ? '' : ' AND ';
+ $prefix = (count($dest) === 0) ? '' : ' AND ';
$key = $this->protect_identifiers($key);
if ($val !== '')
@@ -1012,6 +1118,41 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * 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
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .$where
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .($limit ? ' LIMIT '.$limit : '');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Tests whether the string has an SQL operator
*
* @param string
@@ -1019,7 +1160,21 @@ abstract class CI_DB_driver {
*/
protected function _has_operator($str)
{
- return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL)/i', trim($str));
+ return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL|BETWEEN)/i', trim($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Returns the SQL string operator
+ *
+ * @param string
+ * @return string
+ */
+ protected function _get_operator($str)
+ {
+ return preg_match('/(=|!|<|>| IS NULL| IS NOT NULL| BETWEEN)/i', $str, $match)
+ ? $match[1] : FALSE;
}
// --------------------------------------------------------------------
@@ -1033,7 +1188,7 @@ abstract class CI_DB_driver {
*/
public function call_function($function)
{
- $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
+ $driver = ($this->dbdriver === 'postgre') ? 'pg_' : $this->dbdriver.'_';
if (FALSE === strpos($driver, $function))
{
@@ -1087,7 +1242,6 @@ abstract class CI_DB_driver {
return $this->cache_on = FALSE;
}
-
// --------------------------------------------------------------------
/**
@@ -1152,7 +1306,7 @@ abstract class CI_DB_driver {
{
if ($this->conn_id)
{
- $this->_close($this->conn_id);
+ $this->_close();
$this->conn_id = FALSE;
}
}
@@ -1160,6 +1314,20 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * Close DB Connection
+ *
+ * This method would be overriden by most of the drivers.
+ *
+ * @return void
+ */
+ protected function _close()
+ {
+ $this->conn_id = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Display an error message
*
* @param string the error message
@@ -1174,13 +1342,13 @@ abstract class CI_DB_driver {
$heading = $LANG->line('db_error_heading');
- if ($native == TRUE)
+ if ($native === TRUE)
{
$message = (array) $error;
}
else
{
- $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
+ $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error)));
}
// Find the most likely culprit of the error by going through
@@ -1189,10 +1357,16 @@ abstract class CI_DB_driver {
$trace = debug_backtrace();
foreach ($trace as $call)
{
- if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
+ // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes
+ if (DIRECTORY_SEPARATOR !== '/')
+ {
+ $call['file'] = str_replace('\\', '/', $call['file']);
+ }
+
+ if (isset($call['file'], $call['class']) && strpos($call['file'], $basepath.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE)
{
// Found it - use a relative path for safety
- $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
+ $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']);
$message[] = 'Line Number: '.$call['line'];
break;
}
@@ -1243,34 +1417,43 @@ abstract class CI_DB_driver {
$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, $prefix_single, $protect_identifiers, $field_exists);
}
return $escaped_array;
}
+ // 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
+ // way to deal with this, but I'm not thinking of it -- Rick
+ if (strpos($item, '(') !== FALSE)
+ {
+ return $item;
+ }
+
// Convert tabs or multiple spaces into single spaces
- $item = preg_replace('/[\t ]+/', ' ', $item);
+ $item = preg_replace('/\s+/', ' ', $item);
// If the item has an alias declaration we remove it and set it aside.
- // Basically we remove everything to the right of the first space
- if (strpos($item, ' ') !== FALSE)
+ // Note: strripos() is used in order to support spaces in table names
+ if ($offset = strripos($item, ' AS '))
{
- $alias = strstr($item, ' ');
- $item = substr($item, 0, - strlen($alias));
+ $alias = ($protect_identifiers)
+ ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4))
+ : substr($item, $offset);
+ $item = substr($item, 0, $offset);
}
- else
+ elseif ($offset = strrpos($item, ' '))
{
- $alias = '';
+ $alias = ($protect_identifiers)
+ ? ' '.$this->escape_identifiers(substr($item, $offset + 1))
+ : substr($item, $offset);
+ $item = substr($item, 0, $offset);
}
-
- // 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
- // way to deal with this, but I'm not thinking of it -- Rick
- if (strpos($item, '(') !== FALSE)
+ else
{
- return $item.$alias;
+ $alias = '';
}
// Break the string apart if it contains periods, then insert the table prefix
@@ -1302,7 +1485,7 @@ abstract class CI_DB_driver {
}
// Is there a table prefix defined in the config file? If not, no need to do anything
- if ($this->dbprefix != '')
+ if ($this->dbprefix !== '')
{
// We now add the table prefix based on some logic.
// Do we have 4 segments (hostname.database.table.column)?
@@ -1326,13 +1509,13 @@ abstract class CI_DB_driver {
// This flag is set when the supplied $item does not contain a field name.
// This can happen when this function is being called from a JOIN.
- if ($field_exists == FALSE)
+ if ($field_exists === FALSE)
{
$i++;
}
// Verify table prefix and replace if necessary
- if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0)
+ if ($this->swap_pre !== '' && strpos($parts[$i], $this->swap_pre) === 0)
{
$parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
}
@@ -1355,15 +1538,15 @@ abstract class CI_DB_driver {
}
// Is there a table prefix? If not, no need to insert it
- if ($this->dbprefix != '')
+ if ($this->dbprefix !== '')
{
// Verify table prefix and replace if necessary
- if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0)
+ if ($this->swap_pre !== '' && strpos($item, $this->swap_pre) === 0)
{
$item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item);
}
// Do we prefix an item with no segments?
- elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0)
+ elseif ($prefix_single === TRUE && strpos($item, $this->dbprefix) !== 0)
{
$item = $this->dbprefix.$item;
}
@@ -1381,8 +1564,7 @@ abstract class CI_DB_driver {
/**
* Dummy method that allows Query Builder class to be disabled
- *
- * This function is used extensively by every db driver.
+ * and keep count_all() working.
*
* @return void
*/
@@ -1393,4 +1575,4 @@ abstract class CI_DB_driver {
}
/* End of file DB_driver.php */
-/* Location: ./system/database/DB_driver.php */
+/* Location: ./system/database/DB_driver.php */ \ No newline at end of file
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index a519575f0..91f9d560c 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -72,6 +72,11 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ if ( ! empty($this->db->data_cache['db_names']))
+ {
+ $this->db->data_cache['db_names'][] = $db_name;
+ }
+
return TRUE;
}
@@ -85,7 +90,7 @@ abstract class CI_DB_forge {
*/
public function drop_database($db_name)
{
- if ($db_name == '')
+ if ($db_name === '')
{
show_error('A table name is required for that operation.');
return FALSE;
@@ -99,6 +104,15 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ if ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($db_name), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
return TRUE;
}
@@ -123,7 +137,7 @@ abstract class CI_DB_forge {
return;
}
- if ($key == '')
+ if ($key === '')
{
show_error('Key information is required for that operation.');
}
@@ -150,7 +164,7 @@ abstract class CI_DB_forge {
*/
public function add_field($field = '')
{
- if ($field == '')
+ if ($field === '')
{
show_error('Field information is required.');
}
@@ -197,7 +211,7 @@ abstract class CI_DB_forge {
*/
public function create_table($table = '', $if_not_exists = FALSE)
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
@@ -209,7 +223,18 @@ abstract class CI_DB_forge {
$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
$this->_reset();
- return is_bool($sql) ? $sql : $this->db->query($sql);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
+
+ if (($result = $this->db->query($sql)) !== FALSE && ! empty($this->db->data_cache['table_names']))
+ {
+ $this->db->data_cache['table_names'][] = $this->db->dbprefix.$table;
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -222,7 +247,7 @@ abstract class CI_DB_forge {
*/
public function drop_table($table_name)
{
- if ($table_name == '')
+ if ($table_name === '')
{
return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE;
}
@@ -231,7 +256,19 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- return $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+ $result = $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+
+ // Update table list cache
+ if ($result && ! empty($this->db->data_cache['table_names']))
+ {
+ $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['table_names'][$key]);
+ }
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -245,7 +282,7 @@ abstract class CI_DB_forge {
*/
public function rename_table($table_name, $new_table_name)
{
- if ($table_name == '' OR $new_table_name == '')
+ if ($table_name === '' OR $new_table_name === '')
{
show_error('A table name is required for that operation.');
return FALSE;
@@ -255,10 +292,21 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- return $this->db->query(sprintf($this->_rename_table,
+ $result = $this->db->query(sprintf($this->_rename_table,
$this->db->escape_identifiers($this->db->dbprefix.$table_name),
$this->db->escape_identifiers($this->db->dbprefix.$new_table_name))
);
+
+ if ($result && ! empty($this->db->data_cache['table_names']))
+ {
+ $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ $this->db->data_cache['table_names'][$key] = $this->db->dbprefix.$new_table_name;
+ }
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -273,7 +321,7 @@ abstract class CI_DB_forge {
*/
public function add_column($table = '', $field = array(), $after_field = '')
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
@@ -284,7 +332,7 @@ abstract class CI_DB_forge {
{
$this->add_field(array($k => $field[$k]));
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
@@ -312,12 +360,12 @@ abstract class CI_DB_forge {
*/
public function drop_column($table = '', $column_name = '')
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
- if ($column_name == '')
+ if ($column_name === '')
{
show_error('A column name is required for that operation.');
}
@@ -337,7 +385,7 @@ abstract class CI_DB_forge {
*/
public function modify_column($table = '', $field = array())
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index d0af66de1..479b7f24a 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -53,7 +53,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
protected $qb_keys = array();
protected $qb_limit = FALSE;
protected $qb_offset = FALSE;
- protected $qb_order = FALSE;
protected $qb_orderby = array();
protected $qb_set = array();
protected $qb_wherein = array();
@@ -84,6 +83,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* Generates the SELECT portion of the query
*
* @param string
+ * @param mixed
* @return object
*/
public function select($select = '*', $escape = NULL)
@@ -93,11 +93,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$select = explode(',', $select);
}
+ // If the escape value was not set will will base it on the global setting
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
foreach ($select as $val)
{
$val = trim($val);
- if ($val != '')
+ if ($val !== '')
{
$this->qb_select[] = $val;
$this->qb_no_escape[] = $escape;
@@ -194,7 +197,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
{
- if ( ! is_string($select) OR $select == '')
+ if ( ! is_string($select) OR $select === '')
{
$this->display_error('db_invalid_query');
}
@@ -206,13 +209,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
show_error('Invalid function type: '.$type);
}
- if ($alias == '')
+ if ($alias === '')
{
$alias = $this->_create_alias_from_table(trim($select));
}
- $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->protect_identifiers(trim($alias));
-
+ $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->escape_identifiers(trim($alias));
+
$this->qb_select[] = $sql;
$this->qb_no_escape[] = NULL;
@@ -256,7 +259,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function distinct($val = TRUE)
{
- $this->qb_distinct = (is_bool($val)) ? $val : TRUE;
+ $this->qb_distinct = is_bool($val) ? $val : TRUE;
return $this;
}
@@ -272,7 +275,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function from($from)
{
- foreach ((array)$from as $val)
+ foreach ((array) $from as $val)
{
if (strpos($val, ',') !== FALSE)
{
@@ -321,15 +324,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string
* @param string the join condition
* @param string the type of join
+ * @param string whether not to try to escape identifiers
* @return object
*/
- public function join($table, $cond, $type = '')
+ public function join($table, $cond, $type = '', $escape = NULL)
{
- if ($type != '')
+ if ($type !== '')
{
$type = strtoupper(trim($type));
- if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
+ if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE))
{
$type = '';
}
@@ -343,14 +347,51 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// in the protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
- // Strip apart the condition and protect the identifiers
- if (preg_match('/([\[\w\.]+)([\W\s]+)(.+)/', $cond, $match))
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
+ // Split multiple conditions
+ if ($escape === TRUE && preg_match_all('/\sAND\s|\sOR\s/i', $cond, $m, PREG_OFFSET_CAPTURE))
{
- $cond = $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
+ $newcond = '';
+ $m[0][] = array('', strlen($cond));
+
+ for ($i = 0, $c = count($m[0]), $s = 0;
+ $i < $c;
+ $s = $m[0][$i][1] + strlen($m[0][$i][0]), $i++)
+ {
+ $temp = substr($cond, $s, ($m[0][$i][1] - $s));
+
+ $newcond .= preg_match("/([\[\]\w\.'-]+)(\s*[^\"\[`'\w]+\s*)(.+)/i", $temp, $match)
+ ? $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3])
+ : $temp;
+
+ $newcond .= $m[0][$i][0];
+ }
+
+ $cond = ' ON '.$newcond;
+ }
+ // Split apart the condition and protect the identifiers
+ elseif ($escape === TRUE && preg_match("/([\[\]\w\.'-]+)(\s*[^\"\[`'\w]+\s*)(.+)/i", $cond, $match))
+ {
+ $cond = ' ON '.$this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
+ }
+ elseif ( ! $this->_has_operator($cond))
+ {
+ $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')';
+ }
+ else
+ {
+ $cond = ' ON '.$cond;
+ }
+
+ // Do we want to escape the table name?
+ if ($escape === TRUE)
+ {
+ $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// Assemble the JOIN statement
- $this->qb_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->qb_join[] = $join = $type.'JOIN '.$table.$cond;
if ($this->qb_caching === TRUE)
{
@@ -371,9 +412,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param mixed
* @param mixed
+ * @param bool
* @return object
*/
- public function where($key, $value = NULL, $escape = TRUE)
+ public function where($key, $value = NULL, $escape = NULL)
{
return $this->_where($key, $value, 'AND ', $escape);
}
@@ -388,9 +430,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param mixed
* @param mixed
+ * @param bool
* @return object
*/
- public function or_where($key, $value = NULL, $escape = TRUE)
+ public function or_where($key, $value = NULL, $escape = NULL)
{
return $this->_where($key, $value, 'OR ', $escape);
}
@@ -405,26 +448,31 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param mixed
* @param mixed
* @param string
+ * @param mixed
* @return object
*/
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{
- $type = $this->_group_get_type($type);
-
if ( ! is_array($key))
{
$key = array($key => $value);
}
// If the escape value was not set will will base it on the global setting
- if ( ! is_bool($escape))
- {
- $escape = $this->_protect_identifiers;
- }
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
foreach ($key as $k => $v)
{
- $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
+ ? $this->_group_get_type('')
+ : $this->_group_get_type($type);
+
+ if ($escape === TRUE)
+ {
+ $k = (($op = $this->_get_operator($k)) !== FALSE)
+ ? $this->escape_identifiers(trim(substr($k, 0, strpos($k, $op)))).' '.strstr($k, $op)
+ : $this->escape_identifiers(trim($k));
+ }
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -436,7 +484,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
if ($escape === TRUE)
{
- $k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
@@ -445,10 +492,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$k .= ' = ';
}
}
- else
- {
- $k = $this->protect_identifiers($k, FALSE, $escape);
- }
$this->qb_where[] = $prefix.$k.$v;
if ($this->qb_caching === TRUE)
@@ -474,9 +517,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param array The values searched on
* @return object
*/
- public function where_in($key = NULL, $values = NULL)
+ public function where_in($key = NULL, $values = NULL, $escape = NULL)
{
- return $this->_where_in($key, $values);
+ return $this->_where_in($key, $values, FALSE, 'AND ', $escape);
}
// --------------------------------------------------------------------
@@ -491,9 +534,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param array The values searched on
* @return object
*/
- public function or_where_in($key = NULL, $values = NULL)
+ public function or_where_in($key = NULL, $values = NULL, $escape = NULL)
{
- return $this->_where_in($key, $values, FALSE, 'OR ');
+ return $this->_where_in($key, $values, FALSE, 'OR ', $escape);
}
// --------------------------------------------------------------------
@@ -508,9 +551,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param array The values searched on
* @return object
*/
- public function where_not_in($key = NULL, $values = NULL)
+ public function where_not_in($key = NULL, $values = NULL, $escape = NULL)
{
- return $this->_where_in($key, $values, TRUE);
+ return $this->_where_in($key, $values, TRUE, 'AND ', $escape);
}
// --------------------------------------------------------------------
@@ -525,9 +568,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param array The values searched on
* @return object
*/
- public function or_where_not_in($key = NULL, $values = NULL)
+ public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL)
{
- return $this->_where_in($key, $values, TRUE, 'OR ');
+ return $this->_where_in($key, $values, TRUE, 'OR ', $escape);
}
// --------------------------------------------------------------------
@@ -543,20 +586,20 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string
* @return object
*/
- protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
+ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL)
{
if ($key === NULL OR $values === NULL)
{
- return;
+ return $this;
}
- $type = $this->_group_get_type($type);
-
if ( ! is_array($values))
{
$values = array($values);
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
$not = ($not) ? ' NOT' : '';
foreach ($values as $value)
@@ -564,8 +607,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->qb_wherein[] = $this->escape($value);
}
- $prefix = (count($this->qb_where) === 0) ? '' : $type;
- $this->qb_where[] = $where_in = $prefix.$this->protect_identifiers($key).$not.' IN ('.implode(', ', $this->qb_wherein).') ';
+ if ($escape === TRUE)
+ {
+ $key = $this->escape_identifiers(trim($key));
+ }
+
+ $prefix = (count($this->qb_where) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type);
+ $this->qb_where[] = $where_in = $prefix.$key.$not.' IN ('.implode(', ', $this->qb_wherein).') ';
if ($this->qb_caching === TRUE)
{
@@ -660,8 +708,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
- $type = $this->_group_get_type($type);
-
if ( ! is_array($field))
{
$field = array($field => $match);
@@ -670,28 +716,28 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
foreach ($field as $k => $v)
{
$k = $this->protect_identifiers($k);
- $prefix = (count($this->qb_like) === 0) ? '' : $type;
+ $prefix = (count($this->qb_like) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type);
$v = $this->escape_like_str($v);
if ($side === 'none')
{
- $like_statement = $prefix." $k $not LIKE '{$v}'";
+ $like_statement = "{$prefix} $k $not LIKE '{$v}'";
}
elseif ($side === 'before')
{
- $like_statement = $prefix." $k $not LIKE '%{$v}'";
+ $like_statement = "{$prefix} $k $not LIKE '%{$v}'";
}
elseif ($side === 'after')
{
- $like_statement = $prefix." $k $not LIKE '{$v}%'";
+ $like_statement = "{$prefix} $k $not LIKE '{$v}%'";
}
else
{
- $like_statement = $prefix." $k $not LIKE '%{$v}%'";
+ $like_statement = "{$prefix} $k $not LIKE '%{$v}%'";
}
// some platforms require an escape sequence definition for LIKE wildcards
- if ($this->_like_escape_str != '')
+ if ($this->_like_escape_str !== '')
{
$like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
@@ -829,7 +875,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$val = trim($val);
- if ($val != '')
+ if ($val !== '')
{
$this->qb_groupby[] = $val = $this->protect_identifiers($val);
@@ -853,9 +899,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param bool
* @return object
*/
- public function having($key, $value = '', $escape = TRUE)
+ public function having($key, $value = '', $escape = NULL)
{
return $this->_having($key, $value, 'AND ', $escape);
}
@@ -869,9 +916,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param bool
* @return object
*/
- public function or_having($key, $value = '', $escape = TRUE)
+ public function or_having($key, $value = '', $escape = NULL)
{
return $this->_having($key, $value, 'OR ', $escape);
}
@@ -885,30 +933,33 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param string
+ * @param bool
* @return object
*/
- protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
+ protected function _having($key, $value = '', $type = 'AND ', $escape = NULL)
{
if ( ! is_array($key))
{
$key = array($key => $value);
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
foreach ($key as $k => $v)
{
$prefix = (count($this->qb_having) === 0) ? '' : $type;
- if ($escape === TRUE)
- {
- $k = $this->protect_identifiers($k);
- }
+ $k = $this->_has_operator($k)
+ ? $this->protect_identifiers(substr($k, 0, strpos(rtrim($k), ' ')), FALSE, $escape).strchr(rtrim($k), ' ')
+ : $this->protect_identifiers($k, FALSE, $escape);
if ( ! $this->_has_operator($k))
{
$k .= ' = ';
}
- if ($v != '')
+ if ($v !== '')
{
$v = ' '.$this->escape($v);
}
@@ -934,20 +985,21 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param bool enable field name escaping
* @return object
*/
- public function order_by($orderby, $direction = '', $escape = TRUE)
+ public function order_by($orderby, $direction = '', $escape = NULL)
{
if (strtolower($direction) === 'random')
{
$orderby = ''; // Random results want or don't need a field name
$direction = $this->_random_keyword;
}
- elseif (trim($direction) != '')
+ elseif (trim($direction) !== '')
{
- $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
+ $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : ' ASC';
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
- if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
+ if ($escape === TRUE && strpos($orderby, ',') !== FALSE)
{
$temp = array();
foreach (explode(',', $orderby) as $part)
@@ -955,7 +1007,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$part = trim($part);
if ( ! in_array($part, $this->qb_aliased_tables))
{
- $part = $this->protect_identifiers(trim($part));
+ $part = preg_match('/^(.+)\s+(ASC|DESC)$/i', $part, $matches)
+ ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2]
+ : $this->protect_identifiers($part);
}
$temp[] = $part;
@@ -963,12 +1017,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$orderby = implode(', ', $temp);
}
- elseif ($direction != $this->_random_keyword)
+ elseif ($direction !== $this->_random_keyword && $escape === TRUE)
{
- if ($escape === TRUE)
- {
- $orderby = $this->protect_identifiers($orderby);
- }
+ $orderby = preg_match('/^(.+)\s+(ASC|DESC)$/i', $orderby, $matches)
+ ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2]
+ : $this->protect_identifiers($orderby);
}
$this->qb_orderby[] = $orderby_statement = $orderby.$direction;
@@ -993,12 +1046,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function limit($value, $offset = NULL)
{
- $this->qb_limit = (int) $value;
-
- if ( ! is_null($offset))
- {
- $this->qb_offset = (int) $offset;
- }
+ is_null($value) OR $this->qb_limit = (int) $value;
+ empty($offset) OR $this->qb_offset = (int) $offset;
return $this;
}
@@ -1013,21 +1062,40 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function offset($offset)
{
- $this->qb_offset = (int) $offset;
+ empty($offset) OR $this->qb_offset = (int) $offset;
return $this;
}
// --------------------------------------------------------------------
/**
- * The "set" function. Allows key/value pairs to be set for inserting or updating
+ * 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)
+ {
+ return $sql.' LIMIT '.($offset ? $offset.', ' : '').$limit;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * The "set" function.
+ *
+ * Allows key/value pairs to be set for inserting or updating
*
* @param mixed
* @param string
* @param bool
* @return object
*/
- public function set($key, $value = '', $escape = TRUE)
+ public function set($key, $value = '', $escape = NULL)
{
$key = $this->_object_to_array($key);
@@ -1036,16 +1104,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$key = array($key => $value);
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
foreach ($key as $k => $v)
{
- if ($escape === FALSE)
- {
- $this->qb_set[$this->protect_identifiers($k)] = $v;
- }
- else
- {
- $this->qb_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
- }
+ $this->qb_set[$this->protect_identifiers($k, FALSE, $escape)] = ($escape)
+ ? $this->escape($v) : $v;
}
return $this;
@@ -1064,13 +1128,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function get_compiled_select($table = '', $reset = TRUE)
{
- if ($table != '')
+ if ($table !== '')
{
$this->_track_aliases($table);
$this->from($table);
}
- $select = $this->_compile_select();
+ $select = $this->_compile_select();
if ($reset === TRUE)
{
@@ -1093,15 +1157,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string the offset clause
* @return object
*/
- public function get($table = '', $limit = null, $offset = null)
+ public function get($table = '', $limit = NULL, $offset = NULL)
{
- if ($table != '')
+ if ($table !== '')
{
$this->_track_aliases($table);
$this->from($table);
}
- if ( ! is_null($limit))
+ if ( ! empty($limit))
{
$this->limit($limit, $offset);
}
@@ -1111,6 +1175,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return $result;
}
+ // --------------------------------------------------------------------
+
/**
* "Count All Results" query
*
@@ -1122,7 +1188,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function count_all_results($table = '')
{
- if ($table != '')
+ if ($table !== '')
{
$this->_track_aliases($table);
$this->from($table);
@@ -1139,6 +1205,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$row = $result->row();
return (int) $row->numrows;
}
+
// --------------------------------------------------------------------
/**
@@ -1151,9 +1218,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string the offset clause
* @return object
*/
- public function get_where($table = '', $where = null, $limit = null, $offset = null)
+ public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL)
{
- if ($table != '')
+ if ($table !== '')
{
$this->from($table);
}
@@ -1163,7 +1230,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->where($where);
}
- if ( ! is_null($limit))
+ if ( ! empty($limit))
{
$this->limit($limit, $offset);
}
@@ -1201,7 +1268,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return FALSE;
}
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1248,7 +1315,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param bool
* @return object
*/
- public function set_insert_batch($key, $value = '', $escape = TRUE)
+ public function set_insert_batch($key, $value = '', $escape = NULL)
{
$key = $this->_object_to_array_batch($key);
@@ -1257,6 +1324,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$key = array($key => $value);
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
$keys = array_keys($this->_object_to_array(current($key)));
sort($keys);
@@ -1272,11 +1341,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
ksort($row); // puts $row in the same order as our keys
- if ($escape === FALSE)
- {
- $this->qb_set[] = '('.implode(',', $row).')';
- }
- else
+ if ($escape !== FALSE)
{
$clean = array();
foreach ($row as $value)
@@ -1284,13 +1349,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$clean[] = $this->escape($value);
}
- $this->qb_set[] = '('.implode(',', $clean).')';
+ $row = $clean;
}
+
+ $this->qb_set[] = '('.implode(',', $row).')';
}
foreach ($keys as $k)
{
- $this->qb_keys[] = $this->protect_identifiers($k);
+ $this->qb_keys[] = $this->protect_identifiers($k, FALSE, $escape);
}
return $this;
@@ -1368,23 +1435,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * 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).')';
- }
-
- // --------------------------------------------------------------------
-
- /**
* Validate Insert
*
* This method is used by both insert() and get_compiled_insert() to
@@ -1401,16 +1451,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table !== '')
{
- if ( ! isset($this->qb_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
+ $this->qb_from[0] = $table;
}
- else
+ elseif ( ! isset($this->qb_from[0]))
{
- $this->qb_from[0] = $table;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
return TRUE;
@@ -1439,7 +1486,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1475,6 +1522,24 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * 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)
+ {
+ is_array($tables) OR $tables = array($tables);
+
+ return (count($tables) === 1) ? $tables[0] : '('.implode(', ', $tables).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get UPDATE query string
*
* Compiles an update query and returns the sql
@@ -1530,12 +1595,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return FALSE;
}
- if ($where != NULL)
+ if ($where !== NULL)
{
$this->where($where);
}
- if ($limit != NULL)
+ if ( ! empty($limit))
{
$this->limit($limit);
}
@@ -1549,41 +1614,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * 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
- * @param array the like clause
- * @return string
- */
- protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
- {
- foreach ($values as $key => $val)
- {
- $valstr[] = $key.' = '.$val;
- }
-
- $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
-
- if ( ! empty($like))
- {
- $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
- }
-
- return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
- .$where
- .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
- .($limit ? ' LIMIT '.$limit : '');
- }
-
- // --------------------------------------------------------------------
-
- /**
* Validate Update
*
* This method is used by both update() and get_compiled_update() to
@@ -1595,21 +1625,18 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
protected function _validate_update($table = '')
{
- if (count($this->qb_set) == 0)
+ if (count($this->qb_set) === 0)
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table !== '')
{
- if ( ! isset($this->qb_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
+ $this->qb_from[0] = $table;
}
- else
+ elseif ( ! isset($this->qb_from[0]))
{
- $this->qb_from[0] = $table;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
return TRUE;
@@ -1647,7 +1674,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1677,7 +1704,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param bool
* @return object
*/
- public function set_update_batch($key, $index = '', $escape = TRUE)
+ public function set_update_batch($key, $index = '', $escape = NULL)
{
$key = $this->_object_to_array_batch($key);
@@ -1686,25 +1713,23 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// @todo error
}
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
foreach ($key as $k => $v)
{
$index_set = FALSE;
$clean = array();
foreach ($v as $k2 => $v2)
{
- if ($k2 == $index)
+ if ($k2 === $index)
{
$index_set = TRUE;
}
- else
- {
- $not[] = $k.'-'.$v;
- }
- $clean[$this->protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
+ $clean[$this->protect_identifiers($k2, FALSE, $escape)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
- if ($index_set == FALSE)
+ if ($index_set === FALSE)
{
return $this->display_error('db_batch_missing_index');
}
@@ -1727,7 +1752,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function empty_table($table = '')
{
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1760,7 +1785,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function truncate($table = '')
{
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1834,7 +1859,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// Combine any cached components with the current statements
$this->_merge_cache();
- if ($table == '')
+ if ($table === '')
{
if ( ! isset($this->qb_from[0]))
{
@@ -1858,12 +1883,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
}
- if ($where != '')
+ if ($where !== '')
{
$this->where($where);
}
- if ($limit != NULL)
+ if ( ! empty($limit))
{
$this->limit($limit);
}
@@ -1904,7 +1929,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return 'DELETE FROM '.$table
.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '')
- .($limit ? ' LIMIT '.$limit : '');
+ .($limit ? ' LIMIT '.(int) $limit : '');
}
// --------------------------------------------------------------------
@@ -1919,7 +1944,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function dbprefix($table = '')
{
- if ($table == '')
+ if ($table === '')
{
$this->display_error('db_table_name_required');
}
@@ -1974,7 +1999,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
if (strpos($table, ' ') !== FALSE)
{
// if the alias is written with the AS keyword, remove it
- $table = preg_replace('/ AS /i', ' ', $table);
+ $table = preg_replace('/\s+AS\s+/i', ' ', $table);
// Grab the alias
$table = trim(strrchr($table, ' '));
@@ -2077,10 +2102,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
if (count($this->qb_orderby) > 0)
{
$sql .= "\nORDER BY ".implode(', ', $this->qb_orderby);
- if ($this->qb_order !== FALSE)
- {
- $sql .= ($this->qb_order == 'desc') ? ' DESC' : ' ASC';
- }
}
// Write the "LIMIT" portion of the query
@@ -2102,7 +2123,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param object
* @return array
*/
- public function _object_to_array($object)
+ protected function _object_to_array($object)
{
if ( ! is_object($object))
{
@@ -2113,7 +2134,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
foreach (get_object_vars($object) as $key => $val)
{
// There are some built in keys we need to ignore for this conversion
- if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name')
+ if ( ! is_object($val) && ! is_array($val) && $key !== '_parent_name')
{
$array[$key] = $val;
}
@@ -2132,7 +2153,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param object
* @return array
*/
- public function _object_to_array_batch($object)
+ protected function _object_to_array_batch($object)
{
if ( ! is_object($object))
{
@@ -2310,8 +2331,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_no_escape' => array(),
'qb_distinct' => FALSE,
'qb_limit' => FALSE,
- 'qb_offset' => FALSE,
- 'qb_order' => FALSE
+ 'qb_offset' => FALSE
)
);
}
@@ -2334,8 +2354,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_like' => array(),
'qb_orderby' => array(),
'qb_keys' => array(),
- 'qb_limit' => FALSE,
- 'qb_order' => FALSE
+ 'qb_limit' => FALSE
)
);
}
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 196febe2c..d44df6c02 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -38,32 +38,74 @@
*/
class CI_DB_result {
- public $conn_id = NULL;
- public $result_id = NULL;
+ public $conn_id;
+ public $result_id;
public $result_array = array();
public $result_object = array();
public $custom_result_object = array();
public $current_row = 0;
- public $num_rows = 0;
- public $row_data = NULL;
+ public $num_rows;
+ public $row_data;
+ /**
+ * Constructor
+ *
+ * @param object
+ * @return void
+ */
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.
+ * Number of rows in the result set
*
- * @param string can be "object" or "array"
- * @return object
+ * @return int
+ */
+ public function num_rows()
+ {
+ if (is_int($this->num_rows))
+ {
+ return $this->num_rows;
+ }
+ elseif (count($this->result_array) > 0)
+ {
+ return $this->num_rows = count($this->result_array);
+ }
+ elseif (count($this->result_object) > 0)
+ {
+ return $this->num_rows = count($this->result_object);
+ }
+
+ return $this->num_rows = count($this->result_array());
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Query result. Acts as a wrapper function for the following functions.
+ *
+ * @param string 'object', 'array' or a custom class name
+ * @return array
*/
public function result($type = 'object')
{
- if ($type === 'array') return $this->result_array();
- elseif ($type === 'object') return $this->result_object();
- else return $this->custom_result_object($type);
+ if ($type === 'array')
+ {
+ return $this->result_array();
+ }
+ elseif ($type === 'object')
+ {
+ return $this->result_object();
+ }
+ else
+ {
+ return $this->custom_result_object($type);
+ }
}
// --------------------------------------------------------------------
@@ -76,33 +118,50 @@ class CI_DB_result {
*/
public function custom_result_object($class_name)
{
- if (array_key_exists($class_name, $this->custom_result_object))
+ if (isset($this->custom_result_object[$class_name]))
{
return $this->custom_result_object[$class_name];
}
-
- if ($this->result_id === FALSE OR $this->num_rows() == 0)
+ elseif ( ! $this->result_id OR $this->num_rows === 0)
{
return array();
}
- // add the data to the object
- $this->_data_seek(0);
- $result_object = array();
+ // Don't fetch the result set again if we already have it
+ $_data = NULL;
+ if (($c = count($this->result_array)) > 0)
+ {
+ $_data = 'result_array';
+ }
+ elseif (($c = count($this->result_object)) > 0)
+ {
+ $_data = 'result_object';
+ }
- while ($row = $this->_fetch_object())
+ if ($_data !== NULL)
{
- $object = new $class_name();
- foreach ($row as $key => $value)
+ for ($i = 0; $i < $c; $i++)
{
- $object->$key = $value;
+ $this->custom_result_object[$class_name][$i] = new $class_name();
+
+ foreach ($this->{$_data}[$i] as $key => $value)
+ {
+ $this->custom_result_object[$class_name][$i]->$key = $value;
+ }
}
- $result_object[] = $object;
+ return $this->custom_result_object[$class_name];
+ }
+
+ $this->_data_seek(0);
+ $this->custom_result_object[$class_name] = array();
+
+ while ($row = $this->_fetch_object($class_name))
+ {
+ $this->custom_result_object[$class_name][] = $row;
}
- // return the array
- return $this->custom_result_object[$class_name] = $result_object;
+ return $this->custom_result_object[$class_name];
}
// --------------------------------------------------------------------
@@ -119,14 +178,24 @@ class CI_DB_result {
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 OR $this->num_rows() == 0)
+ // In the event that query caching is on, the result_id variable
+ // will not be a valid resource so we'll simply return an empty
+ // array.
+ if ( ! $this->result_id OR $this->num_rows === 0)
{
return array();
}
+ 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;
+ }
+
$this->_data_seek(0);
while ($row = $this->_fetch_object())
{
@@ -139,7 +208,7 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * Query result. "array" version.
+ * Query result. "array" version.
*
* @return array
*/
@@ -150,14 +219,24 @@ class CI_DB_result {
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 OR $this->num_rows() == 0)
+ // In the event that query caching is on, the result_id variable
+ // will not be a valid resource so we'll simply return an empty
+ // array.
+ if ( ! $this->result_id OR $this->num_rows === 0)
{
return array();
}
+ 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;
+ }
+
$this->_data_seek(0);
while ($row = $this->_fetch_assoc())
{
@@ -224,7 +303,7 @@ class CI_DB_result {
return;
}
- if ($key != '' && ! is_null($value))
+ if ($key !== '' && ! is_null($value))
{
$this->row_data[$key] = $value;
}
@@ -239,20 +318,23 @@ class CI_DB_result {
*/
public function custom_row_object($n, $type)
{
- $result = $this->custom_result_object($type);
- if (count($result) === 0)
+ isset($this->custom_result_object[$type]) OR $this->custom_result_object($type);
+
+ if (count($this->custom_result_object[$type]) === 0)
{
- return $result;
+ return NULL;
}
- if ($n != $this->current_row && isset($result[$n]))
+ if ($n !== $this->current_row && isset($this->custom_result_object[$type][$n]))
{
$this->current_row = $n;
}
- return $result[$this->current_row];
+ return $this->custom_result_object[$type][$this->current_row];
}
+ // --------------------------------------------------------------------
+
/**
* Returns a single result row - object version
*
@@ -263,10 +345,10 @@ class CI_DB_result {
$result = $this->result_object();
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
- if ($n != $this->current_row && isset($result[$n]))
+ if ($n !== $this->current_row && isset($result[$n]))
{
$this->current_row = $n;
}
@@ -286,10 +368,10 @@ class CI_DB_result {
$result = $this->result_array();
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
- if ($n != $this->current_row && isset($result[$n]))
+ if ($n !== $this->current_row && isset($result[$n]))
{
$this->current_row = $n;
}
@@ -307,7 +389,7 @@ class CI_DB_result {
public function first_row($type = 'object')
{
$result = $this->result($type);
- return (count($result) === 0) ? $result : $result[0];
+ return (count($result) === 0) ? NULL : $result[0];
}
// --------------------------------------------------------------------
@@ -320,7 +402,7 @@ class CI_DB_result {
public function last_row($type = 'object')
{
$result = $this->result($type);
- return (count($result) === 0) ? $result : $result[count($result) - 1];
+ return (count($result) === 0) ? NULL : $result[count($result) - 1];
}
// --------------------------------------------------------------------
@@ -335,7 +417,7 @@ class CI_DB_result {
$result = $this->result($type);
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if (isset($result[$this->current_row + 1]))
@@ -358,7 +440,7 @@ class CI_DB_result {
$result = $this->result($type);
if (count($result) === 0)
{
- return $result;
+ return NULL;
}
if (isset($result[$this->current_row - 1]))
@@ -371,6 +453,28 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
+ * Returns an unbuffered row and move pointer to next row
+ *
+ * @param string 'array', 'object' or a custom class name
+ * @return mixed either a result object or array
+ */
+ public function unbuffered_row($type = 'object')
+ {
+ if ($type === 'array')
+ {
+ return $this->_fetch_assoc();
+ }
+ elseif ($type === 'object')
+ {
+ return $this->_fetch_object();
+ }
+
+ return $this->_fetch_object($type);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* The following functions are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
* is used. When caching is enabled we do not load the other driver.
@@ -379,7 +483,6 @@ class CI_DB_result {
* operational due to the unavailability of the database resource IDs with
* cached results.
*/
- public function num_rows() { return $this->num_rows; }
public function num_fields() { return 0; }
public function list_fields() { return array(); }
public function field_data() { return array(); }
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 587dfdc01..6a3b40779 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -35,7 +35,6 @@
abstract class CI_DB_utility extends CI_DB_forge {
public $db;
- public $data_cache = array();
// Platform specific SQL strings
// Just setting those defaults to FALSE as they are mostly MySQL-specific
@@ -60,29 +59,29 @@ abstract class CI_DB_utility extends CI_DB_forge {
public function list_databases()
{
// Is there a cached result?
- if (isset($this->data_cache['db_names']))
+ if (isset($this->db->data_cache['db_names']))
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
elseif ($this->_list_databases === FALSE)
{
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- $this->data_cache['db_names'] = array();
+ $this->db->data_cache['db_names'] = array();
$query = $this->db->query($this->_list_databases);
if ($query === FALSE)
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
for ($i = 0, $c = count($query); $i < $c; $i++)
{
- $this->data_cache['db_names'] = current($query[$i]);
+ $this->db->data_cache['db_names'] = current($query[$i]);
}
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
// --------------------------------------------------------------------
@@ -212,7 +211,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
$out = rtrim($out).$newline;
// Next blast through the result array and build out the rows
- foreach ($query->result_array() as $row)
+ while ($row = $query->unbuffered_row('array'))
{
foreach ($row as $item)
{
@@ -258,7 +257,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
// Generate the result
$xml = '<'.$root.'>'.$newline;
- foreach ($query->result_array() as $row)
+ while ($row = $query->unbuffered_row())
{
$xml .= $tab.'<'.$element.'>'.$newline;
foreach ($row as $key => $val)
@@ -343,7 +342,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
if ($prefs['format'] === 'zip')
{
// Set the filename if not provided (only needed with Zip files)
- if ($prefs['filename'] == '')
+ if ($prefs['filename'] === '')
{
$prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
.date('Y-m-d_H-i', time()).'.sql';
@@ -369,7 +368,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
return $CI->zip->get_zip();
}
- elseif ($prefs['format'] == 'txt') // Was a text file requested?
+ elseif ($prefs['format'] === 'txt') // Was a text file requested?
{
return $this->_backup($prefs);
}
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 1373faa88..28724e0e8 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -45,16 +45,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// The character used for escaping - no need in CUBRID
protected $_escape_char = '`';
- // clause and character used for LIKE escape sequences - not used in CUBRID
- 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.
- */
- protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
// CUBRID-specific properties
@@ -74,10 +64,12 @@ class CI_DB_cubrid_driver extends CI_DB {
else
{
// If no port is defined by the user, use the default value
- $this->port == '' OR $this->port = 33000;
+ empty($this->port) OR $this->port = 33000;
}
}
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -329,35 +321,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified table
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -369,7 +332,7 @@ class CI_DB_cubrid_driver extends CI_DB {
{
$sql = 'SHOW TABLES';
- if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
@@ -425,27 +388,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * From Tables
- *
- * This 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);
- }
-
- return '('.implode(', ', $tables).')';
- }
-
- // --------------------------------------------------------------------
-
- /**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
@@ -464,7 +406,7 @@ class CI_DB_cubrid_driver extends CI_DB {
foreach (array_keys($val) as $field)
{
- if ($field != $index)
+ if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
@@ -480,41 +422,23 @@ class CI_DB_cubrid_driver extends CI_DB {
}
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
- .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
.$index.' IN ('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
-
- /**
- * 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)
- {
- return $sql.'LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
- }
-
- // --------------------------------------------------------------------
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @cubrid_close($conn_id);
+ @cubrid_close($this->conn_id);
}
}
/* End of file cubrid_driver.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 4e66f81e3..d328aa241 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -60,8 +60,10 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field)
- .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
+
+ $sql .= "\n\t".$this->db->escape_identifiers($field);
+
+ empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
if ( ! empty($attributes['TYPE']))
{
@@ -69,7 +71,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
if ( ! empty($attributes['CONSTRAINT']))
{
- switch ($attributes['TYPE'])
+ switch (strtolower($attributes['TYPE']))
{
case 'decimal':
case 'float':
@@ -98,10 +100,23 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
*/
- $sql .= (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' : '')
- .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' AUTO_INCREMENT';
+ }
+
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $sql .= ' UNIQUE';
+ }
}
// don't add a comma on the end of the last field
@@ -142,8 +157,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
// If there is a PK defined
if (count($primary_keys) > 0)
{
- $key_name = $this->db->protect_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
- $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $key_name = $this->db->escape_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
+ $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -152,12 +167,12 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->protect_identifiers('idx_'.$table.implode('_', $key));
- $key = $this->db->protect_identifiers($key);
+ $key_name = $this->db->escape_identifiers('idx_'.$table.implode('_', $key));
+ $key = $this->db->escape_identifiers($key);
}
else
{
- $key_name = $this->db->protect_identifiers('idx_'.$table.$key);
+ $key_name = $this->db->escape_identifiers('idx_'.$table.$key);
$key = array($key_name);
}
@@ -184,16 +199,16 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
protected function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
+ $sql = 'ALTER TABLE '.$this->db->escape_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->escape_identifiers($fields);
}
return $sql.$this->_process_fields($fields)
- .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 3eb9f7e3d..4a06a2d39 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author Esen Sagynov
* @link http://codeigniter.com/user_guide/database/
+ * @since 2.1
*/
class CI_DB_cubrid_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*/
public function num_rows()
{
- return @cubrid_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = @cubrid_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -157,11 +160,12 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return cubrid_fetch_object($this->result_id);
+ return cubrid_fetch_object($this->result_id, $class_name);
}
}
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index c8cee99b6..ea8feb4e2 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -41,12 +41,12 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*/
public function list_databases()
{
- if (isset($this->data_cache['db_names']))
+ if (isset($this->db->data_cache['db_names']))
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
- return $this->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
+ return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/ibase/ibase_driver.php
index 1b18de803..f7811bf46 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/ibase/ibase_driver.php
@@ -38,24 +38,14 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_interbase_driver extends CI_DB {
+class CI_DB_ibase_driver extends CI_DB {
- public $dbdriver = 'interbase';
+ public $dbdriver = 'ibase';
// 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
+ protected $_random_keyword = ' Random()'; // database specific random keyword
// Keeps track of the resource for the current transaction
protected $trans;
@@ -235,7 +225,7 @@ class CI_DB_interbase_driver extends CI_DB {
* @param int $inc_by
* @return int
*/
- public function insert_id($generator_name, $inc_by=0)
+ 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);
@@ -244,35 +234,6 @@ class CI_DB_interbase_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -284,9 +245,10 @@ class CI_DB_interbase_driver extends CI_DB {
{
$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 != '')
+ 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.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
@@ -304,7 +266,7 @@ class CI_DB_interbase_driver extends CI_DB {
*/
protected function _list_columns($table = '')
{
- return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = \''.$this->escape_str($table)."'";
+ return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
}
// --------------------------------------------------------------------
@@ -319,10 +281,7 @@ class CI_DB_interbase_driver extends CI_DB {
*/
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;
+ return $this->_limit('SELECT * FROM '.$this->protect_identifiers($table), 1, NULL);
}
// --------------------------------------------------------------------
@@ -353,13 +312,7 @@ class CI_DB_interbase_driver extends CI_DB {
*/
protected function _from_tables($tables)
{
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- //Interbase/Firebird doesn't like grouped tables
- return implode(', ', $tables);
+ return is_array($tables) ? implode(', ', $tables) : $tables;
}
// --------------------------------------------------------------------
@@ -396,7 +349,6 @@ class CI_DB_interbase_driver extends CI_DB {
.(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '');
}
-
// --------------------------------------------------------------------
/**
@@ -456,12 +408,12 @@ class CI_DB_interbase_driver extends CI_DB {
if (stripos($this->version(), 'firebird') !== FALSE)
{
$select = 'FIRST '. (int) $limit
- .($offset > 0 ? ' SKIP '. (int) $offset : '');
+ .($offset ? ' SKIP '. (int) $offset : '');
}
else
{
$select = 'ROWS '
- .($offset > 0 ? (int) $offset.' TO '.($limit + $offset) : (int) $limit);
+ .($offset ? (int) $offset.' TO '.($limit + $offset) : (int) $limit);
}
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
@@ -472,15 +424,14 @@ class CI_DB_interbase_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @ibase_close($conn_id);
+ @ibase_close($this->conn_id);
}
}
-/* End of file interbase_driver.php */
-/* Location: ./system/database/drivers/interbase/interbase_driver.php */ \ No newline at end of file
+/* End of file ibase_driver.php */
+/* Location: ./system/database/drivers/ibase/ibase_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/ibase/ibase_forge.php
index c850656a8..da75eb9c3 100644
--- a/system/database/drivers/interbase/interbase_forge.php
+++ b/system/database/drivers/ibase/ibase_forge.php
@@ -32,7 +32,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_interbase_forge extends CI_DB_forge {
+class CI_DB_ibase_forge extends CI_DB_forge {
protected $_drop_table = 'DROP TABLE %s';
@@ -67,6 +67,14 @@ class CI_DB_interbase_forge extends CI_DB_forge {
{
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
@@ -87,7 +95,7 @@ class CI_DB_interbase_forge extends CI_DB_forge {
{
$sql = 'CREATE TABLE ';
- $sql .= $this->db->protect_identifiers($table)."(";
+ $sql .= $this->db->escape_identifiers($table).'(';
$current_field_count = 0;
foreach ($fields as $field => $attributes)
@@ -97,41 +105,30 @@ class CI_DB_interbase_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
+ empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -146,30 +143,23 @@ class CI_DB_interbase_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->escape_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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
- $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -191,34 +181,14 @@ class CI_DB_interbase_forge extends CI_DB_forge {
*/
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;
-
+ return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
+ .' '.$column_definition
+ .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
-/* End of file interbase_forge.php */
-/* Location: ./system/database/drivers/interbase/interbase_forge.php */ \ No newline at end of file
+/* End of file ibase_forge.php */
+/* Location: ./system/database/drivers/ibase/ibase_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/ibase/ibase_result.php
index 5ddb6fa47..95e55710b 100644
--- a/system/database/drivers/interbase/interbase_result.php
+++ b/system/database/drivers/ibase/ibase_result.php
@@ -21,7 +21,7 @@
* @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
+ * @since Version 1.0
* @filesource
*/
@@ -33,30 +33,9 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 3.0
*/
-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;
- }
-
- // --------------------------------------------------------------------
+class CI_DB_ibase_result extends CI_DB_result {
/**
* Number of fields in the result set
@@ -139,13 +118,7 @@ class CI_DB_interbase_result extends CI_DB_result {
*/
protected function _fetch_assoc()
{
- if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
- {
- //Increment row count
- $this->num_rows++;
- }
-
- return $row;
+ return @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
}
// --------------------------------------------------------------------
@@ -155,106 +128,28 @@ class CI_DB_interbase_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @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()
+ protected function _fetch_object($class_name = 'stdClass')
{
- 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;
- }
+ $row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
- // 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)
+ if ($class_name === 'stdClass' OR ! $row)
{
- return array();
+ return $row;
}
- $this->num_rows = 0;
- while ($row = $this->_fetch_assoc())
+ $class_name = new $class_name();
+ foreach ($row as $key => $value)
{
- $this->result_array[] = $row;
+ $class_name->$key = $value;
}
- return $this->result_array;
+ return $class_name;
}
}
-/* End of file interbase_result.php */
-/* Location: ./system/database/drivers/interbase/interbase_result.php */ \ No newline at end of file
+/* End of file ibase_result.php */
+/* Location: ./system/database/drivers/ibase/ibase_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/ibase/ibase_utility.php
index 164211836..d0e84a7b2 100644
--- a/system/database/drivers/interbase/interbase_utility.php
+++ b/system/database/drivers/ibase/ibase_utility.php
@@ -32,7 +32,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-class CI_DB_interbase_utility extends CI_DB_utility {
+class CI_DB_ibase_utility extends CI_DB_utility {
protected $_list_databases = FALSE;
@@ -58,5 +58,5 @@ class CI_DB_interbase_utility extends CI_DB_utility {
}
-/* End of file interbase_utility.php */
-/* Location: ./system/database/drivers/interbase/interbase_utility.php */ \ No newline at end of file
+/* End of file ibase_utility.php */
+/* Location: ./system/database/drivers/ibase/ibase_utility.php */ \ No newline at end of file
diff --git a/system/database/drivers/interbase/index.html b/system/database/drivers/ibase/index.html
index c942a79ce..c942a79ce 100644
--- a/system/database/drivers/interbase/index.html
+++ b/system/database/drivers/ibase/index.html
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index f60ec8168..b4a1af7ba 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -43,33 +43,57 @@ class CI_DB_mssql_driver extends CI_DB {
public $dbdriver = 'mssql';
// The character used for escaping
- protected $_escape_char = '';
+ protected $_escape_char = '"';
- // clause and character used for LIKE escape sequences
- protected $_like_escape_str = " ESCAPE '%s' ";
- protected $_like_escape_chr = '!';
+ protected $_random_keyword = ' NEWID()';
- /**
- * 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() methods.
+ // MSSQL-specific properties
+ protected $_quoted_identifier = TRUE;
+
+ /*
+ * Constructor
+ *
+ * Appends the port number to the hostname, if needed.
+ *
+ * @param array
+ * @return void
*/
- protected $_count_string = 'SELECT COUNT(*) AS ';
- protected $_random_keyword = ' NEWID()';
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if ( ! empty($this->port))
+ {
+ $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
+ }
+ }
+
+ // --------------------------------------------------------------------
/**
* Non-persistent database connection
*
+ * @param bool
* @return resource
*/
- public function db_connect()
+ public function db_connect($persistent = FALSE)
{
- if ($this->port != '')
+ $this->conn_id = ($persistent)
+ ? @mssql_pconnect($this->hostname, $this->username, $this->password)
+ : @mssql_connect($this->hostname, $this->username, $this->password);
+
+ if ( ! $this->conn_id)
{
- $this->hostname .= ','.$this->port;
+ return FALSE;
}
- return @mssql_connect($this->hostname, $this->username, $this->password);
+ // Determine how identifiers are escaped
+ $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
+ $query = $query->row_array();
+ $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
+ $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
+
+ return $this->conn_id;
}
// --------------------------------------------------------------------
@@ -81,12 +105,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function db_pconnect()
{
- if ($this->port != '')
- {
- $this->hostname .= ','.$this->port;
- }
-
- return @mssql_pconnect($this->hostname, $this->username, $this->password);
+ return $this->db_connect(TRUE);
}
// --------------------------------------------------------------------
@@ -106,7 +125,7 @@ class CI_DB_mssql_driver extends CI_DB {
// Note: The brackets are required in the event that the DB name
// contains reserved characters
- if (@mssql_select_db('['.$database.']', $this->conn_id))
+ if (@mssql_select_db($this->escape_identifiers($database), $this->conn_id))
{
$this->database = $database;
return TRUE;
@@ -121,7 +140,7 @@ class CI_DB_mssql_driver extends CI_DB {
* Execute the query
*
* @param string an SQL query
- * @return resource
+ * @return mixed resource if rows are returned, bool otherwise
*/
protected function _execute($sql)
{
@@ -137,13 +156,8 @@ class CI_DB_mssql_driver extends CI_DB {
*/
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;
}
@@ -151,10 +165,9 @@ class CI_DB_mssql_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('BEGIN TRAN');
- return TRUE;
+ return $this->simple_query('BEGIN TRAN');
}
// --------------------------------------------------------------------
@@ -166,19 +179,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
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;
}
- $this->simple_query('COMMIT TRAN');
- return TRUE;
+ return $this->simple_query('COMMIT TRAN');
}
// --------------------------------------------------------------------
@@ -190,19 +197,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
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;
}
- $this->simple_query('ROLLBACK TRAN');
- return TRUE;
+ return $this->simple_query('ROLLBACK TRAN');
}
// --------------------------------------------------------------------
@@ -232,7 +233,7 @@ class CI_DB_mssql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(
+ 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
@@ -265,28 +266,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
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");
- $query = $this->query($sql);
- $row = $query->row();
- return $row->last_id;
- }
+ $query = version_compare($this->version(), '8', '>=')
+ ? 'SELECT SCOPE_IDENTITY() AS last_id'
+ : 'SELECT @@IDENTITY AS last_id';
- // --------------------------------------------------------------------
-
- /**
- * 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.
+ $query = $this->query($query);
+ $query = $query->row();
+ return $query->last_id;
}
// --------------------------------------------------------------------
@@ -304,35 +290,6 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -342,16 +299,17 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
+ $sql = 'SELECT '.$this->escape_identifiers('name')
+ .' FROM '.$this->escape_identifiers('sysobjects')
+ .' WHERE '.$this->escape_identifiers('type')." = 'U'";
- // for future compatibility
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ 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
+ $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
- return $sql;
+ return $sql.' ORDER BY '.$this->escape_identifiers('name');
}
// --------------------------------------------------------------------
@@ -381,7 +339,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return "SELECT TOP 1 * FROM ".$table;
+ return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -414,12 +372,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _from_tables($tables)
{
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return implode(', ', $tables);
+ return is_array($tables) ? implode(', ', $tables) : $tables;
}
// --------------------------------------------------------------------
@@ -513,9 +466,30 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- $i = $limit + $offset;
+ // As of SQL Server 2012 (11.0.*) OFFSET is supported
+ if (version_compare($this->version(), '11', '>='))
+ {
+ return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
+ }
+
+ $limit = $offset + $limit;
+
+ // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
+ // however an ORDER BY clause is required for it to work
+ if (version_compare($this->version(), '9', '>=') && $offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
// --------------------------------------------------------------------
@@ -523,15 +497,14 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @mssql_close($conn_id);
+ @mssql_close($this->conn_id);
}
}
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 8f8e7c5b9..3a3528f7b 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -48,16 +48,13 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*/
protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
- $sql = 'CREATE TABLE ';
+ $sql = ($if_not_exists === TRUE)
+ ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
+ : '';
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
+ $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
- $sql .= $this->db->escape_identifiers($table).' (';
$current_field_count = 0;
-
foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
@@ -65,41 +62,33 @@ class CI_DB_mssql_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- if (array_key_exists('CONSTRAINT', $attributes))
+ if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -114,30 +103,22 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -159,37 +140,18 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*/
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 = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index 4cc87f4cf..aeede3f4b 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -26,13 +26,14 @@
*/
/**
- * MS SQL Result Class
+ * MSSQL 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/
+ * @since 1.3
*/
class CI_DB_mssql_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*/
public function num_rows()
{
- return @mssql_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = @mssql_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -92,12 +95,12 @@ class CI_DB_mssql_result extends CI_DB_result {
$retval = array();
while ($field = mssql_fetch_field($this->result_id))
{
- $F = new stdClass();
- $F->name = $field->name;
- $F->type = $field->type;
+ $F = new stdClass();
+ $F->name = $field->name;
+ $F->type = $field->type;
$F->max_length = $field->max_length;
$F->primary_key = 0;
- $F->default = '';
+ $F->default = '';
$retval[] = $F;
}
@@ -158,11 +161,25 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return mssql_fetch_object($this->result_id);
+ $row = @mssql_fetch_object($this->result_id);
+
+ if ($class_name === 'stdClass' OR ! $row)
+ {
+ return $row;
+ }
+
+ $class_name = new $class_name();
+ foreach ($row as $key => $value)
+ {
+ $class_name->$key = $value;
+ }
+
+ return $class_name;
}
}
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 6d47618ce..69fcec5f6 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -41,7 +41,7 @@ class CI_DB_mssql_utility extends CI_DB_utility {
* MSSQL Export
*
* @param array Preferences
- * @return mixed
+ * @return bool
*/
protected function _backup($params = array())
{
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 32c51865d..6b4d84dfb 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -45,16 +45,6 @@ class CI_DB_mysql_driver extends CI_DB {
// The character used for escaping
protected $_escape_char = '`';
- // clause and character used for LIKE escape sequences - not used in MySQL
- 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.
- */
- protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
@@ -64,16 +54,24 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public $delete_hack = TRUE;
+ /**
+ * Constructor
+ *
+ * @param array
+ * @return void
+ */
public function __construct($params)
{
parent::__construct($params);
- if ($this->port != '')
+ if ( ! empty($this->port))
{
$this->hostname .= ':'.$this->port;
}
}
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -81,7 +79,14 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function db_connect()
{
- return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
+ if ($this->compress === TRUE)
+ {
+ return @mysql_connect($this->hostname, $this->username, $this->password, TRUE, MYSQL_CLIENT_COMPRESS);
+ }
+ else
+ {
+ return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
+ }
}
// --------------------------------------------------------------------
@@ -93,7 +98,14 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @mysql_pconnect($this->hostname, $this->username, $this->password);
+ if ($this->compress === TRUE)
+ {
+ return @mysql_pconnect($this->hostname, $this->username, $this->password, MYSQL_CLIENT_COMPRESS);
+ }
+ else
+ {
+ return @mysql_pconnect($this->hostname, $this->username, $this->password);
+ }
}
// --------------------------------------------------------------------
@@ -291,7 +303,9 @@ class CI_DB_mysql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -324,35 +338,6 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -362,9 +347,9 @@ class CI_DB_mysql_driver extends CI_DB {
*/
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_identifiers($this->database);
- if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
@@ -382,7 +367,7 @@ class CI_DB_mysql_driver extends CI_DB {
* @param string the table name
* @return string
*/
- public function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
@@ -397,7 +382,7 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function field_data($table = '')
{
- if ($table == '')
+ if ($table === '')
{
return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
}
@@ -439,27 +424,6 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * From Tables
- *
- * This function implicitly groups FROM tables so there is no confusion
- * about operator precedence in harmony with SQL standards
- *
- * @param string table name
- * @return string
- */
- protected function _from_tables($tables)
- {
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return '('.implode(', ', $tables).')';
- }
-
- // --------------------------------------------------------------------
-
- /**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
@@ -478,7 +442,7 @@ class CI_DB_mysql_driver extends CI_DB {
foreach (array_keys($val) as $field)
{
- if ($field != $index)
+ if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
@@ -494,41 +458,23 @@ class CI_DB_mysql_driver extends CI_DB {
}
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
- .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
.$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
/**
- * 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)
- {
- return $sql.' LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @mysql_close($conn_id);
+ @mysql_close($this->conn_id);
}
}
/* End of file mysql_driver.php */
-/* Location: ./system/database/drivers/mysql/mysql_driver.php */
+/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 0e39affa7..2ac75bad2 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -60,8 +60,9 @@ class CI_DB_mysql_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field)
- .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
+ $sql .= "\n\t".$this->db->escape_identifiers($field);
+
+ empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
if ( ! empty($attributes['TYPE']))
{
@@ -86,10 +87,23 @@ class CI_DB_mysql_forge extends CI_DB_forge {
}
}
- $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' : '');
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
+ {
+ $sql .= ' UNSIGNED';
+ }
+
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' AUTO_INCREMENT';
+ }
}
// don't add a comma on the end of the last field
@@ -123,12 +137,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->protect_identifiers($table).' ('.$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));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -137,12 +151,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->escape_identifiers(implode('_', $key));
+ $key = $this->db->escape_identifiers($key);
}
else
{
- $key_name = $this->db->protect_identifiers($key);
+ $key_name = $this->db->escape_identifiers($key);
$key = array($key_name);
}
@@ -169,16 +183,16 @@ class CI_DB_mysql_forge extends CI_DB_forge {
*/
protected function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
+ $sql = 'ALTER TABLE '.$this->db->escape_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->escape_identifiers($fields);
}
return $sql.$this->_process_fields($fields)
- .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index 14d6d072a..7fbb65496 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -33,17 +33,35 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.0
*/
class CI_DB_mysql_result extends CI_DB_result {
/**
+ * Constructor
+ *
+ * @param object
+ * @return void
+ */
+ public function __construct(&$driver_object)
+ {
+ parent::__construct($driver_object);
+
+ // Required, due to mysql_data_seek() causing nightmares
+ // with empty result sets
+ $this->num_rows = @mysql_num_rows($this->result_id);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Number of rows in the result set
*
* @return int
*/
public function num_rows()
{
- return @mysql_num_rows($this->result_id);
+ return $this->num_rows;
}
// --------------------------------------------------------------------
@@ -132,7 +150,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*/
protected function _data_seek($n = 0)
{
- return mysql_data_seek($this->result_id, $n);
+ return $this->num_rows
+ ? @mysql_data_seek($this->result_id, $n)
+ : FALSE;
}
// --------------------------------------------------------------------
@@ -156,11 +176,12 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return mysql_fetch_object($this->result_id);
+ return mysql_fetch_object($this->result_id, $class_name);
}
}
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 642323dbd..f0bbc665e 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -65,7 +65,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Get the table schema
- $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table));
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
// No result means the table name was invalid
if ($query === FALSE)
@@ -76,7 +76,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Write out the table schema
$output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
- if ($add_drop == TRUE)
+ if ($add_drop === TRUE)
{
$output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
}
@@ -92,7 +92,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// If inserts are not needed we're done...
- if ($add_insert == FALSE)
+ if ($add_insert === FALSE)
{
continue;
}
@@ -100,7 +100,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Grab all the data from the current table
$query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
- if ($query->num_rows() == 0)
+ if ($query->num_rows() === 0)
{
continue;
}
@@ -120,7 +120,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
TRUE);
// Create a string of field names
- $field_str .= $this->db->protect_identifiers($field->name).', ';
+ $field_str .= $this->db->escape_identifiers($field->name).', ';
$i++;
}
@@ -143,7 +143,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
else
{
// Escape the data if it's not an integer
- $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v;
+ $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
}
// Append a comma
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index e2684e4f2..14949ecda 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -45,16 +45,6 @@ class CI_DB_mysqli_driver extends CI_DB {
// The character used for escaping
protected $_escape_char = '`';
- // clause and character used for LIKE escape sequences - not used in MySQL
- 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.
- */
- protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
@@ -71,9 +61,20 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function db_connect()
{
- return ($this->port != '')
- ? @new mysqli($this->hostname, $this->username, $this->password, $this->database, $this->port)
- : @new mysqli($this->hostname, $this->username, $this->password, $this->database);
+ // Use MySQL client compression?
+ if ($this->compress === TRUE)
+ {
+ $port = empty($this->port) ? NULL : $this->port;
+
+ $mysqli = new mysqli();
+ @$mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS);
+
+ return $mysqli;
+ }
+
+ return empty($this->port)
+ ? @new mysqli($this->hostname, $this->username, $this->password, $this->database)
+ : @new mysqli($this->hostname, $this->username, $this->password, $this->database, $this->port);
}
// --------------------------------------------------------------------
@@ -91,9 +92,20 @@ class CI_DB_mysqli_driver extends CI_DB {
return $this->db_connect();
}
- return ($this->port != '')
- ? @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port)
- : @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database);
+ // Use MySQL client compression?
+ if ($this->compress === TRUE)
+ {
+ $port = empty($this->port) ? NULL : $this->port;
+
+ $mysqli = mysqli_init();
+ $mysqli->real_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS);
+
+ return $mysqli;
+ }
+
+ return empty($this->port)
+ ? @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database)
+ : @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port);
}
// --------------------------------------------------------------------
@@ -291,7 +303,9 @@ class CI_DB_mysqli_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
@@ -324,35 +338,6 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -362,9 +347,9 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
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_identifiers($this->database);
- if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
@@ -397,7 +382,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function field_data($table = '')
{
- if ($table == '')
+ if ($table === '')
{
return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
}
@@ -433,28 +418,15 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function error()
{
- return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * From Tables
- *
- * This function implicitly groups FROM tables so there is no confusion
- * about operator precedence in harmony with SQL standards
- *
- * @param string
- * @return string
- */
- protected function _from_tables($tables)
- {
- if ( ! is_array($tables))
+ if ( ! empty($this->conn_id->connect_errno))
{
- $tables = array($tables);
+ return array(
+ 'code' => $this->conn_id->connect_errno,
+ 'message' => is_php('5.2.9') ? $this->conn_id->connect_error : mysqli_connect_error()
+ );
}
- return '('.implode(', ', $tables).')';
+ return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
}
// --------------------------------------------------------------------
@@ -478,7 +450,7 @@ class CI_DB_mysqli_driver extends CI_DB {
foreach (array_keys($val) as $field)
{
- if ($field != $index)
+ if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
@@ -493,46 +465,26 @@ class CI_DB_mysqli_driver extends CI_DB {
.'ELSE '.$k.' END, ';
}
- $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
+ $where = ($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
- .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
.$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
/**
- * 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)
- {
- return $sql.' LIMIT '.$limit
- .($offset > 0 ? ' OFFSET '.$offset : '');
- }
-
- // --------------------------------------------------------------------
-
- /**
* Close DB Connection
*
- * @param object
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
$this->conn_id->close();
- $this->conn_id = FALSE;
}
}
/* End of file mysqli_driver.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
+/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 503574dfc..b74c775b2 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -60,13 +60,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field)
- .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '')
- ;
+ $sql .= "\n\t".$this->db->escape_identifiers($field);
+
+ empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
if ( ! empty($attributes['TYPE']))
{
- $sql .= ' '.$attributes['TYPE'];
+ $sql .= ' '.$attributes['TYPE'];
if ( ! empty($attributes['CONSTRAINT']))
{
@@ -87,10 +87,23 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
}
}
- $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' : '');
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
+ {
+ $sql .= ' UNSIGNED';
+ }
+
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' AUTO_INCREMENT';
+ }
}
// don't add a comma on the end of the last field
@@ -128,8 +141,8 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $key_name = $this->db->protect_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -138,12 +151,12 @@ 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->escape_identifiers(implode('_', $key));
+ $key = $this->db->escape_identifiers($key);
}
else
{
- $key_name = $this->db->protect_identifiers($key);
+ $key_name = $this->db->escape_identifiers($key);
$key = array($key_name);
}
@@ -170,16 +183,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
*/
protected function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
+ $sql = 'ALTER TABLE '.$this->db->escape_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->escape_identifiers($fields);
}
return $sql.$this->_process_fields($fields)
- .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 9b4d494d4..c1ec4da76 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.3
*/
class CI_DB_mysqli_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*/
public function num_rows()
{
- return $this->result_id->num_rows;
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = $this->result_id->num_rows;
}
// --------------------------------------------------------------------
@@ -157,11 +160,12 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return $this->result_id->fetch_object();
+ return $this->result_id->fetch_object($class_name);
}
}
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 27d4ef817..5d2bdbce0 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -46,9 +46,124 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*/
protected function _backup($params = array())
{
- // Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ if (count($params) === 0)
+ {
+ return FALSE;
+ }
+
+ // Extract the prefs for simplicity
+ extract($params);
+
+ // Build the output
+ $output = '';
+ foreach ( (array) $tables as $table)
+ {
+ // Is the table in the "ignore" list?
+ if (in_array($table, (array) $ignore, TRUE))
+ {
+ continue;
+ }
+
+ // Get the table schema
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
+
+ // No result means the table name was invalid
+ if ($query === FALSE)
+ {
+ continue;
+ }
+
+ // Write out the table schema
+ $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
+
+ if ($add_drop === TRUE)
+ {
+ $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
+ }
+
+ $i = 0;
+ $result = $query->result_array();
+ foreach ($result[0] as $val)
+ {
+ if ($i++ % 2)
+ {
+ $output .= $val.';'.$newline.$newline;
+ }
+ }
+
+ // If inserts are not needed we're done...
+ if ($add_insert === FALSE)
+ {
+ continue;
+ }
+
+ // Grab all the data from the current table
+ $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
+
+ if ($query->num_rows() === 0)
+ {
+ continue;
+ }
+
+ // Fetch the field names and determine if the field is an
+ // integer type. We use this info to decide whether to
+ // surround the data with quotes or not
+
+ $i = 0;
+ $field_str = '';
+ $is_int = array();
+ while ($field = $query->result_id->fetch_field())
+ {
+ // Most versions of MySQL store timestamp as a string
+ $is_int[$i] = in_array(strtolower($field->type),
+ array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
+ TRUE);
+
+ // Create a string of field names
+ $field_str .= $this->db->escape_identifiers($field->name).', ';
+ $i++;
+ }
+
+ // Trim off the end comma
+ $field_str = preg_replace('/, $/' , '', $field_str);
+
+ // Build the insert string
+ foreach ($query->result_array() as $row)
+ {
+ $val_str = '';
+
+ $i = 0;
+ foreach ($row as $v)
+ {
+ // Is the value NULL?
+ if ($v === NULL)
+ {
+ $val_str .= 'NULL';
+ }
+ else
+ {
+ // Escape the data if it's not an integer
+ $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
+ }
+
+ // Append a comma
+ $val_str .= ', ';
+ $i++;
+ }
+
+ // Remove the comma at the end of the string
+ $val_str = preg_replace('/, $/' , '', $val_str);
+
+ // Build the INSERT string
+ $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ }
+
+ $output .= $newline.$newline;
+ }
+
+ return $output;
}
+
}
/* End of file mysqli_utility.php */
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 33a89df94..7bf18949b 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -54,10 +54,6 @@ class CI_DB_oci8_driver extends CI_DB {
// The character used for excaping
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
@@ -66,6 +62,8 @@ class CI_DB_oci8_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(1) AS ';
protected $_random_keyword = ' ASC'; // not currently supported
+ protected $_reserved_identifiers = array('*', 'rownum');
+
// Set "auto commit" by default
public $commit_mode = OCI_COMMIT_ON_SUCCESS;
@@ -156,6 +154,8 @@ class CI_DB_oci8_driver extends CI_DB {
$this->dsn = '';
}
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -177,9 +177,9 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function db_pconnect()
{
- return ( ! empty($this->char_set))
- ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set)
- : @oci_pconnect($this->username, $this->password, $this->dsn);
+ return empty($this->char_set)
+ ? @oci_pconnect($this->username, $this->password, $this->dsn)
+ : @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set);
}
// --------------------------------------------------------------------
@@ -215,6 +215,8 @@ class CI_DB_oci8_driver extends CI_DB {
return @oci_execute($this->stmt_id, $this->commit_mode);
}
+ // --------------------------------------------------------------------
+
/**
* Generate a statement ID
*
@@ -234,7 +236,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Get cursor. Returns a cursor from the database
*
- * @return cursor id
+ * @return resource
*/
public function get_cursor()
{
@@ -262,7 +264,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function stored_procedure($package, $procedure, $params)
{
- if ($package == '' OR $procedure == '' OR ! is_array($params))
+ if ($package === '' OR $procedure === '' OR ! is_array($params))
{
if ($this->db_debug)
{
@@ -298,6 +300,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Bind parameters
*
+ * @param array
* @return void
*/
protected function _bind_params($params)
@@ -326,6 +329,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Begin Transaction
*
+ * @param bool
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -455,35 +459,6 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query == FALSE)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -493,11 +468,12 @@ class CI_DB_oci8_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = 'SELECT TABLE_NAME FROM ALL_TABLES';
+ $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"';
- if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
- return $sql." WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
@@ -515,7 +491,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/
protected function _list_columns($table = '')
{
- return 'SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = \''.$table.'\'';
+ return 'SELECT "COLUMN_NAME" FROM "all_tab_columns" WHERE "TABLE_NAME" = '.$this->escape($table);
}
// --------------------------------------------------------------------
@@ -530,7 +506,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return 'SELECT * FROM '.$table.' WHERE rownum = 1';
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' WHERE rownum = 1';
}
// --------------------------------------------------------------------
@@ -662,8 +638,8 @@ class CI_DB_oci8_driver extends CI_DB {
protected function _limit($sql, $limit, $offset)
{
$this->limit_used = TRUE;
- return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')'
- .($offset != 0 ? ' WHERE rnum >= '.$offset : '');
+ return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit + 1).')'
+ .($offset ? ' WHERE rnum >= '.($offset + 1): '');
}
// --------------------------------------------------------------------
@@ -671,15 +647,14 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @oci_close($conn_id);
+ @oci_close($this->conn_id);
}
}
/* End of file oci8_driver.php */
-/* Location: ./system/database/drivers/oci8/oci8_driver.php */
+/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index bd265b6e0..92e8c02ed 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -73,11 +73,22 @@ class CI_DB_oci8_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $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'] : '');
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
+
+ if (isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE)
+ {
+ $sql .= ' UNSIGNED';
+ }
+
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= (isset($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? '' : ' NOT NULL';
+
+ empty($attributes['CONSTRAINT']) OR ' CONSTRAINT '.$attributes['CONSTRAINT'];
}
// don't add a comma on the end of the last field
@@ -89,22 +100,16 @@ class CI_DB_oci8_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')';
+ $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')';
}
@@ -132,7 +137,7 @@ class CI_DB_oci8_forge extends CI_DB_forge {
*/
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 = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type === 'DROP')
@@ -141,9 +146,9 @@ class CI_DB_oci8_forge extends CI_DB_forge {
}
return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
.($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index 7b05e0a43..a2b600e6c 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.4.1
*/
class CI_DB_oci8_result extends CI_DB_result {
@@ -41,14 +42,16 @@ class CI_DB_oci8_result extends CI_DB_result {
public $limit_used;
public $commit_mode;
- /* Overwriting the parent here, so we have a way to know if it's
- * already called or not:
+ /**
+ * Constructor
+ *
+ * @param object
+ * @return void
*/
- public $num_rows;
-
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;
@@ -56,33 +59,6 @@ class CI_DB_oci8_result extends CI_DB_result {
$driver_object->stmt_id = FALSE;
}
- /**
- * Number of rows in the result set.
- *
- * Oracle doesn't have a graceful way to return the number of rows
- * so we have to use what amounts to a hack.
- *
- * @return int
- */
- public function num_rows()
- {
- if ( ! is_int($this->num_rows))
- {
- if (count($this->result_array) > 0)
- {
- return $this->num_rows = count($this->result_array);
- }
- elseif (count($this->result_object) > 0)
- {
- return $this->num_rows = count($this->result_object);
- }
-
- return $this->num_rows = count($this->result_array());
- }
-
- return $this->num_rows;
- }
-
// --------------------------------------------------------------------
/**
@@ -191,450 +167,27 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
- {
- $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
- return oci_fetch_object($id);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Query result. Array version.
- *
- * @return array
- */
- public function result_array()
+ protected function _fetch_object($class_name = 'stdClass')
{
- if (count($this->result_array) > 0)
- {
- return $this->result_array;
- }
- elseif (count($this->result_object) > 0)
- {
- for ($i = 0, $c = count($this->result_object); $i < $c; $i++)
- {
- $this->result_array[$i] = (array) $this->result_object[$i];
- }
-
- return $this->result_array;
- }
- elseif (is_array($this->row_data))
- {
- if (count($this->row_data) === 0)
- {
- return $this->result_array;
- }
- else
- {
- $row_index = count($this->row_data);
- }
- }
- else
- {
- $row_index = 0;
- $this->row_data = array();
- }
-
- $row = NULL;
- while ($row = $this->_fetch_assoc())
- {
- $this->row_data[$row_index++] = $row;
- }
-
- return $this->result_array = $this->row_data;
- }
+ $row = ($this->curs_id)
+ ? oci_fetch_object($this->curs_id)
+ : oci_fetch_object($this->stmt_id);
- // --------------------------------------------------------------------
-
- /**
- * Query result. "object" version.
- *
- * @return array
- */
- public function result_object()
- {
- if (count($this->result_object) > 0)
- {
- return $this->result_object;
- }
- elseif (count($this->result_array) > 0)
- {
- for ($i = 0, $c = count($this->result_array); $i < $c; $i++)
- {
- $this->result_object[] = (object) $this->result_array[$i];
- }
-
- return $this->result_object;
- }
- elseif (is_array($this->row_data))
- {
- if (count($this->row_data) === 0)
- {
- return $this->result_object;
- }
- else
- {
- $row_index = count($this->row_data);
- for ($i = 0; $i < $row_index; $i++)
- {
- $this->result_object[$i] = (object) $this->row_data[$i];
- }
- }
- }
- else
- {
- $row_index = 0;
- $this->row_data = array();
- }
-
- $row = NULL;
- while ($row = $this->_fetch_object())
- {
- $this->row_data[$row_index] = (array) $row;
- $this->result_object[$row_index++] = $row;
- }
-
- return $this->result_object;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Query result. Custom object version.
- *
- * @param string class name used to instantiate rows to
- * @return array
- */
- public function custom_result_object($class_name)
- {
- if (isset($this->custom_result_object[$class_name]))
- {
- return $this->custom_result_object[$class_name];
- }
-
- if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0)
- {
- return array();
- }
-
- /* Even if we didn't have result_array or result_object
- * set prior to custom_result_object() being called,
- * num_rows() has already done so.
- * Pass by reference, as we don't know how
- * large it might be and we don't want 1000 row
- * sets being copied.
- */
- if (count($this->result_array) > 0)
- {
- $data = &$this->result_array;
- }
- elseif (count($this->result_object) > 0)
- {
- $data = &$this->result_object;
- }
-
- $this->custom_result_object[$class_name] = array();
- for ($i = 0, $c = count($data); $i < $c; $i++)
- {
- $this->custom_result_object[$class_name][$i] = new $class_name();
- foreach ($data[$i] as $key => $value)
- {
- $this->custom_result_object[$class_name][$i]->$key = $value;
- }
- }
-
- return $this->custom_result_object[$class_name];
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result.
- *
- * Acts as a wrapper for row_object(), row_array()
- * and custom_row_object(). Also used by first_row(), next_row()
- * and previous_row().
- *
- * @param int row index
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function row($n = 0, $type = 'object')
- {
- if ($type === 'object')
- {
- return $this->row_object($n);
- }
- elseif ($type === 'array')
- {
- return $this->row_array($n);
- }
-
- return $this->custom_row_object($n, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Array version.
- *
- * @param int row index
- * @return array
- */
- public function row_array($n = 0)
- {
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
-
- /* If row_data is initialized, it means that we've already tried
- * (at least) to fetch some data, so ... check if we already have
- * this row.
- */
- if (is_array($this->row_data))
- {
- /* If we already have row_data[$n] - return it.
- *
- * If we enter the elseif, there's a number of reasons to
- * return an empty array:
- *
- * - count($this->row_data) === 0 means there are no results
- * - num_rows being set, result_array and/or result_object
- * having count() > 0 means that we've already fetched all
- * data and $n is greater than our highest row index available
- * - $n < $this->current_row means that if such row existed,
- * we would've already returned it, therefore $n is an
- * invalid index
- */
- if (isset($this->row_data[$n])) // We already have this row
- {
- $this->current_row = $n;
- return $this->row_data[$n];
- }
- elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
- OR count($this->result_array) > 0 OR count($this->result_object) > 0
- OR $n < $this->current_row)
- {
- // No such row exists
- return array();
- }
-
- // Get the next row index that would actually need to be fetched
- $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
- }
- else
- {
- $current_row = $this->current_row = 0;
- $this->row_data = array();
- }
-
- /* Fetch more data, if available
- *
- * NOTE: Operator precedence is important here, if you change
- * 'AND' with '&&' - it WILL BREAK the results, as
- * $row will be assigned the scalar value of both
- * expressions!
- */
- while ($row = $this->_fetch_assoc() AND $current_row <= $n)
- {
- $this->row_data[$current_row++] = $row;
- }
-
- // This would mean that there's no (more) data to fetch
- if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
- {
- // Cache what we already have
- if (is_array($this->row_data))
- {
- $this->num_rows = count($this->row_data);
- /* Usually, row_data could have less elements than result_array,
- * but at this point - they should be exactly the same.
- */
- $this->result_array = $this->row_data;
- }
- else
- {
- $this->num_rows = 0;
- }
-
- return array();
- }
-
- $this->current_row = $n;
- return $this->row_data[$n];
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Object version.
- *
- * @param int row index
- * @return mixed object if row found; empty array if not
- */
- public function row_object($n = 0)
- {
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
- /* Logic here is exactly the same as in row_array,
- * except we have to cast row_data[$n] to an object.
- *
- * If we already have result_object though - we can
- * directly return from it.
- */
- if (isset($this->result_object[$n]))
- {
- $this->current_row = $n;
- // Set this, if not already done.
- if ( ! is_int($this->num_rows))
- {
- $this->num_rows = count($this->result_object);
- }
-
- return $this->result_object[$n];
- }
-
- $row = $this->row_array($n);
- // Cast only if the row exists
- if (count($row) > 0)
- {
- $this->current_row = $n;
- return (object) $row;
- }
-
- return array();
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Custom object version.
- *
- * @param int row index
- * @param string custom class name
- * @return mixed custom object if row found; empty array otherwise
- */
- public function custom_row_object($n = 0, $class_name)
- {
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
-
- if (array_key_exists($class_name, $this->custom_result_object))
- {
- /* We already have a the whole result set with this class_name,
- * return the specified row if it exists, and an empty array if
- * it doesn't.
- */
- if (isset($this->custom_result_object[$class_name][$n]))
- {
- $this->current_row = $n;
- return $this->custom_result_object[$class_name][$n];
- }
- else
- {
- return array();
- }
- }
- elseif ( ! class_exists($class_name)) // No such class exists
- {
- return array();
- }
-
- $row = $this->row_array($n);
- // An array would mean that the row doesn't exist
- if (is_array($row))
+ if ($class_name === 'stdClass' OR ! $row)
{
return $row;
}
- // Convert to the desired class and return
- $row_object = new $class_name();
+ $class_name = new $class_name();
foreach ($row as $key => $value)
{
- $row_object->$key = $value;
+ $class_name->$key = $value;
}
- $this->current_row = $n;
- return $row_object;
- }
-
- // --------------------------------------------------------------------
-
- /* First row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function first_row($type = 'object')
- {
- return $this->row(0, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Last row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function last_row($type = 'object')
- {
- $result = &$this->result($type);
- if ( ! isset($this->num_rows))
- {
- $this->num_rows = count($result);
- }
- $this->current_row = $this->num_rows - 1;
- return $result[$this->current_row];
- }
-
- // --------------------------------------------------------------------
-
- /* Next row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function next_row($type = 'object')
- {
- if (is_array($this->row_data))
- {
- $count = count($this->row_data);
- if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0))
- {
- $n = $count;
- }
- else
- {
- $n = $this->current_row + 1;
- }
- }
- else
- {
- $n = 0;
- }
-
- return $this->row($n, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Previous row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function previous_row($type = 'object')
- {
- $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
- return $this->row($n, $type);
+ return $class_name;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index e36f2d233..fbf6a4cb1 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -45,16 +45,8 @@ class CI_DB_odbc_driver extends CI_DB {
// the character used to excape - not necessary for ODBC
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;
public function __construct($params)
@@ -64,7 +56,7 @@ class CI_DB_odbc_driver extends CI_DB {
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
// Legacy support for DSN in the hostname field
- if ($this->dsn == '')
+ if (empty($this->dsn))
{
$this->dsn = $this->hostname;
}
@@ -114,13 +106,8 @@ class CI_DB_odbc_driver extends CI_DB {
*/
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;
}
@@ -128,7 +115,7 @@ class CI_DB_odbc_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 odbc_autocommit($this->conn_id, FALSE);
}
@@ -142,13 +129,8 @@ class CI_DB_odbc_driver extends CI_DB {
*/
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;
}
@@ -167,13 +149,8 @@ class CI_DB_odbc_driver extends CI_DB {
*/
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;
}
@@ -204,7 +181,6 @@ class CI_DB_odbc_driver extends CI_DB {
return $str;
}
- // ODBC doesn't require escaping
$str = remove_invisible_characters($str);
// escape LIKE condition wildcards
@@ -245,36 +221,6 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string . $this->protect_identifiers('numrows') . " FROM " . $this->protect_identifiers($table, TRUE, NULL, FALSE));
-
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -284,9 +230,9 @@ class CI_DB_odbc_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM `".$this->database."`";
+ $sql = 'SHOW TABLES FROM '.$this->database;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
//$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
return FALSE; // not currently supported
@@ -307,7 +253,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$table;
+ return 'SHOW COLUMNS FROM '.$table;
}
// --------------------------------------------------------------------
@@ -322,7 +268,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$table;
+ return 'SELECT TOP 1 FROM '.$table;
}
// --------------------------------------------------------------------
@@ -353,12 +299,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
protected function _from_tables($tables)
{
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return '('.implode(', ', $tables).')';
+ return is_array($tables) ? implode(', ', $tables) : $tables;
}
// --------------------------------------------------------------------
@@ -382,35 +323,16 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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)
- {
- // Does ODBC doesn't use the LIMIT clause?
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @odbc_close($conn_id);
+ @odbc_close($this->conn_id);
}
}
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index d59b8a911..d17b046ee 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -34,7 +34,6 @@
*/
class CI_DB_odbc_forge extends CI_DB_forge {
- protected $_drop_database = 'DROP DATABASE %s';
protected $_drop_table = 'DROP TABLE %s';
/**
@@ -66,41 +65,30 @@ class CI_DB_odbc_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
+ empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -115,30 +103,22 @@ class CI_DB_odbc_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -160,37 +140,18 @@ class CI_DB_odbc_forge extends CI_DB_forge {
*/
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 = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index ecba5977e..48dc48dd9 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -33,11 +33,10 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.3
*/
class CI_DB_odbc_result extends CI_DB_result {
- public $num_rows;
-
/**
* Number of rows in the result set
*
@@ -49,14 +48,22 @@ class CI_DB_odbc_result extends CI_DB_result {
{
return $this->num_rows;
}
+ elseif (($this->num_rows = @odbc_num_rows($this->result_id)) !== -1)
+ {
+ 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)
+ if (count($this->result_array) > 0)
{
- $this->num_rows = count($this->result_array());
+ return $this->num_rows = count($this->result_array);
+ }
+ elseif (count($this->result_object) > 0)
+ {
+ return $this->num_rows = count($this->result_object);
}
- return $this->num_rows;
+ return $this->num_rows = count($this->result_array());
}
// --------------------------------------------------------------------
@@ -148,14 +155,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
protected function _fetch_assoc()
{
- if (function_exists('odbc_fetch_array'))
- {
- return odbc_fetch_array($this->result_id);
- }
- else
- {
- return $this->_odbc_fetch_array($this->result_id);
- }
+ return odbc_fetch_array($this->result_id);
}
// --------------------------------------------------------------------
@@ -165,141 +165,93 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- if (function_exists('odbc_fetch_object'))
- {
- return odbc_fetch_object($this->result_id);
- }
- else
+ $row = odbc_fetch_object($this->result_id);
+
+ if ($class_name === 'stdClass' OR ! $row)
{
- return $this->_odbc_fetch_object($this->result_id);
+ return $row;
}
- }
-
- // --------------------------------------------------------------------
- /**
- * Result - object
- *
- * subsititutes the odbc_fetch_object function when
- * not available (odbc_fetch_object requires unixODBC)
- *
- * @return object
- */
- protected function _odbc_fetch_object(& $odbc_result)
- {
- $rs = array();
- $rs_obj = FALSE;
- if (odbc_fetch_into($odbc_result, $rs))
+ $class_name = new $class_name();
+ foreach ($row as $key => $value)
{
- foreach ($rs as $k => $v)
- {
- $field_name = odbc_field_name($odbc_result, $k+1);
- $rs_obj->$field_name = $v;
- }
+ $class_name->$key = $value;
}
- return $rs_obj;
+
+ return $class_name;
}
- // --------------------------------------------------------------------
+}
+
+// --------------------------------------------------------------------
+if ( ! function_exists('odbc_fetch_array'))
+{
/**
- * Result - array
+ * ODBC Fetch array
*
- * subsititutes the odbc_fetch_array function when
- * not available (odbc_fetch_array requires unixODBC)
+ * Emulates the native odbc_fetch_array() function when
+ * it is not available (odbc_fetch_array() requires unixODBC)
*
+ * @param resource
+ * @param int
* @return array
*/
- protected function _odbc_fetch_array(& $odbc_result)
+ function odbc_fetch_array(& $result, $rownumber = 1)
{
$rs = array();
- $rs_assoc = FALSE;
- if (odbc_fetch_into($odbc_result, $rs))
+ if ( ! odbc_fetch_into($result, $rs, $rownumber))
{
- $rs_assoc = array();
- foreach ($rs as $k => $v)
- {
- $field_name = odbc_field_name($odbc_result, $k+1);
- $rs_assoc[$field_name] = $v;
- }
+ return FALSE;
}
- 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)
+ $rs_assoc = array();
+ foreach ($rs as $k => $v)
{
- return array();
- }
- else
- {
- while ($row = $this->_fetch_assoc())
- {
- $this->result_array[] = $row;
- }
+ $field_name = odbc_field_name($result, $k+1);
+ $rs_assoc[$field_name] = $v;
}
- return $this->result_array;
+ return $rs_assoc;
}
+}
- // --------------------------------------------------------------------
+// --------------------------------------------------------------------
+if ( ! function_exists('odbc_fetch_object'))
+{
/**
- * Query result. Object version.
+ * ODBC Fetch object
*
- * @return array
+ * Emulates the native odbc_fetch_object() function when
+ * it is not available.
+ *
+ * @param resource
+ * @param int
+ * @return object
*/
- public function result_object()
+ function odbc_fetch_object(& $result, $rownumber = 1)
{
- 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)
+ $rs = array();
+ if ( ! odbc_fetch_into($result, $rs, $rownumber))
{
- return array();
+ return FALSE;
}
- else
+
+ $rs_object = new stdClass();
+ foreach ($rs as $k => $v)
{
- while ($row = $this->_fetch_object())
- {
- $this->result_object[] = $row;
- }
+ $field_name = odbc_field_name($result, $k+1);
+ $rs_object->$field_name = $v;
}
- return $this->result_object;
+ return $rs_object;
}
-
}
/* End of file odbc_result.php */
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 89e69676d..0ffe3bc13 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -42,145 +42,62 @@ class CI_DB_pdo_driver extends CI_DB {
public $dbdriver = 'pdo';
- // the character used to excape - not necessary for PDO
- protected $_escape_char = '';
+ // The character used to escaping
+ 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;
- // need to track the pdo driver and options
- public $pdodriver;
+ public $trans_enabled = FALSE;
+
+ // need to track the PDO options
public $options = array();
+ /**
+ * Constructor
+ *
+ * Validates the DSN string and/or detects the subdriver
+ *
+ * @param array
+ * @return void
+ */
public function __construct($params)
{
parent::__construct($params);
- if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2)
+ 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);
+ $this->subdriver = $match[1];
+ return;
}
- else
+ // Legacy support for DSN specified in the hostname field
+ elseif (preg_match('/([^;]+):/', $this->hostname, $match) && count($match) === 2)
{
- // Try to build a complete DSN string from params
- $this->_connect_string($params);
+ $this->dsn = $this->hostname;
+ $this->hostname = NULL;
+ $this->subdriver = $match[1];
+ return;
}
-
- // clause and character used for LIKE escape sequences
- // this one depends on the driver being used
- if ($this->pdodriver == 'mysql')
+ elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE))
{
- $this->_escape_char = '`';
- $this->_like_escape_str = '';
- $this->_like_escape_chr = '';
+ $this->subdriver = 'dblib';
}
- elseif ($this->pdodriver == 'odbc')
+ elseif ($this->subdriver === '4D')
{
- $this->_like_escape_str = " {escape '%s'} ";
+ $this->subdriver = '4d';
}
- elseif ( ! in_array($this->pdodriver, array('sqlsrv', 'mssql', 'dblib', 'sybase')))
+ elseif ( ! in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'sqlite', 'sqlsrv'), TRUE))
{
- $this->_escape_char = '"';
- }
-
- $this->trans_enabled = FALSE;
- $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
- }
+ log_message('error', 'PDO: Invalid or non-existent subdriver');
- /**
- * Connection String
- *
- * @param array
- * @return void
- */
- protected function _connect_string($params)
- {
- if (strpos($this->hostname, ':'))
- {
- // 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))
+ if ($this->db_debug)
{
- $this->dsn .= rtrim($this->hostname, ';').';';
+ show_error('Invalid or non-existent PDO subdriver');
}
}
- else
- {
- // Invalid DSN, display an error
- if ( ! array_key_exists('pdodriver', $params))
- {
- show_error('Invalid DB Connection String for PDO');
- }
-
- // 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.';';
- }
+ $this->dsn = NULL;
}
// --------------------------------------------------------------------
@@ -188,11 +105,27 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Non-persistent database connection
*
+ * @param bool
* @return object
*/
- public function db_connect()
+ public function db_connect($persistent = FALSE)
{
- return $this->_pdo_connect();
+ $this->options[PDO::ATTR_PERSISTENT] = $persistent;
+
+ // Connecting...
+ try
+ {
+ return @new PDO($this->dsn, $this->username, $this->password, $this->options);
+ }
+ catch (PDOException $e)
+ {
+ if ($this->db_debug && empty($this->failover))
+ {
+ $this->display_error($e->getMessage(), '', TRUE);
+ }
+
+ return FALSE;
+ }
}
// --------------------------------------------------------------------
@@ -204,66 +137,37 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function db_pconnect()
{
- return $this->_pdo_connect(TRUE);
+ return $this->db_connect(TRUE);
}
// --------------------------------------------------------------------
/**
- * PDO connection
+ * Database version number
*
- * @param bool
- * @return object
+ * @return string
*/
- protected function _pdo_connect($persistent = FALSE)
+ public function version()
{
- $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
- $persistent === FALSE OR $this->options[PDO::ATTR_PERSISTENT] = TRUE;
-
- /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
- * on connect - it was ignored. This is a work-around for the issue.
- *
- * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
- */
- if ($this->pdodriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set))
+ if (isset($this->data_cache['version']))
{
- $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
- .( ! empty($this->db_collat) ? " COLLATE '".$this->dbcollat."'" : '');
+ return $this->data_cache['version'];
}
- // Connecting...
+ // Not all subdrivers support the getAttribute() method
try
{
- return new PDO($this->dsn, $this->username, $this->password, $this->options);
+ return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
}
catch (PDOException $e)
{
- if ($this->db_debug && empty($this->failover))
- {
- $this->display_error($e->getMessage(), '', TRUE);
- }
-
- return FALSE;
+ return parent::version();
}
}
// --------------------------------------------------------------------
/**
- * Database version number
- *
- * @return string
- */
- public function version()
- {
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Execute the query
*
* @param string an SQL query
@@ -358,7 +262,7 @@ class CI_DB_pdo_driver extends CI_DB {
$str = $this->conn_id->quote($str);
// If there are duplicated quotes, trim them away
- if (strpos($str, "'") === 0)
+ if ($str[0] === "'")
{
$str = substr($str, 1, -1);
}
@@ -396,101 +300,12 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function insert_id($name = NULL)
{
- if ($this->pdodriver === 'pgsql' && $name === NULL && $this->version() >= '8.1')
- {
- $query = $this->query('SELECT LASTVAL() AS ins_id');
- $query = $query->row();
- return $query->ins_id;
- }
-
return $this->conn_id->lastInsertId($name);
}
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $sql = $this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
- $query = $this->query($sql);
-
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
-
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Show table query
- *
- * Generates a platform-specific query string so that the table names can be fetched
- *
- * @param bool
- * @return string
- */
- protected function _list_tables($prefix_limit = FALSE)
- {
- 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->escape_identifiers($this->database);
- }
-
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
- {
- return FALSE;
- }
-
- 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 'SHOW COLUMNS FROM '.$this->escape_identifiers($table);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -500,23 +315,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
protected function _field_data($table)
{
- if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql')
- {
- // Analog function for mysql and postgre
- return 'SELECT * FROM '.$this->escape_identifiers($table).' LIMIT 1';
- }
- elseif ($this->pdodriver == 'oci')
- {
- // Analog function for oci
- return 'SELECT * FROM '.$this->escape_identifiers($table).' WHERE ROWNUM <= 1';
- }
- elseif ($this->pdodriver == 'sqlite')
- {
- // Analog function for sqlite
- return 'PRAGMA table_info('.$this->escape_identifiers($table).')';
- }
-
- return 'SELECT TOP 1 FROM '.$this->escape_identifiers($table);
+ return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -551,27 +350,6 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * From Tables
- *
- * This 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);
- }
-
- return (count($tables) === 1) ? $tables[0] : '('.implode(', ', $tables).')';
- }
-
- // --------------------------------------------------------------------
-
- /**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
@@ -583,8 +361,8 @@ class CI_DB_pdo_driver extends CI_DB {
*/
protected function _update_batch($table, $values, $index, $where = NULL)
{
- $ids = array();
- $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : '';
+ $ids = array();
+ $where = ($where !== '' && count($where) >=1) ? implode(' ', $where).' AND ' : '';
foreach ($values as $key => $val)
{
@@ -592,7 +370,7 @@ class CI_DB_pdo_driver extends CI_DB {
foreach (array_keys($val) as $field)
{
- if ($field != $index)
+ if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
@@ -635,49 +413,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
protected function _truncate($table)
{
- return 'DELETE FROM '.$table;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * 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)
- {
- if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite')
- {
- $offset = ($offset == 0) ? '' : $offset.', ';
-
- return $sql.'LIMIT '.$offset.$limit;
- }
- else
- {
- $sql .= 'LIMIT '.$limit;
- $sql .= ($offset > 0) ? ' OFFSET '.$offset : '';
-
- return $sql;
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Close DB Connection
- *
- * @param object
- * @return void
- */
- protected function _close($conn_id)
- {
- $this->conn_id = NULL;
+ return 'TRUNCATE TABLE '.$table;
}
}
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index ca8657a0f..34a6ee44e 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -34,7 +34,6 @@
*/
class CI_DB_pdo_forge extends CI_DB_forge {
- protected $_drop_database = 'DROP DATABASE %s';
protected $_drop_table = 'DROP TABLE %s';
/**
@@ -66,46 +65,38 @@ class CI_DB_pdo_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $numeric = array('SERIAL', 'INTEGER');
+ $numeric = array('SERIAL', 'INTEGER');
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
+ if ( ! empty($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)))
+ if ( ! ($this->db->subdriver === 'pgsql' && in_array($attributes['TYPE'], $numeric)))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -120,30 +111,22 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -165,37 +148,18 @@ class CI_DB_pdo_forge extends CI_DB_forge {
*/
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 = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql .' '.$column_definition
+ .($default_value !== '' ? " DEFAULT '".$default_value."'" : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 0b8937cc5..444406986 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -21,7 +21,7 @@
* @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 2.1.0
+ * @since Version 1.0
* @filesource
*/
@@ -33,72 +33,35 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 2.1
*/
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
*
* @return int
*/
public function num_rows()
{
- if (empty($this->result_id) OR ! is_object($this->result_id))
+ if (is_int($this->num_rows))
{
- // invalid result handler
- return 0;
+ return $this->num_rows;
}
- elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0)
+ elseif (count($this->result_array) > 0)
{
- // If rowCount return something, we're done.
- return $num_rows;
+ return $this->num_rows = count($this->result_array);
}
-
- // 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)
+ elseif (count($this->result_object) > 0)
{
- return $this->result_array();
+ return $this->num_rows = count($this->result_object);
}
-
- // Define the output
- $output = array('assoc', 'object');
-
- // Initial value
- $this->result_assoc = array() and $this->result_object = array();
-
- // Fetch the result
- while ($row = $this->_fetch_assoc())
+ elseif (($num_rows = $this->result_id->rowCount()) > 0)
{
- $this->result_assoc[] = $row;
- $this->result_object[] = (object) $row;
+ return $this->num_rows = $num_rows;
}
- // Save this as buffer and marked the fetch flag
- $this->result_array = $this->result_assoc;
- $this->is_fetched = TRUE;
-
- return $this->result_assoc;
+ return $this->num_rows = count($this->result_array());
}
// --------------------------------------------------------------------
@@ -124,12 +87,14 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
public function list_fields()
{
- if ($this->db->db_debug)
+ $field_names = array();
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
- return $this->db->display_error('db_unsuported_feature');
+ $field_names[$i] = @$this->result_id->getColumnMeta();
+ $field_names[$i] = $field_names[$i]['name'];
}
- return FALSE;
+ return $field_names;
}
// --------------------------------------------------------------------
@@ -240,11 +205,12 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return $this->result_id->fetch(PDO::FETCH_OBJ);
+ return $this->result_id->fetchObject($class_name);
}
}
diff --git a/system/database/drivers/pdo/subdrivers/index.html b/system/database/drivers/pdo/subdrivers/index.html
new file mode 100644
index 000000000..c942a79ce
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/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/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
new file mode 100644
index 000000000..e287f5c63
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
@@ -0,0 +1,223 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO 4D Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_4d_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = '4d';
+
+ // The character used for escaping
+ protected $_escape_char = array('[', ']');
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ empty($this->port) OR $this->dsn .= ';port='.$this->port;
+ empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ }
+ elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE)
+ {
+ $this->dsn .= ';charset='.$this->char_set;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES');
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' WHERE '.$this->escape_identifiers('TABLE_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 '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS')
+ .' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($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)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause (ignored)
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ 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)
+ {
+ return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : '');
+ }
+
+}
+
+/* End of file pdo_4d_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_4d_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
new file mode 100644
index 000000000..eb3714783
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
@@ -0,0 +1,185 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO CUBRID Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_cubrid_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'cubrid';
+
+ protected $_escape_char = '`';
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ empty($this->port) OR $this->dsn .= ';port='.$this->port;
+ empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 = 'SHOW TABLES';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ }
+
+ 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 '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
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _field_data($table)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' LIMIT 1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ protected function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ foreach ($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach (array_keys($val) as $field)
+ {
+ if ($field !== $index)
+ {
+ $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k." = CASE \n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
+
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ *
+ * If the database does not support the truncate() command,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'TRUNCATE '.$table;
+ }
+
+}
+
+/* End of file pdo_cubrid_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
new file mode 100644
index 000000000..7060c9eb9
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
@@ -0,0 +1,265 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO DBLIB Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_dblib_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'dblib';
+
+ protected $_random_keyword = ' NEWID()';
+
+ protected $_quoted_identifier;
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = $params['subdriver'].':host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ if ( ! empty($this->port))
+ {
+ $this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
+ }
+
+ empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ empty($this->appname) OR $this->dsn .= ';appname='.$this->appname;
+ }
+ else
+ {
+ if ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE)
+ {
+ $this->dsn .= ';charset='.$this->char_set;
+ }
+
+ $this->subdriver = 'dblib';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Non-persistent database connection
+ *
+ * @param bool
+ * @return object
+ */
+ public function db_connect($persistent = FALSE)
+ {
+ $this->conn_id = parent::db_connect($persistent);
+
+ if ( ! is_object($this->conn_id))
+ {
+ return $this->conn_id;
+ }
+
+ // Determine how identifiers are escaped
+ $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
+ $query = $query->row_array();
+ $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
+ $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
+
+ return $this->conn_id;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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)
+ {
+ return 'SELECT '.$this->escape_identifiers('name')
+ .' FROM '.$this->escape_identifiers('sysobjects')
+ .' WHERE '.$this->escape_identifiers('type')." = 'U'";
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ }
+
+ return $sql.' ORDER BY '.$this->escape_identifiers('name');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 '.$this->escape_identifiers('column_name')
+ .' FROM '.$this->escape_identifiers('information_schema.columns')
+ .' WHERE '.$this->escape_identifiers('table_name').' = '.$this->escape($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ return ($limit)
+ ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete'
+ : '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 = $offset + $limit;
+
+ // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
+ // however an ORDER BY clause is required for it to work
+ if (version_compare($this->version(), '9', '>=') && $offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
+
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
+ }
+
+}
+
+/* End of file pdo_dblib_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php */
diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
new file mode 100644
index 000000000..c074a9a78
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
@@ -0,0 +1,262 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO Firebird Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_firebird_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'firebird';
+
+ /**
+ * 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 $_random_keyword = ' RANDOM()'; // Currently not supported
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'firebird:';
+
+ if ( ! empty($this->database))
+ {
+ $this->dsn .= 'dbname='.$this->database;
+ }
+ elseif ( ! empty($this->hostname))
+ {
+ $this->dsn .= 'dbname='.$this->hostname;
+ }
+
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ empty($this->role) OR $this->dsn .= ';role='.$this->role;
+ }
+ elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE)
+ {
+ $this->dsn .= ';charset='.$this->char_set;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 === TRUE && $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($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)
+ {
+ return 'SELECT FIRST 1 * FROM '.$this->protect_identifiers($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .$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,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'DELETE FROM '.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause (ignored)
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $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);
+ }
+
+}
+
+/* End of file pdo_firebird_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
new file mode 100644
index 000000000..832c03c96
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
@@ -0,0 +1,262 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO IBM DB2 Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_ibm_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'ibm';
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'ibm:';
+
+ // Pre-defined DSN
+ if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
+ {
+ if (isset($this->DSN))
+ {
+ $this->dsn .= 'DSN='.$this->DSN;
+ }
+ elseif ( ! empty($this->database))
+ {
+ $this->dsn .= 'DSN='.$this->database;
+ }
+
+ return;
+ }
+
+ $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
+
+ if (isset($this->DATABASE))
+ {
+ $this->dsn .= 'DATABASE='.$this->DATABASE.';';
+ }
+ elseif ( ! empty($this->database))
+ {
+ $this->dsn .= 'DATABASE='.$this->database.';';
+ }
+
+ if (isset($this->HOSTNAME))
+ {
+ $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
+ }
+ else
+ {
+ $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
+ }
+
+ if (isset($this->PORT))
+ {
+ $this->dsn .= 'PORT='.$this->port.';';
+ }
+ elseif ( ! empty($this->port))
+ {
+ $this->dsn .= ';PORT='.$this->port.';';
+ }
+
+ $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 "tabname" FROM "syscat"."tables" WHERE "type" = \'T\'';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' AND "tabname" 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 "colname" FROM "syscat"."tables"
+ WHERE "syscat"."tabtype" = \'T\' AND "syscat"."tabname" = '.$this->escape($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)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' FETCH FIRST 1 ROWS ONLY';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause (ignored)
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ 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)
+ {
+ $sql .= ' FETCH FIRST '.($limit + $offset).' ROWS ONLY';
+
+ return ($offset)
+ ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$offset
+ : $sql;
+ }
+
+}
+
+/* End of file pdo_ibm_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
new file mode 100644
index 000000000..a3efc63dc
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
@@ -0,0 +1,271 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO Informix Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_informix_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'informix';
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'informix:';
+
+ // Pre-defined DSN
+ if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service))
+ {
+ if (isset($this->DSN))
+ {
+ $this->dsn .= 'DSN='.$this->DSN;
+ }
+ elseif ( ! empty($this->database))
+ {
+ $this->dsn .= 'DSN='.$this->database;
+ }
+
+ return;
+ }
+
+ if (isset($this->host))
+ {
+ $this->dsn .= 'host='.$this->host;
+ }
+ else
+ {
+ $this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+ }
+
+ if (isset($this->service))
+ {
+ $this->dsn .= '; service='.$this->service;
+ }
+ elseif ( ! empty($this->port))
+ {
+ $this->dsn .= '; service='.$this->port;
+ }
+
+ empty($this->database) OR $this->dsn .= '; database='.$this->database;
+ empty($this->server) OR $this->dsn .= '; server='.$this->server;
+
+ $this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp')
+ .'; EnableScrollableCursors=1';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 "tabname" FROM "systables" WHERE "tabid" > 99 AND "tabtype" = \'T\'';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' AND "tabname" 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 "colname" FROM "systables", "syscolumns"
+ WHERE "systables"."tabid" = "syscolumns"."tabid" AND "systables"."tabtype" = \'T\' AND "systables"."tabname" = '
+ .$this->escape($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)
+ {
+ return 'SELECT FIRST 1 * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ *
+ * If the database does not support the truncate() command,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'TRUNCATE TABLE ONLY '.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause (ignored)
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ 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)
+ {
+ $select = 'SELECT '.($offset ? 'SKIP '.$offset : '').'FIRST '.$limit.' ';
+ return preg_replace('/^(SELECT\s)/i', $select, $sql, 1);
+ }
+
+}
+
+/* End of file pdo_informix_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_informix_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
new file mode 100644
index 000000000..b6807026d
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
@@ -0,0 +1,213 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO MySQL Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_mysql_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'mysql';
+
+ protected $_escape_char = '`';
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ empty($this->port) OR $this->dsn .= ';port='.$this->port;
+ empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ }
+ elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE && is_php('5.3.6'))
+ {
+ $this->dsn .= ';charset='.$this->char_set;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Non-persistent database connection
+ *
+ * @param bool
+ * @return object
+ */
+ public function db_connect($persistent = FALSE)
+ {
+ /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
+ * on connect - it was ignored. This is a work-around for the issue.
+ *
+ * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
+ */
+ if ( ! is_php('5.3.6') && ! empty($this->char_set))
+ {
+ $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
+ .(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat);
+ }
+
+ return parent::db_connect($persistent);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 = 'SHOW TABLES';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ }
+
+ 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 '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
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _field_data($table)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' LIMIT 1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ protected function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ foreach ($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach (array_keys($val) as $field)
+ {
+ if ($field !== $index)
+ {
+ $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k." = CASE \n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
+
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ *
+ * If the database does not support the truncate() command,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'TRUNCATE '.$table;
+ }
+
+}
+
+/* End of file pdo_mysql_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
new file mode 100644
index 000000000..56ec1bce1
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
@@ -0,0 +1,230 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO Oracle Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_oci_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'oci';
+
+ /**
+ * 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(1) AS ';
+ protected $_random_keyword = ' ASC'; // Currently not supported
+
+ protected $_reserved_identifiers = array('*', 'rownum');
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'oci:dbname=';
+
+ // Oracle has a slightly different PDO DSN format (Easy Connect),
+ // which also supports pre-defined DSNs.
+ if (empty($this->hostname) && empty($this->port))
+ {
+ $this->dsn .= $this->database;
+ }
+ else
+ {
+ $this->dsn .= '//'.(empty($this->hostname) ? '127.0.0.1' : $this->hostname)
+ .(empty($this->port) ? '' : ':'.$this->port).'/';
+
+ empty($this->database) OR $this->dsn .= $this->database;
+ }
+
+ empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
+ }
+ elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE)
+ {
+ $this->dsn .= ';charset='.$this->char_set;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 "TABLE_NAME" FROM "ALL_TABLES"';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ return $sql.' WHERE "TABLE_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 "COLUMN_NAME" FROM "all_tab_columns" WHERE "TABLE_NAME" = '.$this->escape($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)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' WHERE rownum = 1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert_batch statement
+ *
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ $keys = implode(', ', $keys);
+ $sql = "INSERT ALL\n";
+
+ for ($i = 0, $c = count($values); $i < $c; $i++)
+ {
+ $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n";
+ }
+
+ return $sql.'SELECT * FROM dual';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+ empty($limit) OR $conditions[] = 'rownum <= '.$limit;
+
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $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)
+ {
+ return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit + 1).')'
+ .($offset ? ' WHERE rnum >= '.($offset + 1): '');
+ }
+
+}
+
+/* End of file pdo_oci_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_oci_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
new file mode 100644
index 000000000..dd7a1af52
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
@@ -0,0 +1,267 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO ODBC Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_odbc_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'odbc';
+
+ // The character used for escaping - not used in ODBC
+ protected $_escape_char = '';
+
+ // clause and character used for LIKE escape sequences
+ protected $_like_escape_str = " {escape '%s'} ";
+
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'odbc:';
+
+ // Pre-defined DSN
+ if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
+ {
+ if (isset($this->DSN))
+ {
+ $this->dsn .= 'DSN='.$this->DSN;
+ }
+ elseif ( ! empty($this->database))
+ {
+ $this->dsn .= 'DSN='.$this->database;
+ }
+
+ return;
+ }
+
+ // If the DSN is not pre-configured - try to build an IBM DB2 connection string
+ $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
+
+ if (isset($this->DATABASE))
+ {
+ $this->dsn .= 'DATABASE='.$this->DATABASE.';';
+ }
+ elseif ( ! empty($this->database))
+ {
+ $this->dsn .= 'DATABASE='.$this->database.';';
+ }
+
+ if (isset($this->HOSTNAME))
+ {
+ $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
+ }
+ else
+ {
+ $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
+ }
+
+ if (isset($this->PORT))
+ {
+ $this->dsn .= 'PORT='.$this->port.';';
+ }
+ elseif ( ! empty($this->port))
+ {
+ $this->dsn .= ';PORT='.$this->port.';';
+ }
+
+ $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 table_name FROM information_schema.tables WHERE table_schema = 'public'";
+
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
+ {
+ return $sql." AND table_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 column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ *
+ * If the database does not support the truncate() command,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'DELETE FROM '.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ 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)
+ {
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
+ }
+
+}
+
+/* End of file pdo_odbc_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
new file mode 100644
index 000000000..9a476f143
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
@@ -0,0 +1,341 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO PostgreSQL Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_pgsql_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'pgsql';
+
+ protected $_random_keyword = ' RANDOM()';
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'pgsql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ empty($this->port) OR $this->dsn .= ';port='.$this->port;
+ empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert ID
+ *
+ * @param string
+ * @return int
+ */
+ public function insert_id($name = NULL)
+ {
+ if ($name === NULL && version_compare($this->version(), '8.1', '>='))
+ {
+ $query = $this->query('SELECT LASTVAL() AS ins_id');
+ $query = $query->row();
+ return $query->ins_id;
+ }
+
+ return $this->conn_id->lastInsertId($name);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'public\'';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ return $sql.' AND "table_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 "column_name" FROM "information_schema"."columns" WHERE "table_name" = '.$this->escape($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)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' LIMIT 1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ protected function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ foreach ($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach (array_keys($val) as $field)
+ {
+ if ($field !== $index)
+ {
+ $final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k.' = (CASE '.$k."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
+
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause (ignored)
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $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)
+ {
+ return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : '');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where
+ *
+ * Called by where() or or_where()
+ *
+ * @param mixed
+ * @param mixed
+ * @param string
+ * @return object
+ */
+ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
+ {
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ // If the escape value was not set will will base it on the global setting
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
+ foreach ($key as $k => $v)
+ {
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
+ ? $this->_group_get_type('')
+ : $this->_group_get_type($type);
+
+ $k = (($op = $this->_get_operator($k)) !== FALSE)
+ ? $this->protect_identifiers(substr($k, 0, strpos($k, $op)), FALSE, $escape).strstr($k, $op)
+ : $this->protect_identifiers($k, FALSE, $escape);
+
+ if (is_null($v) && ! $this->_has_operator($k))
+ {
+ // value appears not to have been set, assign the test to IS NULL
+ $k .= ' IS NULL';
+ }
+
+ if ( ! is_null($v))
+ {
+ if ($escape === TRUE)
+ {
+ $v = ' '.$this->escape($v);
+ }
+ elseif (is_bool($v))
+ {
+ $v = ($v ? ' TRUE' : ' FALSE');
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' = ';
+ }
+ }
+
+ $this->qb_where[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_where[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'where';
+ }
+
+ }
+
+ return $this;
+ }
+
+}
+
+/* End of file pdo_pgsql_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
new file mode 100644
index 000000000..bf0363f63
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
@@ -0,0 +1,167 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO SQLite Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_sqlite_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'sqlite';
+
+ /**
+ * 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 $_random_keyword = ' RANDOM()'; // Currently not supported
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'sqlite:';
+
+ if (empty($this->database) && empty($this->hostname))
+ {
+ $this->database = ':memory:';
+ }
+
+ $this->database = empty($this->database) ? $this->hostname : $this->database;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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 "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'';
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ return $sql.' AND "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 = '')
+ {
+ // Not supported
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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)
+ {
+ return 'SELECT * FROM '.$this->protect_identifiers($table).' LIMIT 0,1';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Replace statement
+ *
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
+ */
+ protected function _replace($table, $keys, $values)
+ {
+ return 'INSERT OR '.parent::_replace($table, $keys, $values);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate statement
+ *
+ * Generates a platform-specific truncate string from the supplied data
+ *
+ * If the database does not support the truncate() command,
+ * then this method maps to 'DELETE FROM table'
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _truncate($table)
+ {
+ return 'DELETE FROM '.$table;
+ }
+
+}
+
+/* End of file pdo_sqlite_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
new file mode 100644
index 000000000..f125b8f50
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
@@ -0,0 +1,299 @@
+<?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.0
+ * @filesource
+ */
+
+/**
+ * PDO SQLSRV Database Adapter Class
+ *
+ * Note: _DB is an extender class that the app controller
+ * creates dynamically based on whether the query builder
+ * 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_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
+
+ public $subdriver = 'sqlsrv';
+
+ protected $_random_keyword = ' NEWID()';
+
+ protected $_quoted_identifier;
+
+ /**
+ * Constructor
+ *
+ * Builds the DSN if not already set.
+ *
+ * @param array
+ * @return void
+ */
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if (empty($this->dsn))
+ {
+ $this->dsn = 'sqlsrv:Server='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
+
+ empty($this->port) OR $this->dsn .= ','.$this->port;
+ empty($this->database) OR $this->dsn .= ';Database='.$this->database;
+
+ // Some custom options
+
+ if (isset($this->QuotedId))
+ {
+ $this->dsn .= ';QuotedId='.$this->QuotedId;
+ $this->_quoted_identifier = (bool) $this->QuotedId;
+ }
+
+ if (isset($this->ConnectionPooling))
+ {
+ $this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling;
+ }
+
+ if (isset($this->Encrypt))
+ {
+ $this->dsn .= ';Encrypt='.$this->Encrypt;
+ }
+
+ if (isset($this->TraceOn))
+ {
+ $this->dsn .= ';TraceOn='.$this->TraceOn;
+ }
+
+ if (isset($this->TrustServerCertificate))
+ {
+ $this->dsn .= ';TrustServerCertificate='.$this->TrustServerCertificate;
+ }
+
+ empty($this->APP) OR $this->dsn .= ';APP='.$this->APP;
+ empty($this->Failover_Partner) OR $this->dsn .= ';Failover_Partner='.$this->Failover_Partner;
+ empty($this->LoginTimeout) OR $this->dsn .= ';LoginTimeout='.$this->LoginTimeout;
+ empty($this->MultipleActiveResultSets) OR $this->dsn .= ';MultipleActiveResultSets='.$this->MultipleActiveResultSets;
+ empty($this->TraceFile) OR $this->dsn .= ';TraceFile='.$this->TraceFile;
+ empty($this->WSID) OR $this->dsn .= ';WSID='.$this->WSID;
+ }
+ elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match))
+ {
+ $this->_quoted_identifier = (bool) $match[1];
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Non-persistent database connection
+ *
+ * @param bool
+ * @return object
+ */
+ public function db_connect($persistent = FALSE)
+ {
+ if ( ! empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set))
+ {
+ $this->options[PDO::SQLSRV_ENCODING_UTF8] = 1;
+ }
+
+ $this->conn_id = parent::db_connect($persistent);
+
+ if ( ! is_object($this->conn_id) OR is_bool($this->_quoted_identifier))
+ {
+ return $this->conn_id;
+ }
+
+ // Determine how identifiers are escaped
+ $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
+ $query = $query->row_array();
+ $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
+ $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
+
+ return $this->conn_id;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show 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)
+ {
+ return 'SELECT '.$this->escape_identifiers('name')
+ .' FROM '.$this->escape_identifiers('sysobjects')
+ .' WHERE '.$this->escape_identifiers('type')." = 'U'";
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ }
+
+ return $sql.' ORDER BY '.$this->escape_identifiers('name');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 '.$this->escape_identifiers('column_name')
+ .' FROM '.$this->escape_identifiers('information_schema.columns')
+ .' WHERE '.$this->escape_identifiers('table_name').' = '.$this->escape($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From Tables
+ *
+ * This 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)
+ {
+ return is_array($tables) ? implode(', ', $tables) : $tables;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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 (ignored)
+ * @param array the limit clause (ignored)
+ * @param array the like clause
+ * @return string
+ */
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ {
+ foreach ($values as $key => $val)
+ {
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
+
+ if ( ! empty($like))
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
+ }
+
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @param string the table name
+ * @param array the where clause
+ * @param array the like clause
+ * @param string the limit clause
+ * @return string
+ */
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ {
+ $conditions = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
+
+ return ($limit)
+ ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete'
+ : '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)
+ {
+ // As of SQL Server 2012 (11.0.*) OFFSET is supported
+ if (version_compare($this->version(), '11', '>='))
+ {
+ return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
+ }
+
+ $limit = $offset + $limit;
+
+ // An ORDER BY clause is required for ROW_NUMBER() to work
+ if ($offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
+
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
+ }
+
+}
+
+/* End of file pdo_sqlsrv_driver.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php */
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 17bd37b38..1d6e9567a 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -44,16 +44,6 @@ class CI_DB_postgre_driver extends CI_DB {
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
/**
@@ -138,7 +128,15 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @pg_pconnect($this->dsn);
+ $conn = @pg_pconnect($this->dsn);
+ if ($conn && pg_connection_status($conn) === PGSQL_CONNECTION_BAD)
+ {
+ if (pg_ping($conn) === FALSE)
+ {
+ return FALSE;
+ }
+ }
+ return $conn;
}
// --------------------------------------------------------------------
@@ -356,13 +354,13 @@ class CI_DB_postgre_driver extends CI_DB {
$table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
- if ($table == NULL && $v >= '8.1')
+ if ($table === NULL && $v >= '8.1')
{
$sql = 'SELECT LASTVAL() AS ins_id';
}
- elseif ($table != NULL)
+ elseif ($table !== NULL)
{
- if ($column != NULL && $v >= '8.0')
+ if ($column !== NULL && $v >= '8.0')
{
$sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq";
$query = $this->query($sql);
@@ -390,35 +388,6 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $query = $query->row();
- $this->_reset_select();
- return (int) $query->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -428,11 +397,13 @@ class CI_DB_postgre_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
+ $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'public\'';
- if ($prefix_limit !== FALSE && $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
- return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql.' AND "table_name" LIKE \''
+ .$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
@@ -450,7 +421,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
protected function _list_columns($table = '')
{
- return "SELECT column_name FROM information_schema.columns WHERE table_name = '".$table."'";
+ return 'SELECT "column_name" FROM "information_schema"."columns" WHERE "table_name" = '.$this->escape($table);
}
// --------------------------------------------------------------------
@@ -496,12 +467,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
protected function _from_tables($tables)
{
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return implode(', ', $tables);
+ return is_array($tables) ? implode(', ', $tables) : $tables;
}
// --------------------------------------------------------------------
@@ -539,6 +505,47 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ protected function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ foreach ($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach (array_keys($val) as $field)
+ {
+ if ($field !== $index)
+ {
+ $final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k.' = (CASE '.$index."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
+
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
@@ -573,7 +580,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- return $sql.' LIMIT '.$limit.($offset == 0 ? '' : ' OFFSET '.$offset);
+ return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : '');
}
// --------------------------------------------------------------------
@@ -586,27 +593,31 @@ class CI_DB_postgre_driver extends CI_DB {
* @param mixed
* @param mixed
* @param string
+ * @param mixed
* @return object
- *
*/
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{
- $type = $this->_group_get_type($type);
-
if ( ! is_array($key))
{
$key = array($key => $value);
}
// If the escape value was not set will will base it on the global setting
- if ( ! is_bool($escape))
- {
- $escape = $this->_protect_identifiers;
- }
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
foreach ($key as $k => $v)
{
- $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
+ ? $this->_group_get_type('')
+ : $this->_group_get_type($type);
+
+ if ($escape === TRUE)
+ {
+ $k = (($op = $this->_get_operator($k)) !== FALSE)
+ ? $this->escape_identifiers(trim(substr($k, 0, strpos($k, $op)))).' '.strstr($k, $op)
+ : $this->escape_identifiers(trim($k));
+ }
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -618,7 +629,6 @@ class CI_DB_postgre_driver extends CI_DB {
{
if ($escape === TRUE)
{
- $k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
elseif (is_bool($v))
@@ -631,10 +641,6 @@ class CI_DB_postgre_driver extends CI_DB {
$k .= ' = ';
}
}
- else
- {
- $k = $this->protect_identifiers($k, FALSE, $escape);
- }
$this->qb_where[] = $prefix.$k.$v;
if ($this->qb_caching === TRUE)
@@ -653,12 +659,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @pg_close($conn_id);
+ @pg_close($this->conn_id);
}
}
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 94c97af50..c434e9510 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -58,7 +58,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
}
else
{
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field);
$attributes = array_change_key_case($attributes, CASE_UPPER);
$is_unsigned = ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE);
@@ -107,10 +107,19 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= '('.$attributes['CONSTRAINT'].')';
}
- $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
- .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- // Added new attribute to create unqite fields. Also works with MySQL
- .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ // Added new attribute to create unique fields. Also works with MySQL
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $sql .= ' UNIQUE';
+ }
}
// don't add a comma on the end of the last field
@@ -139,26 +148,17 @@ class CI_DB_postgre_forge extends CI_DB_forge {
{
$sql = 'CREATE TABLE ';
- if ($if_not_exists === TRUE)
+ // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
+ if ($if_not_exists === TRUE && $this->db->table_exists($table))
{
- // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
- if ($this->db->table_exists($table))
- {
- return TRUE;
- }
+ return TRUE;
}
$sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
if (count($primary_keys) > 0)
{
- // 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);
- }
-
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
$sql .= "\n);";
@@ -167,18 +167,14 @@ class CI_DB_postgre_forge extends CI_DB_forge {
{
foreach ($keys as $key)
{
- if (is_array($key))
- {
- $key = $this->db->protect_identifiers($key);
- }
- else
- {
- $key = array($this->db->protect_identifiers($key));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
foreach ($key as $field)
{
- $sql .= 'CREATE INDEX '.$table.'_'.str_replace(array('"', "'"), '', $field).'_index ON '.$table.' ('.$field.'); ';
+ $sql .= "\nCREATE INDEX ".$this->db->escape_identifiers($table.'_'.str_replace(array('"', "'"), '', $field).'_index')
+ .' ON '.$this->db->escape_identifiers($table).' ('.$this->db->escape_identifiers($field).');';
}
}
}
@@ -205,16 +201,16 @@ class CI_DB_postgre_forge extends CI_DB_forge {
*/
protected function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
+ $sql = 'ALTER TABLE '.$this->db->escape_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->escape_identifiers($fields);
}
return $sql.$this->_process_fields($fields)
- .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index f913bc9eb..eb9d647e7 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.3
*/
class CI_DB_postgre_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*/
public function num_rows()
{
- return @pg_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = @pg_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -156,11 +159,12 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return pg_fetch_object($this->result_id);
+ return pg_fetch_object($this->result_id, NULL, $class_name);
}
}
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 551704f83..2744a63cf 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -43,18 +43,8 @@ class CI_DB_sqlite_driver extends CI_DB {
public $dbdriver = 'sqlite';
// The character used to escape with - not needed for SQLite
- protected $_escape_char = '';
+ 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
/**
@@ -127,7 +117,9 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
protected function _execute($sql)
{
- return @sqlite_query($this->conn_id, $sql);
+ return $this->is_write_type($sql)
+ ? @sqlite_exec($this->conn_id, $sql)
+ : @sqlite_query($this->conn_id, $sql);
}
// --------------------------------------------------------------------
@@ -139,13 +131,8 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
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;
}
@@ -153,7 +140,7 @@ class CI_DB_sqlite_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('BEGIN TRANSACTION');
return TRUE;
@@ -168,13 +155,8 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
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;
}
@@ -192,13 +174,8 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
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;
}
@@ -268,35 +245,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return string
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -306,12 +254,13 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SELECT name from sqlite_master WHERE type='table'";
+ $sql = "SELECT name FROM sqlite_master WHERE type='table'";
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
+
return $sql;
}
@@ -343,7 +292,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return "SELECT * FROM ".$table." LIMIT 1";
+ return 'SELECT * FROM '.$this->escape_identifiers($table).' LIMIT 1';
}
// --------------------------------------------------------------------
@@ -366,27 +315,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * From Tables
- *
- * This 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);
- }
-
- return '('.implode(', ', $tables).')';
- }
-
- // --------------------------------------------------------------------
-
- /**
* Replace statement
*
* Generates a platform-specific replace string from the supplied data
@@ -422,43 +350,16 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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)
- {
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
-
- return $sql."LIMIT ".$offset.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @sqlite_close($conn_id);
+ @sqlite_close($this->conn_id);
}
}
/* End of file sqlite_driver.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
+/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index dd6f0f78d..e02e327f3 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -61,6 +61,14 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
{
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
@@ -97,41 +105,31 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
+ empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $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 .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -146,30 +144,22 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
- $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -191,40 +181,21 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
*/
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);
-
- // DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ /* SQLite only supports adding new columns and it does
+ * NOT support the AFTER statement. Each new column will
+ * be added as the last one in the table.
+ */
+ if ($alter_type !== 'ADD COLUMN')
{
- // SQLite does not support dropping columns
- // http://www.sqlite.org/omitted.html
- // http://www.sqlite.org/faq.html#q11
+ // Not supported
return FALSE;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
+ .' '.$column_definition
+ .($default_value != '' ? " DEFAULT '".$default_value."'" : '')
+ // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
+ .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
}
}
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 741dc9d8d..eef9787a1 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.3
*/
class CI_DB_sqlite_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*/
public function num_rows()
{
- return @sqlite_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = @sqlite_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -140,17 +143,12 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- if (function_exists('sqlite_fetch_object'))
- {
- return sqlite_fetch_object($this->result_id);
- }
-
- $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
- return is_array($arr) ? (object) $arr : FALSE;
+ return sqlite_fetch_object($this->result_id, $class_name);
}
}
diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index d22f6a442..d03be15f5 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -46,16 +46,6 @@ class CI_DB_sqlite3_driver extends CI_DB {
// The character used for escaping
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()';
/**
@@ -87,7 +77,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
public function db_pconnect()
{
log_message('debug', 'SQLite3 doesn\'t support persistent connections');
- return $this->db_pconnect();
+ return $this->db_connect();
}
// --------------------------------------------------------------------
@@ -104,7 +94,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
return $this->data_cache['version'];
}
- $version = $this->conn_id->version();
+ $version = SQLite3::version();
return $this->data_cache['version'] = $version['versionString'];
}
@@ -245,30 +235,6 @@ class CI_DB_sqlite3_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $result = $this->conn_id->querySingle($this->_count_string.$this->protect_identifiers('numrows')
- .' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
-
- return empty($result) ? 0 : (int) $result;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -318,46 +284,16 @@ class CI_DB_sqlite3_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @return string
- */
- protected function _error_message()
- {
- return $this->conn_id->lastErrorMsg();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The error message number
+ * Returns an array containing code and message of the last
+ * database error that has occured.
*
- * @return int
+ * @return array
*/
- protected function _error_number()
+ public function error()
{
- return $this->conn_id->lastErrorCode();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * From Tables
- *
- * This function implicitly groups FROM tables so there is no confusion
- * about operator precedence in harmony with SQL standards
- *
- * @param string
- * @return string
- */
- protected function _from_tables($tables)
- {
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return '('.implode(', ', $tables).')';
+ return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg());
}
// --------------------------------------------------------------------
@@ -398,29 +334,11 @@ class CI_DB_sqlite3_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * 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)
- {
- return $sql.' LIMIT '.($offset ? $offset.',' : '').$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Close DB Connection
*
- * @param object (ignored)
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
$this->conn_id->close();
}
diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php
index 20f1e6f63..f9ae5bcce 100644
--- a/system/database/drivers/sqlite3/sqlite3_forge.php
+++ b/system/database/drivers/sqlite3/sqlite3_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,6 +66,14 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
{
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
@@ -111,13 +119,27 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field)
- .' '.$attributes['TYPE']
- .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
- .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
- .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
+
+ empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
+
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
+ {
+ $sql .= ' UNSIGNED';
+ }
+
+ if (isset($attributes['DEFAULT']))
+ {
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
+ }
+
+ $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
+
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' AUTO_INCREMENT';
+ }
}
// don't add a comma on the end of the last field
@@ -129,22 +151,16 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
}
@@ -182,9 +198,9 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
return FALSE;
}
- return 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name)
+ return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
.' '.$column_definition
- .($default_value != '' ? ' DEFAULT '.$default_value : '')
+ .($default_value !== '' ? ' DEFAULT '.$default_value : '')
// If NOT NULL is specified, the field must have a DEFAULT value other than NULL
.(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
}
diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php
index d83d6b2cd..117fb3ce8 100644
--- a/system/database/drivers/sqlite3/sqlite3_result.php
+++ b/system/database/drivers/sqlite3/sqlite3_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
*
@@ -26,40 +26,21 @@
*/
/**
- * SQLite Result Class
+ * SQLite3 Result Class
*
* This class extends the parent result class: CI_DB_result
*
* @category Database
- * @author Andrey Andreev
- * @link http://codeigniter.com/user_guide/database/
+ * @author Andrey Andreev
+ * @link http://codeigniter.com/user_guide/database/
+ * @since 3.0
*/
class CI_DB_sqlite3_result extends CI_DB_result {
- // Overwriting the parent here, so we have a way to know if it's already set
- public $num_rows;
-
// num_fields() might be called multiple times, so we'll use this one to cache it's result
protected $_num_fields;
/**
- * Number of rows in the result set
- *
- * @return int
- */
- public function num_rows()
- {
- /* The SQLite3 driver doesn't have a graceful way to do this,
- * so we'll have to do it on our own.
- */
- return is_int($this->num_rows)
- ? $this->num_rows
- : $this->num_rows = count($this->result_array());
- }
-
- // --------------------------------------------------------------------
-
- /**
* Number of fields in the result set
*
* @return int
@@ -153,443 +134,28 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
- {
- // No native support for fetching as an object
- $row = $this->_fetch_assoc();
- return ($row !== FALSE) ? (object) $row : FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Query result. "array" version.
- *
- * return array
- */
- public function result_array()
- {
- if (count($this->result_array) > 0)
- {
- return $this->result_array;
- }
- elseif (is_array($this->row_data))
- {
- if (count($this->row_data) === 0)
- {
- return $this->result_array;
- }
- else
- {
- $row_index = count($this->row_data);
- }
- }
- else
- {
- $row_index = 0;
- $this->row_data = array();
- }
-
- $row = NULL;
- while ($row = $this->_fetch_assoc())
- {
- $this->row_data[$row_index++] = $row;
- }
-
- return $this->result_array = $this->row_data;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Query result. "object" version.
- *
- * @return array
- */
- public function result_object()
- {
- if (count($this->result_object) > 0)
- {
- return $this->result_object;
- }
- elseif (count($this->result_array) > 0)
- {
- for ($i = 0, $c = count($this->result_array); $i < $c; $i++)
- {
- $this->result_object[] = (object) $this->result_array[$i];
- }
-
- return $this->result_object;
- }
- elseif (is_array($this->row_data))
- {
- if (count($this->row_data) === 0)
- {
- return $this->result_object;
- }
- else
- {
- $row_index = count($this->row_data);
- for ($i = 0; $i < $row_index; $i++)
- {
- $this->result_object[$i] = (object) $this->row_data[$i];
- }
- }
- }
- else
- {
- $row_index = 0;
- $this->row_data = array();
- }
-
- $row = NULL;
- while ($row = $this->_fetch_assoc())
- {
- $this->row_data[$row_index] = $row;
- $this->result_object[$row_index++] = (object) $row;
- }
-
- $this->result_array = $this->row_data;
-
- /* As described for the num_rows() method - there's no easy
- * way to get the number of rows selected. Our work-around
- * solution (as in here as well) first checks if result_array
- * exists and returns its count. It doesn't however check for
- * custom_object_result, so - do it here.
- */
- if ( ! is_int($this->num_rows))
- {
- $this->num_rows = count($this->result_object);
- }
-
- return $this->result_object;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Query result. Custom object version.
- *
- * @param string class name used to instantiate rows to
- * @return array
- */
- public function custom_result_object($class_name)
- {
- if (array_key_exists($class_name, $this->custom_result_object))
- {
- return $this->custom_result_object[$class_name];
- }
-
- if ( ! class_exists($class_name) OR ! is_object($this->result_id) OR $this->num_rows() === 0)
- {
- return array();
- }
-
- /* Even if result_array hasn't been set prior to custom_result_object being called,
- * num_rows() has done it.
- */
- $data = &$this->result_array;
-
- $result_object = array();
- for ($i = 0, $c = count($data); $i < $c; $i++)
- {
- $result_object[$i] = new $class_name();
- foreach ($data[$i] as $key => $value)
- {
- $result_object[$i]->$key = $value;
- }
- }
-
- /* As described for the num_rows() method - there's no easy
- * way to get the number of rows selected. Our work-around
- * solution (as in here as well) first checks if result_array
- * exists and returns its count. It doesn't however check for
- * custom_object_result, so - do it here.
- */
- if ( ! is_int($this->num_rows))
- {
- $this->num_rows = count($result_object);
- }
-
- // Cache and return the array
- return $this->custom_result_object[$class_name] = $result_object;
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result.
- *
- * Acts as a wrapper for row_object(), row_array()
- * and custom_row_object(). Also used by first_row(), next_row()
- * and previous_row().
- *
- * @param int row index
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function row($n = 0, $type = 'object')
- {
- if ($type === 'object')
- {
- return $this->row_object($n);
- }
- elseif ($type === 'array')
- {
- return $this->row_array($n);
- }
-
- return $this->custom_row_object($n, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Array version.
- *
- * @param int row index
- * @return array
- */
- public function row_array($n = 0)
- {
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
-
- /* If row_data is initialized, it means that we've already tried
- * (at least) to fetch some data, so ... check if we already have
- * this row.
- */
- if (is_array($this->row_data))
- {
- /* If we already have row_data[$n] - return it.
- *
- * If we enter the elseif, there's a number of reasons to
- * return an empty array:
- *
- * - count($this->row_data) === 0 means there are no results
- * - num_rows being set or result_array having count() > 0 means
- * that we've already fetched all data and $n is greater than
- * our highest row index available
- * - $n < $this->current_row means that if such row existed,
- * we would've already returned it, therefore $n is an
- * invalid index
- */
- if (isset($this->row_data[$n])) // We already have this row
- {
- $this->current_row = $n;
- return $this->row_data[$n];
- }
- elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
- OR count($this->result_array) > 0 OR $n < $this->current_row)
- {
- // No such row exists
- return array();
- }
-
- // Get the next row index that would actually need to be fetched
- $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
- }
- else
- {
- $current_row = $this->current_row = 0;
- $this->row_data = array();
- }
-
- /* Fetch more data, if available
- *
- * NOTE: Operator precedence is important here, if you change
- * 'AND' with '&&' - it WILL BREAK the results, as
- * $row will be assigned the scalar value of both
- * expressions!
- */
- while ($row = $this->_fetch_assoc() AND $current_row <= $n)
- {
- $this->row_data[$current_row++] = $row;
- }
-
- // This would mean that there's no (more) data to fetch
- if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
- {
- // Cache what we already have
- if (is_array($this->row_data))
- {
- $this->num_rows = count($this->row_data);
- /* Usually, row_data could have less elements than result_array,
- * but at this point - they should be exactly the same.
- */
- $this->result_array = $this->row_data;
- }
- else
- {
- $this->num_rows = 0;
- }
-
- return array();
- }
-
- $this->current_row = $n;
- return $this->row_data[$n];
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Object version.
- *
- * @param int row index
- * @return mixed object if row found; empty array if not
- */
- public function row_object($n = 0)
+ protected function _fetch_object($class_name = 'stdClass')
{
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
-
- /* Logic here is exactly the same as in row_array,
- * except we have to cast row_data[$n] to an object.
- *
- * If we already have result_object though - we can
- * directly return from it.
- */
- if (isset($this->result_object[$n]))
+ // No native support for fetching rows as objects
+ if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
{
- $this->current_row = $n;
- return $this->result_object[$n];
+ return FALSE;
}
-
- $row = $this->row_array($n);
- // Cast only if the row exists
- if (count($row) > 0)
+ elseif ($class_name === 'stdClass')
{
- $this->current_row = $n;
return (object) $row;
}
- return array();
- }
-
- // --------------------------------------------------------------------
-
- /* Single row result. Custom object version.
- *
- * @param int row index
- * @param string custom class name
- * @return mixed custom object if row found; empty array otherwise
- */
- public function custom_row_object($n = 0, $class_name)
- {
- // Make sure $n is not a string
- if ( ! is_int($n))
- {
- $n = (int) $n;
- }
-
- if (array_key_exists($class_name, $this->custom_result_object))
- {
- /* We already have a the whole result set with this class_name,
- * return the specified row if it exists, and an empty array if
- * it doesn't.
- */
- if (isset($this->custom_result_object[$class_name][$n]))
- {
- $this->current_row = $n;
- return $this->custom_result_object[$class_name][$n];
- }
- else
- {
- return array();
- }
- }
- elseif ( ! class_exists($class_name)) // No such class exists
- {
- return array();
- }
-
- $row = $this->row_array($n);
- // An array would mean that the row doesn't exist
- if (is_array($row))
- {
- return $row;
- }
-
- // Convert to the desired class and return
- $row_object = new $class_name();
- foreach ($row as $key => $value)
- {
- $row_object->$key = $value;
- }
-
- $this->current_row = $n;
- return $row_object;
- }
-
- // --------------------------------------------------------------------
-
- /* First row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function first_row($type = 'object')
- {
- return $this->row(0, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Last row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function last_row($type = 'object')
- {
- $result = &$this->result($type);
- if ( ! isset($this->num_rows))
- {
- $this->num_rows = count($result);
- }
- $this->current_row = $this->num_rows - 1;
- return $result[$this->current_row];
- }
-
- // --------------------------------------------------------------------
-
- /* Next row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function next_row($type = 'object')
- {
- if (is_array($this->row_data))
- {
- $count = count($this->row_data);
- $n = ($this->current_row > $count OR ($this->current_row === 0 && $count === 0)) ? $count : $this->current_row + 1;
- }
- else
+ $class_name = new $class_name();
+ foreach (array_keys($row) as $key)
{
- $n = 0;
+ $class_name->$key = $row[$key];
}
- return $this->row($n, $type);
- }
-
- // --------------------------------------------------------------------
-
- /* Previous row result.
- *
- * @param string ('object', 'array' or a custom class name)
- * @return mixed whatever was passed to the second parameter
- */
- public function previous_row($type = 'object')
- {
- $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
- return $this->row($n, $type);
+ return $class_name;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php
index 965c838e5..f58c3d168 100644
--- a/system/database/drivers/sqlite3/sqlite3_utility.php
+++ b/system/database/drivers/sqlite3/sqlite3_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
*
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 8cc500f55..abcaf4577 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -21,7 +21,7 @@
* @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 1.0
+ * @since Version 2.0.3
* @filesource
*/
@@ -43,19 +43,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
public $dbdriver = 'sqlsrv';
// The character used for escaping
- protected $_escape_char = '';
+ protected $_escape_char = '"';
- // clause and character used for LIKE escape sequences
- protected $_like_escape_str = " ESCAPE '%s' ";
- protected $_like_escape_chr = '!';
+ protected $_random_keyword = ' NEWID()';
- /**
- * 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 = ' NEWID()'; // not currently supported
+ // SQLSRV-specific properties
+ protected $_quoted_identifier = TRUE;
/**
* Non-persistent database connection
@@ -83,7 +76,15 @@ class CI_DB_sqlsrv_driver extends CI_DB {
unset($connection['UID'], $connection['PWD']);
}
- return sqlsrv_connect($this->hostname, $connection);
+ $this->conn_id = sqlsrv_connect($this->hostname, $connection);
+
+ // Determine how identifiers are escaped
+ $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
+ $query = $query->row_array();
+ $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
+ $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
+
+ return $this->conn_id;
}
// --------------------------------------------------------------------
@@ -132,11 +133,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _execute($sql)
{
- return sqlsrv_query($this->conn_id,
- $sql,
- NULL,
- array('Scrollable'=> SQLSRV_CURSOR_STATIC, 'SendStreamParamsAtExec' => TRUE)
- );
+ return ($this->is_write_type($sql) && stripos($sql, 'INSERT') === FALSE)
+ ? sqlsrv_query($this->conn_id, $sql)
+ : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => SQLSRV_CURSOR_STATIC));
}
// --------------------------------------------------------------------
@@ -148,13 +147,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
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;
}
@@ -162,7 +156,7 @@ class CI_DB_sqlsrv_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 sqlsrv_begin_transaction($this->conn_id);
}
@@ -176,13 +170,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
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;
}
@@ -199,13 +188,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
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;
}
@@ -237,7 +221,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
public function affected_rows()
{
- return @sqlrv_rows_affected($this->conn_id);
+ return sqlsrv_rows_affected($this->result_id);
}
// --------------------------------------------------------------------
@@ -281,35 +265,6 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * "Count All" query
- *
- * Generates a platform-specific query string that counts all records in
- * the specified database
- *
- * @param string
- * @return int
- */
- public function count_all($table = '')
- {
- if ($table == '')
- {
- return 0;
- }
-
- $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
- if ($query->num_rows() == 0)
- {
- return 0;
- }
-
- $row = $query->row();
- $this->_reset_select();
- return (int) $row->numrows;
- }
-
- // --------------------------------------------------------------------
-
- /**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
@@ -319,7 +274,17 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _list_tables($prefix_limit = FALSE)
{
- return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
+ $sql = 'SELECT '.$this->escape_identifiers('name')
+ .' FROM '.$this->escape_identifiers('sysobjects')
+ .' WHERE '.$this->escape_identifiers('type')." = 'U'";
+
+ if ($prefix_limit === TRUE && $this->dbprefix !== '')
+ {
+ $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_escape_like_str, $this->_escape_like_chr);
+ }
+
+ return $sql.' ORDER BY '.$this->escape_identifiers('name');
}
// --------------------------------------------------------------------
@@ -349,7 +314,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return 'SELECT TOP 1 * FROM '.$table;
+ return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -403,12 +368,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _from_tables($tables)
{
- if ( ! is_array($tables))
- {
- $tables = array($tables);
- }
-
- return implode(', ', $tables);
+ return is_array($tables) ? implode(', ', $tables) : $tables;
}
// --------------------------------------------------------------------
@@ -428,7 +388,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key.' = '.$val;
}
@@ -502,7 +462,29 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
+ // As of SQL Server 2012 (11.0.*) OFFSET is supported
+ if (version_compare($this->version(), '11', '>='))
+ {
+ return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
+ }
+
+ $limit = $offset + $limit;
+
+ // An ORDER BY clause is required for ROW_NUMBER() to work
+ if ($offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
+
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
// --------------------------------------------------------------------
@@ -510,15 +492,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
* @return void
*/
- protected function _close($conn_id)
+ protected function _close()
{
- @sqlsrv_close($conn_id);
+ @sqlsrv_close($this->conn_id);
}
}
/* End of file sqlsrv_driver.php */
-/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index e9143b269..ccdb36929 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -21,7 +21,7 @@
* @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 1.0
+ * @since Version 2.0.3
* @filesource
*/
@@ -44,20 +44,17 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
* @param mixed primary key(s)
* @param mixed key(s)
* @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @return string
*/
protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
- $sql = 'CREATE TABLE ';
+ $sql = ($if_not_exists === TRUE)
+ ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
+ : '';
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
+ $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
- $sql .= $this->db->escape_identifiers($table).' (';
$current_field_count = 0;
-
foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
@@ -65,41 +62,33 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->protect_identifiers($field);
+ $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
+ if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
- if (array_key_exists('DEFAULT', $attributes))
+ if (isset($attributes['DEFAULT']))
{
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
+ $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= ( ! empty($attributes['NULL']) && $attribues['NULL'] === TRUE)
+ ? ' NULL' : ' NOT NULL';
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
@@ -114,30 +103,22 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($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));
- }
+ $key = is_array($key)
+ ? $this->db->escape_identifiers($key)
+ : array($this->escape_identifiers($key));
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -159,37 +140,18 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/
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 = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index 0802677fc..fb7a68647 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -33,6 +33,7 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 2.0.3
*/
class CI_DB_sqlsrv_result extends CI_DB_result {
@@ -43,7 +44,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*/
public function num_rows()
{
- return @sqlsrv_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = @sqlsrv_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -92,12 +95,12 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
$retval = array();
foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
- $F = new stdClass();
- $F->name = $field['Name'];
- $F->type = $field['Type'];
+ $F = new stdClass();
+ $F->name = $field['Name'];
+ $F->type = $field['Type'];
$F->max_length = $field['Size'];
$F->primary_key = 0;
- $F->default = '';
+ $F->default = '';
$retval[] = $F;
}
@@ -142,11 +145,12 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return sqlsrv_fetch_object($this->result_id);
+ return sqlsrv_fetch_object($this->result_id, $class_name);
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index 394964b6a..d518cc15a 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -21,7 +21,7 @@
* @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 1.0
+ * @since Version 2.0.3
* @filesource
*/
@@ -41,7 +41,7 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
* SQLSRV Export
*
* @param array Preferences
- * @return mixed
+ * @return bool
*/
protected function _backup($params = array())
{
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index 6a7c8e3c7..ed2fe3c4a 100644
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -43,16 +43,16 @@ if ( ! function_exists('element'))
* Element
*
* 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.)
+ * If the element is empty it returns NULL (or whatever you specify as the default value.)
*
* @param string
* @param array
* @param mixed
* @return mixed depends on what the array contains
*/
- function element($item, $array, $default = FALSE)
+ function element($item, $array, $default = NULL)
{
- return empty($array[$item]) ? $default : $array[$item];
+ return array_key_exists($item, $array) ? $array[$item] : $default;
}
}
@@ -87,7 +87,7 @@ if ( ! function_exists('elements'))
* @param mixed
* @return mixed depends on what the array contains
*/
- function elements($items, $array, $default = FALSE)
+ function elements($items, $array, $default = NULL)
{
$return = array();
@@ -95,7 +95,7 @@ if ( ! function_exists('elements'))
foreach ($items as $item)
{
- $return[$item] = isset($array[$item]) ? $array[$item] : $default;
+ $return[$item] = array_key_exists($item, $array) ? $array[$item] : $default;
}
return $return;
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index b11670658..3aac14db8 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -32,7 +32,7 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
+ * @link http://codeigniter.com/user_guide/helpers/captcha_helper.html
*/
// ------------------------------------------------------------------------
@@ -64,7 +64,7 @@ if ( ! function_exists('create_captcha'))
}
}
- if ($img_path == '' OR $img_url == ''
+ if ($img_path === '' OR $img_url === ''
OR ! @is_dir($img_path) OR ! is_writeable($img_path)
OR ! extension_loaded('gd'))
{
@@ -80,8 +80,7 @@ if ( ! function_exists('create_captcha'))
$current_dir = @opendir($img_path);
while ($filename = @readdir($current_dir))
{
- if ($filename !== '.' && $filename !== '..' && $filename !== 'index.html'
- && (str_replace('.jpg', '', $filename) + $expiration) < $now)
+ if (substr($filename, -4) === '.jpg' && (str_replace('.jpg', '', $filename) + $expiration) < $now)
{
@unlink($img_path.$filename);
}
@@ -93,7 +92,7 @@ if ( ! function_exists('create_captcha'))
// Do we have a "word" yet?
// -----------------------------------
- if ($word == '')
+ if ($word === '')
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$word = '';
@@ -156,7 +155,7 @@ if ( ! function_exists('create_captcha'))
// Write the text
// -----------------------------------
- $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext'));
+ $use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext'));
if ($use_font === FALSE)
{
$font_size = 5;
@@ -186,7 +185,6 @@ if ( ! function_exists('create_captcha'))
}
}
-
// Create the border
imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index b4517d02e..955d74542 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -42,29 +42,28 @@ if ( ! function_exists('now'))
/**
* Get "now" time
*
- * Returns time() or its GMT equivalent based on the config file preference
+ * Returns time() based on the timezone parameter or on the
+ * "time_reference" setting
*
+ * @param string
* @return int
*/
- function now()
+ function now($timezone = NULL)
{
- $CI =& get_instance();
-
- if (strtolower($CI->config->item('time_reference')) == 'gmt')
+ if (empty($timezone))
{
- $now = time();
- $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
-
- if (strlen($system_time) < 10)
- {
- $system_time = time();
- log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.');
- }
+ $timezone = config_item('time_reference');
+ }
- return $system_time;
+ if ($timezone === 'local' OR $timezone === date_default_timezone_get())
+ {
+ return time();
}
- return time();
+ $datetime = new DateTime('now', new DateTimeZone($timezone));
+ sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second);
+
+ return mktime($hour, $minute, $second, $month, $day, $year);
}
}
@@ -90,12 +89,14 @@ if ( ! function_exists('mdate'))
*/
function mdate($datestr = '', $time = '')
{
- if ($datestr == '')
+ if ($datestr === '')
{
return '';
}
-
- $time = ($time == '') ? now() : $time;
+ elseif (empty($time))
+ {
+ $time = now();
+ }
$datestr = str_replace(
'%\\',
@@ -116,31 +117,37 @@ if ( ! function_exists('standard_date'))
*
* Returns a date formatted according to the submitted standard.
*
+ * As of PHP 5.2, the DateTime extension provides constants that
+ * serve for the exact same purpose and are used with date().
+ * Due to that, this function is DEPRECATED and should be removed
+ * in CodeIgniter 3.1+.
+ *
+ * Here are two examples of how you should replace it:
+ *
+ * date(DATE_RFC822, now()); // default
+ * date(DATE_W3C, $time); // a different format and time
+ *
+ * Reference: http://www.php.net/manual/en/class.datetime.php#datetime.constants.types
+ *
+ * @deprecated
* @param string the chosen format
* @param int Unix timestamp
* @return string
*/
- function standard_date($fmt = 'DATE_RFC822', $time = '')
+ function standard_date($fmt = 'DATE_RFC822', $time = NULL)
{
- $formats = array(
- '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%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%O'
- );
-
- if ( ! isset($formats[$fmt]))
+ if (empty($time))
+ {
+ $time = now();
+ }
+
+ // Procedural style pre-defined constants from the DateTime extension
+ if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === FALSE)
{
return FALSE;
}
- return mdate($formats[$fmt], $time);
+ return date(constant($fmt), $time);
}
}
@@ -164,20 +171,9 @@ if ( ! function_exists('timespan'))
$CI =& get_instance();
$CI->lang->load('date');
- if ( ! is_numeric($seconds))
- {
- $seconds = 1;
- }
-
- if ( ! is_numeric($time))
- {
- $time = time();
- }
-
- if ( ! is_numeric($units))
- {
- $units = 7;
- }
+ is_numeric($seconds) OR $seconds = 1;
+ is_numeric($time) OR $time = time();
+ is_numeric($units) OR $units = 7;
$seconds = ($time <= $seconds) ? 1 : $time - $seconds;
@@ -186,7 +182,7 @@ if ( ! function_exists('timespan'))
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;
@@ -196,7 +192,7 @@ if ( ! function_exists('timespan'))
{
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;
@@ -208,7 +204,7 @@ if ( ! function_exists('timespan'))
{
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;
@@ -220,7 +216,7 @@ if ( ! function_exists('timespan'))
{
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;
@@ -232,7 +228,7 @@ if ( ! function_exists('timespan'))
{
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;
@@ -244,7 +240,7 @@ if ( ! function_exists('timespan'))
{
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;
@@ -252,7 +248,7 @@ if ( ! function_exists('timespan'))
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 implode(', ', $str);
@@ -279,15 +275,19 @@ if ( ! function_exists('days_in_month'))
{
return 0;
}
-
- if ( ! is_numeric($year) OR strlen($year) != 4)
+ elseif ( ! is_numeric($year) OR strlen($year) !== 4)
{
$year = date('Y');
}
+ if ($year >= 1970)
+ {
+ return (int) date('t', mktime(12, 0, 0, $month, 1, $year));
+ }
+
if ($month == 2)
{
- if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0))
+ if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0))
{
return 29;
}
@@ -310,17 +310,17 @@ if ( ! function_exists('local_to_gmt'))
*/
function local_to_gmt($time = '')
{
- if ($time == '')
+ if ($time === '')
{
$time = time();
}
return mktime(
- gmdate('H', $time),
+ gmdate('G', $time),
gmdate('i', $time),
gmdate('s', $time),
- gmdate('m', $time),
- gmdate('d', $time),
+ gmdate('n', $time),
+ gmdate('j', $time),
gmdate('Y', $time)
);
}
@@ -344,19 +344,14 @@ if ( ! function_exists('gmt_to_local'))
*/
function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
{
- if ($time == '')
+ if ($time === '')
{
return now();
}
$time += timezones($timezone) * 3600;
- if ($dst == TRUE)
- {
- $time += 3600;
- }
-
- return $time;
+ return ($dst === TRUE) ? $time + 3600 : $time;
}
}
@@ -376,9 +371,7 @@ if ( ! function_exists('mysql_to_unix'))
// since the formatting changed with MySQL 4.1
// YYYY-MM-DD HH:MM:SS
- $time = str_replace('-', '', $time);
- $time = str_replace(':', '', $time);
- $time = str_replace(' ', '', $time);
+ $time = str_replace(array('-', ':', ' '), '', $time);
// YYYYMMDDHHMMSS
return mktime(
@@ -408,9 +401,9 @@ if ( ! function_exists('unix_to_human'))
*/
function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
{
- $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
+ $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
- if ($fmt == 'us')
+ if ($fmt === 'us')
{
$r .= date('h', $time).':'.date('i', $time);
}
@@ -424,9 +417,9 @@ if ( ! function_exists('unix_to_human'))
$r .= ':'.date('s', $time);
}
- if ($fmt == 'us')
+ if ($fmt === 'us')
{
- $r .= ' '.date('A', $time);
+ return $r.' '.date('A', $time);
}
return $r;
@@ -447,58 +440,40 @@ if ( ! function_exists('human_to_unix'))
*/
function human_to_unix($datestr = '')
{
- if ($datestr == '')
+ if ($datestr === '')
{
return FALSE;
}
$datestr = preg_replace('/\040+/', ' ', trim($datestr));
- if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr))
+ if ( ! preg_match('/^(\d{2}|\d{4})\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr))
{
return FALSE;
}
$split = explode(' ', $datestr);
- $ex = explode('-', $split['0']);
-
- $year = (strlen($ex[0]) === 2) ? '20'.$ex[0] : $ex[0];
- $month = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1];
- $day = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2];
+ list($year, $month, $day) = explode('-', $split[0]);
$ex = explode(':', $split['1']);
- $hour = (strlen($ex[0]) === 1) ? '0'.$ex[0] : $ex[0];
- $min = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1];
+ $hour = (int) $ex[0];
+ $min = (int) $ex[1];
+ $sec = ( ! empty($ex[2]) && preg_match('/[0-9]{1,2}/', $ex[2]))
+ ? (int) $ex[2] : 0;
- if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex[2]))
- {
- $sec = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2];
- }
- else
- {
- // Unless specified, seconds get set to zero.
- $sec = '00';
- }
-
- if (isset($split['2']))
+ if (isset($split[2]))
{
$ampm = strtolower($split[2]);
- if (substr($ampm, 0, 1) === 'p' && $hour < 12)
+ if ($ampm[0] === 'p' && $hour < 12)
{
$hour += 12;
}
-
- if (substr($ampm, 0, 1) === 'a' && $hour == 12)
- {
- $hour = '00';
- }
-
- if (strlen($hour) === 1)
+ elseif ($ampm[0] === 'a' && $hour === 12)
{
- $hour = '0'.$hour;
+ $hour = 0;
}
}
@@ -524,9 +499,13 @@ if ( ! function_exists('nice_date'))
{
return 'Unknown';
}
+ elseif (empty($format))
+ {
+ $format = 'U';
+ }
// Date like: YYYYMM
- if (preg_match('/^\d{6}$/', $bad_date))
+ if (preg_match('/^\d{6}$/i', $bad_date))
{
if (in_array(substr($bad_date, 0, 2), array('19', '20')))
{
@@ -543,26 +522,21 @@ if ( ! function_exists('nice_date'))
}
// Date Like: YYYYMMDD
- if (preg_match('/^\d{8}$/', $bad_date))
+ if (preg_match('/^(\d{2})\d{2}(\d{4})$/i', $bad_date, $matches))
{
- $month = substr($bad_date, 0, 2);
- $day = substr($bad_date, 2, 2);
- $year = substr($bad_date, 4, 4);
-
- return date($format, strtotime($month.'/01/'.$year));
+ return date($format, strtotime($matches[1].'/01/'.$matches[2]));
}
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between)
- if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/', $bad_date))
+ if (preg_match('/^(\d{1,2})-(\d{1,2})-(\d{4})$/i', $bad_date, $matches))
{
- list($m, $d, $y) = explode('-', $bad_date);
- return date($format, strtotime($y.'-'.$m.'-'.$d));
+ return date($format, strtotime($matches[3].'-'.$matches[1].'-'.$matches[2]));
}
// Any other kind of string, when converted into UNIX time,
// produces "0 seconds after epoc..." is probably bad...
// return "Invalid Date".
- if (date('U', strtotime($bad_date)) == '0')
+ if (date('U', strtotime($bad_date)) === '0')
{
return 'Invalid Date';
}
@@ -584,27 +558,28 @@ if ( ! function_exists('timezone_menu'))
* @param string timezone
* @param string classname
* @param string menu name
+ * @param mixed attributes
* @return string
*/
- function timezone_menu($default = 'UTC', $class = '', $name = 'timezones')
+ function timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '')
{
$CI =& get_instance();
$CI->lang->load('date');
- $default = ($default == 'GMT') ? 'UTC' : $default;
+ $default = ($default === 'GMT') ? 'UTC' : $default;
$menu = '<select name="'.$name.'"';
- if ($class != '')
+ if ($class !== '')
{
$menu .= ' class="'.$class.'"';
}
- $menu .= ">\n";
+ $menu .= _stringify_attributes($attributes).">\n";
foreach (timezones() as $key => $val)
{
- $selected = ($default == $key) ? ' selected="selected"' : '';
+ $selected = ($default === $key) ? ' selected="selected"' : '';
$menu .= '<option value="'.$key.'"'.$selected.'>'.$CI->lang->line($key)."</option>\n";
}
@@ -673,13 +648,11 @@ if ( ! function_exists('timezones'))
'UP14' => +14
);
- if ($tz == '')
+ if ($tz === '')
{
return $zones;
}
- $tz = ($tz == 'GMT') ? 'UTC' : $tz;
-
return isset($zones[$tz]) ? $zones[$tz] : 0;
}
}
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index bda8fe8bb..7d6b6770e 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -62,7 +62,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 ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.'))
{
continue;
}
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 470b61ede..0232adfe4 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -46,12 +46,12 @@ if ( ! function_exists('force_download'))
*
* @param string filename
* @param mixed the data to be downloaded
- * @param bool wether to try and send the actual file MIME type
+ * @param bool whether to try and send the actual file MIME type
* @return void
*/
function force_download($filename = '', $data = '', $set_mime = FALSE)
{
- if ($filename == '' OR $data == '')
+ if ($filename === '' OR $data === '')
{
return FALSE;
}
@@ -73,14 +73,7 @@ if ( ! function_exists('force_download'))
}
// 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');
- }
+ $mimes =& get_mimes();
// Only change the default MIME if we can find one
if (isset($mimes[$extension]))
@@ -102,7 +95,10 @@ if ( ! function_exists('force_download'))
}
// Clean output buffer
- ob_clean();
+ if (ob_get_level() !== 0)
+ {
+ ob_clean();
+ }
// Generate the server headers
header('Content-Type: '.$mime);
diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php
index 0516e938a..2a63b36c9 100644
--- a/system/helpers/email_helper.php
+++ b/system/helpers/email_helper.php
@@ -45,9 +45,9 @@ if ( ! function_exists('valid_email'))
* @param string
* @return bool
*/
- function valid_email($address)
+ function valid_email($email)
{
- return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address);
+ return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
}
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index fb4503479..e68bb7f7a 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -32,7 +32,7 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/file_helpers.html
+ * @link http://codeigniter.com/user_guide/helpers/file_helper.html
*/
// ------------------------------------------------------------------------
@@ -44,38 +44,16 @@ if ( ! function_exists('read_file'))
*
* Opens the file specfied in the path and returns it as a string.
*
+ * This function is DEPRECATED and should be removed in
+ * CodeIgniter 3.1+. Use file_get_contents() instead.
+ *
+ * @deprecated
* @param string path to file
* @return string
*/
function read_file($file)
{
- if ( ! file_exists($file))
- {
- return FALSE;
- }
-
- if (function_exists('file_get_contents'))
- {
- return file_get_contents($file);
- }
-
- if ( ! $fp = @fopen($file, FOPEN_READ))
- {
- return FALSE;
- }
-
- flock($fp, LOCK_SH);
-
- $data = '';
- if (filesize($file) > 0)
- {
- $data =& fread($fp, filesize($file));
- }
-
- flock($fp, LOCK_UN);
- fclose($fp);
-
- return $data;
+ return @file_get_contents($file);
}
}
@@ -146,7 +124,7 @@ if ( ! function_exists('delete_files'))
{
delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs);
}
- elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
+ elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
{
@unlink($path.DIRECTORY_SEPARATOR.$filename);
}
@@ -154,7 +132,7 @@ if ( ! function_exists('delete_files'))
}
@closedir($current_dir);
- if ($del_dir == TRUE && $level > 0)
+ if ($del_dir === TRUE && $level > 0)
{
return @rmdir($path);
}
@@ -199,7 +177,7 @@ if ( ! function_exists('get_filenames'))
}
elseif ($file[0] !== '.')
{
- $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
+ $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
}
}
closedir($fp);
@@ -349,36 +327,23 @@ if ( ! function_exists('get_mime_by_extension'))
{
$extension = strtolower(substr(strrchr($file, '.'), 1));
- global $mimes;
+ static $mimes;
if ( ! is_array($mimes))
{
- 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');
- }
+ $mimes =& get_mimes();
- if ( ! is_array($mimes))
+ if (empty($mimes))
{
return FALSE;
}
}
- if (array_key_exists($extension, $mimes))
+ if (isset($mimes[$extension]))
{
- if (is_array($mimes[$extension]))
- {
- // Multiple mime types, just give the first one
- return current($mimes[$extension]);
- }
- else
- {
- return $mimes[$extension];
- }
+ return is_array($mimes[$extension])
+ ? current($mimes[$extension]) // Multiple mime types, just give the first one
+ : $mimes[$extension];
}
return FALSE;
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index eca6c5f1e..1bccac35c 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -52,7 +52,7 @@ if ( ! function_exists('form_open'))
{
$CI =& get_instance();
- if ($attributes == '')
+ if ($attributes === '')
{
$attributes = 'method="post"';
}
@@ -62,9 +62,11 @@ if ( ! function_exists('form_open'))
{
$action = $CI->config->site_url($action);
}
-
- // If no action is provided then set to the current url
- $action OR $action = $CI->config->site_url($CI->uri->uri_string());
+ elseif ( ! $action)
+ {
+ // If no action is provided then set to the current url
+ $action = $CI->config->site_url($CI->uri->uri_string());
+ }
$form = '<form action="'.$action.'"'._attributes_to_string($attributes, TRUE).">\n";
@@ -76,7 +78,7 @@ if ( ! function_exists('form_open'))
if (is_array($hidden) && count($hidden) > 0)
{
- $form .= sprintf('<div style="display:none;">%s</div>', form_hidden($hidden));
+ $form .= '<div style="display:none;">'.form_hidden($hidden).'</div>';
}
return $form;
@@ -325,7 +327,10 @@ if ( ! function_exists('form_dropdown'))
$selected = array($_POST[$name]);
}
- if ($extra != '') $extra = ' '.$extra;
+ if ($extra != '')
+ {
+ $extra = ' '.$extra;
+ }
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
@@ -335,8 +340,13 @@ if ( ! function_exists('form_dropdown'))
{
$key = (string) $key;
- if (is_array($val) && ! empty($val))
+ if (is_array($val))
{
+ if (empty($val))
+ {
+ continue;
+ }
+
$form .= '<optgroup label="'.$key."\">\n";
foreach ($val as $optgroup_key => $optgroup_val)
@@ -506,7 +516,7 @@ if ( ! function_exists('form_label'))
$label = '<label';
- if ($id != '')
+ if ($id !== '')
{
$label .= ' for="'.$id.'"';
}
@@ -540,7 +550,7 @@ if ( ! function_exists('form_fieldset'))
function form_fieldset($legend_text = '', $attributes = array())
{
$fieldset = '<fieldset'._attributes_to_string($attributes, FALSE).">\n";
- if ($legend_text != '')
+ if ($legend_text !== '')
{
return $fieldset.'<legend>'.$legend_text."</legend>\n";
}
@@ -623,7 +633,7 @@ if ( ! function_exists('form_prep'))
return $str;
}
- if ($field_name != '')
+ if ($field_name !== '')
{
$prepped_fields[$field_name] = $field_name;
}
@@ -686,7 +696,7 @@ if ( ! function_exists('set_select'))
{
if ( ! isset($_POST[$field]))
{
- if (count($_POST) === 0 && $default == TRUE)
+ if (count($_POST) === 0 && $default === TRUE)
{
return ' selected="selected"';
}
@@ -702,7 +712,7 @@ if ( ! function_exists('set_select'))
return '';
}
}
- elseif (($field == '' OR $value == '') OR ($field != $value))
+ elseif (($field == '' OR $value == '') OR $field !== $value)
{
return '';
}
@@ -737,7 +747,7 @@ if ( ! function_exists('set_checkbox'))
{
if ( ! isset($_POST[$field]))
{
- if (count($_POST) === 0 && $default == TRUE)
+ if (count($_POST) === 0 && $default === TRUE)
{
return ' checked="checked"';
}
@@ -753,7 +763,7 @@ if ( ! function_exists('set_checkbox'))
return '';
}
}
- elseif (($field == '' OR $value == '') OR ($field != $value))
+ elseif (($field == '' OR $value == '') OR $field !== $value)
{
return '';
}
@@ -788,7 +798,7 @@ if ( ! function_exists('set_radio'))
{
if ( ! isset($_POST[$field]))
{
- if (count($_POST) === 0 && $default == TRUE)
+ if (count($_POST) === 0 && $default === TRUE)
{
return ' checked="checked"';
}
@@ -806,7 +816,7 @@ if ( ! function_exists('set_radio'))
}
else
{
- if (($field == '' OR $value == '') OR ($field != $value))
+ if (($field == '' OR $value == '') OR $field !== $value)
{
return '';
}
@@ -907,7 +917,7 @@ if ( ! function_exists('_parse_form_attributes'))
foreach ($default as $key => $val)
{
- if ($key == 'value')
+ if ($key === 'value')
{
$val = form_prep($val, $default['name']);
}
@@ -936,12 +946,12 @@ if ( ! function_exists('_attributes_to_string'))
{
if (is_string($attributes) && strlen($attributes) > 0)
{
- if ($formtag == TRUE && strpos($attributes, 'method=') === FALSE)
+ if ($formtag === TRUE && strpos($attributes, 'method=') === FALSE)
{
$attributes .= ' method="post"';
}
- if ($formtag == TRUE && strpos($attributes, 'accept-charset=') === FALSE)
+ if ($formtag === TRUE && strpos($attributes, 'accept-charset=') === FALSE)
{
$attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"';
}
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 92a6db477..2372e8174 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -51,7 +51,7 @@ if ( ! function_exists('heading'))
*/
function heading($data = '', $h = '1', $attributes = '')
{
- return '<h'.$h.($attributes != '' ? ' ' : '').$attributes.'>'.$data.'</h'.$h.'>';
+ return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>';
}
}
@@ -119,23 +119,8 @@ if ( ! function_exists('_list'))
// Set the indentation based on the depth
$out = str_repeat(' ', $depth);
- // Were any attributes submitted? If so generate a string
- if (is_array($attributes))
- {
- $atts = '';
- foreach ($attributes as $key => $val)
- {
- $atts .= ' '.$key.'="'.$val.'"';
- }
- $attributes = $atts;
- }
- elseif (is_string($attributes) && strlen($attributes) > 0)
- {
- $attributes = ' '.$attributes;
- }
-
// Write the opening list tag
- $out .= '<'.$type.$attributes.">\n";
+ $out .= '<'.$type._stringify_attributes($attributes).">\n";
// Cycle through the list elements. If an array is
// encountered we will recursively call _list()
@@ -191,9 +176,10 @@ if ( ! function_exists('img'))
*
* @param mixed
* @param bool
+ * @param mixed
* @return string
*/
- function img($src = '', $index_page = FALSE)
+ function img($src = '', $index_page = FALSE, $attributes = '')
{
if ( ! is_array($src) )
{
@@ -229,7 +215,7 @@ if ( ! function_exists('img'))
}
}
- return $img.'/>';
+ return $img._stringify_attributes($attributes).' />';
}
}
@@ -242,9 +228,9 @@ if ( ! function_exists('doctype'))
*
* Generates a page document type declaration
*
- * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame,
- * html4-strict, html4-trans, and html4-frame. Values are saved in the
- * doctypes config file.
+ * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans,
+ * xhtml-frame, html4-strict, html4-trans, and html4-frame.
+ * All values are saved in the doctypes config file.
*
* @param string type The doctype to be generated
* @return string
@@ -334,12 +320,12 @@ if ( ! function_exists('link_tag'))
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
- if ($media != '')
+ if ($media !== '')
{
$link .= 'media="'.$media.'" ';
}
- if ($title != '')
+ if ($title !== '')
{
$link .= 'title="'.$title.'" ';
}
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 2a9466305..647d840e4 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -37,16 +37,16 @@
// --------------------------------------------------------------------
-/**
- * Singular
- *
- * Takes a plural word and makes it singular
- *
- * @param string
- * @return str
- */
if ( ! function_exists('singular'))
{
+ /**
+ * Singular
+ *
+ * Takes a plural word and makes it singular
+ *
+ * @param string
+ * @return string
+ */
function singular($str)
{
$result = strval($str);
@@ -101,17 +101,17 @@ if ( ! function_exists('singular'))
// --------------------------------------------------------------------
-/**
- * Plural
- *
- * Takes a singular word and makes it plural
- *
- * @param string
- * @param bool
- * @return str
- */
if ( ! function_exists('plural'))
{
+ /**
+ * Plural
+ *
+ * Takes a singular word and makes it plural
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function plural($str, $force = FALSE)
{
$result = strval($str);
@@ -158,16 +158,16 @@ if ( ! function_exists('plural'))
// --------------------------------------------------------------------
-/**
- * Camelize
- *
- * Takes multiple words separated by spaces or underscores and camelizes them
- *
- * @param string
- * @return str
- */
if ( ! function_exists('camelize'))
{
+ /**
+ * Camelize
+ *
+ * Takes multiple words separated by spaces or underscores and camelizes them
+ *
+ * @param string
+ * @return string
+ */
function camelize($str)
{
return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
@@ -176,16 +176,16 @@ if ( ! function_exists('camelize'))
// --------------------------------------------------------------------
-/**
- * Underscore
- *
- * Takes multiple words separated by spaces and underscores them
- *
- * @param string
- * @return str
- */
if ( ! function_exists('underscore'))
{
+ /**
+ * Underscore
+ *
+ * Takes multiple words separated by spaces and underscores them
+ *
+ * @param string
+ * @return string
+ */
function underscore($str)
{
return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
@@ -194,31 +194,33 @@ if ( ! function_exists('underscore'))
// --------------------------------------------------------------------
-/**
- * Humanize
- *
- * Takes multiple words separated by the separator and changes them to spaces
- *
- * @param string $str
- * @param string $separator
- * @return string
- */
if ( ! function_exists('humanize'))
{
+ /**
+ * Humanize
+ *
+ * Takes multiple words separated by the separator and changes them to spaces
+ *
+ * @param string $str
+ * @param string $separator
+ * @return string
+ */
function humanize($str, $separator = '_')
{
return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str))));
}
}
-/**
- * Checks if the given word has a plural version.
- *
- * @param string the word to check
- * @return bool if the word is countable
- */
+// --------------------------------------------------------------------
+
if ( ! function_exists('is_countable'))
{
+ /**
+ * Checks if the given word has a plural version.
+ *
+ * @param string the word to check
+ * @return bool if the word is countable
+ */
function is_countable($word)
{
return ! in_array(strtolower(strval($word)),
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index b31c97107..bd567ed79 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -37,23 +37,23 @@
// ------------------------------------------------------------------------
-/**
- * Lang
- *
- * Fetches a language variable and optionally outputs a form label
- *
- * @param string the language line
- * @param string the id of the form element
- * @return string
- */
if ( ! function_exists('lang'))
{
+ /**
+ * Lang
+ *
+ * Fetches a language variable and optionally outputs a form label
+ *
+ * @param string the language line
+ * @param string the id of the form element
+ * @return string
+ */
function lang($line, $id = '')
{
$CI =& get_instance();
$line = $CI->lang->line($line);
- if ($id != '')
+ if ($id !== '')
{
$line = '<label for="'.$id.'">'.$line.'</label>';
}
diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php
index 40da6e7bf..e49f2f7a0 100644
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -37,14 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Formats a numbers as bytes, based on size, and adds the appropriate suffix
- *
- * @param mixed // will be cast as int
- * @return string
- */
if ( ! function_exists('byte_format'))
{
+ /**
+ * Formats a numbers as bytes, based on size, and adds the appropriate suffix
+ *
+ * @param mixed will be cast as int
+ * @param int
+ * @return string
+ */
function byte_format($num, $precision = 1)
{
$CI =& get_instance();
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 6ee99072c..166fef065 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -32,20 +32,20 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
+ * @link http://codeigniter.com/user_guide/helpers/path_helper.html
*/
// ------------------------------------------------------------------------
-/**
- * Set Realpath
- *
- * @param string
- * @param bool checks to see if the path exists
- * @return string
- */
if ( ! function_exists('set_realpath'))
{
+ /**
+ * Set Realpath
+ *
+ * @param string
+ * @param bool checks to see if the path exists
+ * @return string
+ */
function set_realpath($path, $check_existance = FALSE)
{
// Security check to make sure the path is NOT a URL. No remote file inclusion!
@@ -55,7 +55,7 @@ if ( ! function_exists('set_realpath'))
}
// Resolve the path
- if (function_exists('realpath') && @realpath($path) !== FALSE)
+ if (@realpath($path) !== FALSE)
{
$path = realpath($path);
}
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php
index d6f134c9f..5ecc960bc 100644
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * XSS Filtering
- *
- * @param string
- * @param bool whether or not the content is an image file
- * @return string
- */
if ( ! function_exists('xss_clean'))
{
+ /**
+ * XSS Filtering
+ *
+ * @param string
+ * @param bool whether or not the content is an image file
+ * @return string
+ */
function xss_clean($str, $is_image = FALSE)
{
$CI =& get_instance();
@@ -55,14 +55,14 @@ if ( ! function_exists('xss_clean'))
// ------------------------------------------------------------------------
-/**
- * Sanitize Filename
- *
- * @param string
- * @return string
- */
if ( ! function_exists('sanitize_filename'))
{
+ /**
+ * Sanitize Filename
+ *
+ * @param string
+ * @return string
+ */
function sanitize_filename($filename)
{
$CI =& get_instance();
@@ -72,14 +72,19 @@ if ( ! function_exists('sanitize_filename'))
// --------------------------------------------------------------------
-/**
- * Hash encode a string
- *
- * @param string
- * @return string
- */
if ( ! function_exists('do_hash'))
{
+ /**
+ * Hash encode a string
+ *
+ * This function is DEPRECATED and should be removed in
+ * CodeIgniter 3.1+. Use hash() instead.
+ *
+ * @deprecated
+ * @param string
+ * @param string
+ * @return string
+ */
function do_hash($str, $type = 'sha1')
{
if ( ! in_array(strtolower($type), hash_algos()))
@@ -93,33 +98,34 @@ if ( ! function_exists('do_hash'))
// ------------------------------------------------------------------------
-/**
- * Strip Image Tags
- *
- * @param string
- * @return string
- */
if ( ! function_exists('strip_image_tags'))
{
+ /**
+ * Strip Image Tags
+ *
+ * @param string
+ * @return string
+ */
function strip_image_tags($str)
{
- return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
+ $CI =& get_instance();
+ return $CI->security->strip_image_tags($str);
}
}
// ------------------------------------------------------------------------
-/**
- * Convert PHP tags to entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('encode_php_tags'))
{
+ /**
+ * Convert PHP tags to entities
+ *
+ * @param string
+ * @return string
+ */
function encode_php_tags($str)
{
- return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
+ return str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $str);
}
}
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 638100e9c..b6b2afcf4 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -37,24 +37,25 @@
// ------------------------------------------------------------------------
-/**
- * Smiley Javascript
- *
- * Returns the javascript required for the smiley insertion. Optionally takes
- * an array of aliases to loosely couple the smiley array to the view.
- *
- * @param mixed alias name or array of alias->field_id pairs
- * @param string field_id if alias name was passed in
- * @return array
- */
if ( ! function_exists('smiley_js'))
{
+ /**
+ * Smiley Javascript
+ *
+ * Returns the javascript required for the smiley insertion. Optionally takes
+ * an array of aliases to loosely couple the smiley array to the view.
+ *
+ * @param mixed alias name or array of alias->field_id pairs
+ * @param string field_id if alias name was passed in
+ * @param bool
+ * @return array
+ */
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
{
static $do_setup = TRUE;
$r = '';
- if ($alias != '' && ! is_array($alias))
+ if ($alias !== '' && ! is_array($alias))
{
$alias = array($alias => $field_id);
}
@@ -118,17 +119,20 @@ EOF;
// ------------------------------------------------------------------------
-/**
- * Get Clickable Smileys
- *
- * Returns an array of image tag links that can be clicked to be inserted
- * into a form field.
- *
- * @param string the URL to the folder containing the smiley images
- * @return array
- */
+
if ( ! function_exists('get_clickable_smileys'))
{
+ /**
+ * Get Clickable Smileys
+ *
+ * Returns an array of image tag links that can be clicked to be inserted
+ * into a form field.
+ *
+ * @param string the URL to the folder containing the smiley images
+ * @param array
+ * @param array
+ * @return array
+ */
function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
{
// For backward compatibility with js_insert_smiley
@@ -166,20 +170,21 @@ if ( ! function_exists('get_clickable_smileys'))
// ------------------------------------------------------------------------
-/**
- * Parse Smileys
- *
- * Takes a string as input and swaps any contained smileys for the actual image
- *
- * @param string the text to be parsed
- * @param string the URL to the folder containing the smiley images
- * @return string
- */
if ( ! function_exists('parse_smileys'))
{
+ /**
+ * Parse Smileys
+ *
+ * Takes a string as input and swaps any contained smileys for the actual image
+ *
+ * @param string the text to be parsed
+ * @param string the URL to the folder containing the smiley images
+ * @param array
+ * @return string
+ */
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
- if ($image_url == '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
+ if ($image_url === '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
{
return $str;
}
@@ -198,15 +203,15 @@ if ( ! function_exists('parse_smileys'))
// ------------------------------------------------------------------------
-/**
- * Get Smiley Array
- *
- * Fetches the config/smiley.php file
- *
- * @return mixed
- */
if ( ! function_exists('_get_smiley_array'))
{
+ /**
+ * Get Smiley Array
+ *
+ * Fetches the config/smiley.php file
+ *
+ * @return mixed
+ */
function _get_smiley_array()
{
if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
@@ -222,33 +227,5 @@ if ( ! function_exists('_get_smiley_array'))
}
}
-// ------------------------------------------------------------------------
-
-/**
- * JS Insert Smiley
- *
- * Generates the javascript function needed to insert smileys into a form field
- *
- * DEPRECATED as of version 1.7.2, use smiley_js instead
- *
- * @param string form name
- * @param string field name
- * @return string
- */
-if ( ! function_exists('js_insert_smiley'))
-{
- function js_insert_smiley($form_name = '', $form_field = '')
- {
- return <<<EOF
-<script type="text/javascript">
- function insert_smiley(smiley)
- {
- document.{$form_name}.{$form_field}.value += " " + smiley;
- }
-</script>
-EOF;
- }
-}
-
/* End of file smiley_helper.php */
/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index a6a6b485d..4eee2a262 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -37,22 +37,22 @@
// ------------------------------------------------------------------------
-/**
- * Trim Slashes
- *
- * Removes any leading/trailing slashes from a string:
- *
- * /this/that/theother/
- *
- * becomes:
- *
- * this/that/theother
- *
- * @param string
- * @return string
- */
if ( ! function_exists('trim_slashes'))
{
+ /**
+ * Trim Slashes
+ *
+ * Removes any leading/trailing slashes from a string:
+ *
+ * /this/that/theother/
+ *
+ * becomes:
+ *
+ * this/that/theother
+ *
+ * @param string
+ * @return string
+ */
function trim_slashes($str)
{
return trim($str, '/');
@@ -61,16 +61,16 @@ if ( ! function_exists('trim_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Slashes
- *
- * Removes slashes contained in a string or in an array
- *
- * @param mixed string or array
- * @return mixed string or array
- */
if ( ! function_exists('strip_slashes'))
{
+ /**
+ * Strip Slashes
+ *
+ * Removes slashes contained in a string or in an array
+ *
+ * @param mixed string or array
+ * @return mixed string or array
+ */
function strip_slashes($str)
{
if ( ! is_array($str))
@@ -89,16 +89,16 @@ if ( ! function_exists('strip_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Quotes
- *
- * Removes single and double quotes from a string
- *
- * @param string
- * @return string
- */
if ( ! function_exists('strip_quotes'))
{
+ /**
+ * Strip Quotes
+ *
+ * Removes single and double quotes from a string
+ *
+ * @param string
+ * @return string
+ */
function strip_quotes($str)
{
return str_replace(array('"', "'"), '', $str);
@@ -107,16 +107,16 @@ if ( ! function_exists('strip_quotes'))
// ------------------------------------------------------------------------
-/**
- * Quotes to Entities
- *
- * Converts single and double quotes to entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('quotes_to_entities'))
{
+ /**
+ * Quotes to Entities
+ *
+ * Converts single and double quotes to entities
+ *
+ * @param string
+ * @return string
+ */
function quotes_to_entities($str)
{
return str_replace(array("\'","\"","'",'"'), array("&#39;","&quot;","&#39;","&quot;"), $str);
@@ -125,23 +125,23 @@ if ( ! function_exists('quotes_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Reduce Double Slashes
- *
- * Converts double slashes in a string to a single slash,
- * except those found in http://
- *
- * http://www.some-site.com//index.php
- *
- * becomes:
- *
- * http://www.some-site.com/index.php
- *
- * @param string
- * @return string
- */
if ( ! function_exists('reduce_double_slashes'))
{
+ /**
+ * Reduce Double Slashes
+ *
+ * Converts double slashes in a string to a single slash,
+ * except those found in http://
+ *
+ * http://www.some-site.com//index.php
+ *
+ * becomes:
+ *
+ * http://www.some-site.com/index.php
+ *
+ * @param string
+ * @return string
+ */
function reduce_double_slashes($str)
{
return preg_replace('#(^|[^:])//+#', '\\1/', $str);
@@ -150,24 +150,24 @@ if ( ! function_exists('reduce_double_slashes'))
// ------------------------------------------------------------------------
-/**
- * Reduce Multiples
- *
- * Reduces multiple instances of a particular character. Example:
- *
- * Fred, Bill,, Joe, Jimmy
- *
- * becomes:
- *
- * Fred, Bill, Joe, Jimmy
- *
- * @param string
- * @param string the character you wish to reduce
- * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
- * @return string
- */
if ( ! function_exists('reduce_multiples'))
{
+ /**
+ * Reduce Multiples
+ *
+ * Reduces multiple instances of a particular character. Example:
+ *
+ * Fred, Bill,, Joe, Jimmy
+ *
+ * becomes:
+ *
+ * Fred, Bill, Joe, Jimmy
+ *
+ * @param string
+ * @param string the character you wish to reduce
+ * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
+ * @return string
+ */
function reduce_multiples($str, $character = ',', $trim = FALSE)
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
@@ -177,17 +177,17 @@ if ( ! function_exists('reduce_multiples'))
// ------------------------------------------------------------------------
-/**
- * Create a Random String
- *
- * Useful for generating passwords or hashes.
- *
- * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
- * @param int number of characters
- * @return string
- */
if ( ! function_exists('random_string'))
{
+ /**
+ * Create a Random String
+ *
+ * Useful for generating passwords or hashes.
+ *
+ * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
+ * @param int number of characters
+ * @return string
+ */
function random_string($type = 'alnum', $len = 8)
{
switch ($type)
@@ -226,16 +226,16 @@ if ( ! function_exists('random_string'))
// ------------------------------------------------------------------------
-/**
- * Add's _1 to a string or increment the ending number to allow _2, _3, etc
- *
- * @param string required
- * @param string What should the duplicate number be appended with
- * @param string Which number should be used for the first dupe increment
- * @return string
- */
if ( ! function_exists('increment_string'))
{
+ /**
+ * Add's _1 to a string or increment the ending number to allow _2, _3, etc
+ *
+ * @param string required
+ * @param string What should the duplicate number be appended with
+ * @param string Which number should be used for the first dupe increment
+ * @return string
+ */
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
@@ -245,21 +245,21 @@ if ( ! function_exists('increment_string'))
// ------------------------------------------------------------------------
-/**
- * Alternator
- *
- * Allows strings to be alternated. See docs...
- *
- * @param string (as many parameters as needed)
- * @return string
- */
if ( ! function_exists('alternator'))
{
- function alternator()
+ /**
+ * Alternator
+ *
+ * Allows strings to be alternated. See docs...
+ *
+ * @param string (as many parameters as needed)
+ * @return string
+ */
+ function alternator($args)
{
static $i;
- if (func_num_args() == 0)
+ if (func_num_args() === 0)
{
$i = 0;
return '';
@@ -271,15 +271,15 @@ if ( ! function_exists('alternator'))
// ------------------------------------------------------------------------
-/**
- * Repeater function
- *
- * @param string
- * @param int number of repeats
- * @return string
- */
if ( ! function_exists('repeater'))
{
+ /**
+ * Repeater function
+ *
+ * @param string
+ * @param int number of repeats
+ * @return string
+ */
function repeater($data, $num = 1)
{
return ($num > 0) ? str_repeat($data, $num) : '';
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index c1c0eb947..b592f3cc0 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -37,21 +37,21 @@
// ------------------------------------------------------------------------
-/**
- * Word Limiter
- *
- * Limits a string to X number of words.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('word_limiter'))
{
+ /**
+ * Word Limiter
+ *
+ * Limits a string to X number of words.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function word_limiter($str, $limit = 100, $end_char = '&#8230;')
{
- if (trim($str) == '')
+ if (trim($str) === '')
{
return $str;
}
@@ -69,19 +69,19 @@ if ( ! function_exists('word_limiter'))
// ------------------------------------------------------------------------
-/**
- * Character Limiter
- *
- * Limits the string based on the character count. Preserves complete words
- * so the character count may not be exactly as specified.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('character_limiter'))
{
+ /**
+ * Character Limiter
+ *
+ * Limits the string based on the character count. Preserves complete words
+ * so the character count may not be exactly as specified.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function character_limiter($str, $n = 500, $end_char = '&#8230;')
{
if (strlen($str) < $n)
@@ -89,7 +89,8 @@ if ( ! function_exists('character_limiter'))
return $str;
}
- $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
+ // a bit complicated, but faster than preg_replace with \s+
+ $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str));
if (strlen($str) <= $n)
{
@@ -112,16 +113,16 @@ if ( ! function_exists('character_limiter'))
// ------------------------------------------------------------------------
-/**
- * High ASCII to Entities
- *
- * Converts High ascii text and MS Word special characters to character entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('ascii_to_entities'))
{
+ /**
+ * High ASCII to Entities
+ *
+ * Converts High ascii text and MS Word special characters to character entities
+ *
+ * @param string
+ * @return string
+ */
function ascii_to_entities($str)
{
$count = 1;
@@ -174,17 +175,17 @@ if ( ! function_exists('ascii_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Entities to ASCII
- *
- * Converts character entities back to ASCII
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('entities_to_ascii'))
{
+ /**
+ * Entities to ASCII
+ *
+ * Converts character entities back to ASCII
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function entities_to_ascii($str, $all = TRUE)
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
@@ -227,20 +228,20 @@ if ( ! function_exists('entities_to_ascii'))
// ------------------------------------------------------------------------
-/**
- * Word Censoring Function
- *
- * Supply a string and an array of disallowed words and any
- * matched words will be converted to #### or to the replacement
- * word you've submitted.
- *
- * @param string the text string
- * @param string the array of censoered words
- * @param string the optional replacement value
- * @return string
- */
if ( ! function_exists('word_censor'))
{
+ /**
+ * Word Censoring Function
+ *
+ * Supply a string and an array of disallowed words and any
+ * matched words will be converted to #### or to the replacement
+ * word you've submitted.
+ *
+ * @param string the text string
+ * @param string the array of censoered words
+ * @param string the optional replacement value
+ * @return string
+ */
function word_censor($str, $censored, $replacement = '')
{
if ( ! is_array($censored))
@@ -258,7 +259,7 @@ if ( ! function_exists('word_censor'))
foreach ($censored as $badword)
{
- if ($replacement != '')
+ if ($replacement !== '')
{
$str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str);
}
@@ -274,16 +275,16 @@ if ( ! function_exists('word_censor'))
// ------------------------------------------------------------------------
-/**
- * Code Highlighter
- *
- * Colorizes code strings
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('highlight_code'))
{
+ /**
+ * Code Highlighter
+ *
+ * Colorizes code strings
+ *
+ * @param string the text string
+ * @return string
+ */
function highlight_code($str)
{
/* The highlight string function encodes and highlights
@@ -323,27 +324,27 @@ if ( ! function_exists('highlight_code'))
// ------------------------------------------------------------------------
-/**
- * Phrase Highlighter
- *
- * Highlights a phrase within a text string
- *
- * @param string the text string
- * @param string the phrase you'd like to highlight
- * @param string the openging tag to precede the phrase with
- * @param string the closing tag to end the phrase with
- * @return string
- */
if ( ! function_exists('highlight_phrase'))
{
+ /**
+ * Phrase Highlighter
+ *
+ * Highlights a phrase within a text string
+ *
+ * @param string the text string
+ * @param string the phrase you'd like to highlight
+ * @param string the openging tag to precede the phrase with
+ * @param string the closing tag to end the phrase with
+ * @return string
+ */
function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
{
- if ($str == '')
+ if ($str === '')
{
return '';
}
- if ($phrase != '')
+ if ($phrase !== '')
{
return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str);
}
@@ -354,14 +355,14 @@ if ( ! function_exists('highlight_phrase'))
// ------------------------------------------------------------------------
-/**
- * Convert Accented Foreign Characters to ASCII
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('convert_accented_characters'))
{
+ /**
+ * Convert Accented Foreign Characters to ASCII
+ *
+ * @param string the text string
+ * @return string
+ */
function convert_accented_characters($str)
{
global $foreign_characters;
@@ -464,7 +465,7 @@ if ( ! function_exists('word_wrap'))
// If $temp contains data it means we had to split up an over-length
// word into smaller chunks so we'll add it back to our current line
- if ($temp != '')
+ if ($temp !== '')
{
$output .= $temp."\n".$line."\n";
}
@@ -490,19 +491,19 @@ if ( ! function_exists('word_wrap'))
// ------------------------------------------------------------------------
-/**
- * Ellipsize String
- *
- * This function will strip tags from a string, split it at its max_length and ellipsize
- *
- * @param string string to ellipsize
- * @param int max length of string
- * @param mixed int (1|0) or float, .5, .2, etc for position to split
- * @param string ellipsis ; Default '...'
- * @return string ellipsized string
- */
if ( ! function_exists('ellipsize'))
{
+ /**
+ * Ellipsize String
+ *
+ * This function will strip tags from a string, split it at its max_length and ellipsize
+ *
+ * @param string string to ellipsize
+ * @param int max length of string
+ * @param mixed int (1|0) or float, .5, .2, etc for position to split
+ * @param string ellipsis ; Default '...'
+ * @return string ellipsized string
+ */
function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
{
// Strip tags
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 7a3db5d6b..9dbba0679 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -37,14 +37,14 @@
// ------------------------------------------------------------------------
-/**
- * Convert newlines to HTML line breaks except within PRE tags
- *
- * @param string
- * @return string
- */
if ( ! function_exists('nl2br_except_pre'))
{
+ /**
+ * Convert newlines to HTML line breaks except within PRE tags
+ *
+ * @param string
+ * @return string
+ */
function nl2br_except_pre($str)
{
$CI =& get_instance();
@@ -55,38 +55,37 @@ if ( ! function_exists('nl2br_except_pre'))
// ------------------------------------------------------------------------
-/**
- * Auto Typography Wrapper Function
- *
- * @param string
- * @param bool whether to allow javascript event handlers
- * @param bool whether to reduce multiple instances of double newlines to two
- * @return string
- */
if ( ! function_exists('auto_typography'))
{
- function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE)
+ /**
+ * Auto Typography Wrapper Function
+ *
+ * @param string
+ * @param bool whether to allow javascript event handlers
+ * @param bool whether to reduce multiple instances of double newlines to two
+ * @return string
+ */
+ function auto_typography($str, $reduce_linebreaks = FALSE)
{
$CI =& get_instance();
$CI->load->library('typography');
- return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks);
+ return $CI->typography->auto_typography($str, $reduce_linebreaks);
}
}
-
// --------------------------------------------------------------------
-/**
- * HTML Entities Decode
- *
- * This function is a replacement for html_entity_decode()
- *
- * @param string
- * @param string
- * @return string
- */
if ( ! function_exists('entity_decode'))
{
+ /**
+ * HTML Entities Decode
+ *
+ * This function is a replacement for html_entity_decode()
+ *
+ * @param string
+ * @param string
+ * @return string
+ */
function entity_decode($str, $charset = NULL)
{
global $SEC;
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index cf6df4ef5..b1f5eccf1 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -37,17 +37,17 @@
// ------------------------------------------------------------------------
-/**
- * Site URL
- *
- * Create a local URL based on your basepath. Segments can be passed via the
- * first parameter either as a string or an array.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('site_url'))
{
+ /**
+ * Site URL
+ *
+ * Create a local URL based on your basepath. Segments can be passed via the
+ * first parameter either as a string or an array.
+ *
+ * @param string
+ * @return string
+ */
function site_url($uri = '')
{
$CI =& get_instance();
@@ -57,18 +57,18 @@ if ( ! function_exists('site_url'))
// ------------------------------------------------------------------------
-/**
- * Base URL
- *
- * Create a local URL based on your basepath.
- * Segments can be passed in as a string or an array, same as site_url
- * or a URL to a file can be passed in, e.g. to an image file.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('base_url'))
{
+ /**
+ * Base URL
+ *
+ * Create a local URL based on your basepath.
+ * Segments can be passed in as a string or an array, same as site_url
+ * or a URL to a file can be passed in, e.g. to an image file.
+ *
+ * @param string
+ * @return string
+ */
function base_url($uri = '')
{
$CI =& get_instance();
@@ -78,16 +78,16 @@ if ( ! function_exists('base_url'))
// ------------------------------------------------------------------------
-/**
- * Current URL
- *
- * Returns the full URL (including segments) of the page where this
- * function is placed
- *
- * @return string
- */
if ( ! function_exists('current_url'))
{
+ /**
+ * Current URL
+ *
+ * Returns the full URL (including segments) of the page where this
+ * function is placed
+ *
+ * @return string
+ */
function current_url()
{
$CI =& get_instance();
@@ -96,15 +96,16 @@ if ( ! function_exists('current_url'))
}
// ------------------------------------------------------------------------
-/**
- * URL String
- *
- * Returns the URI segments.
- *
- * @return string
- */
+
if ( ! function_exists('uri_string'))
{
+ /**
+ * URL String
+ *
+ * Returns the URI segments.
+ *
+ * @return string
+ */
function uri_string()
{
$CI =& get_instance();
@@ -114,15 +115,15 @@ if ( ! function_exists('uri_string'))
// ------------------------------------------------------------------------
-/**
- * Index page
- *
- * Returns the "index_page" from your config file
- *
- * @return string
- */
if ( ! function_exists('index_page'))
{
+ /**
+ * Index page
+ *
+ * Returns the "index_page" from your config file
+ *
+ * @return string
+ */
function index_page()
{
$CI =& get_instance();
@@ -132,18 +133,18 @@ if ( ! function_exists('index_page'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link
- *
- * Creates an anchor based on the local URL.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor'))
{
+ /**
+ * Anchor Link
+ *
+ * Creates an anchor based on the local URL.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
@@ -157,14 +158,14 @@ if ( ! function_exists('anchor'))
$site_url = site_url($uri);
}
- if ($title == '')
+ if ($title === '')
{
$title = $site_url;
}
- if ($attributes != '')
+ if ($attributes !== '')
{
- $attributes = _parse_attributes($attributes);
+ $attributes = _stringify_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
@@ -173,98 +174,105 @@ if ( ! function_exists('anchor'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link - Pop-up version
- *
- * Creates an anchor based on the local URL. The link
- * opens a new window based on the attributes specified.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor_popup'))
{
+ /**
+ * Anchor Link - Pop-up version
+ *
+ * Creates an anchor based on the local URL. The link
+ * opens a new window based on the attributes specified.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
$title = (string) $title;
$site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri);
- if ($title == '')
+ if ($title === '')
{
$title = $site_url;
}
if ($attributes === FALSE)
{
- return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank');\">".$title.'</a>';
+ return '<a href="'.$site_url.'" onclick="window.open(\''.$site_url."', '_blank'); return false;\">".$title.'</a>';
}
if ( ! is_array($attributes))
{
- $attributes = array();
+ $attributes = array($attributes);
+
+ // Ref: http://www.w3schools.com/jsref/met_win_open.asp
+ $window_name = '_blank';
+ }
+ elseif ( ! empty($attributes['window_name']))
+ {
+ $window_name = $attributes['window_name'];
+ unset($attributes['window_name']);
}
- foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
+ foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0') as $key => $val)
{
$atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val;
unset($attributes[$key]);
}
- if ($attributes != '')
- {
- $attributes = _parse_attributes($attributes);
- }
+ $attributes = _stringify_attributes($attributes);
- return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"".$attributes.'>'.$title.'</a>';
+ return '<a href="'.$site_url
+ .'" onclick="window.open(\''.$site_url."', '".$window_name."', '"._stringify_attributes($atts, TRUE)."'); return false;\""
+ .$attributes.'>'.$title.'</a>';
}
}
// ------------------------------------------------------------------------
-/**
- * Mailto Link
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('mailto'))
{
+ /**
+ * Mailto Link
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
- if ($title == '')
+ if ($title === '')
{
$title = $email;
}
- return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
+ return '<a href="mailto:'.$email.'"'._stringify_attributes($attributes).'>'.$title.'</a>';
}
}
// ------------------------------------------------------------------------
-/**
- * Encoded Mailto Link
- *
- * Create a spam-protected mailto link written in Javascript
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('safe_mailto'))
{
+ /**
+ * Encoded Mailto Link
+ *
+ * Create a spam-protected mailto link written in Javascript
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function safe_mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
- if ($title == '')
+ if ($title === '')
{
$title = $email;
}
@@ -278,7 +286,7 @@ if ( ! function_exists('safe_mailto'))
$x[] = '"';
- if ($attributes != '')
+ if ($attributes !== '')
{
if (is_array($attributes))
{
@@ -344,7 +352,7 @@ if ( ! function_exists('safe_mailto'))
for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?>
for (var i = l.length-1; i >= 0; i=i-1){
- if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
+ if (l[i].substring(0, 1) === '|') document.write("&#"+unescape(l[i].substring(1))+";");
else document.write(unescape(l[i]));}
//]]>
</script><?php
@@ -357,21 +365,21 @@ if ( ! function_exists('safe_mailto'))
// ------------------------------------------------------------------------
-/**
- * Auto-linker
- *
- * Automatically links URL and Email addresses.
- * Note: There's a bit of extra code here to deal with
- * URLs or emails that end in a period. We'll strip these
- * off and add them after the link.
- *
- * @param string the string
- * @param string the type: email, url, or both
- * @param bool whether to create pop-up links
- * @return string
- */
if ( ! function_exists('auto_link'))
{
+ /**
+ * Auto-linker
+ *
+ * Automatically links URL and Email addresses.
+ * Note: There's a bit of extra code here to deal with
+ * URLs or emails that end in a period. We'll strip these
+ * off and add them after the link.
+ *
+ * @param string the string
+ * @param string the type: email, url, or both
+ * @param bool whether to create pop-up links
+ * @return string
+ */
function auto_link($str, $type = 'both', $popup = FALSE)
{
if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
@@ -423,19 +431,19 @@ if ( ! function_exists('auto_link'))
// ------------------------------------------------------------------------
-/**
- * Prep URL
- *
- * Simply adds the http:// part if no scheme is included
- *
- * @param string the URL
- * @return string
- */
if ( ! function_exists('prep_url'))
{
+ /**
+ * Prep URL
+ *
+ * Simply adds the http:// part if no scheme is included
+ *
+ * @param string the URL
+ * @return string
+ */
function prep_url($str = '')
{
- if ($str === 'http://' OR $str == '')
+ if ($str === 'http://' OR $str === '')
{
return '';
}
@@ -453,20 +461,20 @@ if ( ! function_exists('prep_url'))
// ------------------------------------------------------------------------
-/**
- * Create URL Title
- *
- * Takes a "title" string as input and creates a
- * human-friendly URL string with a "separator" string
- * as the word separator.
- *
- * @param string the string
- * @param string the separator
- * @param bool
- * @return string
- */
if ( ! function_exists('url_title'))
{
+ /**
+ * Create URL Title
+ *
+ * Takes a "title" string as input and creates a
+ * human-friendly URL string with a "separator" string
+ * as the word separator.
+ *
+ * @param string the string
+ * @param string the separator
+ * @param bool
+ * @return string
+ */
function url_title($str, $separator = '-', $lowercase = FALSE)
{
if ($separator === 'dash')
@@ -504,20 +512,21 @@ if ( ! function_exists('url_title'))
// ------------------------------------------------------------------------
-/**
- * Header Redirect
- *
- * Header redirect in two flavors
- * For very fine grained control over headers, you could use the Output
- * Library's set_header() function.
- *
- * @param string the URL
- * @param string the method: location or refresh
- * @return string
- */
if ( ! function_exists('redirect'))
{
- function redirect($uri = '', $method = 'auto', $http_response_code = 302)
+ /**
+ * Header Redirect
+ *
+ * Header redirect in two flavors
+ * For very fine grained control over headers, you could use the Output
+ * Library's set_header() function.
+ *
+ * @param string the URL
+ * @param string the method: location or refresh
+ * @param int
+ * @return string
+ */
+ function redirect($uri = '', $method = 'auto', $code = NULL)
{
if ( ! preg_match('#^https?://#i', $uri))
{
@@ -525,65 +534,31 @@ if ( ! function_exists('redirect'))
}
// IIS environment likely? Use 'refresh' for better compatibility
- if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
+ if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
$method = 'refresh';
}
+ elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
+ {
+ // Reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
+ $code = (isset($_SERVER['REQUEST_METHOD'], $_SERVER['SERVER_PROTOCOL'])
+ && $_SERVER['REQUEST_METHOD'] === 'POST'
+ && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
+ ? 303 : 302;
+ }
- switch($method)
+ switch ($method)
{
case 'refresh':
header('Refresh:0;url='.$uri);
break;
default:
- header('Location: '.$uri, TRUE, $http_response_code);
+ header('Location: '.$uri, TRUE, $code);
break;
}
exit;
}
}
-// ------------------------------------------------------------------------
-
-/**
- * Parse out the attributes
- *
- * Some of the functions use this
- *
- * @param array
- * @param bool
- * @return string
- */
-if ( ! function_exists('_parse_attributes'))
-{
- function _parse_attributes($attributes, $javascript = FALSE)
- {
- if (is_string($attributes))
- {
- return ($attributes != '') ? ' '.$attributes : '';
- }
-
- $att = '';
- foreach ($attributes as $key => $val)
- {
- if ($javascript == TRUE)
- {
- $att .= $key.'='.$val.',';
- }
- else
- {
- $att .= ' '.$key.'="'.$val.'"';
- }
- }
-
- if ($javascript == TRUE && $att != '')
- {
- return substr($att, 0, -1);
- }
-
- return $att;
- }
-}
-
/* End of file url_helper.php */
/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 67fd34b97..1431777d2 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Convert Reserved XML characters to Entities
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('xml_convert'))
{
+ /**
+ * Convert Reserved XML characters to Entities
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function xml_convert($str, $protect_all = FALSE)
{
$temp = '__TEMP_AMPERSANDS__';
@@ -54,7 +54,7 @@ if ( ! function_exists('xml_convert'))
// ampersands won't get messed up
$str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str);
- if ($protect_all == TRUE)
+ if ($protect_all === TRUE)
{
$str = preg_replace('/&(\w+);/', $temp.'\\1;', $str);
}
@@ -66,7 +66,7 @@ if ( ! function_exists('xml_convert'))
// Decode the temp markers back to entities
$str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str);
- if ($protect_all == TRUE)
+ if ($protect_all === TRUE)
{
return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str);
}
diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php
index 2d477e6c8..a70a564e8 100644
--- a/system/language/english/calendar_lang.php
+++ b/system/language/english/calendar_lang.php
@@ -5,9 +5,9 @@
* 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,52 +25,51 @@
* @filesource
*/
-$lang['cal_su'] = "Su";
-$lang['cal_mo'] = "Mo";
-$lang['cal_tu'] = "Tu";
-$lang['cal_we'] = "We";
-$lang['cal_th'] = "Th";
-$lang['cal_fr'] = "Fr";
-$lang['cal_sa'] = "Sa";
-$lang['cal_sun'] = "Sun";
-$lang['cal_mon'] = "Mon";
-$lang['cal_tue'] = "Tue";
-$lang['cal_wed'] = "Wed";
-$lang['cal_thu'] = "Thu";
-$lang['cal_fri'] = "Fri";
-$lang['cal_sat'] = "Sat";
-$lang['cal_sunday'] = "Sunday";
-$lang['cal_monday'] = "Monday";
-$lang['cal_tuesday'] = "Tuesday";
-$lang['cal_wednesday'] = "Wednesday";
-$lang['cal_thursday'] = "Thursday";
-$lang['cal_friday'] = "Friday";
-$lang['cal_saturday'] = "Saturday";
-$lang['cal_jan'] = "Jan";
-$lang['cal_feb'] = "Feb";
-$lang['cal_mar'] = "Mar";
-$lang['cal_apr'] = "Apr";
-$lang['cal_may'] = "May";
-$lang['cal_jun'] = "Jun";
-$lang['cal_jul'] = "Jul";
-$lang['cal_aug'] = "Aug";
-$lang['cal_sep'] = "Sep";
-$lang['cal_oct'] = "Oct";
-$lang['cal_nov'] = "Nov";
-$lang['cal_dec'] = "Dec";
-$lang['cal_january'] = "January";
-$lang['cal_february'] = "February";
-$lang['cal_march'] = "March";
-$lang['cal_april'] = "April";
-$lang['cal_mayl'] = "May";
-$lang['cal_june'] = "June";
-$lang['cal_july'] = "July";
-$lang['cal_august'] = "August";
-$lang['cal_september'] = "September";
-$lang['cal_october'] = "October";
-$lang['cal_november'] = "November";
-$lang['cal_december'] = "December";
-
+$lang['cal_su'] = 'Su';
+$lang['cal_mo'] = 'Mo';
+$lang['cal_tu'] = 'Tu';
+$lang['cal_we'] = 'We';
+$lang['cal_th'] = 'Th';
+$lang['cal_fr'] = 'Fr';
+$lang['cal_sa'] = 'Sa';
+$lang['cal_sun'] = 'Sun';
+$lang['cal_mon'] = 'Mon';
+$lang['cal_tue'] = 'Tue';
+$lang['cal_wed'] = 'Wed';
+$lang['cal_thu'] = 'Thu';
+$lang['cal_fri'] = 'Fri';
+$lang['cal_sat'] = 'Sat';
+$lang['cal_sunday'] = 'Sunday';
+$lang['cal_monday'] = 'Monday';
+$lang['cal_tuesday'] = 'Tuesday';
+$lang['cal_wednesday'] = 'Wednesday';
+$lang['cal_thursday'] = 'Thursday';
+$lang['cal_friday'] = 'Friday';
+$lang['cal_saturday'] = 'Saturday';
+$lang['cal_jan'] = 'Jan';
+$lang['cal_feb'] = 'Feb';
+$lang['cal_mar'] = 'Mar';
+$lang['cal_apr'] = 'Apr';
+$lang['cal_may'] = 'May';
+$lang['cal_jun'] = 'Jun';
+$lang['cal_jul'] = 'Jul';
+$lang['cal_aug'] = 'Aug';
+$lang['cal_sep'] = 'Sep';
+$lang['cal_oct'] = 'Oct';
+$lang['cal_nov'] = 'Nov';
+$lang['cal_dec'] = 'Dec';
+$lang['cal_january'] = 'January';
+$lang['cal_february'] = 'February';
+$lang['cal_march'] = 'March';
+$lang['cal_april'] = 'April';
+$lang['cal_mayl'] = 'May';
+$lang['cal_june'] = 'June';
+$lang['cal_july'] = 'July';
+$lang['cal_august'] = 'August';
+$lang['cal_september'] = 'September';
+$lang['cal_october'] = 'October';
+$lang['cal_november'] = 'November';
+$lang['cal_december'] = 'December';
/* End of file calendar_lang.php */
/* Location: ./system/language/english/calendar_lang.php */ \ No newline at end of file
diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php
index 533563700..6683e4c69 100644
--- a/system/language/english/date_lang.php
+++ b/system/language/english/date_lang.php
@@ -5,9 +5,9 @@
* 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,20 +25,20 @@
* @filesource
*/
-$lang['date_year'] = "Year";
-$lang['date_years'] = "Years";
-$lang['date_month'] = "Month";
-$lang['date_months'] = "Months";
-$lang['date_week'] = "Week";
-$lang['date_weeks'] = "Weeks";
-$lang['date_day'] = "Day";
-$lang['date_days'] = "Days";
-$lang['date_hour'] = "Hour";
-$lang['date_hours'] = "Hours";
-$lang['date_minute'] = "Minute";
-$lang['date_minutes'] = "Minutes";
-$lang['date_second'] = "Second";
-$lang['date_seconds'] = "Seconds";
+$lang['date_year'] = 'Year';
+$lang['date_years'] = 'Years';
+$lang['date_month'] = 'Month';
+$lang['date_months'] = 'Months';
+$lang['date_week'] = 'Week';
+$lang['date_weeks'] = 'Weeks';
+$lang['date_day'] = 'Day';
+$lang['date_days'] = 'Days';
+$lang['date_hour'] = 'Hour';
+$lang['date_hours'] = 'Hours';
+$lang['date_minute'] = 'Minute';
+$lang['date_minutes'] = 'Minutes';
+$lang['date_second'] = 'Second';
+$lang['date_seconds'] = 'Seconds';
$lang['UM12'] = '(UTC -12:00) Baker/Howland Island';
$lang['UM11'] = '(UTC -11:00) Niue';
@@ -81,6 +81,5 @@ $lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time';
$lang['UP13'] = '(UTC +13:00) Samoa Time Zone, Phoenix Islands Time, Tonga';
$lang['UP14'] = '(UTC +14:00) Line Islands';
-
/* End of file date_lang.php */
/* Location: ./system/language/english/date_lang.php */ \ No newline at end of file
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index a135d1aac..479cbb167 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -5,9 +5,9 @@
* 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:
diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php
index 23296a244..0de9aa27e 100644
--- a/system/language/english/email_lang.php
+++ b/system/language/english/email_lang.php
@@ -5,9 +5,9 @@
* 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,25 +25,24 @@
* @filesource
*/
-$lang['email_must_be_array'] = "The email validation method must be passed an array.";
-$lang['email_invalid_address'] = "Invalid email address: %s";
-$lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s";
-$lang['email_attachment_unreadable'] = "Unable to open this attachment: %s";
-$lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc";
-$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.";
-$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.";
-$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.";
-$lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s";
-$lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings.";
-$lang['email_no_hostname'] = "You did not specify a SMTP hostname.";
-$lang['email_smtp_error'] = "The following SMTP error was encountered: %s";
-$lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password.";
-$lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s";
-$lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s";
-$lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s";
-$lang['email_smtp_data_failure'] = "Unable to send data: %s";
-$lang['email_exit_status'] = "Exit status code: %s";
-
+$lang['email_must_be_array'] = 'The email validation method must be passed an array.';
+$lang['email_invalid_address'] = 'Invalid email address: %s';
+$lang['email_attachment_missing'] = 'Unable to locate the following email attachment: %s';
+$lang['email_attachment_unreadable'] = 'Unable to open this attachment: %s';
+$lang['email_no_recipients'] = 'You must include recipients: To, Cc, or Bcc';
+$lang['email_send_failure_phpmail'] = 'Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.';
+$lang['email_send_failure_sendmail'] = 'Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.';
+$lang['email_send_failure_smtp'] = 'Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.';
+$lang['email_sent'] = 'Your message has been successfully sent using the following protocol: %s';
+$lang['email_no_socket'] = 'Unable to open a socket to Sendmail. Please check settings.';
+$lang['email_no_hostname'] = 'You did not specify a SMTP hostname.';
+$lang['email_smtp_error'] = 'The following SMTP error was encountered: %s';
+$lang['email_no_smtp_unpw'] = 'Error: You must assign a SMTP username and password.';
+$lang['email_failed_smtp_login'] = 'Failed to send AUTH LOGIN command. Error: %s';
+$lang['email_smtp_auth_un'] = 'Failed to authenticate username. Error: %s';
+$lang['email_smtp_auth_pw'] = 'Failed to authenticate password. Error: %s';
+$lang['email_smtp_data_failure'] = 'Unable to send data: %s';
+$lang['email_exit_status'] = 'Exit status code: %s';
/* End of file email_lang.php */
/* Location: ./system/language/english/email_lang.php */ \ No newline at end of file
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 6cf0b46f4..cf1b3b503 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -5,9 +5,9 @@
* 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,32 +25,31 @@
* @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['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.";
-
+$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 only contain digits.';
+$lang['is_natural_no_zero'] = 'The %s field must only contain digits and must be 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 */
+/* Location: ./system/language/english/form_validation_lang.php */ \ No newline at end of file
diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php
index 4e39e43bf..24923c8d8 100644
--- a/system/language/english/ftp_lang.php
+++ b/system/language/english/ftp_lang.php
@@ -5,9 +5,9 @@
* 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,19 +25,18 @@
* @filesource
*/
-$lang['ftp_no_connection'] = "Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines.";
-$lang['ftp_unable_to_connect'] = "Unable to connect to your FTP server using the supplied hostname.";
-$lang['ftp_unable_to_login'] = "Unable to login to your FTP server. Please check your username and password.";
-$lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specified.";
-$lang['ftp_unable_to_changedir'] = "Unable to change directories.";
-$lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher.";
-$lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path.";
-$lang['ftp_unable_to_download'] = "Unable to download the specified file. Please check your path.";
-$lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path.";
-$lang['ftp_unable_to_rename'] = "Unable to rename the file.";
-$lang['ftp_unable_to_delete'] = "Unable to delete the file.";
-$lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists.";
-
+$lang['ftp_no_connection'] = 'Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines.';
+$lang['ftp_unable_to_connect'] = 'Unable to connect to your FTP server using the supplied hostname.';
+$lang['ftp_unable_to_login'] = 'Unable to login to your FTP server. Please check your username and password.';
+$lang['ftp_unable_to_makdir'] = 'Unable to create the directory you have specified.';
+$lang['ftp_unable_to_changedir'] = 'Unable to change directories.';
+$lang['ftp_unable_to_chmod'] = 'Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher.';
+$lang['ftp_unable_to_upload'] = 'Unable to upload the specified file. Please check your path.';
+$lang['ftp_unable_to_download'] = 'Unable to download the specified file. Please check your path.';
+$lang['ftp_no_source_file'] = 'Unable to locate the source file. Please check your path.';
+$lang['ftp_unable_to_rename'] = 'Unable to rename the file.';
+$lang['ftp_unable_to_delete'] = 'Unable to delete the file.';
+$lang['ftp_unable_to_move'] = 'Unable to move the file. Please make sure the destination directory exists.';
/* End of file ftp_lang.php */
/* Location: ./system/language/english/ftp_lang.php */ \ No newline at end of file
diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php
index 67ca94277..d755437f2 100644
--- a/system/language/english/imglib_lang.php
+++ b/system/language/english/imglib_lang.php
@@ -5,9 +5,9 @@
* 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,25 +25,24 @@
* @filesource
*/
-$lang['imglib_source_image_required'] = "You must specify a source image in your preferences.";
-$lang['imglib_gd_required'] = "The GD image library is required for this feature.";
-$lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties.";
-$lang['imglib_unsupported_imagecreate'] = "Your server does not support the GD function required to process this type of image.";
-$lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead.";
-$lang['imglib_jpg_not_supported'] = "JPG images are not supported.";
-$lang['imglib_png_not_supported'] = "PNG images are not supported.";
-$lang['imglib_jpg_or_png_required'] = "The image resize protocol specified in your preferences only works with JPEG or PNG image types.";
-$lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable.";
-$lang['imglib_rotate_unsupported'] = "Image rotation does not appear to be supported by your server.";
-$lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences.";
-$lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct.";
-$lang['imglib_rotation_angle_required'] = "An angle of rotation is required to rotate the image.";
-$lang['imglib_writing_failed_gif'] = "GIF image.";
-$lang['imglib_invalid_path'] = "The path to the image is not correct.";
-$lang['imglib_copy_failed'] = "The image copy routine failed.";
-$lang['imglib_missing_font'] = "Unable to find a font to use.";
-$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable.";
-
+$lang['imglib_source_image_required'] = 'You must specify a source image in your preferences.';
+$lang['imglib_gd_required'] = 'The GD image library is required for this feature.';
+$lang['imglib_gd_required_for_props'] = 'Your server must support the GD image library in order to determine the image properties.';
+$lang['imglib_unsupported_imagecreate'] = 'Your server does not support the GD function required to process this type of image.';
+$lang['imglib_gif_not_supported'] = 'GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead.';
+$lang['imglib_jpg_not_supported'] = 'JPG images are not supported.';
+$lang['imglib_png_not_supported'] = 'PNG images are not supported.';
+$lang['imglib_jpg_or_png_required'] = 'The image resize protocol specified in your preferences only works with JPEG or PNG image types.';
+$lang['imglib_copy_error'] = 'An error was encountered while attempting to replace the file. Please make sure your file directory is writable.';
+$lang['imglib_rotate_unsupported'] = 'Image rotation does not appear to be supported by your server.';
+$lang['imglib_libpath_invalid'] = 'The path to your image library is not correct. Please set the correct path in your image preferences.';
+$lang['imglib_image_process_failed'] = 'Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct.';
+$lang['imglib_rotation_angle_required'] = 'An angle of rotation is required to rotate the image.';
+$lang['imglib_writing_failed_gif'] = 'GIF image.';
+$lang['imglib_invalid_path'] = 'The path to the image is not correct.';
+$lang['imglib_copy_failed'] = 'The image copy routine failed.';
+$lang['imglib_missing_font'] = 'Unable to find a font to use.';
+$lang['imglib_save_failed'] = 'Unable to save the image. Please make sure the image and file directory are writable.';
/* End of file imglib_lang.php */
/* Location: ./system/language/english/imglib_lang.php */ \ No newline at end of file
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
index 2085cee2a..5753c00bf 100644
--- a/system/language/english/migration_lang.php
+++ b/system/language/english/migration_lang.php
@@ -5,9 +5,9 @@
* 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,13 +25,13 @@
* @filesource
*/
-$lang['migration_none_found'] = "No migrations were found.";
-$lang['migration_not_found'] = "This migration could not be found.";
-$lang['migration_multiple_version'] = "This are multiple migrations with the same version number: %d.";
-$lang['migration_class_doesnt_exist'] = "The migration class \"%s\" could not be found.";
-$lang['migration_missing_up_method'] = "The migration class \"%s\" is missing an 'up' method.";
-$lang['migration_missing_down_method'] = "The migration class \"%s\" is missing a 'down' method.";
-$lang['migration_invalid_filename'] = "Migration \"%s\" has an invalid filename.";
+$lang['migration_none_found'] = 'No migrations were found.';
+$lang['migration_not_found'] = 'No migration could be found with the version number: %d.';
+$lang['migration_multiple_version'] = 'There are multiple migrations with the same version number: %d.';
+$lang['migration_class_doesnt_exist'] = 'The migration class "%s" could not be found.';
+$lang['migration_missing_up_method'] = 'The migration class "%s" is missing an "up" method.';
+$lang['migration_missing_down_method'] = 'The migration class "%s" is missing a "down" method.';
+$lang['migration_invalid_filename'] = 'Migration "%s" has an invalid filename.';
/* End of file migration_lang.php */
diff --git a/system/language/english/number_lang.php b/system/language/english/number_lang.php
index 0c19ec614..429c64738 100644
--- a/system/language/english/number_lang.php
+++ b/system/language/english/number_lang.php
@@ -5,9 +5,9 @@
* 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,11 +25,11 @@
* @filesource
*/
-$lang['terabyte_abbr'] = "TB";
-$lang['gigabyte_abbr'] = "GB";
-$lang['megabyte_abbr'] = "MB";
-$lang['kilobyte_abbr'] = "KB";
-$lang['bytes'] = "Bytes";
+$lang['terabyte_abbr'] = 'TB';
+$lang['gigabyte_abbr'] = 'GB';
+$lang['megabyte_abbr'] = 'MB';
+$lang['kilobyte_abbr'] = 'KB';
+$lang['bytes'] = 'Bytes';
/* End of file number_lang.php */
/* Location: ./system/language/english/number_lang.php */ \ No newline at end of file
diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php
index 11d791272..112527faa 100644
--- a/system/language/english/profiler_lang.php
+++ b/system/language/english/profiler_lang.php
@@ -5,9 +5,9 @@
* 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:
diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php
index 3a8e14403..146ec25b4 100644
--- a/system/language/english/unit_test_lang.php
+++ b/system/language/english/unit_test_lang.php
@@ -5,9 +5,9 @@
* 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:
@@ -45,6 +45,5 @@ $lang['ut_resource'] = 'Resource';
$lang['ut_null'] = 'Null';
$lang['ut_notes'] = 'Notes';
-
/* End of file unit_test_lang.php */
/* Location: ./system/language/english/unit_test_lang.php */ \ No newline at end of file
diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php
index 4fa8394ec..d70e7f20f 100644
--- a/system/language/english/upload_lang.php
+++ b/system/language/english/upload_lang.php
@@ -5,9 +5,9 @@
* 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,23 +25,22 @@
* @filesource
*/
-$lang['upload_userfile_not_set'] = "Unable to find a post variable called userfile.";
-$lang['upload_file_exceeds_limit'] = "The uploaded file exceeds the maximum allowed size in your PHP configuration file.";
-$lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form.";
-$lang['upload_file_partial'] = "The file was only partially uploaded.";
-$lang['upload_no_temp_directory'] = "The temporary folder is missing.";
-$lang['upload_unable_to_write_file'] = "The file could not be written to disk.";
-$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 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.";
-$lang['upload_bad_filename'] = "The file name you submitted already exists on the server.";
-$lang['upload_not_writable'] = "The upload destination folder does not appear to be writable.";
-
+$lang['upload_userfile_not_set'] = 'Unable to find a post variable called userfile.';
+$lang['upload_file_exceeds_limit'] = 'The uploaded file exceeds the maximum allowed size in your PHP configuration file.';
+$lang['upload_file_exceeds_form_limit'] = 'The uploaded file exceeds the maximum size allowed by the submission form.';
+$lang['upload_file_partial'] = 'The file was only partially uploaded.';
+$lang['upload_no_temp_directory'] = 'The temporary folder is missing.';
+$lang['upload_unable_to_write_file'] = 'The file could not be written to disk.';
+$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 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.';
+$lang['upload_bad_filename'] = 'The file name you submitted already exists on the server.';
+$lang['upload_not_writable'] = 'The upload destination folder does not appear to be writable.';
/* End of file upload_lang.php */
/* Location: ./system/language/english/upload_lang.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index ba732ee8e..4395cf411 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -41,11 +41,12 @@ class CI_Cache extends CI_Driver_Library {
*
* @var array
*/
- protected $valid_drivers = array(
+ protected $valid_drivers = array(
'cache_apc',
+ 'cache_dummy',
'cache_file',
'cache_memcached',
- 'cache_dummy',
+ 'cache_redis',
'cache_wincache'
);
@@ -68,7 +69,7 @@ class CI_Cache extends CI_Driver_Library {
*
* @param string
*/
- protected $_backup_driver;
+ protected $_backup_driver = 'dummy';
/**
* Constructor
@@ -102,6 +103,22 @@ class CI_Cache extends CI_Driver_Library {
$this->_backup_driver = $config['backup'];
}
}
+
+ // If the specified adapter isn't available, check the backup.
+ if ( ! $this->is_supported($this->_adapter))
+ {
+ if ( ! $this->is_supported($this->_backup_driver))
+ {
+ // Backup isn't supported either. Default to 'Dummy' driver.
+ log_message('error', 'Cache adapter "'.$this->_adapter.'" and backup "'.$this->_backup_driver.'" are both unavailable. Cache is now using "Dummy" adapter.');
+ $this->_adapter = 'dummy';
+ }
+ else
+ {
+ // Backup is supported. Set it to primary.
+ $this->_adapter = $this->_backup_driver;
+ }
+ }
}
// ------------------------------------------------------------------------
@@ -206,26 +223,6 @@ class CI_Cache extends CI_Driver_Library {
return $support[$driver];
}
- // ------------------------------------------------------------------------
-
- /**
- * __get()
- *
- * @param child
- * @return object
- */
- public function __get($child)
- {
- $obj = parent::__get($child);
-
- if ( ! $this->is_supported($child))
- {
- $this->_adapter = $this->_backup_driver;
- }
-
- return $obj;
- }
-
}
/* End of file Cache.php */
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index f0eb8bdf7..37d77c268 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -26,7 +26,7 @@
*/
/**
- * CodeIgniter Memcached Caching Class
+ * CodeIgniter File Caching Class
*
* @package CodeIgniter
* @subpackage Libraries
@@ -53,7 +53,7 @@ class CI_Cache_file extends CI_Driver {
$CI =& get_instance();
$CI->load->helper('file');
$path = $CI->config->item('cache_path');
- $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
+ $this->_cache_path = ($path === '') ? APPPATH.'cache/' : $path;
}
// ------------------------------------------------------------------------
@@ -71,9 +71,9 @@ class CI_Cache_file extends CI_Driver {
return FALSE;
}
- $data = unserialize(read_file($this->_cache_path.$id));
+ $data = unserialize(file_get_contents($this->_cache_path.$id));
- if (time() > $data['time'] + $data['ttl'])
+ if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl'])
{
unlink($this->_cache_path.$id);
return FALSE;
@@ -165,19 +165,19 @@ class CI_Cache_file extends CI_Driver {
return FALSE;
}
- $data = unserialize(read_file($this->_cache_path.$id));
+ $data = unserialize(file_get_contents($this->_cache_path.$id));
if (is_array($data))
{
$mtime = filemtime($this->_cache_path.$id);
- if ( ! isset($data['data']['ttl']))
+ if ( ! isset($data['ttl']))
{
return FALSE;
}
return array(
- 'expire' => $mtime + $data['data']['ttl'],
+ 'expire' => $mtime + $data['ttl'],
'mtime' => $mtime
);
}
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 1df149c2d..bf90f6197 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -212,7 +212,7 @@ class CI_Cache_memcached extends CI_Driver {
$cache_server['weight'] = $this->_memcache_conf['default']['default_weight'];
}
- if (get_class($this->_memcached) == 'Memcache')
+ if (get_class($this->_memcached) === 'Memcache')
{
// Third parameter is persistance and defaults to TRUE.
$this->_memcached->addServer(
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
new file mode 100644
index 000000000..e4a26b5f0
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -0,0 +1,236 @@
+<?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) 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 Redis Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author Anton Lindqvist <anton@qvister.se>
+ * @link
+ */
+class CI_Cache_redis extends CI_Driver
+{
+ /**
+ * Default config
+ *
+ * @static
+ * @var array
+ */
+ protected static $_default_config = array(
+ 'host' => '127.0.0.1',
+ 'password' => NULL,
+ 'port' => 6379,
+ 'timeout' => 0
+ );
+
+ /**
+ * Redis connection
+ *
+ * @var Redis
+ */
+ protected $_redis;
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache
+ *
+ * @param string Cache key identifier
+ * @return mixed
+ */
+ public function get($key)
+ {
+ return $this->_redis->get($key);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save cache
+ *
+ * @param string Cache key identifier
+ * @param mixed Data to save
+ * @param int Time to live
+ * @return bool
+ */
+ public function save($key, $value, $ttl = NULL)
+ {
+ return ($ttl)
+ ? $this->_redis->setex($key, $ttl, $value)
+ : $this->_redis->set($key, $value);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from cache
+ *
+ * @param string Cache key
+ * @return bool
+ */
+ public function delete($key)
+ {
+ return ($this->_redis->delete($key) === 1);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean cache
+ *
+ * @return bool
+ * @see Redis::flushDB()
+ */
+ public function clean()
+ {
+ return $this->_redis->flushDB();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache driver info
+ *
+ * @param string Not supported in Redis.
+ * Only included in order to offer a
+ * consistent cache API.
+ * @return array
+ * @see Redis::info()
+ */
+ public function cache_info($type = NULL)
+ {
+ return $this->_redis->info();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache metadata
+ *
+ * @param string Cache key
+ * @return array
+ */
+ public function get_metadata($key)
+ {
+ $value = $this->get($key);
+
+ if ($value)
+ {
+ return array(
+ 'expire' => time() + $this->_redis->ttl($key),
+ 'data' => $value
+ );
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Check if Redis driver is supported
+ *
+ * @return bool
+ */
+ public function is_supported()
+ {
+ if (extension_loaded('redis'))
+ {
+ $this->_setup_redis();
+ return TRUE;
+ }
+ else
+ {
+ log_message('error', 'The Redis extension must be loaded to use Redis cache.');
+ return FALSE;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Setup Redis config and connection
+ *
+ * Loads Redis config file if present. Will halt execution
+ * if a Redis connection can't be established.
+ *
+ * @return bool
+ * @see Redis::connect()
+ */
+ protected function _setup_redis()
+ {
+ $config = array();
+ $CI =& get_instance();
+
+ if ($CI->config->load('redis', TRUE, TRUE))
+ {
+ $config += $CI->config->item('redis');
+ }
+
+ $config = array_merge(self::$_default_config, $config);
+
+ $this->_redis = new Redis();
+
+ try
+ {
+ $this->_redis->connect($config['host'], $config['port'], $config['timeout']);
+ }
+ catch (RedisException $e)
+ {
+ show_error('Redis connection refused. ' . $e->getMessage());
+ }
+
+ if (isset($config['password']))
+ {
+ $this->_redis->auth($config['password']);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+
+ * Class destructor
+ *
+ * Closes the connection to Redis if present.
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->_redis)
+ {
+ $this->_redis->close();
+ }
+ }
+
+}
+
+/* End of file Cache_redis.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_redis.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index 74048d564..89e9f77c8 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.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/Calendar.php b/system/libraries/Calendar.php
index 92f372b20..a49f171b9 100644
--- a/system/libraries/Calendar.php
+++ b/system/libraries/Calendar.php
@@ -155,7 +155,7 @@ class CI_Calendar {
public function generate($year = '', $month = '', $data = array())
{
// Set and validate the supplied month/year
- if ($year == '')
+ if (empty($year))
{
$year = date('Y', $this->local_time);
}
@@ -168,7 +168,7 @@ class CI_Calendar {
$year = '20'.$year;
}
- if ($month == '')
+ if (empty($month))
{
$month = date('m', $this->local_time);
}
@@ -214,7 +214,7 @@ class CI_Calendar {
$out = $this->temp['table_open']."\n\n".$this->temp['heading_row_start']."\n";
// "previous" month link
- if ($this->show_next_prev == TRUE)
+ if ($this->show_next_prev === TRUE)
{
// Add a trailing slash to the URL if needed
$this->next_prev_url = preg_replace('/(.+?)\/*$/', '\\1/', $this->next_prev_url);
@@ -224,7 +224,7 @@ class CI_Calendar {
}
// Heading containing the month/year
- $colspan = ($this->show_next_prev == TRUE) ? 5 : 7;
+ $colspan = ($this->show_next_prev === TRUE) ? 5 : 7;
$this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan,
str_replace('{heading}', $this->get_month_name($month).'&nbsp;'.$year, $this->temp['heading_title_cell']));
@@ -232,7 +232,7 @@ class CI_Calendar {
$out .= $this->temp['heading_title_cell']."\n";
// "next" month link
- if ($this->show_next_prev == TRUE)
+ if ($this->show_next_prev === TRUE)
{
$adjusted_date = $this->adjust_date($month + 1, $year);
$out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']);
@@ -306,7 +306,7 @@ class CI_Calendar {
*/
public function get_month_name($month)
{
- if ($this->month_type == 'short')
+ if ($this->month_type === 'short')
{
$month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec');
}
@@ -333,7 +333,7 @@ class CI_Calendar {
*/
public function get_day_names($day_type = '')
{
- if ($day_type != '')
+ if ($day_type !== '')
{
$this->day_type = $day_type;
}
@@ -421,7 +421,7 @@ class CI_Calendar {
// Is the year a leap year?
if ($month == 2)
{
- if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0))
+ if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0))
{
return 29;
}
@@ -480,7 +480,7 @@ class CI_Calendar {
{
$this->temp = $this->default_template();
- if ($this->template == '')
+ if ($this->template === '')
{
return;
}
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index b73ed5128..c442f88da 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -245,7 +245,7 @@ class CI_Cart {
// This becomes the unique "row ID"
if (isset($items['options']) && count($items['options']) > 0)
{
- $rowid = md5($items['id'].implode('', $items['options']));
+ $rowid = md5($items['id'].serialize($items['options']));
}
else
{
@@ -520,7 +520,7 @@ class CI_Cart {
*/
public function format_number($n = '')
{
- return ($n == '') ? '' : number_format( (float) $n, 2, '.', ',');
+ return ($n === '') ? '' : number_format( (float) $n, 2, '.', ',');
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index c79698c7b..1d084c8e4 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -51,16 +51,32 @@ class CI_Driver_Library {
*
* @var string
*/
- protected static $lib_name;
+ protected $lib_name;
/**
+ * Get magic method
+ *
* The first time a child is used it won't exist, so we instantiate it
* subsequents calls will go straight to the proper child.
*
- * @param mixed $child
- * @return mixed
+ * @param string Child class name
+ * @return object Child class
*/
public function __get($child)
+ {
+ // Try to load the driver
+ return $this->load_driver($child);
+ }
+
+ /**
+ * Load driver
+ *
+ * Separate load_driver call to support explicit driver load by library or user
+ *
+ * @param string Child class name
+ * @return object Child class
+ */
+ public function load_driver($child)
{
if ( ! isset($this->lib_name))
{
@@ -268,4 +284,4 @@ class CI_Driver {
}
/* End of file Driver.php */
-/* Location: ./system/libraries/Driver.php */ \ No newline at end of file
+/* Location: ./system/libraries/Driver.php */
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 56d60c802..4776df498 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -104,7 +104,7 @@ class CI_Email {
}
else
{
- $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === '');
$this->_safe_mode = (bool) @ini_get('safe_mode');
}
@@ -139,7 +139,7 @@ class CI_Email {
}
$this->clear();
- $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
+ $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === '');
$this->_safe_mode = (bool) @ini_get('safe_mode');
return $this;
@@ -166,8 +166,8 @@ class CI_Email {
$this->_headers = array();
$this->_debug_msg = array();
- $this->_set_header('User-Agent', $this->useragent);
- $this->_set_header('Date', $this->_set_date());
+ $this->set_header('User-Agent', $this->useragent);
+ $this->set_header('Date', $this->_set_date());
if ($clear_attachments !== FALSE)
{
@@ -188,7 +188,7 @@ class CI_Email {
* @param string
* @return object
*/
- public function from($from, $name = '')
+ public function from($from, $name = '', $return_path = '')
{
if (preg_match('/\<(.*)\>/', $from, $match))
{
@@ -198,10 +198,14 @@ class CI_Email {
if ($this->validate)
{
$this->validate_email($this->_str_to_array($from));
+ if ($return_path)
+ {
+ $this->validate_email($this->_str_to_array($return_path));
+ }
}
// prepare the display name
- if ($name != '')
+ if ($name !== '')
{
// only use Q encoding if there are characters that would require it
if ( ! preg_match('/[\200-\377]/', $name))
@@ -215,8 +219,13 @@ class CI_Email {
}
}
- $this->_set_header('From', $name.' <'.$from.'>');
- $this->_set_header('Return-Path', '<'.$from.'>');
+ $this->set_header('From', $name.' <'.$from.'>');
+
+ if( ! $return_path)
+ {
+ $return_path = $from;
+ }
+ $this->set_header('Return-Path', '<'.$return_path.'>');
return $this;
}
@@ -242,17 +251,17 @@ class CI_Email {
$this->validate_email($this->_str_to_array($replyto));
}
- if ($name == '')
+ if ($name === '')
{
$name = $replyto;
}
- if (strncmp($name, '"', 1) !== 0)
+ if (strpos($name, '"') !== 0)
{
$name = '"'.$name.'"';
}
- $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
+ $this->set_header('Reply-To', $name.' <'.$replyto.'>');
$this->_replyto_flag = TRUE;
return $this;
@@ -278,7 +287,7 @@ class CI_Email {
if ($this->_get_protocol() !== 'mail')
{
- $this->_set_header('To', implode(', ', $to));
+ $this->set_header('To', implode(', ', $to));
}
switch ($this->_get_protocol())
@@ -312,7 +321,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,7 +342,7 @@ class CI_Email {
*/
public function bcc($bcc, $limit = '')
{
- if ($limit != '' && is_numeric($limit))
+ if ($limit !== '' && is_numeric($limit))
{
$this->bcc_batch_mode = TRUE;
$this->bcc_batch_size = $limit;
@@ -352,7 +361,7 @@ class CI_Email {
}
else
{
- $this->_set_header('Bcc', implode(', ', $bcc));
+ $this->set_header('Bcc', implode(', ', $bcc));
}
return $this;
@@ -369,7 +378,7 @@ class CI_Email {
public function subject($subject)
{
$subject = $this->_prep_q_encoding($subject);
- $this->_set_header('Subject', $subject);
+ $this->set_header('Subject', $subject);
return $this;
}
@@ -424,7 +433,7 @@ class CI_Email {
* @param string
* @return void
*/
- protected function _set_header($header, $value)
+ public function set_header($header, $value)
{
$this->_headers[$header] = $value;
}
@@ -586,7 +595,7 @@ class CI_Email {
$this->protocol = strtolower($this->protocol);
in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail';
- if ($return == TRUE)
+ if ($return === TRUE)
{
return $this->protocol;
}
@@ -606,13 +615,13 @@ class CI_Email {
foreach ($this->_base_charsets as $charset)
{
- if (strncmp($charset, $this->charset, strlen($charset)) === 0)
+ if (strpos($charset, $this->charset) === 0)
{
$this->_encoding = '7bit';
}
}
- if ($return == TRUE)
+ if ($return === TRUE)
{
return $this->_encoding;
}
@@ -629,7 +638,7 @@ class CI_Email {
{
if ($this->mailtype === 'html')
{
- return (count($this->_attach_name) == 0) ? 'html' : 'html-attach';
+ return (count($this->_attach_name) === 0) ? 'html' : 'html-attach';
}
elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
{
@@ -651,7 +660,7 @@ class CI_Email {
protected function _set_date()
{
$timezone = date('Z');
- $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
+ $operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
@@ -706,9 +715,9 @@ class CI_Email {
* @param string
* @return bool
*/
- public function valid_email($address)
+ public function valid_email($email)
{
- return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address);
+ return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
// --------------------------------------------------------------------
@@ -750,7 +759,7 @@ class CI_Email {
*/
protected function _get_alt_message()
{
- if ($this->alt_message != '')
+ if ($this->alt_message !== '')
{
return $this->word_wrap($this->alt_message, '76');
}
@@ -778,9 +787,9 @@ class CI_Email {
public function word_wrap($str, $charlim = '')
{
// Se the character limit
- if ($charlim == '')
+ if ($charlim === '')
{
- $charlim = ($this->wrapchars == '') ? 76 : $this->wrapchars;
+ $charlim = ($this->wrapchars === '') ? 76 : $this->wrapchars;
}
// Reduce multiple spaces
@@ -838,7 +847,7 @@ class CI_Email {
// If $temp contains data it means we had to split up an over-length
// word into smaller chunks so we'll add it back to our current line
- if ($temp != '')
+ if ($temp !== '')
{
$output .= $temp.$this->newline;
}
@@ -867,11 +876,11 @@ class CI_Email {
*/
protected function _build_headers()
{
- $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
- $this->_set_header('X-Mailer', $this->useragent);
- $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
- $this->_set_header('Message-ID', $this->_get_message_id());
- $this->_set_header('Mime-Version', '1.0');
+ $this->set_header('X-Sender', $this->clean_email($this->_headers['From']));
+ $this->set_header('X-Mailer', $this->useragent);
+ $this->set_header('X-Priority', $this->_priorities[$this->priority - 1]);
+ $this->set_header('Message-ID', $this->_get_message_id());
+ $this->set_header('Mime-Version', '1.0');
}
// --------------------------------------------------------------------
@@ -896,7 +905,7 @@ class CI_Email {
{
$val = trim($val);
- if ($val != '')
+ if ($val !== '')
{
$this->_header_str .= $key.': '.$val.$this->newline;
}
@@ -1043,7 +1052,7 @@ class CI_Email {
$ctype = $this->_attach_type[$i];
$file_content = '';
- if ($this->_attach_type[$i] == '')
+ if ($this->_attach_type[$i] === '')
{
if ( ! file_exists($filename))
{
@@ -1099,7 +1108,7 @@ class CI_Email {
// Set the character limit
// Don't allow over 76, as that will make servers and MUAs barf
// all over quoted-printable data
- if ($charlim == '' OR $charlim > 76)
+ if ($charlim === '' OR $charlim > 76)
{
$charlim = 76;
}
@@ -1238,9 +1247,9 @@ class CI_Email {
*
* @return bool
*/
- public function send()
+ public function send($auto_clear = TRUE)
{
- if ($this->_replyto_flag == FALSE)
+ if ($this->_replyto_flag === FALSE)
{
$this->reply_to($this->_headers['From']);
}
@@ -1257,11 +1266,25 @@ class CI_Email {
if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
{
- return $this->batch_bcc_send();
+ $result = $this->batch_bcc_send();
+
+ if ($result && $auto_clear)
+ {
+ $this->clear();
+ }
+
+ return $result;
}
$this->_build_message();
- return $this->_spool_email();
+ $result = $this->_spool_email();
+
+ if ($result && $auto_clear)
+ {
+ $this->clear();
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -1284,7 +1307,7 @@ class CI_Email {
$set .= ', '.$this->_bcc_array[$i];
}
- if ($i == $float)
+ if ($i === $float)
{
$chunk[] = substr($set, 1);
$float += $this->bcc_batch_size;
@@ -1305,7 +1328,7 @@ class CI_Email {
if ($this->protocol !== 'smtp')
{
- $this->_set_header('Bcc', implode(', ', $bcc));
+ $this->set_header('Bcc', implode(', ', $bcc));
}
else
{
@@ -1377,7 +1400,7 @@ class CI_Email {
*/
protected function _send_with_mail()
{
- if ($this->_safe_mode == TRUE)
+ if ($this->_safe_mode === TRUE)
{
return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
}
@@ -1385,7 +1408,7 @@ class CI_Email {
{
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
- return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['From']));
+ return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path']));
}
}
@@ -1398,7 +1421,7 @@ class CI_Email {
*/
protected function _send_with_sendmail()
{
- $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t', 'w');
+ $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t'.' -r '.$this->clean_email($this->_headers['Return-Path']), 'w');
if ($fp === FALSE OR $fp === NULL)
{
@@ -1430,7 +1453,7 @@ class CI_Email {
*/
protected function _send_with_smtp()
{
- if ($this->smtp_host == '')
+ if ($this->smtp_host === '')
{
$this->_set_error_message('lang:email_no_hostname');
return FALSE;
@@ -1452,7 +1475,7 @@ class CI_Email {
{
foreach ($this->_cc_array as $val)
{
- if ($val != '')
+ if ($val !== '')
{
$this->_send_command('to', $val);
}
@@ -1463,7 +1486,7 @@ class CI_Email {
{
foreach ($this->_bcc_array as $val)
{
- if ($val != '')
+ if ($val !== '')
{
$this->_send_command('to', $val);
}
@@ -1481,7 +1504,7 @@ class CI_Email {
$this->_set_error_message($reply);
- if (strncmp($reply, '250', 3) !== 0)
+ if (strpos($reply, '250') !== 0)
{
$this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE;
@@ -1501,7 +1524,7 @@ class CI_Email {
*/
protected function _smtp_connect()
{
- $ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
+ $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL;
$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
$this->smtp_port,
@@ -1517,7 +1540,7 @@ class CI_Email {
$this->_set_error_message($this->_get_smtp_data());
- if ($this->smtp_crypto == 'tls')
+ if ($this->smtp_crypto === 'tls')
{
$this->_send_command('hello');
$this->_send_command('starttls');
@@ -1599,13 +1622,13 @@ class CI_Email {
$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
- if (substr($reply, 0, 3) != $resp)
+ if ( (int) substr($reply, 0, 3) !== $resp)
{
$this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE;
}
- if ($cmd == 'quit')
+ if ($cmd === 'quit')
{
fclose($this->_smtp_connect);
}
@@ -1627,7 +1650,7 @@ class CI_Email {
return TRUE;
}
- if ($this->smtp_user == '' && $this->smtp_pass == '')
+ if ($this->smtp_user === '' && $this->smtp_pass === '')
{
$this->_set_error_message('lang:email_no_smtp_unpw');
return FALSE;
@@ -1637,7 +1660,7 @@ class CI_Email {
$reply = $this->_get_smtp_data();
- if (strncmp($reply, '334', 3) !== 0)
+ if (strpos($reply, '334') !== 0)
{
$this->_set_error_message('lang:email_failed_smtp_login', $reply);
return FALSE;
@@ -1647,7 +1670,7 @@ class CI_Email {
$reply = $this->_get_smtp_data();
- if (strncmp($reply, '334', 3) !== 0)
+ if (strpos($reply, '334') !== 0)
{
$this->_set_error_message('lang:email_smtp_auth_un', $reply);
return FALSE;
@@ -1657,7 +1680,7 @@ class CI_Email {
$reply = $this->_get_smtp_data();
- if (strncmp($reply, '235', 3) !== 0)
+ if (strpos($reply, '235') !== 0)
{
$this->_set_error_message('lang:email_smtp_auth_pw', $reply);
return FALSE;
@@ -1699,7 +1722,7 @@ class CI_Email {
{
$data .= $str;
- if ($str[3] == ' ')
+ if ($str[3] === ' ')
{
break;
}
@@ -1816,98 +1839,23 @@ class CI_Email {
*/
protected function _mime_types($ext = '')
{
- $mimes = array(
- 'hqx' => 'application/mac-binhex40',
- 'cpt' => 'application/mac-compactpro',
- 'doc' => 'application/msword',
- 'bin' => 'application/macbinary',
- 'dms' => 'application/octet-stream',
- 'lha' => 'application/octet-stream',
- 'lzh' => 'application/octet-stream',
- 'exe' => 'application/octet-stream',
- 'class' => 'application/octet-stream',
- 'psd' => 'application/octet-stream',
- 'so' => 'application/octet-stream',
- 'sea' => 'application/octet-stream',
- 'dll' => 'application/octet-stream',
- 'oda' => 'application/oda',
- 'pdf' => 'application/pdf',
- 'ai' => 'application/postscript',
- 'eps' => 'application/postscript',
- 'ps' => 'application/postscript',
- 'smi' => 'application/smil',
- 'smil' => 'application/smil',
- 'mif' => 'application/vnd.mif',
- 'xls' => 'application/vnd.ms-excel',
- 'ppt' => 'application/vnd.ms-powerpoint',
- 'wbxml' => 'application/vnd.wap.wbxml',
- 'wmlc' => 'application/vnd.wap.wmlc',
- 'dcr' => 'application/x-director',
- 'dir' => 'application/x-director',
- 'dxr' => 'application/x-director',
- 'dvi' => 'application/x-dvi',
- 'gtar' => 'application/x-gtar',
- 'php' => 'application/x-httpd-php',
- 'php4' => 'application/x-httpd-php',
- 'php3' => 'application/x-httpd-php',
- 'phtml' => 'application/x-httpd-php',
- 'phps' => 'application/x-httpd-php-source',
- 'js' => 'application/x-javascript',
- 'swf' => 'application/x-shockwave-flash',
- 'sit' => 'application/x-stuffit',
- 'tar' => 'application/x-tar',
- 'tgz' => 'application/x-tar',
- 'xhtml' => 'application/xhtml+xml',
- 'xht' => 'application/xhtml+xml',
- 'zip' => 'application/zip',
- 'mid' => 'audio/midi',
- 'midi' => 'audio/midi',
- 'mpga' => 'audio/mpeg',
- 'mp2' => 'audio/mpeg',
- 'mp3' => 'audio/mpeg',
- 'aif' => 'audio/x-aiff',
- 'aiff' => 'audio/x-aiff',
- 'aifc' => 'audio/x-aiff',
- 'ram' => 'audio/x-pn-realaudio',
- 'rm' => 'audio/x-pn-realaudio',
- 'rpm' => 'audio/x-pn-realaudio-plugin',
- 'ra' => 'audio/x-realaudio',
- 'rv' => 'video/vnd.rn-realvideo',
- 'wav' => 'audio/x-wav',
- 'bmp' => 'image/bmp',
- 'gif' => 'image/gif',
- 'jpeg' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
- 'jpe' => 'image/jpeg',
- 'png' => 'image/png',
- 'tiff' => 'image/tiff',
- 'tif' => 'image/tiff',
- 'css' => 'text/css',
- 'ics' => 'text/calendar',
- 'html' => 'text/html',
- 'htm' => 'text/html',
- 'shtml' => 'text/html',
- 'txt' => 'text/plain',
- 'text' => 'text/plain',
- 'log' => 'text/plain',
- 'rtx' => 'text/richtext',
- 'rtf' => 'text/rtf',
- 'xml' => 'text/xml',
- 'xsl' => 'text/xml',
- 'mpeg' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
- 'mpe' => 'video/mpeg',
- 'qt' => 'video/quicktime',
- 'mov' => 'video/quicktime',
- 'avi' => 'video/x-msvideo',
- 'movie' => 'video/x-sgi-movie',
- 'doc' => 'application/msword',
- 'word' => 'application/msword',
- 'xl' => 'application/excel',
- 'eml' => 'message/rfc822'
- );
-
- return isset($mimes[strtolower($ext)]) ? $mimes[strtolower($ext)] : 'application/x-unknown-content-type';
+ static $mimes;
+
+ $ext = strtolower($ext);
+
+ if ( ! is_array($mimes))
+ {
+ $mimes =& get_mimes();
+ }
+
+ if (isset($mimes[$ext]))
+ {
+ return is_array($mimes[$ext])
+ ? current($mimes[$ext])
+ : $mimes[$ext];
+ }
+
+ return 'application/x-unknown-content-type';
}
}
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 751557fab..679609251 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -97,15 +97,14 @@ class CI_Encrypt {
*/
public function get_key($key = '')
{
- if ($key == '')
+ if ($key === '')
{
- if ($this->encryption_key != '')
+ if ($this->encryption_key !== '')
{
return $this->encryption_key;
}
- $CI =& get_instance();
- $key = $CI->config->item('encryption_key');
+ $key = config_item('encryption_key');
if ($key === FALSE)
{
@@ -214,6 +213,7 @@ class CI_Encrypt {
$dec = base64_decode($string);
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
+ $this->set_mode($current_mode);
return FALSE;
}
@@ -449,7 +449,7 @@ class CI_Encrypt {
*/
protected function _get_cipher()
{
- if ($this->_mcrypt_cipher == '')
+ if ($this->_mcrypt_cipher === NULL)
{
return $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256;
}
@@ -466,7 +466,7 @@ class CI_Encrypt {
*/
protected function _get_mode()
{
- if ($this->_mcrypt_mode == '')
+ if ($this->_mcrypt_mode === NULL)
{
return $this->_mcrypt_mode = MCRYPT_MODE_CBC;
}
@@ -484,7 +484,7 @@ class CI_Encrypt {
*/
public function set_hash($type = 'sha1')
{
- $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type;
+ $this->_hash_type = in_array($type, hash_algos()) ? $type : 'sha1';
}
// --------------------------------------------------------------------
@@ -497,7 +497,7 @@ class CI_Encrypt {
*/
public function hash($str)
{
- return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str);
+ return hash($this->_hash_type, $str);
}
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 67cbfd1a0..b490a34ca 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -187,14 +187,20 @@ class CI_Form_validation {
return $this;
}
+ // Convert an array of rules to a string
+ if (is_array($rules))
+ {
+ $rules = implode('|', $rules);
+ }
+
// No fields? Nothing to do...
- if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
+ if ( ! is_string($field) OR ! is_string($rules) OR $field === '')
{
return $this;
}
// If the field label wasn't passed we use the field name
- $label = ($label == '') ? $field : $label;
+ $label = ($label === '') ? $field : $label;
// Is the field name an array? If it is an array, we break it apart
// into its components so that we can fetch the corresponding POST data later
@@ -207,7 +213,7 @@ class CI_Form_validation {
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
- if ($matches[1][$i] != '')
+ if ($matches[1][$i] !== '')
{
$indexes[] = $matches[1][$i];
}
@@ -318,12 +324,12 @@ class CI_Form_validation {
return '';
}
- if ($prefix == '')
+ if ($prefix === '')
{
$prefix = $this->_error_prefix;
}
- if ($suffix == '')
+ if ($suffix === '')
{
$suffix = $this->_error_suffix;
}
@@ -364,12 +370,12 @@ class CI_Form_validation {
return '';
}
- if ($prefix == '')
+ if ($prefix === '')
{
$prefix = $this->_error_prefix;
}
- if ($suffix == '')
+ if ($suffix === '')
{
$suffix = $this->_error_suffix;
}
@@ -378,7 +384,7 @@ class CI_Form_validation {
$str = '';
foreach ($this->_error_array as $val)
{
- if ($val != '')
+ if ($val !== '')
{
$str .= $prefix.$val.$suffix."\n";
}
@@ -417,9 +423,9 @@ class CI_Form_validation {
}
// Is there a validation rule for the particular URI being accessed?
- $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
+ $uri = ($group === '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
- if ($uri != '' && isset($this->_config_rules[$uri]))
+ if ($uri !== '' && isset($this->_config_rules[$uri]))
{
$this->set_rules($this->_config_rules[$uri]);
}
@@ -454,6 +460,12 @@ class CI_Form_validation {
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
+ // Don't try to validate if we have no rules set
+ if (empty($row['rules']))
+ {
+ continue;
+ }
+
$this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
}
@@ -565,8 +577,7 @@ class CI_Form_validation {
{
foreach ($postdata as $key => $val)
{
- $this->_execute($row, $rules, $val, $cycles);
- $cycles++;
+ $this->_execute($row, $rules, $val, $key);
}
return;
@@ -629,7 +640,7 @@ class CI_Form_validation {
// We set the $postdata variable with the current data in our master array so that
// each cycle of the loop is dealing with the processed data from the last cycle
- if ($row['is_array'] == TRUE && is_array($this->_field_data[$row['field']]['postdata']))
+ if ($row['is_array'] === TRUE && is_array($this->_field_data[$row['field']]['postdata']))
{
// We shouldn't need this safety, but just in case there isn't an array index
// associated with this cycle we'll bail out
@@ -643,7 +654,12 @@ class CI_Form_validation {
}
else
{
- $postdata = $this->_field_data[$row['field']]['postdata'];
+ // If we get an array field, but it's not expected - then it is most likely
+ // somebody messing with the form on the client side, so we'll just consider
+ // it an empty field
+ $postdata = is_array($this->_field_data[$row['field']]['postdata'])
+ ? NULL
+ : $this->_field_data[$row['field']]['postdata'];
}
// Is the rule a callback?
@@ -852,7 +868,7 @@ class CI_Form_validation {
return '';
}
}
- elseif (($field == '' OR $value == '') OR ($field != $value))
+ elseif (($field === '' OR $value === '') OR ($field !== $value))
{
return '';
}
@@ -888,7 +904,7 @@ class CI_Form_validation {
return '';
}
}
- elseif (($field == '' OR $value == '') OR ($field != $value))
+ elseif (($field === '' OR $value === '') OR ($field !== $value))
{
return '';
}
@@ -987,15 +1003,19 @@ class CI_Form_validation {
* Minimum Length
*
* @param string
- * @param int
+ * @param string
* @return bool
*/
public function min_length($str, $val)
{
- if (preg_match('/[^0-9]/', $val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
+ else
+ {
+ $val = (int) $val;
+ }
return (MB_ENABLED === TRUE)
? ($val <= mb_strlen($str))
@@ -1008,15 +1028,19 @@ class CI_Form_validation {
* Max Length
*
* @param string
- * @param int
+ * @param string
* @return bool
*/
public function max_length($str, $val)
{
- if (preg_match('/[^0-9]/', $val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
+ else
+ {
+ $val = (int) $val;
+ }
return (MB_ENABLED === TRUE)
? ($val >= mb_strlen($str))
@@ -1029,19 +1053,23 @@ class CI_Form_validation {
* Exact Length
*
* @param string
- * @param int
+ * @param string
* @return bool
*/
public function exact_length($str, $val)
{
- if (preg_match('/[^0-9]/', $val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
+ else
+ {
+ $val = (int) $val;
+ }
return (MB_ENABLED === TRUE)
- ? (mb_strlen($str) == $val)
- : (strlen($str) == $val);
+ ? (mb_strlen($str) === $val)
+ : (strlen($str) === $val);
}
// --------------------------------------------------------------------
@@ -1054,7 +1082,7 @@ class CI_Form_validation {
*/
public function valid_email($str)
{
- return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $str);
+ return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
}
// --------------------------------------------------------------------
@@ -1089,11 +1117,12 @@ class CI_Form_validation {
* Validate IP Address
*
* @param string
+ * @param string 'ipv4' or 'ipv6' to validate a specific IP format
* @return bool
*/
- public function valid_ip($ip)
+ public function valid_ip($ip, $which = '')
{
- return $this->CI->input->valid_ip($ip);
+ return $this->CI->input->valid_ip($ip, $which);
}
// --------------------------------------------------------------------
@@ -1106,7 +1135,7 @@ class CI_Form_validation {
*/
public function alpha($str)
{
- return (bool) preg_match('/^[a-z]+$/i', $str);
+ return ctype_alpha($str);
}
// --------------------------------------------------------------------
@@ -1119,7 +1148,7 @@ class CI_Form_validation {
*/
public function alpha_numeric($str)
{
- return (bool) preg_match('/^[a-z0-9]+$/i', $str);
+ return ctype_alnum((string) $str);
}
// --------------------------------------------------------------------
@@ -1241,7 +1270,7 @@ class CI_Form_validation {
*/
public function is_natural($str)
{
- return (bool) preg_match('/^[0-9]+$/', $str);
+ return ctype_digit((string) $str);
}
// --------------------------------------------------------------------
@@ -1254,7 +1283,7 @@ class CI_Form_validation {
*/
public function is_natural_no_zero($str)
{
- return ($str != 0 && preg_match('/^[0-9]+$/', $str));
+ return ($str != 0 && ctype_digit((string) $str));
}
// --------------------------------------------------------------------
@@ -1296,7 +1325,7 @@ class CI_Form_validation {
return $data;
}
- if ($this->_safe_form_data == FALSE OR $data === '')
+ if ($this->_safe_form_data === FALSE OR $data === '')
{
return $data;
}
@@ -1314,7 +1343,7 @@ class CI_Form_validation {
*/
public function prep_url($str = '')
{
- if ($str === 'http://' OR $str == '')
+ if ($str === 'http://' OR $str === '')
{
return '';
}
@@ -1337,7 +1366,7 @@ class CI_Form_validation {
*/
public function strip_image_tags($str)
{
- return $this->CI->input->strip_image_tags($str);
+ return $this->CI->security->strip_image_tags($str);
}
// --------------------------------------------------------------------
@@ -1363,7 +1392,7 @@ class CI_Form_validation {
*/
public function encode_php_tags($str)
{
- return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
+ return str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $str);
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index 3cfe1b2b6..76f5e151a 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -93,7 +93,7 @@ class CI_FTP {
if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_connect');
}
@@ -102,7 +102,7 @@ class CI_FTP {
if ( ! $this->_login())
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_login');
}
@@ -110,7 +110,7 @@ class CI_FTP {
}
// Set passive mode if needed
- if ($this->passive == TRUE)
+ if ($this->passive === TRUE)
{
ftp_pasv($this->conn_id, TRUE);
}
@@ -141,7 +141,7 @@ class CI_FTP {
{
if ( ! is_resource($this->conn_id))
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_no_connection');
}
@@ -167,7 +167,7 @@ class CI_FTP {
*/
public function changedir($path = '', $supress_debug = FALSE)
{
- if ($path == '' OR ! $this->_is_conn())
+ if ($path === '' OR ! $this->_is_conn())
{
return FALSE;
}
@@ -176,7 +176,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE && $supress_debug == FALSE)
+ if ($this->debug === TRUE && $supress_debug === FALSE)
{
$this->_error('ftp_unable_to_changedir');
}
@@ -197,7 +197,7 @@ class CI_FTP {
*/
public function mkdir($path = '', $permissions = NULL)
{
- if ($path == '' OR ! $this->_is_conn())
+ if ($path === '' OR ! $this->_is_conn())
{
return FALSE;
}
@@ -206,7 +206,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_makdir');
}
@@ -260,7 +260,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_upload');
}
@@ -307,7 +307,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_download');
}
@@ -338,9 +338,9 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
- $this->_error('ftp_unable_to_' . ($move == FALSE ? 'rename' : 'move'));
+ $this->_error('ftp_unable_to_' . ($move === FALSE ? 'rename' : 'move'));
}
return FALSE;
}
@@ -381,7 +381,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_delete');
}
@@ -429,7 +429,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_delete');
}
@@ -445,7 +445,7 @@ class CI_FTP {
* Set file permissions
*
* @param string the file path
- * @param string the permissions
+ * @param int the permissions
* @return bool
*/
public function chmod($path, $perm)
@@ -459,7 +459,7 @@ class CI_FTP {
if ($result === FALSE)
{
- if ($this->debug == TRUE)
+ if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_chmod');
}
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 0cb189445..ef4187847 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -466,7 +466,7 @@ class CI_Image_lib {
}
// Is there a source image? If not, there's no reason to continue
- if ($this->source_image == '')
+ if ($this->source_image === '')
{
$this->set_error('imglib_source_image_required');
return FALSE;
@@ -519,7 +519,7 @@ class CI_Image_lib {
* it means we are altering the original. We'll
* set the destination filename and path accordingly.
*/
- if ($this->new_image == '')
+ if ($this->new_image === '')
{
$this->dest_image = $this->source_image;
$this->dest_folder = $this->source_folder;
@@ -562,7 +562,7 @@ class CI_Image_lib {
* 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 == '')
+ if ($this->create_thumb === FALSE OR $this->thumb_marker === '')
{
$this->thumb_marker = '';
}
@@ -581,7 +581,7 @@ class CI_Image_lib {
* might not be in correct proportion with the source
* image's width/height. We'll recalculate it here.
*/
- if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0))
+ if ($this->maintain_ratio === TRUE && ($this->width !== 0 OR $this->height !== 0))
{
$this->image_reproportion();
}
@@ -591,12 +591,12 @@ class CI_Image_lib {
* If the destination width/height was not submitted we
* will use the values from the actual file
*/
- if ($this->width == '')
+ if ($this->width === '')
{
$this->width = $this->orig_width;
}
- if ($this->height == '')
+ if ($this->height === '')
{
$this->height = $this->orig_height;
}
@@ -604,31 +604,31 @@ class CI_Image_lib {
// Set the quality
$this->quality = trim(str_replace('%', '', $this->quality));
- if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $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 ! 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;
+ is_numeric($this->x_axis) OR $this->x_axis = 0;
+ is_numeric($this->y_axis) OR $this->y_axis = 0;
// Watermark-related Stuff...
- if ($this->wm_overlay_path != '')
+ if ($this->wm_overlay_path !== '')
{
$this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path));
}
- if ($this->wm_shadow_color != '')
+ if ($this->wm_shadow_color !== '')
{
$this->wm_use_drop_shadow = TRUE;
}
- elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '')
+ elseif ($this->wm_use_drop_shadow === TRUE && $this->wm_shadow_color === '')
{
$this->wm_use_drop_shadow = FALSE;
}
- if ($this->wm_font_path != '')
+ if ($this->wm_font_path !== '')
{
$this->wm_use_truetype = TRUE;
}
@@ -683,14 +683,14 @@ class CI_Image_lib {
// Allowed rotation values
$degs = array(90, 180, 270, 'vrt', 'hor');
- if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs))
+ if ($this->rotation_angle === '' OR ! in_array($this->rotation_angle, $degs))
{
$this->set_error('imglib_rotation_angle_required');
return FALSE;
}
// Reassign the width and height
- if ($this->rotation_angle == 90 OR $this->rotation_angle == 270)
+ if ($this->rotation_angle === 90 OR $this->rotation_angle === 270)
{
$this->width = $this->orig_height;
$this->height = $this->orig_width;
@@ -729,9 +729,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 && $this->orig_width == $this->width && $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 && @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);
}
@@ -740,7 +740,7 @@ class CI_Image_lib {
}
// Let's set up our values based on the action
- if ($action == 'crop')
+ if ($action === 'crop')
{
// Reassign the source width/height if cropping
$this->orig_width = $this->width;
@@ -750,7 +750,7 @@ class CI_Image_lib {
if ($this->gd_version() !== FALSE)
{
$gd_version = str_replace('0', '', $this->gd_version());
- $v2_override = ($gd_version == 2) ? TRUE : FALSE;
+ $v2_override = ($gd_version === 2);
}
}
else
@@ -772,7 +772,7 @@ class CI_Image_lib {
* 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') && $v2_override === FALSE)
*/
if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
{
@@ -787,7 +787,7 @@ class CI_Image_lib {
$dst_img = $create($this->width, $this->height);
- if ($this->image_type == 3) // png we can actually preserve transparency
+ if ($this->image_type === 3) // png we can actually preserve transparency
{
imagealphablending($dst_img, FALSE);
imagesavealpha($dst_img, TRUE);
@@ -796,7 +796,7 @@ 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
- if ($this->dynamic_output == TRUE)
+ if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($dst_img);
}
@@ -828,7 +828,7 @@ class CI_Image_lib {
public function image_process_imagemagick($action = 'resize')
{
// Do we have a vaild library path?
- if ($this->library_path == '')
+ if ($this->library_path === '')
{
$this->set_error('imglib_libpath_invalid');
return FALSE;
@@ -842,11 +842,11 @@ class CI_Image_lib {
// Execute the command
$cmd = $this->library_path.' -quality '.$this->quality;
- if ($action == 'crop')
+ 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';
}
- elseif ($action == 'rotate')
+ elseif ($action === 'rotate')
{
$angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
? '-flop' : '-rotate '.$this->rotation_angle;
@@ -855,7 +855,14 @@ class CI_Image_lib {
}
else // Resize
{
- $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
+ if($this->maintain_ratio === TRUE)
+ {
+ $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
+ }
+ else
+ {
+ $cmd .= ' -resize '.$this->width.'x'.$this->height.'\! "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
+ }
}
$retval = 1;
@@ -886,7 +893,7 @@ class CI_Image_lib {
*/
public function image_process_netpbm($action = 'resize')
{
- if ($this->library_path == '')
+ if ($this->library_path === '')
{
$this->set_error('imglib_libpath_invalid');
return FALSE;
@@ -909,11 +916,11 @@ class CI_Image_lib {
break;
}
- if ($action == 'crop')
+ if ($action === 'crop')
{
$cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
}
- elseif ($action == 'rotate')
+ elseif ($action === 'rotate')
{
switch ($this->rotation_angle)
{
@@ -984,7 +991,7 @@ class CI_Image_lib {
$dst_img = imagerotate($src_img, $this->rotation_angle, $white);
// Show the image
- if ($this->dynamic_output == TRUE)
+ if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($dst_img);
}
@@ -1058,7 +1065,7 @@ class CI_Image_lib {
}
// Show the image
- if ($this->dynamic_output == TRUE)
+ if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($src_img);
}
@@ -1129,10 +1136,10 @@ class CI_Image_lib {
$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')
+ if ($this->wm_vrt_alignment === 'B')
$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
- if ($this->wm_hor_alignment == 'R')
+ if ($this->wm_hor_alignment === 'R')
$this->wm_hor_offset = $this->wm_hor_offset * -1;
// Set the base x and y axis values
@@ -1160,7 +1167,7 @@ class CI_Image_lib {
}
// Build the finalized image
- if ($wm_img_type == 3 && function_exists('imagealphablending'))
+ if ($wm_img_type === 3 && function_exists('imagealphablending'))
{
@imagealphablending($src_img, TRUE);
}
@@ -1183,7 +1190,7 @@ class CI_Image_lib {
}
// Output the image
- if ($this->dynamic_output == TRUE)
+ if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($src_img);
}
@@ -1212,7 +1219,7 @@ class CI_Image_lib {
return FALSE;
}
- if ($this->wm_use_truetype == TRUE && ! 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;
@@ -1228,18 +1235,18 @@ class CI_Image_lib {
// invert the offset. Note: The horizontal
// offset flips itself automatically
- if ($this->wm_vrt_alignment == 'B')
+ if ($this->wm_vrt_alignment === 'B')
$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
- if ($this->wm_hor_alignment == 'R')
+ if ($this->wm_hor_alignment === 'R')
$this->wm_hor_offset = $this->wm_hor_offset * -1;
// Set font width and height
// These are calculated differently depending on
// whether we are using the true type font or not
- if ($this->wm_use_truetype == TRUE)
+ if ($this->wm_use_truetype === TRUE)
{
- if ($this->wm_font_size == '')
+ if ($this->wm_font_size === '')
{
$this->wm_font_size = 17;
}
@@ -1258,7 +1265,7 @@ class CI_Image_lib {
$x_axis = $this->wm_hor_offset + $this->wm_padding;
$y_axis = $this->wm_vrt_offset + $this->wm_padding;
- if ($this->wm_use_drop_shadow == FALSE)
+ if ($this->wm_use_drop_shadow === FALSE)
$this->wm_shadow_distance = 0;
$this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
@@ -1313,10 +1320,17 @@ class CI_Image_lib {
imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
}
+
+ // We can preserve transparency for PNG images
+ if ($this->image_type === 3)
+ {
+ imagealphablending($src_img, FALSE);
+ imagesavealpha($src_img, TRUE);
+ }
}
// Output the final image
- if ($this->dynamic_output == TRUE)
+ if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($src_img);
}
@@ -1344,10 +1358,10 @@ class CI_Image_lib {
*/
public function image_create_gd($path = '', $image_type = '')
{
- if ($path == '')
+ if ($path === '')
$path = $this->full_src_path;
- if ($image_type == '')
+ if ($image_type === '')
$image_type = $this->image_type;
@@ -1494,7 +1508,7 @@ class CI_Image_lib {
*/
public function image_reproportion()
{
- if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0
+ 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))
{
@@ -1549,7 +1563,7 @@ class CI_Image_lib {
// For now we require GD but we should
// find a way to determine this using IM or NetPBM
- if ($path == '')
+ if ($path === '')
{
$path = $this->full_src_path;
}
@@ -1564,7 +1578,7 @@ class CI_Image_lib {
$types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
$mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg';
- if ($return == TRUE)
+ if ($return === TRUE)
{
return array(
'width' => $vals[0],
@@ -1620,16 +1634,16 @@ class CI_Image_lib {
}
}
- if ($vals['width'] == 0 OR $vals['height'] == 0)
+ if ($vals['width'] === 0 OR $vals['height'] === 0)
{
return $vals;
}
- if ($vals['new_width'] == 0)
+ if ($vals['new_width'] === 0)
{
$vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
}
- elseif ($vals['new_height'] == 0)
+ elseif ($vals['new_height'] === 0)
{
$vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
}
@@ -1715,14 +1729,14 @@ class CI_Image_lib {
{
foreach ($msg as $val)
{
- $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);
+ $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val);
$this->error_msg[] = $msg;
log_message('error', $msg);
}
}
else
{
- $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg);
+ $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg);
$this->error_msg[] = $msg;
log_message('error', $msg);
}
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index dd2df697c..5c8b09217 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -615,12 +615,12 @@ class CI_Javascript {
{
$this->_javascript_location = $external_file;
}
- elseif ($this->CI->config->item('javascript_location') != '')
+ elseif ($this->CI->config->item('javascript_location') !== '')
{
$this->_javascript_location = $this->CI->config->item('javascript_location');
}
- if ($relative === TRUE OR strncmp($external_file, 'http://', 7) === 0 OR strncmp($external_file, 'https://', 8) === 0)
+ if ($relative === TRUE OR strpos($external_file, 'http://') === 0 OR strpos($external_file, 'https://') === 0)
{
$str = $this->_open_script($external_file);
}
@@ -667,7 +667,7 @@ class CI_Javascript {
protected function _open_script($src = '')
{
return '<script type="text/javascript" charset="'.strtolower($this->CI->config->item('charset')).'"'
- .($src == '' ? '>' : ' src="'.$src.'">');
+ .($src === '' ? '>' : ' src="'.$src.'">');
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index 51ce43dc7..baac80121 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -94,7 +94,7 @@ class CI_Log {
{
$config =& get_config();
- $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
+ $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/';
if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
{
@@ -111,7 +111,7 @@ class CI_Log {
$this->_threshold_array = array_flip($config['log_threshold']);
}
- if ($config['log_date_format'] != '')
+ if ($config['log_date_format'] !== '')
{
$this->_date_fmt = $config['log_date_format'];
}
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index 0a88e6926..5d637d44a 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -109,7 +109,7 @@ class CI_Migration {
}
// If not set, set it
- $this->_migration_path != '' OR $this->_migration_path = APPPATH.'migrations/';
+ $this->_migration_path !== '' OR $this->_migration_path = APPPATH.'migrations/';
// Add trailing slash if not set
$this->_migration_path = rtrim($this->_migration_path, '/').'/';
@@ -285,14 +285,14 @@ class CI_Migration {
if ( ! $migrations = $this->find_migrations())
{
$this->_error_string = $this->lang->line('migration_none_found');
- return false;
+ return FALSE;
}
$last_migration = basename(end($migrations));
// Calculate the last migration step from existing migration
// filenames and procceed to the standard version migration
- return $this->version((int) substr($last_migration, 0, 3));
+ return $this->version((int) $last_migration);
}
// --------------------------------------------------------------------
@@ -322,9 +322,9 @@ class CI_Migration {
// --------------------------------------------------------------------
/**
- * Set's the schema to the latest migration
+ * Retrieves list of available migration scripts
*
- * @return mixed true if already latest, false if failed, int if upgraded
+ * @return array list of migration file paths sorted by version
*/
protected function find_migrations()
{
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 58f86fa17..e1e729bb0 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -52,22 +52,25 @@ class CI_Pagination {
protected $full_tag_open = '';
protected $full_tag_close = '';
protected $first_tag_open = '';
- protected $first_tag_close = '&nbsp;';
- protected $last_tag_open = '&nbsp;';
+ protected $first_tag_close = '';
+ protected $last_tag_open = '';
protected $last_tag_close = '';
protected $first_url = ''; // Alternative URL for the First Page.
- protected $cur_tag_open = '&nbsp;<strong>';
+ protected $cur_tag_open = '<strong>';
protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '&nbsp;';
- protected $next_tag_close = '&nbsp;';
- protected $prev_tag_open = '&nbsp;';
+ protected $next_tag_open = '';
+ protected $next_tag_close = '';
+ protected $prev_tag_open = '';
protected $prev_tag_close = '';
- protected $num_tag_open = '&nbsp;';
+ protected $num_tag_open = '';
protected $num_tag_close = '';
protected $page_query_string = FALSE;
protected $query_string_segment = 'per_page';
protected $display_pages = TRUE;
- protected $anchor_class = '';
+ protected $_attributes = '';
+ protected $_link_types = array();
+ protected $reuse_query_string = FALSE;
+ protected $data_page_attr = 'data-ci-pagination-page';
/**
* Constructor
@@ -91,15 +94,29 @@ class CI_Pagination {
*/
public function initialize($params = array())
{
+ $attributes = array();
+
+ if (isset($params['attributes']) && is_array($params['attributes']))
+ {
+ $attributes = $params['attributes'];
+ unset($params['attributes']);
+ }
+
+ // Deprecated legacy support for the anchor_class option
+ // Should be removed in CI 3.1+
+ if (isset($params['anchor_class']))
+ {
+ empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class'];
+ unset($params['anchor_class']);
+ }
+
+ $this->_parse_attributes($attributes);
+
if (count($params) > 0)
{
foreach ($params as $key => $val)
{
- if ($key === 'anchor_class')
- {
- $this->anchor_class = ($val != '') ? 'class="'.$val.'" ' : '';
- }
- elseif (isset($this->$key))
+ if (isset($this->$key))
{
$this->$key = $val;
}
@@ -117,7 +134,7 @@ class CI_Pagination {
public function create_links()
{
// If our item count or per-page total is zero there is no need to continue.
- if ($this->total_rows == 0 OR $this->per_page == 0)
+ if ($this->total_rows === 0 OR $this->per_page === 0)
{
return '';
}
@@ -138,7 +155,7 @@ class CI_Pagination {
$CI =& get_instance();
// See if we are using a prefix or suffix on links
- if ($this->prefix != '' OR $this->suffix != '')
+ if ($this->prefix !== '' OR $this->suffix !== '')
{
$this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment));
}
@@ -150,13 +167,13 @@ class CI_Pagination {
$this->cur_page = (int) $CI->input->get($this->query_string_segment);
}
}
- elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) != $base_page)
+ elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page)
{
$this->cur_page = (int) $CI->uri->segment($this->uri_segment);
}
// Set current page to 1 if it's not valid or if using page numbers instead of offset
- if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page == 0))
+ if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0))
{
$this->cur_page = $base_page;
}
@@ -186,7 +203,7 @@ class CI_Pagination {
if ( ! $this->use_page_numbers)
{
- $this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
+ $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1);
}
// Calculate the start and end numbers. These determine
@@ -198,7 +215,8 @@ class CI_Pagination {
// string. If post, add a trailing slash to the base URL if needed
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
- $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';
+ $segment = (strpos($this->base_url, '?')) ? '&amp;' : '?';
+ $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'=';
}
else
{
@@ -207,27 +225,56 @@ class CI_Pagination {
// And here we go...
$output = '';
+ $query_string = '';
+
+ // Add anything in the query string back to the links
+ // Note: Nothing to do with query_string_segment or any other query string options
+ if ($this->reuse_query_string === TRUE)
+ {
+ $get = $CI->input->get();
+
+ // Unset the controll, method, old-school routing options
+ unset($get['c'], $get['m'], $get[$this->query_string_segment]);
+
+ if ( ! $get) $get = array();
+
+ // Put everything else onto the end
+ $query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
+
+ // Add this after the suffix to put it into more links easily
+ $this->suffix .= $query_string;
+ }
// Render the "First" link
if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
{
- $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url;
- $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
+ $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url;
+
+ // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
+ $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1);
+
+ $output .= $this->first_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
+ .$this->first_link.'</a>'.$this->first_tag_close;
}
// Render the "previous" link
- if ($this->prev_link !== FALSE && $this->cur_page != 1)
+ if ($this->prev_link !== FALSE && $this->cur_page !== 1)
{
$i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page;
- if ($i == $base_page && $this->first_url != '')
+ // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
+ $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
+
+ if ($i === $base_page && $this->first_url !== '')
{
- $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
else
{
- $i = ($i == $base_page) ? '' : $this->prefix.$i.$this->suffix;
- $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
+ $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
}
@@ -240,25 +287,28 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page;
+ // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
+ $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
+
if ($i >= $base_page)
{
- if ($this->cur_page == $loop)
+ if ($this->cur_page === $loop)
{
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
}
else
{
- $n = ($i == $base_page) ? '' : $i;
-
- if ($n == '' && $this->first_url != '')
+ $n = ($i === $base_page) ? '' : $i;
+ if ($n === '' && ! empty($this->first_url))
{
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
+ $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('start').'>'
+ .$loop.'</a>'.$this->num_tag_close;
}
else
{
- $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;
-
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
+ $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
+ $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
+ .$loop.'</a>'.$this->num_tag_close;
}
}
}
@@ -270,7 +320,11 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;
- $output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
+ // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
+ $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
+
+ $output .= $this->next_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes
+ .$this->_attr_rel('next').'>'.$this->next_link.'</a>'.$this->next_tag_close;
}
// Render the "Last" link
@@ -278,7 +332,11 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;
- $output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>'.$this->last_tag_close;
+ // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
+ $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
+
+ $output .= $this->last_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes.'>'
+ .$this->last_link.'</a>'.$this->last_tag_close;
}
// Kill double slashes. Note: Sometimes we can end up with a double slash
@@ -289,6 +347,49 @@ class CI_Pagination {
return $this->full_tag_open.$output.$this->full_tag_close;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Parse attributes
+ *
+ * @param array
+ * @return void
+ */
+ protected function _parse_attributes($attributes)
+ {
+ isset($attributes['rel']) OR $attributes['rel'] = TRUE;
+ $this->_link_types = ($attributes['rel'])
+ ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next')
+ : array();
+ unset($attributes['rel']);
+
+ $this->_attributes = '';
+ foreach ($attributes as $key => $value)
+ {
+ $this->_attributes .= ' '.$key.'="'.$value.'"';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Add "rel" attribute
+ *
+ * @link http://www.w3.org/TR/html5/links.html#linkTypes
+ * @param string
+ * @return string
+ */
+ protected function _attr_rel($type)
+ {
+ if (isset($this->_link_types[$type]))
+ {
+ unset($this->_link_types[$type]);
+ return ' rel="'.$type.'"';
+ }
+
+ return '';
+ }
+
}
/* End of file Pagination.php */
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index a0b60ed97..b64c78254 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -109,7 +109,7 @@ class CI_Parser {
*/
protected function _parse($template, $data, $return = FALSE)
{
- if ($template == '')
+ if ($template === '')
{
return FALSE;
}
@@ -121,7 +121,7 @@ class CI_Parser {
: $template = $this->_parse_single($key, (string) $val, $template);
}
- if ($return == FALSE)
+ if ($return === FALSE)
{
$this->CI->output->append_output($template);
}
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index e219d20f2..1e961f6df 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -116,6 +116,12 @@ class CI_Profiler {
*/
public function set_sections($config)
{
+ if (isset($config['query_toggle_count']))
+ {
+ $this->_query_toggle_count = (int) $config['query_toggle_count'];
+ unset($config['query_toggle_count']);
+ }
+
foreach ($config as $method => $enable)
{
if (in_array($method, $this->_available_sections))
@@ -219,7 +225,7 @@ class CI_Profiler {
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';
- if ($hide_queries != '')
+ if ($hide_queries !== '')
{
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
}
@@ -315,7 +321,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#009900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_post_data')."&nbsp;&nbsp;</legend>\n";
- if (count($_POST) == 0)
+ if (count($_POST) === 0)
{
$output .= '<div style="color:#009900;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_post').'</div>';
}
@@ -365,7 +371,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_uri_string')."&nbsp;&nbsp;</legend>\n"
.'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">'
- .($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string)
+ .($this->CI->uri->uri_string === '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string)
.'</div></fieldset>';
}
@@ -402,7 +408,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#5a0099;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_memory_usage')."&nbsp;&nbsp;</legend>\n"
.'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">'
- .((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory'))
+ .(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory'))
.'</div></fieldset>';
}
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
deleted file mode 100644
index 783109a60..000000000
--- a/system/libraries/Session.php
+++ /dev/null
@@ -1,952 +0,0 @@
-<?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 1.0
- * @filesource
- */
-
-/**
- * Session Class
- *
- * @package CodeIgniter
- * @subpackage Libraries
- * @category Sessions
- * @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/libraries/sessions.html
- */
-class CI_Session {
-
- /**
- * Whether to encrypt the session cookie
- *
- * @var bool
- */
- public $sess_encrypt_cookie = FALSE;
-
- /**
- * Whether to use to the database for session storage
- *
- * @var bool
- */
- public $sess_use_database = FALSE;
-
- /**
- * Name of the database table in which to store sessions
- *
- * @var string
- */
- public $sess_table_name = '';
-
- /**
- * Length of time (in seconds) for sessions to expire
- *
- * @var int
- */
- public $sess_expiration = 7200;
-
- /**
- * Whether to kill session on close of browser window
- *
- * @var bool
- */
- public $sess_expire_on_close = FALSE;
-
- /**
- * Whether to match session on ip address
- *
- * @var bool
- */
- public $sess_match_ip = FALSE;
-
- /**
- * Whether to match session on user-agent
- *
- * @var bool
- */
- public $sess_match_useragent = TRUE;
-
- /**
- * Name of session cookie
- *
- * @var string
- */
- public $sess_cookie_name = 'ci_session';
-
- /**
- * Session cookie prefix
- *
- * @var string
- */
- public $cookie_prefix = '';
-
- /**
- * Session cookie path
- *
- * @var string
- */
- public $cookie_path = '';
-
- /**
- * Session cookie domain
- *
- * @var string
- */
- public $cookie_domain = '';
-
- /**
- * Whether to set the cookie only on HTTPS connections
- *
- * @var bool
- */
- public $cookie_secure = FALSE;
-
- /**
- * Whether cookie should be allowed only to be sent by the server
- *
- * @var bool
- */
- public $cookie_httponly = FALSE;
-
- /**
- * Interval at which to update session
- *
- * @var int
- */
- public $sess_time_to_update = 300;
-
- /**
- * Key with which to encrypt the session cookie
- *
- * @var string
- */
- public $encryption_key = '';
-
- /**
- * String to indicate flash data cookies
- *
- * @var string
- */
- public $flashdata_key = 'flash';
-
- /**
- * Function to use to get the current time
- *
- * @var string
- */
- public $time_reference = 'time';
-
- /**
- * Probablity level of garbage collection of old sessions
- *
- * @var int
- */
- public $gc_probability = 5;
-
- /**
- * Session data
- *
- * @var array
- */
- public $userdata = array();
-
- /**
- * Reference to CodeIgniter instance
- *
- * @var object
- */
- public $CI;
-
- /**
- * Current time
- *
- * @var int
- */
- public $now;
-
- /**
- * Session Constructor
- *
- * The constructor runs the session routines automatically
- * whenever the class is instantiated.
- *
- * @param array
- * @return void
- */
- public function __construct($params = array())
- {
- 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', '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);
- }
-
- if ($this->encryption_key == '')
- {
- show_error('In order to use the Session class you are required to set an encryption key in your config file.');
- }
-
- // Load the string helper so we can use the strip_slashes() function
- $this->CI->load->helper('string');
-
- // Do we need encryption? If so, load the encryption class
- if ($this->sess_encrypt_cookie == TRUE)
- {
- $this->CI->load->library('encrypt');
- }
-
- // 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
- $this->now = $this->_get_time();
-
- // Set the session length. If the session expiration is
- // set to zero we'll set the expiration two years from now.
- if ($this->sess_expiration == 0)
- {
- $this->sess_expiration = (60*60*24*365*2);
- }
-
- // Set the cookie name
- $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.
- if ( ! $this->sess_read())
- {
- $this->sess_create();
- }
- else
- {
- $this->sess_update();
- }
-
- // Delete 'old' flashdata (from last request)
- $this->_flashdata_sweep();
-
- // Mark all new flashdata as old (data will be deleted before next request)
- $this->_flashdata_mark();
-
- // Delete expired sessions if necessary
- $this->_sess_gc();
-
- log_message('debug', 'Session routines successfully run');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Fetch the current session data if it exists
- *
- * @return bool
- */
- public function sess_read()
- {
- // Fetch the cookie
- $session = $this->CI->input->cookie($this->sess_cookie_name);
-
- // No cookie? Goodbye cruel world!...
- if ($session === FALSE)
- {
- log_message('debug', 'A session cookie was not found.');
- return FALSE;
- }
-
- // Decrypt the cookie data
- if ($this->sess_encrypt_cookie == TRUE)
- {
- $session = $this->CI->encrypt->decode($session);
- }
- else
- {
- // encryption was not used, so we need to check the md5 hash
- $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
- 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.');
- $this->sess_destroy();
- return FALSE;
- }
- }
-
- // Unserialize the session array
- $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'], $session['ip_address'], $session['user_agent'], $session['last_activity']))
- {
- $this->sess_destroy();
- return FALSE;
- }
-
- // Is the session current?
- if (($session['last_activity'] + $this->sess_expiration) < $this->now)
- {
- $this->sess_destroy();
- return FALSE;
- }
-
- // 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 && trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
- {
- $this->sess_destroy();
- return FALSE;
- }
-
- // Is there a corresponding session in the DB?
- if ($this->sess_use_database === TRUE)
- {
- $this->CI->db->where('session_id', $session['session_id']);
-
- if ($this->sess_match_ip == TRUE)
- {
- $this->CI->db->where('ip_address', $session['ip_address']);
- }
-
- if ($this->sess_match_useragent == TRUE)
- {
- $this->CI->db->where('user_agent', $session['user_agent']);
- }
-
- $query = $this->CI->db->limit(1)->get($this->sess_table_name);
-
- // No result? Kill it!
- if ($query->num_rows() === 0)
- {
- $this->sess_destroy();
- return FALSE;
- }
-
- // Is there custom data? If so, add it to the main session array
- $row = $query->row();
- if (isset($row->user_data) && $row->user_data != '')
- {
- $custom_data = $this->_unserialize($row->user_data);
-
- if (is_array($custom_data))
- {
- foreach ($custom_data as $key => $val)
- {
- $session[$key] = $val;
- }
- }
- }
- }
-
- // Session is valid!
- $this->userdata = $session;
- unset($session);
-
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Write the session data
- *
- * @return void
- */
- public function sess_write()
- {
- // Are we saving custom data to the DB? If not, all we do is update the cookie
- if ($this->sess_use_database === FALSE)
- {
- $this->_set_cookie();
- return;
- }
-
- // set the custom userdata, the session data we will set in a second
- $custom_userdata = $this->userdata;
- $cookie_userdata = array();
-
- // Before continuing, we need to determine if there is any custom data to deal with.
- // Let's determine this by removing the default indexes to see if there's anything left in the array
- // and set the session data while we're at it
- foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
- {
- unset($custom_userdata[$val]);
- $cookie_userdata[$val] = $this->userdata[$val];
- }
-
- // 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)
- {
- $custom_userdata = '';
- }
- else
- {
- // Serialize the custom data array so we can store it
- $custom_userdata = $this->_serialize($custom_userdata);
- }
-
- // Run the update query
- $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
- // _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);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Create a new session
- *
- * @return void
- */
- public function sess_create()
- {
- $sessid = '';
- do
- {
- $sessid .= mt_rand(0, mt_getrandmax());
- }
- while (strlen($sessid) < 32);
-
- // To make the session ID even more secure we'll combine it with the user's IP
- $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' => ''
- );
-
- // Save the data to the DB if needed
- if ($this->sess_use_database === TRUE)
- {
- $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata));
- }
-
- // Write the cookie
- $this->_set_cookie();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Update an existing session
- *
- * @return void
- */
- public function sess_update()
- {
- // We only update the session every five minutes by default
- if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
- {
- 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'];
- $new_sessid = '';
- do
- {
- $new_sessid .= mt_rand(0, mt_getrandmax());
- }
- while (strlen($new_sessid) < 32);
-
- // To make the session ID even more secure we'll combine it with the user's IP
- $new_sessid .= $this->CI->input->ip_address();
-
- // Turn it into a hash and update the session data array
- $this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE));
- $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->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));
- }
-
- // Write the cookie
- $this->_set_cookie($cookie_data);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Destroy the current session
- *
- * @return void
- */
- public function sess_destroy()
- {
- // Kill the session DB row
- 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);
- }
-
- // Kill the cookie
- setcookie(
- $this->sess_cookie_name,
- addslashes(serialize(array())),
- ($this->now - 31500000),
- $this->cookie_path,
- $this->cookie_domain,
- 0
- );
-
- // Kill session data
- $this->userdata = array();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Fetch a specific item from the session array
- *
- * @param string
- * @return string
- */
- public function userdata($item)
- {
- return isset($this->userdata[$item]) ? $this->userdata[$item] : FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Fetch all session data
- *
- * @return array
- */
- public function all_userdata()
- {
- 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;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Add or change data in the "userdata" array
- *
- * @param mixed
- * @param string
- * @return void
- */
- public function set_userdata($newdata = array(), $newval = '')
- {
- if (is_string($newdata))
- {
- $newdata = array($newdata => $newval);
- }
-
- if (count($newdata) > 0)
- {
- foreach ($newdata as $key => $val)
- {
- $this->userdata[$key] = $val;
- }
- }
-
- $this->sess_write();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Delete a session variable from the "userdata" array
- *
- * @param array
- * @return void
- */
- public function unset_userdata($newdata = array())
- {
- if (is_string($newdata))
- {
- $newdata = array($newdata => '');
- }
-
- if (count($newdata) > 0)
- {
- foreach ($newdata as $key => $val)
- {
- unset($this->userdata[$key]);
- }
- }
-
- $this->sess_write();
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Add or change flashdata, only available
- * until the next request
- *
- * @param mixed
- * @param string
- * @return void
- */
- public function set_flashdata($newdata = array(), $newval = '')
- {
- if (is_string($newdata))
- {
- $newdata = array($newdata => $newval);
- }
-
- if (count($newdata) > 0)
- {
- foreach ($newdata as $key => $val)
- {
- $this->set_userdata($this->flashdata_key.':new:'.$key, $val);
- }
- }
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Keeps existing flashdata available to next request.
- *
- * @param string
- * @return void
- */
- public function keep_flashdata($key)
- {
- // '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
- $value = $this->userdata($this->flashdata_key.':old:'.$key);
-
- $this->set_userdata($this->flashdata_key.':new:'.$key, $value);
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Fetch a specific flashdata item from the session array
- *
- * @param string
- * @return string
- */
- public function flashdata($key)
- {
- return $this->userdata($this->flashdata_key.':old:'.$key);
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Identifies flashdata as 'old' for removal
- * when _flashdata_sweep() runs.
- *
- * @return void
- */
- protected function _flashdata_mark()
- {
- $userdata = $this->all_userdata();
- foreach ($userdata as $name => $value)
- {
- $parts = explode(':new:', $name);
- if (is_array($parts) && count($parts) === 2)
- {
- $this->set_userdata($this->flashdata_key.':old:'.$parts[1], $value);
- $this->unset_userdata($name);
- }
- }
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Removes all flashdata marked as 'old'
- *
- * @return void
- */
- protected function _flashdata_sweep()
- {
- $userdata = $this->all_userdata();
- foreach ($userdata as $key => $value)
- {
- if (strpos($key, ':old:'))
- {
- $this->unset_userdata($key);
- }
- }
-
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get the "now" time
- *
- * @return string
- */
- protected function _get_time()
- {
- return (strtolower($this->time_reference) === 'gmt')
- ? mktime(gmdate('H'), gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y'))
- : time();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Write the session cookie
- *
- * @param mixed
- * @return void
- */
- protected function _set_cookie($cookie_data = NULL)
- {
- if (is_null($cookie_data))
- {
- $cookie_data = $this->userdata;
- }
-
- // Serialize the userdata for the cookie
- $cookie_data = $this->_serialize($cookie_data);
-
- if ($this->sess_encrypt_cookie == TRUE)
- {
- $cookie_data = $this->CI->encrypt->encode($cookie_data);
- }
- else
- {
- // if encryption is not used, we provide an md5 hash to prevent userside tampering
- $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
- }
-
- $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
-
- // Set the cookie
- setcookie(
- $this->sess_cookie_name,
- $cookie_data,
- $expire,
- $this->cookie_path,
- $this->cookie_domain,
- $this->cookie_secure,
- $this->cookie_httponly
- );
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Serialize an array
- *
- * This function first converts any slashes found in the array to a temporary
- * marker, so when it gets unserialized the slashes will be preserved
- *
- * @param array
- * @return string
- */
- protected function _serialize($data)
- {
- if (is_array($data))
- {
- array_walk_recursive($data, array(&$this, '_escape_slashes'));
- }
- elseif (is_string($data))
- {
- $data = str_replace('\\', '{{slash}}', $data);
- }
- return serialize($data);
- }
-
- /**
- * Escape slashes
- *
- * This function converts any slashes found into a temporary marker
- *
- * @param string
- * @param string
- * @return void
- */
- protected function _escape_slashes(&$val, $key)
- {
- if (is_string($val))
- {
- $val = str_replace('\\', '{{slash}}', $val);
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Unserialize
- *
- * This function unserializes a data string, then converts any
- * temporary slash markers back to actual slashes
- *
- * @param array
- * @return string
- */
- protected function _unserialize($data)
- {
- $data = @unserialize(strip_slashes(trim($data)));
-
- if (is_array($data))
- {
- array_walk_recursive($data, array(&$this, '_unescape_slashes'));
- return $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)
- {
- if (is_string($val))
- {
- $val= str_replace('{{slash}}', '\\', $val);
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Garbage collection
- *
- * This deletes expired session rows from database
- * if the probability percentage is met
- *
- * @return void
- */
- protected function _sess_gc()
- {
- if ($this->sess_use_database != TRUE)
- {
- return;
- }
-
- srand(time());
- if ((rand() % 100) < $this->gc_probability)
- {
- $expire = $this->now - $this->sess_expiration;
-
- $this->CI->db->where('last_activity < '.$expire);
- $this->CI->db->delete($this->sess_table_name);
-
- log_message('debug', 'Session garbage collection performed.');
- }
- }
-
-}
-
-/* End of file Session.php */
-/* Location: ./system/libraries/Session.php */ \ No newline at end of file
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
new file mode 100755
index 000000000..e6f6050c0
--- /dev/null
+++ b/system/libraries/Session/Session.php
@@ -0,0 +1,689 @@
+<?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) 2006 - 2012 EllisLab, Inc.
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+/**
+ * CodeIgniter Session Class
+ *
+ * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms.
+ * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be
+ * used to specify the 'native' driver, or any other you might create.
+ * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the
+ * 'session' member of the global controller framework (e.g.: $CI->session or $this->session).
+ * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing.
+ * The CI_Session library class keeps track of the most recently loaded driver as "current" to call for driver methods.
+ * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods
+ * called through the specific driver will switch the "current" driver to itself before invoking the library method
+ * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be
+ * achieved by specifying which driver to use for each call (e.g.: $this->session->native->set_userdata('foo', 'bar');
+ * $this->session->cookie->userdata('foo'); $this->session->native->unset_userdata('foo');). Notice in the previous
+ * example that the _native_ userdata value 'foo' would be set to 'bar', which would NOT be returned by the call for
+ * the _cookie_ userdata 'foo', nor would the _cookie_ value be unset by the call to unset the _native_ 'foo' value.
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Sessions
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/libraries/sessions.html
+ */
+class CI_Session extends CI_Driver_Library {
+
+ public $params = array();
+ protected $current = NULL;
+ protected $userdata = array();
+
+ const FLASHDATA_KEY = 'flash';
+ const FLASHDATA_NEW = ':new:';
+ const FLASHDATA_OLD = ':old:';
+ const FLASHDATA_EXP = ':exp:';
+ const EXPIRATION_KEY = '__expirations';
+ const TEMP_EXP_DEF = 300;
+
+ /**
+ * CI_Session constructor
+ *
+ * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running
+ * routines in its constructor, and manages flashdata aging.
+ *
+ * @param array Configuration parameters
+ */
+ public function __construct(array $params = array())
+ {
+ log_message('debug', 'CI_Session Class Initialized');
+
+ // Get valid drivers list
+ $CI =& get_instance();
+ $this->valid_drivers = array(
+ 'Session_native',
+ 'Session_cookie'
+ );
+ $key = 'sess_valid_drivers';
+ $drivers = isset($params[$key]) ? $params[$key] : $CI->config->item($key);
+ if ($drivers)
+ {
+ is_array($drivers) OR $drivers = array($drivers);
+
+ // Add driver names to valid list
+ foreach ($drivers as $driver)
+ {
+ if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers)))
+ {
+ $this->valid_drivers[] = $driver;
+ }
+ }
+ }
+
+ // Get driver to load
+ $key = 'sess_driver';
+ $driver = isset($params[$key]) ? $params[$key] : $CI->config->item($key);
+ if ( ! $driver)
+ {
+ $driver = 'cookie';
+ }
+
+ if ( ! in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers)))
+ {
+ $this->valid_drivers[] = 'Session_'.$driver;
+ }
+
+ // Save a copy of parameters in case drivers need access
+ $this->params = $params;
+
+ // Load driver and get array reference
+ $this->load_driver($driver);
+
+ // Delete 'old' flashdata (from last request)
+ $this->_flashdata_sweep();
+
+ // Mark all new flashdata as old (data will be deleted before next request)
+ $this->_flashdata_mark();
+
+ // Delete expired tempdata
+ $this->_tempdata_sweep();
+
+ log_message('debug', 'CI_Session routines successfully run');
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Loads session storage driver
+ *
+ * @param string Driver classname
+ * @return object Loaded driver object
+ */
+ public function load_driver($driver)
+ {
+ // Save reference to most recently loaded driver as library default and sync userdata
+ $this->current = parent::load_driver($driver);
+ $this->userdata =& $this->current->get_userdata();
+ return $this->current;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Select default session storage driver
+ *
+ * @param string Driver classname
+ * @return void
+ */
+ public function select_driver($driver)
+ {
+ // Validate driver name
+ $lowername = strtolower(str_replace('CI_', '', $driver));
+ if (in_array($lowername, array_map('strtolower', $this->valid_drivers)))
+ {
+ // See if driver is loaded
+ $child = str_replace($this->lib_name.'_', '', $driver);
+ if (isset($this->$child))
+ {
+ // See if driver is already current
+ if ($this->$child !== $this->current)
+ {
+ // Make driver current and sync userdata
+ $this->current = $this->$child;
+ $this->userdata =& $this->current->get_userdata();
+ }
+ }
+ else
+ {
+ // Load new driver
+ $this->load_driver($child);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Destroy the current session
+ *
+ * @return void
+ */
+ public function sess_destroy()
+ {
+ // Just call destroy on driver
+ $this->current->sess_destroy();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Regenerate the current session
+ *
+ * @param bool Destroy session data flag (default: false)
+ * @return void
+ */
+ public function sess_regenerate($destroy = FALSE)
+ {
+ // Call regenerate on driver and resync userdata
+ $this->current->sess_regenerate($destroy);
+ $this->userdata =& $this->current->get_userdata();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch a specific item from the session array
+ *
+ * @param string Item key
+ * @return string Item value or NULL if not found
+ */
+ public function userdata($item)
+ {
+ return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch all session data
+ *
+ * @return array User data array
+ */
+ public function all_userdata()
+ {
+ return isset($this->userdata) ? $this->userdata : NULL;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch all flashdata
+ *
+ * @return array Flash data 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, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE)
+ {
+ $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key);
+ $out[$key] = $val;
+ }
+ }
+ return $out;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add or change data in the "userdata" array
+ *
+ * @param mixed Item name or array of items
+ * @param string Item value or empty string
+ * @return void
+ */
+ public function set_userdata($newdata = array(), $newval = '')
+ {
+ // Wrap params as array if singular
+ if (is_string($newdata))
+ {
+ $newdata = array($newdata => $newval);
+ }
+
+ // Set each name/value pair
+ if (count($newdata) > 0)
+ {
+ foreach ($newdata as $key => $val)
+ {
+ $this->userdata[$key] = $val;
+ }
+ }
+
+ // Tell driver data changed
+ $this->current->sess_save();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete a session variable from the "userdata" array
+ *
+ * @param mixed Item name or array of item names
+ * @return void
+ */
+ public function unset_userdata($newdata = array())
+ {
+ // Wrap single name as array
+ if (is_string($newdata))
+ {
+ $newdata = array($newdata => '');
+ }
+
+ // Unset each item name
+ if (count($newdata) > 0)
+ {
+ foreach (array_keys($newdata) as $key)
+ {
+ unset($this->userdata[$key]);
+ }
+ }
+
+ // Tell driver data changed
+ $this->current->sess_save();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Determine if an item exists
+ *
+ * @param string Item name
+ * @return bool
+ */
+ public function has_userdata($item)
+ {
+ return isset($this->userdata[$item]);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add or change flashdata, only available until the next request
+ *
+ * @param mixed Item name or array of items
+ * @param string Item value or empty string
+ * @return void
+ */
+ public function set_flashdata($newdata = array(), $newval = '')
+ {
+ // Wrap item as array if singular
+ if (is_string($newdata))
+ {
+ $newdata = array($newdata => $newval);
+ }
+
+ // Prepend each key name and set value
+ if (count($newdata) > 0)
+ {
+ foreach ($newdata as $key => $val)
+ {
+ $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key;
+ $this->set_userdata($flashdata_key, $val);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Keeps existing flashdata available to next request.
+ *
+ * @param string Item key
+ * @return void
+ */
+ public function keep_flashdata($key)
+ {
+ // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep()
+ // Note the function will return NULL if the $key provided cannot be found
+ $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key;
+ $value = $this->userdata($old_flashdata_key);
+
+ $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key;
+ $this->set_userdata($new_flashdata_key, $value);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch a specific flashdata item from the session array
+ *
+ * @param string Item key
+ * @return string
+ */
+ public function flashdata($key)
+ {
+ // Prepend key and retrieve value
+ $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key;
+ return $this->userdata($flashdata_key);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add or change tempdata, only available until expiration
+ *
+ * @param mixed Item name or array of items
+ * @param string Item value or empty string
+ * @param int Item lifetime in seconds or 0 for default
+ * @return void
+ */
+ public function set_tempdata($newdata = array(), $newval = '', $expire = 0)
+ {
+ // Set expiration time
+ $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF);
+
+ // Wrap item as array if singular
+ if (is_string($newdata))
+ {
+ $newdata = array($newdata => $newval);
+ }
+
+ // Get or create expiration list
+ $expirations = $this->userdata(self::EXPIRATION_KEY);
+ if ( ! $expirations)
+ {
+ $expirations = array();
+ }
+
+ // Prepend each key name and set value
+ if (count($newdata) > 0)
+ {
+ foreach ($newdata as $key => $val)
+ {
+ $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
+ $expirations[$tempdata_key] = $expire;
+ $this->set_userdata($tempdata_key, $val);
+ }
+ }
+
+ // Update expiration list
+ $this->set_userdata(self::EXPIRATION_KEY, $expirations);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete a temporary session variable from the "userdata" array
+ *
+ * @param mixed Item name or array of item names
+ * @return void
+ */
+ public function unset_tempdata($newdata = array())
+ {
+ // Get expirations list
+ $expirations = $this->userdata(self::EXPIRATION_KEY);
+ if (empty($expirations))
+ {
+ // Nothing to do
+ return;
+ }
+
+ // Wrap single name as array
+ if (is_string($newdata))
+ {
+ $newdata = array($newdata => '');
+ }
+
+ // Prepend each item name and unset
+ if (count($newdata) > 0)
+ {
+ foreach (array_keys($newdata) as $key)
+ {
+ $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
+ unset($expirations[$tempdata_key]);
+ $this->unset_userdata($tempdata_key);
+ }
+ }
+
+ // Update expiration list
+ $this->set_userdata(self::EXPIRATION_KEY, $expirations);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch a specific tempdata item from the session array
+ *
+ * @param string Item key
+ * @return string
+ */
+ public function tempdata($key)
+ {
+ // Prepend key and return value
+ $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
+ return $this->userdata($tempdata_key);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Identifies flashdata as 'old' for removal
+ * when _flashdata_sweep() runs.
+ *
+ * @return void
+ */
+ protected function _flashdata_mark()
+ {
+ foreach ($this->all_userdata() as $name => $value)
+ {
+ $parts = explode(self::FLASHDATA_NEW, $name);
+ if (is_array($parts) && count($parts) === 2)
+ {
+ $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1];
+ $this->set_userdata($new_name, $value);
+ $this->unset_userdata($name);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Removes all flashdata marked as 'old'
+ *
+ * @return void
+ */
+ protected function _flashdata_sweep()
+ {
+ $userdata = $this->all_userdata();
+ foreach (array_keys($userdata) as $key)
+ {
+ if (strpos($key, self::FLASHDATA_OLD))
+ {
+ $this->unset_userdata($key);
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Removes all expired tempdata
+ *
+ * @return void
+ */
+ protected function _tempdata_sweep()
+ {
+ // Get expirations list
+ $expirations = $this->userdata(self::EXPIRATION_KEY);
+ if (empty($expirations))
+ {
+ // Nothing to do
+ return;
+ }
+
+ // Unset expired elements
+ $now = time();
+ $userdata = $this->all_userdata();
+ foreach (array_keys($userdata) as $key)
+ {
+ if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now)
+ {
+ unset($expirations[$key]);
+ $this->unset_userdata($key);
+ }
+ }
+
+ // Update expiration list
+ $this->set_userdata(self::EXPIRATION_KEY, $expirations);
+ }
+
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * CI_Session_driver Class
+ *
+ * Extend this class to make a new CI_Session driver.
+ * A CI_Session driver basically manages an array of name/value pairs with some sort of storage mechanism.
+ * To make a new driver, derive from (extend) CI_Session_driver. Overload the initialize method and read or create
+ * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler
+ * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata).
+ * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the
+ * application directory, the system directory, or any path you add with $CI->load->add_package_path().
+ * Your driver must be named CI_Session_<name>, and your filename must be Session_<name>.php,
+ * preferably also capitalized. (e.g.: CI_Session_foo in libraries/Session/drivers/Session_foo.php)
+ * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the CI_Session
+ * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); )
+ * Already provided are the Native driver, which manages the native PHP $_SESSION array, and
+ * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table.
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Sessions
+ * @author EllisLab Dev Team
+ */
+abstract class CI_Session_driver extends CI_Driver {
+
+ /**
+ * Decorate
+ *
+ * Decorates the child with the parent driver lib's methods and properties
+ *
+ * @param object Parent library object
+ * @return void
+ */
+ public function decorate($parent)
+ {
+ // Call base class decorate first
+ parent::decorate($parent);
+
+ // Call initialize method now that driver has access to $this->_parent
+ $this->initialize();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * __call magic method
+ *
+ * Handles access to the parent driver library's methods
+ *
+ * @param string Library method name
+ * @param array Method arguments (default: none)
+ * @return mixed
+ */
+ public function __call($method, $args = array())
+ {
+ // Make sure the parent library uses this driver
+ $this->_parent->select_driver(get_class($this));
+ return parent::__call($method, $args);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Initialize driver
+ *
+ * @return void
+ */
+ protected function initialize()
+ {
+ // Overload this method to implement initialization
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save the session data
+ *
+ * Data in the array has changed - perform any storage synchronization
+ * necessary. The child class MUST implement this abstract method!
+ *
+ * @return void
+ */
+ abstract public function sess_save();
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Destroy the current session
+ *
+ * Clean up storage for this session - it has been terminated.
+ * The child class MUST implement this abstract method!
+ *
+ * @return void
+ */
+ abstract public function sess_destroy();
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Regenerate the current session
+ *
+ * Regenerate the session ID.
+ * The child class MUST implement this abstract method!
+ *
+ * @param bool Destroy session data flag (default: false)
+ * @return void
+ */
+ abstract public function sess_regenerate($destroy = FALSE);
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get a reference to user data array
+ *
+ * Give array access to the main CI_Session object.
+ * The child class MUST implement this abstract method!
+ *
+ * @return array Reference to userdata
+ */
+ abstract public function &get_userdata();
+
+}
+
+/* End of file Session.php */
+/* Location: ./system/libraries/Session/Session.php */ \ No newline at end of file
diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php
new file mode 100755
index 000000000..4f415cc0d
--- /dev/null
+++ b/system/libraries/Session/drivers/Session_cookie.php
@@ -0,0 +1,824 @@
+<?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 1.0
+ * @filesource
+ */
+
+/**
+ * Cookie-based session management driver
+ *
+ * This is the classic CI_Session functionality, as written by EllisLab, abstracted out to a driver.
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Sessions
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/libraries/sessions.html
+ */
+class CI_Session_cookie extends CI_Session_driver {
+
+ /**
+ * Whether to encrypt the session cookie
+ *
+ * @var bool
+ */
+ public $sess_encrypt_cookie = FALSE;
+
+ /**
+ * Whether to use to the database for session storage
+ *
+ * @var bool
+ */
+ public $sess_use_database = FALSE;
+
+ /**
+ * Name of the database table in which to store sessions
+ *
+ * @var string
+ */
+ public $sess_table_name = '';
+
+ /**
+ * Length of time (in seconds) for sessions to expire
+ *
+ * @var int
+ */
+ public $sess_expiration = 7200;
+
+ /**
+ * Whether to kill session on close of browser window
+ *
+ * @var bool
+ */
+ public $sess_expire_on_close = FALSE;
+
+ /**
+ * Whether to match session on ip address
+ *
+ * @var bool
+ */
+ public $sess_match_ip = FALSE;
+
+ /**
+ * Whether to match session on user-agent
+ *
+ * @var bool
+ */
+ public $sess_match_useragent = TRUE;
+
+ /**
+ * Name of session cookie
+ *
+ * @var string
+ */
+ public $sess_cookie_name = 'ci_session';
+
+ /**
+ * Session cookie prefix
+ *
+ * @var string
+ */
+ public $cookie_prefix = '';
+
+ /**
+ * Session cookie path
+ *
+ * @var string
+ */
+ public $cookie_path = '';
+
+ /**
+ * Session cookie domain
+ *
+ * @var string
+ */
+ public $cookie_domain = '';
+
+ /**
+ * Whether to set the cookie only on HTTPS connections
+ *
+ * @var bool
+ */
+ public $cookie_secure = FALSE;
+
+ /**
+ * Whether cookie should be allowed only to be sent by the server
+ *
+ * @var bool
+ */
+ public $cookie_httponly = FALSE;
+
+ /**
+ * Interval at which to update session
+ *
+ * @var int
+ */
+ public $sess_time_to_update = 300;
+
+ /**
+ * Key with which to encrypt the session cookie
+ *
+ * @var string
+ */
+ public $encryption_key = '';
+
+ /**
+ * Timezone to use for the current time
+ *
+ * @var string
+ */
+ public $time_reference = 'local';
+
+ /**
+ * Session data
+ *
+ * @var array
+ */
+ public $userdata = array();
+
+ /**
+ * Reference to CodeIgniter instance
+ *
+ * @var object
+ */
+ public $CI;
+
+ /**
+ * Current time
+ *
+ * @var int
+ */
+ public $now;
+
+ /**
+ * Default userdata keys
+ *
+ * @var array
+ */
+ protected $defaults = array(
+ 'session_id' => NULL,
+ 'ip_address' => NULL,
+ 'user_agent' => NULL,
+ 'last_activity' => NULL
+ );
+
+ /**
+ * Data needs DB update flag
+ *
+ * @var bool
+ */
+ protected $data_dirty = FALSE;
+
+ /**
+ * Initialize session driver object
+ *
+ * @return void
+ */
+ protected function initialize()
+ {
+ // 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 or via the config file
+ $prefs = 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'
+ );
+
+ foreach ($prefs as $key)
+ {
+ $this->$key = isset($this->_parent->params[$key])
+ ? $this->_parent->params[$key]
+ : $this->CI->config->item($key);
+ }
+
+ if ($this->encryption_key === '')
+ {
+ show_error('In order to use the Cookie Session driver you are required to set an encryption key in your config file.');
+ }
+
+ // Load the string helper so we can use the strip_slashes() function
+ $this->CI->load->helper('string');
+
+ // Do we need encryption? If so, load the encryption class
+ if ($this->sess_encrypt_cookie === TRUE)
+ {
+ $this->CI->load->library('encrypt');
+ }
+
+ // Check for database
+ if ($this->sess_use_database === TRUE && $this->sess_table_name !== '')
+ {
+ // Load database driver
+ $this->CI->load->database();
+
+ // Register shutdown function
+ register_shutdown_function(array($this, '_update_db'));
+ }
+
+ // 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
+ // set to zero we'll set the expiration two years from now.
+ if ($this->sess_expiration === 0)
+ {
+ $this->sess_expiration = (60*60*24*365*2);
+ }
+
+ // Set the cookie name
+ $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.
+ if ( ! $this->_sess_read())
+ {
+ $this->_sess_create();
+ }
+ else
+ {
+ $this->_sess_update();
+ }
+
+ // Delete expired sessions if necessary
+ $this->_sess_gc();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Write the session data
+ *
+ * @return void
+ */
+ public function sess_save()
+ {
+ // Check for database
+ if ($this->sess_use_database === TRUE)
+ {
+ // Mark custom data as dirty so we know to update the DB
+ $this->data_dirty = TRUE;
+ }
+
+ // Write the cookie
+ $this->_set_cookie();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Destroy the current session
+ *
+ * @return void
+ */
+ public function sess_destroy()
+ {
+ // Kill the session DB row
+ if ($this->sess_use_database === TRUE && isset($this->userdata['session_id']))
+ {
+ $this->CI->db->delete($this->sess_table_name, array('session_id' => $this->userdata['session_id']));
+ $this->data_dirty = FALSE;
+ }
+
+ // Kill the cookie
+ $this->_setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000),
+ $this->cookie_path, $this->cookie_domain, 0);
+
+ // Kill session data
+ $this->userdata = array();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Regenerate the current session
+ *
+ * Regenerate the session id
+ *
+ * @param bool Destroy session data flag (default: false)
+ * @return void
+ */
+ public function sess_regenerate($destroy = FALSE)
+ {
+ // Check destroy flag
+ if ($destroy)
+ {
+ // Destroy old session and create new one
+ $this->sess_destroy();
+ $this->_sess_create();
+ }
+ else
+ {
+ // Just force an update to recreate the id
+ $this->_sess_update(TRUE);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get a reference to user data array
+ *
+ * @return array Reference to userdata
+ */
+ public function &get_userdata()
+ {
+ return $this->userdata;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch the current session data if it exists
+ *
+ * @return bool
+ */
+ protected function _sess_read()
+ {
+ // Fetch the cookie
+ $session = $this->CI->input->cookie($this->sess_cookie_name);
+
+ // No cookie? Goodbye cruel world!...
+ if ($session === NULL)
+ {
+ log_message('debug', 'A session cookie was not found.');
+ return FALSE;
+ }
+
+ // Check for encryption
+ if ($this->sess_encrypt_cookie === TRUE)
+ {
+ // Decrypt the cookie data
+ $session = $this->CI->encrypt->decode($session);
+ }
+ else
+ {
+ // Encryption was not used, so we need to check the md5 hash in the last 32 chars
+ $len = strlen($session)-32;
+ $hash = substr($session, $len);
+ $session = substr($session, 0, $len);
+
+ // 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.');
+ $this->sess_destroy();
+ return FALSE;
+ }
+ }
+
+ // Unserialize the session array
+ $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'], $session['ip_address'], $session['user_agent'], $session['last_activity']))
+ {
+ $this->sess_destroy();
+ return FALSE;
+ }
+
+ // Is the session current?
+ if (($session['last_activity'] + $this->sess_expiration) < $this->now)
+ {
+ $this->sess_destroy();
+ return FALSE;
+ }
+
+ // 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 &&
+ trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120)))
+ {
+ $this->sess_destroy();
+ return FALSE;
+ }
+
+ // Is there a corresponding session in the DB?
+ if ($this->sess_use_database === TRUE)
+ {
+ $this->CI->db->where('session_id', $session['session_id']);
+
+ if ($this->sess_match_ip === TRUE)
+ {
+ $this->CI->db->where('ip_address', $session['ip_address']);
+ }
+
+ if ($this->sess_match_useragent === TRUE)
+ {
+ $this->CI->db->where('user_agent', $session['user_agent']);
+ }
+
+ // Is caching in effect? Turn it off
+ $db_cache = $this->CI->db->cache_on;
+ $this->CI->db->cache_off();
+
+ $query = $this->CI->db->limit(1)->get($this->sess_table_name);
+
+ // Was caching in effect?
+ if ($db_cache)
+ {
+ // Turn it back on
+ $this->CI->db->cache_on();
+ }
+
+ // No result? Kill it!
+ if ($query->num_rows() === 0)
+ {
+ $this->sess_destroy();
+ return FALSE;
+ }
+
+ // Is there custom data? If so, add it to the main session array
+ $row = $query->row();
+ if ( ! empty($row->user_data))
+ {
+ $custom_data = $this->_unserialize($row->user_data);
+
+ if (is_array($custom_data))
+ {
+ $session = $session + $custom_data;
+ }
+ }
+ }
+
+ // Session is valid!
+ $this->userdata = $session;
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a new session
+ *
+ * @return void
+ */
+ protected function _sess_create()
+ {
+ // Initialize userdata
+ $this->userdata = array(
+ 'session_id' => $this->_make_sess_id(),
+ 'ip_address' => $this->CI->input->ip_address(),
+ 'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
+ 'last_activity' => $this->now,
+ );
+
+ // Check for database
+ if ($this->sess_use_database === TRUE)
+ {
+ // Add empty user_data field and save the data to the DB
+ $this->CI->db->set('user_data', '')->insert($this->sess_table_name, $this->userdata);
+ }
+
+ // Write the cookie
+ $this->_set_cookie();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Update an existing session
+ *
+ * @param bool Force update flag (default: false)
+ * @return void
+ */
+ protected function _sess_update($force = FALSE)
+ {
+ // We only update the session every five minutes by default (unless forced)
+ if ( ! $force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
+ {
+ return;
+ }
+
+ // Update last activity to now
+ $this->userdata['last_activity'] = $this->now;
+
+ // Save the old session id so we know which DB record to update
+ $old_sessid = $this->userdata['session_id'];
+
+ // Changing the session ID during an AJAX call causes problems
+ if ( ! $this->CI->input->is_ajax_request())
+ {
+ // Get new id
+ $this->userdata['session_id'] = $this->_make_sess_id();
+ }
+
+ // Check for database
+ if ($this->sess_use_database === TRUE)
+ {
+ // Update the session ID and last_activity field in the DB
+ $this->CI->db->update($this->sess_table_name, array(
+ 'last_activity' => $this->now,
+ 'session_id' => $this->userdata['session_id']
+ ), array('session_id' => $old_sessid));
+ }
+
+ // Write the cookie
+ $this->_set_cookie();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Update database with current data
+ *
+ * This gets called from the shutdown function and also
+ * registered with PHP to run at the end of the request
+ * so it's guaranteed to update even when a fatal error
+ * occurs. The first call makes the update and clears the
+ * dirty flag so it won't happen twice.
+ *
+ * @return void
+ */
+ public function _update_db()
+ {
+ // Check for database and dirty flag and unsaved
+ if ($this->sess_use_database === TRUE && $this->data_dirty === TRUE)
+ {
+ // Set up activity and data fields to be set
+ // If we don't find custom data, user_data will remain an empty string
+ $set = array(
+ 'last_activity' => $this->userdata['last_activity'],
+ 'user_data' => ''
+ );
+
+ // Get the custom userdata, leaving out the defaults
+ // (which get stored in the cookie)
+ $userdata = array_diff_key($this->userdata, $this->defaults);
+
+ // Did we find any custom data?
+ if ( ! empty($userdata))
+ {
+ // Serialize the custom data array so we can store it
+ $set['user_data'] = $this->_serialize($userdata);
+ }
+
+ // Run the update query
+ // Any time we change the session id, it gets updated immediately,
+ // so our where clause below is always safe
+ $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id']));
+
+ // Clear dirty flag to prevent double updates
+ $this->data_dirty = FALSE;
+
+ log_message('debug', 'CI_Session Data Saved To DB');
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Generate a new session id
+ *
+ * @return string Hashed session id
+ */
+ protected function _make_sess_id()
+ {
+ $new_sessid = '';
+ do
+ {
+ $new_sessid .= mt_rand(0, mt_getrandmax());
+ }
+ while (strlen($new_sessid) < 32);
+
+ // To make the session ID even more secure we'll combine it with the user's IP
+ $new_sessid .= $this->CI->input->ip_address();
+
+ // Turn it into a hash and return
+ return md5(uniqid($new_sessid, TRUE));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the "now" time
+ *
+ * @return int Time
+ */
+ protected function _get_time()
+ {
+ if ($this->time_reference === 'local' OR $this->time_reference === date_default_timezone_get())
+ {
+ return time();
+ }
+
+ $datetime = new DateTime('now', new DateTimeZone($this->time_reference));
+ sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second);
+
+ return mktime($hour, $minute, $second, $month, $day, $year);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Write the session cookie
+ *
+ * @return void
+ */
+ protected function _set_cookie()
+ {
+ // Get userdata (only defaults if database)
+ $cookie_data = ($this->sess_use_database === TRUE)
+ ? array_intersect_key($this->userdata, $this->defaults)
+ : $this->userdata;
+
+ // Serialize the userdata for the cookie
+ $cookie_data = $this->_serialize($cookie_data);
+
+ $cookie_data = ($this->sess_encrypt_cookie === TRUE)
+ ? $this->CI->encrypt->encode($cookie_data)
+ // if encryption is not used, we provide an md5 hash to prevent userside tampering
+ : $cookie_data.md5($cookie_data.$this->encryption_key);
+
+ $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
+
+ // Set the cookie
+ $this->_setcookie($this->sess_cookie_name, $cookie_data, $expire, $this->cookie_path, $this->cookie_domain,
+ $this->cookie_secure, $this->cookie_httponly);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Set a cookie with the system
+ *
+ * This abstraction of the setcookie call allows overriding for unit testing
+ *
+ * @param string Cookie name
+ * @param string Cookie value
+ * @param int Expiration time
+ * @param string Cookie path
+ * @param string Cookie domain
+ * @param bool Secure connection flag
+ * @param bool HTTP protocol only flag
+ * @return void
+ */
+ protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE)
+ {
+ setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Serialize an array
+ *
+ * This function first converts any slashes found in the array to a temporary
+ * marker, so when it gets unserialized the slashes will be preserved
+ *
+ * @param mixed Data to serialize
+ * @return string Serialized data
+ */
+ protected function _serialize($data)
+ {
+ if (is_array($data))
+ {
+ array_walk_recursive($data, array(&$this, '_escape_slashes'));
+ }
+ elseif (is_string($data))
+ {
+ $data = str_replace('\\', '{{slash}}', $data);
+ }
+
+ return serialize($data);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Escape slashes
+ *
+ * This function converts any slashes found into a temporary marker
+ *
+ * @param string Value
+ * @param string Key
+ * @return void
+ */
+ protected function _escape_slashes(&$val, $key)
+ {
+ if (is_string($val))
+ {
+ $val = str_replace('\\', '{{slash}}', $val);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Unserialize
+ *
+ * This function unserializes a data string, then converts any
+ * temporary slash markers back to actual slashes
+ *
+ * @param mixed Data to unserialize
+ * @return mixed Unserialized data
+ */
+ protected function _unserialize($data)
+ {
+ $data = @unserialize(strip_slashes(trim($data)));
+
+ if (is_array($data))
+ {
+ array_walk_recursive($data, array(&$this, '_unescape_slashes'));
+ return $data;
+ }
+
+ return is_string($data) ? str_replace('{{slash}}', '\\', $data) : $data;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Unescape slashes
+ *
+ * This function converts any slash markers back into actual slashes
+ *
+ * @param string Value
+ * @param string Key
+ * @return void
+ */
+ protected function _unescape_slashes(&$val, $key)
+ {
+ if (is_string($val))
+ {
+ $val= str_replace('{{slash}}', '\\', $val);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Garbage collection
+ *
+ * This deletes expired session rows from database
+ * if the probability percentage is met
+ *
+ * @return void
+ */
+ protected function _sess_gc()
+ {
+ if ($this->sess_use_database !== TRUE)
+ {
+ return;
+ }
+
+ $probability = ini_get('session.gc_probability');
+ $divisor = ini_get('session.gc_divisor');
+
+ srand(time());
+ if ((mt_rand(0, $divisor) / $divisor) < $probability)
+ {
+ $expire = $this->now - $this->sess_expiration;
+ $this->CI->db->delete($this->sess_table_name, 'last_activity < '.$expire);
+
+ log_message('debug', 'Session garbage collection performed.');
+ }
+ }
+
+}
+
+/* End of file Session_cookie.php */
+/* Location: ./system/libraries/Session/drivers/Session_cookie.php */ \ No newline at end of file
diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php
new file mode 100755
index 000000000..c97e15356
--- /dev/null
+++ b/system/libraries/Session/drivers/Session_native.php
@@ -0,0 +1,232 @@
+<?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 1.0
+ * @filesource
+ */
+
+/**
+ * Native PHP session management driver
+ *
+ * This is the driver that uses the native PHP $_SESSION array through the Session driver library.
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Sessions
+ * @author EllisLab Dev Team
+ */
+class CI_Session_native extends CI_Session_driver {
+
+ /**
+ * Initialize session driver object
+ *
+ * @return void
+ */
+ protected function initialize()
+ {
+ // Get config parameters
+ $config = array();
+ $CI =& get_instance();
+ $prefs = array(
+ 'sess_cookie_name',
+ 'sess_expire_on_close',
+ 'sess_expiration',
+ 'sess_match_ip',
+ 'sess_match_useragent',
+ 'sess_time_to_update',
+ 'cookie_prefix',
+ 'cookie_path',
+ 'cookie_domain'
+ );
+
+ foreach ($prefs as $key)
+ {
+ $config[$key] = isset($this->_parent->params[$key])
+ ? $this->_parent->params[$key]
+ : $CI->config->item($key);
+ }
+
+ // Set session name, if specified
+ if ($config['sess_cookie_name'])
+ {
+ // Differentiate name from cookie driver with '_id' suffix
+ $name = $config['sess_cookie_name'].'_id';
+ if ($config['cookie_prefix'])
+ {
+ // Prepend cookie prefix
+ $name = $config['cookie_prefix'].$name;
+ }
+ session_name($name);
+ }
+
+ // Set expiration, path, and domain
+ $expire = 7200;
+ $path = '/';
+ $domain = '';
+ if ($config['sess_expiration'] !== FALSE)
+ {
+ // Default to 2 years if expiration is "0"
+ $expire = ($config['sess_expiration'] == 0) ? (60*60*24*365*2) : $config['sess_expiration'];
+ }
+
+ if ($config['cookie_path'])
+ {
+ // Use specified path
+ $path = $config['cookie_path'];
+ }
+
+ if ($config['cookie_domain'])
+ {
+ // Use specified domain
+ $domain = $config['cookie_domain'];
+ }
+ session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain);
+
+ // Start session
+ session_start();
+
+ // Check session expiration, ip, and agent
+ $now = time();
+ $destroy = FALSE;
+ if (isset($_SESSION['last_activity']) && ($_SESSION['last_activity'] + $expire) < $now)
+ {
+ // Expired - destroy
+ $destroy = TRUE;
+ }
+ elseif ($config['sess_match_ip'] === TRUE && isset($_SESSION['ip_address'])
+ && $_SESSION['ip_address'] !== $CI->input->ip_address())
+ {
+ // IP doesn't match - destroy
+ $destroy = TRUE;
+ }
+ elseif ($config['sess_match_useragent'] === TRUE && isset($_SESSION['user_agent'])
+ && $_SESSION['user_agent'] !== trim(substr($CI->input->user_agent(), 0, 50)))
+ {
+ // Agent doesn't match - destroy
+ $destroy = TRUE;
+ }
+
+ // Destroy expired or invalid session
+ if ($destroy)
+ {
+ // Clear old session and start new
+ $this->sess_destroy();
+ session_start();
+ }
+
+ // Check for update time
+ if ($config['sess_time_to_update'] && isset($_SESSION['last_activity'])
+ && ($_SESSION['last_activity'] + $config['sess_time_to_update']) < $now)
+ {
+ // Regenerate ID, but don't destroy session
+ $this->sess_regenerate(FALSE);
+ }
+
+ // Set activity time
+ $_SESSION['last_activity'] = $now;
+
+ // Set matching values as required
+ if ($config['sess_match_ip'] === TRUE && ! isset($_SESSION['ip_address']))
+ {
+ // Store user IP address
+ $_SESSION['ip_address'] = $CI->input->ip_address();
+ }
+
+ if ($config['sess_match_useragent'] === TRUE && ! isset($_SESSION['user_agent']))
+ {
+ // Store user agent string
+ $_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50));
+ }
+
+ // Make session ID available
+ $_SESSION['session_id'] = session_id();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save the session data
+ *
+ * @return void
+ */
+ public function sess_save()
+ {
+ // Nothing to do - changes to $_SESSION are automatically saved
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Destroy the current session
+ *
+ * @return void
+ */
+ public function sess_destroy()
+ {
+ // Cleanup session
+ $_SESSION = array();
+ $name = session_name();
+ if (isset($_COOKIE[$name]))
+ {
+ // Clear session cookie
+ $params = session_get_cookie_params();
+ setcookie($name, '', time() - 42000, $params['path'], $params['domain']);
+ unset($_COOKIE[$name]);
+ }
+ session_destroy();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Regenerate the current session
+ *
+ * Regenerate the session id
+ *
+ * @param bool Destroy session data flag (default: FALSE)
+ * @return void
+ */
+ public function sess_regenerate($destroy = FALSE)
+ {
+ // Just regenerate id, passing destroy flag
+ session_regenerate_id($destroy);
+ $_SESSION['session_id'] = session_id();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get a reference to user data array
+ *
+ * @return array Reference to userdata
+ */
+ public function &get_userdata()
+ {
+ // Just return reference to $_SESSION
+ return $_SESSION;
+ }
+
+}
+
+/* End of file Session_native.php */
+/* Location: ./system/libraries/Session/drivers/Session_native.php */ \ No newline at end of file
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index f844d6435..0f8404d85 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -169,7 +169,7 @@ class CI_Table {
// will want headings from a one-dimensional array
$this->auto_heading = FALSE;
- if ($col_limit == 0)
+ if ($col_limit === 0)
{
return $array;
}
@@ -298,7 +298,7 @@ class CI_Table {
}
elseif (is_array($table_data))
{
- $set_heading = (count($this->heading) !== 0 OR $this->auto_heading != FALSE);
+ $set_heading = (count($this->heading) !== 0 OR $this->auto_heading !== FALSE);
$this->_set_from_array($table_data, $set_heading);
}
}
@@ -336,7 +336,7 @@ class CI_Table {
foreach ($heading as $key => $val)
{
- if ($key != 'data')
+ if ($key !== 'data')
{
$temp = str_replace('<th', '<th '.$key.'="'.$val.'"', $temp);
}
@@ -481,7 +481,7 @@ class CI_Table {
foreach ($data as $row)
{
// If a heading hasn't already been set we'll use the first row of the array as the heading
- if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading == TRUE)
+ if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading === TRUE)
{
$this->heading = $this->_prep_args($row);
}
@@ -501,7 +501,7 @@ class CI_Table {
*/
protected function _compile_template()
{
- if ($this->template == NULL)
+ if ($this->template === NULL)
{
$this->template = $this->_default_template();
return;
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index 6761f63a5..9a680dc2a 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -88,7 +88,7 @@ class CI_Trackback {
}
// Convert High ASCII Characters
- if ($this->convert_ascii == TRUE && in_array($item, array('excerpt', 'title', 'blog_name')))
+ if ($this->convert_ascii === TRUE && in_array($item, array('excerpt', 'title', 'blog_name')))
{
$$item = $this->convert_ascii($$item);
}
@@ -106,7 +106,7 @@ class CI_Trackback {
{
foreach ($ping_url as $url)
{
- if ($this->process($url, $data) == FALSE)
+ if ($this->process($url, $data) === FALSE)
{
$return = FALSE;
}
@@ -132,7 +132,7 @@ class CI_Trackback {
{
foreach (array('url', 'title', 'blog_name', 'excerpt') as $val)
{
- if ( ! isset($_POST[$val]) OR $_POST[$val] == '')
+ if (empty($_POST[$val]))
{
$this->set_error('The following required POST variable is missing: '.$val);
return FALSE;
@@ -140,14 +140,14 @@ class CI_Trackback {
$this->data['charset'] = isset($_POST['charset']) ? strtoupper(trim($_POST['charset'])) : 'auto';
- if ($val != 'url' && MB_ENABLED === TRUE)
+ if ($val !== 'url' && MB_ENABLED === TRUE)
{
$_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']);
}
- $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]);
+ $_POST[$val] = ($val !== 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]);
- if ($val == 'excerpt')
+ if ($val === 'excerpt')
{
$_POST['excerpt'] = $this->limit_characters($_POST['excerpt']);
}
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 6aaa993ae..a50934f2c 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -95,7 +95,7 @@ class CI_Typography {
*/
public function auto_typography($str, $reduce_linebreaks = FALSE)
{
- if ($str == '')
+ if ($str === '')
{
return '';
}
@@ -173,7 +173,7 @@ class CI_Typography {
$process = ($match[1] === '/');
}
- if ($match[1] == '')
+ if ($match[1] === '')
{
$this->last_block_element = $match[2];
}
@@ -344,7 +344,7 @@ class CI_Typography {
*/
protected function _format_newlines($str)
{
- if ($str == '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)))
+ if ($str === '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)))
{
return $str;
}
@@ -356,7 +356,7 @@ class CI_Typography {
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Wrap the whole enchilada in enclosing paragraphs
- if ($str != "\n")
+ if ($str !== "\n")
{
// We trim off the right-side new line so that the closing </p> tag
// will be positioned immediately following the string, matching
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 6ec2dcd5d..c2c01758e 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -93,7 +93,7 @@ class CI_Unit_test {
*/
public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
{
- if ($this->active == FALSE)
+ if ($this->active === FALSE)
{
return FALSE;
}
@@ -106,7 +106,7 @@ class CI_Unit_test {
}
else
{
- $result = ($this->strict == TRUE) ? ($test === $expected) : ($test == $expected);
+ $result = ($this->strict === TRUE) ? ($test === $expected) : ($test === $expected);
$extype = gettype($expected);
}
@@ -124,7 +124,7 @@ class CI_Unit_test {
$this->results[] = $report;
- return($this->report($this->result($report)));
+ return $this->report($this->result($report));
}
// --------------------------------------------------------------------
@@ -155,13 +155,13 @@ class CI_Unit_test {
foreach ($res as $key => $val)
{
- if ($key == $CI->lang->line('ut_result'))
+ if ($key === $CI->lang->line('ut_result'))
{
- if ($val == $CI->lang->line('ut_passed'))
+ if ($val === $CI->lang->line('ut_passed'))
{
$val = '<span style="color: #0C0;">'.$val.'</span>';
}
- elseif ($val == $CI->lang->line('ut_failed'))
+ elseif ($val === $CI->lang->line('ut_failed'))
{
$val = '<span style="color: #C00;">'.$val.'</span>';
}
@@ -240,6 +240,11 @@ class CI_Unit_test {
{
foreach ($val as $k => $v)
{
+ if ( ! in_array($k, $this->_test_items_visible))
+ {
+ continue;
+ }
+
if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v))))
{
$v = $line;
@@ -289,15 +294,11 @@ class CI_Unit_test {
*/
protected function _backtrace()
{
- if (function_exists('debug_backtrace'))
- {
- $back = debug_backtrace();
- return array(
- 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
- 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
- );
- }
- return array('file' => 'Unknown', 'line' => 'Unknown');
+ $back = debug_backtrace();
+ return array(
+ 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
+ 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
+ );
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 271c6d21f..d381440cd 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -59,6 +59,7 @@ class CI_Upload {
public $error_msg = array();
public $mimes = array();
public $remove_spaces = TRUE;
+ public $detect_mime = TRUE;
public $xss_clean = FALSE;
public $temp_prefix = 'temp_file_';
public $client_name = '';
@@ -78,6 +79,8 @@ class CI_Upload {
$this->initialize($props);
}
+ $this->mimes =& get_mimes();
+
log_message('debug', 'Upload Class Initialized');
}
@@ -113,8 +116,8 @@ class CI_Upload {
'image_type' => '',
'image_size_str' => '',
'error_msg' => array(),
- 'mimes' => array(),
'remove_spaces' => TRUE,
+ 'detect_mime' => TRUE,
'xss_clean' => FALSE,
'temp_prefix' => 'temp_file_',
'client_name' => ''
@@ -208,7 +211,13 @@ class CI_Upload {
// Set the uploaded data as class variables
$this->file_temp = $_FILES[$field]['tmp_name'];
$this->file_size = $_FILES[$field]['size'];
- $this->_file_mime_type($_FILES[$field]);
+
+ // Skip MIME type detection?
+ if ($this->detect_mime !== FALSE)
+ {
+ $this->_file_mime_type($_FILES[$field]);
+ }
+
$this->file_type = preg_replace('/^(.+?);.*$/', '\\1', $this->file_type);
$this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
$this->file_name = $this->_prep_filename($_FILES[$field]['name']);
@@ -223,7 +232,7 @@ class CI_Upload {
}
// if we're overriding, let's now make sure the new name and type is allowed
- if ($this->_file_name_override != '')
+ if ($this->_file_name_override !== '')
{
$this->file_name = $this->_prep_filename($this->_file_name_override);
@@ -276,7 +285,7 @@ class CI_Upload {
}
// Remove white spaces in the name
- if ($this->remove_spaces == TRUE)
+ if ($this->remove_spaces === TRUE)
{
$this->file_name = preg_replace('/\s+/', '_', $this->file_name);
}
@@ -289,7 +298,7 @@ class CI_Upload {
*/
$this->orig_name = $this->file_name;
- if ($this->overwrite == FALSE)
+ if ($this->overwrite === FALSE)
{
$this->file_name = $this->set_filename($this->upload_path, $this->file_name);
@@ -346,11 +355,12 @@ class CI_Upload {
* Returns an associative array containing all of the information
* related to the upload, allowing the developer easy access in one array.
*
- * @return array
+ * @param string
+ * @return mixed
*/
- public function data()
+ public function data($index = NULL)
{
- return array(
+ $data = array(
'file_name' => $this->file_name,
'file_type' => $this->file_type,
'file_path' => $this->upload_path,
@@ -366,6 +376,13 @@ class CI_Upload {
'image_type' => $this->image_type,
'image_size_str' => $this->image_size_str,
);
+
+ if ( ! empty($index))
+ {
+ return isset($data[$index]) ? $data[$index] : NULL;
+ }
+
+ return $data;
}
// --------------------------------------------------------------------
@@ -397,7 +414,7 @@ class CI_Upload {
*/
public function set_filename($path, $filename)
{
- if ($this->encrypt_name == TRUE)
+ if ($this->encrypt_name === TRUE)
{
mt_srand();
$filename = md5(uniqid(mt_rand())).$this->file_ext;
@@ -420,7 +437,7 @@ class CI_Upload {
}
}
- if ($new_filename == '')
+ if ($new_filename === '')
{
$this->set_error('upload_bad_filename');
return FALSE;
@@ -545,7 +562,7 @@ class CI_Upload {
*/
public function set_xss_clean($flag = FALSE)
{
- $this->xss_clean = ($flag == TRUE);
+ $this->xss_clean = ($flag === TRUE);
}
// --------------------------------------------------------------------
@@ -641,7 +658,7 @@ class CI_Upload {
*/
public function is_allowed_filesize()
{
- return ($this->max_size == 0 OR $this->max_size > $this->file_size);
+ return ($this->max_size === 0 OR $this->max_size > $this->file_size);
}
// --------------------------------------------------------------------
@@ -687,13 +704,13 @@ class CI_Upload {
*/
public function validate_upload_path()
{
- if ($this->upload_path == '')
+ if ($this->upload_path === '')
{
$this->set_error('upload_no_filepath');
return FALSE;
}
- if (function_exists('realpath') && @realpath($this->upload_path) !== FALSE)
+ if (@realpath($this->upload_path) !== FALSE)
{
$this->upload_path = str_replace('\\', '/', realpath($this->upload_path));
}
@@ -747,6 +764,8 @@ class CI_Upload {
';',
'?',
'/',
+ '!',
+ '#',
'%20',
'%22',
'%3c', // <
@@ -812,17 +831,17 @@ class CI_Upload {
return FALSE;
}
- if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit') != '')
+ if (memory_get_usage() && ($memory_limit = ini_get('memory_limit')))
{
- $current = ini_get('memory_limit') * 1024 * 1024;
+ $memory_limit *= 1024 * 1024;
// There was a bug/behavioural change in PHP 5.2, where numbers over one million get output
// into scientific notation. number_format() ensures this number is an integer
// http://bugs.php.net/bug.php?id=43053
- $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', '');
+ $memory_limit = number_format(ceil(filesize($file) + $memory_limit), 0, '.', '');
- ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net
+ ini_set('memory_limit', $memory_limit); // When an integer is used, the value is measured in bytes. - PHP.net
}
// If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but
@@ -846,14 +865,8 @@ class CI_Upload {
// <a, <body, <head, <html, <img, <plaintext, <pre, <script, <table, <title
// title is basically just in SVG, but we filter it anyhow
- if ( ! preg_match('/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i', $opening_bytes))
- {
- return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good
- }
- else
- {
- return FALSE;
- }
+ // if its an image or no "triggers" detected in the first 256 bytes - we're good
+ return ! preg_match('/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i', $opening_bytes);
}
if (($data = @file_get_contents($file)) === FALSE)
@@ -882,14 +895,14 @@ class CI_Upload {
{
foreach ($msg as $val)
{
- $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);
+ $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val);
$this->error_msg[] = $msg;
log_message('error', $msg);
}
}
else
{
- $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg);
+ $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg);
$this->error_msg[] = $msg;
log_message('error', $msg);
}
@@ -922,26 +935,6 @@ class CI_Upload {
*/
public function mimes_types($mime)
{
- global $mimes;
-
- if (count($this->mimes) == 0)
- {
- 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');
- }
- else
- {
- return FALSE;
- }
-
- $this->mimes = $mimes;
- }
-
return isset($this->mimes[$mime]) ? $this->mimes[$mime] : FALSE;
}
@@ -958,7 +951,7 @@ class CI_Upload {
*/
protected function _prep_filename($filename)
{
- if (strpos($filename, '.') === FALSE OR $this->allowed_types == '*')
+ if (strpos($filename, '.') === FALSE OR $this->allowed_types === '*')
{
return $filename;
}
@@ -1005,7 +998,7 @@ class CI_Upload {
*/
if (function_exists('finfo_file'))
{
- $finfo = finfo_open(FILEINFO_MIME);
+ $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
{
$mime = @finfo_file($finfo, $file['tmp_name']);
@@ -1036,7 +1029,9 @@ class CI_Upload {
*/
if (DIRECTORY_SEPARATOR !== '\\')
{
- $cmd = 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1';
+ $cmd = function_exists('escapeshellarg')
+ ? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
+ : 'file --brief --mime '.$file['tmp_name'].' 2>&1';
if (function_exists('exec'))
{
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index 0d2533855..dc5d27f8c 100644..100755
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -174,7 +174,7 @@ class CI_Xmlrpc {
* @param int port
* @return void
*/
- public function server($url, $port = 80)
+ public function server($url, $port = 80, $proxy = FALSE, $proxy_port = 8080)
{
if (strpos($url, 'http') !== 0)
{
@@ -190,7 +190,7 @@ class CI_Xmlrpc {
$path .= '?'.$parts['query'];
}
- $this->client = new XML_RPC_Client($path, $parts['host'], $port);
+ $this->client = new XML_RPC_Client($path, $parts['host'], $port, $proxy, $proxy_port);
}
// --------------------------------------------------------------------
@@ -256,7 +256,7 @@ class CI_Xmlrpc {
*/
public function set_debug($flag = TRUE)
{
- $this->debug = ($flag == TRUE);
+ $this->debug = ($flag === TRUE);
}
// --------------------------------------------------------------------
@@ -277,7 +277,7 @@ class CI_Xmlrpc {
}
else
{
- if (is_array($value[0]) && ($value[1] == 'struct' OR $value[1] == 'array'))
+ if (is_array($value[0]) && ($value[1] === 'struct' OR $value[1] === 'array'))
{
while (list($k) = each($value[0]))
{
@@ -385,6 +385,8 @@ class XML_RPC_Client extends CI_Xmlrpc
public $path = '';
public $server = '';
public $port = 80;
+ public $proxy = FALSE;
+ public $proxy_port = 8080;
public $errno = '';
public $errstring = '';
public $timeout = 5;
@@ -398,13 +400,15 @@ class XML_RPC_Client extends CI_Xmlrpc
* @param int
* @return void
*/
- public function __construct($path, $server, $port = 80)
+ public function __construct($path, $server, $port = 80, $proxy = FALSE, $proxy_port = 8080)
{
parent::__construct();
$this->port = $port;
$this->server = $server;
$this->path = $path;
+ $this->proxy = $proxy;
+ $this->proxy_port = $proxy_port;
}
// --------------------------------------------------------------------
@@ -436,7 +440,18 @@ class XML_RPC_Client extends CI_Xmlrpc
*/
public function sendPayload($msg)
{
- $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstring, $this->timeout);
+ if ($this->proxy === FALSE)
+ {
+ $server = $this->server;
+ $port = $this->port;
+ }
+ else
+ {
+ $server = $this->proxy;
+ $port = $this->proxy_port;
+ }
+
+ $fp = @fsockopen($server, $port, $this->errno, $this->errstring, $this->timeout);
if ( ! is_resource($fp))
{
@@ -496,7 +511,7 @@ class XML_RPC_Response
*/
public function __construct($val, $code = 0, $fstr = '')
{
- if ($code != 0)
+ if ($code !== 0)
{
// error
$this->errno = $code;
@@ -636,11 +651,11 @@ class XML_RPC_Response
{
$kind = $xmlrpc_val->kindOf();
- if ($kind == 'scalar')
+ if ($kind === 'scalar')
{
return $xmlrpc_val->scalarval();
}
- elseif ($kind == 'array')
+ elseif ($kind === 'array')
{
reset($xmlrpc_val->me);
$b = current($xmlrpc_val->me);
@@ -652,7 +667,7 @@ class XML_RPC_Response
}
return $arr;
}
- elseif ($kind == 'struct')
+ elseif ($kind === 'struct')
{
reset($xmlrpc_val->me['struct']);
$arr = array();
@@ -680,7 +695,7 @@ class XML_RPC_Response
$t = 0;
if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs))
{
- $fnc = ($utc == TRUE) ? 'gmmktime' : 'mktime';
+ $fnc = ($utc === TRUE) ? 'gmmktime' : 'mktime';
$t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
return $t;
@@ -778,7 +793,7 @@ class XML_RPC_Message extends CI_Xmlrpc
}
// Check for HTTP 200 Response
- if (strncmp($data, 'HTTP', 4) === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data))
+ if (strpos($data, 'HTTP') === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data))
{
$errstr = substr($data, 0, strpos($data, "\n")-1);
return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error'].' ('.$errstr.')');
@@ -873,7 +888,7 @@ class XML_RPC_Message extends CI_Xmlrpc
$errstr_v = $v->me['struct']['faultString'];
$errno = $errno_v->scalarval();
- if ($errno == 0)
+ if ($errno === 0)
{
// FAULT returned, errno needs to reflect that
$errno = -1;
@@ -921,9 +936,9 @@ class XML_RPC_Message extends CI_Xmlrpc
if ($this->xh[$the_parser]['isf'] > 1) return;
// Evaluate and check for correct nesting of XML elements
- if (count($this->xh[$the_parser]['stack']) == 0)
+ if (count($this->xh[$the_parser]['stack']) === 0)
{
- if ($name != 'METHODRESPONSE' && $name != 'METHODCALL')
+ if ($name !== 'METHODRESPONSE' && $name !== 'METHODCALL')
{
$this->xh[$the_parser]['isf'] = 2;
$this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
@@ -968,7 +983,7 @@ class XML_RPC_Message extends CI_Xmlrpc
case 'DOUBLE':
case 'DATETIME.ISO8601':
case 'BASE64':
- if ($this->xh[$the_parser]['vt'] != 'value')
+ if ($this->xh[$the_parser]['vt'] !== 'value')
{
//two data elements inside a value: an error occurred!
$this->xh[$the_parser]['isf'] = 2;
@@ -1002,7 +1017,7 @@ class XML_RPC_Message extends CI_Xmlrpc
// Add current element name to stack, to allow validation of nesting
array_unshift($this->xh[$the_parser]['stack'], $name);
- $name == 'VALUE' OR $this->xh[$the_parser]['lv'] = 0;
+ $name === 'VALUE' OR $this->xh[$the_parser]['lv'] = 0;
}
// --------------------------------------------------------------------
@@ -1045,20 +1060,20 @@ class XML_RPC_Message extends CI_Xmlrpc
case 'BASE64':
$this->xh[$the_parser]['vt'] = strtolower($name);
- if ($name == 'STRING')
+ if ($name === 'STRING')
{
$this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
}
- elseif ($name == 'DATETIME.ISO8601')
+ elseif ($name === 'DATETIME.ISO8601')
{
$this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime;
$this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
}
- elseif ($name == 'BASE64')
+ elseif ($name === 'BASE64')
{
$this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']);
}
- elseif ($name == 'BOOLEAN')
+ elseif ($name === 'BOOLEAN')
{
// Translated BOOLEAN values to TRUE AND FALSE
$this->xh[$the_parser]['value'] = (bool) $this->xh[$the_parser]['ac'];
@@ -1093,7 +1108,7 @@ class XML_RPC_Message extends CI_Xmlrpc
// build the XML-RPC value out of the data received, and substitute it
$temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']);
- if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY')
+ if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] === 'ARRAY')
{
// Array
$this->xh[$the_parser]['valuestack'][0]['values'][] = $temp;
@@ -1151,9 +1166,9 @@ class XML_RPC_Message extends CI_Xmlrpc
if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already
// If a value has not been found
- if ($this->xh[$the_parser]['lv'] != 3)
+ if ($this->xh[$the_parser]['lv'] !== 3)
{
- if ($this->xh[$the_parser]['lv'] == 1)
+ if ($this->xh[$the_parser]['lv'] === 1)
{
$this->xh[$the_parser]['lv'] = 2; // Found a value
}
@@ -1204,7 +1219,7 @@ class XML_RPC_Message extends CI_Xmlrpc
{
// 'bits' is for the MetaWeblog API image bits
// @todo - this needs to be made more general purpose
- $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]);
+ $array[$key] = ($key === 'bits' OR $this->xss_clean === FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]);
}
}
@@ -1242,11 +1257,11 @@ class XML_RPC_Message extends CI_Xmlrpc
{
$kind = $param->kindOf();
- if ($kind == 'scalar')
+ if ($kind === 'scalar')
{
return $param->scalarval();
}
- elseif ($kind == 'array')
+ elseif ($kind === 'array')
{
reset($param->me);
$b = current($param->me);
@@ -1259,7 +1274,7 @@ class XML_RPC_Message extends CI_Xmlrpc
return $arr;
}
- elseif ($kind == 'struct')
+ elseif ($kind === 'struct')
{
reset($param->me['struct']);
$arr = array();
@@ -1298,9 +1313,9 @@ class XML_RPC_Values extends CI_Xmlrpc
{
parent::__construct();
- if ($val != -1 OR $type != '')
+ if ($val !== -1 OR $type !== '')
{
- $type = $type == '' ? 'string' : $type;
+ $type = $type === '' ? 'string' : $type;
if ($this->xmlrpcTypes[$type] == 1)
{
@@ -1330,7 +1345,7 @@ class XML_RPC_Values extends CI_Xmlrpc
{
$typeof = $this->xmlrpcTypes[$type];
- if ($this->mytype == 1)
+ if ($this->mytype === 1)
{
echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />';
return 0;
@@ -1342,12 +1357,12 @@ class XML_RPC_Values extends CI_Xmlrpc
return 0;
}
- if ($type == $this->xmlrpcBoolean)
+ if ($type === $this->xmlrpcBoolean)
{
- $val = (int) (strcasecmp($val,'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false')));
+ $val = (int) (strcasecmp($val, 'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false')));
}
- if ($this->mytype == 2)
+ if ($this->mytype === 2)
{
// adding to an array here
$ar = $this->me['array'];
@@ -1374,7 +1389,7 @@ class XML_RPC_Values extends CI_Xmlrpc
*/
public function addArray($vals)
{
- if ($this->mytype != 0)
+ if ($this->mytype !== 0)
{
echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
return 0;
@@ -1395,7 +1410,7 @@ class XML_RPC_Values extends CI_Xmlrpc
*/
public function addStruct($vals)
{
- if ($this->mytype != 0)
+ if ($this->mytype !== 0)
{
echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
return 0;
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 1853906ea..5d01d374d 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -208,7 +208,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
// Get Data
//-------------------------------------
- if ($data == '')
+ if ($data === '')
{
$data = $HTTP_RAW_POST_DATA;
}
@@ -230,7 +230,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
);
xml_set_object($parser, $parser_object);
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE);
xml_set_element_handler($parser, 'open_tag', 'closing_tag');
xml_set_character_data_handler($parser, 'character_data');
//xml_set_default_handler($parser, 'default_handler');
@@ -303,9 +303,9 @@ class CI_Xmlrpcs extends CI_Xmlrpc
$methName = $m->method_name;
// Check to see if it is a system call
- $system_call = (strncmp($methName, 'system', 5) === 0);
+ $system_call = (strpos($methName, 'system') === 0);
- if ($this->xss_clean == FALSE)
+ if ($this->xss_clean === FALSE)
{
$m->xss_clean = FALSE;
}
@@ -324,7 +324,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
//-------------------------------------
$method_parts = explode('.', $this->methods[$methName]['function']);
- $objectCall = (isset($method_parts[1]) && $method_parts[1] != '');
+ $objectCall = (isset($method_parts[1]) && $method_parts[1] !== '');
if ($system_call === TRUE)
{
@@ -356,9 +356,9 @@ class CI_Xmlrpcs extends CI_Xmlrpc
for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
{
$p = $m->params[$n];
- $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf();
+ $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf();
- if ($pt != $current_sig[$n+1])
+ if ($pt !== $current_sig[$n+1])
{
$pno = $n+1;
$wanted = $current_sig[$n+1];
@@ -527,7 +527,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
$attempt = $this->_execute($m);
- if ($attempt->faultCode() != 0)
+ if ($attempt->faultCode() !== 0)
{
return $attempt;
}
@@ -567,7 +567,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
*/
public function do_multicall($call)
{
- if ($call->kindOf() != 'struct')
+ if ($call->kindOf() !== 'struct')
{
return $this->multicall_error('notstruct');
}
@@ -577,13 +577,13 @@ class CI_Xmlrpcs extends CI_Xmlrpc
}
list($scalar_type,$scalar_value)=each($methName->me);
- $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
+ $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
- if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string')
+ if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string')
{
return $this->multicall_error('notstring');
}
- elseif ($scalar_value == 'system.multicall')
+ elseif ($scalar_value === 'system.multicall')
{
return $this->multicall_error('recursion');
}
@@ -591,7 +591,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
{
return $this->multicall_error('noparams');
}
- elseif ($params->kindOf() != 'array')
+ elseif ($params->kindOf() !== 'array')
{
return $this->multicall_error('notarray');
}
@@ -606,7 +606,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc
$result = $this->_execute($msg);
- if ($result->faultCode() != 0)
+ if ($result->faultCode() !== 0)
{
return $this->multicall_error($result);
}
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index e0dc637ad..5c4c257f8 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -40,7 +40,7 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/zip.html
*/
-class CI_Zip {
+class CI_Zip {
/**
* Zip data in string form
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php
index 3c9ae1867..44c16b578 100644
--- a/system/libraries/javascript/Jquery.php
+++ b/system/libraries/javascript/Jquery.php
@@ -416,12 +416,12 @@ class CI_Jquery extends CI_Javascript {
$animations = substr($animations, 0, -2); // remove the last ", "
- if ($speed != '')
+ if ($speed !== '')
{
$speed = ', '.$speed;
}
- if ($extra != '')
+ if ($extra !== '')
{
$extra = ', '.$extra;
}
@@ -446,7 +446,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -471,7 +471,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -496,7 +496,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -537,7 +537,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -562,7 +562,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -587,7 +587,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -644,7 +644,7 @@ class CI_Jquery extends CI_Javascript {
$element = $this->_prep_element($element);
$speed = $this->_validate_speed($speed);
- if ($callback != '')
+ if ($callback !== '')
{
$callback = ", function(){\n{$callback}\n}";
}
@@ -672,7 +672,7 @@ class CI_Jquery extends CI_Javascript {
$controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
// ajaxStart and ajaxStop are better choices here... but this is a stop gap
- if ($this->CI->config->item('javascript_ajax_img') == '')
+ if ($this->CI->config->item('javascript_ajax_img') === '')
{
$loading_notifier = 'Loading...';
}
@@ -685,7 +685,7 @@ class CI_Jquery extends CI_Javascript {
."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
$request_options = '';
- if ($options != '')
+ if ($options !== '')
{
$request_options .= ', {'
.(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
@@ -709,12 +709,12 @@ class CI_Jquery extends CI_Javascript {
*/
protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
{
- $class = ($class != '') ? '.'.$class : '';
+ $class = ($class !== '') ? '.'.$class : '';
$zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
$this->jquery_code_for_compile[] = $zebra;
- if ($hover != '')
+ if ($hover !== '')
{
$hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
}
@@ -739,7 +739,7 @@ class CI_Jquery extends CI_Javascript {
// may want to make this configurable down the road
$corner_location = '/plugins/jquery.corner.js';
- if ($corner_style != '')
+ if ($corner_style !== '')
{
$corner_style = '"'.$corner_style.'"';
}
@@ -972,7 +972,7 @@ class CI_Jquery extends CI_Javascript {
*/
protected function _prep_element($element)
{
- if ($element != 'this')
+ if ($element !== 'this')
{
$element = '"'.$element.'"';
}
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
index 9f89d1be8..5216038c6 100644
--- a/tests/Bootstrap.php
+++ b/tests/Bootstrap.php
@@ -7,13 +7,30 @@ error_reporting(E_ALL | E_STRICT);
$dir = realpath(dirname(__FILE__));
// Path constants
-define('PROJECT_BASE', realpath($dir.'/../').'/');
-define('BASEPATH', PROJECT_BASE.'system/');
-define('APPPATH', PROJECT_BASE.'application/');
-define('VIEWPATH', PROJECT_BASE.'');
+defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/');
+defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/');
+defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/');
+defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.'');
+
+// Get vfsStream either via PEAR or composer
+foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
+{
+ if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.php'))
+ {
+ require_once 'vfsStream/vfsStream.php';
+ break;
+ }
+}
+
+if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.php'))
+{
+ include_once PROJECT_BASE.'vendor/autoload.php';
+ class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
+ class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
+ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
+}
// Prep our test environment
-require_once 'vfsStream/vfsStream.php';
include_once $dir.'/mocks/core/common.php';
include_once $dir.'/mocks/autoloader.php';
spl_autoload_register('autoload');
diff --git a/tests/README.md b/tests/README.md
index c8fc608e8..d600951ee 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -21,8 +21,8 @@ PHP Unit >= 3.5.6
vfsStream
- pear channel-discover pear.php-tools.net
- pear install pat/vfsStream-alpha
+ pear channel-discover pear.bovigo.org
+ pear install bovigo/vfsStream-beta
#### Installation of PEAR and PHPUnit on Ubuntu
@@ -37,11 +37,11 @@ vfsStream
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
+ pear channel-discover pear.bovigo.org
# Finally install PHPUnit and vfsStream (including dependencies)
pear install --alldeps phpunit/PHPUnit
- pear install --alldeps pat/vfsStream-alpha
+ pear install --alldeps bovigo/vfsStream-beta
# Finally, run 'phpunit' from within the ./tests directory
# and you should be on your way!
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
index b48e32bfb..5317c56c7 100644
--- a/tests/codeigniter/Setup_test.php
+++ b/tests/codeigniter/Setup_test.php
@@ -1,13 +1,13 @@
<?php
class Setup_test extends PHPUnit_Framework_TestCase {
-
- function test_bootstrap_constants()
+
+ public function test_bootstrap_constants()
{
$this->assertTrue(defined('PROJECT_BASE'));
$this->assertTrue(defined('BASEPATH'));
$this->assertTrue(defined('APPPATH'));
$this->assertTrue(defined('VIEWPATH'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index 109b38821..a239ba51d 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -1,14 +1,14 @@
<?php
class Benchmark_test extends CI_TestCase {
-
+
public function set_up()
{
$this->benchmark = new Mock_Core_Benchmark();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_mark()
{
$this->assertEmpty($this->benchmark->marker);
@@ -18,7 +18,7 @@ class Benchmark_test extends CI_TestCase {
$this->assertEquals(1, count($this->benchmark->marker));
$this->assertArrayHasKey('code_start', $this->benchmark->marker);
}
-
+
// --------------------------------------------------------------------
public function test_elapsed_time()
@@ -29,7 +29,7 @@ class Benchmark_test extends CI_TestCase {
$this->benchmark->mark('code_start');
sleep(1);
$this->benchmark->mark('code_end');
-
+
$this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
}
@@ -39,4 +39,5 @@ class Benchmark_test extends CI_TestCase {
{
$this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
index dded2e824..27d48efc2 100644
--- a/tests/codeigniter/core/Common_test.php
+++ b/tests/codeigniter/core/Common_test.php
@@ -1,13 +1,44 @@
<?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'));
}
-
+
+ // ------------------------------------------------------------------------
+
+ public function test_stringify_attributes()
+ {
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar')));
+
+ $atts = new Stdclass;
+ $atts->class = 'foo';
+ $atts->id = 'bar';
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts));
+
+ $atts = new Stdclass;
+ $this->assertEquals('', _stringify_attributes($atts));
+
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"'));
+
+ $this->assertEquals('', _stringify_attributes(array()));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_stringify_js_attributes()
+ {
+ $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE));
+
+ $atts = new Stdclass;
+ $atts->width = 800;
+ $atts->height = 600;
+ $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE));
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 30f0cc61d..30cb90a28 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -5,7 +5,7 @@ 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',
@@ -13,9 +13,9 @@ class Config_test extends CI_TestCase {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
// --------------------------------------------------------------------
public function test_item()
@@ -24,30 +24,30 @@ class Config_test extends CI_TestCase {
// 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'));
@@ -58,33 +58,33 @@ class Config_test extends CI_TestCase {
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);
+ $this->config->set_item('enable_query_strings', $q_string);
}
// --------------------------------------------------------------------
-
+
public function test_system_url()
{
$this->assertEquals('http://example.com/system/', $this->config->system_url());
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index fd0576e38..fe8738832 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -1,7 +1,7 @@
<?php
class Input_test extends CI_TestCase {
-
+
public function set_up()
{
// Set server variable to GET as default, since this will leave unset in STDIN env
@@ -17,9 +17,9 @@ class Input_test extends CI_TestCase {
$this->input = new Mock_Core_Input($security, $utf8);
}
-
+
// --------------------------------------------------------------------
-
+
public function test_get_not_exists()
{
$this->assertEmpty($this->input->get());
@@ -28,15 +28,17 @@ class Input_test extends CI_TestCase {
$this->assertTrue( ! $this->input->get());
$this->assertTrue( ! $this->input->get('foo'));
- $this->assertTrue($this->input->get() == FALSE);
- $this->assertTrue($this->input->get('foo') == FALSE);
+ // Test we're getting empty results
+ $this->assertTrue($this->input->get() === NULL);
+ $this->assertTrue($this->input->get('foo') === NULL);
- $this->assertTrue($this->input->get() === FALSE);
- $this->assertTrue($this->input->get('foo') === FALSE);
+ // Test new 3.0 behaviour for non existant results (used to be FALSE)
+ $this->assertTrue($this->input->get() === NULL);
+ $this->assertTrue($this->input->get('foo') === NULL);
}
// --------------------------------------------------------------------
-
+
public function test_get_exist()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -47,7 +49,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -59,7 +61,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_not_exists()
{
$this->assertEmpty($this->input->post());
@@ -68,15 +70,15 @@ class Input_test extends CI_TestCase {
$this->assertTrue( ! $this->input->post());
$this->assertTrue( ! $this->input->post('foo'));
- $this->assertTrue($this->input->post() == FALSE);
- $this->assertTrue($this->input->post('foo') == FALSE);
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
- $this->assertTrue($this->input->post() === FALSE);
- $this->assertTrue($this->input->post('foo') === FALSE);
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
}
// --------------------------------------------------------------------
-
+
public function test_post_exist()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -87,7 +89,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -99,7 +101,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_post()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -109,7 +111,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_cookie()
{
$_COOKIE['foo'] = 'bar';
@@ -118,14 +120,14 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_server()
{
$this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
}
// --------------------------------------------------------------------
-
+
public function test_fetch_from_array()
{
$data = array(
@@ -141,4 +143,19 @@ class Input_test extends CI_TestCase {
$this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $harm);
$this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
}
+
+ // --------------------------------------------------------------------
+
+ public function test_valid_ip()
+ {
+ $ip_v4 = '192.18.0.1';
+ $this->assertTrue($this->input->valid_ip($ip_v4));
+
+ $ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001');
+ foreach ($ip_v6 as $ip)
+ {
+ $this->assertTrue($this->input->valid_ip($ip));
+ }
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
index a414f0ace..a410dabfa 100644
--- a/tests/codeigniter/core/Lang_test.php
+++ b/tests/codeigniter/core/Lang_test.php
@@ -1,9 +1,9 @@
<?php
class Lang_test extends CI_TestCase {
-
+
protected $lang;
-
+
public function set_up()
{
$loader_cls = $this->ci_core_class('load');
@@ -12,20 +12,21 @@ class Lang_test extends CI_TestCase {
$cls = $this->ci_core_class('lang');
$this->lang = new $cls;
}
-
+
// --------------------------------------------------------------------
-
+
public function test_load()
{
$this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
}
-
+
// --------------------------------------------------------------------
- public function test_line()
+ public function test_load_with_unspecified_language()
{
- $this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertTrue($this->lang->load('profiler'));
$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
index 43008651e..fdea962b7 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -1,35 +1,35 @@
<?php
class Loader_test extends CI_TestCase {
-
+
private $ci_obj;
-
+
public function set_up()
{
// Instantiate a new loader
$this->load = new Mock_Core_Loader();
-
+
// mock up a ci instance
- $this->ci_obj = new StdClass;
-
+ $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', ' '));
}
@@ -39,20 +39,18 @@ class Loader_test extends CI_TestCase {
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);
-
+
+ $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'));
+ $this->assertTrue(class_exists('Super_test_library'));
}
-
+
// --------------------------------------------------------------------
-
+
private function _setup_config_mock()
{
// Mock up a config object until we
@@ -61,7 +59,7 @@ class Loader_test extends CI_TestCase {
$config->expects($this->any())
->method('load')
->will($this->returnValue(TRUE));
-
+
// Add the mock to our stdClass
$this->ci_instance_var('config', $config);
}
@@ -73,64 +71,62 @@ class Loader_test extends CI_TestCase {
$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);
-
+
+ $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(''));
+ $this->assertNull($this->load->model(''));
}
// --------------------------------------------------------------------
-
+
// public function testDatabase()
// {
// $this->assertEquals(NULL, $this->load->database());
- // $this->assertEquals(NULL, $this->load->dbutil());
+ // $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);
-
+ $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
*/
@@ -139,8 +135,8 @@ class Loader_test extends CI_TestCase {
$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'));
}
@@ -149,87 +145,77 @@ class Loader_test extends CI_TestCase {
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);
-
+ $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);
-
+ $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(array('foo' => 'bar')));
$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);
}
- // --------------------------------------------------------------------
-
-}
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
index 1796ba74d..3f6e3b07a 100644
--- a/tests/codeigniter/core/Security_test.php
+++ b/tests/codeigniter/core/Security_test.php
@@ -1,7 +1,7 @@
<?php
class Security_test extends CI_TestCase {
-
+
public function set_up()
{
// Set cookie for security test
@@ -14,9 +14,9 @@ class Security_test extends CI_TestCase {
$this->security = new Mock_Core_Security();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_csrf_verify()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -25,7 +25,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_invalid()
{
// Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
@@ -37,7 +37,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_valid()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -47,21 +47,21 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_hash()
{
$this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_token_name()
{
$this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
}
// --------------------------------------------------------------------
-
+
public function test_xss_clean()
{
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
@@ -70,4 +70,37 @@ class Security_test extends CI_TestCase {
$this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_string);
}
+
+ // --------------------------------------------------------------------
+
+ public function test_xss_hash()
+ {
+ $this->assertEmpty($this->security->xss_hash);
+
+ // Perform hash
+ $this->security->xss_hash();
+
+ $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_entity_decode()
+ {
+ $encoded = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
+ $decoded = $this->security->entity_decode($encoded);
+
+ $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_sanitize_filename()
+ {
+ $filename = './<!--foo-->';
+ $safe_filename = $this->security->sanitize_filename($filename);
+
+ $this->assertEquals('foo', $safe_filename);
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index e340ddf73..60ed1a4e9 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -1,7 +1,7 @@
<?php
class URI_test extends CI_TestCase {
-
+
public function set_up()
{
$this->uri = new Mock_Core_URI();
@@ -9,23 +9,21 @@ class URI_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /* As of the following commit, _set_uri_string() is a protected method:
+
+ https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2
+
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->assertEquals('', $this->uri->uri_string);
+
$this->uri->_set_uri_string('nice/uri');
-
- $a = 'nice/uri';
-
- $this->assertEquals($a, $b);
+ $this->assertEquals('nice/uri', $this->uri->uri_string);
}
-
+ */
+
// --------------------------------------------------------------------
public function test_fetch_uri_string()
@@ -34,75 +32,61 @@ class URI_test extends CI_TestCase {
// 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);
-
+ $this->assertEquals('controller/method', $this->uri->uri_string);
+
// death to request uri
unset($_SERVER['REQUEST_URI']);
-
+
// life to path info
- $_SERVER['PATH_INFO'] = '/controller/method/';
-
+ $_SERVER['PATH_INFO'] = $a = '/controller/method/';
+
$this->uri->_fetch_uri_string();
-
- $a = '/controller/method/';
- $b =& $this->uri->uri_string;
+ $this->assertEquals($a, $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();
+ $this->assertEquals($a, $this->uri->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);
+ $this->assertEquals($a, $this->uri->uri_string);
// Test coverage implies that these will work
// uri_protocol: REQUEST_URI
// uri_protocol: CLI
-
}
-
+
// --------------------------------------------------------------------
public function test_explode_segments()
@@ -113,18 +97,15 @@ class URI_test extends CI_TestCase {
'/test2/uri2' => array('test2', 'uri2'),
'//test3/test3///' => array('test3', 'test3')
);
-
- foreach($uris as $uri => $a)
+
+ 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);
+
+ $this->assertEquals($a, $this->uri->segments);
}
-
}
// --------------------------------------------------------------------
@@ -133,7 +114,7 @@ class URI_test extends CI_TestCase {
{
$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);
@@ -145,52 +126,52 @@ class URI_test extends CI_TestCase {
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()
- {
+ 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()
@@ -205,32 +186,33 @@ class URI_test extends CI_TestCase {
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->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(3)
+ );
+
$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->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => FALSE),
+ $this->uri->uri_to_assoc(1)
+ );
+
$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);
+ $this->assertEquals(
+ array('a' => '1', 'b' => FALSE),
+ $this->uri->uri_to_assoc(1, array('a', 'b'))
+ );
}
// --------------------------------------------------------------------
@@ -238,33 +220,33 @@ class URI_test extends CI_TestCase {
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->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(3)
+ );
+
$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->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => FALSE),
+ $this->uri->ruri_to_assoc(1)
+ );
+
$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);
+ // test default
+ $this->assertEquals(
+ array('x' => '1', 'y' => FALSE),
+ $this->uri->ruri_to_assoc(1, array('x', 'y'))
+ );
}
// --------------------------------------------------------------------
@@ -272,11 +254,7 @@ class URI_test extends CI_TestCase {
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);
+ $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
}
// --------------------------------------------------------------------
@@ -286,28 +264,18 @@ class URI_test extends CI_TestCase {
$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);
-
+ $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
+ $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
+
$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);
- }
+ $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading'));
+ $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading'));
+ $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing'));
+ $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing'));
+ }
}
-// END URI_test Class
/* End of file URI_test.php */
-/* Location: ./tests/core/URI_test.php */
+/* Location: ./tests/core/URI_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
index fb40f0608..9e16e29b4 100644
--- a/tests/codeigniter/database/DB_driver_test.php
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -2,8 +2,6 @@
class DB_driver_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_initialize()
{
$config = Mock_Database_DB::config(DB_DRIVER);
@@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase {
{
return new Mock_Database_Drivers_Postgre($config);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
index 9b93e223d..d5c0dea08 100644
--- a/tests/codeigniter/database/DB_test.php
+++ b/tests/codeigniter/database/DB_test.php
@@ -2,8 +2,6 @@
class DB_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_db_invalid()
{
$connection = new Mock_Database_DB(array(
@@ -45,5 +43,5 @@ class DB_test extends CI_TestCase {
$this->assertTrue($db instanceof CI_DB);
$this->assertTrue($db instanceof CI_DB_Driver);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php
index 5e691692d..90ac5283e 100644
--- a/tests/codeigniter/database/query_builder/count_test.php
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -22,10 +22,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all()
{
- $job_count = $this->db->count_all('job');
-
- // Check the result
- $this->assertEquals(4, $job_count);
+ $this->assertEquals(4, $this->db->count_all('job'));
}
// ------------------------------------------------------------------------
@@ -35,10 +32,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all_results()
{
- $job_count = $this->db->like('name', 'ian')
- ->count_all_results('job');
-
- // Check the result
- $this->assertEquals(2, $job_count);
+ $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job'));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php
index 84ea7616f..ab9d97f56 100644
--- a/tests/codeigniter/database/query_builder/delete_test.php
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -23,9 +23,7 @@ class Delete_test extends CI_TestCase {
public function test_delete()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
@@ -33,8 +31,7 @@ class Delete_test extends CI_TestCase {
$this->db->delete('job', array('id' => 1));
// Check the record
- $job1 = $this->db->where('id', 1)
- ->get('job');
+ $job1 = $this->db->where('id', 1)->get('job');
$this->assertEmpty($job1->result_array());
}
@@ -47,13 +44,8 @@ class Delete_test extends CI_TestCase {
public function test_delete_several_tables()
{
// Check initial record
- $user4 = $this->db->where('id', 4)
- ->get('user')
- ->row();
-
- $job4 = $this->db->where('id', 4)
- ->get('job')
- ->row();
+ $user4 = $this->db->where('id', 4)->get('user')->row();
+ $job4 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job4->name);
$this->assertEquals('Chris Martin', $user4->name);
diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php
index 925eadb19..cc98009ce 100644
--- a/tests/codeigniter/database/query_builder/distinct_test.php
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -23,11 +23,10 @@ class Distinct_test extends CI_TestCase {
public function test_distinct()
{
$users = $this->db->select('country')
- ->distinct()
- ->get('user')
- ->result_array();
-
- // Check the result
+ ->distinct()
+ ->get('user')
+ ->result_array();
+
$this->assertEquals(3, count($users));
}
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
new file mode 100644
index 000000000..27e678f22
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -0,0 +1,68 @@
+<?php
+
+class Escape_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_percent_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\%foo');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($res));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_backslash_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\\');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($res));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php
index 95ae4dfdb..7aaae348d 100644
--- a/tests/codeigniter/database/query_builder/from_test.php
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -23,10 +23,9 @@ class From_test extends CI_TestCase {
public function test_from_simple()
{
$jobs = $this->db->from('job')
- ->get()
- ->result_array();
-
- // Check items
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -38,14 +37,13 @@ class From_test extends CI_TestCase {
public function test_from_with_where()
{
$job1 = $this->db->from('job')
- ->where('id', 1)
- ->get()
- ->row();
-
- // Check the result
+ ->where('id', 1)
+ ->get()
+ ->row();
+
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
$this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index 0751c9332..156027537 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -23,7 +23,7 @@ class Get_test extends CI_TestCase {
public function test_get_simple()
{
$jobs = $this->db->get('job')->result_array();
-
+
// Dummy jobs contain 4 rows
$this->assertCount(4, $jobs);
@@ -41,13 +41,13 @@ class Get_test extends CI_TestCase {
*/
public function test_get_where()
{
- $job1 = $this->db->get('job', array('id' => 1))->result_array();
-
+ $job1 = $this->db->get_where('job', array('id' => 1))->result_array();
+
// Dummy jobs contain 1 rows
$this->assertCount(1, $job1);
// Check rows item
$this->assertEquals('Developer', $job1[0]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index 7d8abc33f..5249f7c87 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -23,12 +23,11 @@ class Group_test extends CI_TestCase {
public function test_group_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -40,14 +39,13 @@ class Group_test extends CI_TestCase {
public function test_having_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->having('SUM(id) > 2')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
+ ->get()
+ ->result_array();
+
$this->assertEquals(2, count($jobs));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 8ba60e242..a9aafb66e 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -26,7 +26,7 @@ class Insert_test extends CI_TestCase {
public function test_insert()
{
$job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
-
+
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
@@ -45,10 +45,10 @@ class Insert_test extends CI_TestCase {
public function test_insert_batch()
{
$job_datas = array(
- array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
);
-
+
// Do insert batch except for sqlite driver
if (strpos(DB_DRIVER, 'sqlite') === FALSE)
{
@@ -62,5 +62,5 @@ class Insert_test extends CI_TestCase {
$this->assertEquals('Cab Driver', $job_3->name);
}
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php
index e05329d67..25bd4accb 100644
--- a/tests/codeigniter/database/query_builder/join_test.php
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -34,5 +34,25 @@ class Join_test extends CI_TestCase {
$this->assertEquals('Derek Jones', $job_user[0]['user_name']);
$this->assertEquals('Developer', $job_user[0]['job_name']);
}
-
+
+ // ------------------------------------------------------------------------
+
+ public function test_join_escape_multiple_conditions()
+ {
+ // We just need a valid query produced, not one that makes sense
+ $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2'));
+
+ $expected = 'SELECT '.implode(', ', $fields)
+ ."\nFROM ".$this->db->escape_identifiers('table1')
+ ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields)
+ .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0';
+
+ $result = $this->db->select('table1.field1, table2.field2')
+ ->from('table1')
+ ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT')
+ ->get_compiled_select();
+
+ $this->assertEquals($expected, $result);
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
index df98c713f..5f3e52228 100644
--- a/tests/codeigniter/database/query_builder/like_test.php
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -86,5 +86,5 @@ class Like_test extends CI_TestCase {
$this->assertEquals('Accountant', $jobs[1]['name']);
$this->assertEquals('Musician', $jobs[2]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php
index 704f3b651..a0954c7ab 100644
--- a/tests/codeigniter/database/query_builder/limit_test.php
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -25,8 +25,7 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
}
@@ -40,10 +39,10 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2, 2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php
index 01aa1c2b4..46f452bae 100644
--- a/tests/codeigniter/database/query_builder/order_test.php
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -25,7 +25,7 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'asc')
->get('job')
->result_array();
-
+
// Check the result
$this->assertEquals(4, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
@@ -44,12 +44,12 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'desc')
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(4, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
$this->assertEquals('Developer', $jobs[2]['name']);
$this->assertEquals('Accountant', $jobs[3]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index 0d299ed16..877b5d8c0 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -25,7 +25,7 @@ class Select_test extends CI_TestCase {
$jobs_name = $this->db->select('name')
->get('job')
->result_array();
-
+
// Check rows item
$this->assertArrayHasKey('name',$jobs_name[0]);
$this->assertFalse(array_key_exists('id', $jobs_name[0]));
@@ -42,7 +42,7 @@ class Select_test extends CI_TestCase {
$job_min = $this->db->select_min('id')
->get('job')
->row();
-
+
// Minimum id was 1
$this->assertEquals('1', $job_min->id);
}
@@ -57,7 +57,7 @@ class Select_test extends CI_TestCase {
$job_max = $this->db->select_max('id')
->get('job')
->row();
-
+
// Maximum id was 4
$this->assertEquals('4', $job_max->id);
}
@@ -72,7 +72,7 @@ class Select_test extends CI_TestCase {
$job_avg = $this->db->select_avg('id')
->get('job')
->row();
-
+
// Average should be 2.5
$this->assertEquals('2.5', $job_avg->id);
}
@@ -87,9 +87,9 @@ class Select_test extends CI_TestCase {
$job_sum = $this->db->select_sum('id')
->get('job')
->row();
-
+
// Sum of ids should be 10
$this->assertEquals('10', $job_sum->id);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php
index 2a9c8a91e..09923c7f1 100644
--- a/tests/codeigniter/database/query_builder/truncate_test.php
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -24,7 +24,6 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$jobs = $this->db->get('job')->result_array();
-
$this->assertEquals(4, count($jobs));
// Do the empty
@@ -32,7 +31,6 @@ class Truncate_test extends CI_TestCase {
// Check the record
$jobs = $this->db->get('job');
-
$this->assertEmpty($jobs->result_array());
}
@@ -45,16 +43,13 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$users = $this->db->get('user')->result_array();
-
$this->assertEquals(4, count($users));
// Do the empty
- $this->db->from('user')
- ->truncate();
+ $this->db->from('user')->truncate();
// Check the record
$users = $this->db->get('user');
-
$this->assertEmpty($users->result_array());
}
diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php
index f5bbffd4f..27a647c45 100644
--- a/tests/codeigniter/database/query_builder/update_test.php
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -23,23 +23,14 @@ class Update_test extends CI_TestCase {
public function test_update()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
// Do the update
- $job_data = array('name' => 'Programmer');
-
- $this->db->where('id', 1)
- ->update('job', $job_data);
+ $this->db->where('id', 1)->update('job', array('name' => 'Programmer'));
// Check updated record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Programmer', $job1->name);
}
@@ -51,10 +42,7 @@ class Update_test extends CI_TestCase {
public function test_update_with_set()
{
// Check initial record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job1->name);
// Do the update
@@ -62,10 +50,8 @@ class Update_test extends CI_TestCase {
$this->db->update('job', NULL, 'id = 4');
// Check updated record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Vocalist', $job1->name);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php
index 607eaa076..20b7a567c 100644
--- a/tests/codeigniter/database/query_builder/where_test.php
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -22,11 +22,8 @@ class Where_test extends CI_TestCase {
*/
public function test_where_simple_key_value()
{
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
- // Check the result
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
}
@@ -38,11 +35,7 @@ class Where_test extends CI_TestCase {
*/
public function test_where_custom_key_value()
{
- $jobs = $this->db->where('id !=', 1)
- ->get('job')
- ->result_array();
-
- // Check the result
+ $jobs = $this->db->where('id !=', 1)->get('job')->result_array();
$this->assertEquals(3, count($jobs));
}
@@ -54,16 +47,12 @@ class Where_test extends CI_TestCase {
public function test_where_associative_array()
{
$where = array('id >' => 2, 'name !=' => 'Accountant');
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -75,16 +64,12 @@ class Where_test extends CI_TestCase {
public function test_where_custom_string()
{
$where = "id > 2 AND name != 'Accountant'";
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -100,7 +85,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(3, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Politician', $jobs[1]['name']);
@@ -118,7 +102,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Accountant', $jobs[1]['name']);
@@ -135,10 +118,9 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
index 9cd15960f..ba46e86f9 100644
--- a/tests/codeigniter/helpers/array_helper_test.php
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -1,7 +1,7 @@
<?php
class Array_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('array');
@@ -13,31 +13,31 @@ class Array_helper_test extends CI_TestCase {
'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)));
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index 17d1ef21e..1b79b9480 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -5,153 +5,163 @@ class Date_helper_test extends CI_TestCase {
public function set_up()
{
$this->helper('date');
+
+ $this->time = time();
}
// ------------------------------------------------------------------------
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);
+ */
+
+ $this->ci_set_config('time_reference', 'local');
+
+ $this->assertEquals(time(), now());
}
// ------------------------------------------------------------------------
- public function test_now_gmt()
+ public function test_now_utc()
{
+ /*
+
// 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'));
-
+ ->will($this->returnValue('UTC'));
+
// 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);
+ */
+
+ $this->assertEquals(
+ mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')),
+ now('UTC')
+ );
}
// ------------------------------------------------------------------------
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);
+ $this->assertEquals(
+ date('Y-m-d - h:i a', $this->time),
+ mdate('%Y-%m-%d - %h:%i %a', $this->time)
+ );
}
// ------------------------------------------------------------------------
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));
+ $this->assertEquals(
+ date(DATE_RFC822, $this->time),
+ standard_date('DATE_RFC822', $this->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));
+ $this->assertEquals(
+ date(DATE_ATOM, $this->time),
+ standard_date('DATE_ATOM', $this->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));
+ $this->assertEquals(
+ date(DATE_COOKIE, $this->time),
+ standard_date('DATE_COOKIE', $this->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));
+ $this->assertEquals(
+ date(DATE_ISO8601, $this->time),
+ standard_date('DATE_ISO8601', $this->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));
+ $this->assertEquals(
+ date(DATE_RFC850, $this->time),
+ standard_date('DATE_RFC850', $this->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));
+ $this->assertEquals(
+ date(DATE_RFC1036, $this->time),
+ standard_date('DATE_RFC1036', $this->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));
+ $this->assertEquals(
+ date(DATE_RFC1123, $this->time),
+ standard_date('DATE_RFC1123', $this->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));
+ $this->assertEquals(
+ date(DATE_RFC2822, $this->time),
+ standard_date('DATE_RFC2822', $this->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));
+ $this->assertEquals(
+ date(DATE_RSS, $this->time),
+ standard_date('DATE_RSS', $this->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));
+ $this->assertEquals(
+ date(DATE_W3C, $this->time),
+ standard_date('DATE_W3C', $this->time)
+ );
}
// ------------------------------------------------------------------------
@@ -183,39 +193,36 @@ class Date_helper_test extends CI_TestCase {
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));
+ $this->assertEquals(
+ mktime(
+ gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time),
+ gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time)
+ ),
+ local_to_gmt($this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_gmt_to_local()
{
- $timestamp = '1140153693';
- $timezone = 'UM8';
- $daylight_saving = TRUE;
-
- $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+ $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE));
}
// ------------------------------------------------------------------------
public function test_mysql_to_unix()
{
- $time = time();
- $this->assertEquals($time,
- mysql_to_unix(date("Y-m-d H:i:s", $time)));
+ $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->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'));
+ $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time));
+ $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us'));
+ $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu'));
}
// ------------------------------------------------------------------------
@@ -223,8 +230,7 @@ class Date_helper_test extends CI_TestCase {
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->assertEquals(strtotime($date), human_to_unix($date));
$this->assertFalse(human_to_unix());
}
@@ -283,6 +289,7 @@ class Date_helper_test extends CI_TestCase {
$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
index 3937d2913..c39ccd8d0 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -1,41 +1,52 @@
<?php
class Directory_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('directory');
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' => ''));
-
+ $structure = array(
+ 'libraries' => array(
+ 'benchmark.html' => '',
+ 'database' => array('active_record.html' => '', 'binds.html' => ''),
+ 'email.html' => '',
+ '0' => '',
+ '.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')));
+ $expected = array(
+ 'libraries' => array(
+ 'benchmark.html',
+ 'database' => array('active_record.html', 'binds.html'),
+ 'email.html',
+ '0'
+ )
+ );
- // test recursion depth behavior
- $expected = array('libraries');
-
- $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1));
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
// test detection of hidden files
- $expected = array('libraries' => array('benchmark.html', 'database' =>
- array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt'));
-
+ $expected['libraries'][] = '.hiddenfile.txt';
+
$this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
- }
+
+ // test recursion depth behavior
+ $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1));
+ }
+
}
/* 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
index a01f3d5af..fea452f5f 100644
--- a/tests/codeigniter/helpers/email_helper_test.php
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -14,5 +14,5 @@ class Email_helper_test extends CI_TestCase {
$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
index 4b9c29485..9b03da9d7 100644
--- a/tests/codeigniter/helpers/file_helper_test.php
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase {
public function set_up()
{
$this->helper('file');
-
+
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);
-
+
+ $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir);
+
$this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
}
@@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase {
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()));
+ ->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()));
+ ->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
+ ->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')));
-
+
+ $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'
+ '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);
+ $this->_test_get_file_info(implode(', ', $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);
-
+ ->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,
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
'readable' => TRUE,
- 'writable' => TRUE,
- 'executable' => 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));
- //
+ // 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/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
index 80bace9d1..1a30ed993 100644
--- a/tests/codeigniter/helpers/form_helper_test.php
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -3,26 +3,26 @@
require BASEPATH . 'core/Common.php';
require BASEPATH . 'helpers/form_helper.php';
-class Form_helper_test extends CI_TestCase
+class Form_helper_test extends CI_TestCase
{
public function test_form_hidden()
- {
+ {
$expected = <<<EOH
<input type="hidden" name="username" value="johndoe" />
EOH;
-
+
$this->assertEquals($expected, form_hidden('username', 'johndoe'));
}
-
+
public function test_form_input()
{
$expected = <<<EOH
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
EOH;
-
+
$data = array(
'name' => 'username',
'id' => 'username',
@@ -34,37 +34,37 @@ EOH;
$this->assertEquals($expected, form_input($data));
}
-
+
public function test_form_password()
- {
+ {
$expected = <<<EOH
<input type="password" name="password" value="" />
EOH;
-
+
$this->assertEquals($expected, form_password('password'));
}
-
+
public function test_form_upload()
- {
+ {
$expected = <<<EOH
<input type="file" name="attachment" value="" />
EOH;
-
+
$this->assertEquals($expected, form_upload('attachment'));
}
-
+
public function test_form_textarea()
- {
+ {
$expected = <<<EOH
<textarea name="notes" cols="40" rows="10" >Notes</textarea>
EOH;
-
+
$this->assertEquals($expected, form_textarea('notes', 'Notes'));
}
-
+
public function test_form_dropdown()
{
$expected = <<<EOH
@@ -76,16 +76,16 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
);
-
+
$this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
-
+
$expected = <<<EOH
<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
@@ -95,22 +95,22 @@ EOH;
</select>
EOH;
-
+
$shirts_on_sale = array('small', 'large');
-
+
$this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale));
-
+
$options = array(
'Swedish Cars' => array(
- 'volvo' => 'Volvo',
- 'saab' => 'Saab'
+ 'volvo' => 'Volvo',
+ 'saab' => 'Saab'
),
'German Cars' => array(
- 'mercedes' => 'Mercedes',
- 'audi' => 'Audi'
+ 'mercedes' => 'Mercedes',
+ 'audi' => 'Audi'
)
);
-
+
$expected = <<<EOH
<select name="cars" multiple="multiple">
<optgroup label="Swedish Cars">
@@ -124,13 +124,10 @@ EOH;
</select>
EOH;
-
- $cars_on_sale = array('volvo', 'audi');
-
- $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale));
-
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
}
-
+
public function test_form_multiselect()
{
$expected = <<<EOH
@@ -142,17 +139,17 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
- );
-
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
+ );
+
$this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large')));
}
-
+
public function test_form_fieldset()
{
$expected = <<<EOH
@@ -160,7 +157,7 @@ EOH;
<legend>Address Information</legend>
EOH;
-
+
$this->assertEquals($expected, form_fieldset('Address Information'));
}
@@ -169,10 +166,10 @@ EOH;
$expected = <<<EOH
</fieldset></div></div>
EOH;
-
+
$this->assertEquals($expected, form_fieldset_close('</div></div>'));
}
-
+
public function test_form_checkbox()
{
$expected = <<<EOH
@@ -182,7 +179,7 @@ EOH;
$this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
}
-
+
public function test_form_radio()
{
$expected = <<<EOH
@@ -192,7 +189,7 @@ EOH;
$this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
}
-
+
public function test_form_submit()
{
$expected = <<<EOH
@@ -202,7 +199,7 @@ EOH;
$this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
}
-
+
public function test_form_label()
{
$expected = <<<EOH
@@ -211,7 +208,7 @@ EOH;
$this->assertEquals($expected, form_label('What is your Name', 'username'));
}
-
+
public function test_form_reset()
{
$expected = <<<EOH
@@ -221,7 +218,7 @@ EOH;
$this->assertEquals($expected, form_reset('myreset', 'Reset'));
}
-
+
public function test_form_button()
{
$expected = <<<EOH
@@ -229,9 +226,9 @@ EOH;
EOH;
- $this->assertEquals($expected, form_button('name','content'));
+ $this->assertEquals($expected, form_button('name', 'content'));
}
-
+
public function test_form_close()
{
$expected = <<<EOH
@@ -240,13 +237,14 @@ EOH;
$this->assertEquals($expected, form_close('</div></div>'));
}
-
+
public function test_form_prep()
{
- $expected = "Here is a string containing &quot;quoted&quot; text.";
-
+ $expected = 'Here is a string containing &quot;quoted&quot; text.';
+
$this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.'));
}
+
}
/* End of file form_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php
index 28974b0f8..4dd717ff7 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -6,24 +6,40 @@ class Html_helper_test extends CI_TestCase {
{
$this->helper('html');
}
-
+
// ------------------------------------------------------------------------
-
+
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_heading_array_attributes()
+ {
+ // Test array of attributes
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
+ }
+
+ public function test_heading_object_attributes()
+ {
+ // Test array of attributes
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
+ $test = new stdClass;
+ $test->class = "bar";
+ $test->id = "foo";
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, $test));
+ }
+
// ------------------------------------------------------------------------
-
+
public function test_Ul()
{
$expect = <<<EOH
@@ -35,11 +51,9 @@ class Html_helper_test extends CI_TestCase {
EOH;
$expect = ltrim($expect);
-
$list = array('foo', 'bar');
-
- $this->assertEquals($expect, ul($list));
+ $this->assertEquals(ltrim($expect), ul($list));
$expect = <<<EOH
<ul class="test">
@@ -51,13 +65,11 @@ 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()
@@ -66,15 +78,14 @@ EOH;
}
// ------------------------------------------------------------------------
-
+
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
index 9e9478711..f3b0ebbe8 100644
--- a/tests/codeigniter/helpers/inflector_helper_test.php
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -1,12 +1,12 @@
<?php
class Inflector_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('inflector');
}
-
+
public function test_singular()
{
$strs = array(
@@ -16,15 +16,15 @@ class Inflector_helper_test extends CI_TestCase {
'smells' => 'smell',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, singular($str));
}
}
-
+
// --------------------------------------------------------------------
-
+
public function test_plural()
{
$strs = array(
@@ -35,15 +35,15 @@ class Inflector_helper_test extends CI_TestCase {
'witch' => 'witches',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, plural($str));
- }
- }
+ }
+ }
// --------------------------------------------------------------------
-
+
public function test_camelize()
{
$strs = array(
@@ -52,15 +52,15 @@ class Inflector_helper_test extends CI_TestCase {
'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(
@@ -69,7 +69,7 @@ class Inflector_helper_test extends CI_TestCase {
'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));
@@ -77,7 +77,7 @@ class Inflector_helper_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_humanize()
{
$strs = array(
@@ -86,10 +86,11 @@ class Inflector_helper_test extends CI_TestCase {
'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
index 4bb9a918a..ef6aae138 100644
--- a/tests/codeigniter/helpers/number_helper_test.php
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -1,35 +1,35 @@
<?php
class Number_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('number');
-
+
// 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 = 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)
@@ -37,41 +37,40 @@ class Number_helper_test extends CI_TestCase {
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
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
index 632f57501..0faf6f383 100644
--- a/tests/codeigniter/helpers/path_helper_test.php
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -8,9 +8,8 @@ class Path_helper_test extends CI_TestCase {
}
public function test_set_realpath()
- {
- $expected = getcwd() . DIRECTORY_SEPARATOR;
- $this->assertEquals($expected, set_realpath(getcwd()));
+ {
+ $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd()));
}
public function test_set_realpath_nonexistent_directory()
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
index 29c3d6594..75701ec13 100644
--- a/tests/codeigniter/helpers/string_helper_test.php
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -10,18 +10,18 @@ class String_helper_test extends CI_TestCase {
public function test_strip_slashes()
{
$expected = array(
- "Is your name O'reilly?",
+ "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(
@@ -144,4 +144,5 @@ class String_helper_test extends CI_TestCase {
$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
index 584066b0c..f131469cb 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -3,16 +3,16 @@
class Text_helper_test extends CI_TestCase {
private $_long_string;
-
+
public function set_up()
{
$this->helper('text');
-
+
$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));
@@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('', word_limiter('', 4));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_character_limiter()
{
$this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
@@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase {
$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()
{
@@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase {
'&#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()
+
+ // ------------------------------------------------------------------------
+
+ public 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',
@@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase {
'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));
+ $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_phrase()
{
@@ -113,16 +111,16 @@ class Text_helper_test extends CI_TestCase {
'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()
+ public function test_ellipsize()
{
$strs = array(
'0' => array(
@@ -144,16 +142,30 @@ class Text_helper_test extends CI_TestCase {
'short' => 'short'
),
);
-
+
foreach ($strs as $pos => $s)
{
foreach ($s as $str => $expect)
{
- $this->assertEquals($expect, ellipsize($str, 10, $pos));
+ $this->assertEquals($expect, ellipsize($str, 10, $pos));
}
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ public function test_word_wrap()
+ {
+ $string = 'Here is a simple string of text that will help us demonstrate this function.';
+ $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_default_word_wrap_charlim()
+ {
+ $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function.";
+ $this->assertEquals(strpos(word_wrap($string), "\n"), 73);
+ }
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
index c561809ce..c81c5f1b8 100644
--- a/tests/codeigniter/helpers/url_helper_test.php
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -72,4 +72,5 @@ class Url_helper_test extends CI_TestCase {
$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
index a83fef91e..e8cf411da 100644
--- a/tests/codeigniter/helpers/xml_helper_test.php
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -6,10 +6,10 @@ class Xml_helper_test extends CI_TestCase {
{
$this->helper('xml');
}
-
+
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/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
new file mode 100644
index 000000000..95668d70d
--- /dev/null
+++ b/tests/codeigniter/libraries/Calendar_test.php
@@ -0,0 +1,204 @@
+<?php
+
+class Calendar_test extends CI_TestCase {
+
+ function __construct()
+ {
+ $obj = new stdClass;
+ $obj->calendar = new Mock_Libraries_Calendar();
+
+ $this->calendar = $obj->calendar;
+ }
+
+ function test_initialize()
+ {
+ $this->calendar->initialize(array(
+ 'month_type' => 'short',
+ 'start_day' => 'monday'
+ ));
+ $this->assertEquals('short', $this->calendar->month_type);
+ $this->assertEquals('monday', $this->calendar->start_day);
+ }
+
+ /**
+ * @covers Mock_Libraries_Calendar::parse_template
+ */
+ function test_generate()
+ {
+ $no_events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td>3</td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($no_events, $this->calendar->generate(2011, 9));
+
+ $data = array(
+ 3 => 'http://example.com/news/article/2006/03/',
+ 7 => 'http://example.com/news/article/2006/07/',
+ 13 => 'http://example.com/news/article/2006/13/',
+ 26 => 'http://example.com/news/article/2006/26/'
+ );
+
+ $events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td><a href="http://example.com/news/article/2006/03/">3</a></td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td><a href="http://example.com/news/article/2006/07/">7</a></td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td><a href="http://example.com/news/article/2006/13/">13</a></td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td><a href="http://example.com/news/article/2006/26/">26</a></td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($events, $this->calendar->generate(2011, 9, $data));
+ }
+
+ function test_get_month_name()
+ {
+ $this->calendar->month_type = NULL;
+ $this->assertEquals('January', $this->calendar->get_month_name('01'));
+
+ $this->calendar->month_type = 'short';
+ $this->assertEquals('Jan', $this->calendar->get_month_name('01'));
+ }
+
+ function test_get_day_names()
+ {
+ $this->assertEquals(array(
+ 'Sunday',
+ 'Monday',
+ 'Tuesday',
+ 'Wednesday',
+ 'Thursday',
+ 'Friday',
+ 'Saturday'
+ ), $this->calendar->get_day_names('long'));
+
+ $this->assertEquals(array(
+ 'Sun',
+ 'Mon',
+ 'Tue',
+ 'Wed',
+ 'Thu',
+ 'Fri',
+ 'Sat'
+ ), $this->calendar->get_day_names('short'));
+
+ $this->calendar->day_type = NULL;
+
+ $this->assertEquals(array(
+ 'Su',
+ 'Mo',
+ 'Tu',
+ 'We',
+ 'Th',
+ 'Fr',
+ 'Sa'
+ ), $this->calendar->get_day_names());
+ }
+
+ function test_adjust_date()
+ {
+ $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012));
+ $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012));
+ }
+
+ function test_get_total_days()
+ {
+ $this->assertEquals(0, $this->calendar->get_total_days(13, 2012));
+
+ $this->assertEquals(31, $this->calendar->get_total_days(1, 2012));
+ $this->assertEquals(28, $this->calendar->get_total_days(2, 2011));
+ $this->assertEquals(29, $this->calendar->get_total_days(2, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(3, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(4, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(5, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(6, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(7, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(8, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(9, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(10, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(11, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
+ }
+
+ function test_default_template()
+ {
+ $array = array(
+ 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
+ 'heading_row_start' => '<tr>',
+ 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
+ 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
+ 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
+ 'heading_row_end' => '</tr>',
+ 'week_row_start' => '<tr>',
+ 'week_day_cell' => '<td>{week_day}</td>',
+ 'week_row_end' => '</tr>',
+ 'cal_row_start' => '<tr>',
+ 'cal_cell_start' => '<td>',
+ 'cal_cell_start_today' => '<td>',
+ 'cal_cell_content' => '<a href="{content}">{day}</a>',
+ 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
+ 'cal_cell_no_content' => '{day}',
+ 'cal_cell_no_content_today' => '<strong>{day}</strong>',
+ 'cal_cell_blank' => '&nbsp;',
+ 'cal_cell_end' => '</td>',
+ 'cal_cell_end_today' => '</td>',
+ 'cal_row_end' => '</tr>',
+ 'table_close' => '</table>'
+ );
+
+ $this->assertEquals($array, $this->calendar->default_template());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
new file mode 100644
index 000000000..153a25e1d
--- /dev/null
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -0,0 +1,72 @@
+<?php
+
+class Encrypt_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $obj = new stdClass;
+ $obj->encrypt = new Mock_Libraries_Encrypt();
+
+ $this->ci_instance($obj);
+ $this->encrypt = $obj->encrypt;
+
+ $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
+ $this->msg = 'My secret message';
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_encode()
+ {
+ $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_decode()
+ {
+ $encoded_msg = $this->encrypt->encode($this->msg);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_optional_key()
+ {
+ $key = 'Ohai!ù0129°03182%HD1892P0';
+ $encoded_msg = $this->encrypt->encode($this->msg, $key);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_cipher()
+ {
+ $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+
+ public function test_set_cipher()
+ {
+ $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
+ $this->assertEquals('blowfish', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_mode()
+ {
+ $this->assertEquals('cbc', $this->encrypt->get_mode());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_mode()
+ {
+ $this->encrypt->set_mode(MCRYPT_MODE_CFB);
+ $this->assertEquals('cfb', $this->encrypt->get_mode());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index c3d88fa85..b68f44a33 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -1,73 +1,74 @@
<?php
class Parser_test extends CI_TestCase {
-
+
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->parser = new Mock_Libraries_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(
@@ -78,16 +79,14 @@ class Parser_test extends CI_TestCase {
'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));
+
+ $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _mismatched_var_pair()
{
$data = array(
@@ -98,13 +97,11 @@ class Parser_test extends CI_TestCase {
'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));
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
- // --------------------------------------------------------------------
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
new file mode 100644
index 000000000..135f71806
--- /dev/null
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -0,0 +1,405 @@
+<?php
+
+/**
+ * Session driver library unit test
+ */
+class Session_test extends CI_TestCase {
+ protected $settings = array(
+ 'use_cookies' => 0,
+ 'use_only_cookies' => 0,
+ 'cache_limiter' => false
+ );
+ protected $setting_vals = array();
+ protected $cookie_vals;
+ protected $session;
+
+ /**
+ * Set up test framework
+ */
+ public function set_up()
+ {
+ // Override settings
+ foreach ($this->settings as $name => $value) {
+ $this->setting_vals[$name] = ini_get('session.'.$name);
+ ini_set('session.'.$name, $value);
+ }
+
+ // Start with clean environment
+ $this->cookie_vals = $_COOKIE;
+ $_COOKIE = array();
+
+ // Establish necessary support classes
+ $obj = new stdClass;
+ $classes = array(
+ 'config' => 'cfg',
+ 'load' => 'load',
+ 'input' => 'in'
+ );
+ foreach ($classes as $name => $abbr) {
+ $class = $this->ci_core_class($abbr);
+ $obj->$name = new $class;
+ }
+ $this->ci_instance($obj);
+
+ // Attach session instance locally
+ $config = array(
+ 'sess_encrypt_cookie' => FALSE,
+ 'sess_use_database' => FALSE,
+ 'sess_table_name' => '',
+ 'sess_expiration' => 7200,
+ 'sess_expire_on_close' => FALSE,
+ 'sess_match_ip' => FALSE,
+ 'sess_match_useragent' => TRUE,
+ 'sess_cookie_name' => 'ci_session',
+ 'cookie_path' => '',
+ 'cookie_domain' => '',
+ 'cookie_secure' => FALSE,
+ 'cookie_httponly' => FALSE,
+ 'sess_time_to_update' => 300,
+ 'time_reference' => 'local',
+ 'cookie_prefix' => '',
+ 'encryption_key' => 'foobar',
+ 'sess_valid_drivers' => array(
+ 'Mock_Libraries_Session_native',
+ 'Mock_Libraries_Session_cookie'
+ )
+ );
+ $this->session = new Mock_Libraries_Session($config);
+ }
+
+ /**
+ * Tear down test framework
+ */
+ public function tear_down()
+ {
+ // Restore environment
+ if (session_id()) session_destroy();
+ $_SESSION = array();
+ $_COOKIE = $this->cookie_vals;
+
+ // Restore settings
+ foreach ($this->settings as $name => $value) {
+ ini_set('session.'.$name, $this->setting_vals[$name]);
+ }
+ }
+
+ /**
+ * Test set_userdata() function
+ *
+ * @covers CI_Session::set_userdata
+ * @covers CI_Session::userdata
+ */
+ public function test_set_userdata()
+ {
+ // Set userdata values for each driver
+ $key1 = 'test1';
+ $ckey2 = 'test2';
+ $nkey2 = 'test3';
+ $cmsg1 = 'Some test data';
+ $cmsg2 = 42;
+ $nmsg1 = 'Other test data';
+ $nmsg2 = true;
+ $this->session->cookie->set_userdata($key1, $cmsg1);
+ $this->session->set_userdata($ckey2, $cmsg2);
+ $this->session->native->set_userdata($key1, $nmsg1);
+ $this->session->set_userdata($nkey2, $nmsg2);
+
+ // Verify independent messages
+ $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1));
+ $this->assertEquals($nmsg1, $this->session->native->userdata($key1));
+
+ // Verify pre-selected driver sets
+ $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2));
+ $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2));
+
+ // Verify no crossover
+ $this->assertNull($this->session->cookie->userdata($nkey2));
+ $this->assertNull($this->session->native->userdata($ckey2));
+ }
+
+ /**
+ * Test the has_userdata() function
+ *
+ * @covers CI_Session::has_userdata
+ */
+ public function test_has_userdata()
+ {
+ // Set a userdata value for each driver
+ $key = 'hastest';
+ $cmsg = 'My test data';
+ $this->session->cookie->set_userdata($key, $cmsg);
+ $nmsg = 'Your test data';
+ $this->session->native->set_userdata($key, $nmsg);
+
+ // Verify values exist
+ $this->assertTrue($this->session->cookie->has_userdata($key));
+ $this->assertTrue($this->session->native->has_userdata($key));
+
+ // Verify non-existent values
+ $nokey = 'hasnot';
+ $this->assertFalse($this->session->cookie->has_userdata($nokey));
+ $this->assertFalse($this->session->native->has_userdata($nokey));
+ }
+
+ /**
+ * Test the all_userdata() function
+ *
+ * @covers CI_Session::all_userdata
+ */
+ public function test_all_userdata()
+ {
+ // Set a specific series of data for each driver
+ $cdata = array(
+ 'one' => 'first',
+ 'two' => 'second',
+ 'three' => 'third',
+ 'foo' => 'bar',
+ 'bar' => 'baz'
+ );
+ $ndata = array(
+ 'one' => 'gold',
+ 'two' => 'silver',
+ 'three' => 'bronze',
+ 'foo' => 'baz',
+ 'bar' => 'foo'
+ );
+ $this->session->cookie->set_userdata($cdata);
+ $this->session->native->set_userdata($ndata);
+
+ // Make sure all values are present
+ $call = $this->session->cookie->all_userdata();
+ foreach ($cdata as $key => $value) {
+ $this->assertEquals($value, $call[$key]);
+ }
+ $nall = $this->session->native->all_userdata();
+ foreach ($ndata as $key => $value) {
+ $this->assertEquals($value, $nall[$key]);
+ }
+ }
+
+ /**
+ * Test the unset_userdata() function
+ *
+ * @covers CI_Session::unset_userdata
+ */
+ public function test_unset_userdata()
+ {
+ // Set a userdata message for each driver
+ $key = 'untest';
+ $cmsg = 'Other test data';
+ $this->session->cookie->set_userdata($key, $cmsg);
+ $nmsg = 'Sundry test data';
+ $this->session->native->set_userdata($key, $nmsg);
+
+ // Verify independent messages
+ $this->assertEquals($this->session->cookie->userdata($key), $cmsg);
+ $this->assertEquals($this->session->native->userdata($key), $nmsg);
+
+ // Unset them and verify absence
+ $this->session->cookie->unset_userdata($key);
+ $this->session->native->unset_userdata($key);
+ $this->assertNull($this->session->cookie->userdata($key));
+ $this->assertNull($this->session->native->userdata($key));
+ }
+
+ /**
+ * Test the flashdata() functions
+ *
+ * @covers CI_Session::set_flashdata
+ * @covers CI_Session::flashdata
+ */
+ public function test_flashdata()
+ {
+ // Set flashdata message for each driver
+ $key = 'fltest';
+ $cmsg = 'Some flash data';
+ $this->session->cookie->set_flashdata($key, $cmsg);
+ $nmsg = 'Other flash data';
+ $this->session->native->set_flashdata($key, $nmsg);
+
+ // Simulate page reload
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+
+ // Verify independent messages
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Simulate next page reload
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+
+ // Verify absence of messages
+ $this->assertNull($this->session->cookie->flashdata($key));
+ $this->assertNull($this->session->native->flashdata($key));
+ }
+
+ /**
+ * Test the keep_flashdata() function
+ *
+ * @covers CI_Session::keep_flashdata
+ */
+ public function test_keep_flashdata()
+ {
+ // Set flashdata message for each driver
+ $key = 'kfltest';
+ $cmsg = 'My flash data';
+ $this->session->cookie->set_flashdata($key, $cmsg);
+ $nmsg = 'Your flash data';
+ $this->session->native->set_flashdata($key, $nmsg);
+
+ // Simulate page reload and verify independent messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Keep messages
+ $this->session->cookie->keep_flashdata($key);
+ $this->session->native->keep_flashdata($key);
+
+ // Simulate next page reload and verify message persistence
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Simulate next page reload and verify absence of messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertNull($this->session->cookie->flashdata($key));
+ $this->assertNull($this->session->native->flashdata($key));
+ }
+
+ /**
+ * Test the all_flashdata() function
+ *
+ * @covers CI_Session::all_flashdata
+ */
+ public function test_all_flashdata()
+ {
+ // Set a specific series of data for each driver
+ $cdata = array(
+ 'one' => 'first',
+ 'two' => 'second',
+ 'three' => 'third',
+ 'foo' => 'bar',
+ 'bar' => 'baz'
+ );
+ $ndata = array(
+ 'one' => 'gold',
+ 'two' => 'silver',
+ 'three' => 'bronze',
+ 'foo' => 'baz',
+ 'bar' => 'foo'
+ );
+ $this->session->cookie->set_flashdata($cdata);
+ $this->session->native->set_flashdata($ndata);
+
+ // Simulate page reload and make sure all values are present
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cdata, $this->session->cookie->all_flashdata());
+ $this->assertEquals($ndata, $this->session->native->all_flashdata());
+ }
+
+ /**
+ * Test the tempdata() functions
+ *
+ * @covers CI_Session::set_tempdata
+ * @covers CI_Session::tempdata
+ */
+ public function test_set_tempdata()
+ {
+ // Set tempdata message for each driver - 1 second timeout
+ $key = 'tmptest';
+ $cmsg = 'Some temp data';
+ $this->session->cookie->set_tempdata($key, $cmsg, 1);
+ $nmsg = 'Other temp data';
+ $this->session->native->set_tempdata($key, $nmsg, 1);
+
+ // Simulate page reload and verify independent messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->tempdata($key));
+ $this->assertEquals($nmsg, $this->session->native->tempdata($key));
+
+ // Wait 2 seconds, simulate page reload and verify message absence
+ sleep(2);
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertNull($this->session->cookie->tempdata($key));
+ $this->assertNull($this->session->native->tempdata($key));
+ }
+
+ /**
+ * Test the unset_tempdata() function
+ *
+ * @covers CI_Session::unset_tempdata
+ */
+ public function test_unset_tempdata()
+ {
+ // Set tempdata message for each driver - 1 second timeout
+ $key = 'utmptest';
+ $cmsg = 'My temp data';
+ $this->session->cookie->set_tempdata($key, $cmsg, 1);
+ $nmsg = 'Your temp data';
+ $this->session->native->set_tempdata($key, $nmsg, 1);
+
+ // Verify independent messages
+ $this->assertEquals($cmsg, $this->session->cookie->tempdata($key));
+ $this->assertEquals($nmsg, $this->session->native->tempdata($key));
+
+ // Unset data and verify message absence
+ $this->session->cookie->unset_tempdata($key);
+ $this->session->native->unset_tempdata($key);
+ $this->assertNull($this->session->cookie->tempdata($key));
+ $this->assertNull($this->session->native->tempdata($key));
+ }
+
+ /**
+ * Test the sess_regenerate() function
+ *
+ * @covers CI_Session::sess_regenerate
+ */
+ public function test_sess_regenerate()
+ {
+ // Get current session id, regenerate, and compare
+ // Cookie driver
+ $oldid = $this->session->cookie->userdata('session_id');
+ $this->session->cookie->sess_regenerate();
+ $newid = $this->session->cookie->userdata('session_id');
+ $this->assertNotEquals($oldid, $newid);
+
+ // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this
+ // $oldid = session_id();
+ // $this->session->native->sess_regenerate();
+ // $oldid = session_id();
+ // $this->assertNotEquals($oldid, $newid);
+ }
+
+ /**
+ * Test the sess_destroy() function
+ *
+ * @covers CI_Session::sess_destroy
+ */
+ public function test_sess_destroy()
+ {
+ // Set a userdata message, destroy session, and verify absence
+ $key = 'dsttest';
+ $msg = 'More test data';
+
+ // Cookie driver
+ $this->session->cookie->set_userdata($key, $msg);
+ $this->assertEquals($msg, $this->session->cookie->userdata($key));
+ $this->session->cookie->sess_destroy();
+ $this->assertNull($this->session->cookie->userdata($key));
+
+ // Native driver
+ $this->session->native->set_userdata($key, $msg);
+ $this->assertEquals($msg, $this->session->native->userdata($key));
+ $this->session->native->sess_destroy();
+ $this->assertNull($this->session->native->userdata($key));
+ }
+}
+
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index 13f338c6b..edfc83dd0 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -4,43 +4,39 @@ class Table_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->table = new Mock_Libraries_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'
- );
-
+
+ $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
*/
@@ -49,9 +45,9 @@ class Table_test extends CI_TestCase {
// 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'),
@@ -61,8 +57,7 @@ class Table_test extends CI_TestCase {
$this->table->heading
);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -71,13 +66,13 @@ class Table_test extends CI_TestCase {
// 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'),
@@ -87,11 +82,10 @@ class Table_test extends CI_TestCase {
$this->table->rows[1]
);
}
-
-
+
// Uility Methods
// --------------------------------------------------------------------
-
+
public function test_prep_args()
{
$expected = array(
@@ -99,7 +93,7 @@ class Table_test extends CI_TestCase {
array('data' => 'color'),
array('data' => 'size')
);
-
+
$this->assertEquals(
$expected,
$this->table->prep_args(array('name', 'color', 'size'))
@@ -114,7 +108,7 @@ class Table_test extends CI_TestCase {
$this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
);
}
-
+
public function test_default_template_keys()
{
$keys = array(
@@ -126,132 +120,124 @@ class Table_test extends CI_TestCase {
'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
'table_close'
);
-
+
foreach ($keys as $key)
{
$this->assertArrayHasKey($key, $this->table->default_template());
}
}
-
+
public function test_compile_template()
{
$this->assertFalse($this->table->set_template('invalid_junk'));
-
+
// non default key
$this->table->set_template(array('nonsense' => 'foo'));
$this->table->compile_template();
-
+
$this->assertArrayHasKey('nonsense', $this->table->template);
$this->assertEquals('foo', $this->table->template['nonsense']);
-
+
// override default
$this->table->set_template(array('table_close' => '</table junk>'));
$this->table->compile_template();
-
+
$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;')
+ 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()
{
$this->assertFalse($this->table->set_from_array('bogus'));
$this->assertFalse($this->table->set_from_array(NULL));
-
+
$data = array(
array('name', 'color', 'number'),
array('Laura', 'Red', '22'),
- array('Katie', 'Blue')
+ array('Katie', 'Blue')
);
-
+
$this->table->set_from_array($data, FALSE);
$this->assertEmpty($this->table->heading);
-
+
$this->table->clear();
-
- $expected_heading = array(
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'color'),
array('data' => 'number')
);
-
- $expected_second = array(
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
array('data' => 'Katie'),
array('data' => 'Blue'),
);
-
- $this->table->set_from_array($data);
- $this->assertEquals(count($this->table->rows), 2);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_set_from_object()
+
+ public function test_set_from_object()
{
// Make a stub of query instance
$query = new CI_TestCase();
@@ -268,29 +254,44 @@ class Table_test extends CI_TestCase {
return 2;
};
- $expected_heading = array(
+ $this->table->set_from_object($query);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'email')
);
- $expected_second = array(
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
'name' => array('data' => 'Foo Bar'),
'email' => array('data' => 'foo@bar.com'),
);
- $this->table->set_from_object($query);
+ $this->assertEquals($expected, $this->table->rows[1]);
+ }
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
+ public function test_generate()
+ {
+ // Prepare the data
+ $data = array(
+ array('Name', 'Color', 'Size'),
+ array('Fred', 'Blue', 'Small'),
+ array('Mary', 'Red', 'Large'),
+ array('John', 'Green', 'Medium')
);
+
+ $table = $this->table->generate($data);
+
+ // Test the table header
+ $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
+
+ // Test the first entry
+ $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
}
-
- // 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
index 250aefb24..eb6dacb73 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -4,11 +4,11 @@ class Typography_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->type = new Mock_Libraries_Typography();
-
+
$this->ci_instance($obj);
-
+
$this->type = $obj->type;
}
@@ -33,18 +33,18 @@ class Typography_test extends CI_TestCase {
'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));
+ $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.
@@ -85,12 +85,11 @@ That's my story and I'm sticking to it.<br />
The End.
EOH;
- $this->assertEquals($expected,
- $this->type->nl2br_except_pre($str));
+ $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
}
// --------------------------------------------------------------------
-
+
public function test_auto_typography()
{
$this->_blank_string();
@@ -103,7 +102,7 @@ EOH;
}
// --------------------------------------------------------------------
-
+
private function _blank_string()
{
// Test blank string
@@ -131,7 +130,7 @@ EOH;
{
$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));
}
@@ -141,7 +140,7 @@ EOH;
{
$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));
}
@@ -151,7 +150,7 @@ EOH;
{
$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));
}
@@ -161,7 +160,7 @@ EOH;
{
$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));
}
@@ -170,19 +169,18 @@ EOH;
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));
-
+ $this->assertEquals($expect, $this->type->auto_typography($str));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
new file mode 100644
index 000000000..d79a3ffc9
--- /dev/null
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -0,0 +1,270 @@
+<?php
+
+class Upload_test extends CI_TestCase {
+
+ function set_up()
+ {
+ $obj = new stdClass;
+ $obj->upload = new Mock_Libraries_Upload();
+ $obj->security = new Mock_Core_Security();
+ $obj->lang = new Mock_Core_Lang();
+
+ $this->ci_instance($obj);
+ $this->upload = $obj->upload;
+
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
+
+ $this->_test_dir = vfsStreamWrapper::getRoot();
+ }
+
+ function test_do_upload()
+ {
+ $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream');
+ }
+
+ function test_data()
+ {
+ $data = array(
+ 'file_name' => 'hello.txt',
+ 'file_type' => 'text/plain',
+ 'file_path' => '/tmp/',
+ 'full_path' => '/tmp/hello.txt',
+ 'raw_name' => 'hello',
+ 'orig_name' => 'hello.txt',
+ 'client_name' => '',
+ 'file_ext' => '.txt',
+ 'file_size' => 100,
+ 'is_image' => FALSE,
+ 'image_width' => '',
+ 'image_height' => '',
+ 'image_type' => '',
+ 'image_size_str' => ''
+ );
+
+ $this->upload->set_upload_path('/tmp/');
+
+ foreach ($data as $k => $v)
+ {
+ $this->upload->{$k} = $v;
+ }
+
+ $this->assertEquals('hello.txt', $this->upload->data('file_name'));
+ $this->assertEquals($data, $this->upload->data());
+ }
+
+ function test_set_upload_path()
+ {
+ $this->upload->set_upload_path('/tmp/');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+
+ $this->upload->set_upload_path('/tmp');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+ }
+
+ function test_set_filename()
+ {
+ $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir);
+ $this->upload->file_ext = '.txt';
+
+ $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt'));
+ $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt'));
+ }
+
+ function test_set_max_filesize()
+ {
+ $this->upload->set_max_filesize(100);
+ $this->assertEquals(100, $this->upload->max_size);
+ }
+
+ function test_set_max_filename()
+ {
+ $this->upload->set_max_filename(100);
+ $this->assertEquals(100, $this->upload->max_filename);
+ }
+
+ function test_set_max_width()
+ {
+ $this->upload->set_max_width(100);
+ $this->assertEquals(100, $this->upload->max_width);
+ }
+
+ function test_set_max_height()
+ {
+ $this->upload->set_max_height(100);
+ $this->assertEquals(100, $this->upload->max_height);
+ }
+
+ function test_set_allowed_types()
+ {
+ $this->upload->set_allowed_types('*');
+ $this->assertEquals('*', $this->upload->allowed_types);
+
+ $this->upload->set_allowed_types('foo|bar');
+ $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types);
+ }
+
+ function test_set_image_properties()
+ {
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $props = array(
+ 'image_width' => 170,
+ 'image_height' => 73,
+ 'image_type' => 'gif',
+ 'image_size_str' => 'width="170" height="73"'
+ );
+
+ $this->upload->set_image_properties($this->upload->file_temp);
+
+ $this->assertEquals($props['image_width'], $this->upload->image_width);
+ $this->assertEquals($props['image_height'], $this->upload->image_height);
+ $this->assertEquals($props['image_type'], $this->upload->image_type);
+ $this->assertEquals($props['image_size_str'], $this->upload->image_size_str);
+ }
+
+ function test_set_xss_clean()
+ {
+ $this->upload->set_xss_clean(TRUE);
+ $this->assertTrue($this->upload->xss_clean);
+
+ $this->upload->set_xss_clean(FALSE);
+ $this->assertFalse($this->upload->xss_clean);
+ }
+
+ function test_is_image()
+ {
+ $this->upload->file_type = 'image/x-png';
+ $this->assertTrue($this->upload->is_image());
+
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_image());
+ }
+
+ function test_is_allowed_filetype()
+ {
+ $this->upload->allowed_types = array('html', 'gif');
+
+ $this->upload->file_ext = '.txt';
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_allowed_filetype(FALSE));
+ $this->assertFalse($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_ext = '.html';
+ $this->upload->file_type = 'text/html';
+ $this->assertTrue($this->upload->is_allowed_filetype(FALSE));
+ $this->assertTrue($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->upload->file_ext = '.gif';
+ $this->upload->file_type = 'image/gif';
+ $this->assertTrue($this->upload->is_allowed_filetype());
+ }
+
+ function test_is_allowed_filesize()
+ {
+ $this->upload->max_size = 100;
+ $this->upload->file_size = 99;
+
+ $this->assertTrue($this->upload->is_allowed_filesize());
+
+ $this->upload->file_size = 101;
+ $this->assertFalse($this->upload->is_allowed_filesize());
+ }
+
+ function test_is_allowed_dimensions()
+ {
+ $this->upload->file_type = 'text/plain';
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $this->upload->max_width = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_width = 170;
+ $this->upload->max_height = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_height = 73;
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+ }
+
+ function test_validate_upload_path()
+ {
+ $this->upload->upload_path = '';
+ $this->assertFalse($this->upload->validate_upload_path());
+
+ $this->upload->upload_path = vfsStream::url('testDir');
+ $this->assertTrue($this->upload->validate_upload_path());
+ }
+
+ function test_get_extension()
+ {
+ $this->assertEquals('.txt', $this->upload->get_extension('hello.txt'));
+ $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess'));
+ $this->assertEquals('', $this->upload->get_extension('hello'));
+ }
+
+ function test_clean_file_name()
+ {
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('hello.txt'));
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('%253chell>o.txt'));
+ }
+
+ function test_limit_filename_length()
+ {
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10));
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9));
+ }
+
+ function test_do_xss_clean()
+ {
+ $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir);
+ $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir);
+ $file3 = vfsStream::newFile('file3.txt')->withContent('<script type="text/javascript">alert("Boo! said the billy goat")</script>')->at($this->_test_dir);
+
+ $this->upload->file_temp = vfsStream::url('file1.txt');
+ $this->assertTrue($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file2.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file3.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->assertTrue($this->upload->do_xss_clean());
+ }
+
+ function test_set_error()
+ {
+ $errors = array(
+ 'An error!'
+ );
+
+ $another = 'Another error!';
+
+ $this->upload->set_error($errors);
+ $this->assertEquals($errors, $this->upload->error_msg);
+
+ $errors[] = $another;
+ $this->upload->set_error($another);
+ $this->assertEquals($errors, $this->upload->error_msg);
+ }
+
+ function test_display_errors()
+ {
+ $this->upload->error_msg[] = 'Error test';
+ $this->assertEquals('<p>Error test</p>', $this->upload->display_errors());
+ }
+
+ function test_mimes_types()
+ {
+ $this->assertEquals('text/plain', $this->upload->mimes_types('txt'));
+ $this->assertFalse($this->upload->mimes_types('foobar'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 7dad7ac54..89383f807 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -1,7 +1,7 @@
<?php
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';
@@ -10,7 +10,7 @@ class UserAgent_test extends CI_TestCase {
// set a baseline user agent
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->agent = new Mock_Libraries_UserAgent();
$this->ci_instance($obj);
@@ -82,6 +82,4 @@ class UserAgent_test extends CI_TestCase {
$this->assertFalse($this->agent->accept_charset());
}
- // --------------------------------------------------------------------
-
} \ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index 92c9bea59..88d016bba 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -7,9 +7,9 @@
// Prototype :
//
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
-// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
+// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
-function autoload($class)
+function autoload($class)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
@@ -22,14 +22,18 @@ function autoload($class)
);
$ci_libraries = array(
- 'Calendar', 'Cart', 'Driver',
+ 'Calendar', 'Cart', 'Driver_Library',
'Email', 'Encrypt', 'Form_validation',
'Ftp', 'Image_lib', 'Javascript',
'Log', 'Migration', 'Pagination',
- 'Parser', 'Profiler', 'Session',
- 'Table', 'Trackback', 'Typography',
- 'Unit_test', 'Upload', 'User_agent',
- 'Xmlrpc', 'Zip',
+ 'Parser', 'Profiler', 'Table',
+ 'Trackback', 'Typography', 'Unit_test',
+ 'Upload', 'User_agent', 'Xmlrpc',
+ 'Zip',
+ );
+
+ $ci_drivers = array(
+ 'Session',
);
if (strpos($class, 'Mock_') === 0)
@@ -50,9 +54,18 @@ function autoload($class)
elseif (in_array($subclass, $ci_libraries))
{
$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
+ $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass;
+ }
+ elseif (in_array($subclass, $ci_drivers))
+ {
+ $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR;
+ $class = $subclass;
+ }
+ elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) {
+ $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
- elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
+ elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3)
{
$driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
$dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
@@ -75,15 +88,20 @@ function autoload($class)
{
$trace = debug_backtrace();
- // If the autoload call came from `class_exists` or `file_exists`,
- // we skipped and return FALSE
- if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists')
+ if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists')
{
+ // If the autoload call came from `class_exists` or `file_exists`,
+ // we skipped and return FALSE
return FALSE;
}
-
- throw new InvalidArgumentException("Unable to load $class.");
+ elseif (($autoloader = spl_autoload_functions()) && end($autoloader) !== __FUNCTION__)
+ {
+ // If there was other custom autoloader, passed away
+ return FALSE;
+ }
+
+ throw new InvalidArgumentException("Unable to load {$class}.");
}
include_once($file);
-} \ No newline at end of file
+}
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
index f327e6b07..eda9e1b60 100644
--- a/tests/mocks/ci_testcase.php
+++ b/tests/mocks/ci_testcase.php
@@ -1,11 +1,11 @@
<?php
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',
@@ -19,18 +19,17 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
'loader' => 'load',
'model' => 'model'
);
-
+
// --------------------------------------------------------------------
-
+
public function __construct()
{
parent::__construct();
-
$this->ci_config = array();
}
-
+
// --------------------------------------------------------------------
-
+
public function setUp()
{
if (method_exists($this, 'set_up'))
@@ -38,10 +37,10 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
$this->set_up();
}
}
-
+
// --------------------------------------------------------------------
-
- public function tearDown()
+
+ public function tearDown()
{
if (method_exists($this, 'tear_down'))
{
@@ -50,15 +49,15 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
+
public static function instance()
{
return self::$ci_test_instance;
}
-
+
// --------------------------------------------------------------------
-
- function ci_set_config($key, $val = '')
+
+ public function ci_set_config($key, $val = '')
{
if (is_array($key))
{
@@ -71,36 +70,36 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
- function ci_get_config()
+
+ public function ci_get_config()
{
return $this->ci_config;
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance($obj = FALSE)
+
+ public function ci_instance($obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance;
}
-
+
$this->ci_instance = $obj;
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance_var($name, $obj = FALSE)
+
+ public function ci_instance_var($name, $obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance->$name;
}
-
+
$this->ci_instance->$name =& $obj;
}
-
+
// --------------------------------------------------------------------
/**
@@ -112,10 +111,10 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
* test can modify the variable it assigns to and
* still maintain the global.
*/
- function &ci_core_class($name)
+ public function &ci_core_class($name)
{
$name = strtolower($name);
-
+
if (isset($this->global_map[$name]))
{
$class_name = ucfirst($name);
@@ -130,29 +129,29 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
{
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)
+ public function ci_set_core_class($name, $obj)
{
$orig =& $this->ci_core_class($name);
$orig = $obj;
}
-
+
// --------------------------------------------------------------------
// Internals
// --------------------------------------------------------------------
-
+
/**
* Overwrite runBare
*
@@ -169,28 +168,27 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
- function helper($name)
+
+ public function helper($name)
{
require_once(BASEPATH.'helpers/'.$name.'_helper.php');
}
// --------------------------------------------------------------------
-
+
/**
* This overload is useful to create a stub, that need to have a specific method.
*/
- function __call($method, $args)
+ public function __call($method, $args)
{
- if ($this->{$method} instanceof Closure)
+ if ($this->{$method} instanceof Closure)
{
return call_user_func_array($this->{$method},$args);
- }
- else
+ }
+ else
{
return parent::__call($method, $args);
}
}
-}
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
index fc94d7fff..a655ee1db 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -2,53 +2,65 @@
// Set up the global CI functions in their most minimal core representation
-function &get_instance()
+if ( ! function_exists('get_instance'))
{
- $test = CI_TestCase::instance();
- $instance = $test->ci_instance();
- return $instance;
+ function &get_instance()
+ {
+ $test = CI_TestCase::instance();
+ $test = $test->ci_instance();
+ return $test;
+ }
}
// --------------------------------------------------------------------
-function &get_config() {
- $test = CI_TestCase::instance();
- $config = $test->ci_get_config();
-
- return $config;
+if ( ! function_exists('get_config'))
+{
+ function &get_config()
+ {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+ return $config;
+ }
}
-function config_item($item)
+if ( ! function_exists('config_item'))
{
- $config =& get_config();
-
- if ( ! isset($config[$item]))
+ function config_item($item)
{
- return FALSE;
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
}
-
- return $config[$item];
}
// --------------------------------------------------------------------
-function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+if ( ! function_exists('load_class'))
{
- if ($directory != 'core' OR $prefix != 'CI_')
+ function load_class($class, $directory = 'libraries', $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.'');
+ if ($directory !== 'core' OR $prefix !== 'CI_')
+ {
+ throw new Exception('Not Implemented: Non-core load_class()');
+ }
+
+ $test = CI_TestCase::instance();
+
+ $obj =& $test->ci_core_class($class);
+
+ if (is_string($obj))
+ {
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
+ }
+
+ return $obj;
}
-
- return $obj;
}
// This is sort of meh. Should probably be mocked up with
@@ -57,76 +69,101 @@ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
// bootstrap testsuite.
// --------------------------------------------------------------------
-function remove_invisible_characters($str, $url_encoded = TRUE)
+if ( ! function_exists('remove_invisible_characters'))
{
- $non_displayables = array();
-
- // every control character except newline (dec 10)
- // carriage return (dec 13), and horizontal tab (dec 09)
-
- if ($url_encoded)
+ function remove_invisible_characters($str, $url_encoded = TRUE)
{
- $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
- $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
- }
-
- $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
+ $non_displayables = array();
- do
- {
- $str = preg_replace($non_displayables, '', $str, -1, $count);
- }
- while ($count);
+ // 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;
+ return $str;
+ }
}
// Clean up error messages
// --------------------------------------------------------------------
-function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+if ( ! function_exists('show_error'))
{
- throw new RuntimeException('CI Error: '.$message);
+ function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+ {
+ throw new RuntimeException('CI Error: '.$message);
+ }
}
-function show_404($page = '', $log_error = TRUE)
+if ( ! function_exists('show_404'))
{
- throw new RuntimeException('CI Error: 404');
+ function show_404($page = '', $log_error = TRUE)
+ {
+ throw new RuntimeException('CI Error: 404');
+ }
}
-function _exception_handler($severity, $message, $filepath, $line)
+if ( ! function_exists('_exception_handler'))
{
- throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ function _exception_handler($severity, $message, $filepath, $line)
+ {
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ }
}
// We assume a few things about our environment ...
// --------------------------------------------------------------------
-function is_php($version = '5.0.0')
+if ( ! function_exists('is_php'))
{
- return ! (version_compare(PHP_VERSION, $version) < 0);
+ function is_php($version = '5.0.0')
+ {
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+ }
}
-function is_really_writable($file)
+if ( ! function_exists('is_really_writable'))
{
- return is_writable($file);
+ function is_really_writable($file)
+ {
+ return is_writable($file);
+ }
}
-function is_loaded()
+if ( ! function_exists('is_loaded'))
{
- throw new Exception('Bad Isolation: mock up environment');
+ function is_loaded()
+ {
+ throw new Exception('Bad Isolation: mock up environment');
+ }
}
-function log_message($level = 'error', $message, $php_error = FALSE)
+if ( ! function_exists('log_message'))
{
- return TRUE;
+ function log_message($level = 'error', $message, $php_error = FALSE)
+ {
+ return TRUE;
+ }
}
-function set_status_header($code = 200, $text = '')
+if ( ! function_exists('set_status_header'))
{
- return TRUE;
-}
-
-// EOF \ No newline at end of file
+ function set_status_header($code = 200, $text = '')
+ {
+ return TRUE;
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
index 8a337d2ef..2a4aa4997 100644
--- a/tests/mocks/core/input.php
+++ b/tests/mocks/core/input.php
@@ -1,10 +1,10 @@
<?php
class Mock_Core_Input extends CI_Input {
-
+
/**
- * Since we use GLOBAL to fetch Security and Utf8 classes,
- * we need to use inversion of control to mock up
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
* the same process within CI_Input class constructor.
*
* @covers CI_Input::__construct()
diff --git a/tests/mocks/core/lang.php b/tests/mocks/core/lang.php
new file mode 100644
index 000000000..1b99aedb3
--- /dev/null
+++ b/tests/mocks/core/lang.php
@@ -0,0 +1,15 @@
+<?php
+
+class Mock_Core_Lang extends CI_Lang {
+
+ function line($line = '')
+ {
+ return FALSE;
+ }
+
+ function load($langfile, $idiom = '', $return = false, $add_suffix = true, $alt_path = '')
+ {
+ return;
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
index d4b29bb3d..53d88d55b 100644
--- a/tests/mocks/core/loader.php
+++ b/tests/mocks/core/loader.php
@@ -1,7 +1,7 @@
<?php
class Mock_Core_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
@@ -15,16 +15,17 @@ class Mock_Core_Loader extends CI_Loader {
{
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);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
index d7ea0e6bd..e19a8b20b 100644
--- a/tests/mocks/core/security.php
+++ b/tests/mocks/core/security.php
@@ -1,7 +1,7 @@
<?php
class Mock_Core_Security extends CI_Security {
-
+
public function csrf_set_cookie()
{
// We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
index b6946091e..94f75df64 100644
--- a/tests/mocks/core/uri.php
+++ b/tests/mocks/core/uri.php
@@ -1,12 +1,12 @@
<?php
class Mock_Core_URI 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',
@@ -14,12 +14,13 @@ class Mock_Core_URI extends CI_URI {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
protected function _is_cli_request()
{
return FALSE;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
index b77d717e7..068e74ac1 100644
--- a/tests/mocks/core/utf8.php
+++ b/tests/mocks/core/utf8.php
@@ -1,27 +1,26 @@
<?php
class Mock_Core_Utf8 extends CI_Utf8 {
-
+
/**
- * We need to define several constants as
+ * We need to define several constants as
* the same process within CI_Utf8 class constructor.
*
* @covers CI_Utf8::__construct()
*/
public function __construct()
{
- defined('UTF8_ENABLED') or define('UTF8_ENABLED', TRUE);
+ defined('UTF8_ENABLED') OR define('UTF8_ENABLED', TRUE);
if (extension_loaded('mbstring'))
{
- defined('MB_ENABLED') or define('MB_ENABLED', TRUE);
+ defined('MB_ENABLED') OR define('MB_ENABLED', TRUE);
mb_internal_encoding('UTF-8');
}
else
{
- defined('MB_ENABLED') or define('MB_ENABLED', FALSE);
+ defined('MB_ENABLED') OR define('MB_ENABLED', FALSE);
}
-
}
} \ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 23a3de2a4..44dcef9ec 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php
index ace0a31b1..a590b9f53 100644
--- a/tests/mocks/database/config/mysql.php
+++ b/tests/mocks/database/config/mysql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'mysql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'mysql',
+ 'dbdriver' => 'mysql'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'mysql',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
index cefb6b008..96608f787 100644
--- a/tests/mocks/database/config/pdo/mysql.php
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -1,16 +1,16 @@
<?php
return array(
-
+
// Typical Database configuration
'pdo/mysql' => array(
- 'dsn' => '',
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
'hostname' => 'localhost',
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
+ 'subdriver' => 'mysql'
),
// Database configuration with failover
@@ -21,17 +21,17 @@ return array(
'password' => 'wrong password',
'database' => 'not_ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
+ 'subdriver' => 'mysql',
'failover' => array(
array(
- 'dsn' => '',
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
'hostname' => 'localhost',
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
- ),
- ),
- ),
+ 'subdriver' => 'mysql'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
index 5196e9ad9..e55e3ea77 100644
--- a/tests/mocks/database/config/pdo/pgsql.php
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pdo/pgsql' => array(
'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
@@ -10,7 +10,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
+ 'subdriver' => 'pgsql'
),
// Database configuration with failover
@@ -21,7 +21,7 @@ return array(
'password' => 'wrong password',
'database' => 'not_ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
+ 'subdriver' => 'pgsql',
'failover' => array(
array(
'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
@@ -30,8 +30,8 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
- ),
- ),
- ),
+ 'subdriver' => 'pgsql'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index c68b4b213..1bf56b3ac 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -10,7 +10,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
+ 'subdriver' => 'sqlite'
),
// Database configuration with failover
@@ -21,7 +21,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
+ 'subdriver' => 'sqlite',
'failover' => array(
array(
'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
@@ -29,9 +29,9 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => 'sqlite',
- 'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
- ),
- ),
- ),
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php
index c06af8ce0..1444b0066 100644
--- a/tests/mocks/database/config/pgsql.php
+++ b/tests/mocks/database/config/pgsql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pgsql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'postgres',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'postgre',
+ 'dbdriver' => 'postgre'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'postgre',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 755ce2a3a..d37ee4871 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -9,7 +9,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => 'sqlite3',
+ 'dbdriver' => 'sqlite3'
),
// Database configuration with failover
@@ -27,8 +27,8 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => 'sqlite3',
- ),
- ),
- ),
+ 'dbdriver' => 'sqlite3'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 59028ed9c..75658530b 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -6,7 +6,7 @@ class Mock_Database_DB {
* @var array DB configuration
*/
private $config = array();
-
+
/**
* Prepare database configuration skeleton
*
@@ -21,7 +21,7 @@ class Mock_Database_DB {
/**
* Build DSN connection string for DB driver instantiate process
*
- * @param string Group name
+ * @param string Group name
* @return string DSN Connection string
*/
public function set_dsn($group = 'default')
@@ -45,9 +45,9 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
- $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE;
- $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
- $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
+ $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn'];
+ $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver'];
+ $failover = empty($config['failover']) ? FALSE : $config['failover'];
$dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
.'@'.$config['hostname'].'/'.$config['database'];
@@ -55,7 +55,7 @@ class Mock_Database_DB {
// Build the parameter
$other_params = array_slice($config, 6);
if ($dsnstring) $other_params['dsn'] = $dsnstring;
- if ($pdodriver) $other_params['pdodriver'] = $pdodriver;
+ if ($subdriver) $other_params['subdriver'] = $subdriver;
if ($failover) $other_params['failover'] = $failover;
return $dsn.'?'.http_build_query($other_params);
@@ -65,28 +65,27 @@ class Mock_Database_DB {
* Return a database config array
*
* @see ./config
- * @param string Driver based configuration
- * @return array
+ * @param string Driver based configuration
+ * @return array
*/
public static function config($driver)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
-
return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php');
}
/**
* Main DB method wrapper
*
- * @param string Group or DSN string
- * @param bool
- * @return object
+ * @param string Group or DSN string
+ * @param bool
+ * @return object
*/
public static function DB($group, $query_builder = FALSE)
{
include_once(BASEPATH.'database/DB.php');
- try
+ try
{
$db = DB($group, $query_builder);
}
@@ -97,4 +96,5 @@ class Mock_Database_DB {
return $db;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
index cb1820277..65ac2c4cc 100644
--- a/tests/mocks/database/db/driver.php
+++ b/tests/mocks/database/db/driver.php
@@ -1,7 +1,7 @@
<?php
class Mock_Database_DB_Driver extends CI_DB_driver {
-
+
/**
* @var object The actual Driver
*/
@@ -16,7 +16,10 @@ class Mock_Database_DB_Driver extends CI_DB_driver {
*/
public function __construct($driver_class, $config = array())
{
- if (is_string($driver_class)) $this->ci_db_driver = new $driver_class($config);
+ if (is_string($driver_class))
+ {
+ $this->ci_db_driver = new $driver_class($config);
+ }
}
/**
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
index 1b95c92af..3f2252622 100644
--- a/tests/mocks/database/db/querybuilder.php
+++ b/tests/mocks/database/db/querybuilder.php
@@ -1,10 +1,3 @@
<?php
-if ( ! class_exists('CI_DB_query_builder'))
-{
- class Mock_Database_DB_QueryBuilder extends CI_DB_active_record {}
-}
-else
-{
- class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {}
-}
+class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
index 34a74e2bf..e0c1fb06c 100644
--- a/tests/mocks/database/drivers/mysql.php
+++ b/tests/mocks/database/drivers/mysql.php
@@ -1,16 +1,17 @@
<?php
class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_mysql_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
index 590e19552..17768eed7 100644
--- a/tests/mocks/database/drivers/pdo.php
+++ b/tests/mocks/database/drivers/pdo.php
@@ -1,13 +1,13 @@
<?php
class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
index 0df905963..5a45115fa 100644
--- a/tests/mocks/database/drivers/postgre.php
+++ b/tests/mocks/database/drivers/postgre.php
@@ -1,16 +1,17 @@
<?php
class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_postgre_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
index 76a182cbf..512467520 100644
--- a/tests/mocks/database/drivers/sqlite.php
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -1,16 +1,17 @@
<?php
class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_sqlite3_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 671336cc4..18e1ddd4d 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -41,8 +41,7 @@ class Mock_Database_Schema_Skeleton {
return static::$db;
}
-
-
+
/**
* Create the dummy tables
*
@@ -54,20 +53,20 @@ class Mock_Database_Schema_Skeleton {
static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
- 'constraint' => 3,
+ 'constraint' => 3
),
'name' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
+ 'constraint' => 40
),
'email' => array(
'type' => 'VARCHAR',
- 'constraint' => 100,
+ 'constraint' => 100
),
'country' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
- ),
+ 'constraint' => 40
+ )
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -76,18 +75,35 @@ class Mock_Database_Schema_Skeleton {
static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
- 'constraint' => 3,
+ 'constraint' => 3
),
'name' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
+ 'constraint' => 40
),
'description' => array(
- 'type' => 'TEXT',
- ),
+ 'type' => 'TEXT'
+ )
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+
+ // Misc Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'key' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'value' => array(
+ 'type' => 'TEXT'
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
}
/**
@@ -103,24 +119,29 @@ class Mock_Database_Schema_Skeleton {
array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
- array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK')
),
'job' => array(
- array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
- array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
- array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician')
),
+ 'misc' => array(
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%')
+ )
);
- foreach ($data as $table => $dummy_data)
+ foreach ($data as $table => $dummy_data)
{
static::$db->truncate($table);
foreach ($dummy_data as $single_dummy_data)
{
- static::$db->insert($table, $single_dummy_data);
+ static::$db->insert($table, $single_dummy_data);
}
}
}
+
} \ No newline at end of file
diff --git a/tests/mocks/libraries/calendar.php b/tests/mocks/libraries/calendar.php
new file mode 100644
index 000000000..8fee5365e
--- /dev/null
+++ b/tests/mocks/libraries/calendar.php
@@ -0,0 +1,25 @@
+<?php
+
+class Mock_Libraries_Calendar extends CI_Calendar {
+
+ public function __construct($config = array())
+ {
+ $this->CI = new stdClass;
+ $this->CI->lang = new Mock_Core_Lang();
+
+ if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE))
+ {
+ $this->CI->lang->load('calendar');
+ }
+
+ $this->local_time = time();
+
+ if (count($config) > 0)
+ {
+ $this->initialize($config);
+ }
+
+ log_message('debug', 'Calendar Class Initialized');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/encrypt.php b/tests/mocks/libraries/encrypt.php
new file mode 100644
index 000000000..f1859398f
--- /dev/null
+++ b/tests/mocks/libraries/encrypt.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Libraries_Encrypt extends CI_Encrypt {
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php
new file mode 100644
index 000000000..9d6feee42
--- /dev/null
+++ b/tests/mocks/libraries/session.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Mock library to add testing features to Session driver library
+ */
+class Mock_Libraries_Session extends CI_Session {
+ /**
+ * Simulate new page load
+ */
+ public function reload()
+ {
+ $this->_flashdata_sweep();
+ $this->_flashdata_mark();
+ $this->_tempdata_sweep();
+ }
+}
+
+/**
+ * Mock cookie driver to overload cookie setting
+ */
+class Mock_Libraries_Session_cookie extends CI_Session_cookie {
+ /**
+ * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing
+ */
+ protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false,
+ $httponly = false)
+ {
+ if (empty($value) || $expire <= time()) {
+ // Clear cookie
+ unset($_COOKIE[$name]);
+ }
+ else {
+ // Set cookie
+ $_COOKIE[$name] = $value;
+ }
+ }
+}
+
+/**
+ * Mock native driver (just for consistency in loading)
+ */
+class Mock_Libraries_Session_native extends CI_Session_native { }
+
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 97fbb30bd..87c278bce 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -1,7 +1,7 @@
<?php
class Mock_Libraries_Table extends CI_Table {
-
+
// Overide inaccesible protected method
public function __call($method, $params)
{
@@ -12,4 +12,5 @@ class Mock_Libraries_Table extends CI_Table {
throw new BadMethodCallException('Method '.$method.' was not found');
}
+
} \ No newline at end of file
diff --git a/tests/mocks/libraries/upload.php b/tests/mocks/libraries/upload.php
new file mode 100644
index 000000000..988723e45
--- /dev/null
+++ b/tests/mocks/libraries/upload.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Upload extends CI_Upload {} \ No newline at end of file
diff --git a/tests/mocks/uploads/ci_logo.gif b/tests/mocks/uploads/ci_logo.gif
new file mode 100644
index 000000000..073ec14b4
--- /dev/null
+++ b/tests/mocks/uploads/ci_logo.gif
Binary files differ
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 000000000..56cb8841c
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,25 @@
+<?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">
+ <directory suffix="test.php">./codeigniter/core</directory>
+ <directory suffix="test.php">./codeigniter/helpers</directory>
+ <directory suffix="test.php">./codeigniter/libraries</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ </blacklist>
+ </filters>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index 1792ae38d..06d4a011b 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
index 602030d4e..7121edc45 100644
--- a/tests/travis/pdo/mysql.phpunit.xml
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
index 77e1493c6..df3ff986e 100644
--- a/tests/travis/pdo/pgsql.phpunit.xml
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
index cdccef017..7d867f6d1 100644
--- a/tests/travis/pdo/sqlite.phpunit.xml
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index dfc1bff1c..bfddbf6b5 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 3223da5e7..75c946aee 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -17,10 +17,9 @@
<directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
- <filters>
- <blacklist>
- <directory suffix=".php">PEAR_INSTALL_DIR</directory>
- <directory suffix=".php">PHP_LIBDIR</directory>
- </blacklist>
- </filters>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
</phpunit> \ No newline at end of file
diff --git a/user_guide_src/source/DCO.rst b/user_guide_src/source/DCO.rst
new file mode 100644
index 000000000..c8f9b49c6
--- /dev/null
+++ b/user_guide_src/source/DCO.rst
@@ -0,0 +1,27 @@
+#####################################
+Developer's Certificate of Origin 1.1
+#####################################
+
+By making a contribution to this project, I certify that:
+
+(1) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(2) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(3) The contribution was provided directly to me by some other
+ person who certified (1), (2) or (3) and I have not modified
+ it.
+
+(4) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
diff --git a/user_guide_src/source/_themes/eldocs/layout.html b/user_guide_src/source/_themes/eldocs/layout.html
index 4b1a0221c..51d61b849 100644
--- a/user_guide_src/source/_themes/eldocs/layout.html
+++ b/user_guide_src/source/_themes/eldocs/layout.html
@@ -9,6 +9,9 @@
{%- if project == 'ExpressionEngine' %}{% set project_abbreviation = 'ee' %}{% set project_domain = 'expressionengine.com' %}{% endif -%}
{%- if project == 'CodeIgniter' %}{% set project_abbreviation = 'ci' %}{% set project_domain = 'codeigniter.com' %}{% endif -%}
{%- if project == 'MojoMotor' %}{% set project_abbreviation = 'mm' %}{% set project_domain = 'mojomotor.com' %}{% endif -%}
+{%- set exclude_comments = ['index', 'license', 'changelog',
+ 'development/index', 'development/extension_hooks/index',
+ 'development/guidelines/template'] %}
<html>
<head>
@@ -85,36 +88,29 @@
<div id="brand" class="{{ project_abbreviation }}">
<a href="http://{{ project_domain }}/"><img src="{{ pathto('_static/asset/img/' + project_abbreviation + '-logo.gif', 1) }}" alt="{{ project }}"></a>
<p>{{ release }} User Guide</p>
- {%- if show_source and has_source and sourcename %}
- <p><a href="{{ pathto('_sources/' + sourcename, true)|e }}"
- rel="nofollow">{{ _('Show Source') }}</a></p>
- {%- endif %}
</div><!-- /#brand -->
<div id="header">
- <form method="get" action="http://www.google.com/search">
- <fieldset>
- <input type="text" name="q" id="q" value="">
- <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="{{ project_domain }}/user_guide/" />
- <input class="grades" type="submit" value="search">
- </fieldset>
- </form>
+ {%- include "searchbox.html" %}
<ul>
{%- block rootrellink %}
- <li><a href="{{ pathto(master_doc) }}">Home</a>&nbsp;&nbsp;{{ reldelim1 }}</li>
- <li><a id="toc-link" href="{{ pathto(master_doc) }}">Table of Contents</a>&nbsp;&nbsp;{{ reldelim1 }}</li>
+ <li><a href="{{ pathto(master_doc) }}">User Guide Home</a>{%- if pagename != 'index' %}&nbsp;&nbsp;{{ reldelim1 }}{%- endif %}</li>
{%- endblock %}
{%- for parent in parents %}
<li><a href="{{ parent.link|e }}" {% if loop.last %}{{ accesskey("U") }}{% endif %}>{{ parent.title }}</a>&nbsp;&nbsp; {{ reldelim1 }}</li>
{%- endfor %}
+ {%- if pagename != 'index' %}
<li><strong>{{ title }}</strong></li>
+ {%- endif %}
</ul>
</div><!-- /#header -->
- <div class="section" id="content">
+ <div class="section body" id="content">
+ {%- block body %}
{{ body }}
+ {%- endblock %}
</div>
{%- endblock %}
@@ -124,49 +120,9 @@
{%- block footer %}
<div id="footer">
- <p class="top">
- {% if prev %}
- <span class="prev">Previous Topic: <a href="{{ prev.link }}">{{ prev.title }}</a></span>
- {% endif %}
- {% if next %}
- <span class="next">Next Topic: <a href="{{ next.link }}">{{ next.title }}</a></span>
- {% endif %}
- <a href="#header" title="Return to top">Return to top</a>
- </p>
- <p><a href="{{ project_url }}">{{ project }}</a> &ndash; Copyright &copy; {{ copyright }}</a> &ndash; Last updated: {{ last_updated }}</p>
+ <p class="top"><a href="#header" title="Return to top">Return to top</a></p>
+ <p><a href="http://{{ project_domain }}/">{{ project }}</a> &ndash; Copyright &copy; {{ copyright }}</a></p>
</div><!-- /#footer -->
{%- endblock %}
-
- <script src="{{ pathto('_static/asset/js/jquery-ui-min.js', 1) }}" type="text/javascript" charset="utf-8" async></script>
- <script type="text/javascript" charset="utf-8">
- $('#toc-link').click(function(){
- $('#table-contents').animate({ left: '0' },1000);
- return false;
- });
- $('html').click(function(){
- if ($('#table-contents').css("left") == '0px'){
- $('#table-contents').animate({ left: '-520' },1000);
- }
- });
- $('#table-contents').click(function(event){
- event.stopPropagation();
- });
-/* $('*:not(#table-contents,#toc-link)').click(function(){
- if ($('#table-contents').css("left") == '0px'){
- $('#table-contents').animate({ left: '-520' },1000);
- }
- });
-/* $("#toc-link").click(function () {
- $('#table-contents').show("slide", { direction: "left" }, 100);
- event.stopPropagation();
- return false;
- });
- $('*:not(#table-contents,#toc-link)').click(function () {
- if ($('#table-contents').is(":visible")) {
- $('#table-contents').hide("slide", { direction: "left" }, 100);
- event.stopPropagation();
- }
- }); */
- </script>
</body>
</html> \ No newline at end of file
diff --git a/user_guide_src/source/_themes/eldocs/searchbox.html b/user_guide_src/source/_themes/eldocs/searchbox.html
new file mode 100644
index 000000000..039590bd9
--- /dev/null
+++ b/user_guide_src/source/_themes/eldocs/searchbox.html
@@ -0,0 +1,21 @@
+<!--
+ --------------------------------
+ Original Google search box block
+ --------------------------------
+
+<form method="get" action="http://www.google.com/search">
+ <fieldset>
+ <input type="text" name="q" id="q" value="">
+ <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="{{ project_domain }}/user_guide/" />
+ <input class="grades" type="submit" value="search">
+ </fieldset>
+</form>
+-->
+
+
+<form class="search" action="{{ pathto('search') }}" method="get">
+ <input type="text" name="q" id="q" value="" />
+ <input type="submit" value="search" />
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+</form>
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 66768bac6..0a63871c5 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
@@ -49,7 +49,9 @@ h1, h2, h3, h4, h5, h6, pre{ color: #094776; }
h1{ font-size: 28px; }
-h2{ font-size: 24px; }
+h2{ font-size: 24px; font-weight: normal; }
+
+h1, h2, h3, h4, h5, h6{ margin-bottom: 20px; }
h2, h3{ border-bottom: 2px solid #EEEEEE; padding: 0 0 3px; }
@@ -73,6 +75,10 @@ p, dl, ul, ol{ margin: 20px 0; }
li > ol{ margin: 0; margin-left: 40px; }
dl > dd{ margin-left: 20px; }
+
+ li > p { margin: 0; }
+
+#expressionengine-user-guide li em { font-style: normal; }
p, li, dd, dt, pre{ line-height: 1.5; }
@@ -141,39 +147,35 @@ img{ display: block; max-width: 100%; }
fieldset{ border: 0; }
.top{ float: right; }
-.next{ padding: 0 20px 0 10px; }
-.prev{ padding-right: 10px; }
-.highlight-ci,
+.highlight{ overflow-x: auto; }
+
+.admonition,
.highlight-ee,
+.highlight-ci,
.highlight-rst,
.highlight-bash,
.highlight-perl,
+.highlight-php,
.cp-path,
-.important,
-.note{
- background-color: #F5FBFF;
+.codeblock{
+ background-color: #F9FEFF;
border: 1px solid #C8DEF0;
- margin: 20px 0 20px 20px;
+ -moz-box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
+ -webkit-box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
+ box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
+ margin: 20px 0;
padding: 10px 10px 8px;
}
- .highlight-ci,
- .highlight-ee,
- .highlight-rst,
- .highlight-bash,
- .highlight-perl{
- -moz-box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
- -webkit-box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
- box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
- }
+.highlight-ci{ background-color: #FEFEFE; border-color: #E5E5E5; }
- .cp-path{ background-color: #FFFDED; border-color: #D1CDB0; }
- .important, .note{ background-color: #F2FFE8; border-color: #B9D3A6; }
- .highlight-rst{ background-color: #F9FEFE; border-color: #AACFCF; }
+ .admonition p{ margin: 0; }
+
+ .codeblock{ margin: 10px 0; }
- .important p,
- .note p{ margin: 0; }
+ .cp-path{ background-color: #FAFFF6; border-color: #D1CDB0; }
+ .important, .note{ background-color: #FFFFF2; border-color: #C8C8A5; }
.admonition-title{
float: left;
@@ -183,6 +185,8 @@ fieldset{ border: 0; }
}
.admonition-title:after{ content: ': '; }
+
+.highlighted{ background-color: #FFF09B; }
#table-contents{
bottom: 0;
@@ -295,6 +299,43 @@ fieldset{ border: 0; }
#footer p{ margin: 0; }
+#comments,
+#feedLink{ background: #FCFCFC; padding: 1px 40px 20px; }
+
+ #comments{ border-top: 1px solid #CCCCCC; }
+ #comments h3{ margin: 20px 0; }
+
+.comments td.avatar{ min-width: 100px; }
+
+.comments td.column1,
+.comments td.post{ background-color: #FFFFFF; padding: 10px; }
+
+.comments td.staffeven{ border-left: 10px solid #C8DEF0; }
+
+#comment_form p,
+.comments p{ margin: 0; }
+
+ .comments p{ margin-bottom: 10px; }
+
+#comment_form textarea{
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+ margin-bottom: 10px;
+ resize: none;
+ width: 100%;
+}
+
+#comment_form input[type="submit"]{ margin-top: 10px; }
+
+ #comment_form textarea:focus{ background-color: #FFFFF2; border: 1px solid #666666; outline: 0; }
+
+ #commentFormInstructions{ font-size: 12px; margin: 20px 0; }
+
+ #feedLink a{ font-size: 16px; }
+
+ #feedLink a img{ float: left; margin-right: 5px; }
+
@media (max-width:800px){
#footer .top,
#header form{ float: none; margin-bottom: 10px; }
@@ -310,4 +351,4 @@ fieldset{ border: 0; }
@media screen and (-webkit-min-device-pixel-ratio:0){
#header input[type="submit"]{ padding-bottom: 7px; }
-} \ No newline at end of file
+}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 730c52bb4..486a67696 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -9,8 +9,7 @@ Release Date: Not Released
- License
- - CodeIgniter has been relicensed with the Open Software License (3.0),
- eliminating its old proprietary licensing.
+ - CodeIgniter has been relicensed with the Open Software License (3.0), eliminating its old proprietary licensing.
- All system files are licensed with OSL 3.0.
- Config, error, and sample files shipped in the application folder are
@@ -20,108 +19,165 @@ Release Date: Not Released
- General Changes
- PHP 5.1.6 is no longer supported. CodeIgniter now requires PHP 5.2.4.
+ - ``$_SERVER['CI_ENV']`` can now be set to control the ``ENVIRONMENT`` constant.
- Added an optional backtrace to php-error template.
- Added Android to the list of user agents.
- - Added Windows 7, Android, Blackberry and iOS to the list of user platforms.
+ - Added Windows 7, Windows 8, Android, Blackberry, iOS and PlayStation 3 to the list of user platforms.
+ - Added Fennec (Firefox for mobile) to the list of mobile user agents.
- Ability to log certain error types, not all under a threshold.
- Added support for pem, p10, p12, p7a, p7c, p7m, p7r, p7s, crt, crl, der, kdb, rsa, cer, sst, csr Certs to mimes.php.
- Added support for pgp and gpg to mimes.php.
- 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.
- - Added Romanian and Greek characters in foreign_characters.php
+ - Added support for ics Calendar files to mimes.php.
+ - Added support for rar archives to mimes.php.
+ - Updated support for xml ('application/xml') and xsl ('application/xml', 'text/xsl') files in 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.
+ - Updated support for docx files in mimes.php.
+ - Updated support for php files in mimes.php.
+ - Updated support for zip files in mimes.php.
+ - Updated support for csv files in mimes.php.
+ - Added some more doctypes.
+ - Added Romanian, Greek and Vietnamese characters in *foreign_characters.php*.
- Changed logger to only chmod when file is first created.
- Removed previously deprecated SHA1 Library.
- Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php.
Only entries in ``$autoload['libraries']`` are auto-loaded now.
- - Added some more doctypes.
+ - Removed previously deprecated EXT constant.
- Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
+ - Moved error templates to "application/views/errors"
+ - Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per environment.
+ - Changed detection of ``$view_folder`` so that if it's not found in the current path, it will now also be searched for under the application folder.
+ - Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths.
+ - Updated email validation methods to use ``filter_var()`` instead of PCRE.
+ - Changed environment defaults to report all errors in *development* and only fatal ones in *testing*, *production* but only display them in *development*.
+ - Updated *ip_address* database field lengths from 16 to 45 for supporting IPv6 address on :doc:`Trackback Library <libraries/trackback>` and :doc:`Captcha Helper <helpers/captcha_helper>`.
- Helpers
- - url_title() will now trim extra dashes from beginning and end.
+ - :doc:`Date Helper <helpers/date_helper>` changes include:
+ - ``now()`` now works with all timezone strings supported by PHP.
+ - Added an optional third parameter to ``timespan()`` that constrains the number of time units displayed.
+ - Added an optional parameter to ``timezone_menu()`` that allows more attributes to be added to the generated select tag.
+ - Deprecated ``standard_date()``, which now just uses the native ``date()`` with `DateTime constants <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_.
+ - Added function ``date_range()`` that generates a list of dates between a specified period.
+ - ``create_captcha()`` accepts additional colors parameter, allowing for color customization.
+ - :doc:`URL Helper <helpers/url_helper>` changes include:
+ - ``url_title()`` will now trim extra dashes from beginning and end.
+ - ``anchor_popup()`` will now fill the "href" attribute with the URL and its JS code will return false instead.
+ - Added JS window name support to ``anchor_popup()`` function.
+ - Added support (auto-detection) for HTTP/1.1 response code 303 in ``redirect()``.
+ - "auto" method in ``redirect()`` now chooses the "refresh" method only on IIS servers, instead of all servers on Windows.
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
- - Changed humanize to include a second param for the separator.
+ - Changed ``humanize()`` to include a second param for the separator.
- Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
- Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
- - Added an optional third parameter to ``timespan()`` that constrains the number of time units displayed.
- - 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.
- - Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
- - Added date_range() to the :doc:`Date Helper <helpers/html_helper>`.
+ - 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.
+ - ``do_hash()`` now uses PHP's native ``hash()`` function (supporting more algorithms) and is deprecated.
+ - Removed previously deprecated helper function ``js_insert_smiley()`` from :doc:`Smiley Helper <helpers/smiley_helper>`.
+ - :doc:`File Helper <helpers/file_helper>` changes include:
+ - ``set_realpath()`` can now also handle file paths as opposed to just directories.
+ - Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
+ - ``read_file()`` is now a deprecated alias of ``file_get_contents()``.
+ - :doc:`Security Helper <helpers/security_helper>` function ``strip_image_tags()`` is now an alias for the same method in the :doc:`Security Library <libraries/security>`.
- Database
- - Renamed the Active Record class to Query Builder to remove confusion with
- the Active Record design pattern
- - Added new :doc:`Query Builder <database/query_builder>` methods that return
- - Added the ability to insert objects with insert_batch() in :doc:`Query Builder <database/query_builder>`.
- - Added new :doc:`Query Builder <database/query_builder>` methods that return
- the SQL string of queries without executing them: get_compiled_select(),
- get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- - Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - :doc:`Query Builder <database/query_builder>` changes include:
+ - Renamed the Active Record class to Query Builder to remove confusion with the Active Record design pattern.
+ - Added the ability to insert objects with insert_batch().
+ - Added new methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
+ - Added an optional parameter that allows to disable escaping (useful for custom fields) for methods join(), order_by(), where_in(), or_where_in(), where_not_in(), or_where_not_in().
+ - Added support for join() with multiple conditions.
+ - Added support for USING in join().
+ - Changed limit() to ignore NULL values instead of always casting to integer.
+ - Changed offset() to ignore empty values instead of always casting to integer.
- Improved support for the MySQLi driver, including:
- - OOP style of the PHP extension is now used, instead of the procedural aliases.
- - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
- - Added persistent connections support for PHP >= 5.3.
+ - OOP style of the PHP extension is now used, instead of the procedural aliases.
+ - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
+ - Added persistent connections support for PHP >= 5.3.
+ - Added support for backup() in :doc:`Database Utilities <database/utilities>`.
- Added 'dsn' configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
- Improved PDO database support.
- - Added Interbase/Firebird database support via the "interbase" driver
+ - Added Interbase/Firebird database support via the 'ibase' 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 boolean data type support in escape().
+ - ``pg_version()`` is now used to get the database version number, when possible.
+ - Added ``db_set_charset()`` support.
+ - Added support for ``optimize_table()`` in :doc:`Database Utilities <database/utilities>` (rebuilds table indexes).
+ - Added boolean data type support in ``escape()``.
+ - Added ``update_batch()`` support.
+ - Removed ``limit()`` and ``order_by()`` support for UPDATE and DELETE queries as PostgreSQL does not support those features.
+ - Added a work-around for dead persistent connections to be re-created after a database restart.
- Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction.
- - Removed limit() and order_by() support for UPDATE and DELETE queries in PostgreSQL driver. Postgres does not support those features.
- Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias.
+ - Renamed internal method _escape_identifiers() to escape_identifiers().
+ - Updated escape_identifiers() to accept an array of fields as well as strings.
- 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 random ordering support for MSSQL, SQLSRV.
- Added support for SQLite3 database driver.
+ - Improved support of the CUBRID driver, including:
+ - Added DSN string support.
+ - Added persistent connections support.
+ - Improved list_databases() in :doc:`Database Utility <database/utilities>` (until now only the currently used database was returned).
+ - Improved support of the MSSQL and SQLSRV drivers, including:
+ - Added random ordering support.
+ - Added support for optimize_table() in :doc:`Database Utility <database/utilities>`.
+ - Added escaping with QUOTE_IDENTIFIER setting detection.
+ - Added port handling support for UNIX-based systems (MSSQL driver).
+ - Added OFFSET support for SQL Server 2005 and above.
- Improved support of the Oracle (OCI8) driver, including:
- - Added DSN string support (Easy Connect and TNS).
- - Added support for dropping tables to :doc:`Database Forge <database/forge>`.
- - Added support for listing database schemas to :doc:`Database Utilities <database/utilities>`.
- - Generally improved for speed and cleaned up all of its components.
- - *Row* result methods now really only fetch only the needed number of rows, instead of depending entirely on result().
- - num_rows() is now only called explicitly by the developer and no longer re-executes statements.
- - Added replace() support for SQLite.
- - Renamed internal method _escape_identifiers() to escape_identifiers().
- - Added SQLite support for drop_table() in :doc:`Database Forge <database/forge>`.
+ - Added DSN string support (Easy Connect and TNS).
+ - Added support for drop_table() in :doc:`Database Forge <database/forge>`.
+ - Added support for list_databases() in :doc:`Database Utilities <database/utilities>`.
+ - Generally improved for speed and cleaned up all of its components.
+ - num_rows() is now only called explicitly by the developer and no longer re-executes statements.
+ - Improved support of the SQLite driver, including:
+ - Added support for replace() in :doc:`Query Builder <database/query_builder>`.
+ - Added support for drop_table() in :doc:`Database Forge <database/forge>`.
- Added ODBC support for create_database(), drop_database() and drop_table() in :doc:`Database Forge <database/forge>`.
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`.
- - Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility <database/utilities>`.
- - Improved CUBRID support for list_databases() in :doc:`Database Utility <database/utilities>` (until now only the currently used database was returned).
+ - Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory).
+ - Added PDO support for ``list_fields()`` in :doc:`Database Results <database/results>`.
+ - Added capability for packages to hold database.php config files
+ - Added subdrivers support (currently only used by PDO).
+ - Added client compression support for MySQL and MySQLi.
+ - Removed :doc:`Loader Class <libraries/loader>` from Database error tracing to better find the likely culprit.
- Libraries
- - Added max_filename_increment config setting for Upload library.
- - CI_Loader::_ci_autoloader() is now a protected method.
- - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname).
- - Added possibility to send attachment as buffer string in Email::attach() as $this->email->attach($buffer, $disposition, $newname, $mime).
- - Cart library changes include:
+ - :doc:`Session Library <libraries/sessions>` changes include:
+ - Library changed to :doc:`Driver <general/drivers>` with classic Cookie driver as default.
+ - Added Native PHP Session driver to work with $_SESSION.
+ - Custom session drivers can be added anywhere in package paths and loaded with Session library.
+ - Session drivers interchangeable on the fly.
+ - New tempdata feature allows setting user data items with an expiration time.
+ - Added default $config['sess_driver'] and $config['sess_valid_drivers'] items to config.php file.
+ - Cookie driver now respects php.ini's session.gc_probability and session.gc_divisor
+ - Changed the Cookie driver to select only one row when using database sessions.
+ - Cookie driver now only writes to database at end of request when using database.
+ - Cookie driver now uses PHP functions for faster array manipulation when using database.
+ - Added ``all_flashdata()`` method to session class. Returns an associative array of only flashdata.
+ - Added ``has_userdata()`` method to verify existence of userdata item.
+ - Added ``tempdata()``, ``set_tempdata()``, and ``unset_tempdata()`` methods for manipulating tempdata.
+ - :doc:`File Uploading Library <libraries/file_uploading>` changes include:
+ - Added *max_filename_increment* config setting.
+ - Added an "index" parameter to the ``data()`` method.
+ - :doc:`Cart library <libraries/cart>` changes include:
- It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites.
- - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe"
- - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatability
+ - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe".
+ - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatibility.
- :doc:`Image Manipulation library <libraries/image_lib>` changes include:
- The initialize() method now only sets existing class properties.
- - Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them.
- - Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method
- if they are set manually after initialization.
- - 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 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.
+ - Property *maintain_ratio* is now taken into account when resizing images using ImageMagick library.
+ - Added support for maintaining transparency for PNG images in method ``text_watermark()``.
- :doc:`Form Validation library <libraries/form_validation>` changes include:
- Added method error_array() to return all error messages as an array.
- Added method set_data() to set an alternative data array to be validated instead of the default $_POST.
@@ -130,48 +186,82 @@ Release Date: Not Released
- _execute() now considers input data to be invalid if a specified rule is not found.
- Removed method is_numeric() as it exists as a native PHP function and _execute() will find and use that (the 'is_numeric' rule itself is deprecated since 1.6.1).
- Native PHP functions used as rules can now accept an additional parameter, other than the data itself.
- - Changed the :doc:`Session Library <libraries/sessions>` to select only one row when using database sessions.
- - Added all_flashdata() method to session class. Returns an associative array of only flashdata.
- - Allowed for setting table class defaults in a config file.
+ - Updated set_rules() to accept an array of rules as well as a string.
+ - Fields that have empty rules set no longer run through validation (and therefore are not considered erroneous).
+ - Added support for setting :doc:`Table <libraries/table>` class defaults in a config file.
- Added a Wincache driver to the :doc:`Caching Library <libraries/caching>`.
- - Added dsn (delivery status notification) option to the :doc:`Email Library <libraries/email>`.
+ - Added a Redis driver to the :doc:`Caching Library <libraries/caching>`.
+ - :doc:`Email library <libraries/email>` changes include:
+ - Added custom filename to ``Email::attach()`` as ``$this->email->attach($filename, $disposition, $newname)``.
+ - Added possibility to send attachment as buffer string in ``Email::attach()`` as ``$this->email->attach($buffer, $disposition, $newname, $mime)``.
+ - Added dsn (delivery status notification) option.
+ - Renamed method _set_header() to set_header() and made it public to enable adding custom headers in the :doc:`Email Library <libraries/email>`.
+ - Successfully sent emails will automatically clear the parameters.
+ - Added a *return_path* parameter to the ``from()`` method.
+ - :doc:`Pagination Library <libraries/pagination>` changes include:
+ - Added support for the anchor "rel" attribute.
+ - Added support for setting custom attributes.
+ - Deprecated usage of the "anchor_class" setting (use the new "attributes" setting instead).
+ - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments.
+ - Removed the default ``&nbsp;`` from a number of the configuration variables.
+ - Added the ability to use a proxy with the :doc:`XML-RPC Library <libraries/xmlrpc>`.
+ - :doc:`Encryption Library <libraries/encryption>` changes include:
+ - Added support for hashing algorithms other than SHA1 and MD5.
+ - Removed previously deprecated ``sha1()`` method.
- Core
- - Changed private functions in CI_URI to protected so MY_URI can override them.
- - Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
- - Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars().
- - is_loaded() function from system/core/Commons.php now returns a reference.
+ - Changed private methods in the :doc:`URI Library <libraries/uri>` to protected so MY_URI can override them.
+ - Removed ``CI_CORE`` boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
+ - :doc:`Loader Library <libraries/loader>` changes include:
+ - Added method get_vars() to the Loader to retrieve all variables loaded with $this->load->vars().
+ - CI_Loader::_ci_autoloader() is now a protected method.
+ - Added autoloading of drivers with $autoload['drivers'].
+ - CI_Loader::library() will now load drivers as well, for backward compatibility of converted libraries (like Session).
+ - ``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'].
+ - Added ``method()`` to the :doc:`Input Library <libraries/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).
+ - Added support for HTTP-Only cookies with new config option *cookie_httponly* (default FALSE).
- Renamed method _call_hook() to call_hook() in the :doc:`Hooks Library <general/hooks>`.
- - Added get_content_type() method to the :doc:`Output Library <libraries/output>`.
+ - :doc:`Output Library <libraries/output>` changes include:
+ - Added method ``get_content_type()``.
+ - Added a second argument to method ``set_content_type()`` that allows setting the document charset as well.
+ - Added ``get_mimes()`` function to *system/core/Commons.php* to return the *config/mimes.php* array.
+ - ``$config['time_reference']`` now supports all timezone strings supported by PHP.
+ - Added support for HTTP code 303 ("See Other") in ``set_status_header()``.
+ - Changed :doc:`Config Library <libraries/config>` method ``site_url()`` to accept an array as well.
+ - :doc:`Security Library <libraries/security>` changes include:
+ - Added method ``strip_image_tags()``.
+ - Added ``$config['csrf_regeneration']``, which makes token regeneration optional.
+ - Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run.
+ - Changed ``_exception_handler()`` to respect php.ini 'display_errors' setting.
+ - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()``.
+ - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the *proxy_ips* setting.
Bug fixes for 3.0
------------------
-- Unlink raised an error if cache file did not exist when you try to delete it.
+- Fixed a bug where ``unlink()`` raised an error if cache file did not exist when you try to delete it.
- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
-- Fixed a bug (#159, #163) that mishandled Active Record nested transactions because _trans_depth was not getting incremented.
-- Fixed a bug (#737, #75) where pagination anchor class was not set properly when using initialize method.
+- Fixed a bug (#159, #163) that mishandled Query Builder nested transactions because _trans_depth was not getting incremented.
+- Fixed a bug (#737, #75) - :doc:`Pagination <libraries/pagination>` anchor class was not set properly when using initialize method.
- Fixed a bug (#419) - auto_link() now recognizes URLs that come after a word boundary.
- Fixed a bug (#724) - is_unique in form validation now checks that you are connected to a database.
-- Fixed a bug (#647) - _get_mod_time() in Zip library no longer generates stat failed errors
-- Fixed a bug (#608) - Fixes an issue with the Image_lib class not clearing properties completely
-- Fixed bugs (#157 and #174) - the Image_lib clear() function now resets all variables to their default values.
+- Fixed a bug (#647) - _get_mod_time() in Zip library no longer generates stat failed errors.
+- Fixed a bug (#608) - Fixes an issue with the Image_lib class not clearing properties completely.
+- Fixed a bug (#157, #174) - the Image_lib clear() function now resets all variables to their default values.
- Fixed a bug where using $this->dbforge->create_table() with PostgreSQL database could lead to fetching whole table.
- Fixed a bug (#795) - Fixed form method and accept-charset when passing an empty array.
-- Fixed a bug (#797) - timespan was using incorrect seconds for year and month.
+- Fixed a bug (#797) - timespan() was using incorrect seconds for year and month.
- Fixed a bug in CI_Cart::contents() where if called without a TRUE (or equal) parameter, it would fail due to a typo.
-- Fixed a bug (#696) - make oci_execute calls inside num_rows non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed.
-- Fixed a bug (#406) - sqlsrv DB driver not reuturning resource on <samp>db_pconnect()</samp>.
+- Fixed a bug (#696) - make oci_execute() calls inside num_rows() non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed.
+- Fixed a bug (#406) - SQLSRV DB driver not returning resource on ``db_pconnect()``.
- Fixed a bug in CI_Image_lib::gd_loaded() where it was possible for the script execution to end or a PHP E_WARNING message to be emitted.
-- In Pagination library, when use_page_numbers=TRUE previous link and page 1 link do not have the same url
+- Fixed a bug in the :doc:`Pagination library <libraries/pagination>` where when use_page_numbers=TRUE previous link and page 1 link did not have the same url.
- Fixed a bug (#561) - Errors in :doc:`XML-RPC Library <libraries/xmlrpc>` were not properly escaped.
- Fixed a bug (#904) - ``CI_Loader::initialize()`` caused a PHP Fatal error to be triggered if error level E_STRICT is used.
-- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
+- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'.
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
- Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped.
@@ -182,7 +272,7 @@ Bug fixes for 3.0
- Fixed a bug (#129) - ODBC's num_rows() returned -1 in some cases, due to not all subdrivers supporting the odbc_num_rows() function.
- Fixed a bug (#153) - E_NOTICE being generated by getimagesize() in the :doc:`File Uploading Library <libraries/file_uploading>`.
- Fixed a bug (#611) - SQLSRV's error handling methods used to issue warnings when there's no actual error.
-- Fixed a bug (#1036) - is_write_type() method in the :doc:`Database Library <database/index>` didn't return TRUE for RENAME and OPTIMIZE queries.
+- Fixed a bug (#1036) - ``is_write_type()`` method in the :doc:`Database Library <database/index>` didn't return TRUE for RENAME queries.
- Fixed a bug in PDO's _version() method where it used to return the client version as opposed to the server one.
- Fixed a bug in PDO's insert_id() method where it could've failed if it's used with Postgre versions prior to 8.1.
- Fixed a bug in CUBRID's affected_rows() method where a connection resource was passed to cubrid_affected_rows() instead of a result.
@@ -195,18 +285,18 @@ Bug fixes for 3.0
- Fixed a bug (#499) - a CSRF cookie was created even with CSRF protection being disabled.
- Fixed a bug (#306) - ODBC's insert_id() method was calling non-existent function odbc_insert_id(), which resulted in a fatal error.
- Fixed a bug in Oracle's DB_result class where the cursor id passed to it was always NULL.
-- Fixed a bug (#64) - Regular expression in DB_active_rec.php failed to handle queries containing SQL bracket delimiters in the join condition.
+- Fixed a bug (#64) - Regular expression in DB_query_builder.php failed to handle queries containing SQL bracket delimiters in the join condition.
- Fixed a bug in the :doc:`Session Library <libraries/sessions>` where a PHP E_NOTICE error was triggered by _unserialize() due to results from databases such as MSSQL and Oracle being space-padded on the right.
- Fixed a bug (#501) - set_rules() to check if the request method is not 'POST' before aborting, instead of depending on count($_POST) in the :doc:`Form Validation Library <libraries/form_validation>`.
- Fixed a bug (#940) - csrf_verify() used to set the CSRF cookie while processing a POST request with no actual POST data, which resulted in validating a request that should be considered invalid.
-- Fixed a bug in PostgreSQL's escape_str() where it didn't properly escape LIKE wild characters.
+- Fixed a bug (#136) - PostgreSQL, MySQL and MySQLi's escape_str() method didn't properly escape LIKE wild characters.
- Fixed a bug in the library loader where some PHP versions wouldn't execute the class constructor.
- Fixed a bug (#88) - An unexisting property was used for configuration of the Memcache cache driver.
- Fixed a bug (#14) - create_database() method in the :doc:`Database Forge Library <database/forge>` didn't utilize the configured database character set.
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library <database/caching>` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library <libraries/trackback>` method validate_url() where it didn't actually do anything, due to input not being passed by reference.
- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found.
-- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories
+- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories.
- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library <libraries/zip>` wasn't compatible with Windows.
- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it.
- Fixed a bug in MSSQL and SQLSrv's _truncate() where the TABLE keyword was missing.
@@ -216,32 +306,94 @@ Bug fixes for 3.0
- Fixed a bug in SQLSRV's delete() method where like() and limit() conditions were ignored.
- Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
- Fixed a bug (#128) - :doc:`Language Library <libraries/language>` did not correctly keep track of loaded language files.
-- Fixed a bug (#1242) - Added Windows path compatibility to function read_dir of ZIP library
+- Fixed a bug (#1242) - Added Windows path compatibility to function read_dir of ZIP library.
- Fixed a bug (#1314) - sess_destroy() did not destroy userdata.
-- Fixed a bug (#1349) - get_extension() in the `File Uploading Library <libraries/file_uploading>` returned the original filename when it didn't have an actual extension.
+- Fixed a bug (#1349) - get_extension() in the :doc:`File Uploading Library <libraries/file_uploading>` returned the original filename when it didn't have an actual extension.
+- Fixed a bug (#1273) - E_NOTICE being generated by :doc:`Query Builder <database/query_builder>`'s set_update_batch() method.
+- Fixed a bug (#44, #110) - :doc:`Upload library <libraries/file_uploading>`'s clean_file_name() method didn't clear '!' and '#' characters.
+- Fixed a bug (#121) - ``CI_DB_result::row()`` returned an array when there's no actual result to be returned.
+- Fixed a bug (#319) - SQLSRV's affected_rows() method failed due to a scrollable cursor being created for write-type queries.
+- Fixed a bug (#356) - PostgreSQL driver didn't have an _update_batch() method, which resulted in fatal error being triggered when update_batch() is used with it.
+- Fixed a bug (#784, #862) - :doc:`Database Forge <database/forge>` method ``create_table()`` failed on SQLSRV/MSSQL when used with 'IF NOT EXISTS'.
+- Fixed a bug (#1419) - libraries/Driver.php had a static variable that was causing an error.
+- Fixed a bug (#1411) - the :doc:`Email library <libraries/email>` used its own short list of MIMEs instead the one from config/mimes.php.
+- Fixed a bug where the magic_quotes_runtime setting wasn't turned off for PHP 5.3 (where it is indeed deprecated, but not non-existent).
+- Fixed a bug (#666) - :doc:`Output library <libraries/output>`'s set_content_type() method didn't set the document charset.
+- Fixed a bug (#784, #861) - :doc:`Database Forge <database/forge>` method ``create_table()`` used to accept constraints for MSSQL/SQLSRV integer-type columns.
+- Fixed a bug (#706) - SQLSRV/MSSSQL didn't escape field names.
+- Fixed a bug (#1452) - ``protect_identifiers()`` didn't properly detect identifiers with spaces in their names.
+- Fixed a bug where ``protect_identifiers()`` ignored it's extra arguments when the value passed to it is an array.
+- Fixed a bug where ``_has_operator()`` didn't detect BETWEEN.
+- Fixed a bug in :doc:`Query Builder <database/query_builder>`'s ``join()`` method where it failed with identifiers containing dashes.
+- Fixed a bug (#1264) - :doc:`Database Forge <database/forge>` and :doc:`Database Utilities <database/utilities>` didn't update/reset the databases and tables list cache when a table or a database is created, dropped or renamed.
+- Fixed a bug (#7) - :doc:`Query Builder <database/query_builder>`'s ``join()`` method only escaped one set of conditions.
+- Fixed a bug (#1321) - Core Exceptions class couldn't find the errors/ folder in some cases.
+- Fixed a bug in the File-based :doc:`Cache Library <libraries/caching>` driver's get_metadata() method where a non-existent array key was accessed for the TTL value.
+- Fixed a bug (#1202) - :doc:`Encryption Library <libraries/encryption>` encode_from_legacy() didn't set back the encrypt mode on failure.
+- Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query.
+- Fixed a bug in protect_identifiers() where if passed along with the field names, operators got escaped as well.
+- Fixed a bug (#10) - :doc:`URI Library <libraries/uri>` internal method _detect_uri() failed with paths containing a colon.
+- Fixed a bug (#1387) - :doc:`Query Builder <database/query_builder>`'s from() method didn't escape table aliases.
+- Fixed a bug (#520) - :doc:`Date Helper <helpers/date_helper>` function nice_date() failed when the optional second parameter is not passed.
+- Fixed a bug (#167) - ``$config['permitted_uri_chars']`` didn't affect URL-encoded characters.
+- Fixed a bug (#318) - :doc:`Profiling <general/profiling>` setting *query_toggle_count* was not settable as described in the manual.
+- Fixed a bug (#938) - :doc:`Config Library <libraries/config>` method site_url() added a question mark to the URL string when query strings are enabled even if it already existed.
+- Fixed a bug (#999) - :doc:`Config Library <libraries/config>` method site_url() always appended ``$config['url_suffix']`` to the end of the URL string, regardless of wether a query string exists in it.
+- Fixed a bug where :doc:`URL Helper <helpers/url_helper>` function anchor_popup() ignored the attributes argument if it is not an array.
+- Fixed a bug (#1328) - :doc:`Form Validation Library <libraries/form_validation>` didn't properly check the type of the form fields before processing them.
+- Fixed a bug (#79) - :doc:`Form Validation Library <libraries/form_validation>` didn't properly validate array fields that use associative keys or have custom indexes.
+- Fixed a bug (#427) - :doc:`Form Validation Library <libraries/form_validation>` method ``strip_image_tags()`` was an alias to a non-existent method.
+- Fixed a bug (#1545) - :doc:`Query Builder <database/query_builder>` method ``limit()`` wasn't executed properly under Oracle.
+- Fixed a bug (#1551) - :doc:`Date Helper <helpers/date_helper>` function ``standard_date()`` didn't properly format *W3C* and *ATOM* standard dates.
+- Fixed a bug in :doc:`Query Builder <database/query_builder>` method join() where literal values were escaped as if they were fields.
+- Fixed a bug (#135) - PHP Error logging was impossible without the errors being displayed.
+- Fixed a bug (#1613) - :doc:`Form Helper <helpers/form_helper>` functions ``form_multiselect()``, ``form_dropdown()`` didn't properly handle empty array option groups.
+- Fixed a bug (#1605) - :doc:`Pagination Library <libraries/pagination>` produced incorrect *previous* and *next* link values.
+- Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used.
+- Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application.
+- Fixed a bug (#1757) - :doc:`Directory Helper <helpers/directory_helper>` function ``directory_map()`` was skipping files and directories named *0*.
+- Fixed a bug (#1789) - :doc:`Database Library <database/index>` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL.
+- Fixed a bug (#395) - :doc:`Unit Testing Library <libraries/unit_testing>` method ``result()`` didn't properly check array result columns when called from ``report()``.
+- Fixed a bug (#1692) - :doc:`Database Library <database/index>` method ``display_error()`` didn't properly trace the possible error source on Windows systems.
+- Fixed a bug (#1745) - ``is_write_type()`` method in the :doc:`Database Library <database/index>` didn't return TRUE for LOAD queries.
+- Fixed a bug (#1765) - :doc:`Database Library <database/index>` didn't properly detect connection errors for MySQLi.
+
+Version 2.1.2
+=============
+
+Release Date: June 29, 2012
+
+- General Changes
+ - Improved security in ``xss_clean()``.
Version 2.1.1
=============
-Release Date: Not Released
+Release Date: June 12, 2012
- 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>`.
+ - Added support for IPv6 to the :doc:`Input Library <libraries/input>`.
+ - Added support for the IP format parameter to the :doc:`Form Validation Library <libraries/form_validation>`.
- Helpers
- - url_title() performance and output improved. You can now use any string as the word delimiter, but 'dash' and 'underscore' are still supported.
+ - ``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 (#697) - A wrong array key was used in the :doc:`File Uploading Library <libraries/file_uploading>` 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
+- Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
+- Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
+- Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite.
+- Fixed a bug - ``CI_DB_pdo_driver::num_rows()`` was not returning properly value with SELECT queries, cause it was relying on ``PDOStatement::rowCount()``.
+- Fixed a bug (#1059) - ``CI_Image_lib::clear()`` was not correctly clearing all necessary object properties, namely width and height.
Version 2.1.0
=============
@@ -277,7 +429,7 @@ Release Date: November 14, 2011
injection.
- Added additional option 'none' for the optional third argument for
$this->db->like() in the :doc:`Database
- Driver <database/active_record>`.
+ Driver <database/query_builder>`.
- Added $this->db->insert_batch() support to the OCI8 (Oracle) driver.
- Added failover if the main connections in the config should fail
@@ -375,7 +527,6 @@ Release Date: August 20, 2011
- Added insert_batch() function to the PostgreSQL database driver.
Thanks to epallerols for the patch.
- Added "application/x-csv" to mimes.php.
- - Added CSRF protection URI whitelisting.
- Fixed a bug where :doc:`Email library <libraries/email>`
attachments with a "." in the name would using invalid MIME-types.
@@ -1552,27 +1703,27 @@ Release Date: January 30, 2008
- Active Record
- Added protect_identifiers() in :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- All AR queries are backticked if appropriate to the database.
- Added where_in(), or_where_in(), where_not_in(),
or_where_not_in(), not_like() and or_not_like() to :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- Added support for limit() into update() and delete() statements in
- :doc:`Active Record <./database/active_record>`.
+ :doc:`Active Record <./database/query_builder>`.
- Added empty_table() and truncate_table() to :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- Added the ability to pass an array of tables to the delete()
- statement in :doc:`Active Record <./database/active_record>`.
+ statement in :doc:`Active Record <./database/query_builder>`.
- Added count_all_results() function to :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- Added select_max(), select_min(), select_avg() and
- select_sum() to :doc:`Active Record <./database/active_record>`.
+ select_sum() to :doc:`Active Record <./database/query_builder>`.
- Added the ability to use aliases with joins in :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- Added a third parameter to Active Record's like() clause to
control where the wildcard goes.
- Added a third parameter to set() in :doc:`Active
- Record <./database/active_record>` that withholds escaping
+ Record <./database/query_builder>` that withholds escaping
data.
- Changed the behaviour of variables submitted to the where() clause
with no values to auto set "IS NULL"
@@ -1680,7 +1831,7 @@ Release Date: January 30, 2008
the table of contents of the userguide.
- Moved part of the userguide menu javascript to an external file.
- Documented distinct() in :doc:`Active
- Record <./database/active_record>`.
+ Record <./database/query_builder>`.
- Documented the timezones() function in the :doc:`Date
Helper <./helpers/date_helper>`.
- Documented unset_userdata in the :doc:`Session
@@ -2256,9 +2407,9 @@ Release Date: April 11, 2006
function <./general/views>`: $this->load->view('my_view',
$object);
- Added getwhere function to :doc:`Active Record
- class <./database/active_record>`.
+ class <./database/query_builder>`.
- Added count_all function to :doc:`Active Record
- class <./database/active_record>`.
+ class <./database/query_builder>`.
- Added language file for scaffolding and fixed a scaffolding bug that
occurs when there are no rows in the specified table.
- Added :doc:`$this->db->last_query() <./database/queries>`, which
@@ -2283,7 +2434,7 @@ Release Date: April 3, 2006
- Added support for :doc:`Models <general/models>`.
- Redesigned the database libraries to support additional RDBMs
(Postgres, MySQLi, etc.).
-- Redesigned the :doc:`Active Record class <./database/active_record>`
+- Redesigned the :doc:`Active Record class <./database/query_builder>`
to enable more varied types of queries with simpler syntax, and
advanced features like JOINs.
- Added a feature to the database class that lets you run :doc:`custom
@@ -2316,7 +2467,7 @@ Release Date: April 3, 2006
whether PHP 4 or 5 is being run, since PHP 5 allows a more graceful
way to manage objects that utilizes a bit less resources.
- Deprecated: $this->db->use_table() has been deprecated. Please read
- the :doc:`Active Record <./database/active_record>` page for
+ the :doc:`Active Record <./database/query_builder>` page for
information.
- Deprecated: $this->db->smart_escape_str() has been deprecated.
Please use this instead: $this->db->escape()
diff --git a/user_guide_src/source/conf.py b/user_guide_src/source/conf.py
index e972a388b..f68405b36 100644
--- a/user_guide_src/source/conf.py
+++ b/user_guide_src/source/conf.py
@@ -167,6 +167,7 @@ html_last_updated_fmt = '%b %d, %Y'
# Output file base name for HTML help builder.
htmlhelp_basename = 'CodeIgniterdoc'
+html_copy_source = False
# -- Options for LaTeX output --------------------------------------------------
diff --git a/user_guide_src/source/contributing/index.rst b/user_guide_src/source/contributing/index.rst
new file mode 100644
index 000000000..2ede0e6e5
--- /dev/null
+++ b/user_guide_src/source/contributing/index.rst
@@ -0,0 +1,105 @@
+###########################
+Contributing to CodeIgniter
+###########################
+
+CodeIgniter is a community driven project and accepts contributions of code
+and documentation from the community. These contributions are made in the form
+of Issues or `Pull Requests <http://help.github.com/send-pull-requests/>`_ on
+the `EllisLab CodeIgniter repository
+<https://github.com/EllisLab/CodeIgniter>`_ on GitHub.
+
+Issues are a quick way to point out a bug. If you find a bug or documentation
+error in CodeIgniter then please check a few things first:
+
+- There is not already an open Issue
+- The issue has already been fixed (check the develop branch, or look for
+ closed Issues)
+- Is it something really obvious that you fix it yourself?
+
+Reporting issues is helpful but an even better approach is to send a Pull
+Request, which is done by "Forking" the main repository and committing to your
+own copy. This will require you to use the version control system called Git.
+
+**********
+Guidelines
+**********
+
+Before we look into how, here are the guidelines. If your Pull Requests fail
+to pass these guidelines it will be declined and you will need to re-submit
+when you’ve made the changes. This might sound a bit tough, but it is required
+for us to maintain quality of the code-base.
+
+PHP Style
+=========
+
+All code must meet the `Style Guide
+<http://codeigniter.com/user_guide/general/styleguide.html>`_, which is
+essentially the `Allman indent style
+<http://en.wikipedia.org/wiki/Indent_style#Allman_style>`_, underscores and
+readable operators. This makes certain that all code is the same format as the
+existing code and means it will be as readable as possible.
+
+Documentation
+=============
+
+If you change anything that requires a change to documentation then you will
+need to add it. New classes, methods, parameters, changing default values, etc
+are all things that will require a change to documentation. The change-log
+must also be updated for every change. Also PHPDoc blocks must be maintained.
+
+Compatibility
+=============
+
+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
+=========
+
+CodeIgniter uses the `Git-Flow
+<http://nvie.com/posts/a-successful-git-branching-model/>`_ branching model
+which requires all pull requests to be sent to the "develop" branch. This is
+where the next planned version will be developed. The "master" branch will
+always contain the latest stable version and is kept clean so a "hotfix" (e.g:
+an emergency security patch) can be applied to master to create a new version,
+without worrying about other features holding it up. For this reason all
+commits need to be made to "develop" and any sent to "master" will be closed
+automatically. If you have multiple changes to submit, please place all
+changes into their own branch on your fork.
+
+One thing at a time: A pull request should only contain one change. That does
+not mean only one commit, but one change - however many commits it took. The
+reason for this is that if you change X and Y but send a pull request for both
+at the same time, we might really want X but disagree with Y, meaning we
+cannot merge the request. Using the Git-Flow branching model you can create
+new branches for both of these features and send two requests.
+
+Signing
+=======
+You must sign your work, certifying that you either wrote the work or
+otherwise have the right to pass it on to an open source project. git makes
+this trivial as you merely have to use `--signoff` on your commits to your
+CodeIgniter fork.
+
+.. code-block:: bash
+
+ git commit --signoff
+
+or simply
+
+.. code-block:: bash
+
+ git commit -s
+
+This will sign your commits with the information setup in your git config, e.g.
+
+ Signed-off-by: John Q Public <john.public@example.com>
+
+If you are using Tower there is a "Sign-Off" checkbox in the commit window. You
+could even alias git commit to use the -s flag so you don’t have to think about
+it.
+
+By signing your work in this manner, you certify to a "Developer's Certificate
+or Origin". The current version of this certificate is in the :doc:`/DCO` file
+in the root of this documentation.
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 7a19c840f..636b5b5b2 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -12,26 +12,45 @@ it the respective environment config folder.
The config settings are stored in a multi-dimensional array with this
prototype::
- $db['default']['hostname'] = "localhost";
- $db['default']['username'] = "root";
- $db['default']['password'] = "";
- $db['default']['database'] = "database_name";
- $db['default']['dbdriver'] = "mysql";
- $db['default']['dbprefix'] = "";
- $db['default']['pconnect'] = TRUE;
- $db['default']['db_debug'] = FALSE;
- $db['default']['cache_on'] = FALSE;
- $db['default']['cachedir'] = "";
- $db['default']['char_set'] = "utf8";
- $db['default']['dbcollat'] = "utf8_general_ci";
- $db['default']['swap_pre'] = "";
- $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'] = array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'root',
+ 'password' => '',
+ 'database' => 'database_name',
+ 'dbdriver' => 'mysqli',
+ 'dbprefix' => '',
+ 'pconnect' => TRUE,
+ 'db_debug' => TRUE,
+ 'cache_on' => FALSE,
+ 'cachedir' => '',
+ 'char_set' => 'utf8',
+ 'dbcollat' => 'utf8_general_ci',
+ 'swap_pre' => '',
+ 'autoinit' => TRUE,
+ 'compress' => TRUE,
+ 'stricton' => FALSE,
+ 'failover' => array()
+ );
+
+Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might
+require a full DSN string to be provided. If that is the case, you
+should use the 'dsn' configuration setting, as if you're using the
+driver's underlying native PHP extension, like this::
+
+ // PDO
$db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
+ // Oracle
+ $db['default']['dsn'] = '//localhost/XE';
+
+.. note:: If you do not specify a DSN string for a driver that requires it, CodeIgniter
+ will try to build it with the rest of the provided settings.
+
+.. note:: If you provide a DSN string and it is missing some valid settings (e.g. the
+ database character set), which are present in the rest of the configuration
+ fields, CodeIgniter will append them.
+
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::
@@ -41,7 +60,7 @@ These failovers can be specified by setting the failover for a connection like t
'username' => '',
'password' => '',
'database' => '',
- 'dbdriver' => 'mysql',
+ 'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
@@ -51,6 +70,7 @@ These failovers can be specified by setting the failover for a connection like t
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
+ 'compress' => TRUE,
'stricton' => FALSE
),
array(
@@ -58,7 +78,7 @@ These failovers can be specified by setting the failover for a connection like t
'username' => '',
'password' => '',
'database' => '',
- 'dbdriver' => 'mysql',
+ 'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
@@ -68,6 +88,7 @@ These failovers can be specified by setting the failover for a connection like t
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
+ 'compress' => TRUE,
'stricton' => FALSE
)
);
@@ -81,30 +102,35 @@ production, test, etc.) under a single installation, you can set up a
connection group for each, then switch between groups as needed. For
example, to set up a "test" environment you would do this::
- $db['test']['hostname'] = "localhost";
- $db['test']['username'] = "root";
- $db['test']['password'] = "";
- $db['test']['database'] = "database_name";
- $db['test']['dbdriver'] = "mysql";
- $db['test']['dbprefix'] = "";
- $db['test']['pconnect'] = TRUE;
- $db['test']['db_debug'] = FALSE;
- $db['test']['cache_on'] = FALSE;
- $db['test']['cachedir'] = "";
- $db['test']['char_set'] = "utf8";
- $db['test']['dbcollat'] = "utf8_general_ci";
- $db['test']['swap_pre'] = "";
- $db['test']['autoinit'] = TRUE;
- $db['test']['stricton'] = FALSE;
+ $db['test'] = array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'root',
+ 'password' => '',
+ 'database' => 'database_name',
+ 'dbdriver' => 'mysqli',
+ 'dbprefix' => '',
+ 'pconnect' => TRUE,
+ 'db_debug' => TRUE,
+ 'cache_on' => FALSE,
+ 'cachedir' => '',
+ 'char_set' => 'utf8',
+ 'dbcollat' => 'utf8_general_ci',
+ 'swap_pre' => '',
+ 'autoinit' => TRUE,
+ 'compress' => TRUE,
+ 'stricton' => FALSE,
+ 'failover' => array()
+ );
Then, to globally tell the system to use that group you would set this
variable located in the config file::
- $active_group = "test";
+ $active_group = 'test';
-Note: The name "test" is arbitrary. It can be anything you want. By
-default we've used the word "default" for the primary connection, but it
-too can be renamed to something more relevant to your project.
+.. note:: The name 'test' is arbitrary. It can be anything you want. By
+ default we've used the word "default" for the primary connection,
+ but it too can be renamed to something more relevant to your project.
Query Builder
-------------
@@ -119,8 +145,8 @@ when the database classes are initialized.
$query_builder = TRUE;
-.. note:: that some CodeIgniter classes such as Sessions require Active
- Records be enabled to access certain functionality.
+.. note:: that some CodeIgniter classes such as Sessions require Query
+ Builder to be enabled to access certain functionality.
Explanation of Values:
----------------------
@@ -128,11 +154,12 @@ Explanation of Values:
====================== ==================================================================================================
Name Config Description
====================== ==================================================================================================
-**hostname** The hostname of your database server. Often this is "localhost".
+**dsn** The DSN connect string (an all-in-one configuration sequence).
+**hostname** The hostname of your database server. Often this is 'localhost'.
**username** The username used to connect to the database.
**password** The password used to connect to the database.
**database** The name of the database you want to connect to.
-**dbdriver** The database type. ie: mysql, postgre, odbc, etc. Must be specified in lower case.
+**dbdriver** The database type. ie: mysqli, postgre, odbc, etc. Must be specified in lower case.
**dbprefix** An optional table prefix which will added to the table name when running :doc:
`Query Builder <query_builder>` queries. This permits multiple CodeIgniter installations
to share one database.
@@ -144,30 +171,24 @@ Explanation of Values:
**char_set** The character set used in communicating with the database.
**dbcollat** The character collation used in communicating with the database
- .. note:: For MySQL and MySQLi databases, this setting is only used
- as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
- (and in table creation queries made with DB Forge). There is an
- incompatibility in PHP with mysql_real_escape_string() which can
- make your site vulnerable to SQL injection if you are using a
- multi-byte character set and are running versions lower than these.
- Sites using Latin-1 or UTF-8 database character set and collation are
- unaffected.
+ .. note:: Only used in the 'mysql' and 'mysqli' drivers.
**swap_pre** A default table prefix that should be swapped with dbprefix. This is useful for distributed
applications where you might run manually written queries, and need the prefix to still be
customizable by the end user.
**autoinit** Whether or not to automatically connect to the database when the library loads. If set to false,
the connection will take place prior to executing the first query.
+**compress** Whether or not to use client compression for MySQL or MySQLi.
**stricton** TRUE/FALSE (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL
while developing an application.
**port** The database port number. To use this value you have to add a line to the database config array.
::
-
- $db['default']['port'] = 5432;
+
+ $db['default']['port'] = 5432;
====================== ==================================================================================================
.. note:: Depending on what database platform you are using (MySQL, PostgreSQL,
etc.) not all values will be needed. For example, when using SQLite you
will not need to supply a username or password, and the database name
will be the path to your database file. The information above assumes
- you are using MySQL.
+ you are using MySQL. \ No newline at end of file
diff --git a/user_guide_src/source/database/connecting.rst b/user_guide_src/source/database/connecting.rst
index 5822ca62c..9b8117076 100644
--- a/user_guide_src/source/database/connecting.rst
+++ b/user_guide_src/source/database/connecting.rst
@@ -57,25 +57,28 @@ file.
To connect manually to a desired database you can pass an array of
values::
- $config['hostname'] = "localhost";
- $config['username'] = "myusername";
- $config['password'] = "mypassword";
- $config['database'] = "mydatabase";
- $config['dbdriver'] = "mysql";
- $config['dbprefix'] = "";
- $config['pconnect'] = FALSE;
- $config['db_debug'] = TRUE;
- $config['cache_on'] = FALSE;
- $config['cachedir'] = "";
- $config['char_set'] = "utf8";
- $config['dbcollat'] = "utf8_general_ci";
+ $config['hostname'] = 'localhost';
+ $config['username'] = 'myusername';
+ $config['password'] = 'mypassword';
+ $config['database'] = 'mydatabase';
+ $config['dbdriver'] = 'mysqli';
+ $config['dbprefix'] = '';
+ $config['pconnect'] = FALSE;
+ $config['db_debug'] = TRUE;
+ $config['cache_on'] = FALSE;
+ $config['cachedir'] = '';
+ $config['char_set'] = 'utf8';
+ $config['dbcollat'] = 'utf8_general_ci';
$this->load->database($config);
For information on each of these values please see the :doc:`configuration
page <configuration>`.
-.. note:: For the PDO driver, $config['hostname'] should look like
- this: 'mysql:host=localhost'
+.. note:: For the PDO driver, you should use the $config['dsn'] setting
+ instead of 'hostname' and 'database':
+
+ |
+ | $config['dsn'] = 'mysql:host=localhost;dbname=mydatabase';
Or you can submit your database values as a Data Source Name. DSNs must
have this prototype::
@@ -149,5 +152,4 @@ connections, you can explicitly close the connection.
::
- $this->db->close();
-
+ $this->db->close(); \ No newline at end of file
diff --git a/user_guide_src/source/database/queries.rst b/user_guide_src/source/database/queries.rst
index d23efecb3..11dd78392 100644
--- a/user_guide_src/source/database/queries.rst
+++ b/user_guide_src/source/database/queries.rst
@@ -21,11 +21,31 @@ this::
$this->db->simple_query();
===========================
-This is a simplified version of the $this->db->query() function. It ONLY
-returns TRUE/FALSE on success or failure. It DOES NOT return a database
-result set, nor does it set the query timer, or compile bind data, or
-store your query for debugging. It simply lets you submit a query. Most
-users will rarely use this function.
+This is a simplified version of the $this->db->query() method. It DOES
+NOT return a database result set, nor does it set the query timer, or
+compile bind data, or store your query for debugging. It simply lets you
+submit a query. Most users will rarely use this function.
+
+It returns whatever the database drivers' "execute" function returns.
+That typically is TRUE/FALSE on success or failure for write type queries
+such as INSERT, DELETE or UPDATE statements (which is what it really
+should be used for) and a resource/object on success for queries with
+fetchable results.
+
+::
+
+ if ($this->db->simple_query('YOUR QUERY'))
+ {
+ echo "Success!";
+ }
+ else
+ {
+ echo "Query failed!";
+ }
+
+.. note:: PostgreSQL's pg_exec() function always returns a resource on
+ success, even for write type queries. So take that in mind if
+ you're looking for a boolean value.
***************************************
Working with Database prefixes manually
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 54e8df6b5..b86a0c8db 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -603,9 +603,9 @@ Here is an example using an object::
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ public $title = 'My Title';
+ public $content = 'My Content';
+ public $date = 'My Date';
}
*/
@@ -730,9 +730,9 @@ Or an object::
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ public $title = 'My Title';
+ public $content = 'My Content';
+ public $date = 'My Date';
}
*/
@@ -766,9 +766,9 @@ Or you can supply an object::
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ public $title = 'My Title';
+ public $content = 'My Content';
+ public $date = 'My Date';
}
*/
diff --git a/user_guide_src/source/database/results.rst b/user_guide_src/source/database/results.rst
index 865345762..d032f734e 100644
--- a/user_guide_src/source/database/results.rst
+++ b/user_guide_src/source/database/results.rst
@@ -136,6 +136,26 @@ parameter:
| **$row = $query->next_row('array')**
| **$row = $query->previous_row('array')**
+.. note:: all the functions above will load the whole result into memory (prefetching) use unbuffered_row() for processing large result sets.
+
+unbuffered_row($type)
+=====================
+
+This function returns a single result row without prefetching the whole result in memory as row() does.
+If your query has more than one row, it returns the current row and moves the internal data pointer ahead.
+The result is returned as $type could be 'object' (default) or 'array' that will return an associative array.
+
+::
+
+ $query = $this->db->query("YOUR QUERY");
+
+ while ($row = $query->unbuffered_row())
+ {
+ echo $row->title;
+ echo $row->name;
+ echo $row->body;
+ }
+
***********************
Result Helper Functions
***********************
diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst
index 70563b8d2..99126f900 100644
--- a/user_guide_src/source/general/common_functions.rst
+++ b/user_guide_src/source/general/common_functions.rst
@@ -79,3 +79,8 @@ html_escape($mixed)
This function provides short cut for htmlspecialchars() function. It
accepts string and array. To prevent Cross Site Scripting (XSS), it is
very useful.
+
+get_mimes()
+=============
+
+This function returns the MIMEs array from config/mimes.php. \ No newline at end of file
diff --git a/user_guide_src/source/general/core_classes.rst b/user_guide_src/source/general/core_classes.rst
index ac41407f7..4aa6693f7 100644
--- a/user_guide_src/source/general/core_classes.rst
+++ b/user_guide_src/source/general/core_classes.rst
@@ -31,6 +31,7 @@ time CodeIgniter runs:
- Log
- Output
- Router
+- Security
- URI
- Utf8
diff --git a/user_guide_src/source/general/environments.rst b/user_guide_src/source/general/environments.rst
index 40725feba..fa1b096e2 100644
--- a/user_guide_src/source/general/environments.rst
+++ b/user_guide_src/source/general/environments.rst
@@ -11,10 +11,16 @@ when "live".
The ENVIRONMENT Constant
========================
-By default, CodeIgniter comes with the environment constant set to
+By default, CodeIgniter comes with the environment constant set to use
+the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to
'development'. At the top of index.php, you will see::
- define('ENVIRONMENT', 'development');
+ define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
+
+This server variable can be set in your .htaccess file, or Apache
+config using `SetEnv <https://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv>`_.
+Alternative methods are available for nginx and other servers, or you can
+remove this logic entirely and set the constant based on the HTTP_HOST or IP.
In addition to affecting some basic framework behavior (see the next
section), you may use this constant in your own development to
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index 0156b0460..4e52a9648 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -16,11 +16,11 @@ blog. You might have a model class that contains functions to insert,
update, and retrieve your blog data. Here is an example of what such a
model class might look like::
- class Blogmodel extends CI_Model {
+ class Blog_model extends CI_Model {
- var $title = '';
- var $content = '';
- var $date = '';
+ public $title = '';
+ public $content = '';
+ public $date = '';
function __construct()
{
@@ -72,10 +72,11 @@ The basic prototype for a model class is this::
class Model_name extends CI_Model {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
}
Where **Model_name** is the name of your class. Class names **must** have
@@ -87,10 +88,11 @@ example, if your class is this::
class User_model extends CI_Model {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
}
Your file will be this::
@@ -102,9 +104,9 @@ Loading a Model
Your models will typically be loaded and called from within your
:doc:`controller <controllers>` functions. To load a model you will use
-the following function::
+the following method::
- $this->load->model('Model_name');
+ $this->load->model('model_name');
If your model is located in a sub-folder, include the relative path from
your models folder. For example, if you have a model located at
@@ -112,33 +114,34 @@ application/models/blog/queries.php you'll load it using::
$this->load->model('blog/queries');
-Once loaded, you will access your model functions using an object with
-the same name as your class::
+Once loaded, you will access your model methods using an object with the
+same name as your class::
- $this->load->model('Model_name');
+ $this->load->model('model_name');
- $this->Model_name->function();
+ $this->model_name->method();
If you would like your model assigned to a different object name you can
-specify it via the second parameter of the loading function::
+specify it via the second parameter of the loading method::
- $this->load->model('Model_name', 'fubar');
+ $this->load->model('model_name', 'foobar');
- $this->fubar->function();
+ $this->foobar->method();
Here is an example of a controller, that loads a model, then serves a
view::
class Blog_controller extends CI_Controller {
- function blog()
- {
- $this->load->model('Blog');
+ public function blog()
+ {
+ $this->load->model('blog');
- $data['query'] = $this->Blog->get_last_ten_entries();
+ $data['query'] = $this->Blog->get_last_ten_entries();
+
+ $this->load->view('blog', $data);
+ }
- $this->load->view('blog', $data);
- }
}
@@ -165,20 +168,18 @@ database. The following options for connecting are available to you:
defined in your database config file will be used:
::
- $this->load->model('Model_name', '', TRUE);
+ $this->load->model('model_name', '', TRUE);
- You can manually pass database connectivity settings via the third
parameter::
- $config['hostname'] = "localhost";
- $config['username'] = "myusername";
- $config['password'] = "mypassword";
- $config['database'] = "mydatabase";
- $config['dbdriver'] = "mysql";
- $config['dbprefix'] = "";
+ $config['hostname'] = 'localhost';
+ $config['username'] = 'myusername';
+ $config['password'] = 'mypassword';
+ $config['database'] = 'mydatabase';
+ $config['dbdriver'] = 'mysqli';
+ $config['dbprefix'] = '';
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
- $this->load->model('Model_name', '', $config);
-
-
+ $this->load->model('Model_name', '', $config); \ No newline at end of file
diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst
index d97b7b4b2..d9edfba6d 100644
--- a/user_guide_src/source/general/requirements.rst
+++ b/user_guide_src/source/general/requirements.rst
@@ -4,5 +4,6 @@ Server Requirements
- `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 (5.1+), MySQLi, MS SQL, SQLSRV, Oracle,
- PostgreSQL, SQLite, SQLite3, CUBRID, Interbase, ODBC and PDO.
+ supported databases are MySQL (5.1+), MySQLi, Oracle, PostgreSQL,
+ MS SQL, SQLSRV (SQL Server 2005+), SQLite, SQLite3, CUBRID, Interbase,
+ ODBC and PDO.
diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst
index 5ce7fc2ff..3354375c5 100644
--- a/user_guide_src/source/general/reserved_names.rst
+++ b/user_guide_src/source/general/reserved_names.rst
@@ -45,11 +45,11 @@ Constants
---------
- ENVIRONMENT
-- EXT
- FCPATH
- SELF
- BASEPATH
- APPPATH
+- VIEWPATH
- CI_VERSION
- FILE_READ_MODE
- FILE_WRITE_MODE
diff --git a/user_guide_src/source/general/welcome.rst b/user_guide_src/source/general/welcome.rst
new file mode 100644
index 000000000..b28c3bcc2
--- /dev/null
+++ b/user_guide_src/source/general/welcome.rst
@@ -0,0 +1,32 @@
+######################
+Welcome to CodeIgniter
+######################
+
+CodeIgniter is an Application Development Framework - a toolkit - for
+people who build web sites using PHP. Its goal is to enable you to
+develop projects much faster than you could if you were writing code
+from scratch, by providing a rich set of libraries for commonly needed
+tasks, as well as a simple interface and logical structure to access
+these libraries. CodeIgniter lets you creatively focus on your project
+by minimizing the amount of code needed for a given task.
+
+***********************
+Who is CodeIgniter For?
+***********************
+
+CodeIgniter is right for you if:
+
+- You want a framework with a small footprint.
+- You need exceptional performance.
+- You need broad compatibility with standard hosting accounts that run
+ a variety of PHP versions and configurations.
+- You want a framework that requires nearly zero configuration.
+- You want a framework that does not require you to use the command
+ line.
+- You want a framework that does not require you to adhere to
+ restrictive coding rules.
+- You are not interested in large-scale monolithic libraries like PEAR.
+- You do not want to be forced to learn a templating language (although
+ a template parser is optionally available if you desire one).
+- You eschew complexity, favoring simple solutions.
+- You need clear, thorough documentation.
diff --git a/user_guide_src/source/helpers/array_helper.rst b/user_guide_src/source/helpers/array_helper.rst
index 4308753bb..15b5e17c4 100644
--- a/user_guide_src/source/helpers/array_helper.rst
+++ b/user_guide_src/source/helpers/array_helper.rst
@@ -21,17 +21,17 @@ The following functions are available:
element()
=========
-.. php:method:: element($item, $array, $default = FALSE)
+.. php:method:: element($item, $array, $default = NULL)
:param string $item: Item to fetch from the array
:param array $array: Input array
:param boolean $default: What to return if the array isn't valid
- :returns: FALSE on failure or the array item.
+ :returns: NULL on failure or the array item.
Lets you fetch an item from an array. The function tests whether the
array index is set and whether it has a value. If a value exists it is
-returned. If a value does not exist it returns FALSE, or whatever you've
+returned. If a value does not exist it returns NULL, or whatever you've
specified as the default value via the third parameter. Example
::
@@ -43,31 +43,31 @@ specified as the default value via the third parameter. Example
);
echo element('color', $array); // returns "red"
- echo element('size', $array, NULL); // returns NULL
+ echo element('size', $array, 'foobar'); // returns "foobar"
elements()
==========
Lets you fetch a number of items from an array. The function tests
whether each of the array indices is set. If an index does not exist it
-is set to FALSE, or whatever you've specified as the default value via
+is set to NULL, or whatever you've specified as the default value via
the third parameter.
-.. php:method:: elements($items, $array, $default = FALSE)
+.. php:method:: elements($items, $array, $default = NULL)
:param string $item: Item to fetch from the array
:param array $array: Input array
:param boolean $default: What to return if the array isn't valid
- :returns: FALSE on failure or the array item.
+ :returns: NULL on failure or the array item.
Example
::
$array = array(
- 'color' => 'red',  
- 'shape' => 'round',     
- 'radius' => '10',     
+ 'color' => 'red',
+ 'shape' => 'round',
+ 'radius' => '10',
'diameter' => '20'
);
@@ -78,25 +78,25 @@ The above will return the following array
::
array(
- 'color' => 'red',     
- 'shape' => 'round',     
- 'height' => FALSE
+ 'color' => 'red',
+ 'shape' => 'round',
+ 'height' => NULL
);
You can set the third parameter to any default value you like
::
- $my_shape = elements(array('color', 'shape', 'height'), $array, NULL);
+ $my_shape = elements(array('color', 'shape', 'height'), $array, 'foobar');
The above will return the following array
::
array(     
- 'color' => 'red',     
- 'shape' => 'round',     
- 'height' => NULL
+ 'color' => 'red',
+ 'shape' => 'round',
+ 'height' => 'foobar'
);
This is useful when sending the $_POST array to one of your Models.
diff --git a/user_guide_src/source/helpers/captcha_helper.rst b/user_guide_src/source/helpers/captcha_helper.rst
index 48095a11d..90244739b 100644
--- a/user_guide_src/source/helpers/captcha_helper.rst
+++ b/user_guide_src/source/helpers/captcha_helper.rst
@@ -102,7 +102,7 @@ Here is a table prototype
CREATE TABLE captcha (  
captcha_id bigint(13) unsigned NOT NULL auto_increment,  
captcha_time int(10) unsigned NOT NULL,  
- ip_address varchar(16) default '0' NOT NULL,  
+ ip_address varchar(45) NOT NULL,  
word varchar(20) NOT NULL,  
PRIMARY KEY `captcha_id` (`captcha_id`),  
KEY `word` (`word`)
diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst
index 8f4b2a8b8..d0c72c3c4 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -21,18 +21,26 @@ now()
=====
Returns the current time as a Unix timestamp, referenced either to your
-server's local time or GMT, based on the "time reference" setting in
-your config file. If you do not intend to set your master time reference
-to GMT (which you'll typically do if you run a site that lets each user
-set their own timezone settings) there is no benefit to using this
+server's local time or any PHP suported timezone, based on the "time reference"
+setting in your config file. If you do not intend to set your master time reference
+to any other PHP suported timezone (which you'll typically do if you run a site that
+lets each user set their own timezone settings) there is no benefit to using this
function over PHP's time() function.
-.. php:method:: now()
+.. php:method:: now($timezone = NULL)
+
+ :param string $timezone: The timezone you want to be returned
+ :returns: integer
+
+::
+ echo now("Australia/Victoria");
+
+If a timezone is not provided, it will return time() based on "time_reference" setting.
mdate()
=======
-This function is identical to PHPs `date() <http://www.php.net/date>`_
+This function is identical to PHP's `date() <http://www.php.net/date>`_
function, except that it lets you use MySQL style date codes, where each
code letter is preceded with a percent sign: %Y %m %d etc.
@@ -77,37 +85,34 @@ Example
The first parameter must contain the format, the second parameter must
contain the date as a Unix timestamp.
-Supported formats:
+.. note:: This function is DEPRECATED. Use the native ``date()`` combined
+ with `DateTime's format constants <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_
+ instead:
-+----------------+------------------------+-----------------------------------+
-| Constant | Description | Example |
-+================+========================+===================================+
-| DATE_ATOM | Atom | 2005-08-15T16:13:03+0000 |
-+----------------+------------------------+-----------------------------------+
-| DATE_COOKIE | HTTP Cookies | Sun, 14 Aug 2005 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_ISO8601 | ISO-8601 | 2005-08-14T16:13:03+00:00 |
-+----------------+------------------------+-----------------------------------+
-| DATE_RFC822 | RFC 822 | Sun, 14 Aug 05 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_RFC850 | RFC 850 | Sunday, 14-Aug-05 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_RFC1036 | RFC 1036 | Sunday, 14-Aug-05 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_RFC1123 | RFC 1123 | Sun, 14 Aug 2005 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_RFC2822 | RFC 2822 | Sun, 14 Aug 2005 16:13:03 +0000 |
-+----------------+------------------------+-----------------------------------+
-| DATE_RSS | RSS | Sun, 14 Aug 2005 16:13:03 UTC |
-+----------------+------------------------+-----------------------------------+
-| DATE_W3C | W3C | 2005-08-14T16:13:03+0000 |
-+----------------+------------------------+-----------------------------------+
+ |
+ | echo date(DATE_RFC822, time());
+Supported formats:
+
+=============== ======================= ======================================
+Constant Description Example
+=============== ======================= ======================================
+DATE_ATOM Atom 2005-08-15T16:13:03+0000
+DATE_COOKIE HTTP Cookies Sun, 14 Aug 2005 16:13:03 UTC
+DATE_ISO8601 ISO-8601 2005-08-14T16:13:03+00:00
+DATE_RFC822 RFC 822 Sun, 14 Aug 05 16:13:03 UTC
+DATE_RFC850 RFC 850 Sunday, 14-Aug-05 16:13:03 UTC
+DATE_RFC1036 RFC 1036 Sunday, 14-Aug-05 16:13:03 UTC
+DATE_RFC1123 RFC 1123 Sun, 14 Aug 2005 16:13:03 UTC
+DATE_RFC2822 RFC 2822 Sun, 14 Aug 2005 16:13:03 +0000
+DATE_RSS RSS Sun, 14 Aug 2005 16:13:03 UTC
+DATE_W3C W3C 2005-08-14T16:13:03+0000
+=============== ======================= ======================================
local_to_gmt()
==============
-Takes a Unix timestamp as input and returns it as GMT.
+Takes a Unix timestamp as input and returns it as GMT.
.. php:method:: local_to_gmt($time = '')
@@ -151,7 +156,7 @@ Example
mysql_to_unix()
===============
-Takes a MySQL Timestamp as input and returns it as Unix.
+Takes a MySQL Timestamp as input and returns it as Unix.
.. php:method:: mysql_to_unix($time = '')
@@ -204,7 +209,7 @@ human_to_unix()
The opposite of the above function. Takes a "human" time as input and
returns it as Unix. This function is useful if you accept "human"
formatted dates submitted via a form. Returns FALSE (boolean) if the
-date string passed to it is not formatted as indicated above.
+date string passed to it is not formatted as indicated above.
.. php:method:: human_to_unix($datestr = '')
@@ -227,9 +232,9 @@ them into something useful. It also accepts well-formed dates.
The function will return a Unix timestamp by default. You can,
optionally, pass a format string (the same type as the PHP date function
-accepts) as the second parameter.
+accepts) as the second parameter.
-.. php:method:: nice_date($bad_date = '', $format = FALSE)
+.. php:method:: nice_date($bad_date = '', $format = FALSE)
:param integer $bad_date: The terribly formatted date-like string
:param string $format: Date format to return (same as php date function)
@@ -239,26 +244,28 @@ Example
::
- $bad_time = 199605 // Should Produce: 1996-05-01
- $better_time = nice_date($bad_time,'Y-m-d');
- $bad_time = 9-11-2001 // Should Produce: 2001-09-11
- $better_time = nice_date($human,'Y-m-d');
+ $bad_date = '199605';
+ // Should Produce: 1996-05-01
+ $better_date = nice_date($bad_date, 'Y-m-d');
+
+ $bad_date = '9-11-2001';
+ // Should Produce: 2001-09-11
+ $better_date = nice_date($bad_date, 'Y-m-d');
timespan()
==========
Formats a unix timestamp so that is appears similar to this
-
::
1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes
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 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.
+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 = '', $units = '')
@@ -283,7 +290,7 @@ days_in_month()
===============
Returns the number of days in a given month/year. Takes leap years into
-account.
+account.
.. php:method:: days_in_month($month = 0, $year = '')
@@ -404,14 +411,15 @@ allowed to set their local timezone value.
The first parameter lets you set the "selected" state of the menu. For
example, to set Pacific time as the default you will do this
-.. php:method:: timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
+.. php:method:: timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '')
:param string $default: timezone
:param string $class: classname
:param string $name: menu name
+ :param mixed $attributes: attributes
:returns: string
-Example:
+Example:
::
@@ -421,6 +429,8 @@ Please see the timezone reference below to see the values of this menu.
The second parameter lets you set a CSS class name for the menu.
+The fourth parameter lets you set one or more attributes on the generated select tag.
+
.. note:: The text contained in the menu is found in the following
language file: `language/<your_lang>/date_lang.php`
@@ -432,86 +442,47 @@ The following table indicates each timezone and its location.
Note some of the location lists have been abridged for clarity and formatting.
-+------------+----------------------------------------------------------------+
-| Time Zone | Location |
-+============+================================================================+
-| UM12 | (UTC - 12:00) Baker/Howland Island |
-+------------+----------------------------------------------------------------+
-| UM11 | (UTC - 11:00) Samoa Time Zone, Niue |
-+------------+----------------------------------------------------------------+
-| UM10 | (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands |
-+------------+----------------------------------------------------------------+
-| UM95 | (UTC - 09:30) Marquesas Islands |
-+------------+----------------------------------------------------------------+
-| UM9 | (UTC - 09:00) Alaska Standard Time, Gambier Islands |
-+------------+----------------------------------------------------------------+
-| UM8 | (UTC - 08:00) Pacific Standard Time, Clipperton Island |
-+------------+----------------------------------------------------------------+
-| UM7 | (UTC - 11:00) Mountain Standard Time |
-+------------+----------------------------------------------------------------+
-| UM6 | (UTC - 06:00) Central Standard Time |
-+------------+----------------------------------------------------------------+
-| UM5 | (UTC - 05:00) Eastern Standard Time, Western Caribbean |
-+------------+----------------------------------------------------------------+
-| UM45 | (UTC - 04:30) Venezuelan Standard Time |
-+------------+----------------------------------------------------------------+
-| UM4 | (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean |
-+------------+----------------------------------------------------------------+
-| UM35 | (UTC - 03:30) Newfoundland Standard Time |
-+------------+----------------------------------------------------------------+
-| UM3 | (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay |
-+------------+----------------------------------------------------------------+
-| UM2 | (UTC - 02:00) South Georgia/South Sandwich Islands |
-+------------+----------------------------------------------------------------+
-| UM1 | (UTC -1:00) Azores, Cape Verde Islands |
-+------------+----------------------------------------------------------------+
-| UTC | (UTC) Greenwich Mean Time, Western European Time |
-+------------+----------------------------------------------------------------+
-| UP1 | (UTC +1:00) Central European Time, West Africa Time |
-+------------+----------------------------------------------------------------+
-| UP2 | (UTC +2:00) Central Africa Time, Eastern European Time |
-+------------+----------------------------------------------------------------+
-| UP3 | (UTC +3:00) Moscow Time, East Africa Time |
-+------------+----------------------------------------------------------------+
-| UP35 | (UTC +3:30) Iran Standard Time |
-+------------+----------------------------------------------------------------+
-| UP4 | (UTC +4:00) Azerbaijan Standard Time, Samara Time |
-+------------+----------------------------------------------------------------+
-| UP45 | (UTC +4:30) Afghanistan |
-+------------+----------------------------------------------------------------+
-| UP5 | (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time |
-+------------+----------------------------------------------------------------+
-| UP55 | (UTC +5:30) Indian Standard Time, Sri Lanka Time |
-+------------+----------------------------------------------------------------+
-| UP575 | (UTC +5:45) Nepal Time |
-+------------+----------------------------------------------------------------+
-| UP6 | (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time |
-+------------+----------------------------------------------------------------+
-| UP65 | (UTC +6:30) Cocos Islands, Myanmar |
-+------------+----------------------------------------------------------------+
-| UP7 | (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam|
-+------------+----------------------------------------------------------------+
-| UP8 | (UTC +8:00) Australian Western Standard Time, Beijing Time |
-+------------+----------------------------------------------------------------+
-| UP875 | (UTC +8:45) Australian Central Western Standard Time |
-+------------+----------------------------------------------------------------+
-| UP9 | (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk |
-+------------+----------------------------------------------------------------+
-| UP95 | (UTC +9:30) Australian Central Standard Time |
-+------------+----------------------------------------------------------------+
-| UP10 | (UTC +10:00) Australian Eastern Standard Time, Vladivostok Time|
-+------------+----------------------------------------------------------------+
-| UP105 | (UTC +10:30) Lord Howe Island |
-+------------+----------------------------------------------------------------+
-| UP11 | (UTC +11:00) Magadan Time, Solomon Islands, Vanuatu |
-+------------+----------------------------------------------------------------+
-| UP115 | (UTC +11:30) Norfolk Island |
-+------------+----------------------------------------------------------------+
-| UP12 | (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand |
-+------------+----------------------------------------------------------------+
-| UP1275 | (UTC +12:45) Chatham Islands Standard Time |
-+------------+----------------------------------------------------------------+
-| UP13 | (UTC +13:00) Phoenix Islands Time, Tonga |
-+------------+----------------------------------------------------------------+
-| UP14 | (UTC +14:00) Line Islands |
-+------------+----------------------------------------------------------------+
+=========== =====================================================================
+Time Zone Location
+=========== =====================================================================
+UM2 (UTC - 12:00) Baker/Howland Island
+UM1 (UTC - 11:00) Samoa Time Zone, Niue
+UM0 (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands
+UM95 (UTC - 09:30) Marquesas Islands
+UM9 (UTC - 09:00) Alaska Standard Time, Gambier Islands
+UM8 (UTC - 08:00) Pacific Standard Time, Clipperton Island
+UM7 (UTC - 11:00) Mountain Standard Time
+UM6 (UTC - 06:00) Central Standard Time
+UM5 (UTC - 05:00) Eastern Standard Time, Western Caribbean
+UM45 (UTC - 04:30) Venezuelan Standard Time
+UM4 (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean
+UM35 (UTC - 03:30) Newfoundland Standard Time
+UM3 (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay
+UM2 (UTC - 02:00) South Georgia/South Sandwich Islands
+UM (UTC -1:00) Azores, Cape Verde Islands
+UTC (UTC) Greenwich Mean Time, Western European Time
+UP1 (UTC +1:00) Central European Time, West Africa Time
+UP2 (UTC +2:00) Central Africa Time, Eastern European Time
+UP3 (UTC +3:00) Moscow Time, East Africa Time
+UP35 (UTC +3:30) Iran Standard Time
+UP4 (UTC +4:00) Azerbaijan Standard Time, Samara Time
+UP45 (UTC +4:30) Afghanistan
+UP5 (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time
+UP55 (UTC +5:30) Indian Standard Time, Sri Lanka Time
+UP575 (UTC +5:45) Nepal Time
+UP6 (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time
+UP65 (UTC +6:30) Cocos Islands, Myanmar
+UP7 (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam
+UP8 (UTC +8:00) Australian Western Standard Time, Beijing Time
+UP875 (UTC +8:45) Australian Central Western Standard Time
+UP9 (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk
+UP95 (UTC +9:30) Australian Central Standard Time
+UP10 (UTC +10:00) Australian Eastern Standard Time, Vladivostok Time
+UP105 (UTC +10:30) Lord Howe Island
+UP11 (UTC +11:00) Magadan Time, Solomon Islands, Vanuatu
+UP115 (UTC +11:30) Norfolk Island
+UP12 (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand
+UP1275 (UTC +12:45) Chatham Islands Standard Time
+UP1 (UTC +13:00) Phoenix Islands Time, Tonga
+UP14 (UTC +14:00) Line Islands
+=========== =====================================================================
diff --git a/user_guide_src/source/helpers/file_helper.rst b/user_guide_src/source/helpers/file_helper.rst
index bfc271eb3..60c5aa98c 100644
--- a/user_guide_src/source/helpers/file_helper.rst
+++ b/user_guide_src/source/helpers/file_helper.rst
@@ -32,6 +32,9 @@ The path can be a relative or full server path. Returns FALSE (boolean) on failu
controller or view files. CodeIgniter uses a front controller so paths
are always relative to the main site index.
+.. note:: This function is DEPRECATED. Use the native ``file_get_contents()``
+ instead.
+
If your server is running an `open_basedir` restriction this function might not work if you are trying to access a file above the calling script.
write_file('path', $data)
diff --git a/user_guide_src/source/helpers/form_helper.rst b/user_guide_src/source/helpers/form_helper.rst
index a110f3c14..fa7b3dbf9 100644
--- a/user_guide_src/source/helpers/form_helper.rst
+++ b/user_guide_src/source/helpers/form_helper.rst
@@ -543,3 +543,7 @@ 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'); ?> />
+.. note:: If you are using the Form Validation class, you must always specify a rule for your field,
+ even if empty, in order for the set_*() functions to work. This is because if a Form Validation object
+ is defined, the control for set_*() is handed over to a method of the class instead of the generic helper
+ function. \ No newline at end of file
diff --git a/user_guide_src/source/helpers/security_helper.rst b/user_guide_src/source/helpers/security_helper.rst
index b1bcf2b4a..ec0be28b3 100644
--- a/user_guide_src/source/helpers/security_helper.rst
+++ b/user_guide_src/source/helpers/security_helper.rst
@@ -43,8 +43,10 @@ for a full list of supported algorithms.
$str = do_hash($str); // SHA1
$str = do_hash($str, 'md5'); // MD5
-.. note:: This function was formerly named dohash(), which has been
- removed in favor of `do_hash()`.
+.. note:: This function was formerly named ``dohash()``, which has been
+ removed in favor of ``do_hash()``.
+
+.. note:: This function is DEPRECATED. Use the native ``hash()`` instead.
strip_image_tags()
==================
diff --git a/user_guide_src/source/helpers/string_helper.rst b/user_guide_src/source/helpers/string_helper.rst
index 2d23fb00c..19500aa0d 100644
--- a/user_guide_src/source/helpers/string_helper.rst
+++ b/user_guide_src/source/helpers/string_helper.rst
@@ -36,8 +36,7 @@ alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
- **unique**: Encrypted with MD5 and uniqid(). Note: The length
parameter is not available for this type. Returns a fixed length 32
character string.
-- **sha1**: An encrypted random number based on do_hash() from the
- :doc:`security helper <security_helper>`.
+- **sha1**: An encrypted random number based on ``sha1()``.
Usage example
diff --git a/user_guide_src/source/helpers/url_helper.rst b/user_guide_src/source/helpers/url_helper.rst
index e6d51b22b..1987dfb72 100644
--- a/user_guide_src/source/helpers/url_helper.rst
+++ b/user_guide_src/source/helpers/url_helper.rst
@@ -168,27 +168,35 @@ browser settings. Here is an example with attributes
::
- $atts = array(               
- 'width'      => '800',               
- 'height'     => '600',               
- 'scrollbars' => 'yes',               
- 'status'     => 'yes',               
- 'resizable'  => 'yes',               
- 'screenx'    => '0',               
- 'screeny'    => '0'             
+ $atts = array(
+ 'width' => '800',
+ 'height' => '600',
+ 'scrollbars' => 'yes',
+ 'status'      => 'yes',
+ 'resizable'   => 'yes',
+ 'screenx'     => '0',
+ 'screeny'     => '0',
+ 'window_name' => '_blank'
);
echo anchor_popup('news/local/123', 'Click Me!', $atts);
-Note: The above attributes are the function defaults so you only need to
-set the ones that are different from what you need. If you want the
-function to use all of its defaults simply pass an empty array in the
-third parameter
+.. note:: The above attributes are the function defaults so you only need to
+ set the ones that are different from what you need. If you want the
+ function to use all of its defaults simply pass an empty array in the
+ third parameter
::
echo anchor_popup('news/local/123', 'Click Me!', array());
+.. note:: The 'window_name' is not really an attribute, but an argument to
+ the JavaScript `window.open() <http://www.w3schools.com/jsref/met_win_open.asp>`
+ method, which accepts either a window name or a window target.
+
+.. note:: Any other attribute than the listed above will be parsed as an
+ HTML attribute to the anchor tag.
+
mailto()
========
@@ -199,7 +207,12 @@ Creates a standard HTML email link. Usage example
echo mailto('me@my-site.com', 'Click Here to Contact Me');
As with the anchor() tab above, you can set attributes using the third
-parameter.
+parameter:
+
+::
+
+ $attributes = array('title' => 'Mail me');
+ echo mailto('me@my-site.com', 'Contact Me', $attributes);
safe_mailto()
=============
@@ -290,7 +303,7 @@ link. The function will build the URL based on your config file values.
The optional second parameter allows you to force a particular redirection
method. The available methods are "location" or "refresh", with location
-being faster but less reliable on Windows servers. The default is "auto",
+being faster but less reliable on IIS servers. The default is "auto",
which will attempt to intelligently choose the method based on the server
environment.
@@ -312,3 +325,7 @@ engine purposes. The default Response Code is 302. The third parameter is
.. note:: For very fine grained control over headers, you should use the
`Output Library </libraries/output>` set_header() function.
+
+.. note:: To IIS users: if you hide the `Server` HTTP header, the "auto"
+ method won't detect IIS, in that case it is advised you explicitly
+ use the "refresh" method.
diff --git a/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png b/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png
index 554ae2eed..7f054f95f 100644
--- a/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png
+++ b/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png
Binary files differ
diff --git a/user_guide_src/source/index.rst b/user_guide_src/source/index.rst
index 6cdeb2442..35089703f 100644
--- a/user_guide_src/source/index.rst
+++ b/user_guide_src/source/index.rst
@@ -1,34 +1,107 @@
-Welcome to CodeIgniter
-======================
-
-CodeIgniter is an Application Development Framework - a toolkit - for
-people who build web sites using PHP. Its goal is to enable you to
-develop projects much faster than you could if you were writing code
-from scratch, by providing a rich set of libraries for commonly needed
-tasks, as well as a simple interface and logical structure to access
-these libraries. CodeIgniter lets you creatively focus on your project
-by minimizing the amount of code needed for a given task.
-
-Who is CodeIgniter For?
-=======================
-
-CodeIgniter is right for you if:
-
-- You want a framework with a small footprint.
-- You need exceptional performance.
-- You need broad compatibility with standard hosting accounts that run
- a variety of PHP versions and configurations.
-- You want a framework that requires nearly zero configuration.
-- You want a framework that does not require you to use the command
- line.
-- You want a framework that does not require you to adhere to
- restrictive coding rules.
-- You are not interested in large-scale monolithic libraries like PEAR.
-- You do not want to be forced to learn a templating language (although
- a template parser is optionally available if you desire one).
-- You eschew complexity, favoring simple solutions.
-- You need clear, thorough documentation.
+######################
+CodeIgniter User Guide
+######################
+- :doc:`License Agreement <license>`
+- :doc:`Change Log <changelog>`
+
+.. contents::
+ :local:
+ :depth: 2
+
+*******
+Welcome
+*******
+
+- :doc:`general/welcome`
+
+**********
+Basic Info
+**********
+
+- :doc:`general/requirements`
+- :doc:`general/credits`
+
+************
+Installation
+************
+
+- :doc:`installation/downloads`
+- :doc:`installation/index`
+- :doc:`installation/upgrading`
+- :doc:`installation/troubleshooting`
+
+************
+Introduction
+************
+
+- :doc:`overview/getting_started`
+- :doc:`overview/at_a_glance`
+- :doc:`overview/cheatsheets`
+- :doc:`overview/features`
+- :doc:`overview/appflow`
+- :doc:`overview/mvc`
+- :doc:`overview/goals`
+
+********
+Tutorial
+********
+
+- :doc:`tutorial/index`
+- :doc:`tutorial/static_pages`
+- :doc:`tutorial/news_section`
+- :doc:`tutorial/create_news_items`
+- :doc:`tutorial/conclusion`
+
+**************
+General Topics
+**************
+
+.. toctree::
+ :glob:
+ :titlesonly:
+
+ general/index
+
+*****************
+Library Reference
+*****************
+
+.. toctree::
+ :glob:
+ :titlesonly:
+
+ libraries/index
+
+****************
+Driver Reference
+****************
+
+- :doc:`libraries/caching`
+- :doc:`database/index`
+- :doc:`libraries/javascript`
+- :doc:`libraries/sessions`
+
+****************
+Helper Reference
+****************
+
+.. toctree::
+ :glob:
+ :titlesonly:
+
+ helpers/index
+
+***************************
+Contributing to CodeIgniter
+***************************
+
+.. toctree::
+ :glob:
+ :titlesonly:
+
+ contributing/index
+ DCO
.. toctree::
:glob:
@@ -38,6 +111,7 @@ CodeIgniter is right for you if:
*
overview/index
general/requirements
+ general/welcome
installation/index
general/index
libraries/index
@@ -46,4 +120,4 @@ CodeIgniter is right for you if:
documentation/index
tutorial/index
general/quick_reference
- general/credits \ No newline at end of file
+ general/credits
diff --git a/user_guide_src/source/installation/downloads.rst b/user_guide_src/source/installation/downloads.rst
index a4a6b7fbe..45a8f80a7 100644
--- a/user_guide_src/source/installation/downloads.rst
+++ b/user_guide_src/source/installation/downloads.rst
@@ -2,9 +2,15 @@
Downloading CodeIgniter
#######################
-- `CodeIgniter V 2.1.0 (Current
+- `CodeIgniter V 3.0.0 (Current
version) <http://codeigniter.com/downloads/>`_
- `CodeIgniter V
+ 2.1.2 <http://codeigniter.com/download_files/reactor/CodeIgniter_2.1.2.zip>`_
+- `CodeIgniter V
+ 2.1.1 <http://codeigniter.com/download_files/reactor/CodeIgniter_2.1.1.zip>`_
+- `CodeIgniter V
+ 2.1.0 <http://codeigniter.com/download_files/reactor/CodeIgniter_2.1.0.zip>`_
+- `CodeIgniter V
2.0.3 <http://codeigniter.com/download_files/reactor/CodeIgniter_2.0.3.zip>`_
- `CodeIgniter V
2.0.2 <http://codeigniter.com/download_files/reactor/CodeIgniter_2.0.2.zip>`_
diff --git a/user_guide_src/source/installation/upgrade_200.rst b/user_guide_src/source/installation/upgrade_200.rst
index b39f4fd23..29f44bd9e 100644
--- a/user_guide_src/source/installation/upgrade_200.rst
+++ b/user_guide_src/source/installation/upgrade_200.rst
@@ -87,7 +87,14 @@ All native CodeIgniter classes now use the PHP 5 \__construct()
convention. Please update extended libraries to call
parent::\__construct().
-Step 8: Update your user guide
+Step 8: Move any core extensions to application/core
+====================================================
+
+Any extensions to core classes (e.g. MY_Controller.php) in your
+application/libraries folder must be moved to the new
+application/core folder.
+
+Step 9: Update your user guide
==============================
Please replace your local copy of the user guide with the new version,
diff --git a/user_guide_src/source/installation/upgrade_210.rst b/user_guide_src/source/installation/upgrade_210.rst
index 9d7e1a265..5874bfc86 100644
--- a/user_guide_src/source/installation/upgrade_210.rst
+++ b/user_guide_src/source/installation/upgrade_210.rst
@@ -8,15 +8,19 @@ replacing the index.php file with a static one.
Step 1: Update your CodeIgniter files
=====================================
-Replace all files and directories in your "system" folder and replace
-your index.php file. If any modifications were made to your index.php
-they will need to be made fresh in this new one.
+Replace all files and directories in your "system" folder.
+
+.. note:: If you have any custom developed files in these folders please
+ make copies of them first.
Step 2: Replace config/user_agents.php
======================================
This config file has been updated to contain more user agent types,
-please copy it to application/config/user_agents.php.
+please copy it to _application/config/user_agents.php*.
-.. note:: If you have any custom developed files in these folders please
- make copies of them first. \ No newline at end of file
+Step 3: Update your user guide
+==============================
+
+Please also replace your local copy of the user guide with the new
+version. \ No newline at end of file
diff --git a/user_guide_src/source/installation/upgrade_211.rst b/user_guide_src/source/installation/upgrade_211.rst
new file mode 100644
index 000000000..59faca8e6
--- /dev/null
+++ b/user_guide_src/source/installation/upgrade_211.rst
@@ -0,0 +1,33 @@
+#############################
+Upgrading from 2.1.0 to 2.1.1
+#############################
+
+Before performing an update you should take your site offline by
+replacing the index.php file with a static one.
+
+Step 1: Update your CodeIgniter files
+=====================================
+
+Replace all files and directories in your "system" folder and replace
+your index.php file. If any modifications were made to your index.php
+they will need to be made fresh in this new one.
+
+.. note:: If you have any custom developed files in these folders please
+ make copies of them first.
+
+Step 2: Replace config/mimes.php
+================================
+
+This config file has been updated to contain more user mime-types, please copy
+it to _application/config/mimes.php*.
+
+Step 3: Update your IP address tables
+=====================================
+
+This upgrade adds support for IPv6 IP addresses. In order to store them, you need
+to enlarge your ip_address columns to 45 characters. For example, CodeIgniter's
+session table will need to change
+
+::
+
+ ALTER TABLE ci_sessions CHANGE ip_address ip_address varchar(45) default '0' NOT NULL \ No newline at end of file
diff --git a/user_guide_src/source/installation/upgrade_212.rst b/user_guide_src/source/installation/upgrade_212.rst
new file mode 100644
index 000000000..205ad8622
--- /dev/null
+++ b/user_guide_src/source/installation/upgrade_212.rst
@@ -0,0 +1,22 @@
+#############################
+Upgrading from 2.1.1 to 2.1.2
+#############################
+
+Before performing an update you should take your site offline by
+replacing the index.php file with a static one.
+
+Step 1: Update your CodeIgniter files
+=====================================
+
+Replace all files and directories in your "system" folder and replace
+your index.php file. If any modifications were made to your index.php
+they will need to be made fresh in this new one.
+
+.. note:: If you have any custom developed files in these folders please
+ make copies of them first.
+
+Step 2: Update your user guide
+==============================
+
+Please also replace your local copy of the user guide with the new
+version. \ No newline at end of file
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index e434e8d45..31a5c0761 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -1,15 +1,14 @@
#############################
-Upgrading from 2.1.0 to 3.0.0
+Upgrading from 2.1.2 to 3.0.0
#############################
.. note:: These upgrade notes are for a version that is yet to be released.
+Before performing an update you should take your site offline by replacing the index.php file with a static one.
-Before performing an update you should take your site offline by
-replacing the index.php file with a static one.
-
+*************************************
Step 1: Update your CodeIgniter files
-=====================================
+*************************************
Replace all files and directories in your "system" folder and replace
your index.php file. If any modifications were made to your index.php
@@ -18,26 +17,154 @@ they will need to be made fresh in this new one.
.. note:: If you have any custom developed files in these folders please
make copies of them first.
-Step 2: Change References to the SHA Library
-============================================
-
-The previously deprecated SHA library has been removed in CodeIgniter 3.0.
-Alter your code to use the native `sha1()` PHP function to generate a sha1 hash.
+********************************
+Step 2: Replace config/mimes.php
+********************************
-Additionally, the `sha1()` method in the :doc:`Encryption Library <../libraries/encryption>` has been removed.
+This config file has been updated to contain more user mime-types, please copy
+it to _application/config/mimes.php*.
+**************************************************************
Step 3: Remove $autoload['core'] from your config/autoload.php
-==============================================================
+**************************************************************
+
+Use of the ``$autoload['core']`` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
+Move any entries that you might have listed there to ``$autoload['libraries']`` instead.
+
+**************************************************************
+Step 4: Add new session driver items to your config/config.php
+**************************************************************
+
+With the change from a single Session Library to the new Session Driver, two new config items have been added:
-Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
-Move any entries that you might have listed there to `$autoload['libraries']` instead.
+ - ``$config['sess_driver']`` selects which driver to initially load. Options are:
+ - 'cookie' (the default) for classic CodeIgniter cookie-based sessions
+ - 'native' for native PHP Session support
+ - the name of a custom driver you have provided (see :doc:`Session Driver <../libraries/sessions>` for more info)
+ - ``$config['sess_valid_drivers']`` provides an array of additional custom drivers to make available for loading
-Step 4: Update your config/database.php
-=======================================
+As the new Session Driver library loads the classic Cookie driver by default and always makes 'cookie' and 'native'
+available as valid drivers, neither of these configuration items are required. However, it is recommended that you
+add them for clarity and ease of configuration in the future.
-Due to 3.0.0's renaming of Active Record to Query Builder, inside your _config/database.php_, you will
+***************************************
+Step 5: Update your config/database.php
+***************************************
+
+Due to 3.0.0's renaming of Active Record to Query Builder, inside your `config/database.php`, you will
need to rename the `$active_record` variable to `$query_builder`.
$active_group = 'default';
// $active_record = TRUE;
- $query_builder = TRUE; \ No newline at end of file
+ $query_builder = TRUE;
+
+*******************************
+Step 6: Move your errors folder
+*******************************
+
+In version 3.0.0, the errors folder has been moved from _application/errors* to _application/views/errors*.
+
+****************************************************************************
+Step 7: Check the calls to Array Helper's element() and elements() functions
+****************************************************************************
+
+The default return value of these functions, when the required elements
+don't exist, has been changed from FALSE to NULL.
+
+***************************************************************
+Step 8: Remove usage of (previously) deprecated functionalities
+***************************************************************
+
+In addition to the ``$autoload['core']`` configuration setting, there's a number of other functionalities
+that have been removed in CodeIgniter 3.0.0:
+
+The SHA1 library
+================
+
+The previously deprecated SHA1 library has been removed, alter your code to use PHP's native
+``sha1()`` function to generate a SHA1 hash.
+
+Additionally, the ``sha1()`` method in the :doc:`Encryption Library <../libraries/encryption>` has been removed.
+
+The EXT constant
+================
+
+Usage of the ``EXT`` constant has been deprecated since dropping support for PHP 4. There's no
+longer a need to maintain different filename extensions and in this new CodeIgniter version,
+the ``EXT`` constant has been removed. Use just '.php' instead.
+
+Smiley helper js_insert_smiley()
+================================
+
+:doc:`Smiley Helper <../helpers/smiley_helper>` function ``js_insert_smiley()`` has been deprecated
+since CodeIgniter 1.7.2 and is now removed. You'll need to switch to ``smiley_js()`` instead.
+
+Security helper do_hash()
+=========================
+
+:doc:`Security Helper <../helpers/security_helper>` function ``do_hash()`` is now just an alias for
+PHP's native ``hash()`` function. It is deprecated and scheduled for removal in CodeIgniter 3.1+.
+
+.. note:: This function is still available, but you're strongly encouraged to remove it's usage sooner
+ rather than later.
+
+File helper read_file()
+=======================
+
+:doc:`File Helper <../helpers/file_helper>` function ``read_file()`` is now just an alias for
+PHP's native ``file_get_contents()`` function. It is deprecated and scheduled for removal in
+CodeIgniter 3.1+.
+
+.. note:: This function is still available, but you're strongly encouraged to remove it's usage sooner
+ rather than later.
+
+Date helper standard_date()
+===========================
+
+:doc:`Date Helper <../helpers/date_helper>` function ``standard_date()`` is being deprecated due
+to the availability of native PHP `constants <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_,
+which when combined with ``date()`` provide the same functionality. Furthermore, they have the
+exact same names as the ones supported by ``standard_date()``. Here are examples of how to replace
+it's usage:
+
+::
+
+ // Old way
+ standard_date(); // defaults to standard_date('DATE_RFC822', now());
+
+ // Replacement
+ date(DATE_RFC822, now());
+
+ // Old way
+ standard_date('DATE_ATOM', $time);
+
+ // Replacement
+ date(DATE_ATOM, $time);
+
+.. note:: This function is still available, but you're strongly encouraged to remove its' usage sooner
+ rather than later as it is scheduled for removal in CodeIgniter 3.1+.
+
+Pagination library 'anchor_class' setting
+=========================================
+
+The :doc:`Pagination Library <../libraries/pagination>` now supports adding pretty much any HTML
+attribute to your anchors via the 'attributes' configuration setting. This includes passing the
+'class' attribute and using the separate 'anchor_class' setting no longer makes sense.
+As a result of that, the 'anchor_class' setting is now deprecated and scheduled for removal in
+CodeIgniter 3.1+.
+
+.. note:: This setting is still available, but you're strongly encouraged to remove its' usage sooner
+ rather than later.
+
+Email library
+=============
+
+The :doc:`Email library <../libraries/email>` will automatically clear the set parameters after successfully sending
+emails. To override this behaviour, pass FALSE as the first parameter in the ``send()`` function:
+
+::
+
+ if ($this->email->send(FALSE))
+ {
+ // Parameters won't be cleared
+ }
diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst
index 2badffc93..545f344ee 100644
--- a/user_guide_src/source/installation/upgrading.rst
+++ b/user_guide_src/source/installation/upgrading.rst
@@ -5,6 +5,9 @@ Upgrading From a Previous Version
Please read the upgrade notes corresponding to the version you are
upgrading from.
+- :doc:`Upgrading from 2.1.2 to 3.0.0 <upgrade_300>`
+- :doc:`Upgrading from 2.1.1 to 2.1.2 <upgrade_212>`
+- :doc:`Upgrading from 2.1.0 to 2.1.1 <upgrade_211>`
- :doc:`Upgrading from 2.0.3 to 2.1.0 <upgrade_210>`
- :doc:`Upgrading from 2.0.2 to 2.0.3 <upgrade_203>`
- :doc:`Upgrading from 2.0.1 to 2.0.2 <upgrade_202>`
diff --git a/user_guide_src/source/libraries/config.rst b/user_guide_src/source/libraries/config.rst
index c81cad7b3..08d9c2905 100644
--- a/user_guide_src/source/libraries/config.rst
+++ b/user_guide_src/source/libraries/config.rst
@@ -149,11 +149,13 @@ folders:
- Your own custom configuration files
.. note::
- CodeIgniter always tries to load the configuration files for
- the current environment first. If the file does not exist, the global
- config file (i.e., the one in application/config/) is loaded. This means
- you are not obligated to place **all** of your configuration files in an
- environment folder − only the files that change per environment.
+ CodeIgniter always loads the global config file first (i.e., the one in application/config/),
+ then tries to load the configuration files for the current environment.
+ This means you are not obligated to place **all** of your configuration files in an
+ environment folder. Only the files that change per environment. Additionally you don't
+ have to copy **all** the config items in the environment config file. Only the config items
+ that you wish to change for your environment. The config items declared in your environment
+ folders always overwrite those in your global config files.
Helper Functions
================
diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst
index daf000907..e7ed9f74c 100644
--- a/user_guide_src/source/libraries/email.rst
+++ b/user_guide_src/source/libraries/email.rst
@@ -117,6 +117,13 @@ Sets the email address and name of the person sending the email::
$this->email->from('you@example.com', 'Your Name');
+You can also set a Return-Path, to help redirect undelivered mail::
+
+ $this->email->from('you@example.com', 'Your Name', 'returned_emails@example.com');
+
+.. note:: Return-Path can't be used if you've configured
+ 'smtp' as your protocol.
+
$this->email->reply_to()
-------------------------
@@ -182,6 +189,14 @@ formatting which is added to the header string for people who do not
accept HTML email. If you do not set your own message CodeIgniter will
extract the message from your HTML email and strip the tags.
+$this->email->set_header()
+--------------------------
+
+Appends additional headers to the e-mail::
+
+ $this->email->set_header('Header1', 'Value1');
+ $this->email->set_header('Header2', 'Value2');
+
$this->email->clear()
---------------------
@@ -218,6 +233,14 @@ success or failure, enabling it to be used conditionally::
// Generate error
}
+This function will automatically clear all parameters if the request was
+successful. To stop this behaviour pass FALSE::
+
+ if ($this->email->send(FALSE))
+ {
+ // Parameters won't be cleared
+ }
+
$this->email->attach()
----------------------
diff --git a/user_guide_src/source/libraries/encryption.rst b/user_guide_src/source/libraries/encryption.rst
index 28bdca203..a38122203 100644
--- a/user_guide_src/source/libraries/encryption.rst
+++ b/user_guide_src/source/libraries/encryption.rst
@@ -26,7 +26,7 @@ key security so you may want to think carefully before using it for
anything that requires high security, like storing credit card numbers.
To take maximum advantage of the encryption algorithm, your key should
-be 32 characters in length (128 bits). The key should be as random a
+be 32 characters in length (256 bits). The key should be as random a
string as you can concoct, with numbers and uppercase and lowercase
letters. Your key should **not** be a simple text string. In order to be
cryptographically secure it needs to be as random as possible.
diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst
index d573fc770..1698dcbb9 100644
--- a/user_guide_src/source/libraries/file_uploading.rst
+++ b/user_guide_src/source/libraries/file_uploading.rst
@@ -197,6 +197,7 @@ Preference Default Value Options Descripti
Separate multiple types with a pipe.
**file_name** None Desired file name If set CodeIgniter will rename the uploaded file to this name. The
extension provided in the file name must also be an allowed file type.
+ If no extension is provided in the original file_name will be used.
**overwrite** FALSE TRUE/FALSE (boolean) If set to true, if a file with the same name as the one you are
uploading exists, it will be overwritten. If set to false, a number will
be appended to the filename if another with the same name exists.
@@ -215,6 +216,9 @@ Preference Default Value Options Descripti
that can not be discerned by the person uploading it.
**remove_spaces** TRUE TRUE/FALSE (boolean) If set to TRUE, any spaces in the file name will be converted to
underscores. This is recommended.
+**detect_mime** TRUE TRUE/FALSE (boolean) If set to TRUE, a server side detection of the file type will be
+ performed to avoid code injection attacks. DO NOT disable this option
+ unless you have no other option as that would cause a security risk.
============================ ================= ======================= ======================================================================
Setting preferences in a config file
@@ -287,6 +291,10 @@ data related to the file you uploaded. Here is the array prototype::
[image_size_str] => width="800" height="200"
)
+To return one element from the array::
+
+ $this->upload->data('file_name'); // Returns: mypic.jpg
+
Explanation
***********
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 028b61c4c..14305b664 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -304,6 +304,10 @@ Give it a try! Submit your form without the proper data and you'll see
new error messages that correspond to your new rules. There are numerous
rules available which you can read about in the validation reference.
+.. note:: You can also pass an array of rules to set_rules(), instead of a string. Example::
+
+ $this->form_validation->set_rules('username', 'Username', array('required', 'min_length[5]'));
+
Prepping Data
=============
@@ -484,6 +488,17 @@ the name of the function::
$this->form_validation->set_message('username_check')
+If you are using an error message that can accept two $s in your error string,
+such as:
+::
+
+ $this->form_validation->set_message('min_length', 'The $s field must contain at least $s characters.');
+
+Then you can also use %1$s and %2$s:
+::
+
+ $this->form_validation->set_message('min_length', 'This field must contain at least %2$s characters.');
+
You can also override any error message found in the language file. For
example, to change the message for the "required" rule you will do this::
@@ -857,8 +872,9 @@ Rule Parameter Description
========================= ========== ============================================================================================= =======================
**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]
+**is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field]
+ parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be
+ enabled in order to work.
**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]
@@ -880,10 +896,10 @@ Rule Parameter Description
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.
+ Accepts an optional parameter of 'ipv4' or 'ipv6' to specify an IP format.
**valid_base64** No Returns FALSE if the supplied string contains anything other than valid Base64 characters.
========================= ========== ============================================================================================= =======================
@@ -934,7 +950,7 @@ $this->form_validation->set_rules();
:param string $field: The field name
:param string $label: The field label
- :param string $rules: The rules, seperated by a pipe "|"
+ :param mixed $rules: The rules, as a string with rules separated by a pipe "|", or an array or rules.
:rtype: Object
Permits you to set validation rules, as described in the tutorial
diff --git a/user_guide_src/source/libraries/ftp.rst b/user_guide_src/source/libraries/ftp.rst
index 20b11a5c8..05a3fdcc8 100644
--- a/user_guide_src/source/libraries/ftp.rst
+++ b/user_guide_src/source/libraries/ftp.rst
@@ -26,7 +26,7 @@ Usage Examples
In this example a connection is opened to the FTP server, and a local
file is read and uploaded in ASCII mode. The file permissions are set to
-755. Note: Setting permissions requires PHP 5.
+755.
::
@@ -136,8 +136,7 @@ Example::
**Mode options are:** ascii, binary, and auto (the default). If auto is
used it will base the mode on the file extension of the source file.
-Permissions are available if you are running PHP 5 and can be passed as
-an octal value in the fourth parameter.
+If set, permissions have to be passed as an octal value.
$this->ftp->download()
======================
diff --git a/user_guide_src/source/libraries/image_lib.rst b/user_guide_src/source/libraries/image_lib.rst
index ed6575c62..dcdccbd92 100644
--- a/user_guide_src/source/libraries/image_lib.rst
+++ b/user_guide_src/source/libraries/image_lib.rst
@@ -91,9 +91,9 @@ error upon failure, like this::
echo $this->image_lib->display_errors();
}
-Note: You can optionally specify the HTML formatting to be applied to
-the errors, by submitting the opening/closing tags in the function, like
-this::
+.. note:: You can optionally specify the HTML formatting to be applied to
+ the errors, by submitting the opening/closing tags in the function,
+ like this::
$this->image_lib->display_errors('<p>', '</p>');
@@ -225,8 +225,7 @@ pixels) specifying where to crop, like this::
$config['y_axis'] = '40';
All preferences listed in the table above are available for this
-function except these: rotation_angle, width, height, create_thumb,
-new_image.
+function except these: rotation_angle, create_thumb, new_image.
Here's an example showing how you might crop an image::
@@ -243,11 +242,11 @@ Here's an example showing how you might crop an image::
echo $this->image_lib->display_errors();
}
-Note: Without a visual interface it is difficult to crop images, so this
-function is not very useful unless you intend to build such an
-interface. That's exactly what we did using for the photo gallery module
-in ExpressionEngine, the CMS we develop. We added a JavaScript UI that
-lets the cropping area be selected.
+.. note:: Without a visual interface it is difficult to crop images, so this
+ function is not very useful unless you intend to build such an
+ interface. That's exactly what we did using for the photo gallery module
+ in ExpressionEngine, the CMS we develop. We added a JavaScript UI that
+ lets the cropping area be selected.
$this->image_lib->rotate()
===========================
@@ -338,8 +337,8 @@ The above example will use a 16 pixel True Type font to create the text
bottom/center of the image, 20 pixels from the bottom of the image.
.. note:: In order for the image class to be allowed to do any
- processing, the image file must have "write" file permissions. For
- example, 777.
+ processing, the image file must have "write" file permissions
+ For example, 777.
Watermarking Preferences
========================
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index 1f2ea650a..c0b9c6589 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -18,7 +18,7 @@ The security filtering function is called automatically when a new
:doc:`controller <../general/controllers>` is invoked. It does the
following:
-- If $config['allow_get_array'] is FALSE(default is TRUE), destroys
+- If $config['allow_get_array'] is FALSE (default is TRUE), destroys
the global GET array.
- Destroys all global variables in the event register_globals is
turned on.
@@ -42,33 +42,27 @@ this::
Please refer to the :doc:`Security class <security>` documentation for
information on using XSS Filtering in your application.
-Using POST, COOKIE, or SERVER Data
-==================================
+Using POST, GET, COOKIE, or SERVER Data
+=======================================
-CodeIgniter comes with three helper functions that let you fetch POST,
+CodeIgniter comes with four helper methods that let you fetch POST, GET,
COOKIE or SERVER items. The main advantage of using the provided
functions rather than fetching an item directly ($_POST['something'])
-is that the functions will check to see if the item is set and return
-false (boolean) if not. This lets you conveniently use data without
+is that the methods will check to see if the item is set and return
+NULL if not. This lets you conveniently use data without
having to test whether an item exists first. In other words, normally
you might do something like this::
- if ( ! isset($_POST['something']))
- {
- $something = FALSE;
- }
- else
- {
- $something = $_POST['something'];
- }
+ $something = isset($_POST['something']) ? $_POST['something'] : NULL;
With CodeIgniter's built in functions you can simply do this::
$something = $this->input->post('something');
-The three functions are:
+The four methods are:
- $this->input->post()
+- $this->input->get()
- $this->input->cookie()
- $this->input->server()
@@ -80,8 +74,8 @@ looking for::
$this->input->post('some_data');
-The function returns FALSE (boolean) if the item you are attempting to
-retrieve does not exist.
+The function returns NULL if the item you are attempting to retrieve
+does not exist.
The second optional parameter lets you run the data through the XSS
filter. It's enabled by setting the second parameter to boolean TRUE;
@@ -95,7 +89,7 @@ To return an array of all POST items call without any parameters.
To return all POST items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns FALSE (boolean) if there are no items in the POST.
+The function returns NULL if there are no items in the POST.
::
@@ -115,7 +109,7 @@ To return an array of all GET items call without any parameters.
To return all GET items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns FALSE (boolean) if there are no items in the GET.
+The function returns NULL if there are no items in the GET.
::
@@ -137,7 +131,9 @@ $this->input->cookie()
This function is identical to the post function, only it fetches cookie
data::
- $this->input->cookie('some_data', TRUE);
+ $this->input->cookie('some_cookie');
+ $this->input->cookie('some_cookie, TRUE); // with XSS filter
+
$this->input->server()
======================
@@ -202,25 +198,6 @@ parameters::
$this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
-$this->input->cookie()
-======================
-
-Lets you fetch a cookie. The first parameter will contain the name of
-the cookie you are looking for (including any prefixes)::
-
- cookie('some_cookie');
-
-The function returns FALSE (boolean) if the item you are attempting to
-retrieve does not exist.
-
-The second optional parameter lets you run the data through the XSS
-filter. It's enabled by setting the second parameter to boolean TRUE;
-
-::
-
- cookie('some_cookie', TRUE);
-
-
$this->input->ip_address()
===========================
@@ -249,6 +226,9 @@ validates the IP automatically.
echo 'Valid';
}
+Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
+an IP format. The default checks for both formats.
+
$this->input->user_agent()
===========================
diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst
index 2090404bf..615aba1c2 100644
--- a/user_guide_src/source/libraries/loader.rst
+++ b/user_guide_src/source/libraries/loader.rst
@@ -4,6 +4,7 @@ Loader Class
Loader, as the name suggests, is used to load elements. These elements
can be libraries (classes) :doc:`View files <../general/views>`,
+:doc:`Drivers <../general/drivers>`,
:doc:`Helpers <../general/helpers>`,
:doc:`Models <../general/models>`, or your own files.
@@ -74,6 +75,70 @@ Assigning a Library to a different object name
If the third (optional) parameter is blank, the library will usually be
assigned to an object with the same name as the library. For example, if
+the library is named Calendar, it will be assigned to a variable named
+$this->calendar.
+
+If you prefer to set your own class names you can pass its value to the
+third parameter::
+
+ $this->load->library('calendar', '', 'my_calendar');
+
+ // Calendar class is now accessed using:
+
+ $this->my_calendar
+
+Please take note, when multiple libraries are supplied in an array for
+the first parameter, this parameter is discarded.
+
+$this->load->driver('parent_name', $config, 'object name')
+===========================================================
+
+This function is used to load driver libraries. Where parent_name is the
+name of the parent class you want to load.
+
+As an example, if you would like to use sessions with CodeIgniter, the first
+step is to load the session driver within your controller::
+
+ $this->load->driver('session');
+
+Once loaded, the library will be ready for use, using
+$this->session->*some_function*().
+
+Driver files must be stored in a subdirectory within the main
+"libraries" folder, or within your personal application/libraries
+folder. The subdirectory must match the parent class name. Read the
+:doc:`Drivers <../general/drivers>` description for details.
+
+Additionally, multiple driver libraries can be loaded at the same time by
+passing an array of drivers to the load function.
+
+::
+
+ $this->load->driver(array('session', 'cache'));
+
+Setting options
+---------------
+
+The second (optional) parameter allows you to optionally pass
+configuration settings. You will typically pass these as an array::
+
+ $config = array (
+ 'sess_driver' => 'cookie',
+ 'sess_encrypt_cookie' => true,
+ 'encryption_key' => 'mysecretkey'
+ );
+
+ $this->load->driver('session', $config);
+
+Config options can usually also be set via a config file. Each library
+is explained in detail in its own page, so please read the information
+regarding each one you would like to use.
+
+Assigning a Driver to a different object name
+----------------------------------------------
+
+If the third (optional) parameter is blank, the library will be assigned
+to an object with the same name as the parent class. For example, if
the library is named Session, it will be assigned to a variable named
$this->session.
@@ -86,8 +151,8 @@ third parameter::
$this->my_session
-Please take note, when multiple libraries are supplied in an array for
-the first parameter, this parameter is discarded.
+.. note:: Driver libraries may also be loaded with the library() method,
+ but it is faster to use driver()
$this->load->view('file_name', $data, true/false)
==================================================
@@ -116,12 +181,12 @@ assign it to a variable if you want the data returned::
$string = $this->load->view('myfile', '', true);
-$this->load->model('Model_name');
+$this->load->model('model_name');
==================================
::
- $this->load->model('Model_name');
+ $this->load->model('model_name');
If your model is located in a sub-folder, include the relative path from
@@ -134,7 +199,7 @@ application/models/blog/queries.php you'll load it using::
If you would like your model assigned to a different object name you can
specify it via the second parameter of the loading function::
- $this->load->model('Model_name', 'fubar');
+ $this->load->model('model_name', 'fubar');
$this->fubar->function();
@@ -279,6 +344,6 @@ calling add_package_path().
$this->load->remove_package_path(APPPATH.'my_app');
// Again without the second parameter:
- $this->load->add_package_path(APPPATH.'my_app', TRUE);
+ $this->load->add_package_path(APPPATH.'my_app');
$this->load->view('my_app_index'); // Loads
- $this->load->view('welcome_message'); // Loads \ No newline at end of file
+ $this->load->view('welcome_message'); // Loads
diff --git a/user_guide_src/source/libraries/migration.rst b/user_guide_src/source/libraries/migration.rst
index 5192f1f29..cb7d96a6d 100644
--- a/user_guide_src/source/libraries/migration.rst
+++ b/user_guide_src/source/libraries/migration.rst
@@ -2,4 +2,136 @@
Migrations Class
################
-Coming soon. \ No newline at end of file
+Migrations are a convenient way for you to alter your database in a
+structured and organized manner. You could edit fragments of SQL by hand
+but you would then be responsible for telling other developers that they
+need to go and run them. You would also have to keep track of which changes
+need to be run against the production machines next time you deploy.
+
+The database table **migration** tracks which migrations have already been
+run so all you have to do is update your application files and
+call **$this->migrate->current()** to work out which migrations should be run.
+The current version is found in **config/migration.php**.
+
+******************
+Create a Migration
+******************
+
+.. note:: Each Migration is run in numerical order forward or backwards
+ depending on the method taken. Use a prefix of 3 numbers followed by an
+ underscore for the filename of your migration.
+
+This will be the first migration for a new site which has a blog. All
+migrations go in the folder **application/migrations/** and have names such
+as: **001_add_blog.php**.::
+
+ defined('BASEPATH') OR exit('No direct script access allowed');
+
+ class Migration_Add_blog extends CI_Migration {
+
+ public function up()
+ {
+ $this->dbforge->add_field(array(
+ 'blog_id' => array(
+ 'type' => 'INT',
+ 'constraint' => 5,
+ 'unsigned' => TRUE,
+ 'auto_increment' => TRUE
+ ),
+ 'blog_title' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => '100',
+ ),
+ 'blog_description' => array(
+ 'type' => 'TEXT',
+ 'null' => TRUE,
+ ),
+ ));
+
+ $this->dbforge->create_table('blog');
+ }
+
+ public function down()
+ {
+ $this->dbforge->drop_table('blog');
+ }
+
+Then in **application/config/migration.php** set **$config['migration_version'] = 1;**.
+
+*************
+Usage Example
+*************
+
+In this example some simple code is placed in **application/controllers/migrate.php**
+to update the schema.::
+
+ $this->load->library('migration');
+
+ if ( ! $this->migration->current())
+ {
+ show_error($this->migration->error_string());
+ }
+
+******************
+Function Reference
+******************
+
+There are five available methods for the Migration class:
+
+- $this->migration->current();
+- $this->migration->error_string();
+- $this->migration->find_migrations();
+- $this->migration->latest();
+- $this->migration->version();
+
+$this->migration->current()
+============================
+
+The current migration is whatever is set for **$config['migration_version']** in
+**application/config/migration.php**.
+
+$this->migration->error_string()
+=================================
+
+This returns a string of errors while performing a migration.
+
+$this->migration->find_migrations()
+====================================
+
+An array of migration filenames are returned that are found in the **migration_path**
+property.
+
+$this->migration->latest()
+===========================
+
+This works much the same way as current() but instead of looking for
+the **$config['migration_version']** the Migration class will use the very
+newest migration found in the filesystem.
+
+$this->migration->version()
+============================
+
+Version can be used to roll back changes or step forwards programmatically to
+specific versions. It works just like current but ignores **$config['migration_version']**.::
+
+ $this->load->library('migration');
+
+ $this->migration->version(5);
+
+*********************
+Migration Preferences
+*********************
+
+The following is a table of all the config options for migrations.
+
+========================== ====================== ============= =============================================
+Preference Default Options Description
+========================== ====================== ============= =============================================
+**migration_enabled** FALSE TRUE / FALSE Enable or disable migrations.
+**migration_path** APPPATH.'migrations/' None The path to your migrations folder.
+**migration_version** 0 None The current version your database should use.
+**migration_table** migrations None The table name for storing the shema
+ version number.
+**migration_auto_latest** FALSE TRUE / FALSE Enable or disable automatically
+ running migrations.
+========================== ====================== ============= =============================================
diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst
index baceaae7b..0472d14cf 100644
--- a/user_guide_src/source/libraries/output.rst
+++ b/user_guide_src/source/libraries/output.rst
@@ -49,6 +49,10 @@ data, JPEG's, XML, etc easily.
.. important:: Make sure any non-mime string you pass to this method
exists in config/mimes.php or it will have no effect.
+You can also set the character set of the document, by passing a second argument::
+
+ $this->output->set_content_type('css', 'utf-8');
+
$this->output->get_content_type();
==========================================
diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst
index f1653c913..d9d3f5092 100644
--- a/user_guide_src/source/libraries/pagination.rst
+++ b/user_guide_src/source/libraries/pagination.rst
@@ -21,9 +21,9 @@ Here is a simple example showing how to create pagination in one of your
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
- $config['per_page'] = 20;
+ $config['per_page'] = 20;
- $this->pagination->initialize($config);
+ $this->pagination->initialize($config);
echo $this->pagination->create_links();
@@ -80,8 +80,8 @@ The number of "digit" links you would like before and after the selected
page number. For example, the number 2 will place two digits on either
side, as in the example links at the very top of this page.
-$config['use_page_number'] = TRUE;
-==================================
+$config['use_page_numbers'] = TRUE;
+===================================
By default, the URI segment will use the starting index for the items
you are paginating. If you prefer to show the the actual page number,
@@ -112,6 +112,33 @@ the pagination link will become.
Note that "per_page" is the default query string passed, however can be
configured using $config['query_string_segment'] = 'your_string'
+$config['reuse_query_string'] = FALSE;
+======================================
+
+By default your Query String arguments (nothing to do with other
+query string options) will be ignored. Setting this config to
+TRUE will add existing query string arguments back into the
+URL after the URI segment and before the suffix
+
+::
+
+ http://example.com/index.php/test/page/20?query=search%term
+
+This helps you mix together normal :doc:`URI Segments <../general/urls>`
+as well as query string arguments, which until 3.0 was not possible.
+
+$config['prefix'] = '';
+==================================
+
+A custom prefix added to the path. The prefix value will be right before
+the offset segment.
+
+$config['suffix'] = '';
+==================================
+
+A custom suffix added to the path. The sufix value will be right after
+the offset segment.
+
***********************
Adding Enclosing Markup
***********************
@@ -247,10 +274,30 @@ adding::
$config['display_pages'] = FALSE;
-******************************
-Adding a class to every anchor
-******************************
+****************************
+Adding attributes to anchors
+****************************
+
+If you want to add an extra attribute to be added to every link rendered
+by the pagination class, you can set them as key/value pairs in the
+"attributes" config
+
+::
+
+ // Produces: class="myclass"
+ $config['attributes'] = array('class' => 'myclass');
+
+.. note:: Usage of the old method of setting classes via "anchor_class"
+ is deprecated.
+
+*****************************
+Disabling the "rel" attribute
+*****************************
+
+By default the rel attribute is dynamically generated and appended to
+the appropriate anchors. If for some reason you want to turn it off,
+you can pass boolean FALSE as a regular attribute
+
+::
-If you want to add a class attribute to every link rendered by the
-pagination class, you can set the config "anchor_class" equal to the
-classname you want.
+ $config['attributes']['rel'] = FALSE; \ No newline at end of file
diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst
index e8332ee97..dd9e8cbb4 100644
--- a/user_guide_src/source/libraries/sessions.rst
+++ b/user_guide_src/source/libraries/sessions.rst
@@ -1,29 +1,19 @@
-#############
-Session Class
-#############
+##############
+Session Driver
+##############
The Session class permits you maintain a user's "state" and track their
-activity while they browse your site. The Session class stores session
-information for each user as serialized (and optionally encrypted) data
-in a cookie. It can also store the session data in a database table for
-added security, as this permits the session ID in the user's cookie to
-be matched against the stored session ID. By default only the cookie is
-saved. If you choose to use the database option you'll need to create
-the session table as indicated below.
-
-.. note:: The Session class does **not** utilize native PHP sessions. It
- generates its own session data, offering more flexibility for
- developers.
-
-.. note:: Even if you are not using encrypted sessions, you must set
- an :doc:`encryption key <./encryption>` in your config file which is used
- to aid in preventing session data manipulation.
+activity while they browse your site. CodeIgniter offers two default
+session drivers: the classic `Cookie Driver`_, and the `Native Driver`_,
+which supports usage of the native PHP Session mechanism. In addition,
+you may create your own `Custom Drivers`_ to store session data however
+you wish, while still taking advantage of the features of the Session class.
Initializing a Session
======================
Sessions will typically run globally with each page load, so the session
-class must either be :doc:`initialized <../general/libraries>` in your
+class must either be :doc:`initialized <../general/drivers>` in your
:doc:`controller <../general/controllers>` constructors, or it can be
:doc:`auto-loaded <../general/autoloader>` by the system. For the most
part the session class will run unattended in the background, so simply
@@ -31,22 +21,25 @@ initializing the class will cause it to read, create, and update
sessions.
To initialize the Session class manually in your controller constructor,
-use the $this->load->library function::
+use the $this->load->driver function::
- $this->load->library('session');
+ $this->load->driver('session');
Once loaded, the Sessions library object will be available using:
$this->session
+.. note:: For backward compatibility, the Session class may stil be loaded
+ using the $this->load->library function, but converting your applications
+ to use $this->load->driver is strongly recommended.
+
How do Sessions work?
=====================
When a page is loaded, the session class will check to see if valid
-session data exists in the user's session cookie. If sessions data does
-**not** exist (or if it has expired) a new session will be created and
-saved in the cookie. If a session does exist, its information will be
-updated and the cookie will be updated. With each update, the
-session_id will be regenerated.
+session data exists in the user's session. If sessions data does **not**
+exist (or if it has expired) a new session will be created and saved.
+If a session does exist, its information will be updated. With each update,
+the session_id will be regenerated.
It's important for you to understand that once initialized, the Session
class runs automatically. There is nothing you need to do to cause the
@@ -79,19 +72,12 @@ prototype::
'last_activity' => timestamp
)
-If you have the encryption option enabled, the serialized array will be
-encrypted before being stored in the cookie, making the data highly
-secure and impervious to being read or altered by someone. More info
-regarding encryption can be :doc:`found here <encryption>`, although
-the Session class will take care of initializing and encrypting the data
-automatically.
-
-Note: Session cookies are only updated every five minutes by default to
-reduce processor load. If you repeatedly reload a page you'll notice
-that the "last activity" time only updates if five minutes or more has
-passed since the last time the cookie was written. This time is
-configurable by changing the $config['sess_time_to_update'] line in
-your system/config/config.php file.
+.. note:: Sessions are only updated every five minutes by default to
+ reduce processor load. If you repeatedly reload a page you'll notice
+ that the "last activity" time only updates if five minutes or more has
+ passed since the last time the cookie was written. This time is
+ configurable by changing the $config['sess_time_to_update'] line in
+ your system/config/config.php file.
Retrieving Session Data
=======================
@@ -106,7 +92,7 @@ fetch. For example, to fetch the session ID you will do this::
$session_id = $this->session->userdata('session_id');
-.. note:: The function returns FALSE (boolean) if the item you are
+.. note:: The function returns NULL if the item you are
trying to access does not exist.
Adding Custom Session Data
@@ -117,7 +103,7 @@ to it and it will be stored in the user's cookie. Why would you want to
do this? Here's one example:
Let's say a particular user logs into your site. Once authenticated, you
-could add their username and email address to the session cookie, making
+could add their username and email address to the session, making
that data globally available to you without having to run a database
query when you need it.
@@ -144,11 +130,11 @@ supports this syntax.
$this->session->set_userdata('some_name', 'some_value');
+If you want to verify that a userdata value exists, call has_userdata().
-.. note:: Cookies can only hold 4KB of data, so be careful not to exceed
- the capacity. The encryption process in particular produces a longer
- data string than the original so keep careful track of how much data you
- are storing.
+::
+
+ $this->session->has_userdata('some_name');
Retrieving All Session Data
===========================
@@ -195,8 +181,8 @@ available for the next server request, and are then automatically
cleared. These can be very useful, and are typically used for
informational or status messages (for example: "record 2 deleted").
-Note: Flash variables are prefaced with "flash\_" so avoid this prefix
-in your own session names.
+.. note:: Flash variables are prefaced with "flash\_" so avoid this prefix
+ in your own session names.
To add flashdata::
@@ -222,9 +208,162 @@ additional request, you can do so using the keep_flashdata() function.
$this->session->keep_flashdata('item');
+Tempdata
+========
+
+CodeIgniter also supports "tempdata", or session data with a specific
+expiration time. After the value expires, or the session expires or is
+deleted, the value is automatically removed.
+
+To add tempdata::
+
+ $expire = 300; // Expire in 5 minutes
+
+ $this->session->set_tempdata('item', 'value', $expire);
+
+You can also pass an array to set_tempdata()::
+
+ $tempdata = array('newuser' => TRUE, 'message' => 'Thanks for joining!');
+
+ $this->session->set_tempdata($tempdata, '', $expire);
+
+.. note:: If the expiration is omitted or set to 0, the default expiration of
+ 5 minutes will be used.
+
+To read a tempdata variable::
+
+ $this->session->tempdata('item');
+
+If you need to remove a tempdata value before it expires,
+use unset_tempdata()::
+
+ $this->session->unset_tempdata('item');
+
+Destroying a Session
+====================
+
+To clear the current session::
+
+ $this->session->sess_destroy();
+
+.. note:: This function should be the last one called, and even flash
+ variables will no longer be available. If you only want some items
+ destroyed and not all, use unset_userdata().
+
+Session Preferences
+===================
+
+You'll find the following Session related preferences in your
+application/config/config.php file:
+
+=========================== =============== =========================== ==========================================================================
+Preference Default Options Description
+=========================== =============== =========================== ==========================================================================
+**sess_driver** cookie cookie/native/*custom* The initial session driver to load.
+**sess_valid_drivers** cookie, native None Additional valid drivers which may be loaded.
+**sess_cookie_name** ci_session None The name you want the session cookie saved as (data for Cookie driver or
+ session ID for Native driver).
+**sess_expiration** 7200 None The number of seconds you would like the session to last. The default
+ value is 2 hours (7200 seconds). If you would like a non-expiring
+ session set the value to zero: 0
+**sess_expire_on_close** FALSE TRUE/FALSE (boolean) Whether to cause the session to expire automatically when the browser
+ window is closed.
+**sess_encrypt_cookie** FALSE TRUE/FALSE (boolean) Whether to encrypt the session data (Cookie driver only).
+**sess_use_database** FALSE TRUE/FALSE (boolean) Whether to save the session data to a database. You must create the
+ table before enabling this option (Cookie driver only).
+**sess_table_name** ci_sessions Any valid SQL table name The name of the session database table (Cookie driver only).
+**sess_time_to_update** 300 Time in seconds This options controls how often the session class will regenerate itself
+ and create a new session id.
+**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to match the user's IP address when reading the session data.
+ Note that some ISPs dynamically changes the IP, so if you want a
+ non-expiring session you will likely set this to FALSE.
+**sess_match_useragent** TRUE TRUE/FALSE (boolean) Whether to match the User Agent when reading the session data.
+=========================== =============== =========================== ==========================================================================
+
+In addition to the values above, the cookie and native drivers apply the
+following configuration values shared by the :doc:`Input <input>` and
+:doc:`Security <security>` classes:
+
+=========================== =============== ==========================================================================
+Preference Default Description
+=========================== =============== ==========================================================================
+**cookie_prefix** '' Set a cookie name prefix in order to avoid name collisions
+**cookie_domain** '' The domain for which the session is applicable
+**cookie_path** / The path to which the session is applicable
+=========================== =============== ==========================================================================
+
+Session Drivers
+===============
+
+By default, the `Cookie Driver`_ is loaded when a session is initialized.
+However, any valid driver may be selected with the $config['sess_driver']
+line in your config.php file.
+
+The session driver library comes with the cookie and native drivers
+installed, and `Custom Drivers`_ may also be installed by the user.
+
+Typically, only one driver will be used at a time, but CodeIgniter does
+support loading multiple drivers. If a specific valid driver is called, it
+will be automatically loaded. Or, an additional driver may be explicitly
+loaded by calling load_driver()::
+
+ $this->session->load_driver('native');
+
+The Session library keeps track of the most recently selected driver to call
+for driver methods. Normally, session class methods are called directly on
+the parent class, as illustrated above. However, any methods called through
+a specific driver will select that driver before invoking the parent method.
+
+So, alternation between multiple drivers can be achieved by specifying which
+driver to use for each call::
+
+ $this->session->native->set_userdata('foo', 'bar');
+
+ $this->session->cookie->userdata('foo');
+
+ $this->session->native->unset_userdata('foo');
+
+Notice in the previous example that the *native* userdata value 'foo'
+would be set to 'bar', which would NOT be returned by the call for
+the *cookie* userdata 'foo', nor would the *cookie* value be unset by
+the call to unset the *native* 'foo' value. The drivers maintain independent
+sets of values, regardless of key names.
+
+A specific driver may also be explicitly selected for use by pursuant
+methods with the select_driver() call::
+
+ $this->session->select_driver('native');
+
+ $this->session->userdata('item'); // Uses the native driver
+
+Cookie Driver
+-------------
+
+The Cookie driver stores session information for each user as serialized
+(and optionally encrypted) data in a cookie. It can also store the session
+data in a database table for added security, as this permits the session ID
+in the user's cookie to be matched against the stored session ID. By default
+only the cookie is saved. If you choose to use the database option you'll
+need to create the session table as indicated below.
+
+If you have the encryption option enabled, the serialized array will be
+encrypted before being stored in the cookie, making the data highly
+secure and impervious to being read or altered by someone. More info
+regarding encryption can be :doc:`found here <encryption>`, although
+the Session class will take care of initializing and encrypting the data
+automatically.
+
+.. note:: Even if you are not using encrypted sessions, you must set
+ an :doc:`encryption key <./encryption>` in your config file which is used
+ to aid in preventing session data manipulation.
+
+.. note:: Cookies can only hold 4KB of data, so be careful not to exceed
+ the capacity. The encryption process in particular produces a longer
+ data string than the original so keep careful track of how much data you
+ are storing.
Saving Session Data to a Database
-=================================
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
While the session data array stored in the user's cookie contains a
Session ID, unless you store session data in a database there is no way
@@ -245,7 +384,7 @@ session class::
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
- ip_address varchar(16) DEFAULT '0' NOT NULL,
+ ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
@@ -267,44 +406,83 @@ session class::
$config['sess_table_name'] = 'ci_sessions';
-.. note:: The Session class has built-in garbage collection which clears
+.. note:: The Cookie driver has built-in garbage collection which clears
out expired sessions so you do not need to write your own routine to do
it.
-Destroying a Session
-====================
+Native Driver
+-------------
-To clear the current session::
+The Native driver relies on native PHP sessions to store data in the
+$_SESSION superglobal array. All stored values continue to be available
+through $_SESSION, but flash- and temp- data items carry special prefixes.
- $this->session->sess_destroy();
+Custom Drivers
+--------------
-.. note:: This function should be the last one called, and even flash
- variables will no longer be available. If you only want some items
- destroyed and not all, use unset_userdata().
+You may also :doc:`create your own <../general/creating_drivers>` custom
+session drivers. A session driver basically manages an array of name/value
+pairs with some sort of storage mechanism.
-Session Preferences
-===================
+To make a new driver, extend CI_Session_driver. Overload the initialize()
+method and read or create session data. Then implement a save handler to
+write changed data to storage (sess_save), a destroy handler to remove
+deleted data (sess_destroy), a regenerate handler to make a new session ID
+(sess_regenerate), and an access handler to expose the data (get_userdata).
+Your initial class might look like::
-You'll find the following Session related preferences in your
-application/config/config.php file:
+ class CI_Session_custom extends CI_Session_driver {
+ protected function initialize()
+ {
+ // Read existing session data or create a new one
+ }
+
+ public function sess_save()
+ {
+ // Save current data to storage
+ }
+
+ public function sess_destroy()
+ {
+ // Destroy the current session and clean up storage
+ }
+
+ public function sess_regenerate()
+ {
+ // Create new session ID
+ }
+
+ public function &get_userdata()
+ {
+ // Return a reference to your userdata array
+ }
+ }
+
+Notice that get_userdata() returns a reference so the parent library is
+accessing the same array the driver object is using. This saves memory
+and avoids synchronization issues during usage.
+
+Put your driver in the libraries/Session/drivers folder anywhere in your
+package paths. This includes the application directory, the system directory,
+or any path you add with $CI->load->add_package_path(). Your driver must be
+named CI_Session_<name>, and your filename must be Session_<name>.php,
+preferably also capitalized, such as::
+
+ CI_Session_foo in libraries/Session/drivers/Session_foo.php
+
+Then specify the driver by setting 'sess_driver' in your config.php file or as a
+parameter when loading the CI_Session object::
+
+ $config['sess_driver'] = 'foo';
+
+OR::
+
+ $CI->load->driver('session', array('sess_driver' => 'foo'));
+
+The driver specified by 'sess_driver' is automatically included as a valid
+driver. However, if you want to make a custom driver available as an option
+without making it the initially loaded driver, set 'sess_valid_drivers' in
+your config.php file to an array including your driver name::
+
+ $config['sess_valid_drivers'] = array('sess_driver');
-=========================== =============== =========================== ==========================================================================
-Preference Default Options Description
-=========================== =============== =========================== ==========================================================================
-**sess_cookie_name** ci_session None The name you want the session cookie saved as.
-**sess_expiration** 7200 None The number of seconds you would like the session to last. The default
- value is 2 hours (7200 seconds). If you would like a non-expiring
- session set the value to zero: 0
-**sess_expire_on_close** FALSE TRUE/FALSE (boolean) Whether to cause the session to expire automatically when the browser
- window is closed.
-**sess_encrypt_cookie** FALSE TRUE/FALSE (boolean) Whether to encrypt the session data.
-**sess_use_database** FALSE TRUE/FALSE (boolean) Whether to save the session data to a database. You must create the
- table before enabling this option.
-**sess_table_name** ci_sessions Any valid SQL table name The name of the session database table.
-**sess_time_to_update** 300 Time in seconds This options controls how often the session class will regenerate itself
- and create a new session id.
-**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to match the user's IP address when reading the session data.
- Note that some ISPs dynamically changes the IP, so if you want a
- non-expiring session you will likely set this to FALSE.
-**sess_match_useragent** TRUE TRUE/FALSE (boolean) Whether to match the User Agent when reading the session data.
-=========================== =============== =========================== ========================================================================== \ No newline at end of file
diff --git a/user_guide_src/source/libraries/trackback.rst b/user_guide_src/source/libraries/trackback.rst
index 07b2b2177..f9e0df882 100644
--- a/user_guide_src/source/libraries/trackback.rst
+++ b/user_guide_src/source/libraries/trackback.rst
@@ -114,7 +114,7 @@ store them. Here is a basic prototype for such a table::
excerpt text NOT NULL,
blog_name varchar(100) NOT NULL,
tb_date int(10) NOT NULL,
- ip_address varchar(16) NOT NULL,
+ ip_address varchar(45) NOT NULL,
PRIMARY KEY `tb_id` (`tb_id`),
KEY `entry_id` (`entry_id`)
);
diff --git a/user_guide_src/source/libraries/uri.rst b/user_guide_src/source/libraries/uri.rst
index ee60b77d7..bb959b002 100644
--- a/user_guide_src/source/libraries/uri.rst
+++ b/user_guide_src/source/libraries/uri.rst
@@ -25,7 +25,7 @@ The segment numbers would be this:
#. metro
#. crime_is_up
-By default the function returns FALSE (boolean) if the segment does not
+By default the function returns NULL if the segment does not
exist. There is an optional second parameter that permits you to set
your own default value if the segment is missing. For example, this
would tell the function to return the number zero in the event of
@@ -146,7 +146,7 @@ full URL::
The function would return this::
- /news/local/345
+ news/local/345
$this->uri->ruri_string()
==========================
diff --git a/license_afl.rst b/user_guide_src/source/license_afl.rst
index ca39be9b6..ca39be9b6 100644
--- a/license_afl.rst
+++ b/user_guide_src/source/license_afl.rst
diff --git a/user_guide_src/source/overview/cheatsheets.rst b/user_guide_src/source/overview/cheatsheets.rst
index 2e277aa9a..80c3112c4 100644
--- a/user_guide_src/source/overview/cheatsheets.rst
+++ b/user_guide_src/source/overview/cheatsheets.rst
@@ -5,12 +5,19 @@ CodeIgniter Cheatsheets
Library Reference
=================
-`|CodeIgniter Library
-Reference| <../images/codeigniter_1.7.1_library_reference.pdf>`_
+|CodeIgniter Library Reference|
+
+- :download:`Download PDF <../images/codeigniter_1.7.1_library_reference.pdf>`
+
Helpers Reference
=================
-`|image1| <../images/codeigniter_1.7.1_helper_reference.pdf>`_
+|CodeIgniter Helper Reference|
+
+- :download:`Download PDF <../images/codeigniter_1.7.1_helper_reference.pdf>`
+
.. |CodeIgniter Library Reference| image:: ../images/codeigniter_1.7.1_library_reference.png
-.. |image1| image:: ../images/codeigniter_1.7.1_helper_reference.png
+ :target: ../_downloads/codeigniter_1.7.1_library_reference.pdf
+.. |CodeIgniter Helper Reference| image:: ../images/codeigniter_1.7.1_helper_reference.png
+ :target: ../_downloads/codeigniter_1.7.1_helper_reference.pdf