From 308e10dc7a523e1d13caedaf89744c3710a01a55 Mon Sep 17 00:00:00 2001 From: Ryan Syah Erwin <54809074+dendengnenek@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:15:40 +0700 Subject: [PATCH 1/6] Add files via upload --- application/views/view_login.php | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 application/views/view_login.php diff --git a/application/views/view_login.php b/application/views/view_login.php new file mode 100644 index 00000000000..4c6cfd679d8 --- /dev/null +++ b/application/views/view_login.php @@ -0,0 +1,66 @@ + + + + Vietgram | Login + + + + + + + + +
+
+ +
+
+ + + +
+
+ + + \ No newline at end of file From 6724842950d163ab9768b72b2bca29a16f64e2a6 Mon Sep 17 00:00:00 2001 From: Ryan Syah Erwin <54809074+dendengnenek@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:18:02 +0700 Subject: [PATCH 2/6] Add files via upload --- application/controllers/Login.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 application/controllers/Login.php diff --git a/application/controllers/Login.php b/application/controllers/Login.php new file mode 100644 index 00000000000..8119fbf141e --- /dev/null +++ b/application/controllers/Login.php @@ -0,0 +1,14 @@ +load->view('view_login'); + } + +} + +/* End of file Login.php */ +/* Location: ./application/controllers/Login.php */ \ No newline at end of file From 46e4d6088777902c1a6c36fbae54af51d58ecbf8 Mon Sep 17 00:00:00 2001 From: Ryan Syah Erwin <54809074+dendengnenek@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:22:44 +0700 Subject: [PATCH 3/6] Update config.php --- application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/config.php b/application/config/config.php index 782b19c74b6..e000ab45623 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = ''; +$config['base_url'] = 'http://localhost/CodeIgniter'; /* |-------------------------------------------------------------------------- From 4696c41572022f29a7adedaed174fbe1813a239f Mon Sep 17 00:00:00 2001 From: Ryan Syah Erwin <54809074+dendengnenek@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:24:03 +0700 Subject: [PATCH 4/6] Update database.php --- application/config/database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/database.php b/application/config/database.php index 77748959f9f..1e65c34463b 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -76,7 +76,7 @@ $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => '', + 'username' => 'root', 'password' => '', 'database' => '', 'dbdriver' => 'mysqli', From 11783936aa9804c306875b1b382e5751dc767a11 Mon Sep 17 00:00:00 2001 From: Ryan Syah Erwin <54809074+dendengnenek@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:25:05 +0700 Subject: [PATCH 5/6] Update routes.php --- application/config/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/routes.php b/application/config/routes.php index 8ebf62bfa43..e7355b59e34 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -49,6 +49,6 @@ | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = 'welcome'; +$route['default_controller'] = 'login'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; From 084a3a0816bbce14da5c3b8c3a410737c429d562 Mon Sep 17 00:00:00 2001 From: dendengnenek Date: Sun, 19 Apr 2020 01:28:30 +0700 Subject: [PATCH 6/6] bebas --- .gitattributes | 25 - .htaccess | 4 + .travis.yml | 63 - application/cache/index.html | 2 +- application/config/autoload.php | 4 +- application/config/config.php | 74 +- application/config/constants.php | 4 +- application/config/database.php | 4 +- application/config/index.html | 2 +- application/config/routes.php | 6 +- application/config/smileys.php | 64 + application/config/user_agents.php | 3 +- application/controllers/Login.php | 28 +- application/controllers/User.php | 72 ++ application/controllers/index.html | 2 +- application/core/index.html | 2 +- application/helpers/index.html | 2 +- application/hooks/index.html | 2 +- application/index.html | 2 +- application/language/english/index.html | 2 +- application/language/index.html | 2 +- application/libraries/index.html | 2 +- application/logs/index.html | 2 +- application/models/index.html | 2 +- application/models/userM.php | 31 + application/third_party/index.html | 2 +- application/views/add-photo.php | 112 ++ application/views/edit-profile.php | 113 ++ application/views/errors/cli/index.html | 2 +- application/views/errors/html/error_404.php | 115 +- application/views/errors/html/error_db.php | 115 +- .../views/errors/html/error_exception.php | 38 +- .../views/errors/html/error_general.php | 115 +- application/views/errors/html/error_php.php | 38 +- application/views/errors/html/index.html | 2 +- application/views/errors/index.html | 2 +- application/views/feed.php | 112 ++ application/views/index.html | 2 +- application/views/profile.php | 114 ++ application/views/view_login.php | 3 +- application/views/welcome_message.php | 80 +- assets/css/edit-profile.css | 100 ++ assets/css/explore.css | 70 ++ assets/css/feed.css | 101 ++ assets/css/footer.css | 30 + assets/css/globals.css | 21 + assets/css/login.css | 128 ++ assets/css/mobile.css | 110 ++ assets/css/navigation.css | 77 ++ assets/css/profile.css | 161 +++ assets/css/reset.css | 124 ++ assets/css/styles.css | 12 + assets/css/variables.css | 5 + assets/images/_5b3f15962754c.jpg | Bin 0 -> 57630 bytes assets/images/_82931_M_1.jpg | Bin 0 -> 9697 bytes assets/images/_Capture.PNG | Bin 0 -> 166 bytes assets/images/_Harga-Oppo-K3-600x600.jpg | Bin 0 -> 26445 bytes assets/images/_Luna_G8_L_1.jpg | Bin 0 -> 8578 bytes assets/images/android.png | Bin 0 -> 10071 bytes assets/images/avatar.jpg | Bin 0 -> 4544 bytes assets/images/feedPhoto.jpg | Bin 0 -> 169811 bytes assets/images/feedPhoto1.jpg | Bin 0 -> 9332 bytes assets/images/ios.png | Bin 0 -> 3754 bytes assets/images/loginLogo.png | Bin 0 -> 17111 bytes assets/images/logo.png | Bin 0 -> 14740 bytes assets/images/phoneImage.png | Bin 0 -> 1029664 bytes composer.json | 4 +- contributing.md | 6 +- index.php | 9 +- phpdoc.dist.xml | 21 - readme.rst | 4 +- system/core/CodeIgniter.php | 89 +- system/core/Common.php | 14 +- system/core/Config.php | 16 +- system/core/Exceptions.php | 12 - system/core/Hooks.php | 6 +- system/core/Input.php | 285 ++++- system/core/Loader.php | 20 +- system/core/Log.php | 7 +- system/core/Model.php | 8 + system/core/Output.php | 19 +- system/core/Router.php | 43 + system/core/Security.php | 43 +- system/core/URI.php | 122 +- system/core/Utf8.php | 14 +- system/core/compat/hash.php | 8 +- system/core/compat/index.html | 2 +- system/core/compat/mbstring.php | 8 +- system/core/compat/password.php | 12 +- system/core/compat/standard.php | 50 +- system/core/index.html | 2 +- system/database/DB.php | 7 +- system/database/DB_driver.php | 101 +- system/database/DB_forge.php | 36 +- system/database/DB_query_builder.php | 148 +-- system/database/DB_utility.php | 14 +- system/database/drivers/cubrid/index.html | 2 +- system/database/drivers/ibase/index.html | 2 +- system/database/drivers/index.html | 2 +- system/database/drivers/mssql/index.html | 2 +- .../database/drivers/mssql/mssql_driver.php | 14 +- system/database/drivers/mysql/index.html | 2 +- .../database/drivers/mysql/mysql_driver.php | 57 +- system/database/drivers/mysqli/index.html | 2 +- .../database/drivers/mysqli/mysqli_driver.php | 20 +- system/database/drivers/oci8/index.html | 2 +- system/database/drivers/odbc/index.html | 2 +- system/database/drivers/pdo/index.html | 2 +- .../drivers/pdo/subdrivers/index.html | 2 +- .../pdo/subdrivers/pdo_pgsql_driver.php | 4 +- system/database/drivers/postgre/index.html | 2 +- .../drivers/postgre/postgre_driver.php | 26 +- system/database/drivers/sqlite/index.html | 11 + .../database/drivers/sqlite/sqlite_driver.php | 330 +++++ .../database/drivers/sqlite/sqlite_forge.php | 205 ++++ .../database/drivers/sqlite/sqlite_result.php | 164 +++ .../drivers/sqlite/sqlite_utility.php | 61 + system/database/drivers/sqlite3/index.html | 2 +- system/database/drivers/sqlsrv/index.html | 2 +- system/database/index.html | 2 +- system/fonts/index.html | 2 +- system/helpers/captcha_helper.php | 78 +- system/helpers/cookie_helper.php | 7 +- system/helpers/date_helper.php | 40 + system/helpers/download_helper.php | 54 +- system/helpers/email_helper.php | 84 ++ system/helpers/file_helper.php | 20 + system/helpers/form_helper.php | 22 +- system/helpers/html_helper.php | 61 +- system/helpers/index.html | 2 +- system/helpers/inflector_helper.php | 39 - system/helpers/security_helper.php | 24 + system/helpers/smiley_helper.php | 255 ++++ system/helpers/string_helper.php | 47 + system/helpers/url_helper.php | 6 +- system/index.html | 2 +- .../language/english/form_validation_lang.php | 1 - system/language/english/imglib_lang.php | 1 - system/language/english/index.html | 2 +- system/language/index.html | 2 +- system/libraries/Cache/Cache.php | 13 - system/libraries/Cache/drivers/Cache_apcu.php | 219 ---- .../Cache/drivers/Cache_memcached.php | 18 +- .../libraries/Cache/drivers/Cache_redis.php | 73 +- .../Cache/drivers/Cache_wincache.php | 2 +- system/libraries/Cache/drivers/index.html | 2 +- system/libraries/Cache/index.html | 2 +- system/libraries/Cart.php | 567 +++++++++ system/libraries/Email.php | 249 ++-- system/libraries/Encryption.php | 7 +- system/libraries/Form_validation.php | 148 +-- system/libraries/Image_lib.php | 39 +- system/libraries/Javascript.php | 856 +++++++++++++ system/libraries/Javascript/Jquery.php | 1076 +++++++++++++++++ system/libraries/Javascript/index.html | 11 + system/libraries/Pagination.php | 2 +- system/libraries/Session/Session.php | 21 +- .../Session/SessionHandlerInterface.php | 59 + .../Session/drivers/Session_redis_driver.php | 70 +- system/libraries/Session/drivers/index.html | 2 +- system/libraries/Session/index.html | 2 +- system/libraries/Table.php | 1 - system/libraries/Upload.php | 8 +- system/libraries/Xmlrpc.php | 6 +- system/libraries/Zip.php | 7 +- system/libraries/index.html | 2 +- tests/README.md | 4 +- tests/codeigniter/Setup_test.php | 13 - tests/codeigniter/core/Benchmark_test.php | 67 - tests/codeigniter/core/Common_test.php | 69 -- tests/codeigniter/core/Config_test.php | 233 ---- tests/codeigniter/core/Input_test.php | 317 ----- tests/codeigniter/core/Lang_test.php | 101 -- tests/codeigniter/core/Loader_test.php | 602 --------- tests/codeigniter/core/Log_test.php | 63 - tests/codeigniter/core/Model_test.php | 37 - tests/codeigniter/core/Output_test.php | 63 - tests/codeigniter/core/Security_test.php | 354 ------ tests/codeigniter/core/URI_test.php | 263 ---- tests/codeigniter/core/Utf8_test.php | 90 -- tests/codeigniter/core/compat/hash_test.php | 77 -- .../codeigniter/core/compat/mbstring_test.php | 54 - .../codeigniter/core/compat/password_test.php | 159 --- .../codeigniter/core/compat/standard_test.php | 346 ------ tests/codeigniter/database/DB_driver_test.php | 37 - tests/codeigniter/database/DB_test.php | 61 - .../database/query_builder/count_test.php | 48 - .../database/query_builder/delete_test.php | 64 - .../database/query_builder/distinct_test.php | 33 - .../database/query_builder/empty_test.php | 39 - .../database/query_builder/escape_test.php | 68 -- .../database/query_builder/from_test.php | 49 - .../database/query_builder/get_test.php | 53 - .../database/query_builder/group_test.php | 120 -- .../database/query_builder/insert_test.php | 66 - .../database/query_builder/join_test.php | 101 -- .../database/query_builder/like_test.php | 129 -- .../database/query_builder/limit_test.php | 48 - .../database/query_builder/order_test.php | 55 - .../database/query_builder/select_test.php | 95 -- .../database/query_builder/truncate_test.php | 56 - .../database/query_builder/update_test.php | 57 - .../database/query_builder/where_test.php | 134 -- .../codeigniter/helpers/array_helper_test.php | 45 - .../helpers/captcha_helper_test.php | 10 - .../helpers/cookie_helper_test.php | 58 - .../codeigniter/helpers/date_helper_test.php | 225 ---- .../helpers/directory_helper_test.php | 59 - .../helpers/download_helper_test.php | 10 - .../codeigniter/helpers/file_helper_test.php | 134 -- .../codeigniter/helpers/form_helper_test.php | 274 ----- .../codeigniter/helpers/html_helper_test.php | 104 -- .../helpers/inflector_helper_test.php | 115 -- .../helpers/language_helper_test.php | 16 - .../helpers/number_helper_test.php | 63 - .../codeigniter/helpers/path_helper_test.php | 30 - .../helpers/security_helper_test.php | 40 - .../helpers/string_helper_test.php | 118 -- .../codeigniter/helpers/text_helper_test.php | 179 --- tests/codeigniter/helpers/url_helper_test.php | 99 -- tests/codeigniter/helpers/xml_helper_test.php | 15 - tests/codeigniter/libraries/Calendar_test.php | 222 ---- tests/codeigniter/libraries/Driver_test.php | 178 --- tests/codeigniter/libraries/Encrypt_test.php | 79 -- .../codeigniter/libraries/Encryption_test.php | 400 ------ .../libraries/Form_validation_test.php | 667 ---------- tests/codeigniter/libraries/Parser_test.php | 95 -- tests/codeigniter/libraries/Session_test.php | 441 ------- tests/codeigniter/libraries/Table_test.php | 300 ----- .../codeigniter/libraries/Typography_test.php | 182 --- tests/codeigniter/libraries/Upload_test.php | 299 ----- .../codeigniter/libraries/Useragent_test.php | 125 -- tests/mocks/autoloader.php | 1 + tests/mocks/core/input.php | 49 + tests/mocks/core/utf8.php | 19 + tests/travis/mysql.phpunit.xml | 25 - tests/travis/mysqli.phpunit.xml | 25 - tests/travis/pdo/mysql.phpunit.xml | 25 - tests/travis/pdo/pgsql.phpunit.xml | 25 - tests/travis/pdo/sqlite.phpunit.xml | 25 - tests/travis/pgsql.phpunit.xml | 25 - tests/travis/sqlite.phpunit.xml | 25 - uploads/Capture.PNG | Bin 0 -> 166 bytes uploads/Capture1.PNG | Bin 0 -> 166 bytes uploads/Capture2.PNG | Bin 0 -> 166 bytes uploads/Capture3.PNG | Bin 0 -> 166 bytes uploads/Capture4.PNG | Bin 0 -> 166 bytes user_guide_src/README.rst | 2 +- user_guide_src/cilexer/cilexer/cilexer.py | 4 +- .../_themes/sphinx_rtd_theme/layout.html | 2 +- .../_themes/sphinx_rtd_theme/versions.html | 2 +- user_guide_src/source/changelog.rst | 215 +--- user_guide_src/source/conf.py | 4 +- user_guide_src/source/contributing/index.rst | 10 +- .../source/database/db_driver_reference.rst | 17 +- .../source/database/query_builder.rst | 98 +- .../source/general/alternative_php.rst | 16 +- user_guide_src/source/general/cli.rst | 2 +- .../source/general/common_functions.rst | 8 +- .../general/compatibility_functions.rst | 36 +- user_guide_src/source/general/controllers.rst | 2 +- user_guide_src/source/general/credits.rst | 2 +- .../source/general/requirements.rst | 8 +- user_guide_src/source/general/routing.rst | 2 +- user_guide_src/source/general/security.rst | 2 +- user_guide_src/source/general/styleguide.rst | 10 +- user_guide_src/source/general/views.rst | 8 +- .../source/helpers/captcha_helper.rst | 9 +- .../source/helpers/cookie_helper.rst | 4 +- user_guide_src/source/helpers/date_helper.rst | 41 +- .../source/helpers/download_helper.rst | 17 +- .../source/helpers/email_helper.rst | 75 ++ user_guide_src/source/helpers/file_helper.rst | 30 +- user_guide_src/source/helpers/form_helper.rst | 20 +- user_guide_src/source/helpers/html_helper.rst | 100 +- .../source/helpers/inflector_helper.rst | 16 - .../source/helpers/security_helper.rst | 27 +- .../source/helpers/smiley_helper.rst | 169 +++ .../source/helpers/string_helper.rst | 35 + user_guide_src/source/helpers/url_helper.rst | 2 +- user_guide_src/source/images/smile.gif | Bin 0 -> 1156 bytes .../source/installation/downloads.rst | 5 +- .../source/installation/upgrade_220.rst | 2 +- .../source/installation/upgrade_300.rst | 43 +- .../source/installation/upgrade_310.rst | 2 +- .../source/installation/upgrade_320.rst | 259 ---- .../source/installation/upgrading.rst | 1 - user_guide_src/source/libraries/caching.rst | 39 +- user_guide_src/source/libraries/cart.rst | 398 ++++++ user_guide_src/source/libraries/config.rst | 11 + user_guide_src/source/libraries/email.rst | 16 +- user_guide_src/source/libraries/encrypt.rst | 4 +- .../source/libraries/encryption.rst | 16 +- .../source/libraries/file_uploading.rst | 6 +- .../source/libraries/form_validation.rst | 32 +- user_guide_src/source/libraries/image_lib.rst | 4 +- user_guide_src/source/libraries/input.rst | 98 +- .../source/libraries/javascript.rst | 322 +++++ user_guide_src/source/libraries/language.rst | 2 +- user_guide_src/source/libraries/loader.rst | 4 +- user_guide_src/source/libraries/output.rst | 4 +- user_guide_src/source/libraries/parser.rst | 4 +- user_guide_src/source/libraries/sessions.rst | 16 +- user_guide_src/source/libraries/table.rst | 10 +- user_guide_src/source/libraries/trackback.rst | 2 +- user_guide_src/source/libraries/xmlrpc.rst | 2 +- .../source/overview/at_a_glance.rst | 2 +- .../source/overview/getting_started.rst | 2 +- user_guide_src/source/tutorial/conclusion.rst | 2 +- .../source/tutorial/static_pages.rst | 2 +- 310 files changed, 8561 insertions(+), 11366 deletions(-) delete mode 100644 .gitattributes create mode 100644 .htaccess delete mode 100644 .travis.yml create mode 100644 application/config/smileys.php create mode 100644 application/controllers/User.php create mode 100644 application/models/userM.php create mode 100644 application/views/add-photo.php create mode 100644 application/views/edit-profile.php create mode 100644 application/views/feed.php create mode 100644 application/views/profile.php create mode 100644 assets/css/edit-profile.css create mode 100644 assets/css/explore.css create mode 100644 assets/css/feed.css create mode 100644 assets/css/footer.css create mode 100644 assets/css/globals.css create mode 100644 assets/css/login.css create mode 100644 assets/css/mobile.css create mode 100644 assets/css/navigation.css create mode 100644 assets/css/profile.css create mode 100644 assets/css/reset.css create mode 100644 assets/css/styles.css create mode 100644 assets/css/variables.css create mode 100644 assets/images/_5b3f15962754c.jpg create mode 100644 assets/images/_82931_M_1.jpg create mode 100644 assets/images/_Capture.PNG create mode 100644 assets/images/_Harga-Oppo-K3-600x600.jpg create mode 100644 assets/images/_Luna_G8_L_1.jpg create mode 100644 assets/images/android.png create mode 100644 assets/images/avatar.jpg create mode 100644 assets/images/feedPhoto.jpg create mode 100644 assets/images/feedPhoto1.jpg create mode 100644 assets/images/ios.png create mode 100644 assets/images/loginLogo.png create mode 100644 assets/images/logo.png create mode 100644 assets/images/phoneImage.png delete mode 100644 phpdoc.dist.xml create mode 100644 system/database/drivers/sqlite/index.html create mode 100644 system/database/drivers/sqlite/sqlite_driver.php create mode 100644 system/database/drivers/sqlite/sqlite_forge.php create mode 100644 system/database/drivers/sqlite/sqlite_result.php create mode 100644 system/database/drivers/sqlite/sqlite_utility.php create mode 100644 system/helpers/email_helper.php create mode 100644 system/helpers/smiley_helper.php delete mode 100644 system/libraries/Cache/drivers/Cache_apcu.php create mode 100644 system/libraries/Cart.php create mode 100644 system/libraries/Javascript.php create mode 100644 system/libraries/Javascript/Jquery.php create mode 100644 system/libraries/Javascript/index.html create mode 100644 system/libraries/Session/SessionHandlerInterface.php delete mode 100644 tests/codeigniter/Setup_test.php delete mode 100644 tests/codeigniter/core/Benchmark_test.php delete mode 100644 tests/codeigniter/core/Common_test.php delete mode 100644 tests/codeigniter/core/Config_test.php delete mode 100644 tests/codeigniter/core/Input_test.php delete mode 100644 tests/codeigniter/core/Lang_test.php delete mode 100644 tests/codeigniter/core/Loader_test.php delete mode 100644 tests/codeigniter/core/Log_test.php delete mode 100644 tests/codeigniter/core/Model_test.php delete mode 100644 tests/codeigniter/core/Output_test.php delete mode 100644 tests/codeigniter/core/Security_test.php delete mode 100644 tests/codeigniter/core/URI_test.php delete mode 100644 tests/codeigniter/core/Utf8_test.php delete mode 100644 tests/codeigniter/core/compat/hash_test.php delete mode 100644 tests/codeigniter/core/compat/mbstring_test.php delete mode 100644 tests/codeigniter/core/compat/password_test.php delete mode 100644 tests/codeigniter/core/compat/standard_test.php delete mode 100644 tests/codeigniter/database/DB_driver_test.php delete mode 100644 tests/codeigniter/database/DB_test.php delete mode 100644 tests/codeigniter/database/query_builder/count_test.php delete mode 100644 tests/codeigniter/database/query_builder/delete_test.php delete mode 100644 tests/codeigniter/database/query_builder/distinct_test.php delete mode 100644 tests/codeigniter/database/query_builder/empty_test.php delete mode 100644 tests/codeigniter/database/query_builder/escape_test.php delete mode 100644 tests/codeigniter/database/query_builder/from_test.php delete mode 100644 tests/codeigniter/database/query_builder/get_test.php delete mode 100644 tests/codeigniter/database/query_builder/group_test.php delete mode 100644 tests/codeigniter/database/query_builder/insert_test.php delete mode 100644 tests/codeigniter/database/query_builder/join_test.php delete mode 100644 tests/codeigniter/database/query_builder/like_test.php delete mode 100644 tests/codeigniter/database/query_builder/limit_test.php delete mode 100644 tests/codeigniter/database/query_builder/order_test.php delete mode 100644 tests/codeigniter/database/query_builder/select_test.php delete mode 100644 tests/codeigniter/database/query_builder/truncate_test.php delete mode 100644 tests/codeigniter/database/query_builder/update_test.php delete mode 100644 tests/codeigniter/database/query_builder/where_test.php delete mode 100644 tests/codeigniter/helpers/array_helper_test.php delete mode 100644 tests/codeigniter/helpers/captcha_helper_test.php delete mode 100644 tests/codeigniter/helpers/cookie_helper_test.php delete mode 100644 tests/codeigniter/helpers/date_helper_test.php delete mode 100644 tests/codeigniter/helpers/directory_helper_test.php delete mode 100644 tests/codeigniter/helpers/download_helper_test.php delete mode 100644 tests/codeigniter/helpers/file_helper_test.php delete mode 100644 tests/codeigniter/helpers/form_helper_test.php delete mode 100644 tests/codeigniter/helpers/html_helper_test.php delete mode 100644 tests/codeigniter/helpers/inflector_helper_test.php delete mode 100644 tests/codeigniter/helpers/language_helper_test.php delete mode 100644 tests/codeigniter/helpers/number_helper_test.php delete mode 100644 tests/codeigniter/helpers/path_helper_test.php delete mode 100644 tests/codeigniter/helpers/security_helper_test.php delete mode 100644 tests/codeigniter/helpers/string_helper_test.php delete mode 100644 tests/codeigniter/helpers/text_helper_test.php delete mode 100644 tests/codeigniter/helpers/url_helper_test.php delete mode 100644 tests/codeigniter/helpers/xml_helper_test.php delete mode 100644 tests/codeigniter/libraries/Calendar_test.php delete mode 100644 tests/codeigniter/libraries/Driver_test.php delete mode 100644 tests/codeigniter/libraries/Encrypt_test.php delete mode 100644 tests/codeigniter/libraries/Encryption_test.php delete mode 100644 tests/codeigniter/libraries/Form_validation_test.php delete mode 100644 tests/codeigniter/libraries/Parser_test.php delete mode 100644 tests/codeigniter/libraries/Session_test.php delete mode 100644 tests/codeigniter/libraries/Table_test.php delete mode 100644 tests/codeigniter/libraries/Typography_test.php delete mode 100644 tests/codeigniter/libraries/Upload_test.php delete mode 100644 tests/codeigniter/libraries/Useragent_test.php create mode 100644 tests/mocks/core/input.php create mode 100644 tests/mocks/core/utf8.php delete mode 100644 tests/travis/mysql.phpunit.xml delete mode 100644 tests/travis/mysqli.phpunit.xml delete mode 100644 tests/travis/pdo/mysql.phpunit.xml delete mode 100644 tests/travis/pdo/pgsql.phpunit.xml delete mode 100644 tests/travis/pdo/sqlite.phpunit.xml delete mode 100644 tests/travis/pgsql.phpunit.xml delete mode 100644 tests/travis/sqlite.phpunit.xml create mode 100644 uploads/Capture.PNG create mode 100644 uploads/Capture1.PNG create mode 100644 uploads/Capture2.PNG create mode 100644 uploads/Capture3.PNG create mode 100644 uploads/Capture4.PNG create mode 100644 user_guide_src/source/helpers/email_helper.rst create mode 100644 user_guide_src/source/helpers/smiley_helper.rst create mode 100644 user_guide_src/source/images/smile.gif delete mode 100644 user_guide_src/source/installation/upgrade_320.rst create mode 100644 user_guide_src/source/libraries/cart.rst create mode 100644 user_guide_src/source/libraries/javascript.rst diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index a4296d591b8..00000000000 --- a/.gitattributes +++ /dev/null @@ -1,25 +0,0 @@ -# This file tells which files and directories should be ignored and -# NOT downloaded when using composer to pull down a project with -# the --prefer-dist option selected. Used to remove development -# specific files so user has a clean download. - -# git files -.gitattributes export-ignore -# .gitignore - -# helper config files -.travis.yml export-ignore -phpdoc.dist.xml export-ignore - -# Misc other files -readme.rst - -# They don't want all of our tests... -tests/codeigniter/ export-ignore -tests/travis/ export-ignore - -# User Guide Source Files -user_guide_src - -# User Guide Compiled Files -user_guide export-ignore diff --git a/.htaccess b/.htaccess new file mode 100644 index 00000000000..9e25198b5a4 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php/$1 [L] \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8525d5f6cef..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -language: php -dist: trusty - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4snapshot - - nightly - - hhvm-3.30 - -env: - - DB=mysql - - DB=mysqli - - DB=pgsql - - DB=sqlite - - DB=pdo/mysql - - DB=pdo/pgsql - - DB=pdo/sqlite - -sudo: false - -before_script: - - sh -c "composer install --dev --no-progress" - - 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' = 'mysqli' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi" - -script: php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml - -matrix: - allow_failures: - - php: 7.4snapshot - - php: nightly - - php: hhvm-3.30 - exclude: - - php: hhvm-3.30 - env: DB=pgsql - - php: hhvm-3.30 - env: DB=pdo/pgsql - - php: 7.0 - env: DB=mysql - - php: 7.1 - env: DB=mysql - - php: 7.2 - env: DB=mysql - - php: 7.3 - env: DB=mysql - - php: 7.4snapshot - env: DB=mysql - - php: nightly - env: DB=mysql - -branches: - only: - - develop - - 3.0-stable - - 3.1-stable - - /^feature\/.+$/ diff --git a/application/cache/index.html b/application/cache/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/cache/index.html +++ b/application/cache/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/config/autoload.php b/application/config/autoload.php index 7cdc9013c11..8ca9eb60505 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'session', 'form_validation'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('url', 'file'); /* | ------------------------------------------------------------------- diff --git a/application/config/config.php b/application/config/config.php index e000ab45623..6a12e48e2ac 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = 'http://localhost/CodeIgniter'; +$config['base_url'] = 'http://localhost/CodeIgniter/'; /* |-------------------------------------------------------------------------- @@ -35,7 +35,7 @@ | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- @@ -63,8 +63,6 @@ | For more information please see the user guide: | | https://codeigniter.com/user_guide/general/urls.html -| -| Note: This option is ignored for CLI requests. */ $config['url_suffix'] = ''; @@ -88,7 +86,7 @@ | This determines which character set is used by default in various methods | that require a character set to be provided. | -| See https://secure.php.net/htmlspecialchars for a list of supported charsets. +| See http://php.net/htmlspecialchars for a list of supported charsets. | */ $config['charset'] = 'UTF-8'; @@ -133,7 +131,7 @@ | | $config['composer_autoload'] = '/path/to/vendor/autoload.php'; | -| For more information about Composer, please visit https://getcomposer.org/ +| For more information about Composer, please visit http://getcomposer.org/ | | Note: This will NOT disable or override the CodeIgniter-specific | autoloading (application/config/autoload.php) @@ -159,8 +157,6 @@ | | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | -| Note: This option is ignored for CLI requests. -| */ $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; @@ -191,6 +187,20 @@ $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'; +/* +|-------------------------------------------------------------------------- +| Allow $_GET array +|-------------------------------------------------------------------------- +| +| By default CodeIgniter enables access to the $_GET array. If for some +| reason you would like to disable it, set 'allow_get_array' to FALSE. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['allow_get_array'] = TRUE; + /* |-------------------------------------------------------------------------- | Error Logging Threshold @@ -221,7 +231,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/logs/ directory. Use a full server path. +| application/logs/ directory. Use a full server path with trailing slash. | */ $config['log_path'] = ''; @@ -269,7 +279,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/views/errors/ directory. Use a full server path. +| application/views/errors/ directory. Use a full server path with trailing slash. | */ $config['error_views_path'] = ''; @@ -280,7 +290,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/cache/ directory. Use a full server path. +| application/cache/ directory. Use a full server path with trailing slash. | */ $config['cache_path'] = ''; @@ -396,6 +406,34 @@ $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE; +/* +|-------------------------------------------------------------------------- +| Standardize newlines +|-------------------------------------------------------------------------- +| +| Determines whether to standardize newline characters in input data, +| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['standardize_newlines'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Global XSS Filtering +|-------------------------------------------------------------------------- +| +| Determines whether the XSS filter is always active when GET, POST or +| COOKIE data is encountered +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['global_xss_filtering'] = FALSE; + /* |-------------------------------------------------------------------------- | Cross Site Request Forgery @@ -452,6 +490,20 @@ */ $config['time_reference'] = 'local'; +/* +|-------------------------------------------------------------------------- +| Rewrite PHP Short Tags +|-------------------------------------------------------------------------- +| +| If your PHP installation does not have short tag support enabled CI +| can rewrite the tags on-the-fly, enabling you to utilize that syntax +| in your view files. Options are TRUE or FALSE (boolean) +| +| Note: You need to have eval() enabled for this to work. +| +*/ +$config['rewrite_short_tags'] = FALSE; + /* |-------------------------------------------------------------------------- | Reverse Proxy IPs diff --git a/application/config/constants.php b/application/config/constants.php index fb58784477c..18d3b4b76ff 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -65,10 +65,10 @@ | are as follows: | | Standard C/C++ Library (stdlibc): -| https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html +| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html | (This link also contains other GNU-specific conventions) | BSD sysexits.h: -| https://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits +| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits | Bash scripting: | http://tldp.org/LDP/abs/html/exitcodes.html | diff --git a/application/config/database.php b/application/config/database.php index 1e65c34463b..526c26d97cb 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -22,7 +22,7 @@ | ['dbdriver'] The database driver. e.g.: mysqli. | Currently supported: | cubrid, ibase, mssql, mysql, mysqli, oci8, -| odbc, pdo, postgre, sqlite3, sqlsrv +| 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 | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection @@ -78,7 +78,7 @@ 'hostname' => 'localhost', 'username' => 'root', 'password' => '', - 'database' => '', + 'database' => 'vietgram', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, diff --git a/application/config/index.html b/application/config/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/config/index.html +++ b/application/config/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/config/routes.php b/application/config/routes.php index e7355b59e34..aaea762ed3c 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -43,12 +43,12 @@ | This is not exactly a route, but allows you to automatically route | controller and method names that contain dashes. '-' isn't a valid | class or method name character, so it requires translation. -| When you set this option to TRUE, it will replace ALL dashes with -| underscores in the controller and method URI segments. +| When you set this option to TRUE, it will replace ALL dashes in the +| controller and method URI segments. | | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = 'login'; +$route['default_controller'] = 'Login'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; diff --git a/application/config/smileys.php b/application/config/smileys.php new file mode 100644 index 00000000000..abf9a898dde --- /dev/null +++ b/application/config/smileys.php @@ -0,0 +1,64 @@ + array('grin.gif', '19', '19', 'grin'), + ':lol:' => array('lol.gif', '19', '19', 'LOL'), + ':cheese:' => array('cheese.gif', '19', '19', 'cheese'), + ':)' => array('smile.gif', '19', '19', 'smile'), + ';-)' => array('wink.gif', '19', '19', 'wink'), + ';)' => array('wink.gif', '19', '19', 'wink'), + ':smirk:' => array('smirk.gif', '19', '19', 'smirk'), + ':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'), + ':-S' => array('confused.gif', '19', '19', 'confused'), + ':wow:' => array('surprise.gif', '19', '19', 'surprised'), + ':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'), + ':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'), + '%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'), + ';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'), + ':P' => array('raspberry.gif', '19', '19', 'raspberry'), + ':blank:' => array('blank.gif', '19', '19', 'blank stare'), + ':long:' => array('longface.gif', '19', '19', 'long face'), + ':ohh:' => array('ohh.gif', '19', '19', 'ohh'), + ':grrr:' => array('grrr.gif', '19', '19', 'grrr'), + ':gulp:' => array('gulp.gif', '19', '19', 'gulp'), + '8-/' => array('ohoh.gif', '19', '19', 'oh oh'), + ':down:' => array('downer.gif', '19', '19', 'downer'), + ':red:' => array('embarrassed.gif', '19', '19', 'red face'), + ':sick:' => array('sick.gif', '19', '19', 'sick'), + ':shut:' => array('shuteye.gif', '19', '19', 'shut eye'), + ':-/' => array('hmm.gif', '19', '19', 'hmmm'), + '>:(' => array('mad.gif', '19', '19', 'mad'), + ':mad:' => array('mad.gif', '19', '19', 'mad'), + '>:-(' => array('angry.gif', '19', '19', 'angry'), + ':angry:' => array('angry.gif', '19', '19', 'angry'), + ':zip:' => array('zip.gif', '19', '19', 'zipper'), + ':kiss:' => array('kiss.gif', '19', '19', 'kiss'), + ':ahhh:' => array('shock.gif', '19', '19', 'shock'), + ':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'), + ':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'), + ':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'), + ':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'), + ':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'), + ':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'), + ':vampire:' => array('vampire.gif', '19', '19', 'vampire'), + ':snake:' => array('snake.gif', '19', '19', 'snake'), + ':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'), + ':question:' => array('question.gif', '19', '19', 'question') + +); diff --git a/application/config/user_agents.php b/application/config/user_agents.php index c866903f6da..c4429aac55f 100644 --- a/application/config/user_agents.php +++ b/application/config/user_agents.php @@ -87,8 +87,7 @@ 'amaya' => 'Amaya', 'IBrowse' => 'IBrowse', 'Maxthon' => 'Maxthon', - 'Ubuntu' => 'Ubuntu Web Browser', - 'Vivaldi' => 'Vivaldi' + 'Ubuntu' => 'Ubuntu Web Browser' ); $mobiles = array( diff --git a/application/controllers/Login.php b/application/controllers/Login.php index 8119fbf141e..c787316de6b 100644 --- a/application/controllers/Login.php +++ b/application/controllers/Login.php @@ -3,11 +3,35 @@ class Login extends CI_Controller { + public function __construct() + { + parent::__construct(); + $this->load->model('userM'); + $this->load->library(''); + } public function index() { - $this->load->view('view_login'); + $this->form_validation->set_rules('username', 'Username', 'trim|required'); + $this->form_validation->set_rules('password', 'Password', 'trim|required'); + if ($this->form_validation->run() == FALSE) { + $this->load->view('view_login'); + } else { + $data['username'] = $this->input->post('username'); + $data['password'] = $this->input->post('password'); + $q = $this->userM->login($data); + if ($q == 1) { + $array = array( + 'id' = 1, + 'username' => $data['username'] + ); + $this->session->set_userdata($array); + redirect('User'); + }else{ + $this->session->set_flashdata('error', ''); + redirect('Login'); + } + } } - } /* End of file Login.php */ diff --git a/application/controllers/User.php b/application/controllers/User.php new file mode 100644 index 00000000000..3a27d230fb3 --- /dev/null +++ b/application/controllers/User.php @@ -0,0 +1,72 @@ +load->model('userM'); + } + public function index() + { + $data['feed'] = $this->userM->getPost(); + $this->load->view('feed',$data); + } + public function profile() + { + $data['user'] = $this->userM->getUser(1)->row(); + $this->load->view('profile', $data); + } + public function editProfile() + { + $this->form_validation->set_rules('username', 'Username', 'trim|required'); + $data['user'] = $this->userM->getUser(1)->row(); + $this->load->view('edit-profile', $data); + } + public function editProfileAction() + { + $user['name'] = $this->input->post('full-name'); + $user['username'] = $this->input->post('username'); + $user['website'] = $this->input->post('website'); + $user['bio'] = $this->input->post('bio'); + $user['email'] = $this->input->post('email'); + $user['phone_number'] = $this->input->post('phone'); + $user['gender'] = $this->input->post('gender'); + $this->userM->updateUser(1,$user); + $this->session->set_flashdata('success', 'Profile Updated !'); + redirect('user/editProfile'); + } + public function addPhoto() + { + $this->load->view('add-photo'); + } + public function addPhotoAction() + { + + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'gif|jpg|png'; + $config['max_size'] = '100'; + $config['max_width'] = '1024'; + $config['max_height'] = '768'; + + $this->load->library('upload', $config); + + if ( ! $this->upload->do_upload('file')){ + $error = array('error' => $this->upload->display_errors()); + print_r($error); + } + else{ + $data = array('upload_data' => $this->upload->data()); + $poto['caption'] = $this->input->post('caption'); + $poto['url'] = 'uploads/'.$data['upload_data']['file_name']; + $this->userM->uploadPhoto($poto); + $this->session->set_flashdata('success', 'upload success !'); + redirect('user/addPhoto'); + } + } + +} + +/* End of file User.php */ +/* Location: ./application/controllers/User.php */ \ No newline at end of file diff --git a/application/controllers/index.html b/application/controllers/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/controllers/index.html +++ b/application/controllers/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/core/index.html b/application/core/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/core/index.html +++ b/application/core/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/helpers/index.html b/application/helpers/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/helpers/index.html +++ b/application/helpers/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/hooks/index.html b/application/hooks/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/hooks/index.html +++ b/application/hooks/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/index.html b/application/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/index.html +++ b/application/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/language/english/index.html b/application/language/english/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/language/english/index.html +++ b/application/language/english/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/language/index.html b/application/language/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/language/index.html +++ b/application/language/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/libraries/index.html b/application/libraries/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/libraries/index.html +++ b/application/libraries/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/logs/index.html b/application/logs/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/logs/index.html +++ b/application/logs/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/models/index.html b/application/models/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/models/index.html +++ b/application/models/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/models/userM.php b/application/models/userM.php new file mode 100644 index 00000000000..5274f0c2eeb --- /dev/null +++ b/application/models/userM.php @@ -0,0 +1,31 @@ +db->query("SELECT * FROM `user` WHERE `username`='".$data['username']."' AND `password`='".md5($data['password'])."'"); + return $q->num_rows(); + } + public function getUser($id) + { + $q = $this->db->query("SELECT * FROM `profile` WHERE `id_profile`='$id'"); + return $q; + } + public function updateUser($id, $data) + { + $this->db->where('id_profile', $id); + $this->db->update('profile', $data); + } + public function uploadPhoto($data) + { + $this->db->insert('photo', $data); + } + public function getPost() + { + return $this->db->query("SELECT * FROM `photo`")->result(); + } +} + +/* End of file userM.php */ +/* Location: ./application/models/userM.php */ \ No newline at end of file diff --git a/application/third_party/index.html b/application/third_party/index.html index bcb7cae3433..b702fbc3967 100644 --- a/application/third_party/index.html +++ b/application/third_party/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/application/views/add-photo.php b/application/views/add-photo.php new file mode 100644 index 00000000000..0fc0524cb35 --- /dev/null +++ b/application/views/add-photo.php @@ -0,0 +1,112 @@ + + + + + + + + add photo | Vietgram + + + + + + + + +
+
+
+
+ +
+

session->userdata('username'); ?>

+
+
+ +
+ + +
+
+ + +
+
+ + image preview +
+ + session->flashdata('success'); ?> +
+
+
+ + +' + : $r; + } +} + +// ------------------------------------------------------------------------ + +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 + * @return array + */ + function get_clickable_smileys($image_url, $alias = '') + { + // For backward compatibility with js_insert_smiley + if (is_array($alias)) + { + $smileys = $alias; + } + elseif (FALSE === ($smileys = _get_smiley_array())) + { + return FALSE; + } + + // Add a trailing slash to the file path if needed + $image_url = rtrim($image_url, '/').'/'; + + $used = array(); + foreach ($smileys as $key => $val) + { + // Keep duplicates from being used, which can happen if the + // mapping array contains multiple identical replacements. For example: + // :-) and :) might be replaced with the same image so both smileys + // will be in the array. + if (isset($used[$smileys[$key][0]])) + { + continue; + } + + $link[] = ''.$smileys[$key][3].''; + $used[$smileys[$key][0]] = TRUE; + } + + return $link; + } +} + +// ------------------------------------------------------------------------ + +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()))) + { + return $str; + } + + // Add a trailing slash to the file path if needed + $image_url = rtrim($image_url, '/').'/'; + + foreach ($smileys as $key => $val) + { + $str = str_replace($key, ''.$smileys[$key][3].'', $str); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('_get_smiley_array')) +{ + /** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @return mixed + */ + function _get_smiley_array() + { + static $_smileys; + + if ( ! is_array($_smileys)) + { + if (file_exists(APPPATH.'config/smileys.php')) + { + include(APPPATH.'config/smileys.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); + } + + if (empty($smileys) OR ! is_array($smileys)) + { + $_smileys = array(); + return FALSE; + } + + $_smileys = $smileys; + } + + return $_smileys; + } +} diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 7738bf97f9b..c7dd96977f0 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -49,6 +49,33 @@ // ------------------------------------------------------------------------ +if ( ! function_exists('trim_slashes')) +{ + /** + * Trim Slashes + * + * Removes any leading/trailing slashes from a string: + * + * /this/that/theother/ + * + * becomes: + * + * this/that/theother + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 This is just an alias for PHP's native trim() + * + * @param string + * @return string + */ + function trim_slashes($str) + { + return trim($str, '/'); + } +} + +// ------------------------------------------------------------------------ + if ( ! function_exists('strip_slashes')) { /** @@ -255,3 +282,23 @@ function alternator() return $args[($i++ % count($args))]; } } + +// ------------------------------------------------------------------------ + +if ( ! function_exists('repeater')) +{ + /** + * Repeater function + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 This is just an alias for PHP's native str_repeat() + * + * @param string $data String to repeat + * @param int $num Number of repeats + * @return string + */ + function repeater($data, $num = 1) + { + return ($num > 0) ? str_repeat($data, $num) : ''; + } +} diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 6a959f0e6da..bebfd258357 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -211,7 +211,7 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { $attributes = array($attributes); - // Ref: https://www.w3schools.com/jsref/met_win_open.asp + // Ref: http://www.w3schools.com/jsref/met_win_open.asp $window_name = '_blank'; } elseif ( ! empty($attributes['window_name'])) @@ -443,7 +443,7 @@ function auto_link($str, $type = 'both', $popup = FALSE) */ function prep_url($str = '') { - if ($str === '') + if ($str === 'http://' OR $str === '') { return ''; } @@ -546,7 +546,7 @@ function redirect($uri = '', $method = 'auto', $code = NULL) if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') { $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') - ? 303 // reference: https://en.wikipedia.org/wiki/Post/Redirect/Get + ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get : 307; } else diff --git a/system/index.html b/system/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/index.html +++ b/system/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index 74a2512c4d9..bdb0254429d 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -43,7 +43,6 @@ $lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.'; $lang['form_validation_valid_url'] = 'The {field} field must contain a valid URL.'; $lang['form_validation_valid_ip'] = 'The {field} field must contain a valid IP.'; -$lang['form_validation_valid_mac'] = 'The {field} field must contain a valid MAC.'; $lang['form_validation_valid_base64'] = 'The {field} field must contain a valid Base64 string.'; $lang['form_validation_min_length'] = 'The {field} field must be at least {param} characters in length.'; $lang['form_validation_max_length'] = 'The {field} field cannot exceed {param} characters in length.'; diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 9a26b8a9bdb..c34b087c7f6 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -44,7 +44,6 @@ $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_webp_not_supported'] = 'WEBP 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.'; diff --git a/system/language/english/index.html b/system/language/english/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/language/english/index.html +++ b/system/language/english/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/language/index.html b/system/language/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/language/index.html +++ b/system/language/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index b1241766015..450d57b8ae9 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -55,7 +55,6 @@ class CI_Cache extends CI_Driver_Library { */ protected $valid_drivers = array( 'apc', - 'apcu', 'dummy', 'file', 'memcached', @@ -253,16 +252,4 @@ public function is_supported($driver) return $support[$driver]; } - - // ------------------------------------------------------------------------ - - /** - * Get currently loaded driver - * - * @return string - */ - public function get_loaded_driver() - { - return $this->_adapter; - } } diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php deleted file mode 100644 index 01f80e79bca..00000000000 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ /dev/null @@ -1,219 +0,0 @@ -is_supported()) - { - log_message('error', 'Cache: Failed to initialize APCu; extension not loaded/enabled?'); - } - } - - // ------------------------------------------------------------------------ - - /** - * Get - * - * Look for a value in the cache. If it exists, return the data - * if not, return FALSE - * - * @param string - * @return mixed value that is stored/FALSE on failure - */ - public function get($id) - { - $success = FALSE; - $data = apcu_fetch($id, $success); - - if ($success === TRUE) - { - return is_array($data) - ? $data[0] - : $data; - } - - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Cache Save - * - * @param string $id Cache ID - * @param mixed $data Data to store - * @param int $ttl Length of time (in seconds) to cache the data - * @param bool $raw Whether to store the raw value - * @return bool TRUE on success, FALSE on failure - */ - public function save($id, $data, $ttl = 60, $raw = FALSE) - { - $ttl = (int) $ttl; - - return apcu_store( - $id, - ($raw === TRUE ? $data : array($data, time(), $ttl)), - $ttl - ); - } - - // ------------------------------------------------------------------------ - - /** - * Delete from Cache - * - * @param mixed unique identifier of the item in the cache - * @return bool true on success/false on failure - */ - public function delete($id) - { - return apcu_delete($id); - } - - // ------------------------------------------------------------------------ - - /** - * Increment a raw value - * - * @param string $id Cache ID - * @param int $offset Step/value to add - * @return mixed New value on success or FALSE on failure - */ - public function increment($id, $offset = 1) - { - return apcu_inc($id, $offset); - } - - // ------------------------------------------------------------------------ - - /** - * Decrement a raw value - * - * @param string $id Cache ID - * @param int $offset Step/value to reduce by - * @return mixed New value on success or FALSE on failure - */ - public function decrement($id, $offset = 1) - { - return apcu_dec($id, $offset); - } - - // ------------------------------------------------------------------------ - - /** - * Clean the cache - * - * @return bool false on failure/true on success - */ - public function clean() - { - return apcu_clear_cache(); - } - - // ------------------------------------------------------------------------ - - /** - * Cache Info - * - * @return mixed array on success, false on failure - */ - public function cache_info() - { - return apcu_cache_info(); - } - - // ------------------------------------------------------------------------ - - /** - * Get Cache Metadata - * - * @param mixed key to get cache metadata on - * @return mixed array on success/false on failure - */ - public function get_metadata($id) - { - $success = FALSE; - $stored = apcu_fetch($id, $success); - - if ($success === FALSE OR count($stored) !== 3) - { - return FALSE; - } - - list($data, $time, $ttl) = $stored; - - return array( - 'expire' => $time + $ttl, - 'mtime' => $time, - 'data' => $data - ); - } - - // ------------------------------------------------------------------------ - - /** - * is_supported() - * - * Check to see if APCu is available on this system, bail if it isn't. - * - * @return bool - */ - public function is_supported() - { - return (extension_loaded('apcu') && ini_get('apc.enabled')); - } -} \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 24969e0bf11..bdc86a5d689 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -102,22 +102,10 @@ public function __construct() return; } - foreach ($this->_config as $cache_name => $cache_server) + foreach ($this->_config as $cache_server) { - if ( ! isset($cache_server['hostname'])) - { - log_message('debug', 'Cache: Memcache(d) configuration "'.$cache_name.'" doesn\'t include a hostname; ignoring.'); - continue; - } - elseif ($cache_server['hostname'][0] === '/') - { - $cache_server['port'] = 0; - } - elseif (empty($cache_server['port'])) - { - $cache_server['port'] = $defaults['port']; - } - + isset($cache_server['hostname']) OR $cache_server['hostname'] = $defaults['host']; + isset($cache_server['port']) OR $cache_server['port'] = $defaults['port']; isset($cache_server['weight']) OR $cache_server['weight'] = $defaults['weight']; if ($this->_memcached instanceof Memcache) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 9b082d11b36..f0a72ee3cc0 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -55,11 +55,11 @@ class CI_Cache_redis extends CI_Driver * @var array */ protected static $_default_config = array( + 'socket_type' => 'tcp', 'host' => '127.0.0.1', 'password' => NULL, 'port' => 6379, - 'timeout' => 0, - 'database' => 0 + 'timeout' => 0 ); /** @@ -69,6 +69,12 @@ class CI_Cache_redis extends CI_Driver */ protected $_redis; + /** + * An internal cache for storing keys of serialized values. + * + * @var array + */ + protected $_serialized = array(); /** * del()/delete() method name depending on phpRedis version @@ -134,19 +140,23 @@ public function __construct() try { - if ( ! $this->_redis->connect($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) + if ($config['socket_type'] === 'unix') { - log_message('error', 'Cache: Redis connection failed. Check your configuration.'); + $success = $this->_redis->connect($config['socket']); + } + else // tcp socket + { + $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } - if (isset($config['password']) && ! $this->_redis->auth($config['password'])) + if ( ! $success) { - log_message('error', 'Cache: Redis authentication failed.'); + log_message('error', 'Cache: Redis connection failed. Check your configuration.'); } - if (isset($config['database']) && $config['database'] > 0 && ! $this->_redis->select($config['database'])) + if (isset($config['password']) && ! $this->_redis->auth($config['password'])) { - log_message('error', 'Cache: Redis select database failed.'); + log_message('error', 'Cache: Redis authentication failed.'); } } catch (RedisException $e) @@ -165,30 +175,14 @@ public function __construct() */ public function get($key) { - $data = $this->_redis->hMGet($key, array('__ci_type', '__ci_value')); + $value = $this->_redis->get($key); if ($value !== FALSE && $this->_redis->sIsMember('_ci_redis_serialized', $key)) { - return FALSE; + return unserialize($value); } - switch ($data['__ci_type']) - { - case 'array': - case 'object': - return unserialize($data['__ci_value']); - case 'boolean': - case 'integer': - case 'double': // Yes, 'double' is returned and NOT 'float' - case 'string': - case 'NULL': - return settype($data['__ci_value'], $data['__ci_type']) - ? $data['__ci_value'] - : FALSE; - case 'resource': - default: - return FALSE; - } + return $value; } // ------------------------------------------------------------------------ @@ -204,33 +198,22 @@ public function get($key) */ public function save($id, $data, $ttl = 60, $raw = FALSE) { - switch ($data_type = gettype($data)) + if (is_array($data) OR is_object($data)) { - case 'array': - case 'object': - $data = serialize($data); - break; - case 'boolean': - case 'integer': - case 'double': // Yes, 'double' is returned and NOT 'float' - case 'string': - case 'NULL': - break; - case 'resource': - default: + if ( ! $this->_redis->sIsMember('_ci_redis_serialized', $id) && ! $this->_redis->sAdd('_ci_redis_serialized', $id)) + { return FALSE; - } + } - if ( ! $this->_redis->hMSet($id, array('__ci_type' => $data_type, '__ci_value' => $data))) - { - return FALSE; + isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE; + $data = serialize($data); } else { $this->_redis->{static::$_sRemove_name}('_ci_redis_serialized', $id); } - return TRUE; + return $this->_redis->set($id, $data, $ttl); } // ------------------------------------------------------------------------ diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index 703fece7a51..c20d0bc91df 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -41,7 +41,7 @@ * CodeIgniter Wincache Caching Class * * Read more about Wincache functions here: - * https://secure.php.net/manual/en/ref.wincache.php + * http://www.php.net/manual/en/ref.wincache.php * * @package CodeIgniter * @subpackage Libraries diff --git a/system/libraries/Cache/drivers/index.html b/system/libraries/Cache/drivers/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/libraries/Cache/drivers/index.html +++ b/system/libraries/Cache/drivers/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/libraries/Cache/index.html b/system/libraries/Cache/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/libraries/Cache/index.html +++ b/system/libraries/Cache/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php new file mode 100644 index 00000000000..6a107752caf --- /dev/null +++ b/system/libraries/Cart.php @@ -0,0 +1,567 @@ +CI =& get_instance(); + + // Are any config settings being passed manually? If so, set them + $config = is_array($params) ? $params : array(); + + // Load the Sessions class + $this->CI->load->driver('session', $config); + + // Grab the shopping cart array from the session table + $this->_cart_contents = $this->CI->session->userdata('cart_contents'); + if ($this->_cart_contents === NULL) + { + // No cart exists so we'll set some base values + $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); + } + + log_message('info', 'Cart Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Insert items into the cart and save it to the session table + * + * @param array + * @return bool + */ + public function insert($items = array()) + { + // Was any cart data passed? No? Bah... + if ( ! is_array($items) OR count($items) === 0) + { + log_message('error', 'The insert method must be passed an array containing data.'); + return FALSE; + } + + // You can either insert a single product using a one-dimensional array, + // or multiple products using a multi-dimensional one. The way we + // determine the array type is by looking for a required array key named "id" + // at the top level. If it's not found, we will assume it's a multi-dimensional array. + + $save_cart = FALSE; + if (isset($items['id'])) + { + if (($rowid = $this->_insert($items))) + { + $save_cart = TRUE; + } + } + else + { + foreach ($items as $val) + { + if (is_array($val) && isset($val['id'])) + { + if ($this->_insert($val)) + { + $save_cart = TRUE; + } + } + } + } + + // Save the cart data if the insert was successful + if ($save_cart === TRUE) + { + $this->_save_cart(); + return isset($rowid) ? $rowid : TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * @param array + * @return bool + */ + protected function _insert($items = array()) + { + // Was any cart data passed? No? Bah... + if ( ! is_array($items) OR count($items) === 0) + { + log_message('error', 'The insert method must be passed an array containing data.'); + return FALSE; + } + + // -------------------------------------------------------------------- + + // Does the $items array contain an id, quantity, price, and name? These are required + if ( ! isset($items['id'], $items['qty'], $items['price'], $items['name'])) + { + log_message('error', 'The cart array must contain a product ID, quantity, price, and name.'); + return FALSE; + } + + // -------------------------------------------------------------------- + + // Prep the quantity. It can only be a number. Duh... also trim any leading zeros + $items['qty'] = (float) $items['qty']; + + // If the quantity is zero or blank there's nothing for us to do + if ($items['qty'] == 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + // Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods + // Not totally sure we should impose this rule, but it seems prudent to standardize IDs. + // Note: These can be user-specified by setting the $this->product_id_rules variable. + if ( ! preg_match('/^['.$this->product_id_rules.']+$/i', $items['id'])) + { + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); + return FALSE; + } + + // -------------------------------------------------------------------- + + // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. + // Note: These can be user-specified by setting the $this->product_name_rules variable. + if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $items['name'])) + { + log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces'); + return FALSE; + } + + // -------------------------------------------------------------------- + + // Prep the price. Remove leading zeros and anything that isn't a number or decimal point. + $items['price'] = (float) $items['price']; + + // We now need to create a unique identifier for the item being inserted into the cart. + // Every time something is added to the cart it is stored in the master cart array. + // Each row in the cart array, however, must have a unique index that identifies not only + // a particular product, but makes it possible to store identical products with different options. + // For example, what if someone buys two identical t-shirts (same product ID), but in + // different sizes? The product ID (and other attributes, like the name) will be identical for + // both sizes because it's the same shirt. The only difference will be the size. + // Internally, we need to treat identical submissions, but with different options, as a unique product. + // Our solution is to convert the options array to a string and MD5 it along with the product ID. + // This becomes the unique "row ID" + if (isset($items['options']) && count($items['options']) > 0) + { + $rowid = md5($items['id'].serialize($items['options'])); + } + else + { + // No options were submitted so we simply MD5 the product ID. + // Technically, we don't need to MD5 the ID in this case, but it makes + // sense to standardize the format of array indexes for both conditions + $rowid = md5($items['id']); + } + + // -------------------------------------------------------------------- + + // Now that we have our unique "row ID", we'll add our cart items to the master array + // grab quantity if it's already there and add it on + $old_quantity = isset($this->_cart_contents[$rowid]['qty']) ? (int) $this->_cart_contents[$rowid]['qty'] : 0; + + // Re-create the entry, just to make sure our index contains only the data from this submission + $items['rowid'] = $rowid; + $items['qty'] += $old_quantity; + $this->_cart_contents[$rowid] = $items; + + return $rowid; + } + + // -------------------------------------------------------------------- + + /** + * Update the cart + * + * This function permits the quantity of a given item to be changed. + * Typically it is called from the "view cart" page if a user makes + * changes to the quantity before checkout. That array must contain the + * product ID and quantity for each item. + * + * @param array + * @return bool + */ + public function update($items = array()) + { + // Was any cart data passed? + if ( ! is_array($items) OR count($items) === 0) + { + return FALSE; + } + + // You can either update a single product using a one-dimensional array, + // or multiple products using a multi-dimensional one. The way we + // determine the array type is by looking for a required array key named "rowid". + // If it's not found we assume it's a multi-dimensional array + $save_cart = FALSE; + if (isset($items['rowid'])) + { + if ($this->_update($items) === TRUE) + { + $save_cart = TRUE; + } + } + else + { + foreach ($items as $val) + { + if (is_array($val) && isset($val['rowid'])) + { + if ($this->_update($val) === TRUE) + { + $save_cart = TRUE; + } + } + } + } + + // Save the cart data if the insert was successful + if ($save_cart === TRUE) + { + $this->_save_cart(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update the cart + * + * This function permits changing item properties. + * Typically it is called from the "view cart" page if a user makes + * changes to the quantity before checkout. That array must contain the + * rowid and quantity for each item. + * + * @param array + * @return bool + */ + protected function _update($items = array()) + { + // Without these array indexes there is nothing we can do + if ( ! isset($items['rowid'], $this->_cart_contents[$items['rowid']])) + { + return FALSE; + } + + // Prep the quantity + if (isset($items['qty'])) + { + $items['qty'] = (float) $items['qty']; + // Is the quantity zero? If so we will remove the item from the cart. + // If the quantity is greater than zero we are updating + if ($items['qty'] == 0) + { + unset($this->_cart_contents[$items['rowid']]); + return TRUE; + } + } + + // find updatable keys + $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); + // if a price was passed, make sure it contains valid data + if (isset($items['price'])) + { + $items['price'] = (float) $items['price']; + } + + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) + { + $this->_cart_contents[$items['rowid']][$key] = $items[$key]; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Save the cart array to the session DB + * + * @return bool + */ + protected function _save_cart() + { + // Let's add up the individual prices and set the cart sub-total + $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; + foreach ($this->_cart_contents as $key => $val) + { + // We make sure the array contains the proper indexes + if ( ! is_array($val) OR ! isset($val['price'], $val['qty'])) + { + continue; + } + + $this->_cart_contents['cart_total'] += ($val['price'] * $val['qty']); + $this->_cart_contents['total_items'] += $val['qty']; + $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); + } + + // Is our cart empty? If so we delete it from the session + if (count($this->_cart_contents) <= 2) + { + $this->CI->session->unset_userdata('cart_contents'); + + // Nothing more to do... coffee time! + return FALSE; + } + + // If we made it this far it means that our cart has data. + // Let's pass it to the Session class so it can be stored + $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents)); + + // Woot! + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Cart Total + * + * @return int + */ + public function total() + { + return $this->_cart_contents['cart_total']; + } + + // -------------------------------------------------------------------- + + /** + * Remove Item + * + * Removes an item from the cart + * + * @param int + * @return bool + */ + public function remove($rowid) + { + // unset & save + unset($this->_cart_contents[$rowid]); + $this->_save_cart(); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Total Items + * + * Returns the total item count + * + * @return int + */ + public function total_items() + { + return $this->_cart_contents['total_items']; + } + + // -------------------------------------------------------------------- + + /** + * Cart Contents + * + * Returns the entire cart array + * + * @param bool + * @return array + */ + public function contents($newest_first = FALSE) + { + // do we want the newest first? + $cart = ($newest_first) ? array_reverse($this->_cart_contents) : $this->_cart_contents; + + // Remove these so they don't create a problem when showing the cart table + unset($cart['total_items']); + unset($cart['cart_total']); + + return $cart; + } + + // -------------------------------------------------------------------- + + /** + * Get cart item + * + * Returns the details of a specific item in the cart + * + * @param string $row_id + * @return array + */ + public function get_item($row_id) + { + return (in_array($row_id, array('total_items', 'cart_total'), TRUE) OR ! isset($this->_cart_contents[$row_id])) + ? FALSE + : $this->_cart_contents[$row_id]; + } + + // -------------------------------------------------------------------- + + /** + * Has options + * + * Returns TRUE if the rowid passed to this function correlates to an item + * that has options associated with it. + * + * @param string $row_id = '' + * @return bool + */ + public function has_options($row_id = '') + { + return (isset($this->_cart_contents[$row_id]['options']) && count($this->_cart_contents[$row_id]['options']) !== 0); + } + + // -------------------------------------------------------------------- + + /** + * Product options + * + * Returns the an array of options, for a particular product row ID + * + * @param string $row_id = '' + * @return array + */ + public function product_options($row_id = '') + { + return isset($this->_cart_contents[$row_id]['options']) ? $this->_cart_contents[$row_id]['options'] : array(); + } + + // -------------------------------------------------------------------- + + /** + * Format Number + * + * Returns the supplied number with commas and a decimal point. + * + * @param float + * @return string + */ + public function format_number($n = '') + { + return ($n === '') ? '' : number_format( (float) $n, 2, '.', ','); + } + + // -------------------------------------------------------------------- + + /** + * Destroy the cart + * + * Empties the cart and kills the session + * + * @return void + */ + public function destroy() + { + $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); + $this->CI->session->unset_userdata('cart_contents'); + } + +} diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1912e0442d3..10b74777dec 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -147,7 +147,7 @@ class CI_Email { * * @var string */ - public $charset = 'utf-8'; + public $charset = 'UTF-8'; /** * Alternative message (for HTML messages only) @@ -161,7 +161,7 @@ class CI_Email { * * @var bool */ - public $validate = TRUE; + public $validate = FALSE; /** * X-Priority header value. @@ -174,7 +174,7 @@ class CI_Email { * Newline character sequence. * Use "\r\n" to comply with RFC 822. * - * @link https://www.ietf.org/rfc/rfc822.txt + * @link http://www.ietf.org/rfc/rfc822.txt * @var string "\r\n" or "\n" */ public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) @@ -188,7 +188,7 @@ class CI_Email { * switching to "\n", while improper, is the only solution * that seems to work for all environments. * - * @link https://www.ietf.org/rfc/rfc822.txt + * @link http://www.ietf.org/rfc/rfc822.txt * @var string */ public $crlf = "\n"; @@ -225,6 +225,13 @@ class CI_Email { // -------------------------------------------------------------------- + /** + * Whether PHP is running in safe mode. Initialized by the class constructor. + * + * @var bool + */ + protected $_safe_mode = FALSE; + /** * Subject header * @@ -388,6 +395,7 @@ public function __construct(array $config = array()) { $this->charset = config_item('charset'); $this->initialize($config); + $this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode')); isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); @@ -667,6 +675,18 @@ public function subject($subject) public function message($body) { $this->_body = rtrim(str_replace("\r", '', $body)); + + /* strip slashes only if magic quotes is ON + if we do it with magic quotes OFF, it strips real, user-inputted chars. + + NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and + it will probably not exist in future versions at all. + */ + if ( ! is_php('5.4') && get_magic_quotes_gpc()) + { + $this->_body = stripslashes($this->_body); + } + return $this; } @@ -1012,15 +1032,16 @@ public function validate_email($email) */ public function valid_email($email) { - if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $email, $matches)) + if (function_exists('idn_to_ascii') && strpos($email, '@')) { + list($account, $domain) = explode('@', $email, 2); $domain = defined('INTL_IDNA_VARIANT_UTS46') - ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46) - : idn_to_ascii($matches[2]); + ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) + : idn_to_ascii($domain); if ($domain !== FALSE) { - $email = $matches[1].'@'.$domain; + $email = $account.'@'.$domain; } } @@ -1240,7 +1261,7 @@ protected function _write_headers() /** * Build Final Body and attachments * - * @return void + * @return bool */ protected function _build_message() { @@ -1407,6 +1428,8 @@ protected function _build_message() $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; + + return TRUE; } // -------------------------------------------------------------------- @@ -1467,7 +1490,7 @@ protected function _append_attachments(&$body, $boundary, $multipart = null) * Prep Quoted Printable * * Prepares string for Quoted-Printable Content-Transfer-Encoding - * Refer to RFC 2045 https://www.ietf.org/rfc/rfc2045.txt + * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt * * @param string * @return string @@ -1476,7 +1499,7 @@ protected function _prep_quoted_printable($str) { // ASCII code numbers for "safe" characters that can always be // used literally, without encoding, as described in RFC 2049. - // https://www.ietf.org/rfc/rfc2049.txt + // http://www.ietf.org/rfc/rfc2049.txt static $ascii_safe_chars = array( // ' ( ) + , - . / : = ? 39, 40, 41, 43, 44, 45, 46, 47, 58, 61, 63, @@ -1668,8 +1691,8 @@ public function send($auto_clear = TRUE) $this->reply_to($this->_headers['From']); } - if (empty($this->_recipients) && ! isset($this->_headers['To']) - && empty($this->_bcc_array) && ! isset($this->_headers['Bcc']) + if ( ! isset($this->_recipients) && ! isset($this->_headers['To']) + && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc']) && ! isset($this->_headers['Cc'])) { $this->_set_error_message('lang:email_no_recipients'); @@ -1680,17 +1703,21 @@ public function send($auto_clear = TRUE) if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size) { - $this->batch_bcc_send(); + $result = $this->batch_bcc_send(); - if ($auto_clear) + if ($result && $auto_clear) { $this->clear(); } - return TRUE; + return $result; + } + + if ($this->_build_message() === FALSE) + { + return FALSE; } - $this->_build_message(); $result = $this->_spool_email(); if ($result && $auto_clear) @@ -1749,7 +1776,11 @@ public function batch_bcc_send() $this->_bcc_array = $bcc; } - $this->_build_message(); + if ($this->_build_message() === FALSE) + { + return FALSE; + } + $this->_spool_email(); } } @@ -1826,7 +1857,7 @@ protected function _spool_email() */ protected function _validate_email_for_shell(&$email) { - if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) + if (function_exists('idn_to_ascii') && strpos($email, '@')) { list($account, $domain) = explode('@', $email, 2); $domain = defined('INTL_IDNA_VARIANT_UTS46') @@ -1860,14 +1891,16 @@ protected function _send_with_mail() // so this needs to be assigned to a variable $from = $this->clean_email($this->_headers['Return-Path']); - if ( ! $this->_validate_email_for_shell($from)) + if ($this->_safe_mode === TRUE || ! $this->_validate_email_for_shell($from)) { return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str); } - - // 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 '.$from); + else + { + // 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 '.$from); + } } // -------------------------------------------------------------------- @@ -1948,21 +1981,27 @@ protected function _send_with_smtp() } } - foreach ($this->_cc_array as $val) + if (count($this->_cc_array) > 0) { - if ($val !== '' && ! $this->_send_command('to', $val)) + foreach ($this->_cc_array as $val) { - $this->_smtp_end(); - return FALSE; + if ($val !== '' && ! $this->_send_command('to', $val)) + { + $this->_smtp_end(); + return FALSE; + } } } - foreach ($this->_bcc_array as $val) + if (count($this->_bcc_array) > 0) { - if ($val !== '' && ! $this->_send_command('to', $val)) + foreach ($this->_bcc_array as $val) { - $this->_smtp_end(); - return FALSE; + if ($val !== '' && ! $this->_send_command('to', $val)) + { + $this->_smtp_end(); + return FALSE; + } } } @@ -1976,6 +2015,7 @@ protected function _send_with_smtp() $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); $this->_send_data('.'); + $reply = $this->_get_smtp_data(); $this->_set_error_message($reply); @@ -2001,7 +2041,9 @@ protected function _send_with_smtp() */ protected function _smtp_end() { - $this->_send_command($this->smtp_keepalive ? 'reset' : 'quit'); + ($this->smtp_keepalive) + ? $this->_send_command('reset') + : $this->_send_command('quit'); } // -------------------------------------------------------------------- @@ -2020,13 +2062,11 @@ protected function _smtp_connect() $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : ''; - $this->_smtp_connect = fsockopen( - $ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout - ); + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout); if ( ! is_resource($this->_smtp_connect)) { @@ -2079,49 +2119,57 @@ protected function _send_command($cmd, $data = '') { switch ($cmd) { - case 'hello': - if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') - { - $this->_send_data('EHLO '.$this->_get_hostname()); - } - else - { - $this->_send_data('HELO '.$this->_get_hostname()); - } - - $resp = 250; - break; - case 'starttls': - $this->_send_data('STARTTLS'); - $resp = 220; - break; - case 'from': - $this->_send_data('MAIL FROM:<'.$data.'>'); - $resp = 250; - break; - case 'to': - if ($this->dsn) - { - $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); - } - else - { - $this->_send_data('RCPT TO:<'.$data.'>'); - } - $resp = 250; - break; - case 'data': - $this->_send_data('DATA'); - $resp = 354; - break; + case 'hello' : + + if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') + { + $this->_send_data('EHLO '.$this->_get_hostname()); + } + else + { + $this->_send_data('HELO '.$this->_get_hostname()); + } + + $resp = 250; + break; + case 'starttls' : + + $this->_send_data('STARTTLS'); + $resp = 220; + break; + case 'from' : + + $this->_send_data('MAIL FROM:<'.$data.'>'); + $resp = 250; + break; + case 'to' : + + if ($this->dsn) + { + $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); + } + else + { + $this->_send_data('RCPT TO:<'.$data.'>'); + } + + $resp = 250; + break; + case 'data' : + + $this->_send_data('DATA'); + $resp = 354; + break; case 'reset': - $this->_send_data('RSET'); - $resp = 250; - break; - case 'quit': - $this->_send_data('QUIT'); - $resp = 221; - break; + + $this->_send_data('RSET'); + $resp = 250; + break; + case 'quit' : + + $this->_send_data('QUIT'); + $resp = 221; + break; } $reply = $this->_get_smtp_data(); @@ -2163,6 +2211,7 @@ protected function _smtp_authenticate() } $this->_send_data('AUTH LOGIN'); + $reply = $this->_get_smtp_data(); if (strpos($reply, '503') === 0) // Already authenticated @@ -2176,6 +2225,7 @@ protected function _smtp_authenticate() } $this->_send_data(base64_encode($this->smtp_user)); + $reply = $this->_get_smtp_data(); if (strpos($reply, '334') !== 0) @@ -2185,6 +2235,7 @@ protected function _smtp_authenticate() } $this->_send_data(base64_encode($this->smtp_pass)); + $reply = $this->_get_smtp_data(); if (strpos($reply, '235') !== 0) @@ -2218,7 +2269,7 @@ protected function _send_data($data) { break; } - // See https://bugs.php.net/bug.php?id=39598 and https://secure.php.net/manual/en/function.fwrite.php#96951 + // See https://bugs.php.net/bug.php?id=39598 and http://php.net/manual/en/function.fwrite.php#96951 elseif ($result === 0) { if ($timestamp === 0) @@ -2281,7 +2332,7 @@ protected function _get_smtp_data() * (eg: "[1.2.3.4]"). * * @link https://tools.ietf.org/html/rfc5321#section-2.3.5 - * @link https://cbl.abuseat.org/namingproblems.html + * @link http://cbl.abuseat.org/namingproblems.html * @return string */ protected function _get_hostname() @@ -2305,15 +2356,34 @@ protected function _get_hostname() */ public function print_debugger($include = array('headers', 'subject', 'body')) { - $msg = implode('', $this->_debug_msg); + $msg = ''; + + if (count($this->_debug_msg) > 0) + { + foreach ($this->_debug_msg as $val) + { + $msg .= $val; + } + } // Determine which parts of our raw data needs to be printed $raw_data = ''; is_array($include) OR $include = array($include); - in_array('headers', $include, TRUE) && $raw_data = htmlspecialchars($this->_header_str)."\n"; - in_array('subject', $include, TRUE) && $raw_data .= htmlspecialchars($this->_subject)."\n"; - in_array('body', $include, TRUE) && $raw_data .= htmlspecialchars($this->_finalbody); + if (in_array('headers', $include, TRUE)) + { + $raw_data = htmlspecialchars($this->_header_str)."\n"; + } + + if (in_array('subject', $include, TRUE)) + { + $raw_data .= htmlspecialchars($this->_subject)."\n"; + } + + if (in_array('body', $include, TRUE)) + { + $raw_data .= htmlspecialchars($this->_finalbody); + } return $msg.($raw_data === '' ? '' : '
'.$raw_data.'
'); } @@ -2407,6 +2477,9 @@ protected static function substr($str, $start, $length = NULL) { if (self::$func_overload) { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); return mb_substr($str, $start, $length, '8bit'); } diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index fd858cb297b..4c1973fee55 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -482,7 +482,7 @@ protected function _openssl_encrypt($data, $params) $data, $params['handle'], $params['key'], - OPENSSL_RAW_DATA, + 1, // DO NOT TOUCH! $iv ); @@ -641,7 +641,7 @@ protected function _openssl_decrypt($data, $params) $data, $params['handle'], $params['key'], - OPENSSL_RAW_DATA, + 1, // DO NOT TOUCH! $iv ); } @@ -928,6 +928,9 @@ protected static function substr($str, $start, $length = NULL) { if (self::$func_overload) { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); return mb_substr($str, $start, $length, '8bit'); } diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index de59ef9f736..fdf2020101c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -104,6 +104,13 @@ class CI_Form_validation { */ protected $error_string = ''; + /** + * Whether the form data has been validated as safe + * + * @var bool + */ + protected $_safe_form_data = FALSE; + /** * Custom data to validate * @@ -157,7 +164,7 @@ public function __construct($rules = array()) * @param array $errors * @return CI_Form_validation */ - public function set_rules($field, $label = null, $rules = null, $errors = array()) + public function set_rules($field, $label = '', $rules = array(), $errors = array()) { // No reason to set rules if we have no POST data // or a validation array has not been specified @@ -190,22 +197,18 @@ public function set_rules($field, $label = null, $rules = null, $errors = array( return $this; } - elseif ( ! isset($rules)) - { - throw new BadMethodCallException('Form_validation: set_rules() called without a $rules parameter'); - } // No fields or no rules? Nothing to do... if ( ! is_string($field) OR $field === '' OR empty($rules)) { - throw new RuntimeException('Form_validation: set_rules() called with an empty $rules parameter'); + return $this; } elseif ( ! is_array($rules)) { // BC: Convert pipe-separated rules string to an array if ( ! is_string($rules)) { - throw new InvalidArgumentException('Form_validation: set_rules() expect $rules to be string or array; '.gettype($rules).' given'); + return $this; } $rules = preg_split('/\|(?![^\[]*\])/', $rules); @@ -407,11 +410,10 @@ public function error_string($prefix = '', $suffix = '') * * This function does all the work. * - * @param string $config - * @param array $data + * @param string $group * @return bool */ - public function run($config = NULL, &$data = NULL) + public function run($group = '') { $validation_array = empty($this->validation_data) ? $_POST @@ -422,19 +424,19 @@ public function run($config = NULL, &$data = NULL) if (count($this->_field_data) === 0) { // No validation rules? We're done... - if (empty($this->_config_rules)) + if (count($this->_config_rules) === 0) { return FALSE; } - if (empty($config)) + if (empty($group)) { // Is there a validation rule for the particular URI being accessed? - $config = trim($this->CI->uri->ruri_string(), '/'); - isset($this->_config_rules[$config]) OR $config = $this->CI->router->class.'/'.$this->CI->router->method; + $group = trim($this->CI->uri->ruri_string(), '/'); + isset($this->_config_rules[$group]) OR $group = $this->CI->router->class.'/'.$this->CI->router->method; } - $this->set_rules(isset($this->_config_rules[$config]) ? $this->_config_rules[$config] : $this->_config_rules); + $this->set_rules(isset($this->_config_rules[$group]) ? $this->_config_rules[$group] : $this->_config_rules); // Were we able to set the rules correctly? if (count($this->_field_data) === 0) @@ -476,22 +478,17 @@ public function run($config = NULL, &$data = NULL) $this->_execute($row, $row['rules'], $row['postdata']); } - if ( ! empty($this->_error_array)) + // Did we end up with any errors? + $total_errors = count($this->_error_array); + if ($total_errors > 0) { - return FALSE; + $this->_safe_form_data = TRUE; } - // Fill $data if requested, otherwise modify $_POST, as long as - // set_data() wasn't used (yea, I know it sounds confusing) - if (func_num_args() >= 2) - { - $data = empty($this->validation_data) ? $_POST : $this->validation_data; - $this->_reset_data_array($data); - return TRUE; - } + // Now we need to re-set the POST data with the new, processed data + empty($this->validation_data) && $this->_reset_post_array(); - empty($this->validation_data) && $this->_reset_data_array($_POST); - return TRUE; + return ($total_errors === 0); } // -------------------------------------------------------------------- @@ -579,7 +576,7 @@ protected function _reduce_array($array, $keys, $i = 0) * * @return void */ - protected function _reset_data_array(&$data) + protected function _reset_post_array() { foreach ($this->_field_data as $field => $row) { @@ -587,26 +584,27 @@ protected function _reset_data_array(&$data) { if ($row['is_array'] === FALSE) { - isset($data[$field]) && $data[$field] = is_array($row['postdata']) ? NULL : $row['postdata']; + isset($_POST[$field]) && $_POST[$field] = is_array($row['postdata']) ? NULL : $row['postdata']; } else { - $data_ref =& $data; + // start with a reference + $post_ref =& $_POST; // before we assign values, make a reference to the right POST key if (count($row['keys']) === 1) { - $data_ref =& $data[current($row['keys'])]; + $post_ref =& $post_ref[current($row['keys'])]; } else { foreach ($row['keys'] as $val) { - $data_ref =& $data_ref[$val]; + $post_ref =& $post_ref[$val]; } } - $data_ref = $row['postdata']; + $post_ref = $row['postdata']; } } } @@ -625,13 +623,11 @@ protected function _reset_data_array(&$data) */ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) { - $allow_arrays = in_array('is_array', $rules, TRUE); - // If the $_POST data is an array we will run a recursive call // // Note: We MUST check if the array is empty or not! // Otherwise empty arrays will always pass validation. - if ($allow_arrays === FALSE && is_array($postdata) && ! empty($postdata)) + if (is_array($postdata) && ! empty($postdata)) { foreach ($postdata as $key => $val) { @@ -660,16 +656,14 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; $_in_array = TRUE; } - // 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 - elseif ($allow_arrays === FALSE && is_array($this->_field_data[$row['field']]['postdata'])) - { - $postdata = NULL; - } 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? @@ -704,7 +698,7 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) // Ignore empty, non-required inputs with a few exceptions ... if ( - ($postdata === NULL OR ($allow_arrays === FALSE && $postdata === '')) + ($postdata === NULL OR $postdata === '') && $callback === FALSE && $callable === FALSE && ! in_array($rule, array('required', 'isset', 'matches'), TRUE) @@ -1299,31 +1293,6 @@ public function valid_ip($ip, $which = '') // -------------------------------------------------------------------- - /** - * Validate MAC address - * - * @param string $mac - * @return bool - */ - public function valid_mac($mac) - { - if ( ! is_php('5.5')) - { - // Most common format, with either dash or colon delimiters - if (preg_match('#\A[0-9a-f]{2}(?[:-])([0-9a-f]{2}(?P=delimiter)){4}[0-9a-f]{2}\z#i', $mac)) - { - return TRUE; - } - - // The less common format; e.g. 0123.4567.89ab - return (bool) preg_match('#((\A|\.)[0-9a-f]{4}){3}\z#i', $mac); - } - - return (bool) filter_var($mac, FILTER_VALIDATE_MAC); - } - - // -------------------------------------------------------------------- - /** * Alpha * @@ -1528,6 +1497,38 @@ public function valid_base64($str) // -------------------------------------------------------------------- + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @deprecated 3.0.6 Not used anywhere within the framework and pretty much useless + * @param mixed $data Input data + * @return mixed + */ + public function prep_for_form($data) + { + if ($this->_safe_form_data === FALSE OR empty($data)) + { + return $data; + } + + if (is_array($data)) + { + foreach ($data as $key => $val) + { + $data[$key] = $this->prep_for_form($val); + } + + return $data; + } + + return str_replace(array("'", '"', '<', '>'), array(''', '"', '<', '>'), stripslashes($data)); + } + + // -------------------------------------------------------------------- + /** * Prep URL * @@ -1536,7 +1537,12 @@ public function valid_base64($str) */ public function prep_url($str = '') { - if ($str !== '' && stripos($str, 'http://') !== 0 && stripos($str, 'https://') !== 0) + if ($str === 'http://' OR $str === '') + { + return ''; + } + + if (strpos($str, 'http://') !== 0 && strpos($str, 'https://') !== 0) { return 'http://'.$str; } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0d9fa442035..b89bc5b7e37 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -946,10 +946,6 @@ public function image_process_netpbm($action = 'resize') $cmd_in = 'pngtopnm'; $cmd_out = 'ppmtopng'; break; - case 18 : - $cmd_in = 'webptopnm'; - $cmd_out = 'ppmtowebp'; - break; } if ($action === 'crop') @@ -1211,7 +1207,7 @@ public function overlay_watermark() } // Build the finalized image - if ($wm_img_type === 3) + if ($wm_img_type === 3 && function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); } @@ -1474,13 +1470,6 @@ public function image_create_gd($path = '', $image_type = '') $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; } - case 18: - if ( ! function_exists('imagecreatefromwebp')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported')); - return FALSE; - } - return imagecreatefromwebp($path); return imagecreatefrompng($path); default: @@ -1543,19 +1532,6 @@ public function image_save_gd($resource) return FALSE; } break; - case 18: - if ( ! function_exists('imagewebp')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_webp_not_supported')); - return FALSE; - } - - if ( ! @imagewebp($resource, $this->full_dst_path)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; default: $this->set_error(array('imglib_unsupported_imagecreate')); return FALSE; @@ -1575,16 +1551,7 @@ public function image_save_gd($resource) */ public function image_display_gd($resource) { - // RFC 6266 allows for multibyte filenames, but only in UTF-8, - // so we have to make it conditional ... - $filename = basename(empty($this->new_image) ? $this->source_image : $this->new_image); - $charset = strtoupper(config_item('charset')); - $utf8_filename = ($charset !== 'UTF-8') - ? get_instance()->utf8->convert_to_utf8($filename, $charset) - : $filename; - isset($utf8_filename[0]) && $utf8_filename = " filename*=UTF-8''".rawurlencode($utf8_filename); - - header('Content-Disposition: filename="'.$filename.'";'.$utf8_filename); + header('Content-Disposition: filename='.$this->source_image.';'); header('Content-Type: '.$this->mime_type); header('Content-Transfer-Encoding: binary'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); @@ -1597,8 +1564,6 @@ public function image_display_gd($resource) break; case 3 : imagepng($resource); break; - case 18 : imagewebp($resource); - break; default: echo 'Unable to display the image'; break; } diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php new file mode 100644 index 00000000000..c9103945b73 --- /dev/null +++ b/system/libraries/Javascript.php @@ -0,0 +1,856 @@ + 'jquery', 'autoload' => TRUE); + + foreach ($defaults as $key => $val) + { + if (isset($params[$key]) && $params[$key] !== '') + { + $defaults[$key] = $params[$key]; + } + } + + extract($defaults); + + $this->CI =& get_instance(); + + // load the requested js library + $this->CI->load->library('Javascript/'.$js_library_driver, array('autoload' => $autoload)); + // make js to refer to current library + $this->js =& $this->CI->$js_library_driver; + + log_message('info', 'Javascript Class Initialized and loaded. Driver used: '.$js_library_driver); + } + + // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- + + /** + * Blur + * + * Outputs a javascript library blur event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function blur($element = 'this', $js = '') + { + return $this->js->_blur($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Change + * + * Outputs a javascript library change event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function change($element = 'this', $js = '') + { + return $this->js->_change($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Click + * + * Outputs a javascript library click event + * + * @param string The element to attach the event to + * @param string The code to execute + * @param bool whether or not to return false + * @return string + */ + public function click($element = 'this', $js = '', $ret_false = TRUE) + { + return $this->js->_click($element, $js, $ret_false); + } + + // -------------------------------------------------------------------- + + /** + * Double Click + * + * Outputs a javascript library dblclick event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function dblclick($element = 'this', $js = '') + { + return $this->js->_dblclick($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Outputs a javascript library error event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function error($element = 'this', $js = '') + { + return $this->js->_error($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Focus + * + * Outputs a javascript library focus event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function focus($element = 'this', $js = '') + { + return $this->js->_focus($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Hover + * + * Outputs a javascript library hover event + * + * @param string - element + * @param string - Javascript code for mouse over + * @param string - Javascript code for mouse out + * @return string + */ + public function hover($element = 'this', $over = '', $out = '') + { + return $this->js->_hover($element, $over, $out); + } + + // -------------------------------------------------------------------- + + /** + * Keydown + * + * Outputs a javascript library keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function keydown($element = 'this', $js = '') + { + return $this->js->_keydown($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Keyup + * + * Outputs a javascript library keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function keyup($element = 'this', $js = '') + { + return $this->js->_keyup($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Load + * + * Outputs a javascript library load event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function load($element = 'this', $js = '') + { + return $this->js->_load($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mousedown + * + * Outputs a javascript library mousedown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function mousedown($element = 'this', $js = '') + { + return $this->js->_mousedown($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Out + * + * Outputs a javascript library mouseout event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function mouseout($element = 'this', $js = '') + { + return $this->js->_mouseout($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Over + * + * Outputs a javascript library mouseover event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function mouseover($element = 'this', $js = '') + { + return $this->js->_mouseover($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouseup + * + * Outputs a javascript library mouseup event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function mouseup($element = 'this', $js = '') + { + return $this->js->_mouseup($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Output + * + * Outputs the called javascript to the screen + * + * @param string The code to output + * @return string + */ + public function output($js) + { + return $this->js->_output($js); + } + + // -------------------------------------------------------------------- + + /** + * Ready + * + * Outputs a javascript library mouseup event + * + * @param string $js Code to execute + * @return string + */ + public function ready($js) + { + return $this->js->_document_ready($js); + } + + // -------------------------------------------------------------------- + + /** + * Resize + * + * Outputs a javascript library resize event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function resize($element = 'this', $js = '') + { + return $this->js->_resize($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Scroll + * + * Outputs a javascript library scroll event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function scroll($element = 'this', $js = '') + { + return $this->js->_scroll($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Unload + * + * Outputs a javascript library unload event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + public function unload($element = 'this', $js = '') + { + return $this->js->_unload($element, $js); + } + + // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- + + /** + * Add Class + * + * Outputs a javascript library addClass event + * + * @param string - element + * @param string - Class to add + * @return string + */ + public function addClass($element = 'this', $class = '') + { + return $this->js->_addClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Animate + * + * Outputs a javascript library animate event + * + * @param string $element = 'this' + * @param array $params = array() + * @param mixed $speed 'slow', 'normal', 'fast', or time in milliseconds + * @param string $extra + * @return string + */ + public function animate($element = 'this', $params = array(), $speed = '', $extra = '') + { + return $this->js->_animate($element, $params, $speed, $extra); + } + + // -------------------------------------------------------------------- + + /** + * Fade In + * + * Outputs a javascript library hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function fadeIn($element = 'this', $speed = '', $callback = '') + { + return $this->js->_fadeIn($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Fade Out + * + * Outputs a javascript library hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function fadeOut($element = 'this', $speed = '', $callback = '') + { + return $this->js->_fadeOut($element, $speed, $callback); + } + // -------------------------------------------------------------------- + + /** + * Slide Up + * + * Outputs a javascript library slideUp event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function slideUp($element = 'this', $speed = '', $callback = '') + { + return $this->js->_slideUp($element, $speed, $callback); + + } + + // -------------------------------------------------------------------- + + /** + * Remove Class + * + * Outputs a javascript library removeClass event + * + * @param string - element + * @param string - Class to add + * @return string + */ + public function removeClass($element = 'this', $class = '') + { + return $this->js->_removeClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Slide Down + * + * Outputs a javascript library slideDown event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function slideDown($element = 'this', $speed = '', $callback = '') + { + return $this->js->_slideDown($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Slide Toggle + * + * Outputs a javascript library slideToggle event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function slideToggle($element = 'this', $speed = '', $callback = '') + { + return $this->js->_slideToggle($element, $speed, $callback); + + } + + // -------------------------------------------------------------------- + + /** + * Hide + * + * Outputs a javascript library hide action + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function hide($element = 'this', $speed = '', $callback = '') + { + return $this->js->_hide($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Toggle + * + * Outputs a javascript library toggle event + * + * @param string - element + * @return string + */ + public function toggle($element = 'this') + { + return $this->js->_toggle($element); + + } + + // -------------------------------------------------------------------- + + /** + * Toggle Class + * + * Outputs a javascript library toggle class event + * + * @param string $element = 'this' + * @param string $class = '' + * @return string + */ + public function toggleClass($element = 'this', $class = '') + { + return $this->js->_toggleClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Show + * + * Outputs a javascript library show event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function show($element = 'this', $speed = '', $callback = '') + { + return $this->js->_show($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Compile + * + * gather together all script needing to be output + * + * @param string $view_var + * @param bool $script_tags + * @return string + */ + public function compile($view_var = 'script_foot', $script_tags = TRUE) + { + $this->js->_compile($view_var, $script_tags); + } + + // -------------------------------------------------------------------- + + /** + * Clear Compile + * + * Clears any previous javascript collected for output + * + * @return void + */ + public function clear_compile() + { + $this->js->_clear_compile(); + } + + // -------------------------------------------------------------------- + + /** + * External + * + * Outputs a + * + * @param string + * @return string + */ + protected function _close_script($extra = "\n") + { + return ''.$extra; + } + + // -------------------------------------------------------------------- + // AJAX-Y STUFF - still a testbed + // -------------------------------------------------------------------- + + /** + * Update + * + * Outputs a javascript library slideDown event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + public function update($element = 'this', $speed = '', $callback = '') + { + return $this->js->_updater($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Generate JSON + * + * Can be passed a database result or associative array and returns a JSON formatted string + * + * @param mixed result set or array + * @param bool match array types (defaults to objects) + * @return string a json formatted string + */ + public function generate_json($result = NULL, $match_array_type = FALSE) + { + // JSON data can optionally be passed to this function + // either as a database result object or an array, or a user supplied array + if ($result !== NULL) + { + if (is_object($result)) + { + $json_result = is_callable(array($result, 'result_array')) ? $result->result_array() : (array) $result; + } + elseif (is_array($result)) + { + $json_result = $result; + } + else + { + return $this->_prep_args($result); + } + } + else + { + return 'null'; + } + + $json = array(); + $_is_assoc = TRUE; + + if ( ! is_array($json_result) && empty($json_result)) + { + show_error('Generate JSON Failed - Illegal key, value pair.'); + } + elseif ($match_array_type) + { + $_is_assoc = $this->_is_associative_array($json_result); + } + + foreach ($json_result as $k => $v) + { + if ($_is_assoc) + { + $json[] = $this->_prep_args($k, TRUE).':'.$this->generate_json($v, $match_array_type); + } + else + { + $json[] = $this->generate_json($v, $match_array_type); + } + } + + $json = implode(',', $json); + + return $_is_assoc ? '{'.$json.'}' : '['.$json.']'; + + } + + // -------------------------------------------------------------------- + + /** + * Is associative array + * + * Checks for an associative array + * + * @param array + * @return bool + */ + protected function _is_associative_array($arr) + { + foreach (array_keys($arr) as $key => $val) + { + if ($key !== $val) + { + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Prep Args + * + * Ensures a standard json value and escapes values + * + * @param mixed $result + * @param bool $is_key = FALSE + * @return string + */ + protected function _prep_args($result, $is_key = FALSE) + { + if ($result === NULL) + { + return 'null'; + } + elseif (is_bool($result)) + { + return ($result === TRUE) ? 'true' : 'false'; + } + elseif (is_string($result) OR $is_key) + { + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; + } + elseif (is_scalar($result)) + { + return $result; + } + } + +} diff --git a/system/libraries/Javascript/Jquery.php b/system/libraries/Javascript/Jquery.php new file mode 100644 index 00000000000..485d1dc1819 --- /dev/null +++ b/system/libraries/Javascript/Jquery.php @@ -0,0 +1,1076 @@ +CI =& get_instance(); + extract($params); + + if ($autoload === TRUE) + { + $this->script(); + } + + log_message('info', 'Jquery Class Initialized'); + } + + // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- + + /** + * Blur + * + * Outputs a jQuery blur event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _blur($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'blur'); + } + + // -------------------------------------------------------------------- + + /** + * Change + * + * Outputs a jQuery change event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _change($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'change'); + } + + // -------------------------------------------------------------------- + + /** + * Click + * + * Outputs a jQuery click event + * + * @param string The element to attach the event to + * @param string The code to execute + * @param bool whether or not to return false + * @return string + */ + protected function _click($element = 'this', $js = '', $ret_false = TRUE) + { + is_array($js) OR $js = array($js); + + if ($ret_false) + { + $js[] = 'return false;'; + } + + return $this->_add_event($element, $js, 'click'); + } + + // -------------------------------------------------------------------- + + /** + * Double Click + * + * Outputs a jQuery dblclick event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _dblclick($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'dblclick'); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Outputs a jQuery error event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _error($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'error'); + } + + // -------------------------------------------------------------------- + + /** + * Focus + * + * Outputs a jQuery focus event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _focus($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'focus'); + } + + // -------------------------------------------------------------------- + + /** + * Hover + * + * Outputs a jQuery hover event + * + * @param string - element + * @param string - Javascript code for mouse over + * @param string - Javascript code for mouse out + * @return string + */ + protected function _hover($element = 'this', $over = '', $out = '') + { + $event = "\n\t$(".$this->_prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; + + $this->jquery_code_for_compile[] = $event; + + return $event; + } + + // -------------------------------------------------------------------- + + /** + * Keydown + * + * Outputs a jQuery keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _keydown($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'keydown'); + } + + // -------------------------------------------------------------------- + + /** + * Keyup + * + * Outputs a jQuery keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _keyup($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'keyup'); + } + + // -------------------------------------------------------------------- + + /** + * Load + * + * Outputs a jQuery load event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _load($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'load'); + } + + // -------------------------------------------------------------------- + + /** + * Mousedown + * + * Outputs a jQuery mousedown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mousedown($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mousedown'); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Out + * + * Outputs a jQuery mouseout event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseout($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseout'); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Over + * + * Outputs a jQuery mouseover event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseover($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseover'); + } + + // -------------------------------------------------------------------- + + /** + * Mouseup + * + * Outputs a jQuery mouseup event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseup($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseup'); + } + + // -------------------------------------------------------------------- + + /** + * Output + * + * Outputs script directly + * + * @param array $array_js = array() + * @return void + */ + protected function _output($array_js = array()) + { + if ( ! is_array($array_js)) + { + $array_js = array($array_js); + } + + foreach ($array_js as $js) + { + $this->jquery_code_for_compile[] = "\t".$js."\n"; + } + } + + // -------------------------------------------------------------------- + + /** + * Resize + * + * Outputs a jQuery resize event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _resize($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'resize'); + } + + // -------------------------------------------------------------------- + + /** + * Scroll + * + * Outputs a jQuery scroll event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _scroll($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'scroll'); + } + + // -------------------------------------------------------------------- + + /** + * Unload + * + * Outputs a jQuery unload event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _unload($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'unload'); + } + + // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- + + /** + * Add Class + * + * Outputs a jQuery addClass event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _addClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').addClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Animate + * + * Outputs a jQuery animate event + * + * @param string $element + * @param array $params + * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds + * @param string $extra + * @return string + */ + protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + $animations = "\t\t\t"; + + foreach ($params as $param => $value) + { + $animations .= $param.": '".$value."', "; + } + + $animations = substr($animations, 0, -2); // remove the last ", " + + if ($speed !== '') + { + $speed = ', '.$speed; + } + + if ($extra !== '') + { + $extra = ', '.$extra; + } + + return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');'; + } + + // -------------------------------------------------------------------- + + /** + * Fade In + * + * Outputs a jQuery hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _fadeIn($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return "$({$element}).fadeIn({$speed}{$callback});"; + } + + // -------------------------------------------------------------------- + + /** + * Fade Out + * + * Outputs a jQuery hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _fadeOut($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').fadeOut('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Hide + * + * Outputs a jQuery hide action + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _hide($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return "$({$element}).hide({$speed}{$callback});"; + } + + // -------------------------------------------------------------------- + + /** + * Remove Class + * + * Outputs a jQuery remove class event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _removeClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').removeClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Up + * + * Outputs a jQuery slideUp event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideUp($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideUp('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Down + * + * Outputs a jQuery slideDown event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideDown($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideDown('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Toggle + * + * Outputs a jQuery slideToggle event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideToggle($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideToggle('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Toggle + * + * Outputs a jQuery toggle event + * + * @param string - element + * @return string + */ + protected function _toggle($element = 'this') + { + $element = $this->_prep_element($element); + return '$('.$element.').toggle();'; + } + + // -------------------------------------------------------------------- + + /** + * Toggle Class + * + * Outputs a jQuery toggle class event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _toggleClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').toggleClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Show + * + * Outputs a jQuery show event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _show($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').show('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Updater + * + * An Ajax call that populates the designated DOM node with + * returned content + * + * @param string The element to attach the event to + * @param string the controller to run the call against + * @param string optional parameters + * @return string + */ + + protected function _updater($container = 'this', $controller = '', $options = '') + { + $container = $this->_prep_element($container); + $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') === '') + { + $loading_notifier = 'Loading...'; + } + else + { + $loading_notifier = 'Loading'; + } + + $updater = '$('.$container.").empty();\n" // anything that was in... get it out + ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image + + $request_options = ''; + if ($options !== '') + { + $request_options .= ', {' + .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'") + .'}'; + } + + return $updater."\t\t$($container).load('$controller'$request_options);"; + } + + // -------------------------------------------------------------------- + // Pre-written handy stuff + // -------------------------------------------------------------------- + + /** + * Zebra tables + * + * @param string $class + * @param string $odd + * @param string $hover + * @return string + */ + protected function _zebraTables($class = '', $odd = 'odd', $hover = '') + { + $class = ($class !== '') ? '.'.$class : ''; + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $this->jquery_code_for_compile[] = $zebra; + + if ($hover !== '') + { + $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); + } + + return $zebra; + } + + // -------------------------------------------------------------------- + // Plugins + // -------------------------------------------------------------------- + + /** + * Corner Plugin + * + * @link http://www.malsup.com/jquery/corner/ + * @param string $element + * @param string $corner_style + * @return string + */ + public function corner($element = '', $corner_style = '') + { + // may want to make this configurable down the road + $corner_location = '/plugins/jquery.corner.js'; + + if ($corner_style !== '') + { + $corner_style = '"'.$corner_style.'"'; + } + + return '$('.$this->_prep_element($element).').corner('.$corner_style.');'; + } + + // -------------------------------------------------------------------- + + /** + * Modal window + * + * Load a thickbox modal window + * + * @param string $src + * @param bool $relative + * @return void + */ + public function modal($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Effect + * + * Load an Effect library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function effect($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Plugin + * + * Load a plugin library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function plugin($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * UI + * + * Load a user interface library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function ui($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Sortable + * + * Creates a jQuery sortable + * + * @param string $element + * @param array $options + * @return string + */ + public function sortable($element, $options = array()) + { + if (count($options) > 0) + { + $sort_options = array(); + foreach ($options as $k=>$v) + { + $sort_options[] = "\n\t\t".$k.': '.$v; + } + $sort_options = implode(',', $sort_options); + } + else + { + $sort_options = ''; + } + + return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});"; + } + + // -------------------------------------------------------------------- + + /** + * Table Sorter Plugin + * + * @param string table name + * @param string plugin location + * @return string + */ + public function tablesorter($table = '', $options = '') + { + $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n"; + } + + // -------------------------------------------------------------------- + // Class functions + // -------------------------------------------------------------------- + + /** + * Add Event + * + * Constructs the syntax for an event, and adds to into the array for compilation + * + * @param string The element to attach the event to + * @param string The code to execute + * @param string The event to pass + * @return string + */ + protected function _add_event($element, $js, $event) + { + if (is_array($js)) + { + $js = implode("\n\t\t", $js); + } + + $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n"; + $this->jquery_code_for_compile[] = $event; + return $event; + } + + // -------------------------------------------------------------------- + + /** + * Compile + * + * As events are specified, they are stored in an array + * This function compiles them all for output on a page + * + * @param string $view_var + * @param bool $script_tags + * @return void + */ + protected function _compile($view_var = 'script_foot', $script_tags = TRUE) + { + // External references + $external_scripts = implode('', $this->jquery_code_for_load); + $this->CI->load->vars(array('library_src' => $external_scripts)); + + if (count($this->jquery_code_for_compile) === 0) + { + // no inline references, let's just return + return; + } + + // Inline references + $script = '$(document).ready(function() {'."\n" + .implode('', $this->jquery_code_for_compile) + .'});'; + + $output = ($script_tags === FALSE) ? $script : $this->inline($script); + + $this->CI->load->vars(array($view_var => $output)); + } + + // -------------------------------------------------------------------- + + /** + * Clear Compile + * + * Clears the array of script events collected for output + * + * @return void + */ + protected function _clear_compile() + { + $this->jquery_code_for_compile = array(); + } + + // -------------------------------------------------------------------- + + /** + * Document Ready + * + * A wrapper for writing document.ready() + * + * @param array $js + * @return void + */ + protected function _document_ready($js) + { + is_array($js) OR $js = array($js); + + foreach ($js as $script) + { + $this->jquery_code_for_compile[] = $script; + } + } + + // -------------------------------------------------------------------- + + /** + * Script Tag + * + * Outputs the script tag that loads the jquery.js file into an HTML document + * + * @param string $library_src + * @param bool $relative + * @return string + */ + public function script($library_src = '', $relative = FALSE) + { + $library_src = $this->external($library_src, $relative); + $this->jquery_code_for_load[] = $library_src; + return $library_src; + } + + // -------------------------------------------------------------------- + + /** + * Prep Element + * + * Puts HTML element in quotes for use in jQuery code + * unless the supplied element is the Javascript 'this' + * object, in which case no quotes are added + * + * @param string + * @return string + */ + protected function _prep_element($element) + { + if ($element !== 'this') + { + $element = '"'.$element.'"'; + } + + return $element; + } + + // -------------------------------------------------------------------- + + /** + * Validate Speed + * + * Ensures the speed parameter is valid for jQuery + * + * @param string + * @return string + */ + protected function _validate_speed($speed) + { + if (in_array($speed, array('slow', 'normal', 'fast'))) + { + return '"'.$speed.'"'; + } + elseif (preg_match('/[^0-9]/', $speed)) + { + return ''; + } + + return $speed; + } + +} diff --git a/system/libraries/Javascript/index.html b/system/libraries/Javascript/index.html new file mode 100644 index 00000000000..b702fbc3967 --- /dev/null +++ b/system/libraries/Javascript/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 11d63fe50b9..5d501a966ba 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -686,7 +686,7 @@ protected function _parse_attributes($attributes) /** * Add "rel" attribute * - * @link https://www.w3.org/TR/html5/links.html#linkTypes + * @link http://www.w3.org/TR/html5/links.html#linkTypes * @param string $type * @return string */ diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index dfd0f432e87..9b834f86ae8 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -105,7 +105,23 @@ public function __construct(array $params = array()) $class = new $class($this->_config); if ($class instanceof SessionHandlerInterface) { - session_set_save_handler($class, TRUE); + if (is_php('5.4')) + { + session_set_save_handler($class, TRUE); + } + else + { + session_set_save_handler( + array($class, 'open'), + array($class, 'close'), + array($class, 'read'), + array($class, 'write'), + array($class, 'destroy'), + array($class, 'gc') + ); + + register_shutdown_function('session_write_close'); + } } else { @@ -174,6 +190,9 @@ public function __construct(array $params = array()) */ protected function _ci_load_classes($driver) { + // PHP 5.4 compatibility + interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php'); + $prefix = config_item('subclass_prefix'); if ( ! class_exists('CI_Session_driver', FALSE)) diff --git a/system/libraries/Session/SessionHandlerInterface.php b/system/libraries/Session/SessionHandlerInterface.php new file mode 100644 index 00000000000..240c5f54e88 --- /dev/null +++ b/system/libraries/Session/SessionHandlerInterface.php @@ -0,0 +1,59 @@ +\?.+)?$#', $this->_config['save_path'], $matches)) + elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches)) { - $save_path = array('path' => $matches[1]); - } - elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(?\?.+)?#', $this->_config['save_path'], $matches)) - { - $save_path = array( - 'host' => $matches[1], - 'port' => empty($matches[2]) ? NULL : $matches[2], - 'timeout' => NULL // We always pass this to Redis::connect(), so it needs to exist + isset($matches[3]) OR $matches[3] = ''; // Just to avoid undefined index notices below + $this->_config['save_path'] = array( + 'host' => $matches[1], + 'port' => empty($matches[2]) ? NULL : $matches[2], + 'password' => preg_match('#auth=([^\s&]+)#', $matches[3], $match) ? $match[1] : NULL, + 'database' => preg_match('#database=(\d+)#', $matches[3], $match) ? (int) $match[1] : NULL, + 'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[3], $match) ? (float) $match[1] : NULL ); + + preg_match('#prefix=([^\s&]+)#', $matches[3], $match) && $this->_key_prefix = $match[1]; } else { log_message('error', 'Session: Invalid Redis save path format: '.$this->_config['save_path']); } - if (isset($save_path)) + if ($this->_config['match_ip'] === TRUE) { - if (isset($matches['options'])) - { - $save_path['password'] = preg_match('#auth=([^\s&]+)#', $matches['options'], $match) ? $match[1] : NULL; - $save_path['database'] = preg_match('#database=(\d+)#', $matches['options'], $match) ? (int) $match[1] : NULL; - $save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : NULL; - - preg_match('#prefix=([^\s&]+)#', $matches['options'], $match) && $this->_key_prefix = $match[1]; - } - - $this->_config['save_path'] = $save_path; - - if ($this->_config['match_ip'] === TRUE) - { - $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; - } + $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; } } @@ -189,30 +176,17 @@ public function open($save_path, $name) } $redis = new Redis(); - $connected = isset($this->_config['save_path']['path']) - ? $redis->connect($this->_config['save_path']['path']) - : $redis->connect( - $this->_config['save_path']['host'], - $this->_config['save_path']['port'], - $this->_config['save_path']['timeout'] - ); - - if ($connected) + if ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) { - if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) - { - log_message('error', 'Session: Unable to authenticate to Redis instance.'); - } - elseif (isset($this->_config['save_path']['database']) && ! $redis->select($this->_config['save_path']['database'])) - { - log_message('error', 'Session: Unable to select Redis database with index '.$this->_config['save_path']['database']); - } - else - { - $this->_redis = $redis; - $this->php5_validate_id(); - return $this->_success; - } + log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + } + elseif (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) + { + log_message('error', 'Session: Unable to authenticate to Redis instance.'); + } + elseif (isset($this->_config['save_path']['database']) && ! $redis->select($this->_config['save_path']['database'])) + { + log_message('error', 'Session: Unable to select Redis database with index '.$this->_config['save_path']['database']); } else { diff --git a/system/libraries/Session/drivers/index.html b/system/libraries/Session/drivers/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/libraries/Session/drivers/index.html +++ b/system/libraries/Session/drivers/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/libraries/Session/index.html b/system/libraries/Session/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/libraries/Session/index.html +++ b/system/libraries/Session/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 05551269868..06e8d709889 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -427,7 +427,6 @@ public function clear() $this->rows = array(); $this->heading = array(); $this->auto_heading = TRUE; - $this->caption = NULL; return $this; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 95f765b782c..ed78af18c43 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1183,7 +1183,7 @@ public function display_errors($open = '

', $close = '

') * Prevents possible script execution from Apache's handling * of files' multiple extensions. * - * @link https://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext + * @link http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext * * @param string $filename * @return string @@ -1257,7 +1257,9 @@ protected function _file_mime_type($file) */ 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_usable('exec')) { @@ -1274,7 +1276,7 @@ protected function _file_mime_type($file) } } - if (function_usable('shell_exec')) + if ( ! ini_get('safe_mode') && function_usable('shell_exec')) { $mime = @shell_exec($cmd); if (strlen($mime) > 0) diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 4e8c303c7d2..690b245be98 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -743,7 +743,7 @@ public function sendPayload($msg) { break; } - // See https://bugs.php.net/bug.php?id=39598 and https://secure.php.net/manual/en/function.fwrite.php#96951 + // See https://bugs.php.net/bug.php?id=39598 and http://php.net/manual/en/function.fwrite.php#96951 elseif ($result === 0) { if ($timestamp === 0) @@ -836,7 +836,9 @@ public function __construct($val, $code = 0, $fstr = '') { // error $this->errno = $code; - $this->errstr = htmlspecialchars($fstr, ENT_XML1 | ENT_NOQUOTES, 'UTF-8'); + $this->errstr = htmlspecialchars($fstr, + (is_php('5.4') ? ENT_XML1 | ENT_NOQUOTES : ENT_NOQUOTES), + 'UTF-8'); } elseif ( ! is_object($val)) { diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 4579e8c2b71..52fac2f8a34 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -41,7 +41,7 @@ * Zip Compression Class * * This class is based on a library I found at Zend: - * https://www.zend.com/codex.php?id=696&single=1 + * http://www.zend.com/codex.php?id=696&single=1 * * The original library is a little rough around the edges so I * refactored it and added several additional methods -- Rick Ellis @@ -366,7 +366,7 @@ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) while (FALSE !== ($file = readdir($fp))) { - if ($file === '.' OR $file === '..') + if ($file[0] === '.') { continue; } @@ -520,6 +520,9 @@ protected static function substr($str, $start, $length = NULL) { if (self::$func_overload) { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); return mb_substr($str, $start, $length, '8bit'); } diff --git a/system/libraries/index.html b/system/libraries/index.html index bcb7cae3433..b702fbc3967 100644 --- a/system/libraries/index.html +++ b/system/libraries/index.html @@ -1,5 +1,5 @@ - + 403 Forbidden diff --git a/tests/README.md b/tests/README.md index 365f551a182..04dfbc3d89b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # CodeIgniter Unit Tests # -Status : [![Build Status](https://secure.travis-ci.org/bcit-ci/CodeIgniter.png?branch=develop)](https://travis-ci.org/bcit-ci/CodeIgniter) +Status : [![Build Status](https://secure.travis-ci.org/bcit-ci/CodeIgniter.png?branch=develop)](http://travis-ci.org/bcit-ci/CodeIgniter) ### Introduction: @@ -8,7 +8,7 @@ This is the preliminary CodeIgniter testing documentation. It will cover both internal as well as external APIs and the reasoning behind their implementation, where appropriate. As with all CodeIgniter documentation, this file should maintain a mostly human readable -format to facilitate clean api design. [see https://arrenbrecht.ch/testing/] +format to facilitate clean api design. [see http://arrenbrecht.ch/testing/] *First public draft: everything is subject to change* diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php deleted file mode 100644 index 5317c56c70b..00000000000 --- a/tests/codeigniter/Setup_test.php +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 33bd742b2f6..00000000000 --- a/tests/codeigniter/core/Benchmark_test.php +++ /dev/null @@ -1,67 +0,0 @@ -benchmark = new CI_Benchmark(); - } - - // -------------------------------------------------------------------- - - public function test_mark() - { - $this->assertEmpty($this->benchmark->marker); - - $this->benchmark->mark('code_start'); - - $this->assertCount(1, $this->benchmark->marker); - $this->assertArrayHasKey('code_start', $this->benchmark->marker); - } - - // -------------------------------------------------------------------- - - public function test_elapsed_time() - { - $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time()); - $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); - - $this->benchmark->mark('code_start'); - $this->benchmark->mark('code_end'); - - // Override values, because time isn't testable, but make sure the markers were set - if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start'])) - { - $this->benchmark->marker['code_start'] = 1389956144.1944; - } - - if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end'])) - { - $this->benchmark->marker['code_end'] = 1389956145.1946; - } - - $this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0)); - $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); - $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2)); - $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); - $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4)); - $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end')); - - // Test with non-existing 2nd marker, but again - we need to override the value - $this->benchmark->elapsed_time('code_start', 'code_end2'); - if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2'])) - { - $this->benchmark->marker['code_end2'] = 1389956146.2046; - } - - $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2')); - } - - // -------------------------------------------------------------------- - - public function test_memory_usage() - { - $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); - } - -} diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php deleted file mode 100644 index effae50c596..00000000000 --- a/tests/codeigniter/core/Common_test.php +++ /dev/null @@ -1,69 +0,0 @@ -assertTrue(is_php('1.2.0')); - $this->assertFalse(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)); - } - - // ------------------------------------------------------------------------ - - public function test_html_escape() - { - $this->assertEquals( - html_escape('Here is a string containing "quoted" text.'), - 'Here is a string containing "quoted" text.' - ); - - $this->assertEquals( - html_escape(array('associative' => 'and', array('multi' => 'dimentional'))), - array('associative' => 'and', array('multi' => 'dimentional')) - ); - } - - // ------------------------------------------------------------------------ - - public function test_remove_invisible_characters() - { - $raw_string = 'Here is a string containing invisible'.chr(0x08).' text %0e.'; - $removed_string = 'Here is a string containing invisible text %0e.'; - $this->assertEquals($removed_string, remove_invisible_characters($raw_string, FALSE)); - - $raw_string = 'Here is a string %0econtaining url_encoded invisible%1F text.'; - $removed_string = 'Here is a string containing url_encoded invisible text.'; - $this->assertEquals($removed_string, remove_invisible_characters($raw_string)); - } -} diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php deleted file mode 100644 index 5201d46dcdd..00000000000 --- a/tests/codeigniter/core/Config_test.php +++ /dev/null @@ -1,233 +0,0 @@ -ci_core_class('cfg'); - - // set predictable config values - $this->cfg = array( - 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', - 'subclass_prefix' => 'MY_' - ); - $this->ci_set_config($this->cfg); - - $this->config = new $cls; - } - - // -------------------------------------------------------------------- - - public function test_item() - { - $this->assertEquals($this->cfg['base_url'], $this->config->item('base_url')); - - // Bad Config value - $this->assertNull($this->config->item('no_good_item')); - - // Index - $this->assertNull($this->config->item('no_good_item', 'bad_index')); - $this->assertNull($this->config->item('no_good_item', 'default')); - } - - // -------------------------------------------------------------------- - - public function test_set_item() - { - $this->assertNull($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->assertNull($this->config->slash_item('no_good_item')); - - $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url')); - $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix')); - } - - // -------------------------------------------------------------------- - - public function test_base_url() - { - // Test regular base URL - $base_url = $this->cfg['base_url']; - $this->assertEquals($base_url, $this->config->base_url()); - - // Test with URI - $uri = 'test'; - $this->assertEquals($base_url.$uri, $this->config->base_url($uri)); - - // Clear base_url - $this->ci_set_config('base_url', ''); - - // Rerun constructor - $cls =& $this->ci_core_class('cfg'); - $this->config = new $cls; - - // Test default base - $this->assertEquals('http://localhost/', $this->config->base_url()); - - // Capture server vars - $old_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL; - $old_script_name = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL; - $old_script_filename = $_SERVER['SCRIPT_FILENAME']; - $old_https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : NULL; - $old_server_addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : NULL; - - // The 'Host' header is user input and must not be trusted - $_SERVER['HTTP_HOST'] = 'test.com'; - $this->config = new $cls; - $this->assertEquals('http://localhost/', $this->config->base_url()); - - // However, we may fallback to the server's IP address - $_SERVER['SERVER_ADDR'] = '127.0.0.1'; - $_SERVER['SCRIPT_NAME'] = '/base_test.php'; - $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/base_test.php'; - $this->config = new $cls; - $this->assertEquals('http://127.0.0.1/', $this->config->base_url()); - - // Making sure that HTTPS and URI path are also detected - $_SERVER['HTTPS'] = 'on'; - $_SERVER['SCRIPT_NAME'] = '/path/base_test.php'; - $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/path/base_test.php'; - $this->config = new $cls; - $this->assertEquals('https://127.0.0.1/path/', $this->config->base_url()); - - // Restore server vars - $_SERVER['HTTP_HOST'] = $old_host; - $_SERVER['SCRIPT_NAME'] = $old_script_name; - $_SERVER['SCRIPT_FILENAME'] = $old_script_filename; - $_SERVER['HTTPS'] = $old_https; - $_SERVER['SERVER_ADDR'] = $old_server_addr; - } - - // -------------------------------------------------------------------- - - public function test_site_url() - { - $base_url = $this->cfg['base_url']; - $index_page = $this->cfg['index_page']; - $this->assertEquals($base_url.$index_page, $this->config->site_url()); - - $old_base = $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); - - $uri = 'test'; - $uri2 = '1'; - $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri)); - $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2))); - - $this->assertEquals($index_page.'/test/', $this->config->site_url('test/')); - - $suffix = 'ing'; - $this->config->set_item('url_suffix', $suffix); - - $arg = 'pass'; - $this->assertEquals($index_page.'/'.$uri.$suffix, $this->config->site_url($uri)); - $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg)); - - $this->config->set_item('url_suffix', FALSE); - $this->config->set_item('enable_query_strings', TRUE); - - $this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri)); - $this->assertEquals($index_page.'?0='.$uri.'&1='.$uri2, $this->config->site_url(array($uri, $uri2))); - - $this->config->set_item('base_url', $old_base); - - $this->assertEquals($base_url.$index_page.'?'.$uri, $this->config->site_url($uri)); - - // back to home base - $this->config->set_item('enable_query_strings', $q_string); - } - - // -------------------------------------------------------------------- - - public function test_load() - { - // Test regular load - $file = 'test.php'; - $key = 'testconfig'; - $val = 'my_value'; - $cfg = array($key => $val); - $this->ci_vfs_create($file, 'ci_app_root, 'config'); - $this->assertTrue($this->config->load($file)); - $this->assertEquals($val, $this->config->item($key)); - - // Test reload - value should not change - $val2 = 'new_value'; - $cfg = array($key => $val2); - $this->ci_vfs_create($file, 'ci_app_root, 'config'); - $this->assertTrue($this->config->load($file)); - $this->assertEquals($val, $this->config->item($key)); - - // Test section load - $file = 'secttest'; - $cfg = array( - 'one' => 'prime', - 'two' => 2, - 'three' => TRUE - ); - $this->ci_vfs_create($file.'.php', 'ci_app_root, 'config'); - $this->assertTrue($this->config->load($file, TRUE)); - $this->assertEquals($cfg, $this->config->item($file)); - - // Test section merge - $cfg2 = array( - 'three' => 'tres', - 'number' => 42, - 'letter' => 'Z' - ); - - $pkg_dir = 'package'; - $this->ci_vfs_create( - $file.'.php', - 'ci_app_root, - array($pkg_dir, 'config') - ); - array_unshift($this->config->_config_paths, $this->ci_vfs_path($pkg_dir.'/', APPPATH)); - $this->assertTrue($this->config->load($file, TRUE)); - $this->assertEquals(array_merge($cfg, $cfg2), $this->config->item($file)); - array_shift($this->config->_config_paths); - - // Test graceful fail of invalid file - $file = 'badfile'; - $this->ci_vfs_create($file, '', $this->ci_app_root, 'config'); - $this->assertFalse($this->config->load($file, FALSE, TRUE)); - - // Test regular fail of invalid file - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH). - ' file does not appear to contain a valid configuration array.' - ); - $this->assertNull($this->config->load($file)); - } - - // -------------------------------------------------------------------- - - public function test_load_nonexistent() - { - // Test graceful fail of nonexistent file - $this->assertFalse($this->config->load('not_config_file', FALSE, TRUE)); - - // Test regular fail - $file = 'absentia'; - $this->setExpectedException( - 'RuntimeException', - 'CI Error: The configuration file '.$file.'.php does not exist.' - ); - $this->assertNull($this->config->load($file)); - } - -} diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php deleted file mode 100644 index 07a99e13672..00000000000 --- a/tests/codeigniter/core/Input_test.php +++ /dev/null @@ -1,317 +0,0 @@ -ci_set_config('allow_get_array', TRUE); - $this->ci_set_config('global_xss_filtering', FALSE); - $this->ci_set_config('csrf_protection', FALSE); - - $security = new Mock_Core_Security('UTF-8'); - $this->input = new CI_Input($security); - } - - // -------------------------------------------------------------------- - - public function test_get_not_exists() - { - $this->assertSame(array(), $this->input->get()); - $this->assertNull($this->input->get('foo')); - } - - // -------------------------------------------------------------------- - - public function test_get_exist() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET['foo'] = 'bar'; - - $this->assertArrayHasKey('foo', $this->input->get()); - $this->assertEquals('bar', $this->input->get('foo')); - } - - // -------------------------------------------------------------------- - - public function test_get_exist_with_xss_clean() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET['harm'] = "Hello, i try to your site"; - - $this->assertArrayHasKey('harm', $this->input->get()); - $this->assertEquals("Hello, i try to your site", $this->input->get('harm')); - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_post_not_exists() - { - $this->assertSame(array(), $this->input->post()); - $this->assertNull($this->input->post('foo')); - } - - // -------------------------------------------------------------------- - - public function test_post_exist() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo'] = 'bar'; - - $this->assertArrayHasKey('foo', $this->input->post()); - $this->assertEquals('bar', $this->input->post('foo')); - } - - // -------------------------------------------------------------------- - - public function test_post_exist_with_xss_clean() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['harm'] = "Hello, i try to your site"; - - $this->assertArrayHasKey('harm', $this->input->post()); - $this->assertEquals("Hello, i try to your site", $this->input->post('harm')); - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_post_get() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo'] = 'bar'; - - $this->assertEquals('bar', $this->input->post_get('foo')); - } - - // -------------------------------------------------------------------- - - public function test_post_get_array_notation() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo']['bar'] = 'baz'; - $barArray = array('bar' => 'baz'); - - $this->assertEquals('baz', $this->input->get_post('foo[bar]')); - $this->assertEquals($barArray, $this->input->get_post('foo[]')); - $this->assertNull($this->input->get_post('foo[baz]')); - - $this->assertEquals('baz', $this->input->post_get('foo[bar]')); - $this->assertEquals($barArray, $this->input->post_get('foo[]')); - $this->assertNull($this->input->post_get('foo[baz]')); - } - - // -------------------------------------------------------------------- - - public function test_get_post() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET['foo'] = 'bar'; - - $this->assertEquals('bar', $this->input->get_post('foo')); - } - - // -------------------------------------------------------------------- - - public function test_get_post_array_notation() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET['foo']['bar'] = 'baz'; - $barArray = array('bar' => 'baz'); - - $this->assertEquals('baz', $this->input->get_post('foo[bar]')); - $this->assertEquals($barArray, $this->input->get_post('foo[]')); - $this->assertNull($this->input->get_post('foo[baz]')); - - $this->assertEquals('baz', $this->input->post_get('foo[bar]')); - $this->assertEquals($barArray, $this->input->post_get('foo[]')); - $this->assertNull($this->input->post_get('foo[baz]')); - } - - // -------------------------------------------------------------------- - - public function test_cookie() - { - $_COOKIE['foo'] = 'bar'; - $this->assertEquals('bar', $this->input->cookie('foo')); - $this->assertNull($this->input->cookie('bar')); - } - - // -------------------------------------------------------------------- - - public function test_server() - { - $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); - } - - // -------------------------------------------------------------------- - - public function test_fetch_from_array() - { - $reflection = new ReflectionMethod($this->input, '_fetch_from_array'); - $reflection->setAccessible(TRUE); - - $data = array( - 'foo' => 'bar', - 'harm' => 'Hello, i try to your site', - ); - - $foo = $reflection->invokeArgs($this->input, [&$data, 'foo']); - $harm = $reflection->invokeArgs($this->input, [&$data, 'harm']); - $harmless = $reflection->invokeArgs($this->input, [&$data, 'harm', TRUE]); - - $this->assertEquals('bar', $foo); - $this->assertEquals("Hello, i try to your site", $harm); - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); - - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo']['bar'] = 'baz'; - $barArray = array('bar' => 'baz'); - - $this->assertEquals('baz', $this->input->post('foo[bar]')); - $this->assertEquals($barArray, $this->input->post('foo[]')); - $this->assertNull($this->input->post('foo[baz]')); - } - - // -------------------------------------------------------------------- - - public function test_valid_ip() - { - $this->assertTrue($this->input->valid_ip('192.18.0.1')); - $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4')); - $this->assertFalse($this->input->valid_ip('555.0.0.0')); - $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4')); - - // v6 tests - $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6')); - - $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)); - $this->assertTrue($this->input->valid_ip($ip, 'ipv6')); - } - } - - // -------------------------------------------------------------------- - - public function test_method() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - $this->assertEquals('get', $this->input->method()); - $this->assertEquals('GET', $this->input->method(TRUE)); - $_SERVER['REQUEST_METHOD'] = 'POST'; - $this->assertEquals('post', $this->input->method()); - $this->assertEquals('POST', $this->input->method(TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_is_ajax_request() - { - $this->assertFalse($this->input->is_ajax_request()); - $_SERVER['HTTP_X_REQUESTED_WITH'] = 'test'; - $this->assertFalse($this->input->is_ajax_request()); - $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; - $this->assertTrue($this->input->is_ajax_request()); - } - - // -------------------------------------------------------------------- - - public function test_input_stream() - { - $this->markTestSkipped('TODO: Find a way to test input://'); - } - - // -------------------------------------------------------------------- - - public function test_set_cookie() - { - $this->markTestSkipped('TODO: Find a way to test HTTP headers'); - } - - // -------------------------------------------------------------------- - - public function test_get_request_header() - { - $this->markTestSkipped('TODO: Find a way to test HTTP headers'); - } - - // -------------------------------------------------------------------- - - public function test_ip_address() - { - $reflection = new ReflectionProperty($this->input, 'ip_address'); - $reflection->setAccessible(TRUE); - - $reflection->setValue($this->input, '127.0.0.1'); - $this->assertEquals('127.0.0.1', $this->input->ip_address()); - - // 127.0.0.1 is set in our Bootstrap file - $reflection->setValue($this->input, FALSE); - $this->assertEquals('127.0.0.1', $this->input->ip_address()); - - // Invalid - $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address'; - $reflection->setValue($this->input, FALSE); // reset cached value - $this->assertEquals('0.0.0.0', $this->input->ip_address()); - - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - - // Proxy_ips tests - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', '127.0.0.3, 127.0.0.4, 127.0.0.2'); - $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; - $this->assertEquals('127.0.0.1', $this->input->ip_address()); - - // Invalid spoof - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', 'invalid_ip_address'); - $_SERVER['HTTP_CLIENT_IP'] = 'invalid_ip_address'; - $this->assertEquals('127.0.0.1', $this->input->ip_address()); - - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.1/1'); - $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1'; - $this->assertEquals('127.0.0.1', $this->input->ip_address()); - - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.2'); - $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; - $_SERVER['REMOTE_ADDR'] = '127.0.0.2'; - $this->assertEquals('127.0.0.2', $this->input->ip_address()); - - // IPv6 - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329/1, FE80:0000:0000:0000:0202:B3FF:FE1E:8300/2'); - $_SERVER['HTTP_CLIENT_IP'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8300'; - $_SERVER['REMOTE_ADDR'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'; - $this->assertEquals('FE80:0000:0000:0000:0202:B3FF:FE1E:8300', $this->input->ip_address()); - - $reflection->setValue($this->input, FALSE); - $this->ci_set_config('proxy_ips', '0::/32'); - $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.7'; - $_SERVER['REMOTE_ADDR'] = '0000:0000:0000:0000:0000:0000:0000:0001'; - $this->assertEquals('127.0.0.7', $this->input->ip_address()); - - $reflection->setValue($this->input, FALSE); - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality - } - - // -------------------------------------------------------------------- - - public function test_user_agent() - { - $_SERVER['HTTP_USER_AGENT'] = 'test'; - $this->assertEquals('test', $this->input->user_agent()); - } -} diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php deleted file mode 100644 index 4958f42e12c..00000000000 --- a/tests/codeigniter/core/Lang_test.php +++ /dev/null @@ -1,101 +0,0 @@ -ci_core_class('load'); - $this->ci_instance_var('load', new $loader_cls); - $cls = $this->ci_core_class('lang'); - $this->lang = new $cls; - } - - // -------------------------------------------------------------------- - - public function test_load() - { - // Regular usage - $this->ci_vfs_clone('system/language/english/profiler_lang.php'); - $this->assertTrue($this->lang->load('profiler', 'english')); - $this->assertEquals('URI STRING', $this->lang->language['profiler_uri_string']); - - // Already loaded file - $this->assertNull($this->lang->load('profiler', 'english')); - - // Unspecified language (defaults to english) - $this->ci_vfs_clone('system/language/english/date_lang.php'); - $this->assertTrue($this->lang->load('date')); - $this->assertEquals('Year', $this->lang->language['date_year']); - - // A language other than english - $this->ci_vfs_clone('system/language/english/email_lang.php', 'system/language/german/'); - $this->assertTrue($this->lang->load('email', 'german')); - $this->assertEquals('german', $this->lang->is_loaded['email_lang.php']); - - // Non-existent file - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested language file: language/english/nonexistent_lang.php' - ); - $this->lang->load('nonexistent'); - } - - // -------------------------------------------------------------------- - - public function test_non_alpha_idiom() - { - // Non-alpha idiom (should act the same as unspecified language) - // test with existing file - $this->ci_vfs_clone('system/language/english/number_lang.php'); - $this->ci_vfs_clone('system/language/english/number_lang.php', 'system/language/123funny/'); - $this->assertTrue($this->lang->load('number', '123funny')); - $this->assertEquals('Bytes', $this->lang->language['bytes']); - - // test without existing file - $this->ci_vfs_clone('system/language/english/email_lang.php'); - $this->assertTrue($this->lang->load('email', '456funny')); - $this->assertEquals('You did not specify a SMTP hostname.', $this->lang->language['email_no_hostname']); - } - - // -------------------------------------------------------------------- - - public function test_multiple_file_load() - { - // Multiple files - $this->ci_vfs_clone('system/language/english/profiler_lang.php'); - $files = array( - 0 => 'profiler', - 1 => 'nonexistent' - ); - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested language file: language/english/nonexistent_lang.php' - ); - $this->lang->load($files, 'english'); - } - - // -------------------------------------------------------------------- - - public function test_alternative_path_load() - { - // Alternative Path - $this->ci_vfs_clone('system/language/english/profiler_lang.php'); - $this->assertTrue($this->lang->load('profiler', 'english', FALSE, TRUE, 'vfs://system/')); - } - - // -------------------------------------------------------------------- - - /** - * @depends test_load - */ - public function test_line() - { - $this->ci_vfs_clone('system/language/english/profiler_lang.php'); - $this->lang->load('profiler', 'english'); - $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); - $this->assertFalse($this->lang->line('nonexistent_string')); - $this->assertFalse($this->lang->line(NULL)); - } -} diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php deleted file mode 100644 index df698f30ce5..00000000000 --- a/tests/codeigniter/core/Loader_test.php +++ /dev/null @@ -1,602 +0,0 @@ -ci_core_class('loader'); - $this->load = new $loader(); - - // Get CI instance - $this->ci_obj = $this->ci_instance(); - - // Set subclass prefix - $this->prefix = 'MY_'; - $this->ci_set_config('subclass_prefix', $this->prefix); - } - - // -------------------------------------------------------------------- - - public function test_library() - { - // Test getting CI_Loader object - $this->assertInstanceOf('CI_Loader', $this->load->library(NULL)); - - // Create library in VFS - $lib = 'unit_test_lib'; - $class = 'CI_'.ucfirst($lib); - $this->ci_vfs_create(ucfirst($lib), 'ci_base_root, 'libraries'); - - // Test is_loaded fail - $this->assertFalse($this->load->is_loaded(ucfirst($lib))); - - // Test loading as an array. - $this->assertInstanceOf('CI_Loader', $this->load->library(array($lib))); - $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); - - // Create library in VFS - $lib = array('unit_test_lib' => 'unit_test_lib'); - - // Test loading as an array (int). - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - $this->assertTrue(class_exists($class), $class.' does not exist'); - - // Test a string given to params - $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' ')); - - // test non existent lib - $lib = 'non_existent_test_lib'; - - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested class: '.ucfirst($lib) - ); - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - } - - // -------------------------------------------------------------------- - - public function test_bad_library() - { - $lib = 'bad_test_lib'; - $this->ci_vfs_create(ucfirst($lib), '', $this->ci_app_root, 'libraries'); - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Non-existent class: '.ucfirst($lib) - ); - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - } - - // -------------------------------------------------------------------- - - public function test_library_extension() - { - // Create library and extension in VFS - $name = 'ext_test_lib'; - $lib = ucfirst($name); - $class = 'CI_'.$lib; - $ext = $this->prefix.$lib; - $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); - $this->ci_vfs_create($ext, 'ci_app_root, 'libraries'); - - // Test loading with extension - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertTrue(class_exists($ext), $ext.' does not exist'); - $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); - $this->assertAttributeInstanceOf($ext, $name, $this->ci_obj); - - // Test reloading with object name - $obj = 'exttest'; - $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); - $this->assertAttributeInstanceOf($ext, $obj, $this->ci_obj); - - // Test reloading - unset($this->ci_obj->$name); - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - $this->assertObjectHasAttribute($name, $this->ci_obj); - - // Create baseless library - $name = 'ext_baseless_lib'; - $lib = ucfirst($name); - $class = $this->prefix.$lib; - $this->ci_vfs_create($class, 'ci_app_root, 'libraries'); - - // Test missing base class - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested class: '.$lib - ); - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - } - - // -------------------------------------------------------------------- - - public function test_library_config() - { - // Create library in VFS - $lib = 'unit_test_config_lib'; - $class = 'CI_'.ucfirst($lib); - $content = 'config = $params; } }'; - $this->ci_vfs_create(ucfirst($lib), $content, $this->ci_base_root, 'libraries'); - - // Create config file - $cfg = array( - 'foo' => 'bar', - 'bar' => 'baz', - 'baz' => false - ); - $this->ci_vfs_create($lib, 'ci_app_root, 'config'); - - // Test object name and config - $obj = 'testy'; - $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); - $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); - $this->assertEquals($cfg, $this->ci_obj->$obj->config); - - // Test is_loaded - $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib))); - - // Test to load another class with the same object name - $lib = 'another_test_lib'; - $class = ucfirst($lib); - $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); - $this->setExpectedException( - 'RuntimeException', - "CI Error: Resource '".$obj."' already exists and is not a ".$class." instance." - ); - $this->load->library($lib, NULL, $obj); - } - - // -------------------------------------------------------------------- - - public function test_load_library_in_application_dir() - { - // Create library in VFS - $lib = 'super_test_library'; - $class = ucfirst($lib); - $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); - - // Load library - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - - // Was the model class instantiated. - $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); - } - - // -------------------------------------------------------------------- - - public function test_driver() - { - // Call the autoloader, to include system/libraries/Driver.php - class_exists('CI_Driver_Library', TRUE); - - // Create driver in VFS - $driver = 'unit_test_driver'; - $dir = ucfirst($driver); - $class = 'CI_'.$dir; - $content = 'ci_vfs_create(ucfirst($driver), $content, $this->ci_base_root, 'libraries/'.$dir); - - // Test loading as an array. - $this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver))); - $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $driver, $this->ci_obj); - - // Test loading as a library with a name - $obj = 'testdrive'; - $this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj)); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); - - // Test a string given to params - $this->assertInstanceOf('CI_Loader', $this->load->driver($driver, ' ')); - } - - // -------------------------------------------------------------------- - - public function test_models() - { - $this->ci_set_core_class('model', 'CI_Model'); - - // Create model in VFS - $model = 'Unit_test_model'; - $content = 'ci_vfs_create($model, $content, $this->ci_app_root, 'models'); - - // Load model - $this->assertInstanceOf('CI_Loader', $this->load->model($model)); - - // Was the model class instantiated. - $this->assertTrue(class_exists($model)); - $this->assertObjectHasAttribute($model, $this->ci_obj); - - // Test no model given - $this->assertInstanceOf('CI_Loader', $this->load->model('')); - } - - // -------------------------------------------------------------------- - - public function test_model_subdir() - { - // Make sure base class is loaded - we'll test _ci_include later - $this->ci_core_class('model'); - - // Create modelin VFS - $model = 'Test_sub_model'; - $base = 'CI_Model'; - $subdir = 'cars'; - $this->ci_vfs_create($model, 'ci_app_root, - array('models', $subdir)); - - // Load model - $name = 'testors'; - $this->assertInstanceOf('CI_Loader', $this->load->model($subdir.'/'.$model, $name)); - - // Was the model class instantiated? - $this->assertTrue(class_exists($model)); - $this->assertObjectHasAttribute($name, $this->ci_obj); - $this->assertAttributeInstanceOf($base, $name, $this->ci_obj); - $this->assertAttributeInstanceOf($model, $name, $this->ci_obj); - - // Test name conflict - $obj = 'conflict'; - $this->ci_obj->$obj = new stdClass(); - $this->setExpectedException( - 'RuntimeException', - 'The model name you are loading is the name of a resource that is already being used: '.$obj - ); - $this->load->model('not_real', $obj); - } - - // -------------------------------------------------------------------- - - public function test_non_existent_model() - { - $this->setExpectedException( - 'RuntimeException', - 'Unable to locate the model you have specified: Ci_test_nonexistent_model.php' - ); - - $this->load->model('ci_test_nonexistent_model.php'); - } - - // -------------------------------------------------------------------- - - public function test_invalid_model() - { - $this->ci_set_core_class('model', 'CI_Model'); - - // Create model in VFS - $model = 'Unit_test_invalid_model'; - $content = 'ci_vfs_create($model, $content, $this->ci_app_root, 'models'); - - // Test no extending - $this->setExpectedException( - 'RuntimeException', - 'Class '.$model.' doesn\'t extend CI_Model' - ); - $this->load->model($model); - } - - // -------------------------------------------------------------------- - - // public function testDatabase() - // { - // $this->assertInstanceOf('CI_Loader', $this->load->database()); - // $this->assertInstanceOf('CI_Loader', $this->load->dbutil()); - // } - - // -------------------------------------------------------------------- - - public function test_load_view() - { - // Create view in VFS - $view = 'unit_test_view'; - $var = 'hello'; - $value = 'World!'; - $content = 'This is my test page. '; - $this->ci_vfs_create($view, $content.'ci_app_root, 'views'); - - // Test returning view - $out = $this->load->view($view, array($var => $value), TRUE); - $this->assertEquals($content.$value, $out); - - // Mock output class - $output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock(); - $output->expects($this->once())->method('append_output')->with($content.$value); - $this->ci_instance_var('output', $output); - - // Test view output and $vars as an object - $vars = new stdClass(); - $vars->$var = $value; - $this->assertInstanceOf('CI_Loader', $this->load->view($view, $vars)); - } - - // -------------------------------------------------------------------- - - public function test_non_existent_view() - { - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php' - ); - - $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar')); - } - - // -------------------------------------------------------------------- - - public function test_file() - { - // Create view in VFS - $dir = 'views'; - $file = 'ci_test_mock_file'; - $content = 'Here is a test file, which we will load now.'; - $this->ci_vfs_create($file, $content, $this->ci_app_root, $dir); - - // Just like load->view(), take the output class out of the mix here. - $out = $this->load->file(APPPATH.$dir.'/'.$file.'.php', TRUE); - $this->assertEquals($content, $out); - - // Test non-existent file - $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() - { - $key1 = 'foo'; - $val1 = 'bar'; - $key2 = 'boo'; - $val2 = 'hoo'; - $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1))); - $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2)); - $this->assertEquals($val1, $this->load->get_var($key1)); - $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars()); - } - - // -------------------------------------------------------------------- - - public function test_clear_vars() - { - $key1 = 'foo'; - $val1 = 'bar'; - $key2 = 'boo'; - $val2 = 'hoo'; - $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1))); - $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2)); - $this->assertEquals($val1, $this->load->get_var($key1)); - $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars()); - - $this->assertInstanceOf('CI_Loader', $this->load->clear_vars()); - $this->assertEquals('', $this->load->get_var($key1)); - $this->assertEquals('', $this->load->get_var($key2)); - } - - // -------------------------------------------------------------------- - - public function test_helper() - { - // Create helper in VFS - $helper = 'test'; - $func = '_my_helper_test_func'; - $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_base_root, 'helpers'); - - // Create helper extension - $exfunc = '_my_extension_func'; - $content = 'ci_vfs_create($this->prefix.$helper.'_helper', $content, $this->ci_app_root, 'helpers'); - - // Load helper - $this->assertInstanceOf('CI_Loader', $this->load->helper($helper)); - $this->assertTrue(function_exists($func), $func.' does not exist'); - $this->assertTrue(function_exists($exfunc), $exfunc.' does not exist'); - - // Create baseless extension - $ext = 'bad_ext'; - $this->ci_vfs_create($this->prefix.$ext.'_helper', '', $this->ci_app_root, 'helpers'); - - // Test bad extension - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested file: helpers/'.$ext.'_helper.php' - ); - $this->load->helper($ext); - } - - // -------------------------------------------------------------------- - - public function test_non_existent_helper() - { - $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() - { - // Create helpers in VFS - $helpers = array(); - $funcs = array(); - $files = array(); - for ($i = 1; $i <= 3; ++$i) { - $helper = 'test'.$i; - $helpers[] = $helper; - $func = '_my_helper_test_func'.$i; - $funcs[] = $func; - $files[$helper.'_helper'] = 'ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers'); - - // Load helpers - $this->assertInstanceOf('CI_Loader', $this->load->helpers($helpers)); - - // Verify helper existence - foreach ($funcs as $func) { - $this->assertTrue(function_exists($func), $func.' does not exist'); - } - } - - // -------------------------------------------------------------------- - - public function test_language() - { - // Mock lang class and test load call - $file = 'test'; - $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); - $lang->expects($this->once())->method('load')->with($file); - $this->ci_instance_var('lang', $lang); - $this->assertInstanceOf('CI_Loader', $this->load->language($file)); - } - - // -------------------------------------------------------------------- - - public function test_packages() - { - // Create model in VFS package path - $dir = 'third-party'; - $lib = 'unit_test_package'; - $class = ucfirst($lib); - $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, array($dir, 'libraries')); - - // Get paths - $paths = $this->load->get_package_paths(TRUE); - - // Test failed load without path - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested class: '.ucfirst($lib) - ); - $this->load->library($lib); - - // Add path and verify - $path = APPPATH.$dir.'/'; - $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path)); - $this->assertContains($path, $this->load->get_package_paths(TRUE)); - - // Test successful load - $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); - $this->assertTrue(class_exists($class), $class.' does not exist'); - - // Add another path - $path2 = APPPATH.'another/'; - $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2)); - $this->assertContains($path2, $this->load->get_package_paths(TRUE)); - - // Remove last path - $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path()); - $this->assertNotContains($path2, $this->load->get_package_paths(TRUE)); - - // Remove path and verify restored paths - $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path)); - $this->assertEquals($paths, $this->load->get_package_paths(TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_remove_package_path() - { - $dir = 'third-party'; - $path = APPPATH.$dir.'/'; - $path2 = APPPATH.'another/'; - $paths = $this->load->get_package_paths(TRUE); - - $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path)); - $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path)); - $this->assertEquals($paths, $this->load->get_package_paths(TRUE)); - - $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2)); - $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path()); - $this->assertNotContains($path2, $this->load->get_package_paths(TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_load_config() - { - $cfg = 'someconfig'; - $this->assertTrue($this->load->config($cfg, FALSE)); - $this->assertContains($cfg, $this->ci_obj->config->loaded); - } - - // -------------------------------------------------------------------- - - public function test_initialize() - { - // Create helper in VFS - $helper = 'autohelp'; - $hlp_func = '_autohelp_test_func'; - $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); - - // Create library in VFS - $lib = 'autolib'; - $lib_class = 'CI_'.ucfirst($lib); - $this->ci_vfs_create(ucfirst($lib), 'ci_base_root, 'libraries'); - - // Create driver in VFS - $drv = 'autodrv'; - $subdir = ucfirst($drv); - $drv_class = 'CI_'.$subdir; - $this->ci_vfs_create(ucfirst($drv), 'ci_base_root, array('libraries', $subdir)); - - // Create model in VFS package path - $dir = 'testdir'; - $path = APPPATH.$dir.'/'; - $model = 'Automod'; - $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); - - // Create autoloader config - $cfg = array( - 'packages' => array($path), - 'helper' => array($helper), - 'libraries' => array($lib), - 'drivers' => array($drv), - 'model' => array($model), - 'config' => array('config1', 'config2') - ); - $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); - - $this->load->initialize(); - - // Verify path - $this->assertContains($path, $this->load->get_package_paths()); - - // Verify helper - $this->assertTrue(function_exists($hlp_func), $hlp_func.' does not exist'); - - // Verify library - $this->assertTrue(class_exists($lib_class), $lib_class.' does not exist'); - $this->assertAttributeInstanceOf($lib_class, $lib, $this->ci_obj); - - // Verify driver - $this->assertTrue(class_exists($drv_class), $drv_class.' does not exist'); - $this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj); - - // Verify model - $this->assertTrue(class_exists($model), $model.' does not exist'); - $this->assertAttributeInstanceOf($model, $model, $this->ci_obj); - - // Verify config calls - $this->assertEquals($cfg['config'], $this->ci_obj->config->loaded); - } -} diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php deleted file mode 100644 index 9279843857e..00000000000 --- a/tests/codeigniter/core/Log_test.php +++ /dev/null @@ -1,63 +0,0 @@ -setAccessible(TRUE); - $threshold = new ReflectionProperty('CI_Log', '_threshold'); - $threshold->setAccessible(TRUE); - $date_fmt = new ReflectionProperty('CI_Log', '_date_fmt'); - $date_fmt->setAccessible(TRUE); - $file_ext = new ReflectionProperty('CI_Log', '_file_ext'); - $file_ext->setAccessible(TRUE); - $file_perms = new ReflectionProperty('CI_Log', '_file_permissions'); - $file_perms->setAccessible(TRUE); - $enabled = new ReflectionProperty('CI_Log', '_enabled'); - $enabled->setAccessible(TRUE); - - $this->ci_set_config('log_path', '/root/'); - $this->ci_set_config('log_threshold', 'z'); - $this->ci_set_config('log_date_format', 'd.m.Y'); - $this->ci_set_config('log_file_extension', ''); - $this->ci_set_config('log_file_permissions', ''); - $instance = new CI_Log(); - - $this->assertEquals($path->getValue($instance), '/root/'); - $this->assertEquals($threshold->getValue($instance), 1); - $this->assertEquals($date_fmt->getValue($instance), 'd.m.Y'); - $this->assertEquals($file_ext->getValue($instance), 'php'); - $this->assertEquals($file_perms->getValue($instance), 0644); - $this->assertFalse($enabled->getValue($instance)); - - $this->ci_set_config('log_path', ''); - $this->ci_set_config('log_threshold', '0'); - $this->ci_set_config('log_date_format', ''); - $this->ci_set_config('log_file_extension', '.log'); - $this->ci_set_config('log_file_permissions', 0600); - $instance = new CI_Log(); - - $this->assertEquals($path->getValue($instance), APPPATH.'logs/'); - $this->assertEquals($threshold->getValue($instance), 0); - $this->assertEquals($date_fmt->getValue($instance), 'Y-m-d H:i:s'); - $this->assertEquals($file_ext->getValue($instance), 'log'); - $this->assertEquals($file_perms->getValue($instance), 0600); - $this->assertEquals($enabled->getValue($instance), TRUE); - } - - // -------------------------------------------------------------------- - - public function test_format_line() - { - $this->ci_set_config('log_path', ''); - $this->ci_set_config('log_threshold', 0); - $instance = new CI_Log(); - - $format_line = new ReflectionMethod($instance, '_format_line'); - $format_line->setAccessible(TRUE); - $this->assertEquals( - $format_line->invoke($instance, 'LEVEL', 'Timestamp', 'Message'), - "LEVEL - Timestamp --> Message".PHP_EOL - ); - } -} diff --git a/tests/codeigniter/core/Model_test.php b/tests/codeigniter/core/Model_test.php deleted file mode 100644 index 80dc97b3bc0..00000000000 --- a/tests/codeigniter/core/Model_test.php +++ /dev/null @@ -1,37 +0,0 @@ -ci_core_class('loader'); - $this->load = new $loader(); - $this->ci_obj = $this->ci_instance(); - $this->ci_set_core_class('model', 'CI_Model'); - - $model_code =<<ci_vfs_create('Test_model', $model_code, $this->ci_app_root, 'models'); - $this->load->model('test_model'); - } - - // -------------------------------------------------------------------- - - public function test__get() - { - $this->assertEquals('foo', $this->ci_obj->test_model->property); - - $this->ci_obj->controller_property = 'bar'; - $this->assertEquals('bar', $this->ci_obj->test_model->controller_property); - } - -} \ No newline at end of file diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php deleted file mode 100644 index 8c99c1fc5fe..00000000000 --- a/tests/codeigniter/core/Output_test.php +++ /dev/null @@ -1,63 +0,0 @@ -_output_data =<< - - Basic HTML - - - Test - - -HTML; - $this->ci_set_config('charset', 'UTF-8'); - $output = $this->ci_core_class('output'); - $this->output = new $output(); - } - - // -------------------------------------------------------------------- - - public function test_set_get_append_output() - { - $append = "\n"; - - $this->assertEquals( - $this->_output_data.$append, - $this->output - ->set_output($this->_output_data) - ->append_output("\n") - ->get_output() - ); - } - - // -------------------------------------------------------------------- - - public function test_get_content_type() - { - $this->assertEquals('text/html', $this->output->get_content_type()); - } - - // -------------------------------------------------------------------- - - public function test_get_header() - { - $this->assertNull($this->output->get_header('Non-Existent-Header')); - - // TODO: Find a way to test header() values as well. Currently, - // PHPUnit prevents this by not using output buffering. - - $this->output->set_content_type('text/plain', 'WINDOWS-1251'); - $this->assertEquals( - 'text/plain; charset=WINDOWS-1251', - $this->output->get_header('content-type') - ); - } - -} diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php deleted file mode 100644 index 64efdf9c8c6..00000000000 --- a/tests/codeigniter/core/Security_test.php +++ /dev/null @@ -1,354 +0,0 @@ -ci_set_config('csrf_protection', TRUE); - $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); - $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - - $_SERVER['REQUEST_METHOD'] = 'GET'; - $this->security = new Mock_Core_Security('UTF-8'); - } - - // -------------------------------------------------------------------- - - public function test_csrf_verify() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - - $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); - } - - // -------------------------------------------------------------------- - - public function test_csrf_verify_invalid() - { - // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error - $_SERVER['REQUEST_METHOD'] = 'POST'; - - $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed'); - - $this->security->csrf_verify(); - } - - // -------------------------------------------------------------------- - - public function test_csrf_verify_valid() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash; - - $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); - } - - // -------------------------------------------------------------------- - - public function test_get_csrf_hash() - { - $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash()); - } - - // -------------------------------------------------------------------- - - public function test_get_csrf_token_name() - { - $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name()); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean() - { - $harm_string = "Hello, i try to your site"; - - $harmless_string = $this->security->xss_clean($harm_string); - - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_string_array() - { - $harm_strings = array( - "Hello, i try to your site", - "Simple clean string", - "Hello, i try to your site" - ); - - $harmless_strings = $this->security->xss_clean($harm_strings); - - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_strings[0]); - $this->assertEquals("Simple clean string", $harmless_strings[1]); - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_strings[2]); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_image_valid() - { - $harm_string = ''; - - $xss_clean_return = $this->security->xss_clean($harm_string, TRUE); - -// $this->assertTrue($xss_clean_return); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_image_invalid() - { - $harm_string = ''; - - $xss_clean_return = $this->security->xss_clean($harm_string, TRUE); - - $this->assertFalse($xss_clean_return); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_entity_double_encoded() - { - $input = 'Clickhere'; - $this->assertEquals('Clickhere', $this->security->xss_clean($input)); - } - - // -------------------------------------------------------------------- - - public function text_xss_clean_js_link_removal() - { - // This one is to prevent a false positive - $this->assertEquals( - "", - $this->security->xss_clean("") - ); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_js_img_removal() - { - $input = 'Clickhere'; - $this->assertEquals('', $this->security->xss_clean($input)); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_sanitize_naughty_html_tags() - { - $this->assertEquals('<unclosedTag', $this->security->xss_clean('assertEquals('<blink>', $this->security->xss_clean('')); - $this->assertEquals('', $this->security->xss_clean('')); - - $this->assertEquals( - ' src="x">', - $this->security->xss_clean(' src="x">') - ); - - $this->assertEquals( - 'on=">"x onerror="alert(1)">', - $this->security->xss_clean('on=">"x onerror="alert(1)">') - ); - - $this->assertEquals( - "\n><!-\n