From a365c0e05a8aa40ad097ef65f30fcba0cedb45d4 Mon Sep 17 00:00:00 2001 From: Pierre-Henry Soria Date: Wed, 1 Apr 2020 08:09:43 +1000 Subject: [PATCH 1/5] Update Codeigniter's system files and config files for v3.1.11 And rename application files to be compatible with the latest Codeigniter version --- application/config/autoload.php | 73 +- application/config/database.php | 124 +- application/config/doctypes.php | 33 +- application/config/foreign_chars.php | 120 +- application/config/hooks.php | 10 +- application/config/migration.php | 65 +- application/config/mimes.php | 272 +- application/config/routes.php | 29 +- application/config/user_agents.php | 340 +- application/controllers/admin.php | 2 +- application/controllers/cron.php | 6 +- application/controllers/main.php | 5 +- application/controllers/smiles.php | 6 +- application/controllers/user.php | 3 +- application/core/MY_Controller.php | 13 +- application/errors/error_404.php | 73 - application/errors/error_db.php | 73 - application/errors/error_general.php | 73 - application/errors/error_php.php | 10 - application/libraries/image_crud.php | 2 +- application/views/errors/cli/error_404.php | 8 + application/views/errors/cli/error_db.php | 8 + .../views/errors/cli/error_exception.php | 21 + .../views/errors/cli/error_general.php | 8 + application/views/errors/cli/error_php.php | 21 + .../{errors => views/errors/cli}/index.html | 5 +- application/views/errors/html/error_404.php | 64 + application/views/errors/html/error_db.php | 64 + .../views/errors/html/error_exception.php | 32 + .../views/errors/html/error_general.php | 64 + application/views/errors/html/error_php.php | 33 + application/views/errors/html/index.html | 11 + application/views/errors/index.html | 11 + index.php | 288 +- system/.htaccess | 13 +- system/core/Benchmark.php | 220 +- system/core/CodeIgniter.php | 588 ++- system/core/Common.php | 1221 +++-- system/core/Config.php | 731 ++- system/core/Controller.php | 124 +- system/core/Exceptions.php | 438 +- system/core/Hooks.php | 483 +- system/core/Input.php | 1727 ++++--- system/core/Lang.php | 334 +- system/core/Loader.php | 2634 +++++----- system/core/Log.php | 296 ++ system/core/Model.php | 106 +- system/core/Output.php | 1387 +++-- system/core/Router.php | 1004 ++-- system/core/Security.php | 1936 +++---- system/core/URI.php | 1264 +++-- system/core/Utf8.php | 296 +- system/core/compat/hash.php | 254 + system/core/compat/index.html | 11 + system/core/compat/mbstring.php | 149 + system/core/compat/password.php | 251 + system/core/compat/standard.php | 182 + system/core/index.html | 5 +- system/database/DB.php | 355 +- system/database/DB_active_rec.php | 2046 -------- system/database/DB_cache.php | 387 +- system/database/DB_driver.php | 3362 +++++++----- system/database/DB_forge.php | 1392 +++-- system/database/DB_query_builder.php | 2808 ++++++++++ system/database/DB_result.php | 1038 ++-- system/database/DB_utility.php | 813 +-- .../database/drivers/cubrid/cubrid_driver.php | 1162 ++--- .../database/drivers/cubrid/cubrid_forge.php | 489 +- .../database/drivers/cubrid/cubrid_result.php | 346 +- .../drivers/cubrid/cubrid_utility.php | 154 +- system/database/drivers/cubrid/index.html | 5 +- .../database/drivers/ibase/ibase_driver.php | 413 ++ system/database/drivers/ibase/ibase_forge.php | 251 + .../database/drivers/ibase/ibase_result.php | 161 + .../database/drivers/ibase/ibase_utility.php | 69 + system/database/drivers/ibase/index.html | 11 + system/database/drivers/index.html | 5 +- system/database/drivers/mssql/index.html | 5 +- .../database/drivers/mssql/mssql_driver.php | 1150 ++--- system/database/drivers/mssql/mssql_forge.php | 370 +- .../database/drivers/mssql/mssql_result.php | 336 +- .../database/drivers/mssql/mssql_utility.php | 132 +- system/database/drivers/mysql/index.html | 5 +- .../database/drivers/mysql/mysql_driver.php | 1238 ++--- system/database/drivers/mysql/mysql_forge.php | 487 +- .../database/drivers/mysql/mysql_result.php | 340 +- .../database/drivers/mysql/mysql_utility.php | 394 +- system/database/drivers/mysqli/index.html | 5 +- .../database/drivers/mysqli/mysqli_driver.php | 1279 ++--- .../database/drivers/mysqli/mysqli_forge.php | 473 +- .../database/drivers/mysqli/mysqli_result.php | 373 +- .../drivers/mysqli/mysqli_utility.php | 271 +- system/database/drivers/oci8/index.html | 5 +- system/database/drivers/oci8/oci8_driver.php | 1458 +++--- system/database/drivers/oci8/oci8_forge.php | 415 +- system/database/drivers/oci8/oci8_result.php | 413 +- system/database/drivers/oci8/oci8_utility.php | 124 +- system/database/drivers/odbc/index.html | 5 +- system/database/drivers/odbc/odbc_driver.php | 1033 ++-- system/database/drivers/odbc/odbc_forge.php | 323 +- system/database/drivers/odbc/odbc_result.php | 459 +- system/database/drivers/odbc/odbc_utility.php | 137 +- system/database/drivers/pdo/index.html | 5 +- system/database/drivers/pdo/pdo_driver.php | 1105 ++-- system/database/drivers/pdo/pdo_forge.php | 300 +- system/database/drivers/pdo/pdo_result.php | 348 +- system/database/drivers/pdo/pdo_utility.php | 137 +- .../drivers/pdo/subdrivers/index.html | 11 + .../drivers/pdo/subdrivers/pdo_4d_driver.php | 200 + .../drivers/pdo/subdrivers/pdo_4d_forge.php | 217 + .../pdo/subdrivers/pdo_cubrid_driver.php | 209 + .../pdo/subdrivers/pdo_cubrid_forge.php | 230 + .../pdo/subdrivers/pdo_dblib_driver.php | 353 ++ .../pdo/subdrivers/pdo_dblib_forge.php | 149 + .../pdo/subdrivers/pdo_firebird_driver.php | 279 + .../pdo/subdrivers/pdo_firebird_forge.php | 237 + .../drivers/pdo/subdrivers/pdo_ibm_driver.php | 244 + .../drivers/pdo/subdrivers/pdo_ibm_forge.php | 154 + .../pdo/subdrivers/pdo_informix_driver.php | 309 ++ .../pdo/subdrivers/pdo_informix_forge.php | 163 + .../pdo/subdrivers/pdo_mysql_driver.php | 379 ++ .../pdo/subdrivers/pdo_mysql_forge.php | 256 + .../drivers/pdo/subdrivers/pdo_oci_driver.php | 326 ++ .../drivers/pdo/subdrivers/pdo_oci_forge.php | 183 + .../pdo/subdrivers/pdo_odbc_driver.php | 229 + .../drivers/pdo/subdrivers/pdo_odbc_forge.php | 70 + .../pdo/subdrivers/pdo_pgsql_driver.php | 384 ++ .../pdo/subdrivers/pdo_pgsql_forge.php | 210 + .../pdo/subdrivers/pdo_sqlite_driver.php | 213 + .../pdo/subdrivers/pdo_sqlite_forge.php | 238 + .../pdo/subdrivers/pdo_sqlsrv_driver.php | 369 ++ .../pdo/subdrivers/pdo_sqlsrv_forge.php | 149 + system/database/drivers/postgre/index.html | 5 +- .../drivers/postgre/postgre_driver.php | 1287 +++-- .../drivers/postgre/postgre_forge.php | 475 +- .../drivers/postgre/postgre_result.php | 318 +- .../drivers/postgre/postgre_utility.php | 133 +- system/database/drivers/sqlite/index.html | 5 +- .../database/drivers/sqlite/sqlite_driver.php | 953 ++-- .../database/drivers/sqlite/sqlite_forge.php | 441 +- .../database/drivers/sqlite/sqlite_result.php | 310 +- .../drivers/sqlite/sqlite_utility.php | 128 +- system/database/drivers/sqlite3/index.html | 11 + .../drivers/sqlite3/sqlite3_driver.php | 344 ++ .../drivers/sqlite3/sqlite3_forge.php | 225 + .../drivers/sqlite3/sqlite3_result.php | 194 + .../drivers/sqlite3/sqlite3_utility.php | 61 + system/database/drivers/sqlsrv/index.html | 5 +- .../database/drivers/sqlsrv/sqlsrv_driver.php | 1111 ++-- .../database/drivers/sqlsrv/sqlsrv_forge.php | 365 +- .../database/drivers/sqlsrv/sqlsrv_result.php | 329 +- .../drivers/sqlsrv/sqlsrv_utility.php | 130 +- system/database/index.html | 5 +- system/fonts/index.html | 5 +- system/fonts/texb.ttf | Bin system/helpers/array_helper.php | 171 +- system/helpers/captcha_helper.php | 554 +- system/helpers/cookie_helper.php | 159 +- system/helpers/date_helper.php | 1180 +++-- system/helpers/directory_helper.php | 140 +- system/helpers/download_helper.php | 231 +- system/helpers/email_helper.php | 101 +- system/helpers/file_helper.php | 803 ++- system/helpers/form_helper.php | 1754 +++---- system/helpers/html_helper.php | 715 ++- system/helpers/index.html | 5 +- system/helpers/inflector_helper.php | 405 +- system/helpers/language_helper.php | 96 +- system/helpers/number_helper.php | 133 +- system/helpers/path_helper.php | 117 +- system/helpers/security_helper.php | 184 +- system/helpers/smiley_helper.php | 465 +- system/helpers/string_helper.php | 472 +- system/helpers/text_helper.php | 952 ++-- system/helpers/typography_helper.php | 140 +- system/helpers/url_helper.php | 988 ++-- system/helpers/xml_helper.php | 116 +- system/index.html | 5 +- system/language/english/calendar_lang.php | 131 +- system/language/english/date_lang.php | 149 +- system/language/english/db_lang.php | 44 +- system/language/english/email_lang.php | 78 +- .../language/english/form_validation_lang.php | 94 +- system/language/english/ftp_lang.php | 65 +- system/language/english/imglib_lang.php | 77 +- system/language/english/index.html | 5 +- system/language/english/migration_lang.php | 56 +- system/language/english/number_lang.php | 50 +- system/language/english/pagination_lang.php | 43 + system/language/english/profiler_lang.php | 79 +- system/language/english/unit_test_lang.php | 79 +- system/language/english/upload_lang.php | 73 +- system/language/index.html | 5 +- system/libraries/Cache/Cache.php | 441 +- system/libraries/Cache/drivers/Cache_apc.php | 334 +- .../libraries/Cache/drivers/Cache_dummy.php | 266 +- system/libraries/Cache/drivers/Cache_file.php | 449 +- .../Cache/drivers/Cache_memcached.php | 497 +- .../libraries/Cache/drivers/Cache_redis.php | 330 ++ .../Cache/drivers/Cache_wincache.php | 217 + system/libraries/Cache/drivers/index.html | 5 +- system/libraries/Cache/index.html | 5 +- system/libraries/Calendar.php | 988 ++-- system/libraries/Cart.php | 1089 ++-- system/libraries/Driver.php | 506 +- system/libraries/Email.php | 4551 +++++++++-------- system/libraries/Encrypt.php | 990 ++-- system/libraries/Encryption.php | 941 ++++ system/libraries/Form_validation.php | 2951 ++++++----- system/libraries/Ftp.php | 1297 ++--- system/libraries/Image_lib.php | 3350 ++++++------ system/libraries/Javascript.php | 1700 +++--- system/libraries/Log.php | 115 - system/libraries/Migration.php | 769 +-- system/libraries/Pagination.php | 1017 ++-- system/libraries/Parser.php | 431 +- system/libraries/Profiler.php | 1093 ++-- system/libraries/Session.php | 794 --- system/libraries/Session/Session.php | 983 ++++ .../Session/SessionHandlerInterface.php | 59 + system/libraries/Session/Session_driver.php | 187 + .../drivers/Session_database_driver.php | 445 ++ .../Session/drivers/Session_files_driver.php | 428 ++ .../drivers/Session_memcached_driver.php | 397 ++ .../Session/drivers/Session_redis_driver.php | 459 ++ system/libraries/Session/drivers/index.html | 11 + system/libraries/Session/index.html | 11 + system/libraries/Sha1.php | 252 - system/libraries/Table.php | 1036 ++-- system/libraries/Trackback.php | 1071 ++-- system/libraries/Typography.php | 803 +-- system/libraries/Unit_test.php | 736 +-- system/libraries/Upload.php | 2405 +++++---- system/libraries/User_agent.php | 1199 +++-- system/libraries/Xmlrpc.php | 3242 +++++++----- system/libraries/Xmlrpcs.php | 1188 ++--- system/libraries/Zip.php | 920 ++-- system/libraries/index.html | 5 +- system/libraries/javascript/Jquery.php | 2118 ++++---- system/libraries/javascript/index.html | 5 +- 240 files changed, 64746 insertions(+), 47871 deletions(-) mode change 100755 => 100644 application/config/autoload.php mode change 100755 => 100644 application/config/doctypes.php mode change 100755 => 100644 application/config/migration.php mode change 100755 => 100644 application/config/mimes.php mode change 100755 => 100644 application/config/user_agents.php delete mode 100755 application/errors/error_404.php delete mode 100755 application/errors/error_db.php delete mode 100755 application/errors/error_general.php delete mode 100755 application/errors/error_php.php create mode 100644 application/views/errors/cli/error_404.php create mode 100644 application/views/errors/cli/error_db.php create mode 100644 application/views/errors/cli/error_exception.php create mode 100644 application/views/errors/cli/error_general.php create mode 100644 application/views/errors/cli/error_php.php rename application/{errors => views/errors/cli}/index.html (58%) mode change 100755 => 100644 create mode 100644 application/views/errors/html/error_404.php create mode 100644 application/views/errors/html/error_db.php create mode 100644 application/views/errors/html/error_exception.php create mode 100644 application/views/errors/html/error_general.php create mode 100644 application/views/errors/html/error_php.php create mode 100644 application/views/errors/html/index.html create mode 100644 application/views/errors/index.html mode change 100755 => 100644 system/.htaccess mode change 100755 => 100644 system/core/Benchmark.php mode change 100755 => 100644 system/core/CodeIgniter.php mode change 100755 => 100644 system/core/Common.php mode change 100755 => 100644 system/core/Config.php mode change 100755 => 100644 system/core/Controller.php mode change 100755 => 100644 system/core/Exceptions.php mode change 100755 => 100644 system/core/Hooks.php mode change 100755 => 100644 system/core/Input.php mode change 100755 => 100644 system/core/Lang.php mode change 100755 => 100644 system/core/Loader.php create mode 100644 system/core/Log.php mode change 100755 => 100644 system/core/Model.php mode change 100755 => 100644 system/core/Output.php mode change 100755 => 100644 system/core/Router.php mode change 100755 => 100644 system/core/Security.php mode change 100755 => 100644 system/core/URI.php mode change 100755 => 100644 system/core/Utf8.php create mode 100644 system/core/compat/hash.php create mode 100644 system/core/compat/index.html create mode 100644 system/core/compat/mbstring.php create mode 100644 system/core/compat/password.php create mode 100644 system/core/compat/standard.php mode change 100755 => 100644 system/core/index.html mode change 100755 => 100644 system/database/DB.php delete mode 100755 system/database/DB_active_rec.php mode change 100755 => 100644 system/database/DB_cache.php mode change 100755 => 100644 system/database/DB_driver.php mode change 100755 => 100644 system/database/DB_forge.php create mode 100644 system/database/DB_query_builder.php mode change 100755 => 100644 system/database/DB_result.php mode change 100755 => 100644 system/database/DB_utility.php mode change 100755 => 100644 system/database/drivers/cubrid/cubrid_driver.php mode change 100755 => 100644 system/database/drivers/cubrid/cubrid_forge.php mode change 100755 => 100644 system/database/drivers/cubrid/cubrid_result.php mode change 100755 => 100644 system/database/drivers/cubrid/cubrid_utility.php mode change 100755 => 100644 system/database/drivers/cubrid/index.html create mode 100644 system/database/drivers/ibase/ibase_driver.php create mode 100644 system/database/drivers/ibase/ibase_forge.php create mode 100644 system/database/drivers/ibase/ibase_result.php create mode 100644 system/database/drivers/ibase/ibase_utility.php create mode 100644 system/database/drivers/ibase/index.html mode change 100755 => 100644 system/database/drivers/index.html mode change 100755 => 100644 system/database/drivers/mssql/index.html mode change 100755 => 100644 system/database/drivers/mssql/mssql_driver.php mode change 100755 => 100644 system/database/drivers/mssql/mssql_forge.php mode change 100755 => 100644 system/database/drivers/mssql/mssql_result.php mode change 100755 => 100644 system/database/drivers/mssql/mssql_utility.php mode change 100755 => 100644 system/database/drivers/mysql/index.html mode change 100755 => 100644 system/database/drivers/mysql/mysql_driver.php mode change 100755 => 100644 system/database/drivers/mysql/mysql_forge.php mode change 100755 => 100644 system/database/drivers/mysql/mysql_result.php mode change 100755 => 100644 system/database/drivers/mysql/mysql_utility.php mode change 100755 => 100644 system/database/drivers/mysqli/index.html mode change 100755 => 100644 system/database/drivers/mysqli/mysqli_driver.php mode change 100755 => 100644 system/database/drivers/mysqli/mysqli_forge.php mode change 100755 => 100644 system/database/drivers/mysqli/mysqli_result.php mode change 100755 => 100644 system/database/drivers/mysqli/mysqli_utility.php mode change 100755 => 100644 system/database/drivers/oci8/index.html mode change 100755 => 100644 system/database/drivers/oci8/oci8_driver.php mode change 100755 => 100644 system/database/drivers/oci8/oci8_forge.php mode change 100755 => 100644 system/database/drivers/oci8/oci8_result.php mode change 100755 => 100644 system/database/drivers/oci8/oci8_utility.php mode change 100755 => 100644 system/database/drivers/odbc/index.html mode change 100755 => 100644 system/database/drivers/odbc/odbc_driver.php mode change 100755 => 100644 system/database/drivers/odbc/odbc_forge.php mode change 100755 => 100644 system/database/drivers/odbc/odbc_result.php mode change 100755 => 100644 system/database/drivers/odbc/odbc_utility.php mode change 100755 => 100644 system/database/drivers/pdo/index.html mode change 100755 => 100644 system/database/drivers/pdo/pdo_driver.php mode change 100755 => 100644 system/database/drivers/pdo/pdo_forge.php mode change 100755 => 100644 system/database/drivers/pdo/pdo_result.php mode change 100755 => 100644 system/database/drivers/pdo/pdo_utility.php create mode 100644 system/database/drivers/pdo/subdrivers/index.html create mode 100644 system/database/drivers/pdo/subdrivers/pdo_4d_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_4d_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_informix_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_informix_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_oci_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_oci_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php mode change 100755 => 100644 system/database/drivers/postgre/index.html mode change 100755 => 100644 system/database/drivers/postgre/postgre_driver.php mode change 100755 => 100644 system/database/drivers/postgre/postgre_forge.php mode change 100755 => 100644 system/database/drivers/postgre/postgre_result.php mode change 100755 => 100644 system/database/drivers/postgre/postgre_utility.php mode change 100755 => 100644 system/database/drivers/sqlite/index.html mode change 100755 => 100644 system/database/drivers/sqlite/sqlite_driver.php mode change 100755 => 100644 system/database/drivers/sqlite/sqlite_forge.php mode change 100755 => 100644 system/database/drivers/sqlite/sqlite_result.php mode change 100755 => 100644 system/database/drivers/sqlite/sqlite_utility.php create mode 100644 system/database/drivers/sqlite3/index.html create mode 100644 system/database/drivers/sqlite3/sqlite3_driver.php create mode 100644 system/database/drivers/sqlite3/sqlite3_forge.php create mode 100644 system/database/drivers/sqlite3/sqlite3_result.php create mode 100644 system/database/drivers/sqlite3/sqlite3_utility.php mode change 100755 => 100644 system/database/drivers/sqlsrv/index.html mode change 100755 => 100644 system/database/drivers/sqlsrv/sqlsrv_driver.php mode change 100755 => 100644 system/database/drivers/sqlsrv/sqlsrv_forge.php mode change 100755 => 100644 system/database/drivers/sqlsrv/sqlsrv_result.php mode change 100755 => 100644 system/database/drivers/sqlsrv/sqlsrv_utility.php mode change 100755 => 100644 system/database/index.html mode change 100755 => 100644 system/fonts/index.html mode change 100755 => 100644 system/fonts/texb.ttf mode change 100755 => 100644 system/helpers/array_helper.php mode change 100755 => 100644 system/helpers/captcha_helper.php mode change 100755 => 100644 system/helpers/cookie_helper.php mode change 100755 => 100644 system/helpers/date_helper.php mode change 100755 => 100644 system/helpers/directory_helper.php mode change 100755 => 100644 system/helpers/download_helper.php mode change 100755 => 100644 system/helpers/email_helper.php mode change 100755 => 100644 system/helpers/file_helper.php mode change 100755 => 100644 system/helpers/form_helper.php mode change 100755 => 100644 system/helpers/html_helper.php mode change 100755 => 100644 system/helpers/index.html mode change 100755 => 100644 system/helpers/inflector_helper.php mode change 100755 => 100644 system/helpers/language_helper.php mode change 100755 => 100644 system/helpers/number_helper.php mode change 100755 => 100644 system/helpers/path_helper.php mode change 100755 => 100644 system/helpers/security_helper.php mode change 100755 => 100644 system/helpers/smiley_helper.php mode change 100755 => 100644 system/helpers/string_helper.php mode change 100755 => 100644 system/helpers/text_helper.php mode change 100755 => 100644 system/helpers/typography_helper.php mode change 100755 => 100644 system/helpers/url_helper.php mode change 100755 => 100644 system/helpers/xml_helper.php mode change 100755 => 100644 system/index.html mode change 100755 => 100644 system/language/english/calendar_lang.php mode change 100755 => 100644 system/language/english/date_lang.php mode change 100755 => 100644 system/language/english/db_lang.php mode change 100755 => 100644 system/language/english/email_lang.php mode change 100755 => 100644 system/language/english/form_validation_lang.php mode change 100755 => 100644 system/language/english/ftp_lang.php mode change 100755 => 100644 system/language/english/imglib_lang.php mode change 100755 => 100644 system/language/english/index.html mode change 100755 => 100644 system/language/english/migration_lang.php mode change 100755 => 100644 system/language/english/number_lang.php create mode 100644 system/language/english/pagination_lang.php mode change 100755 => 100644 system/language/english/profiler_lang.php mode change 100755 => 100644 system/language/english/unit_test_lang.php mode change 100755 => 100644 system/language/english/upload_lang.php mode change 100755 => 100644 system/language/index.html mode change 100755 => 100644 system/libraries/Cache/Cache.php mode change 100755 => 100644 system/libraries/Cache/drivers/Cache_apc.php mode change 100755 => 100644 system/libraries/Cache/drivers/Cache_dummy.php mode change 100755 => 100644 system/libraries/Cache/drivers/Cache_file.php mode change 100755 => 100644 system/libraries/Cache/drivers/Cache_memcached.php create mode 100644 system/libraries/Cache/drivers/Cache_redis.php create mode 100644 system/libraries/Cache/drivers/Cache_wincache.php mode change 100755 => 100644 system/libraries/Cache/drivers/index.html mode change 100755 => 100644 system/libraries/Cache/index.html mode change 100755 => 100644 system/libraries/Calendar.php mode change 100755 => 100644 system/libraries/Cart.php mode change 100755 => 100644 system/libraries/Driver.php mode change 100755 => 100644 system/libraries/Email.php mode change 100755 => 100644 system/libraries/Encrypt.php create mode 100644 system/libraries/Encryption.php mode change 100755 => 100644 system/libraries/Form_validation.php mode change 100755 => 100644 system/libraries/Ftp.php mode change 100755 => 100644 system/libraries/Image_lib.php mode change 100755 => 100644 system/libraries/Javascript.php delete mode 100755 system/libraries/Log.php mode change 100755 => 100644 system/libraries/Migration.php mode change 100755 => 100644 system/libraries/Pagination.php mode change 100755 => 100644 system/libraries/Parser.php mode change 100755 => 100644 system/libraries/Profiler.php delete mode 100755 system/libraries/Session.php create mode 100644 system/libraries/Session/Session.php create mode 100644 system/libraries/Session/SessionHandlerInterface.php create mode 100644 system/libraries/Session/Session_driver.php create mode 100644 system/libraries/Session/drivers/Session_database_driver.php create mode 100644 system/libraries/Session/drivers/Session_files_driver.php create mode 100644 system/libraries/Session/drivers/Session_memcached_driver.php create mode 100644 system/libraries/Session/drivers/Session_redis_driver.php create mode 100644 system/libraries/Session/drivers/index.html create mode 100644 system/libraries/Session/index.html delete mode 100755 system/libraries/Sha1.php mode change 100755 => 100644 system/libraries/Table.php mode change 100755 => 100644 system/libraries/Trackback.php mode change 100755 => 100644 system/libraries/Typography.php mode change 100755 => 100644 system/libraries/Unit_test.php mode change 100755 => 100644 system/libraries/Upload.php mode change 100755 => 100644 system/libraries/User_agent.php mode change 100755 => 100644 system/libraries/Xmlrpc.php mode change 100755 => 100644 system/libraries/Xmlrpcs.php mode change 100755 => 100644 system/libraries/Zip.php mode change 100755 => 100644 system/libraries/index.html mode change 100755 => 100644 system/libraries/javascript/Jquery.php mode change 100755 => 100644 system/libraries/javascript/index.html diff --git a/application/config/autoload.php b/application/config/autoload.php old mode 100755 new mode 100644 index 6bb84c3..7cdc901 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -1,4 +1,6 @@ - 'ua'); */ - $autoload['libraries'] = array(); +/* +| ------------------------------------------------------------------- +| Auto-load Drivers +| ------------------------------------------------------------------- +| These classes are located in system/libraries/ or in your +| application/libraries/ directory, but are also placed inside their +| own subdirectory and they extend the CI_Driver_Library class. They +| offer multiple interchangeable driver options. +| +| Prototype: +| +| $autoload['drivers'] = array('cache'); +| +| You can also supply an alternative property name to be assigned in +| the controller: +| +| $autoload['drivers'] = array('cache' => 'cch'); +| +*/ +$autoload['drivers'] = array(); /* | ------------------------------------------------------------------- @@ -61,56 +87,49 @@ | ------------------------------------------------------------------- | Prototype: | -| $autoload['helper'] = array('url', 'file'); +| $autoload['helper'] = array('url', 'file'); */ - $autoload['helper'] = array(); - /* | ------------------------------------------------------------------- | Auto-load Config files | ------------------------------------------------------------------- | Prototype: | -| $autoload['config'] = array('config1', 'config2'); +| $autoload['config'] = array('config1', 'config2'); | | NOTE: This item is intended for use ONLY if you have created custom | config files. Otherwise, leave it blank. | */ - $autoload['config'] = array(); - /* | ------------------------------------------------------------------- | Auto-load Language files | ------------------------------------------------------------------- | Prototype: | -| $autoload['language'] = array('lang1', 'lang2'); +| $autoload['language'] = array('lang1', 'lang2'); | | NOTE: Do not include the "_lang" part of your file. For example | "codeigniter_lang.php" would be referenced as array('codeigniter'); | */ - $autoload['language'] = array(); - /* | ------------------------------------------------------------------- | Auto-load Models | ------------------------------------------------------------------- | Prototype: | -| $autoload['model'] = array('model1', 'model2'); +| $autoload['model'] = array('first_model', 'second_model'); +| +| You can also supply an alternative model name to be assigned +| in the controller: | +| $autoload['model'] = array('first_model' => 'first'); */ - $autoload['model'] = array(); - - -/* End of file autoload.php */ -/* Location: ./application/config/autoload.php */ \ No newline at end of file diff --git a/application/config/database.php b/application/config/database.php index 28b14b9..0088ef1 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -1,4 +1,6 @@ -db->last_query() and profiling of DB queries. +| When you run a query, with this setting set to TRUE (default), +| CodeIgniter will store the SQL statement for debugging purposes. +| However, this may cause high memory usage, especially if you run +| a lot of SQL queries ... disable this to avoid that problem. | | The $active_group variable lets you choose which connection group to | make active. By default there is only one group (the 'default' group). | -| The $active_record variables lets you determine whether or not to load -| the active record class +| The $query_builder variables lets you determine whether or not to load +| the query builder class. */ - $active_group = 'default'; -$active_record = true; - -$db['default']['hostname'] = 'localhost'; -$db['default']['username'] = ''; -$db['default']['password'] = ''; -$db['default']['database'] = ''; -$db['default']['dbdriver'] = 'mysql'; -$db['default']['dbprefix'] = ''; -$db['default']['pconnect'] = true; -$db['default']['db_debug'] = true; -$db['default']['cache_on'] = false; -$db['default']['cachedir'] = ''; -$db['default']['char_set'] = 'utf8'; -$db['default']['dbcollat'] = 'utf8_general_ci'; -$db['default']['swap_pre'] = ''; -$db['default']['autoinit'] = true; -$db['default']['stricton'] = false; +$query_builder = TRUE; -/* End of file database.php */ -/* Location: ./application/config/database.php */ +$db['default'] = array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => (ENVIRONMENT !== 'production'), + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'encrypt' => FALSE, + 'compress' => FALSE, + 'stricton' => FALSE, + 'failover' => array(), + 'save_queries' => TRUE +); diff --git a/application/config/doctypes.php b/application/config/doctypes.php old mode 100755 new mode 100644 index f520d1a..59a7991 --- a/application/config/doctypes.php +++ b/application/config/doctypes.php @@ -1,15 +1,24 @@ - '', - 'xhtml1-strict' => '', - 'xhtml1-trans' => '', - 'xhtml1-frame' => '', - 'html5' => '', - 'html4-strict' => '', - 'html4-trans' => '', - 'html4-frame' => '' + 'xhtml11' => '', + 'xhtml1-strict' => '', + 'xhtml1-trans' => '', + 'xhtml1-frame' => '', + 'xhtml-basic11' => '', + 'html5' => '', + 'html4-strict' => '', + 'html4-trans' => '', + 'html4-frame' => '', + 'mathml1' => '', + 'mathml2' => '', + 'svg10' => '', + 'svg11' => '', + 'svg11-basic' => '', + 'svg11-tiny' => '', + 'xhtml-math-svg-xh' => '', + 'xhtml-math-svg-sh' => '', + 'xhtml-rdfa-1' => '', + 'xhtml-rdfa-2' => '' ); - -/* End of file doctypes.php */ -/* Location: ./application/config/doctypes.php */ \ No newline at end of file diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php index 61916d7..f4d0f0c 100755 --- a/application/config/foreign_chars.php +++ b/application/config/foreign_chars.php @@ -1,4 +1,6 @@ - 'Ae', '/Ü/' => 'Ue', '/Ö/' => 'Oe', - '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', - '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', + '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A', + '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a', + '/Б/' => 'B', + '/б/' => 'b', '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', '/ç|ć|ĉ|ċ|č/' => 'c', - '/Ð|Ď|Đ/' => 'D', - '/ð|ď|đ/' => 'd', - '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E', - '/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e', - '/Ĝ|Ğ|Ġ|Ģ/' => 'G', - '/ĝ|ğ|ġ|ģ/' => 'g', + '/Д|Δ/' => 'D', + '/д|δ/' => 'd', + '/Ð|Ď|Đ/' => 'Dj', + '/ð|ď|đ/' => 'dj', + '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E', + '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e', + '/Ф/' => 'F', + '/ф/' => 'f', + '/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G', + '/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g', '/Ĥ|Ħ/' => 'H', '/ĥ|ħ/' => 'h', - '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I', - '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i', + '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I', + '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i', '/Ĵ/' => 'J', '/ĵ/' => 'j', - '/Ķ/' => 'K', - '/ķ/' => 'k', - '/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L', - '/ĺ|ļ|ľ|ŀ|ł/' => 'l', - '/Ñ|Ń|Ņ|Ň/' => 'N', - '/ñ|ń|ņ|ň|ʼn/' => 'n', - '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O', - '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o', - '/Ŕ|Ŗ|Ř/' => 'R', - '/ŕ|ŗ|ř/' => 'r', - '/Ś|Ŝ|Ş|Š/' => 'S', - '/ś|ŝ|ş|š|ſ/' => 's', - '/Ţ|Ť|Ŧ/' => 'T', - '/ţ|ť|ŧ/' => 't', - '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', - '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u', - '/Ý|Ÿ|Ŷ/' => 'Y', - '/ý|ÿ|ŷ/' => 'y', + '/Θ/' => 'TH', + '/θ/' => 'th', + '/Ķ|Κ|К/' => 'K', + '/ķ|κ|к/' => 'k', + '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L', + '/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l', + '/М/' => 'M', + '/м/' => 'm', + '/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N', + '/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n', + '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O', + '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o', + '/П/' => 'P', + '/п/' => 'p', + '/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R', + '/ŕ|ŗ|ř|ρ|р/' => 'r', + '/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S', + '/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's', + '/Ț|Ţ|Ť|Ŧ|Τ|Т/' => 'T', + '/ț|ţ|ť|ŧ|τ|т/' => 't', + '/Þ|þ/' => 'th', + '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U', + '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u', + '/Ƴ|Ɏ|Ỵ|Ẏ|Ӳ|Ӯ|Ў|Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y', + '/ẙ|ʏ|ƴ|ɏ|ỵ|ẏ|ӳ|ӯ|ў|ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y', + '/В/' => 'V', + '/в/' => 'v', '/Ŵ/' => 'W', '/ŵ/' => 'w', - '/Ź|Ż|Ž/' => 'Z', - '/ź|ż|ž/' => 'z', + '/Φ/' => 'F', + '/φ/' => 'f', + '/Χ/' => 'CH', + '/χ/' => 'ch', + '/Ź|Ż|Ž|Ζ|З/' => 'Z', + '/ź|ż|ž|ζ|з/' => 'z', '/Æ|Ǽ/' => 'AE', '/ß/' => 'ss', '/IJ/' => 'IJ', '/ij/' => 'ij', '/Œ/' => 'OE', - '/ƒ/' => 'f' + '/ƒ/' => 'f', + '/Ξ/' => 'KS', + '/ξ/' => 'ks', + '/Π/' => 'P', + '/π/' => 'p', + '/Β/' => 'V', + '/β/' => 'v', + '/Μ/' => 'M', + '/μ/' => 'm', + '/Ψ/' => 'PS', + '/ψ/' => 'ps', + '/Ё/' => 'Yo', + '/ё/' => 'yo', + '/Є/' => 'Ye', + '/є/' => 'ye', + '/Ї/' => 'Yi', + '/Ж/' => 'Zh', + '/ж/' => 'zh', + '/Х/' => 'Kh', + '/х/' => 'kh', + '/Ц/' => 'Ts', + '/ц/' => 'ts', + '/Ч/' => 'Ch', + '/ч/' => 'ch', + '/Ш/' => 'Sh', + '/ш/' => 'sh', + '/Щ/' => 'Shch', + '/щ/' => 'shch', + '/Ъ|ъ|Ь|ь/' => '', + '/Ю/' => 'Yu', + '/ю/' => 'yu', + '/Я/' => 'Ya', + '/я/' => 'ya' ); - -/* End of file foreign_chars.php */ -/* Location: ./application/config/foreign_chars.php */ \ No newline at end of file diff --git a/application/config/hooks.php b/application/config/hooks.php index 071adfb..ec06bd8 100755 --- a/application/config/hooks.php +++ b/application/config/hooks.php @@ -1,4 +1,6 @@ -migration->latest() this is the version that schema will +| If you run $this->migration->current() this is the version that schema will | be upgraded / downgraded to. | */ $config['migration_version'] = 0; - /* |-------------------------------------------------------------------------- | Migrations Path @@ -34,8 +81,4 @@ | Also, writing permission is required within the migrations path. | */ -$config['migration_path'] = APPPATH . 'migrations/'; - - -/* End of file migration.php */ -/* Location: ./application/config/migration.php */ +$config['migration_path'] = APPPATH.'migrations/'; diff --git a/application/config/mimes.php b/application/config/mimes.php old mode 100755 new mode 100644 index b96a83f..7aa5c9e --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -1,4 +1,6 @@ - 'application/mac-binhex40', - 'cpt' => 'application/mac-compactpro', - 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'), - 'bin' => 'application/macbinary', - 'dms' => 'application/octet-stream', - 'lha' => 'application/octet-stream', - 'lzh' => 'application/octet-stream', - 'exe' => array('application/octet-stream', 'application/x-msdownload'), - 'class' => 'application/octet-stream', - 'psd' => 'application/x-photoshop', - 'so' => 'application/octet-stream', - 'sea' => 'application/octet-stream', - 'dll' => 'application/octet-stream', - 'oda' => 'application/oda', - 'pdf' => array('application/pdf', 'application/x-download'), - 'ai' => 'application/postscript', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - 'smi' => 'application/smil', - 'smil' => 'application/smil', - 'mif' => 'application/vnd.mif', - 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), - 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), - 'wbxml' => 'application/wbxml', - 'wmlc' => 'application/wmlc', - 'dcr' => 'application/x-director', - 'dir' => 'application/x-director', - 'dxr' => 'application/x-director', - 'dvi' => 'application/x-dvi', - 'gtar' => 'application/x-gtar', - 'gz' => 'application/x-gzip', - 'php' => 'application/x-httpd-php', - 'php4' => 'application/x-httpd-php', - 'php3' => 'application/x-httpd-php', - 'phtml' => 'application/x-httpd-php', - 'phps' => 'application/x-httpd-php-source', - 'js' => 'application/x-javascript', - 'swf' => 'application/x-shockwave-flash', - 'sit' => 'application/x-stuffit', - 'tar' => 'application/x-tar', - 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), - 'xhtml' => 'application/xhtml+xml', - 'xht' => 'application/xhtml+xml', - 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), - 'mid' => 'audio/midi', - 'midi' => 'audio/midi', - 'mpga' => 'audio/mpeg', - 'mp2' => 'audio/mpeg', - 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), - 'aif' => 'audio/x-aiff', - 'aiff' => 'audio/x-aiff', - 'aifc' => 'audio/x-aiff', - 'ram' => 'audio/x-pn-realaudio', - 'rm' => 'audio/x-pn-realaudio', - 'rpm' => 'audio/x-pn-realaudio-plugin', - 'ra' => 'audio/x-realaudio', - 'rv' => 'video/vnd.rn-realvideo', - 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), - 'bmp' => array('image/bmp', 'image/x-windows-bmp'), - 'gif' => 'image/gif', - 'jpeg' => array('image/jpeg', 'image/pjpeg'), - 'jpg' => array('image/jpeg', 'image/pjpeg'), - 'jpe' => array('image/jpeg', 'image/pjpeg'), - 'png' => array('image/png', 'image/x-png'), - 'tiff' => 'image/tiff', - 'tif' => 'image/tiff', - 'css' => 'text/css', - 'html' => 'text/html', - 'htm' => 'text/html', - 'shtml' => 'text/html', - 'txt' => 'text/plain', - 'text' => 'text/plain', - 'log' => array('text/plain', 'text/x-log'), - 'rtx' => 'text/richtext', - 'rtf' => 'text/rtf', - 'xml' => 'text/xml', - 'xsl' => 'text/xml', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - 'avi' => 'video/x-msvideo', - 'movie' => 'video/x-sgi-movie', - 'doc' => 'application/msword', - 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'), - 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'), - 'word' => array('application/msword', 'application/octet-stream'), - 'xl' => 'application/excel', - 'eml' => 'message/rfc822', - 'json' => array('application/json', 'text/json') +return array( + 'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'), + 'cpt' => 'application/mac-compactpro', + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'), + 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'), + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => array('application/octet-stream', 'application/x-msdownload'), + 'class' => 'application/octet-stream', + 'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'), + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'), + 'ai' => array('application/pdf', 'application/postscript'), + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'), + 'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'), + 'wbxml' => 'application/wbxml', + 'wmlc' => 'application/wmlc', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'gzip' => 'application/x-gzip', + 'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'), + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => array('application/x-javascript', 'text/plain'), + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), + 'z' => 'application/x-compress', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'), + 'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'), + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), + 'aif' => array('audio/x-aiff', 'audio/aiff'), + 'aiff' => array('audio/x-aiff', 'audio/aiff'), + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), + 'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'), + 'gif' => 'image/gif', + 'jpeg' => array('image/jpeg', 'image/pjpeg'), + 'jpg' => array('image/jpeg', 'image/pjpeg'), + 'jpe' => array('image/jpeg', 'image/pjpeg'), + 'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'png' => array('image/png', 'image/x-png'), + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'css' => array('text/css', 'text/plain'), + 'html' => array('text/html', 'text/plain'), + 'htm' => array('text/html', 'text/plain'), + 'shtml' => array('text/html', 'text/plain'), + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'log' => array('text/plain', 'text/x-log'), + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'xml' => array('application/xml', 'text/xml', 'text/plain'), + 'xsl' => array('application/xml', 'text/xsl', 'text/xml'), + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'), + 'movie' => 'video/x-sgi-movie', + 'doc' => array('application/msword', 'application/vnd.ms-office'), + 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'), + 'dot' => array('application/msword', 'application/vnd.ms-office'), + 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), + 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'), + 'word' => array('application/msword', 'application/octet-stream'), + 'xl' => 'application/excel', + 'eml' => 'message/rfc822', + 'json' => array('application/json', 'text/json'), + 'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'), + 'p10' => array('application/x-pkcs10', 'application/pkcs10'), + 'p12' => 'application/x-pkcs12', + 'p7a' => 'application/x-pkcs7-signature', + 'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), + 'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), + 'p7r' => 'application/x-pkcs7-certreqresp', + 'p7s' => 'application/pkcs7-signature', + 'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'), + 'crl' => array('application/pkix-crl', 'application/pkcs-crl'), + 'der' => 'application/x-x509-ca-cert', + 'kdb' => 'application/octet-stream', + 'pgp' => 'application/pgp', + 'gpg' => 'application/gpg-keys', + 'sst' => 'application/octet-stream', + 'csr' => 'application/octet-stream', + 'rsa' => 'application/x-pkcs7', + 'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'), + '3g2' => 'video/3gpp2', + '3gp' => array('video/3gp', 'video/3gpp'), + 'mp4' => 'video/mp4', + 'm4a' => 'audio/x-m4a', + 'f4v' => array('video/mp4', 'video/x-f4v'), + 'flv' => 'video/x-flv', + 'webm' => 'video/webm', + 'aac' => array('audio/x-aac', 'audio/aac'), + 'm4u' => 'application/vnd.mpegurl', + 'm3u' => 'text/plain', + 'xspf' => 'application/xspf+xml', + 'vlc' => 'application/videolan', + 'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'), + 'au' => 'audio/x-au', + 'ac3' => 'audio/ac3', + 'flac' => 'audio/x-flac', + 'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'), + 'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'), + 'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'), + 'ics' => 'text/calendar', + 'ical' => 'text/calendar', + 'zsh' => 'text/x-scriptzsh', + '7z' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'), + '7zip' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'), + 'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'), + 'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'), + 'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'), + 'svg' => array('image/svg+xml', 'application/xml', 'text/xml'), + 'vcf' => 'text/x-vcard', + 'srt' => array('text/srt', 'text/plain'), + 'vtt' => array('text/vtt', 'text/plain'), + 'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon'), + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'otc' => 'application/vnd.oasis.opendocument.chart-template', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'otf' => 'application/vnd.oasis.opendocument.formula-template', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'oti' => 'application/vnd.oasis.opendocument.image-template', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web' ); - - -/* End of file mimes.php */ -/* Location: ./application/config/mimes.php */ diff --git a/application/config/routes.php b/application/config/routes.php index c785e02..2757caf 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -1,4 +1,6 @@ - my_controller/index +| my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = "user"; +$route['default_controller'] = 'user'; $route['404_override'] = ''; - - -/* End of file routes.php */ -/* Location: ./application/config/routes.php */ \ No newline at end of file +$route['translate_uri_dashes'] = FALSE; diff --git a/application/config/user_agents.php b/application/config/user_agents.php old mode 100755 new mode 100644 index 8e94d76..c1581e5 --- a/application/config/user_agents.php +++ b/application/config/user_agents.php @@ -1,178 +1,216 @@ - 'Windows Longhorn', - 'windows nt 5.2' => 'Windows 2003', - 'windows nt 5.0' => 'Windows 2000', - 'windows nt 5.1' => 'Windows XP', - 'windows nt 4.0' => 'Windows NT 4.0', - 'winnt4.0' => 'Windows NT 4.0', - 'winnt 4.0' => 'Windows NT', - 'winnt' => 'Windows NT', - 'windows 98' => 'Windows 98', - 'win98' => 'Windows 98', - 'windows 95' => 'Windows 95', - 'win95' => 'Windows 95', - 'windows' => 'Unknown Windows OS', - 'os x' => 'Mac OS X', - 'ppc mac' => 'Power PC Mac', - 'freebsd' => 'FreeBSD', - 'ppc' => 'Macintosh', - 'linux' => 'Linux', - 'debian' => 'Debian', - 'sunos' => 'Sun Solaris', - 'beos' => 'BeOS', - 'apachebench' => 'ApacheBench', - 'aix' => 'AIX', - 'irix' => 'Irix', - 'osf' => 'DEC OSF', - 'hp-ux' => 'HP-UX', - 'netbsd' => 'NetBSD', - 'bsdi' => 'BSDi', - 'openbsd' => 'OpenBSD', - 'gnu' => 'GNU/Linux', - 'unix' => 'Unknown Unix OS' + 'windows nt 10.0' => 'Windows 10', + 'windows nt 6.3' => 'Windows 8.1', + 'windows nt 6.2' => 'Windows 8', + 'windows nt 6.1' => 'Windows 7', + 'windows nt 6.0' => 'Windows Vista', + 'windows nt 5.2' => 'Windows 2003', + 'windows nt 5.1' => 'Windows XP', + 'windows nt 5.0' => 'Windows 2000', + 'windows nt 4.0' => 'Windows NT 4.0', + 'winnt4.0' => 'Windows NT 4.0', + 'winnt 4.0' => 'Windows NT', + 'winnt' => 'Windows NT', + 'windows 98' => 'Windows 98', + 'win98' => 'Windows 98', + 'windows 95' => 'Windows 95', + 'win95' => 'Windows 95', + 'windows phone' => 'Windows Phone', + 'windows' => 'Unknown Windows OS', + 'android' => 'Android', + 'blackberry' => 'BlackBerry', + 'iphone' => 'iOS', + 'ipad' => 'iOS', + 'ipod' => 'iOS', + 'os x' => 'Mac OS X', + 'ppc mac' => 'Power PC Mac', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'linux' => 'Linux', + 'debian' => 'Debian', + 'sunos' => 'Sun Solaris', + 'beos' => 'BeOS', + 'apachebench' => 'ApacheBench', + 'aix' => 'AIX', + 'irix' => 'Irix', + 'osf' => 'DEC OSF', + 'hp-ux' => 'HP-UX', + 'netbsd' => 'NetBSD', + 'bsdi' => 'BSDi', + 'openbsd' => 'OpenBSD', + 'gnu' => 'GNU/Linux', + 'unix' => 'Unknown Unix OS', + 'symbian' => 'Symbian OS' ); // The order of this array should NOT be changed. Many browsers return // multiple browser types so we want to identify the sub-type first. $browsers = array( - 'Flock' => 'Flock', - 'Chrome' => 'Chrome', - 'Opera' => 'Opera', - 'MSIE' => 'Internet Explorer', - 'Internet Explorer' => 'Internet Explorer', - 'Shiira' => 'Shiira', - 'Firefox' => 'Firefox', - 'Chimera' => 'Chimera', - 'Phoenix' => 'Phoenix', - 'Firebird' => 'Firebird', - 'Camino' => 'Camino', - 'Netscape' => 'Netscape', - 'OmniWeb' => 'OmniWeb', - 'Safari' => 'Safari', - 'Mozilla' => 'Mozilla', - 'Konqueror' => 'Konqueror', - 'icab' => 'iCab', - 'Lynx' => 'Lynx', - 'Links' => 'Links', - 'hotjava' => 'HotJava', - 'amaya' => 'Amaya', - 'IBrowse' => 'IBrowse' + 'OPR' => 'Opera', + 'Flock' => 'Flock', + 'Edge' => 'Edge', + 'Chrome' => 'Chrome', + // Opera 10+ always reports Opera/9.80 and appends Version/ to the user agent string + 'Opera.*?Version' => 'Opera', + 'Opera' => 'Opera', + 'MSIE' => 'Internet Explorer', + 'Internet Explorer' => 'Internet Explorer', + 'Trident.* rv' => 'Internet Explorer', + 'Shiira' => 'Shiira', + 'Firefox' => 'Firefox', + 'Chimera' => 'Chimera', + 'Phoenix' => 'Phoenix', + 'Firebird' => 'Firebird', + 'Camino' => 'Camino', + 'Netscape' => 'Netscape', + 'OmniWeb' => 'OmniWeb', + 'Safari' => 'Safari', + 'Mozilla' => 'Mozilla', + 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', + 'Lynx' => 'Lynx', + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse', + 'Maxthon' => 'Maxthon', + 'Ubuntu' => 'Ubuntu Web Browser' ); $mobiles = array( - // legacy array, old values commented out - 'mobileexplorer' => 'Mobile Explorer', -// 'openwave' => 'Open Wave', -// 'opera mini' => 'Opera Mini', -// 'operamini' => 'Opera Mini', -// 'elaine' => 'Palm', - 'palmsource' => 'Palm', -// 'digital paths' => 'Palm', -// 'avantgo' => 'Avantgo', -// 'xiino' => 'Xiino', - 'palmscape' => 'Palmscape', -// 'nokia' => 'Nokia', -// 'ericsson' => 'Ericsson', -// 'blackberry' => 'BlackBerry', -// 'motorola' => 'Motorola' + // legacy array, old values commented out + 'mobileexplorer' => 'Mobile Explorer', +// 'openwave' => 'Open Wave', +// 'opera mini' => 'Opera Mini', +// 'operamini' => 'Opera Mini', +// 'elaine' => 'Palm', + 'palmsource' => 'Palm', +// 'digital paths' => 'Palm', +// 'avantgo' => 'Avantgo', +// 'xiino' => 'Xiino', + 'palmscape' => 'Palmscape', +// 'nokia' => 'Nokia', +// 'ericsson' => 'Ericsson', +// 'blackberry' => 'BlackBerry', +// 'motorola' => 'Motorola' - // Phones and Manufacturers - 'motorola' => "Motorola", - 'nokia' => "Nokia", - 'palm' => "Palm", - 'iphone' => "Apple iPhone", - 'ipad' => "iPad", - 'ipod' => "Apple iPod Touch", - 'sony' => "Sony Ericsson", - 'ericsson' => "Sony Ericsson", - 'blackberry' => "BlackBerry", - 'cocoon' => "O2 Cocoon", - 'blazer' => "Treo", - 'lg' => "LG", - 'amoi' => "Amoi", - 'xda' => "XDA", - 'mda' => "MDA", - 'vario' => "Vario", - 'htc' => "HTC", - 'samsung' => "Samsung", - 'sharp' => "Sharp", - 'sie-' => "Siemens", - 'alcatel' => "Alcatel", - 'benq' => "BenQ", - 'ipaq' => "HP iPaq", - 'mot-' => "Motorola", - 'playstation portable' => "PlayStation Portable", - 'hiptop' => "Danger Hiptop", - 'nec-' => "NEC", - 'panasonic' => "Panasonic", - 'philips' => "Philips", - 'sagem' => "Sagem", - 'sanyo' => "Sanyo", - 'spv' => "SPV", - 'zte' => "ZTE", - 'sendo' => "Sendo", + // Phones and Manufacturers + 'motorola' => 'Motorola', + 'nokia' => 'Nokia', + 'nexus' => 'Nexus', + 'palm' => 'Palm', + 'iphone' => 'Apple iPhone', + 'ipad' => 'iPad', + 'ipod' => 'Apple iPod Touch', + 'sony' => 'Sony Ericsson', + 'ericsson' => 'Sony Ericsson', + 'blackberry' => 'BlackBerry', + 'cocoon' => 'O2 Cocoon', + 'blazer' => 'Treo', + 'lg' => 'LG', + 'amoi' => 'Amoi', + 'xda' => 'XDA', + 'mda' => 'MDA', + 'vario' => 'Vario', + 'htc' => 'HTC', + 'samsung' => 'Samsung', + 'sharp' => 'Sharp', + 'sie-' => 'Siemens', + 'alcatel' => 'Alcatel', + 'benq' => 'BenQ', + 'ipaq' => 'HP iPaq', + 'mot-' => 'Motorola', + 'playstation portable' => 'PlayStation Portable', + 'playstation 3' => 'PlayStation 3', + 'playstation vita' => 'PlayStation Vita', + 'hiptop' => 'Danger Hiptop', + 'nec-' => 'NEC', + 'panasonic' => 'Panasonic', + 'philips' => 'Philips', + 'sagem' => 'Sagem', + 'sanyo' => 'Sanyo', + 'spv' => 'SPV', + 'zte' => 'ZTE', + 'sendo' => 'Sendo', + 'nintendo dsi' => 'Nintendo DSi', + 'nintendo ds' => 'Nintendo DS', + 'nintendo 3ds' => 'Nintendo 3DS', + 'wii' => 'Nintendo Wii', + 'open web' => 'Open Web', + 'openweb' => 'OpenWeb', + 'meizu' => 'Meizu', - // Operating Systems - 'symbian' => "Symbian", - 'SymbianOS' => "SymbianOS", - 'elaine' => "Palm", - 'palm' => "Palm", - 'series60' => "Symbian S60", - 'windows ce' => "Windows CE", + // Operating Systems + 'android' => 'Android', + 'symbian' => 'Symbian', + 'SymbianOS' => 'SymbianOS', + 'elaine' => 'Palm', + 'series60' => 'Symbian S60', + 'windows ce' => 'Windows CE', - // Browsers - 'obigo' => "Obigo", - 'netfront' => "Netfront Browser", - 'openwave' => "Openwave Browser", - 'mobilexplorer' => "Mobile Explorer", - 'operamini' => "Opera Mini", - 'opera mini' => "Opera Mini", + // Browsers + 'obigo' => 'Obigo', + 'netfront' => 'Netfront Browser', + 'openwave' => 'Openwave Browser', + 'mobilexplorer' => 'Mobile Explorer', + 'operamini' => 'Opera Mini', + 'opera mini' => 'Opera Mini', + 'opera mobi' => 'Opera Mobile', + 'fennec' => 'Firefox Mobile', - // Other - 'digital paths' => "Digital Paths", - 'avantgo' => "AvantGo", - 'xiino' => "Xiino", - 'novarra' => "Novarra Transcoder", - 'vodafone' => "Vodafone", - 'docomo' => "NTT DoCoMo", - 'o2' => "O2", + // Other + 'digital paths' => 'Digital Paths', + 'avantgo' => 'AvantGo', + 'xiino' => 'Xiino', + 'novarra' => 'Novarra Transcoder', + 'vodafone' => 'Vodafone', + 'docomo' => 'NTT DoCoMo', + 'o2' => 'O2', - // Fallback - 'mobile' => "Generic Mobile", - 'wireless' => "Generic Mobile", - 'j2me' => "Generic Mobile", - 'midp' => "Generic Mobile", - 'cldc' => "Generic Mobile", - 'up.link' => "Generic Mobile", - 'up.browser' => "Generic Mobile", - 'smartphone' => "Generic Mobile", - 'cellphone' => "Generic Mobile" + // Fallback + 'mobile' => 'Generic Mobile', + 'wireless' => 'Generic Mobile', + 'j2me' => 'Generic Mobile', + 'midp' => 'Generic Mobile', + 'cldc' => 'Generic Mobile', + 'up.link' => 'Generic Mobile', + 'up.browser' => 'Generic Mobile', + 'smartphone' => 'Generic Mobile', + 'cellphone' => 'Generic Mobile' ); // There are hundreds of bots but these are the most common. $robots = array( - 'googlebot' => 'Googlebot', - 'msnbot' => 'MSNBot', - 'slurp' => 'Inktomi Slurp', - 'yahoo' => 'Yahoo', - 'askjeeves' => 'AskJeeves', - 'fastcrawler' => 'FastCrawler', - 'infoseek' => 'InfoSeek Robot 1.0', - 'lycos' => 'Lycos' + 'googlebot' => 'Googlebot', + 'msnbot' => 'MSNBot', + 'baiduspider' => 'Baiduspider', + 'bingbot' => 'Bing', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', + 'ask jeeves' => 'Ask Jeeves', + 'fastcrawler' => 'FastCrawler', + 'infoseek' => 'InfoSeek Robot 1.0', + 'lycos' => 'Lycos', + 'yandex' => 'YandexBot', + 'mediapartners-google' => 'MediaPartners Google', + 'CRAZYWEBCRAWLER' => 'Crazy Webcrawler', + 'adsbot-google' => 'AdsBot Google', + 'feedfetcher-google' => 'Feedfetcher Google', + 'curious george' => 'Curious George', + 'ia_archiver' => 'Alexa Crawler', + 'MJ12bot' => 'Majestic-12', + 'Uptimebot' => 'Uptimebot' ); - -/* End of file user_agents.php */ -/* Location: ./application/config/user_agents.php */ \ No newline at end of file diff --git a/application/controllers/admin.php b/application/controllers/admin.php index 71de1de..3869e65 100755 --- a/application/controllers/admin.php +++ b/application/controllers/admin.php @@ -1,6 +1,6 @@ load->library('ion_auth'); $this->load->library('form_validation'); $this->load->helper('url'); $this->load->library('image_CRUD'); $this->load->database(); - $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth')); + $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth')); $this->load->helper('language'); $this->data['setting'] = $this->db->get('setting')->row(); - - } - } class Admin_Controller extends MY_Controller { - public function __construct() { - parent::__construct(); $this->load->library('grocery_CRUD'); if (!$this->ion_auth->is_admin() AND $this->uri->segment(2) != "login") { @@ -45,8 +38,6 @@ public function __construct() class Website_Controller extends MY_Controller { - - public function __construct() { parent::__construct(); @@ -77,4 +68,4 @@ public function __construct() $this->msg_success_left = $this->session->flashdata('msg_success_left'); $this->msg_success_right = $this->session->flashdata('msg_success_right'); } -} \ No newline at end of file +} diff --git a/application/errors/error_404.php b/application/errors/error_404.php deleted file mode 100755 index 894cc2d..0000000 --- a/application/errors/error_404.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - 404 Page Not Found - - - -
-

- -
- - \ No newline at end of file diff --git a/application/errors/error_db.php b/application/errors/error_db.php deleted file mode 100755 index aa96a2e..0000000 --- a/application/errors/error_db.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - Database Error - - - -
-

- -
- - \ No newline at end of file diff --git a/application/errors/error_general.php b/application/errors/error_general.php deleted file mode 100755 index d9d7f34..0000000 --- a/application/errors/error_general.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - Error - - - -
-

- -
- - \ No newline at end of file diff --git a/application/errors/error_php.php b/application/errors/error_php.php deleted file mode 100755 index 95176e8..0000000 --- a/application/errors/error_php.php +++ /dev/null @@ -1,10 +0,0 @@ -
- -

A PHP Error was encountered

- -

Severity:

-

Message:

-

Filename:

-

Line Number:

- -
\ No newline at end of file diff --git a/application/libraries/image_crud.php b/application/libraries/image_crud.php index c741368..84491c9 100755 --- a/application/libraries/image_crud.php +++ b/application/libraries/image_crud.php @@ -20,7 +20,7 @@ * @version 0.5 * @author John Skoumbourdis */ -class image_CRUD +class Image_CRUD { protected $table_name = null; diff --git a/application/views/errors/cli/error_404.php b/application/views/errors/cli/error_404.php new file mode 100644 index 0000000..6984b61 --- /dev/null +++ b/application/views/errors/cli/error_404.php @@ -0,0 +1,8 @@ + + +An uncaught Exception was encountered + +Type: +Message: +Filename: getFile(), "\n"; ?> +Line Number: getLine(); ?> + + + +Backtrace: +getTrace() as $error): ?> + + File: + Line: + Function: + + + + diff --git a/application/views/errors/cli/error_general.php b/application/views/errors/cli/error_general.php new file mode 100644 index 0000000..6984b61 --- /dev/null +++ b/application/views/errors/cli/error_general.php @@ -0,0 +1,8 @@ + + +A PHP Error was encountered + +Severity: +Message: +Filename: +Line Number: + + + +Backtrace: + + + File: + Line: + Function: + + + + diff --git a/application/errors/index.html b/application/views/errors/cli/index.html old mode 100755 new mode 100644 similarity index 58% rename from application/errors/index.html rename to application/views/errors/cli/index.html index 04e928c..b702fbc --- a/application/errors/index.html +++ b/application/views/errors/cli/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/application/views/errors/html/error_404.php b/application/views/errors/html/error_404.php new file mode 100644 index 0000000..756ea9d --- /dev/null +++ b/application/views/errors/html/error_404.php @@ -0,0 +1,64 @@ + + + + +404 Page Not Found + + + +
+

+ +
+ + \ No newline at end of file diff --git a/application/views/errors/html/error_db.php b/application/views/errors/html/error_db.php new file mode 100644 index 0000000..f5a43f6 --- /dev/null +++ b/application/views/errors/html/error_db.php @@ -0,0 +1,64 @@ + + + + +Database Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/application/views/errors/html/error_exception.php b/application/views/errors/html/error_exception.php new file mode 100644 index 0000000..8784886 --- /dev/null +++ b/application/views/errors/html/error_exception.php @@ -0,0 +1,32 @@ + + +
+ +

An uncaught Exception was encountered

+ +

Type:

+

Message:

+

Filename: getFile(); ?>

+

Line Number: getLine(); ?>

+ + + +

Backtrace:

+ getTrace() as $error): ?> + + + +

+ File:
+ Line:
+ Function: +

+ + + + + + +
\ No newline at end of file diff --git a/application/views/errors/html/error_general.php b/application/views/errors/html/error_general.php new file mode 100644 index 0000000..fc3b2eb --- /dev/null +++ b/application/views/errors/html/error_general.php @@ -0,0 +1,64 @@ + + + + +Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/application/views/errors/html/error_php.php b/application/views/errors/html/error_php.php new file mode 100644 index 0000000..b146f9c --- /dev/null +++ b/application/views/errors/html/error_php.php @@ -0,0 +1,33 @@ + + +
+ +

A PHP Error was encountered

+ +

Severity:

+

Message:

+

Filename:

+

Line Number:

+ + + +

Backtrace:

+ + + + +

+ File:
+ Line:
+ Function: +

+ + + + + + + +
\ No newline at end of file diff --git a/application/views/errors/html/index.html b/application/views/errors/html/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/application/views/errors/html/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/views/errors/index.html b/application/views/errors/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/application/views/errors/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/index.php b/index.php index 4a59957..e505504 100755 --- a/index.php +++ b/index.php @@ -1,4 +1,40 @@ =')) + { + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); + } + else + { + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); + } + break; + + default: + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); + echo 'The application environment is not set correctly.'; + exit(1); // EXIT_ERROR } /* *--------------------------------------------------------------- - * SYSTEM FOLDER NAME + * SYSTEM DIRECTORY NAME *--------------------------------------------------------------- * - * This variable must contain the name of your "system" folder. - * Include the path if the folder is not in the same directory - * as this file. - * + * This variable must contain the name of your "system" directory. + * Set the path if it is not in the same directory as this file. */ - $system_path = 'system'; + $system_path = 'system'; /* *--------------------------------------------------------------- - * APPLICATION FOLDER NAME + * APPLICATION DIRECTORY NAME *--------------------------------------------------------------- * * If you want this front controller to use a different "application" - * folder then the default one you can set its name here. The folder - * can also be renamed or relocated anywhere on your server. If - * you do, use a full server path. For more info please see the user guide: - * http://codeigniter.com/user_guide/general/managing_apps.html + * directory than the default one you can set its name here. The directory + * can also be renamed or relocated anywhere on your server. If you do, + * use an absolute (full) server path. + * For more info please see the user guide: + * + * https://codeigniter.com/user_guide/general/managing_apps.html * * NO TRAILING SLASH! + */ + $application_folder = 'application'; + +/* + *--------------------------------------------------------------- + * VIEW DIRECTORY NAME + *--------------------------------------------------------------- + * + * If you want to move the view directory out of the application + * directory, set the path to it here. The directory can be renamed + * and relocated anywhere on your server. If blank, it will default + * to the standard location inside your application directory. + * If you do move this, use an absolute (full) server path. * + * NO TRAILING SLASH! */ - $application_folder = 'application'; + $view_folder = ''; + /* * -------------------------------------------------------------------- @@ -83,28 +139,27 @@ * * Normally you will set your default controller in the routes.php file. * You can, however, force a custom routing by hard-coding a - * specific controller class/function here. For most applications, you + * specific controller class/function here. For most applications, you * WILL NOT set your routing here, but it's an option for those * special instances where you might want to override the standard * routing in a specific front controller that shares a common CI installation. * - * IMPORTANT: If you set the routing here, NO OTHER controller will be + * IMPORTANT: If you set the routing here, NO OTHER controller will be * callable. In essence, this preference limits your application to ONE - * specific controller. Leave the function name blank if you need + * specific controller. Leave the function name blank if you need * to call functions dynamically via the URI. * * Un-comment the $routing array below to use this feature - * */ - // The directory name, relative to the "controllers" folder. Leave blank - // if your controller is not in a sub-folder within the "controllers" folder - // $routing['directory'] = ''; + // The directory name, relative to the "controllers" directory. Leave blank + // if your controller is not in a sub-directory within the "controllers" one + // $routing['directory'] = ''; - // The controller class file name. Example: Mycontroller - // $routing['controller'] = ''; + // The controller class file name. Example: mycontroller + // $routing['controller'] = ''; - // The controller function you wish to be called. - // $routing['function'] = ''; + // The controller function you wish to be called. + // $routing['function'] = ''; /* @@ -120,9 +175,8 @@ * config values. * * Un-comment the $assign_to_config array below to use this feature - * */ - // $assign_to_config['name_of_config_item'] = 'value of config item'; + // $assign_to_config['name_of_config_item'] = 'value of config item'; @@ -136,62 +190,120 @@ * --------------------------------------------------------------- */ - // Set the current directory correctly for CLI requests - if (defined('STDIN')) - { - chdir(dirname(__FILE__)); - } + // Set the current directory correctly for CLI requests + if (defined('STDIN')) + { + chdir(dirname(__FILE__)); + } - if (realpath($system_path) !== FALSE) - { - $system_path = realpath($system_path).'/'; - } + if (($_temp = realpath($system_path)) !== FALSE) + { + $system_path = $_temp.DIRECTORY_SEPARATOR; + } + else + { + // Ensure there's a trailing slash + $system_path = strtr( + rtrim($system_path, '/\\'), + '/\\', + DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR + ).DIRECTORY_SEPARATOR; + } - // ensure there's a trailing slash - $system_path = rtrim($system_path, '/').'/'; - - // Is the system path correct? - if ( ! is_dir($system_path)) - { - exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME)); - } + // Is the system path correct? + if ( ! is_dir($system_path)) + { + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); + echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME); + exit(3); // EXIT_CONFIG + } /* * ------------------------------------------------------------------- * Now that we know the path, set the main path constants * ------------------------------------------------------------------- */ - // The name of THIS file - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); + // The name of THIS file + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); - // The PHP file extension - // this global constant is deprecated. - define('EXT', '.php'); + // Path to the system directory + define('BASEPATH', $system_path); - // Path to the system folder - define('BASEPATH', str_replace("\\", "/", $system_path)); + // Path to the front controller (this file) directory + define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); - // Path to the front controller (this file) - define('FCPATH', str_replace(SELF, '', __FILE__)); + // Name of the "system" directory + define('SYSDIR', basename(BASEPATH)); - // Name of the "system folder" - define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); + // The path to the "application" directory + if (is_dir($application_folder)) + { + if (($_temp = realpath($application_folder)) !== FALSE) + { + $application_folder = $_temp; + } + else + { + $application_folder = strtr( + rtrim($application_folder, '/\\'), + '/\\', + DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR + ); + } + } + elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR)) + { + $application_folder = BASEPATH.strtr( + trim($application_folder, '/\\'), + '/\\', + DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR + ); + } + else + { + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); + echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; + exit(3); // EXIT_CONFIG + } + define('APPPATH', $application_folder.DIRECTORY_SEPARATOR); - // The path to the "application" folder - if (is_dir($application_folder)) - { - define('APPPATH', $application_folder.'/'); - } - else - { - if ( ! is_dir(BASEPATH.$application_folder.'/')) - { - exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF); - } + // The path to the "views" directory + if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR)) + { + $view_folder = APPPATH.'views'; + } + elseif (is_dir($view_folder)) + { + if (($_temp = realpath($view_folder)) !== FALSE) + { + $view_folder = $_temp; + } + else + { + $view_folder = strtr( + rtrim($view_folder, '/\\'), + '/\\', + DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR + ); + } + } + elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR)) + { + $view_folder = APPPATH.strtr( + trim($view_folder, '/\\'), + '/\\', + DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR + ); + } + else + { + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); + echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; + exit(3); // EXIT_CONFIG + } - define('APPPATH', BASEPATH.$application_folder.'/'); - } + define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR); /* * -------------------------------------------------------------------- @@ -199,9 +311,5 @@ * -------------------------------------------------------------------- * * And away we go... - * */ require_once BASEPATH.'core/CodeIgniter.php'; - -/* End of file index.php */ -/* Location: ./index.php */ diff --git a/system/.htaccess b/system/.htaccess old mode 100755 new mode 100644 index d680707..97c65d2 --- a/system/.htaccess +++ b/system/.htaccess @@ -1,9 +1,6 @@ -# Apache >= 2.4 - - Require all denied - - -# Apache <= 2.2 - - Deny from all + + Require all denied + + Deny from all + \ No newline at end of file diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php old mode 100755 new mode 100644 index 1d2892f..014220a --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -1,119 +1,133 @@ -marker[$name] = microtime(); - } - - // -------------------------------------------------------------------- - - /** - * Calculates the time difference between two marked points. - * - * If the first parameter is empty this function instead returns the - * {elapsed_time} pseudo-variable. This permits the full system - * execution time to be shown in a template. The output class will - * swap the real value for this variable. - * - * @access public - * @param string a particular marked point - * @param string a particular marked point - * @param integer the number of decimal places - * @return mixed - */ - function elapsed_time($point1 = '', $point2 = '', $decimals = 4) - { - if ($point1 == '') - { - return '{elapsed_time}'; - } - - if ( ! isset($this->marker[$point1])) - { - return ''; - } - - if ( ! isset($this->marker[$point2])) - { - $this->marker[$point2] = microtime(); - } - - list($sm, $ss) = explode(' ', $this->marker[$point1]); - list($em, $es) = explode(' ', $this->marker[$point2]); - - return number_format(($em + $es) - ($sm + $ss), $decimals); - } - - // -------------------------------------------------------------------- - - /** - * Memory Usage - * - * This function returns the {memory_usage} pseudo-variable. - * This permits it to be put it anywhere in a template - * without the memory being calculated until the end. - * The output class will swap the real value for this variable. - * - * @access public - * @return string - */ - function memory_usage() - { - return '{memory_usage}'; - } + /** + * List of all benchmark markers + * + * @var array + */ + public $marker = array(); + + /** + * Set a benchmark marker + * + * Multiple calls to this function can be made so that several + * execution points can be timed. + * + * @param string $name Marker name + * @return void + */ + public function mark($name) + { + $this->marker[$name] = microtime(TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Elapsed time + * + * Calculates the time difference between two marked points. + * + * If the first parameter is empty this function instead returns the + * {elapsed_time} pseudo-variable. This permits the full system + * execution time to be shown in a template. The output class will + * swap the real value for this variable. + * + * @param string $point1 A particular marked point + * @param string $point2 A particular marked point + * @param int $decimals Number of decimal places + * + * @return string Calculated elapsed time on success, + * an '{elapsed_string}' if $point1 is empty + * or an empty string if $point1 is not found. + */ + public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) + { + if ($point1 === '') + { + return '{elapsed_time}'; + } + + if ( ! isset($this->marker[$point1])) + { + return ''; + } + + if ( ! isset($this->marker[$point2])) + { + $this->marker[$point2] = microtime(TRUE); + } + + return number_format($this->marker[$point2] - $this->marker[$point1], $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Memory Usage + * + * Simply returns the {memory_usage} marker. + * + * This permits it to be put it anywhere in a template + * without the memory being calculated until the end. + * The output class will swap the real value for this variable. + * + * @return string '{memory_usage}' + */ + public function memory_usage() + { + return '{memory_usage}'; + } } - -// END CI_Benchmark class - -/* End of file Benchmark.php */ -/* Location: ./system/core/Benchmark.php */ \ No newline at end of file diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php old mode 100755 new mode 100644 index 51bc0d4..8aecc0a --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -1,81 +1,143 @@ - '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal) + { + if (strpos($_registered, $key) === FALSE) + { + continue; + } + + foreach (array_keys($$superglobal) as $var) + { + if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE)) + { + $GLOBALS[$var] = NULL; + } + } + } + } +} + /* * ------------------------------------------------------ * Define a custom error handler so we can log PHP errors * ------------------------------------------------------ */ - set_error_handler('_exception_handler'); - - if ( ! is_php('5.3')) - { - @set_magic_quotes_runtime(0); // Kill magic quotes - } + set_error_handler('_error_handler'); + set_exception_handler('_exception_handler'); + register_shutdown_function('_shutdown_handler'); /* * ------------------------------------------------------ @@ -86,139 +148,205 @@ * The subclass prefix allows CI to know if a core class is * being extended via a library in the local application * "libraries" folder. Since CI allows config items to be - * overriden via data set in the main index. php file, + * overridden via data set in the main index.php file, * before proceeding we need to know if a subclass_prefix - * override exists. If so, we will set this value now, + * override exists. If so, we will set this value now, * before any classes are loaded * Note: Since the config file data is cached it doesn't * hurt to load it here. */ - if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '') - { - get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); - } + if ( ! empty($assign_to_config['subclass_prefix'])) + { + get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); + } /* * ------------------------------------------------------ - * Set a liberal script execution time limit + * Should we use a Composer autoloader? * ------------------------------------------------------ */ - if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0) - { - @set_time_limit(300); - } + if ($composer_autoload = config_item('composer_autoload')) + { + if ($composer_autoload === TRUE) + { + file_exists(APPPATH.'vendor/autoload.php') + ? require_once(APPPATH.'vendor/autoload.php') + : log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.'); + } + elseif (file_exists($composer_autoload)) + { + require_once($composer_autoload); + } + else + { + log_message('error', 'Could not find the specified $config[\'composer_autoload\'] path: '.$composer_autoload); + } + } /* * ------------------------------------------------------ * Start the timer... tick tock tick tock... * ------------------------------------------------------ */ - $BM =& load_class('Benchmark', 'core'); - $BM->mark('total_execution_time_start'); - $BM->mark('loading_time:_base_classes_start'); + $BM =& load_class('Benchmark', 'core'); + $BM->mark('total_execution_time_start'); + $BM->mark('loading_time:_base_classes_start'); /* * ------------------------------------------------------ * Instantiate the hooks class * ------------------------------------------------------ */ - $EXT =& load_class('Hooks', 'core'); + $EXT =& load_class('Hooks', 'core'); /* * ------------------------------------------------------ * Is there a "pre_system" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('pre_system'); + $EXT->call_hook('pre_system'); /* * ------------------------------------------------------ * Instantiate the config class * ------------------------------------------------------ + * + * Note: It is important that Config is loaded first as + * most other classes depend on it either directly or by + * depending on another class that uses it. + * */ - $CFG =& load_class('Config', 'core'); + $CFG =& load_class('Config', 'core'); - // Do we have any manually set config items in the index.php file? - if (isset($assign_to_config)) - { - $CFG->_assign_to_config($assign_to_config); - } + // Do we have any manually set config items in the index.php file? + if (isset($assign_to_config) && is_array($assign_to_config)) + { + foreach ($assign_to_config as $key => $value) + { + $CFG->set_item($key, $value); + } + } /* * ------------------------------------------------------ - * Instantiate the UTF-8 class + * Important charset-related stuff * ------------------------------------------------------ * - * Note: Order here is rather important as the UTF-8 - * class needs to be used very early on, but it cannot - * properly determine if UTf-8 can be supported until - * after the Config class is instantiated. + * Configure mbstring and/or iconv if they are enabled + * and set MB_ENABLED and ICONV_ENABLED constants, so + * that we don't repeatedly do extension_loaded() or + * function_exists() calls. + * + * Note: UTF-8 class depends on this. It used to be done + * in it's constructor, but it's _not_ class-specific. * */ + $charset = strtoupper(config_item('charset')); + ini_set('default_charset', $charset); + + if (extension_loaded('mbstring')) + { + define('MB_ENABLED', TRUE); + // mbstring.internal_encoding is deprecated starting with PHP 5.6 + // and it's usage triggers E_DEPRECATED messages. + @ini_set('mbstring.internal_encoding', $charset); + // This is required for mb_convert_encoding() to strip invalid characters. + // That's utilized by CI_Utf8, but it's also done for consistency with iconv. + mb_substitute_character('none'); + } + else + { + define('MB_ENABLED', FALSE); + } + + // There's an ICONV_IMPL constant, but the PHP manual says that using + // iconv's predefined constants is "strongly discouraged". + if (extension_loaded('iconv')) + { + define('ICONV_ENABLED', TRUE); + // iconv.internal_encoding is deprecated starting with PHP 5.6 + // and it's usage triggers E_DEPRECATED messages. + @ini_set('iconv.internal_encoding', $charset); + } + else + { + define('ICONV_ENABLED', FALSE); + } + + if (is_php('5.6')) + { + ini_set('php.internal_encoding', $charset); + } + +/* + * ------------------------------------------------------ + * Load compatibility features + * ------------------------------------------------------ + */ + + require_once(BASEPATH.'core/compat/mbstring.php'); + require_once(BASEPATH.'core/compat/hash.php'); + require_once(BASEPATH.'core/compat/password.php'); + require_once(BASEPATH.'core/compat/standard.php'); - $UNI =& load_class('Utf8', 'core'); +/* + * ------------------------------------------------------ + * Instantiate the UTF-8 class + * ------------------------------------------------------ + */ + $UNI =& load_class('Utf8', 'core'); /* * ------------------------------------------------------ * Instantiate the URI class * ------------------------------------------------------ */ - $URI =& load_class('URI', 'core'); + $URI =& load_class('URI', 'core'); /* * ------------------------------------------------------ * Instantiate the routing class and set the routing * ------------------------------------------------------ */ - $RTR =& load_class('Router', 'core'); - $RTR->_set_routing(); - - // Set any routing overrides that may exist in the main index file - if (isset($routing)) - { - $RTR->_set_overrides($routing); - } + $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL); /* * ------------------------------------------------------ * Instantiate the output class * ------------------------------------------------------ */ - $OUT =& load_class('Output', 'core'); + $OUT =& load_class('Output', 'core'); /* * ------------------------------------------------------ - * Is there a valid cache file? If so, we're done... + * Is there a valid cache file? If so, we're done... * ------------------------------------------------------ */ - if ($EXT->_call_hook('cache_override') === FALSE) - { - if ($OUT->_display_cache($CFG, $URI) == TRUE) - { - exit; - } - } + if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) + { + exit; + } /* * ----------------------------------------------------- * Load the security class for xss and csrf support * ----------------------------------------------------- */ - $SEC =& load_class('Security', 'core'); + $SEC =& load_class('Security', 'core'); /* * ------------------------------------------------------ * Load the Input class and sanitize globals * ------------------------------------------------------ */ - $IN =& load_class('Input', 'core'); + $IN =& load_class('Input', 'core'); /* * ------------------------------------------------------ * Load the Language class * ------------------------------------------------------ */ - $LANG =& load_class('Lang', 'core'); + $LANG =& load_class('Lang', 'core'); /* * ------------------------------------------------------ @@ -226,178 +354,206 @@ * ------------------------------------------------------ * */ - // Load the base controller class - require BASEPATH.'core/Controller.php'; - - function &get_instance() - { - return CI_Controller::get_instance(); - } - - - if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php')) - { - require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'; - } - - // Load the local application controller - // Note: The Router class automatically validates the controller path using the router->_validate_request(). - // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid. - if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php')) - { - show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); - } - - include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'); - - // Set a mark point for benchmarking - $BM->mark('loading_time:_base_classes_end'); + // Load the base controller class + require_once BASEPATH.'core/Controller.php'; + + /** + * Reference to the CI_Controller method. + * + * Returns current CI instance object + * + * @return CI_Controller + */ + function &get_instance() + { + return CI_Controller::get_instance(); + } + + if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php')) + { + require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'; + } + + // Set a mark point for benchmarking + $BM->mark('loading_time:_base_classes_end'); /* * ------------------------------------------------------ - * Security check + * Sanity checks * ------------------------------------------------------ * - * None of the functions in the app controller or the - * loader class can be called via the URI, nor can - * controller functions that begin with an underscore - */ - $class = $RTR->fetch_class(); - $method = $RTR->fetch_method(); - - if ( ! class_exists($class) - OR strncmp($method, '_', 1) == 0 - OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller'))) - ) - { - if ( ! empty($RTR->routes['404_override'])) - { - $x = explode('/', $RTR->routes['404_override']); - $class = $x[0]; - $method = (isset($x[1]) ? $x[1] : 'index'); - if ( ! class_exists($class)) - { - if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) - { - show_404("{$class}/{$method}"); - } - - include_once(APPPATH.'controllers/'.$class.'.php'); - } - } - else - { - show_404("{$class}/{$method}"); - } - } + * The Router class has already validated the request, + * leaving us with 3 options here: + * + * 1) an empty class name, if we reached the default + * controller, but it didn't exist; + * 2) a query string which doesn't go through a + * file_exists() check + * 3) a regular request for a non-existing page + * + * We handle all of these as a 404 error. + * + * Furthermore, none of the methods in the app controller + * or the loader class can be called via the URI, nor can + * controller methods that begin with an underscore. + */ + + $e404 = FALSE; + $class = ucfirst($RTR->class); + $method = $RTR->method; + + if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php')) + { + $e404 = TRUE; + } + else + { + require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php'); + + if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method)) + { + $e404 = TRUE; + } + elseif (method_exists($class, '_remap')) + { + $params = array($method, array_slice($URI->rsegments, 2)); + $method = '_remap'; + } + elseif ( ! method_exists($class, $method)) + { + $e404 = TRUE; + } + /** + * DO NOT CHANGE THIS, NOTHING ELSE WORKS! + * + * - method_exists() returns true for non-public methods, which passes the previous elseif + * - is_callable() returns false for PHP 4-style constructors, even if there's a __construct() + * - method_exists($class, '__construct') won't work because CI_Controller::__construct() is inherited + * - People will only complain if this doesn't work, even though it is documented that it shouldn't. + * + * ReflectionMethod::isConstructor() is the ONLY reliable check, + * knowing which method will be executed as a constructor. + */ + elseif ( ! is_callable(array($class, $method))) + { + $reflection = new ReflectionMethod($class, $method); + if ( ! $reflection->isPublic() OR $reflection->isConstructor()) + { + $e404 = TRUE; + } + } + } + + if ($e404) + { + if ( ! empty($RTR->routes['404_override'])) + { + if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2) + { + $error_method = 'index'; + } + + $error_class = ucfirst($error_class); + + if ( ! class_exists($error_class, FALSE)) + { + if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php')) + { + require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'); + $e404 = ! class_exists($error_class, FALSE); + } + // Were we in a directory? If so, check for a global override + elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php')) + { + require_once(APPPATH.'controllers/'.$error_class.'.php'); + if (($e404 = ! class_exists($error_class, FALSE)) === FALSE) + { + $RTR->directory = ''; + } + } + } + else + { + $e404 = FALSE; + } + } + + // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1 + if ( ! $e404) + { + $class = $error_class; + $method = $error_method; + + $URI->rsegments = array( + 1 => $class, + 2 => $method + ); + } + else + { + show_404($RTR->directory.$class.'/'.$method); + } + } + + if ($method !== '_remap') + { + $params = array_slice($URI->rsegments, 2); + } /* * ------------------------------------------------------ * Is there a "pre_controller" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('pre_controller'); + $EXT->call_hook('pre_controller'); /* * ------------------------------------------------------ * Instantiate the requested controller * ------------------------------------------------------ */ - // Mark a start point so we can benchmark the controller - $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + // Mark a start point so we can benchmark the controller + $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); - $CI = new $class(); + $CI = new $class(); /* * ------------------------------------------------------ * Is there a "post_controller_constructor" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('post_controller_constructor'); + $EXT->call_hook('post_controller_constructor'); /* * ------------------------------------------------------ * Call the requested method * ------------------------------------------------------ */ - // Is there a "remap" function? If so, we call it instead - if (method_exists($CI, '_remap')) - { - $CI->_remap($method, array_slice($URI->rsegments, 2)); - } - else - { - // is_callable() returns TRUE on some versions of PHP 5 for private and protected - // methods, so we'll use this workaround for consistent behavior - if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) - { - // Check and see if we are using a 404 override and use it. - if ( ! empty($RTR->routes['404_override'])) - { - $x = explode('/', $RTR->routes['404_override']); - $class = $x[0]; - $method = (isset($x[1]) ? $x[1] : 'index'); - if ( ! class_exists($class)) - { - if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) - { - show_404("{$class}/{$method}"); - } - - include_once(APPPATH.'controllers/'.$class.'.php'); - unset($CI); - $CI = new $class(); - } - } - else - { - show_404("{$class}/{$method}"); - } - } - - // Call the requested method. - // Any URI segments present (besides the class/function) will be passed to the method for convenience - call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); - } - - - // Mark a benchmark end point - $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); + call_user_func_array(array(&$CI, $method), $params); + + // Mark a benchmark end point + $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); /* * ------------------------------------------------------ * Is there a "post_controller" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('post_controller'); + $EXT->call_hook('post_controller'); /* * ------------------------------------------------------ * Send the final rendered output to the browser * ------------------------------------------------------ */ - if ($EXT->_call_hook('display_override') === FALSE) - { - $OUT->_display(); - } + if ($EXT->call_hook('display_override') === FALSE) + { + $OUT->_display(); + } /* * ------------------------------------------------------ * Is there a "post_system" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('post_system'); - -/* - * ------------------------------------------------------ - * Close the DB connection if one exists - * ------------------------------------------------------ - */ - if (class_exists('CI_DB') AND isset($CI->db)) - { - $CI->db->close(); - } - - -/* End of file CodeIgniter.php */ -/* Location: ./system/core/CodeIgniter.php */ \ No newline at end of file + $EXT->call_hook('post_system'); diff --git a/system/core/Common.php b/system/core/Common.php old mode 100755 new mode 100644 index f7e43b2..624b5a9 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -1,560 +1,849 @@ -='); + } + + return $_is_php[$version]; + } } // ------------------------------------------------------------------------ -/** - * Tests for file writability - * - * is_writable() returns TRUE on Windows servers when you really can't write to - * the file, based on the read-only attribute. is_writable() is also unreliable - * on Unix servers if safe_mode is on. - * - * @access private - * @return void - */ if ( ! function_exists('is_really_writable')) { - function is_really_writable($file) - { - // If we're on a Unix server with safe_mode off we call is_writable - if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE) - { - return is_writable($file); - } - - // For windows servers and safe_mode "on" installations we'll actually - // write a file then read it. Bah... - if (is_dir($file)) - { - $file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100)); - - if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) - { - return FALSE; - } - - fclose($fp); - @chmod($file, DIR_WRITE_MODE); - @unlink($file); - return TRUE; - } - elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) - { - return FALSE; - } - - fclose($fp); - return TRUE; - } + /** + * Tests for file writability + * + * is_writable() returns TRUE on Windows servers when you really can't write to + * the file, based on the read-only attribute. is_writable() is also unreliable + * on Unix servers if safe_mode is on. + * + * @link https://bugs.php.net/bug.php?id=54709 + * @param string + * @return bool + */ + function is_really_writable($file) + { + // If we're on a Unix server with safe_mode off we call is_writable + if (DIRECTORY_SEPARATOR === '/' && (is_php('5.4') OR ! ini_get('safe_mode'))) + { + return is_writable($file); + } + + /* For Windows servers and safe_mode "on" installations we'll actually + * write a file then read it. Bah... + */ + if (is_dir($file)) + { + $file = rtrim($file, '/').'/'.md5(mt_rand()); + if (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + @chmod($file, 0777); + @unlink($file); + return TRUE; + } + elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + return TRUE; + } } // ------------------------------------------------------------------------ -/** -* Class registry -* -* This function acts as a singleton. If the requested class does not -* exist it is instantiated and set to a static variable. If it has -* previously been instantiated the variable is returned. -* -* @access public -* @param string the class name being requested -* @param string the directory where the class should be found -* @param string the class name prefix -* @return object -*/ if ( ! function_exists('load_class')) { - function &load_class($class, $directory = 'libraries', $prefix = 'CI_') - { - static $_classes = array(); - - // Does the class exist? If so, we're done... - if (isset($_classes[$class])) - { - return $_classes[$class]; - } - - $name = FALSE; - - // Look for the class first in the local application/libraries folder - // then in the native system/libraries folder - foreach (array(APPPATH, BASEPATH) as $path) - { - if (file_exists($path.$directory.'/'.$class.'.php')) - { - $name = $prefix.$class; - - if (class_exists($name) === FALSE) - { - require($path.$directory.'/'.$class.'.php'); - } - - break; - } - } - - // Is the request a class extension? If so we load it too - if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php')) - { - $name = config_item('subclass_prefix').$class; - - if (class_exists($name) === FALSE) - { - require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'); - } - } - - // Did we find the class? - if ($name === FALSE) - { - // Note: We use exit() rather then show_error() in order to avoid a - // self-referencing loop with the Excptions class - exit('Unable to locate the specified class: '.$class.'.php'); - } - - // Keep track of what we just loaded - is_loaded($class); - - $_classes[$class] = new $name(); - return $_classes[$class]; - } + /** + * Class registry + * + * This function acts as a singleton. If the requested class does not + * exist it is instantiated and set to a static variable. If it has + * previously been instantiated the variable is returned. + * + * @param string the class name being requested + * @param string the directory where the class should be found + * @param mixed an optional argument to pass to the class constructor + * @return object + */ + function &load_class($class, $directory = 'libraries', $param = NULL) + { + static $_classes = array(); + + // Does the class exist? If so, we're done... + if (isset($_classes[$class])) + { + return $_classes[$class]; + } + + $name = FALSE; + + // Look for the class first in the local application/libraries folder + // then in the native system/libraries folder + foreach (array(APPPATH, BASEPATH) as $path) + { + if (file_exists($path.$directory.'/'.$class.'.php')) + { + $name = 'CI_'.$class; + + if (class_exists($name, FALSE) === FALSE) + { + require_once($path.$directory.'/'.$class.'.php'); + } + + break; + } + } + + // Is the request a class extension? If so we load it too + if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php')) + { + $name = config_item('subclass_prefix').$class; + + if (class_exists($name, FALSE) === FALSE) + { + require_once(APPPATH.$directory.'/'.$name.'.php'); + } + } + + // Did we find the class? + if ($name === FALSE) + { + // Note: We use exit() rather than show_error() in order to avoid a + // self-referencing loop with the Exceptions class + set_status_header(503); + echo 'Unable to locate the specified class: '.$class.'.php'; + exit(5); // EXIT_UNK_CLASS + } + + // Keep track of what we just loaded + is_loaded($class); + + $_classes[$class] = isset($param) + ? new $name($param) + : new $name(); + return $_classes[$class]; + } } // -------------------------------------------------------------------- -/** -* Keeps track of which libraries have been loaded. This function is -* called by the load_class() function above -* -* @access public -* @return array -*/ if ( ! function_exists('is_loaded')) { - function &is_loaded($class = '') - { - static $_is_loaded = array(); - - if ($class != '') - { - $_is_loaded[strtolower($class)] = $class; - } - - return $_is_loaded; - } + /** + * Keeps track of which libraries have been loaded. This function is + * called by the load_class() function above + * + * @param string + * @return array + */ + function &is_loaded($class = '') + { + static $_is_loaded = array(); + + if ($class !== '') + { + $_is_loaded[strtolower($class)] = $class; + } + + return $_is_loaded; + } } // ------------------------------------------------------------------------ -/** -* Loads the main config.php file -* -* This function lets us grab the config file even if the Config class -* hasn't been instantiated yet -* -* @access private -* @return array -*/ if ( ! function_exists('get_config')) { - function &get_config($replace = array()) - { - static $_config; - - if (isset($_config)) - { - return $_config[0]; - } - - // Is the config file in the environment folder? - if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) - { - $file_path = APPPATH.'config/config.php'; - } - - // Fetch the config file - if ( ! file_exists($file_path)) - { - exit('The configuration file does not exist.'); - } - - require($file_path); - - // Does the $config array exist in the file? - if ( ! isset($config) OR ! is_array($config)) - { - exit('Your config file does not appear to be formatted correctly.'); - } - - // Are any values being dynamically replaced? - if (count($replace) > 0) - { - foreach ($replace as $key => $val) - { - if (isset($config[$key])) - { - $config[$key] = $val; - } - } - } - - $_config[0] =& $config; - return $_config[0]; - } + /** + * Loads the main config.php file + * + * This function lets us grab the config file even if the Config class + * hasn't been instantiated yet + * + * @param array + * @return array + */ + function &get_config(Array $replace = array()) + { + static $config; + + if (empty($config)) + { + $file_path = APPPATH.'config/config.php'; + $found = FALSE; + if (file_exists($file_path)) + { + $found = TRUE; + require($file_path); + } + + // Is the config file in the environment folder? + if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) + { + require($file_path); + } + elseif ( ! $found) + { + set_status_header(503); + echo 'The configuration file does not exist.'; + exit(3); // EXIT_CONFIG + } + + // Does the $config array exist in the file? + if ( ! isset($config) OR ! is_array($config)) + { + set_status_header(503); + echo 'Your config file does not appear to be formatted correctly.'; + exit(3); // EXIT_CONFIG + } + } + + // Are any values being dynamically added or replaced? + foreach ($replace as $key => $val) + { + $config[$key] = $val; + } + + return $config; + } } // ------------------------------------------------------------------------ -/** -* Returns the specified config item -* -* @access public -* @return mixed -*/ if ( ! function_exists('config_item')) { - function config_item($item) - { - static $_config_item = array(); - - if ( ! isset($_config_item[$item])) - { - $config =& get_config(); - - if ( ! isset($config[$item])) - { - return FALSE; - } - $_config_item[$item] = $config[$item]; - } - - return $_config_item[$item]; - } + /** + * Returns the specified config item + * + * @param string + * @return mixed + */ + function config_item($item) + { + static $_config; + + if (empty($_config)) + { + // references cannot be directly assigned to static variables, so we use an array + $_config[0] =& get_config(); + } + + return isset($_config[0][$item]) ? $_config[0][$item] : NULL; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('get_mimes')) +{ + /** + * Returns the MIME types array from config/mimes.php + * + * @return array + */ + function &get_mimes() + { + static $_mimes; + + if (empty($_mimes)) + { + $_mimes = file_exists(APPPATH.'config/mimes.php') + ? include(APPPATH.'config/mimes.php') + : array(); + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + $_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')); + } + } + + return $_mimes; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('is_https')) +{ + /** + * Is HTTPS? + * + * Determines if the application is accessed via an encrypted + * (HTTPS) connection. + * + * @return bool + */ + function is_https() + { + if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') + { + return TRUE; + } + elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') + { + return TRUE; + } + elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') + { + return TRUE; + } + + return FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('is_cli')) +{ + + /** + * Is CLI? + * + * Test to see if a request was made from the command line. + * + * @return bool + */ + function is_cli() + { + return (PHP_SAPI === 'cli' OR defined('STDIN')); + } } // ------------------------------------------------------------------------ -/** -* Error Handler -* -* This function lets us invoke the exception class and -* display errors using the standard error template located -* in application/errors/errors.php -* This function will send the error page directly to the -* browser and exit. -* -* @access public -* @return void -*/ if ( ! function_exists('show_error')) { - function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') - { - $_error =& load_class('Exceptions', 'core'); - echo $_error->show_error($heading, $message, 'error_general', $status_code); - exit; - } + /** + * Error Handler + * + * This function lets us invoke the exception class and + * display errors using the standard error template located + * in application/views/errors/error_general.php + * This function will send the error page directly to the + * browser and exit. + * + * @param string + * @param int + * @param string + * @return void + */ + function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') + { + $status_code = abs($status_code); + if ($status_code < 100) + { + $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN + $status_code = 500; + } + else + { + $exit_status = 1; // EXIT_ERROR + } + + $_error =& load_class('Exceptions', 'core'); + echo $_error->show_error($heading, $message, 'error_general', $status_code); + exit($exit_status); + } } // ------------------------------------------------------------------------ -/** -* 404 Page Handler -* -* This function is similar to the show_error() function above -* However, instead of the standard error template it displays -* 404 errors. -* -* @access public -* @return void -*/ if ( ! function_exists('show_404')) { - function show_404($page = '', $log_error = TRUE) - { - $_error =& load_class('Exceptions', 'core'); - $_error->show_404($page, $log_error); - exit; - } + /** + * 404 Page Handler + * + * This function is similar to the show_error() function above + * However, instead of the standard error template it displays + * 404 errors. + * + * @param string + * @param bool + * @return void + */ + function show_404($page = '', $log_error = TRUE) + { + $_error =& load_class('Exceptions', 'core'); + $_error->show_404($page, $log_error); + exit(4); // EXIT_UNKNOWN_FILE + } } // ------------------------------------------------------------------------ -/** -* Error Logging Interface -* -* We use this as a simple mechanism to access the logging -* class and send messages to be logged. -* -* @access public -* @return void -*/ if ( ! function_exists('log_message')) { - function log_message($level = 'error', $message, $php_error = FALSE) - { - static $_log; - - if (config_item('log_threshold') == 0) - { - return; - } - - $_log =& load_class('Log'); - $_log->write_log($level, $message, $php_error); - } + /** + * Error Logging Interface + * + * We use this as a simple mechanism to access the logging + * class and send messages to be logged. + * + * @param string the error level: 'error', 'debug' or 'info' + * @param string the error message + * @return void + */ + function log_message($level, $message) + { + static $_log; + + if ($_log === NULL) + { + // references cannot be directly assigned to static variables, so we use an array + $_log[0] =& load_class('Log', 'core'); + } + + $_log[0]->write_log($level, $message); + } } // ------------------------------------------------------------------------ -/** - * Set HTTP Status Header - * - * @access public - * @param int the status code - * @param string - * @return void - */ if ( ! function_exists('set_status_header')) { - function set_status_header($code = 200, $text = '') - { - $stati = array( - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 307 => 'Temporary Redirect', - - 400 => 'Bad Request', - 401 => 'Unauthorized', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed', - - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported' - ); - - if ($code == '' OR ! is_numeric($code)) - { - show_error('Status codes must be numeric', 500); - } - - if (isset($stati[$code]) AND $text == '') - { - $text = $stati[$code]; - } - - if ($text == '') - { - show_error('No status text available. Please check your status code number or supply your own message text.', 500); - } - - $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; - - if (substr(php_sapi_name(), 0, 3) == 'cgi') - { - header("Status: {$code} {$text}", TRUE); - } - elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0') - { - header($server_protocol." {$code} {$text}", TRUE, $code); - } - else - { - header("HTTP/1.1 {$code} {$text}", TRUE, $code); - } - } + /** + * Set HTTP Status Header + * + * @param int the status code + * @param string + * @return void + */ + function set_status_header($code = 200, $text = '') + { + if (is_cli()) + { + return; + } + + if (empty($code) OR ! is_numeric($code)) + { + show_error('Status codes must be numeric', 500); + } + + if (empty($text)) + { + is_int($code) OR $code = (int) $code; + $stati = array( + 100 => 'Continue', + 101 => 'Switching Protocols', + + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', + 426 => 'Upgrade Required', + 428 => 'Precondition Required', + 429 => 'Too Many Requests', + 431 => 'Request Header Fields Too Large', + + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 511 => 'Network Authentication Required', + ); + + if (isset($stati[$code])) + { + $text = $stati[$code]; + } + else + { + show_error('No status text available. Please check your status code number or supply your own message text.', 500); + } + } + + if (strpos(PHP_SAPI, 'cgi') === 0) + { + header('Status: '.$code.' '.$text, TRUE); + return; + } + + $server_protocol = (isset($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.0', 'HTTP/1.1', 'HTTP/2'), TRUE)) + ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; + header($server_protocol.' '.$code.' '.$text, TRUE, $code); + } } // -------------------------------------------------------------------- -/** -* Exception Handler -* -* This is the custom exception handler that is declaired at the top -* of Codeigniter.php. The main reason we use this is to permit -* PHP errors to be logged in our own log files since the user may -* not have access to server logs. Since this function -* effectively intercepts PHP errors, however, we also need -* to display errors based on the current error_reporting level. -* We do that with the use of a PHP error template. -* -* @access private -* @return void -*/ +if ( ! function_exists('_error_handler')) +{ + /** + * Error Handler + * + * This is the custom error handler that is declared at the (relative) + * top of CodeIgniter.php. The main reason we use this is to permit + * PHP errors to be logged in our own log files since the user may + * not have access to server logs. Since this function effectively + * intercepts PHP errors, however, we also need to display errors + * based on the current error_reporting level. + * We do that with the use of a PHP error template. + * + * @param int $severity + * @param string $message + * @param string $filepath + * @param int $line + * @return void + */ + function _error_handler($severity, $message, $filepath, $line) + { + $is_error = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity); + + // When an error occurred, set the status header to '500 Internal Server Error' + // to indicate to the client something went wrong. + // This can't be done within the $_error->show_php_error method because + // it is only called when the display_errors flag is set (which isn't usually + // the case in a production environment) or when errors are ignored because + // they are above the error_reporting threshold. + if ($is_error) + { + set_status_header(500); + } + + // Should we ignore the error? We'll get the current error_reporting + // level and add its bits with the severity bits to find out. + if (($severity & error_reporting()) !== $severity) + { + return; + } + + $_error =& load_class('Exceptions', 'core'); + $_error->log_exception($severity, $message, $filepath, $line); + + // Should we display the error? + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) + { + $_error->show_php_error($severity, $message, $filepath, $line); + } + + // If the error is fatal, the execution of the script should be stopped because + // errors can't be recovered from. Halting the script conforms with PHP's + // default error handling. See http://www.php.net/manual/en/errorfunc.constants.php + if ($is_error) + { + exit(1); // EXIT_ERROR + } + } +} + +// ------------------------------------------------------------------------ + if ( ! function_exists('_exception_handler')) { - function _exception_handler($severity, $message, $filepath, $line) - { - // We don't bother with "strict" notices since they tend to fill up - // the log file with excess information that isn't normally very helpful. - if ($severity == E_STRICT) - { - return; - } - - $_error =& load_class('Exceptions', 'core'); - - // Should we display the error? We'll get the current error_reporting - // level and add its bits with the severity bits to find out. - if (($severity & error_reporting()) == $severity) - { - $_error->show_php_error($severity, $message, $filepath, $line); - } - - // Should we log the error? No? We're done... - if (config_item('log_threshold') == 0) - { - return; - } - - $_error->log_exception($severity, $message, $filepath, $line); - } + /** + * Exception Handler + * + * Sends uncaught exceptions to the logger and displays them + * only if display_errors is On so that they don't show up in + * production environments. + * + * @param Exception $exception + * @return void + */ + function _exception_handler($exception) + { + $_error =& load_class('Exceptions', 'core'); + $_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine()); + + is_cli() OR set_status_header(500); + // Should we display the error? + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) + { + $_error->show_exception($exception); + } + + exit(1); // EXIT_ERROR + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('_shutdown_handler')) +{ + /** + * Shutdown Handler + * + * This is the shutdown handler that is declared at the top + * of CodeIgniter.php. The main reason we use this is to simulate + * a complete custom exception handler. + * + * E_STRICT is purposively neglected because such events may have + * been caught. Duplication or none? None is preferred for now. + * + * @link http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a + * @return void + */ + function _shutdown_handler() + { + $last_error = error_get_last(); + if (isset($last_error) && + ($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) + { + _error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']); + } + } } // -------------------------------------------------------------------- -/** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('remove_invisible_characters')) { - function remove_invisible_characters($str, $url_encoded = TRUE) - { - $non_displayables = array(); - - // every control character except newline (dec 10) - // carriage return (dec 13), and horizontal tab (dec 09) + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @param string + * @param bool + * @return string + */ + function remove_invisible_characters($str, $url_encoded = TRUE) + { + $non_displayables = array(); + + // every control character except newline (dec 10), + // carriage return (dec 13) and horizontal tab (dec 09) + if ($url_encoded) + { + $non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15 + $non_displayables[] = '/%1[0-9a-f]/i'; // url encoded 16-31 + $non_displayables[] = '/%7f/i'; // url encoded 127 + } + + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 + + do + { + $str = preg_replace($non_displayables, '', $str, -1, $count); + } + while ($count); + + return $str; + } +} - if ($url_encoded) - { - $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 - $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 - } +// ------------------------------------------------------------------------ - $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 +if ( ! function_exists('html_escape')) +{ + /** + * Returns HTML escaped variable. + * + * @param mixed $var The input string or array of strings to be escaped. + * @param bool $double_encode $double_encode set to FALSE prevents escaping twice. + * @return mixed The escaped string or array of strings as a result. + */ + function html_escape($var, $double_encode = TRUE) + { + if (empty($var)) + { + return $var; + } + + if (is_array($var)) + { + foreach (array_keys($var) as $key) + { + $var[$key] = html_escape($var[$key], $double_encode); + } + + return $var; + } + + return htmlspecialchars($var, ENT_QUOTES, config_item('charset'), $double_encode); + } +} - do - { - $str = preg_replace($non_displayables, '', $str, -1, $count); - } - while ($count); +// ------------------------------------------------------------------------ - return $str; - } +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Stringify attributes for use in HTML tags. + * + * Helper function used to convert a string, array, or object + * of attributes to a string. + * + * @param mixed string, array, object + * @param bool + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + $atts = NULL; + + if (empty($attributes)) + { + return $atts; + } + + if (is_string($attributes)) + { + return ' '.$attributes; + } + + $attributes = (array) $attributes; + + foreach ($attributes as $key => $val) + { + $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; + } + + return rtrim($atts, ','); + } } // ------------------------------------------------------------------------ -/** -* Returns HTML escaped variable -* -* @access public -* @param mixed -* @return mixed -*/ -if ( ! function_exists('html_escape')) +if ( ! function_exists('function_usable')) { - function html_escape($var) - { - if (is_array($var)) - { - return array_map('html_escape', $var); - } - else - { - return htmlspecialchars($var, ENT_QUOTES, config_item('charset')); - } - } + /** + * Function usable + * + * Executes a function_exists() check, and if the Suhosin PHP + * extension is loaded - checks whether the function that is + * checked might be disabled in there as well. + * + * This is useful as function_exists() will return FALSE for + * functions disabled via the *disable_functions* php.ini + * setting, but not for *suhosin.executor.func.blacklist* and + * *suhosin.executor.disable_eval*. These settings will just + * terminate script execution if a disabled function is executed. + * + * The above described behavior turned out to be a bug in Suhosin, + * but even though a fix was committed for 0.9.34 on 2012-02-12, + * that version is yet to be released. This function will therefore + * be just temporary, but would probably be kept for a few years. + * + * @link http://www.hardened-php.net/suhosin/ + * @param string $function_name Function to check for + * @return bool TRUE if the function exists and is safe to call, + * FALSE otherwise. + */ + function function_usable($function_name) + { + static $_suhosin_func_blacklist; + + if (function_exists($function_name)) + { + if ( ! isset($_suhosin_func_blacklist)) + { + $_suhosin_func_blacklist = extension_loaded('suhosin') + ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) + : array(); + } + + return ! in_array($function_name, $_suhosin_func_blacklist, TRUE); + } + + return FALSE; + } } - -/* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file diff --git a/system/core/Config.php b/system/core/Config.php old mode 100755 new mode 100644 index 99b370f..fc6c30f --- a/system/core/Config.php +++ b/system/core/Config.php @@ -1,382 +1,379 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - - // Set the base_url automatically if none was provided - if ($this->config['base_url'] == '') - { - // The regular expression is only a basic validation for a valid "Host" header. - // It's not exhaustive, only checks for valid characters. - if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST'])) - { - $base_url = (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off') ? 'http' : 'https'; - $base_url .= '://'. $_SERVER['HTTP_HOST']; - $base_url .= substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); - } - - else - { - $base_url = 'http://localhost/'; - } - - $this->set_item('base_url', $base_url); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @access public - * @param string the config file name - * @param boolean if configuration values should be loaded into their own section - * @param boolean true if errors should just return false, false if an error message should be displayed - * @return boolean if the file was loaded correctly - */ - function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $file = ($file == '') ? 'config' : str_replace('.php', '', $file); - $found = FALSE; - $loaded = FALSE; - - $check_locations = defined('ENVIRONMENT') - ? array(ENVIRONMENT.'/'.$file, $file) - : array($file); - - foreach ($this->_config_paths as $path) - { - foreach ($check_locations as $location) - { - $file_path = $path.'config/'.$location.'.php'; - - if (in_array($file_path, $this->is_loaded, TRUE)) - { - $loaded = TRUE; - continue 2; - } - - if (file_exists($file_path)) - { - $found = TRUE; - break; - } - } - - if ($found === FALSE) - { - continue; - } - - include($file_path); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); - } - - if ($use_sections === TRUE) - { - if (isset($this->config[$file])) - { - $this->config[$file] = array_merge($this->config[$file], $config); - } - else - { - $this->config[$file] = $config; - } - } - else - { - $this->config = array_merge($this->config, $config); - } - - $this->is_loaded[] = $file_path; - unset($config); - - $loaded = TRUE; - log_message('debug', 'Config file loaded: '.$file_path); - break; - } - - if ($loaded === FALSE) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.'.php does not exist.'); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - * - * - * @access public - * @param string the config item name - * @param string the index name - * @param bool - * @return string - */ - function item($item, $index = '') - { - if ($index == '') - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - } - else - { - if ( ! isset($this->config[$index])) - { - return FALSE; - } - - if ( ! isset($this->config[$index][$item])) - { - return FALSE; - } - - $pref = $this->config[$index][$item]; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - adds slash after item (if item is not empty) - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - if( trim($this->config[$item]) == '') - { - return ''; - } - - return rtrim($this->config[$item], '/').'/'; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * Returns base_url . index_page [. uri_string] - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - - if ($this->item('enable_query_strings') == FALSE) - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix; - } - else - { - return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri); - } - } - - // ------------------------------------------------------------- - - /** - * Base URL - * Returns base_url [. uri_string] - * - * @access public - * @param string $uri - * @return string - */ - function base_url($uri = '') - { - return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/'); - } - - // ------------------------------------------------------------- - - /** - * Build URI string for use in Config::site_url() and Config::base_url() - * - * @access protected - * @param $uri - * @return string - */ - protected function _uri_string($uri) - { - if ($this->item('enable_query_strings') == FALSE) - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - $uri = trim($uri, '/'); - } - else - { - if (is_array($uri)) - { - $i = 0; - $str = ''; - foreach ($uri as $key => $val) - { - $prefix = ($i == 0) ? '' : '&'; - $str .= $prefix.$key.'='.$val; - $i++; - } - $uri = $str; - } - } - return $uri; - } - - // -------------------------------------------------------------------- - - /** - * System URL - * - * @access public - * @return string - */ - function system_url() - { - $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); - return $this->slash_item('base_url').end($x).'/'; - } - - // -------------------------------------------------------------------- - - /** - * Set a config file item - * - * @access public - * @param string the config item key - * @param string the config item value - * @return void - */ - function set_item($item, $value) - { - $this->config[$item] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Assign to Config - * - * This function is called by the front controller (CodeIgniter.php) - * after the Config class is instantiated. It permits config items - * to be assigned or overriden by variables contained in the index.php file - * - * @access private - * @param array - * @return void - */ - function _assign_to_config($items = array()) - { - if (is_array($items)) - { - foreach ($items as $key => $val) - { - $this->set_item($key, $val); - } - } - } -} - -// END CI_Config class + /** + * List of all loaded config values + * + * @var array + */ + public $config = array(); + + /** + * List of all loaded config files + * + * @var array + */ + public $is_loaded = array(); + + /** + * List of paths to search when trying to load a config file. + * + * @used-by CI_Loader + * @var array + */ + public $_config_paths = array(APPPATH); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Sets the $config data from the primary config.php file as a class variable. + * + * @return void + */ + public function __construct() + { + $this->config =& get_config(); + + // Set the base_url automatically if none was provided + if (empty($this->config['base_url'])) + { + if (isset($_SERVER['SERVER_ADDR'])) + { + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) + { + $server_addr = '['.$_SERVER['SERVER_ADDR'].']'; + } + else + { + $server_addr = $_SERVER['SERVER_ADDR']; + } + + $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr + .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); + } + else + { + $base_url = 'http://localhost/'; + } + + $this->set_item('base_url', $base_url); + } + + log_message('info', 'Config Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @param string $file Configuration file name + * @param bool $use_sections Whether configuration values should be loaded into their own section + * @param bool $fail_gracefully Whether to just return FALSE or display an error message + * @return bool TRUE if the file was loaded correctly or FALSE on failure + */ + public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $file = ($file === '') ? 'config' : str_replace('.php', '', $file); + $loaded = FALSE; + + foreach ($this->_config_paths as $path) + { + foreach (array($file, ENVIRONMENT.DIRECTORY_SEPARATOR.$file) as $location) + { + $file_path = $path.'config/'.$location.'.php'; + if (in_array($file_path, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists($file_path)) + { + continue; + } + + include($file_path); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + + show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); + } + + if ($use_sections === TRUE) + { + $this->config[$file] = isset($this->config[$file]) + ? array_merge($this->config[$file], $config) + : $config; + } + else + { + $this->config = array_merge($this->config, $config); + } + + $this->is_loaded[] = $file_path; + $config = NULL; + $loaded = TRUE; + log_message('debug', 'Config file loaded: '.$file_path); + } + } + + if ($loaded === TRUE) + { + return TRUE; + } + elseif ($fail_gracefully === TRUE) + { + return FALSE; + } + + show_error('The configuration file '.$file.'.php does not exist.'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item + * + * @param string $item Config item name + * @param string $index Index name + * @return string|null The configuration item or NULL if the item doesn't exist + */ + public function item($item, $index = '') + { + if ($index == '') + { + return isset($this->config[$item]) ? $this->config[$item] : NULL; + } + + return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item with slash appended (if not empty) + * + * @param string $item Config item name + * @return string|null The configuration item or NULL if the item doesn't exist + */ + public function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return NULL; + } + elseif (trim($this->config[$item]) === '') + { + return ''; + } + + return rtrim($this->config[$item], '/').'/'; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * Returns base_url . index_page [. uri_string] + * + * @uses CI_Config::_uri_string() + * + * @param string|string[] $uri URI string or an array of segments + * @param string $protocol + * @return string + */ + public function site_url($uri = '', $protocol = NULL) + { + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + // For protocol-relative links + if ($protocol === '') + { + $base_url = substr($base_url, strpos($base_url, '//')); + } + else + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + } + + if (empty($uri)) + { + return $base_url.$this->item('index_page'); + } + + $uri = $this->_uri_string($uri); + + if ($this->item('enable_query_strings') === FALSE) + { + $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : ''; + + if ($suffix !== '') + { + if (($offset = strpos($uri, '?')) !== FALSE) + { + $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset); + } + else + { + $uri .= $suffix; + } + } + + return $base_url.$this->slash_item('index_page').$uri; + } + elseif (strpos($uri, '?') === FALSE) + { + $uri = '?'.$uri; + } + + return $base_url.$this->item('index_page').$uri; + } + + // ------------------------------------------------------------- + + /** + * Base URL + * + * Returns base_url [. uri_string] + * + * @uses CI_Config::_uri_string() + * + * @param string|string[] $uri URI string or an array of segments + * @param string $protocol + * @return string + */ + public function base_url($uri = '', $protocol = NULL) + { + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + // For protocol-relative links + if ($protocol === '') + { + $base_url = substr($base_url, strpos($base_url, '//')); + } + else + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + } + + return $base_url.$this->_uri_string($uri); + } + + // ------------------------------------------------------------- + + /** + * Build URI string + * + * @used-by CI_Config::site_url() + * @used-by CI_Config::base_url() + * + * @param string|string[] $uri URI string or an array of segments + * @return string + */ + protected function _uri_string($uri) + { + if ($this->item('enable_query_strings') === FALSE) + { + is_array($uri) && $uri = implode('/', $uri); + return ltrim($uri, '/'); + } + elseif (is_array($uri)) + { + return http_build_query($uri); + } + + return $uri; + } + + // -------------------------------------------------------------------- + + /** + * System URL + * + * @deprecated 3.0.0 Encourages insecure practices + * @return string + */ + public function system_url() + { + $x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH)); + return $this->slash_item('base_url').end($x).'/'; + } + + // -------------------------------------------------------------------- + + /** + * Set a config file item + * + * @param string $item Config item key + * @param string $value Config item value + * @return void + */ + public function set_item($item, $value) + { + $this->config[$item] = $value; + } -/* End of file Config.php */ -/* Location: ./system/core/Config.php */ +} diff --git a/system/core/Controller.php b/system/core/Controller.php old mode 100755 new mode 100644 index 7e42ef2..e25b847 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -1,65 +1,103 @@ - $class) - { - $this->$var =& load_class($class); - } + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + self::$instance =& $this; - $this->load =& load_class('Loader', 'core'); + // Assign all the class objects that were instantiated by the + // bootstrap file (CodeIgniter.php) to local class variables + // so that CI can run as one big super object. + foreach (is_loaded() as $var => $class) + { + $this->$var =& load_class($class); + } - $this->load->initialize(); + $this->load =& load_class('Loader', 'core'); + $this->load->initialize(); + log_message('info', 'Controller Class Initialized'); + } - log_message('debug', "Controller Class Initialized"); - } + // -------------------------------------------------------------------- - public static function &get_instance() - { - return self::$instance; - } -} -// END Controller class + /** + * Get the CI singleton + * + * @static + * @return object + */ + public static function &get_instance() + { + return self::$instance; + } -/* End of file Controller.php */ -/* Location: ./system/core/Controller.php */ \ No newline at end of file +} diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php old mode 100755 new mode 100644 index f928f39..90ff1ab --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -1,194 +1,274 @@ - 'Error', - E_WARNING => 'Warning', - E_PARSE => 'Parsing Error', - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core Error', - E_CORE_WARNING => 'Core Warning', - E_COMPILE_ERROR => 'Compile Error', - E_COMPILE_WARNING => 'Compile Warning', - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_STRICT => 'Runtime Notice' - ); - - - /** - * Constructor - */ - public function __construct() - { - $this->ob_level = ob_get_level(); - // Note: Do not log messages from this constructor. - } - - // -------------------------------------------------------------------- - - /** - * Exception Logger - * - * This function logs PHP generated error messages - * - * @access private - * @param string the error severity - * @param string the error string - * @param string the error filepath - * @param string the error line number - * @return string - */ - function log_exception($severity, $message, $filepath, $line) - { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - - log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * 404 Page Not Found Handler - * - * @access private - * @param string the page - * @param bool log error yes/no - * @return string - */ - function show_404($page = '', $log_error = TRUE) - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - // By default we log this, but allow a dev to skip it - if ($log_error) - { - log_message('error', '404 Page Not Found --> '.$page); - } - - echo $this->show_error($heading, $message, 'error_404', 404); - exit; - } - - // -------------------------------------------------------------------- - - /** - * General Error Page - * - * This function takes an error message as input - * (either as a string or an array) and displays - * it using the specified template. - * - * @access private - * @param string the heading - * @param string the message - * @param string the template name - * @param int the status code - * @return string - */ - function show_error($heading, $message, $template = 'error_general', $status_code = 500) - { - set_status_header($status_code); - - $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; - - if (ob_get_level() > $this->ob_level + 1) - { - ob_end_flush(); - } - ob_start(); - include(APPPATH.'errors/'.$template.'.php'); - $buffer = ob_get_contents(); - ob_end_clean(); - return $buffer; - } - - // -------------------------------------------------------------------- - - /** - * Native PHP error handler - * - * @access private - * @param string the error severity - * @param string the error string - * @param string the error filepath - * @param string the error line number - * @return string - */ - function show_php_error($severity, $message, $filepath, $line) - { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - - $filepath = str_replace("\\", "/", $filepath); - - // For safety reasons we do not show the full file path - if (FALSE !== strpos($filepath, '/')) - { - $x = explode('/', $filepath); - $filepath = $x[count($x)-2].'/'.end($x); - } - - if (ob_get_level() > $this->ob_level + 1) - { - ob_end_flush(); - } - ob_start(); - include(APPPATH.'errors/error_php.php'); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } + /** + * Nesting level of the output buffering mechanism + * + * @var int + */ + public $ob_level; -} -// END Exceptions Class + /** + * List of available error levels + * + * @var array + */ + public $levels = array( + E_ERROR => 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice' + ); + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $this->ob_level = ob_get_level(); + // Note: Do not log messages from this constructor. + } + + // -------------------------------------------------------------------- + + /** + * Exception Logger + * + * Logs PHP generated error messages + * + * @param int $severity Log level + * @param string $message Error message + * @param string $filepath File path + * @param int $line Line number + * @return void + */ + public function log_exception($severity, $message, $filepath, $line) + { + $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; + log_message('error', 'Severity: '.$severity.' --> '.$message.' '.$filepath.' '.$line); + } + + // -------------------------------------------------------------------- + + /** + * 404 Error Handler + * + * @uses CI_Exceptions::show_error() + * + * @param string $page Page URI + * @param bool $log_error Whether to log the error + * @return void + */ + public function show_404($page = '', $log_error = TRUE) + { + if (is_cli()) + { + $heading = 'Not Found'; + $message = 'The controller/method pair you requested was not found.'; + } + else + { + $heading = '404 Page Not Found'; + $message = 'The page you requested was not found.'; + } + + // By default we log this, but allow a dev to skip it + if ($log_error) + { + log_message('error', $heading.': '.$page); + } + + echo $this->show_error($heading, $message, 'error_404', 404); + exit(4); // EXIT_UNKNOWN_FILE + } + + // -------------------------------------------------------------------- + + /** + * General Error Page + * + * Takes an error message as input (either as a string or an array) + * and displays it using the specified template. + * + * @param string $heading Page heading + * @param string|string[] $message Error message + * @param string $template Template name + * @param int $status_code (default: 500) + * + * @return string Error page output + */ + public function show_error($heading, $message, $template = 'error_general', $status_code = 500) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } -/* End of file Exceptions.php */ -/* Location: ./system/core/Exceptions.php */ \ No newline at end of file + if (is_cli()) + { + $message = "\t".(is_array($message) ? implode("\n\t", $message) : $message); + $template = 'cli'.DIRECTORY_SEPARATOR.$template; + } + else + { + set_status_header($status_code); + $message = '

'.(is_array($message) ? implode('

', $message) : $message).'

'; + $template = 'html'.DIRECTORY_SEPARATOR.$template; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + ob_start(); + include($templates_path.$template.'.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + + // -------------------------------------------------------------------- + + public function show_exception($exception) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } + + $message = $exception->getMessage(); + if (empty($message)) + { + $message = '(null)'; + } + + if (is_cli()) + { + $templates_path .= 'cli'.DIRECTORY_SEPARATOR; + } + else + { + $templates_path .= 'html'.DIRECTORY_SEPARATOR; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + + ob_start(); + include($templates_path.'error_exception.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + // -------------------------------------------------------------------- + + /** + * Native PHP error handler + * + * @param int $severity Error level + * @param string $message Error message + * @param string $filepath File path + * @param int $line Line number + * @return void + */ + public function show_php_error($severity, $message, $filepath, $line) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } + + $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; + + // For safety reasons we don't show the full file path in non-CLI requests + if ( ! is_cli()) + { + $filepath = str_replace('\\', '/', $filepath); + if (FALSE !== strpos($filepath, '/')) + { + $x = explode('/', $filepath); + $filepath = $x[count($x)-2].'/'.end($x); + } + + $template = 'html'.DIRECTORY_SEPARATOR.'error_php'; + } + else + { + $template = 'cli'.DIRECTORY_SEPARATOR.'error_php'; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + ob_start(); + include($templates_path.$template.'.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + +} diff --git a/system/core/Hooks.php b/system/core/Hooks.php old mode 100755 new mode 100644 index 49fb89f..6236dd4 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -1,249 +1,266 @@ -_initialize(); - log_message('debug', "Hooks Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Hooks Preferences - * - * @access private - * @return void - */ - function _initialize() - { - $CFG =& load_class('Config', 'core'); - - // If hooks are not enabled in the config file - // there is nothing else to do - - if ($CFG->item('enable_hooks') == FALSE) - { - return; - } - - // Grab the "hooks" definition file. - // If there are no hooks, we're done. - - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); - } - elseif (is_file(APPPATH.'config/hooks.php')) - { - include(APPPATH.'config/hooks.php'); - } - - - if ( ! isset($hook) OR ! is_array($hook)) - { - return; - } - - $this->hooks =& $hook; - $this->enabled = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Call Hook - * - * Calls a particular hook - * - * @access private - * @param string the hook name - * @return mixed - */ - function _call_hook($which = '') - { - if ( ! $this->enabled OR ! isset($this->hooks[$which])) - { - return FALSE; - } - - if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0])) - { - foreach ($this->hooks[$which] as $val) - { - $this->_run_hook($val); - } - } - else - { - $this->_run_hook($this->hooks[$which]); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Run Hook - * - * Runs a particular hook - * - * @access private - * @param array the hook details - * @return bool - */ - function _run_hook($data) - { - if ( ! is_array($data)) - { - return FALSE; - } - - // ----------------------------------- - // Safety - Prevents run-away loops - // ----------------------------------- - - // If the script being called happens to have the same - // hook call within it a loop can happen - - if ($this->in_progress == TRUE) - { - return; - } - - // ----------------------------------- - // Set file path - // ----------------------------------- - - if ( ! isset($data['filepath']) OR ! isset($data['filename'])) - { - return FALSE; - } - - $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - - if ( ! file_exists($filepath)) - { - return FALSE; - } - - // ----------------------------------- - // Set class/function name - // ----------------------------------- - - $class = FALSE; - $function = FALSE; - $params = ''; - - if (isset($data['class']) AND $data['class'] != '') - { - $class = $data['class']; - } - - if (isset($data['function'])) - { - $function = $data['function']; - } - - if (isset($data['params'])) - { - $params = $data['params']; - } - - if ($class === FALSE AND $function === FALSE) - { - return FALSE; - } - - // ----------------------------------- - // Set the in_progress flag - // ----------------------------------- - - $this->in_progress = TRUE; - - // ----------------------------------- - // Call the requested class and/or function - // ----------------------------------- - - if ($class !== FALSE) - { - if ( ! class_exists($class)) - { - require($filepath); - } - - $HOOK = new $class; - $HOOK->$function($params); - } - else - { - if ( ! function_exists($function)) - { - require($filepath); - } - - $function($params); - } - - $this->in_progress = FALSE; - return TRUE; - } + /** + * Determines whether hooks are enabled + * + * @var bool + */ + public $enabled = FALSE; + + /** + * List of all hooks set in config/hooks.php + * + * @var array + */ + public $hooks = array(); + + /** + * Array with class objects to use hooks methods + * + * @var array + */ + protected $_objects = array(); + + /** + * In progress flag + * + * Determines whether hook is in progress, used to prevent infinte loops + * + * @var bool + */ + protected $_in_progress = FALSE; + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $CFG =& load_class('Config', 'core'); + log_message('info', 'Hooks Class Initialized'); + + // If hooks are not enabled in the config file + // there is nothing else to do + if ($CFG->item('enable_hooks') === FALSE) + { + return; + } + + // Grab the "hooks" definition file. + if (file_exists(APPPATH.'config/hooks.php')) + { + include(APPPATH.'config/hooks.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); + } + + // If there are no hooks, we're done. + if ( ! isset($hook) OR ! is_array($hook)) + { + return; + } + + $this->hooks =& $hook; + $this->enabled = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Call Hook + * + * Calls a particular hook. Called by CodeIgniter.php. + * + * @uses CI_Hooks::_run_hook() + * + * @param string $which Hook name + * @return bool TRUE on success or FALSE on failure + */ + public function call_hook($which = '') + { + if ( ! $this->enabled OR ! isset($this->hooks[$which])) + { + return FALSE; + } + + if (is_array($this->hooks[$which]) && ! isset($this->hooks[$which]['function'])) + { + foreach ($this->hooks[$which] as $val) + { + $this->_run_hook($val); + } + } + else + { + $this->_run_hook($this->hooks[$which]); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Run Hook + * + * Runs a particular hook + * + * @param array $data Hook details + * @return bool TRUE on success or FALSE on failure + */ + protected function _run_hook($data) + { + // Closures/lambda functions and array($object, 'method') callables + if (is_callable($data)) + { + is_array($data) + ? $data[0]->{$data[1]}() + : $data(); + + return TRUE; + } + elseif ( ! is_array($data)) + { + return FALSE; + } + + // ----------------------------------- + // Safety - Prevents run-away loops + // ----------------------------------- + + // If the script being called happens to have the same + // hook call within it a loop can happen + if ($this->_in_progress === TRUE) + { + return; + } + + // ----------------------------------- + // Set file path + // ----------------------------------- + + if ( ! isset($data['filepath'], $data['filename'])) + { + return FALSE; + } + + $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; + + if ( ! file_exists($filepath)) + { + return FALSE; + } + + // Determine and class and/or function names + $class = empty($data['class']) ? FALSE : $data['class']; + $function = empty($data['function']) ? FALSE : $data['function']; + $params = isset($data['params']) ? $data['params'] : ''; + + if (empty($function)) + { + return FALSE; + } + + // Set the _in_progress flag + $this->_in_progress = TRUE; + + // Call the requested class and/or function + if ($class !== FALSE) + { + // The object is stored? + if (isset($this->_objects[$class])) + { + if (method_exists($this->_objects[$class], $function)) + { + $this->_objects[$class]->$function($params); + } + else + { + return $this->_in_progress = FALSE; + } + } + else + { + class_exists($class, FALSE) OR require_once($filepath); + + if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function)) + { + return $this->_in_progress = FALSE; + } + + // Store the object and execute the method + $this->_objects[$class] = new $class(); + $this->_objects[$class]->$function($params); + } + } + else + { + function_exists($function) OR require_once($filepath); + + if ( ! function_exists($function)) + { + return $this->_in_progress = FALSE; + } + + $function($params); + } + + $this->_in_progress = FALSE; + return TRUE; + } } - -// END CI_Hooks class - -/* End of file Hooks.php */ -/* Location: ./system/core/Hooks.php */ \ No newline at end of file diff --git a/system/core/Input.php b/system/core/Input.php old mode 100755 new mode 100644 index be38270..30b31d0 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -1,866 +1,895 @@ -_allow_get_array = (config_item('allow_get_array') === TRUE); - $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); - $this->_enable_csrf = (config_item('csrf_protection') === TRUE); - - global $SEC; - $this->security =& $SEC; - - // Do we need the UTF-8 class? - if (UTF8_ENABLED === TRUE) - { - global $UNI; - $this->uni =& $UNI; - } - - // Sanitize global arrays - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * Fetch from array - * - * This is a helper function to retrieve values from global arrays - * - * @access private - * @param array - * @param string - * @param bool - * @return string - */ - function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE) - { - if ( ! isset($array[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - return $this->security->xss_clean($array[$index]); - } - - return $array[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the GET array - * - * @access public - * @param string - * @param bool - * @return string - */ - function get($index = NULL, $xss_clean = FALSE) - { - // Check if a field has been provided - if ($index === NULL AND ! empty($_GET)) - { - $get = array(); - - // loop through the full _GET array - foreach (array_keys($_GET) as $key) - { - $get[$key] = $this->_fetch_from_array($_GET, $key, $xss_clean); - } - return $get; - } - - return $this->_fetch_from_array($_GET, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the POST array - * - * @access public - * @param string - * @param bool - * @return string - */ - function post($index = NULL, $xss_clean = FALSE) - { - // Check if a field has been provided - if ($index === NULL AND ! empty($_POST)) - { - $post = array(); - - // Loop through the full _POST array and return it - foreach (array_keys($_POST) as $key) - { - $post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean); - } - return $post; - } - - return $this->_fetch_from_array($_POST, $index, $xss_clean); - } - - - // -------------------------------------------------------------------- - - /** - * Fetch an item from either the GET array or the POST - * - * @access public - * @param string The index key - * @param bool XSS cleaning - * @return string - */ - function get_post($index = '', $xss_clean = FALSE) - { - if ( ! isset($_POST[$index]) ) - { - return $this->get($index, $xss_clean); - } - else - { - return $this->post($index, $xss_clean); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return string - */ - function cookie($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); - } - - // ------------------------------------------------------------------------ - - /** - * Set cookie - * - * Accepts six parameter, or you can submit an associative - * array in the first parameter containing all the values. - * - * @access public - * @param mixed - * @param string the value of the cookie - * @param string the number of seconds until expiration - * @param string the cookie domain. Usually: .yourdomain.com - * @param string the cookie path - * @param string the cookie prefix - * @param bool true makes the cookie secure - * @return void - */ - function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE) - { - if (is_array($name)) - { - // always leave 'name' in last place, as the loop will break otherwise, due to $$item - foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item) - { - if (isset($name[$item])) - { - $$item = $name[$item]; - } - } - } - - if ($prefix == '' AND config_item('cookie_prefix') != '') - { - $prefix = config_item('cookie_prefix'); - } - if ($domain == '' AND config_item('cookie_domain') != '') - { - $domain = config_item('cookie_domain'); - } - if ($path == '/' AND config_item('cookie_path') != '/') - { - $path = config_item('cookie_path'); - } - if ($secure == FALSE AND config_item('cookie_secure') != FALSE) - { - $secure = config_item('cookie_secure'); - } - - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - $expire = ($expire > 0) ? time() + $expire : 0; - } - - setcookie($prefix.$name, $value, $expire, $path, $domain, $secure); - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the SERVER array - * - * @access public - * @param string - * @param bool - * @return string - */ - function server($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_SERVER, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the IP Address - * - * @return string - */ - public function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - $proxy_ips = config_item('proxy_ips'); - if ( ! empty($proxy_ips)) - { - $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); - foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) - { - if (($spoof = $this->server($header)) !== FALSE) - { - // Some proxies typically list the whole chain of IP - // addresses through which the client has reached us. - // e.g. client_ip, proxy_ip1, proxy_ip2, etc. - if (strpos($spoof, ',') !== FALSE) - { - $spoof = explode(',', $spoof, 2); - $spoof = $spoof[0]; - } - - if ( ! $this->valid_ip($spoof)) - { - $spoof = FALSE; - } - else - { - break; - } - } - } - - $this->ip_address = ($spoof !== FALSE && in_array($_SERVER['REMOTE_ADDR'], $proxy_ips, TRUE)) - ? $spoof : $_SERVER['REMOTE_ADDR']; - } - else - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - - if ( ! $this->valid_ip($this->ip_address)) - { - $this->ip_address = '0.0.0.0'; - } - - return $this->ip_address; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @param string ipv4 or ipv6 - * @return bool - */ - public function valid_ip($ip, $which = '') - { - $which = strtolower($which); - - // First check if filter_var is available - if (is_callable('filter_var')) - { - switch ($which) { - case 'ipv4': - $flag = FILTER_FLAG_IPV4; - break; - case 'ipv6': - $flag = FILTER_FLAG_IPV6; - break; - default: - $flag = ''; - break; - } - - return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag); - } - - if ($which !== 'ipv6' && $which !== 'ipv4') - { - if (strpos($ip, ':') !== FALSE) - { - $which = 'ipv6'; - } - elseif (strpos($ip, '.') !== FALSE) - { - $which = 'ipv4'; - } - else - { - return FALSE; - } - } - - $func = '_valid_'.$which; - return $this->$func($ip); - } - - // -------------------------------------------------------------------- - - /** - * Validate IPv4 Address - * - * Updated version suggested by Geert De Deckere - * - * @access protected - * @param string - * @return bool - */ - protected function _valid_ipv4($ip) - { - $ip_segments = explode('.', $ip); - - // Always 4 segments needed - if (count($ip_segments) !== 4) - { - return FALSE; - } - // IP can not start with 0 - if ($ip_segments[0][0] == '0') - { - return FALSE; - } - - // Check each segment - foreach ($ip_segments as $segment) - { - // IP segments must be digits and can not be - // longer than 3 digits or greater then 255 - if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IPv6 Address - * - * @access protected - * @param string - * @return bool - */ - protected function _valid_ipv6($str) - { - // 8 groups, separated by : - // 0-ffff per group - // one set of consecutive 0 groups can be collapsed to :: - - $groups = 8; - $collapsed = FALSE; - - $chunks = array_filter( - preg_split('/(:{1,2})/', $str, NULL, PREG_SPLIT_DELIM_CAPTURE) - ); - - // Rule out easy nonsense - if (current($chunks) == ':' OR end($chunks) == ':') - { - return FALSE; - } - - // PHP supports IPv4-mapped IPv6 addresses, so we'll expect those as well - if (strpos(end($chunks), '.') !== FALSE) - { - $ipv4 = array_pop($chunks); - - if ( ! $this->_valid_ipv4($ipv4)) - { - return FALSE; - } - - $groups--; - } - - while ($seg = array_pop($chunks)) - { - if ($seg[0] == ':') - { - if (--$groups == 0) - { - return FALSE; // too many groups - } - - if (strlen($seg) > 2) - { - return FALSE; // long separator - } - - if ($seg == '::') - { - if ($collapsed) - { - return FALSE; // multiple collapsed - } - - $collapsed = TRUE; - } - } - elseif (preg_match("/[^0-9a-f]/i", $seg) OR strlen($seg) > 4) - { - return FALSE; // invalid segment - } - } - - return $collapsed OR $groups == 1; - } - - // -------------------------------------------------------------------- - - /** - * User Agent - * - * @access public - * @return string - */ - function user_agent() - { - if ($this->user_agent !== FALSE) - { - return $this->user_agent; - } - - $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; - - return $this->user_agent; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Globals - * - * This function does the following: - * - * Unsets $_GET data (if query strings are not enabled) - * - * Unsets all globals if register_globals is enabled - * - * Standardizes newline characters to \n - * - * @access private - * @return void - */ - function _sanitize_globals() - { - // It would be "wrong" to unset any of these GLOBALS. - $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', - '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA', - 'system_folder', 'application_folder', 'BM', 'EXT', - 'CFG', 'URI', 'RTR', 'OUT', 'IN'); - - // Unset globals for securiy. - // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE) as $global) - { - if ( ! is_array($global)) - { - if ( ! in_array($global, $protected)) - { - global $$global; - $$global = NULL; - } - } - else - { - foreach ($global as $key => $val) - { - if ( ! in_array($key, $protected)) - { - global $$key; - $$key = NULL; - } - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->_allow_get_array == FALSE) - { - $_GET = array(); - } - else - { - if (is_array($_GET) AND count($_GET) > 0) - { - foreach ($_GET as $key => $val) - { - $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - } - - // Clean $_POST Data - if (is_array($_POST) AND count($_POST) > 0) - { - foreach ($_POST as $key => $val) - { - $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - - // Clean $_COOKIE Data - if (is_array($_COOKIE) AND count($_COOKIE) > 0) - { - // Also get rid of specially treated cookies that might be set by a server - // or silly application, that are of no use to a CI application anyway - // but that when present will trip our 'Disallowed Key Characters' alarm - // http://www.ietf.org/rfc/rfc2109.txt - // note that the key names below are single quoted strings, and are not PHP variables - unset($_COOKIE['$Version']); - unset($_COOKIE['$Path']); - unset($_COOKIE['$Domain']); - - // Work-around for PHP bug #66827 (https://bugs.php.net/bug.php?id=66827) - // - // The session ID sanitizer doesn't check for the value type and blindly does - // an implicit cast to string, which triggers an 'Array to string' E_NOTICE. - $sess_cookie_name = config_item('cookie_prefix').config_item('sess_cookie_name'); - if (isset($_COOKIE[$sess_cookie_name]) && ! is_string($_COOKIE[$sess_cookie_name])) - { - unset($_COOKIE[$sess_cookie_name]); - } - - foreach ($_COOKIE as $key => $val) - { - // _clean_input_data() has been reported to break encrypted cookies - if ($key === $sess_cookie_name && config_item('sess_encrypt_cookie')) - { - continue; - } - - $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - - // Sanitize PHP_SELF - $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); - - - // CSRF Protection check on HTTP requests - if ($this->_enable_csrf == TRUE && ! $this->is_cli_request()) - { - $this->security->csrf_verify(); - } - - log_message('debug', "Global POST and COOKIE data sanitized"); - } - - // -------------------------------------------------------------------- - - /** - * Clean Input Data - * - * This is a helper function. It escapes data and - * standardizes newline characters to \n - * - * @access private - * @param string - * @return string - */ - function _clean_input_data($str) - { - if (is_array($str)) - { - $new_array = array(); - foreach ($str as $key => $val) - { - $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - return $new_array; - } - - /* We strip slashes if magic quotes is on to keep things consistent - - 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()) - { - $str = stripslashes($str); - } - - // Clean UTF-8 if supported - if (UTF8_ENABLED === TRUE) - { - $str = $this->uni->clean_string($str); - } - - // Remove control characters - $str = remove_invisible_characters($str); - - // Should we filter the input data? - if ($this->_enable_xss === TRUE) - { - $str = $this->security->xss_clean($str); - } - - // Standardize newlines if needed - if ($this->_standardize_newlines == TRUE) - { - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str); - } - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Clean Keys - * - * This is a helper function. To prevent malicious users - * from trying to exploit keys we make sure that keys are - * only named with alpha-numeric text and a few other items. - * - * @access private - * @param string - * @return string - */ - function _clean_input_keys($str) - { - if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) - { - exit('Disallowed Key Characters.'); - } - - // Clean UTF-8 if supported - if (UTF8_ENABLED === TRUE) - { - $str = $this->uni->clean_string($str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Request Headers - * - * In Apache, you can simply call apache_request_headers(), however for - * people running other webservers the function is undefined. - * - * @param bool XSS cleaning - * - * @return array - */ - public function request_headers($xss_clean = FALSE) - { - // Look at Apache go! - if (function_exists('apache_request_headers')) - { - $headers = apache_request_headers(); - } - else - { - $headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); - - foreach ($_SERVER as $key => $val) - { - if (strncmp($key, 'HTTP_', 5) === 0) - { - $headers[substr($key, 5)] = $this->_fetch_from_array($_SERVER, $key, $xss_clean); - } - } - } - - // take SOME_HEADER and turn it into Some-Header - foreach ($headers as $key => $val) - { - $key = str_replace('_', ' ', strtolower($key)); - $key = str_replace(' ', '-', ucwords($key)); - - $this->headers[$key] = $val; - } - - return $this->headers; - } - - // -------------------------------------------------------------------- - - /** - * Get Request Header - * - * Returns the value of a single member of the headers class member - * - * @param string array key for $this->headers - * @param boolean XSS Clean or not - * @return mixed FALSE on failure, string on success - */ - public function get_request_header($index, $xss_clean = FALSE) - { - if (empty($this->headers)) - { - $this->request_headers(); - } - - if ( ! isset($this->headers[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - return $this->security->xss_clean($this->headers[$index]); - } - - return $this->headers[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Is ajax Request? - * - * Test to see if a request contains the HTTP_X_REQUESTED_WITH header - * - * @return boolean - */ - public function is_ajax_request() - { - return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest'); - } - - // -------------------------------------------------------------------- - - /** - * Is cli Request? - * - * Test to see if a request was made from the command line - * - * @return bool - */ - public function is_cli_request() - { - return (php_sapi_name() === 'cli' OR defined('STDIN')); - } + /** + * IP address of the current user + * + * @var string + */ + protected $ip_address = FALSE; + + /** + * Allow GET array flag + * + * If set to FALSE, then $_GET will be set to an empty array. + * + * @var bool + */ + protected $_allow_get_array = TRUE; + + /** + * Standardize new lines flag + * + * If set to TRUE, then newlines are standardized. + * + * @var bool + */ + protected $_standardize_newlines; + + /** + * Enable XSS flag + * + * Determines whether the XSS filter is always active when + * GET, POST or COOKIE data is encountered. + * Set automatically based on config setting. + * + * @var bool + */ + protected $_enable_xss = FALSE; + + /** + * Enable CSRF flag + * + * Enables a CSRF cookie token to be set. + * Set automatically based on config setting. + * + * @var bool + */ + protected $_enable_csrf = FALSE; + + /** + * List of all HTTP request headers + * + * @var array + */ + protected $headers = array(); + + /** + * Raw input stream data + * + * Holds a cache of php://input contents + * + * @var string + */ + protected $_raw_input_stream; + + /** + * Parsed input stream data + * + * Parsed from php://input at runtime + * + * @see CI_Input::input_stream() + * @var array + */ + protected $_input_stream; + + protected $security; + protected $uni; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Determines whether to globally enable the XSS processing + * and whether to allow the $_GET array. + * + * @return void + */ + public function __construct() + { + $this->_allow_get_array = (config_item('allow_get_array') !== FALSE); + $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); + $this->_enable_csrf = (config_item('csrf_protection') === TRUE); + $this->_standardize_newlines = (bool) config_item('standardize_newlines'); + + $this->security =& load_class('Security', 'core'); + + // Do we need the UTF-8 class? + if (UTF8_ENABLED === TRUE) + { + $this->uni =& load_class('Utf8', 'core'); + } + + // Sanitize global arrays + $this->_sanitize_globals(); + + // CSRF Protection check + if ($this->_enable_csrf === TRUE && ! is_cli()) + { + $this->security->csrf_verify(); + } + + log_message('info', 'Input Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch from array + * + * Internal method used to retrieve values from global arrays. + * + * @param array &$array $_GET, $_POST, $_COOKIE, $_SERVER, etc. + * @param mixed $index Index for item to be fetched from $array + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL) + { + is_bool($xss_clean) OR $xss_clean = $this->_enable_xss; + + // If $index is NULL, it means that the whole $array is requested + isset($index) OR $index = array_keys($array); + + // allow fetching multiple keys at once + if (is_array($index)) + { + $output = array(); + foreach ($index as $key) + { + $output[$key] = $this->_fetch_from_array($array, $key, $xss_clean); + } + + return $output; + } + + if (isset($array[$index])) + { + $value = $array[$index]; + } + elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation + { + $value = $array; + for ($i = 0; $i < $count; $i++) + { + $key = trim($matches[0][$i], '[]'); + if ($key === '') // Empty notation will return the value as array + { + break; + } + + if (isset($value[$key])) + { + $value = $value[$key]; + } + else + { + return NULL; + } + } + } + else + { + return NULL; + } + + return ($xss_clean === TRUE) + ? $this->security->xss_clean($value) + : $value; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the GET array + * + * @param mixed $index Index for item to be fetched from $_GET + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function get($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_GET, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @param mixed $index Index for item to be fetched from $_POST + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function post($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_POST, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from POST data with fallback to GET + * + * @param string $index Index for item to be fetched from $_POST or $_GET + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function post_get($index, $xss_clean = NULL) + { + return isset($_POST[$index]) + ? $this->post($index, $xss_clean) + : $this->get($index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from GET data with fallback to POST + * + * @param string $index Index for item to be fetched from $_GET or $_POST + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function get_post($index, $xss_clean = NULL) + { + return isset($_GET[$index]) + ? $this->get($index, $xss_clean) + : $this->post($index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @param mixed $index Index for item to be fetched from $_COOKIE + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function cookie($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @param mixed $index Index for item to be fetched from $_SERVER + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function server($index, $xss_clean = NULL) + { + return $this->_fetch_from_array($_SERVER, $index, $xss_clean); + } + + // ------------------------------------------------------------------------ + + /** + * Fetch an item from the php://input stream + * + * Useful when you need to access PUT, DELETE or PATCH request data. + * + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function input_stream($index = NULL, $xss_clean = NULL) + { + // Prior to PHP 5.6, the input stream can only be read once, + // so we'll need to check if we have already done that first. + if ( ! is_array($this->_input_stream)) + { + // $this->raw_input_stream will trigger __get(). + parse_str($this->raw_input_stream, $this->_input_stream); + is_array($this->_input_stream) OR $this->_input_stream = array(); + } + + return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); + } + + // ------------------------------------------------------------------------ + + /** + * Set cookie + * + * Accepts an arbitrary number of parameters (up to 7) or an associative + * array in the first parameter containing all the values. + * + * @param string|mixed[] $name Cookie name or an array containing parameters + * @param string $value Cookie value + * @param int $expire Cookie expiration time in seconds + * @param string $domain Cookie domain (e.g.: '.yourdomain.com') + * @param string $path Cookie path (default: '/') + * @param string $prefix Cookie name prefix + * @param bool $secure Whether to only transfer cookies via SSL + * @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript) + * @return void + */ + public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) + { + if (is_array($name)) + { + // always leave 'name' in last place, as the loop will break otherwise, due to $$item + foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item) + { + if (isset($name[$item])) + { + $$item = $name[$item]; + } + } + } + + if ($prefix === '' && config_item('cookie_prefix') !== '') + { + $prefix = config_item('cookie_prefix'); + } + + if ($domain == '' && config_item('cookie_domain') != '') + { + $domain = config_item('cookie_domain'); + } + + if ($path === '/' && config_item('cookie_path') !== '/') + { + $path = config_item('cookie_path'); + } + + $secure = ($secure === NULL && config_item('cookie_secure') !== NULL) + ? (bool) config_item('cookie_secure') + : (bool) $secure; + + $httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL) + ? (bool) config_item('cookie_httponly') + : (bool) $httponly; + + if ( ! is_numeric($expire)) + { + $expire = time() - 86500; + } + else + { + $expire = ($expire > 0) ? time() + $expire : 0; + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * Determines and validates the visitor's IP address. + * + * @return string IP address + */ + public function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + $proxy_ips = config_item('proxy_ips'); + if ( ! empty($proxy_ips) && ! is_array($proxy_ips)) + { + $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); + } + + $this->ip_address = $this->server('REMOTE_ADDR'); + + if ($proxy_ips) + { + foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) + { + if (($spoof = $this->server($header)) !== NULL) + { + // Some proxies typically list the whole chain of IP + // addresses through which the client has reached us. + // e.g. client_ip, proxy_ip1, proxy_ip2, etc. + sscanf($spoof, '%[^,]', $spoof); + + if ( ! $this->valid_ip($spoof)) + { + $spoof = NULL; + } + else + { + break; + } + } + } + + if ($spoof) + { + for ($i = 0, $c = count($proxy_ips); $i < $c; $i++) + { + // Check if we have an IP address or a subnet + if (strpos($proxy_ips[$i], '/') === FALSE) + { + // An IP address (and not a subnet) is specified. + // We can compare right away. + if ($proxy_ips[$i] === $this->ip_address) + { + $this->ip_address = $spoof; + break; + } + + continue; + } + + // We have a subnet ... now the heavy lifting begins + isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.'; + + // If the proxy entry doesn't match the IP protocol - skip it + if (strpos($proxy_ips[$i], $separator) === FALSE) + { + continue; + } + + // Convert the REMOTE_ADDR IP address to binary, if needed + if ( ! isset($ip, $sprintf)) + { + if ($separator === ':') + { + // Make sure we're have the "full" IPv6 format + $ip = explode(':', + str_replace('::', + str_repeat(':', 9 - substr_count($this->ip_address, ':')), + $this->ip_address + ) + ); + + for ($j = 0; $j < 8; $j++) + { + $ip[$j] = intval($ip[$j], 16); + } + + $sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b'; + } + else + { + $ip = explode('.', $this->ip_address); + $sprintf = '%08b%08b%08b%08b'; + } + + $ip = vsprintf($sprintf, $ip); + } + + // Split the netmask length off the network address + sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen); + + // Again, an IPv6 address is most likely in a compressed form + if ($separator === ':') + { + $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr)); + for ($j = 0; $j < 8; $j++) + { + $netaddr[$j] = intval($netaddr[$j], 16); + } + } + else + { + $netaddr = explode('.', $netaddr); + } + + // Convert to binary and finally compare + if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0) + { + $this->ip_address = $spoof; + break; + } + } + } + } + + if ( ! $this->valid_ip($this->ip_address)) + { + return $this->ip_address = '0.0.0.0'; + } + + return $this->ip_address; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @param string $ip IP address + * @param string $which IP protocol: 'ipv4' or 'ipv6' + * @return bool + */ + public function valid_ip($ip, $which = '') + { + switch (strtolower($which)) + { + case 'ipv4': + $which = FILTER_FLAG_IPV4; + break; + case 'ipv6': + $which = FILTER_FLAG_IPV6; + break; + default: + $which = NULL; + break; + } + + return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which); + } + + // -------------------------------------------------------------------- + + /** + * Fetch User Agent string + * + * @return string|null User Agent string or NULL if it doesn't exist + */ + public function user_agent($xss_clean = NULL) + { + return $this->_fetch_from_array($_SERVER, 'HTTP_USER_AGENT', $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Globals + * + * Internal method serving for the following purposes: + * + * - Unsets $_GET data, if query strings are not enabled + * - Cleans POST, COOKIE and SERVER data + * - Standardizes newline characters to PHP_EOL + * + * @return void + */ + protected function _sanitize_globals() + { + // Is $_GET data allowed? If not we'll set the $_GET to an empty array + if ($this->_allow_get_array === FALSE) + { + $_GET = array(); + } + elseif (is_array($_GET)) + { + foreach ($_GET as $key => $val) + { + $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + // Clean $_POST Data + if (is_array($_POST)) + { + foreach ($_POST as $key => $val) + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + // Clean $_COOKIE Data + if (is_array($_COOKIE)) + { + // Also get rid of specially treated cookies that might be set by a server + // or silly application, that are of no use to a CI application anyway + // but that when present will trip our 'Disallowed Key Characters' alarm + // http://www.ietf.org/rfc/rfc2109.txt + // note that the key names below are single quoted strings, and are not PHP variables + unset( + $_COOKIE['$Version'], + $_COOKIE['$Path'], + $_COOKIE['$Domain'] + ); + + foreach ($_COOKIE as $key => $val) + { + if (($cookie_key = $this->_clean_input_keys($key)) !== FALSE) + { + $_COOKIE[$cookie_key] = $this->_clean_input_data($val); + } + else + { + unset($_COOKIE[$key]); + } + } + } + + // Sanitize PHP_SELF + $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); + + log_message('debug', 'Global POST, GET and COOKIE data sanitized'); + } + + // -------------------------------------------------------------------- + + /** + * Clean Input Data + * + * Internal method that aids in escaping data and + * standardizing newline characters to PHP_EOL. + * + * @param string|string[] $str Input string(s) + * @return string + */ + protected function _clean_input_data($str) + { + if (is_array($str)) + { + $new_array = array(); + foreach (array_keys($str) as $key) + { + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($str[$key]); + } + return $new_array; + } + + /* We strip slashes if magic quotes is on to keep things consistent + + 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()) + { + $str = stripslashes($str); + } + + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) + { + $str = $this->uni->clean_string($str); + } + + // Remove control characters + $str = remove_invisible_characters($str, FALSE); + + // Standardize newlines if needed + if ($this->_standardize_newlines === TRUE) + { + return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Clean Keys + * + * Internal method that helps to prevent malicious users + * from trying to exploit keys we make sure that keys are + * only named with alpha-numeric text and a few other items. + * + * @param string $str Input string + * @param bool $fatal Whether to terminate script exection + * or to return FALSE if an invalid + * key is encountered + * @return string|bool + */ + protected function _clean_input_keys($str, $fatal = TRUE) + { + if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str)) + { + if ($fatal === TRUE) + { + return FALSE; + } + else + { + set_status_header(503); + echo 'Disallowed Key Characters.'; + exit(7); // EXIT_USER_INPUT + } + } + + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) + { + return $this->uni->clean_string($str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Request Headers + * + * @param bool $xss_clean Whether to apply XSS filtering + * @return array + */ + public function request_headers($xss_clean = FALSE) + { + // If header is already defined, return it immediately + if ( ! empty($this->headers)) + { + return $this->_fetch_from_array($this->headers, NULL, $xss_clean); + } + + // In Apache, you can simply call apache_request_headers() + if (function_exists('apache_request_headers')) + { + $this->headers = apache_request_headers(); + } + else + { + isset($_SERVER['CONTENT_TYPE']) && $this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE']; + + foreach ($_SERVER as $key => $val) + { + if (sscanf($key, 'HTTP_%s', $header) === 1) + { + // take SOME_HEADER and turn it into Some-Header + $header = str_replace('_', ' ', strtolower($header)); + $header = str_replace(' ', '-', ucwords($header)); + + $this->headers[$header] = $_SERVER[$key]; + } + } + } + + return $this->_fetch_from_array($this->headers, NULL, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Get Request Header + * + * Returns the value of a single member of the headers class member + * + * @param string $index Header name + * @param bool $xss_clean Whether to apply XSS filtering + * @return string|null The requested header on success or NULL on failure + */ + public function get_request_header($index, $xss_clean = FALSE) + { + static $headers; + + if ( ! isset($headers)) + { + empty($this->headers) && $this->request_headers(); + foreach ($this->headers as $key => $value) + { + $headers[strtolower($key)] = $value; + } + } + + $index = strtolower($index); + + if ( ! isset($headers[$index])) + { + return NULL; + } + + return ($xss_clean === TRUE) + ? $this->security->xss_clean($headers[$index]) + : $headers[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Is AJAX request? + * + * Test to see if a request contains the HTTP_X_REQUESTED_WITH header. + * + * @return bool + */ + public function is_ajax_request() + { + return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); + } + + // -------------------------------------------------------------------- + + /** + * Is CLI request? + * + * Test to see if a request was made from the command line. + * + * @deprecated 3.0.0 Use is_cli() instead + * @return bool + */ + public function is_cli_request() + { + return is_cli(); + } + + // -------------------------------------------------------------------- + + /** + * Get Request Method + * + * Return the request method + * + * @param bool $upper Whether to return in upper or lower case + * (default: FALSE) + * @return string + */ + public function method($upper = FALSE) + { + return ($upper) + ? strtoupper($this->server('REQUEST_METHOD')) + : strtolower($this->server('REQUEST_METHOD')); + } + + // ------------------------------------------------------------------------ + + /** + * Magic __get() + * + * Allows read access to protected properties + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + if ($name === 'raw_input_stream') + { + isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); + return $this->_raw_input_stream; + } + elseif ($name === 'ip_address') + { + return $this->ip_address; + } + } } - -/* End of file Input.php */ -/* Location: ./system/core/Input.php */ \ No newline at end of file diff --git a/system/core/Lang.php b/system/core/Lang.php old mode 100755 new mode 100644 index 8adaf29..2c8654d --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -1,161 +1,203 @@ -is_loaded, TRUE)) - { - return; - } - - $config =& get_config(); - - if ($idiom == '') - { - $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; - $idiom = ($deft_lang == '') ? 'english' : $deft_lang; - } - - // Determine where the language file is and load it - if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) - { - include($alt_path.'language/'.$idiom.'/'.$langfile); - } - else - { - $found = FALSE; - - foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) - { - if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) - { - include($package_path.'language/'.$idiom.'/'.$langfile); - $found = TRUE; - break; - } - } - - if ($found !== TRUE) - { - show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); - } - } - - - if ( ! isset($lang)) - { - log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); - return; - } - - if ($return == TRUE) - { - return $lang; - } - - $this->is_loaded[] = $langfile; - $this->language = array_merge($this->language, $lang); - unset($lang); - - log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a single line of text from the language array - * - * @access public - * @param string $line the language line - * @return string - */ - function line($line = '') - { - $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; - - // Because killer robots like unicorns! - if ($value === FALSE) - { - log_message('error', 'Could not find the language line "'.$line.'"'); - } - - return $value; - } + /** + * List of translations + * + * @var array + */ + public $language = array(); + + /** + * List of loaded language files + * + * @var array + */ + public $is_loaded = array(); + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + log_message('info', 'Language Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Load a language file + * + * @param mixed $langfile Language file name + * @param string $idiom Language name (english, etc.) + * @param bool $return Whether to return the loaded array of translations + * @param bool $add_suffix Whether to add suffix to $langfile + * @param string $alt_path Alternative path to look for the language file + * + * @return void|string[] Array containing translations, if $return is set to TRUE + */ + public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') + { + if (is_array($langfile)) + { + foreach ($langfile as $value) + { + $this->load($value, $idiom, $return, $add_suffix, $alt_path); + } + + return; + } + + $langfile = str_replace('.php', '', $langfile); + + if ($add_suffix === TRUE) + { + $langfile = preg_replace('/_lang$/', '', $langfile).'_lang'; + } + + $langfile .= '.php'; + + if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom)) + { + $config =& get_config(); + $idiom = empty($config['language']) ? 'english' : $config['language']; + } + + if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom) + { + return; + } + + // Load the base file, so any others found can override it + $basepath = BASEPATH.'language/'.$idiom.'/'.$langfile; + if (($found = file_exists($basepath)) === TRUE) + { + include($basepath); + } + + // Do we have an alternative path to look in? + if ($alt_path !== '') + { + $alt_path .= 'language/'.$idiom.'/'.$langfile; + if (file_exists($alt_path)) + { + include($alt_path); + $found = TRUE; + } + } + else + { + foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) + { + $package_path .= 'language/'.$idiom.'/'.$langfile; + if ($basepath !== $package_path && file_exists($package_path)) + { + include($package_path); + $found = TRUE; + break; + } + } + } + + if ($found !== TRUE) + { + show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); + } + + if ( ! isset($lang) OR ! is_array($lang)) + { + log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); + + if ($return === TRUE) + { + return array(); + } + return; + } + + if ($return === TRUE) + { + return $lang; + } + + $this->is_loaded[$langfile] = $idiom; + $this->language = array_merge($this->language, $lang); + + log_message('info', 'Language file loaded: language/'.$idiom.'/'.$langfile); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Language line + * + * Fetches a single line of text from the language array + * + * @param string $line Language line key + * @param bool $log_errors Whether to log an error message if the line is not found + * @return string Translation + */ + public function line($line, $log_errors = TRUE) + { + $value = isset($this->language[$line]) ? $this->language[$line] : FALSE; + + // Because killer robots like unicorns! + if ($value === FALSE && $log_errors === TRUE) + { + log_message('error', 'Could not find the language line "'.$line.'"'); + } + + return $value; + } } -// END Language Class - -/* End of file Lang.php */ -/* Location: ./system/core/Lang.php */ diff --git a/system/core/Loader.php b/system/core/Loader.php old mode 100755 new mode 100644 index 8371808..14888e4 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1,1249 +1,1415 @@ - 'unit', - 'user_agent' => 'agent'); - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - */ - public function __construct() - { - $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array(APPPATH, BASEPATH); - $this->_ci_helper_paths = array(APPPATH, BASEPATH); - $this->_ci_model_paths = array(APPPATH); - $this->_ci_view_paths = array(APPPATH.'views/' => TRUE); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Loader - * - * This method is called once in CI_Controller. - * - * @param array - * @return object - */ - public function initialize() - { - $this->_ci_classes = array(); - $this->_ci_loaded_files = array(); - $this->_ci_models = array(); - $this->_base_classes =& is_loaded(); - - $this->_ci_autoloader(); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Is Loaded - * - * A utility function to test if a class is in the self::$_ci_classes array. - * This function returns the object name if the class tested for is loaded, - * and returns FALSE if it isn't. - * - * It is mainly used in the form_helper -> _get_validation_object() - * - * @param string class being checked for - * @return mixed class object name on the CI SuperObject or FALSE - */ - public function is_loaded($class) - { - if (isset($this->_ci_classes[$class])) - { - return $this->_ci_classes[$class]; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @param string the name of the class - * @param mixed the optional parameters - * @param string an optional object name - * @return void - */ - public function library($library = '', $params = NULL, $object_name = NULL) - { - if (is_array($library)) - { - foreach ($library as $class) - { - $this->library($class, $params); - } - - return; - } - - if ($library == '' OR isset($this->_base_classes[$library])) - { - return FALSE; - } - - if ( ! is_null($params) && ! is_array($params)) - { - $params = NULL; - } - - $this->_ci_load_class($library, $params, $object_name); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @param string the name of the class - * @param string name for the model - * @param bool database connection - * @return void - */ - public function model($model, $name = '', $db_conn = FALSE) - { - if (is_array($model)) - { - foreach ($model as $babe) - { - $this->model($babe); - } - return; - } - - if ($model == '') - { - return; - } - - $path = ''; - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (($last_slash = strrpos($model, '/')) !== FALSE) - { - // The path is in front of the last slash - $path = substr($model, 0, $last_slash + 1); - - // And the model name behind it - $model = substr($model, $last_slash + 1); - } - - if ($name == '') - { - $name = $model; - } - - if (in_array($name, $this->_ci_models, TRUE)) - { - return; - } - - $CI =& get_instance(); - if (isset($CI->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } - - $model = strtolower($model); - - foreach ($this->_ci_model_paths as $mod_path) - { - if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) - { - continue; - } - - if ($db_conn !== FALSE AND ! class_exists('CI_DB')) - { - if ($db_conn === TRUE) - { - $db_conn = ''; - } - - $CI->load->database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('CI_Model')) - { - load_class('Model', 'core'); - } - - require_once($mod_path.'models/'.$path.$model.'.php'); - - $model = ucfirst($model); - - $CI->$name = new $model(); - - $this->_ci_models[] = $name; - return; - } - - // couldn't find the model - show_error('Unable to locate the model you have specified: '.$model); - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @param string the DB credentials - * @param bool whether to return the DB object - * @param bool whether to enable active record (this allows us to override the config setting) - * @return object - */ - public function database($params = '', $return = FALSE, $active_record = NULL) - { - // Grab the super object - $CI =& get_instance(); - - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB.php'); - - if ($return === TRUE) - { - return DB($params, $active_record); - } - - // Initialize the db variable. Needed to prevent - // reference errors with some configurations - $CI->db = ''; - - // Load the DB class - $CI->db =& DB($params, $active_record); - } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @return string - */ - public function dbutil() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - // for backwards compatibility, load dbforge so we can extend dbutils off it - // this use is deprecated and strongly discouraged - $CI->load->dbforge(); - - require_once(BASEPATH.'database/DB_utility.php'); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php'); - $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - - $CI->dbutil = new $class(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Database Forge Class - * - * @return string - */ - public function dbforge() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - require_once(BASEPATH.'database/DB_forge.php'); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php'); - $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; - - $CI->dbforge = new $class(); - } - - // -------------------------------------------------------------------- - - /** - * Load View - * - * This function is used to load a "view" file. It has three parameters: - * - * 1. The name of the "view" file to be included. - * 2. An associative array of data to be extracted for use in the view. - * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. - * - * @param string - * @param array - * @param bool - * @return void - */ - public function view($view, $vars = array(), $return = FALSE) - { - return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Load File - * - * This is a generic file loader - * - * @param string - * @param bool - * @return string - */ - public function file($path, $return = FALSE) - { - return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Set Variables - * - * Once variables are set they become available within - * the controller class and its "view" files. - * - * @param array - * @param string - * @return void - */ - public function vars($vars = array(), $val = '') - { - if ($val != '' AND is_string($vars)) - { - $vars = array($vars => $val); - } - - $vars = $this->_ci_object_to_array($vars); - - if (is_array($vars) AND count($vars) > 0) - { - foreach ($vars as $key => $val) - { - $this->_ci_cached_vars[$key] = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Get Variable - * - * Check if a variable is set and retrieve it. - * - * @param array - * @return void - */ - public function get_var($key) - { - return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @param mixed - * @return void - */ - public function helper($helpers = array()) - { - foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) - { - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php'; - - // Is this a helper extension request? - if (file_exists($ext_helper)) - { - $base_helper = BASEPATH.'helpers/'.$helper.'.php'; - - if ( ! file_exists($base_helper)) - { - show_error('Unable to load the requested file: helpers/'.$helper.'.php'); - } - - include_once($ext_helper); - include_once($base_helper); - - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); - continue; - } - - // Try to load the helper - foreach ($this->_ci_helper_paths as $path) - { - if (file_exists($path.'helpers/'.$helper.'.php')) - { - include_once($path.'helpers/'.$helper.'.php'); - - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); - break; - } - } - - // unable to load the helper - if ( ! isset($this->_ci_helpers[$helper])) - { - show_error('Unable to load the requested file: helpers/'.$helper.'.php'); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @param array - * @return void - */ - public function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @param array - * @param string - * @return void - */ - public function language($file = array(), $lang = '') - { - $CI =& get_instance(); - - if ( ! is_array($file)) - { - $file = array($file); - } - - foreach ($file as $langfile) - { - $CI->lang->load($langfile, $lang); - } - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @param string - * @param bool - * @param bool - * @return void - */ - public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Driver - * - * Loads a driver library - * - * @param string the name of the class - * @param mixed the optional parameters - * @param string an optional object name - * @return void - */ - public function driver($library = '', $params = NULL, $object_name = NULL) - { - if ( ! class_exists('CI_Driver_Library')) - { - // we aren't instantiating an object here, that'll be done by the Library itself - require BASEPATH.'libraries/Driver.php'; - } - - if ($library == '') - { - return FALSE; - } - - // We can save the loader some time since Drivers will *always* be in a subfolder, - // and typically identically named to the library - if ( ! strpos($library, '/')) - { - $library = ucfirst($library).'/'.$library; - } - - return $this->library($library, $params, $object_name); - } - - // -------------------------------------------------------------------- - - /** - * Add Package Path - * - * Prepends a parent path to the library, model, helper, and config path arrays - * - * @param string - * @param boolean - * @return void - */ - public function add_package_path($path, $view_cascade=TRUE) - { - $path = rtrim($path, '/').'/'; - - array_unshift($this->_ci_library_paths, $path); - array_unshift($this->_ci_model_paths, $path); - array_unshift($this->_ci_helper_paths, $path); - - $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; - - // Add config file path - $config =& $this->_ci_get_component('config'); - array_unshift($config->_config_paths, $path); - } - - // -------------------------------------------------------------------- - - /** - * Get Package Paths - * - * Return a list of all package paths, by default it will ignore BASEPATH. - * - * @param string - * @return void - */ - public function get_package_paths($include_base = FALSE) - { - return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths; - } - - // -------------------------------------------------------------------- - - /** - * Remove Package Path - * - * Remove a path from the library, model, and helper path arrays if it exists - * If no path is provided, the most recently added path is removed. - * - * @param type - * @param bool - * @return type - */ - public function remove_package_path($path = '', $remove_config_path = TRUE) - { - $config =& $this->_ci_get_component('config'); - - if ($path == '') - { - $void = array_shift($this->_ci_library_paths); - $void = array_shift($this->_ci_model_paths); - $void = array_shift($this->_ci_helper_paths); - $void = array_shift($this->_ci_view_paths); - $void = array_shift($config->_config_paths); - } - else - { - $path = rtrim($path, '/').'/'; - foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) - { - if (($key = array_search($path, $this->{$var})) !== FALSE) - { - unset($this->{$var}[$key]); - } - } - - if (isset($this->_ci_view_paths[$path.'views/'])) - { - unset($this->_ci_view_paths[$path.'views/']); - } - - if (($key = array_search($path, $config->_config_paths)) !== FALSE) - { - unset($config->_config_paths[$key]); - } - } - - // make sure the application default paths are still in the array - $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); - $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); - $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); - $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE)); - $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); - } - - // -------------------------------------------------------------------- - - /** - * Loader - * - * This function is used to load views and files. - * Variables are prefixed with _ci_ to avoid symbol collision with - * variables made available to view files - * - * @param array - * @return void - */ - protected function _ci_load($_ci_data) - { - // Set the default data variables - foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) - { - $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; - } - - $file_exists = FALSE; - - // Set the path to the requested file - if ($_ci_path != '') - { - $_ci_x = explode('/', $_ci_path); - $_ci_file = end($_ci_x); - } - else - { - $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); - $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view; - - foreach ($this->_ci_view_paths as $view_file => $cascade) - { - if (file_exists($view_file.$_ci_file)) - { - $_ci_path = $view_file.$_ci_file; - $file_exists = TRUE; - break; - } - - if ( ! $cascade) - { - break; - } - } - } - - if ( ! $file_exists && ! file_exists($_ci_path)) - { - show_error('Unable to load the requested file: '.$_ci_file); - } - - // This allows anything loaded using $this->load (views, files, etc.) - // to become accessible from within the Controller and Model functions. - - $_ci_CI =& get_instance(); - foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) - { - if ( ! isset($this->$_ci_key)) - { - $this->$_ci_key =& $_ci_CI->$_ci_key; - } - } - - /* - * Extract and cache variables - * - * You can either set variables using the dedicated $this->load_vars() - * function or via the second parameter of this function. We'll merge - * the two types and cache them so that views that are embedded within - * other views can have access to these variables. - */ - if (is_array($_ci_vars)) - { - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); - } - extract($this->_ci_cached_vars); - - /* - * Buffer the output - * - * We buffer the output for two reasons: - * 1. Speed. You get a significant speed boost. - * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we - * can intercept the content right before it's sent to - * the browser and then stop the timer it won't be accurate. - */ - ob_start(); - - // If the PHP installation does not support short tags we'll - // do a little string replacement, changing the short tags - // to standard PHP echo statements. - - if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) - { - echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' $this->_ci_ob_level + 1) - { - ob_end_flush(); - } - else - { - $_ci_CI->output->append_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @param string the item that is being loaded - * @param mixed any additional parameters - * @param string an optional object name - * @return void - */ - protected function _ci_load_class($class, $params = NULL, $object_name = NULL) - { - // Get the class name, and while we're at it trim any slashes. - // The directory path can be included as part of the class name, - // but we don't want a leading slash - $class = str_replace('.php', '', trim($class, '/')); - - // Was the path included with the class name? - // We look for a slash to determine this - $subdir = ''; - if (($last_slash = strrpos($class, '/')) !== FALSE) - { - // Extract the path - $subdir = substr($class, 0, $last_slash + 1); - - // Get the filename from the path - $class = substr($class, $last_slash + 1); - } - - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) - { - $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php'; - - // Is this a class extension request? - if (file_exists($subclass)) - { - $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php'; - - if ( ! file_exists($baseclass)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($subclass, $this->_ci_loaded_files)) - { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ( ! is_null($object_name)) - { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); - } - } - - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include_once($baseclass); - include_once($subclass); - $this->_ci_loaded_files[] = $subclass; - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); - } - - // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - foreach ($this->_ci_library_paths as $path) - { - $filepath = $path.'libraries/'.$subdir.$class.'.php'; - - // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) - { - continue; - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($filepath, $this->_ci_loaded_files)) - { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ( ! is_null($object_name)) - { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, '', $params, $object_name); - } - } - - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include_once($filepath); - $this->_ci_loaded_files[] = $filepath; - return $this->_ci_init_class($class, '', $params, $object_name); - } - - } // END FOREACH - - // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? - if ($subdir == '') - { - $path = strtolower($class).'/'.$class; - return $this->_ci_load_class($path, $params); - } - - // If we got this far we were unable to find the requested class. - // We do not issue errors if the load call failed due to a duplicate request - if ($is_duplicate == FALSE) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @param string - * @param string - * @param bool - * @param string an optional object name - * @return null - */ - protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) - { - // Is there an associated config file for this class? Note: these should always be lowercase - if ($config === NULL) - { - // Fetch the config paths containing any package paths - $config_component = $this->_ci_get_component('config'); - - if (is_array($config_component->_config_paths)) - { - // Break on the first found file, thus package files - // are not overridden by default paths - foreach ($config_component->_config_paths as $path) - { - // We test for both uppercase and lowercase, for servers that - // are case-sensitive with regard to file names. Check for environment - // first, global next - if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) - { - include($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); - break; - } - elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) - { - include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); - break; - } - elseif (file_exists($path .'config/'.strtolower($class).'.php')) - { - include($path .'config/'.strtolower($class).'.php'); - break; - } - elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php')) - { - include($path .'config/'.ucfirst(strtolower($class)).'.php'); - break; - } - } - } - } - - if ($prefix == '') - { - if (class_exists('CI_'.$class)) - { - $name = 'CI_'.$class; - } - elseif (class_exists(config_item('subclass_prefix').$class)) - { - $name = config_item('subclass_prefix').$class; - } - else - { - $name = $class; - } - } - else - { - $name = $prefix.$class; - } - - // Is the class name valid? - if ( ! class_exists($name)) - { - log_message('error', "Non-existent class: ".$name); - show_error("Non-existent class: ".$class); - } - - // Set the variable name we will assign the class to - // Was a custom class name supplied? If so we'll use it - $class = strtolower($class); - - if (is_null($object_name)) - { - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - } - else - { - $classvar = $object_name; - } - - // Save the class name and object name - $this->_ci_classes[$class] = $classvar; - - // Instantiate the class - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Autoloader - * - * The config/autoload.php file contains an array that permits sub-systems, - * libraries, and helpers to be loaded automatically. - * - * @param array - * @return void - */ - private function _ci_autoloader() - { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); - } - else - { - include(APPPATH.'config/autoload.php'); - } - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Autoload packages - if (isset($autoload['packages'])) - { - foreach ($autoload['packages'] as $package_path) - { - $this->add_package_path($package_path); - } - } - - // Load any custom config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Autoload helpers and languages - foreach (array('helper', 'language') as $type) - { - if (isset($autoload[$type]) AND count($autoload[$type]) > 0) - { - $this->$type($autoload[$type]); - } - } - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries']) AND isset($autoload['core'])) - { - $autoload['libraries'] = $autoload['core']; - } - - // Load libraries - if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) - { - // Load the database driver. - if (in_array('database', $autoload['libraries'])) - { - $this->database(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - - // Autoload models - if (isset($autoload['model'])) - { - $this->model($autoload['model']); - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @param object - * @return array - */ - protected function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Get a reference to a specific library or model - * - * @param string - * @return bool - */ - protected function &_ci_get_component($component) - { - $CI =& get_instance(); - return $CI->$component; - } - - // -------------------------------------------------------------------- - - /** - * Prep filename - * - * This function preps the name of various items to make loading them more reliable. - * - * @param mixed - * @param string - * @return array - */ - protected function _ci_prep_filename($filename, $extension) - { - if ( ! is_array($filename)) - { - return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension)); - } - else - { - foreach ($filename as $key => $val) - { - $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension); - } - - return $filename; - } - } + // All these are set automatically. Don't mess with them. + /** + * Nesting level of the output buffering mechanism + * + * @var int + */ + protected $_ci_ob_level; + + /** + * List of paths to load views from + * + * @var array + */ + protected $_ci_view_paths = array(VIEWPATH => TRUE); + + /** + * List of paths to load libraries from + * + * @var array + */ + protected $_ci_library_paths = array(APPPATH, BASEPATH); + + /** + * List of paths to load models from + * + * @var array + */ + protected $_ci_model_paths = array(APPPATH); + + /** + * List of paths to load helpers from + * + * @var array + */ + protected $_ci_helper_paths = array(APPPATH, BASEPATH); + + /** + * List of cached variables + * + * @var array + */ + protected $_ci_cached_vars = array(); + + /** + * List of loaded classes + * + * @var array + */ + protected $_ci_classes = array(); + + /** + * List of loaded models + * + * @var array + */ + protected $_ci_models = array(); + + /** + * List of loaded helpers + * + * @var array + */ + protected $_ci_helpers = array(); + + /** + * List of class name mappings + * + * @var array + */ + protected $_ci_varmap = array( + 'unit_test' => 'unit', + 'user_agent' => 'agent' + ); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Sets component load paths, gets the initial output buffering level. + * + * @return void + */ + public function __construct() + { + $this->_ci_ob_level = ob_get_level(); + $this->_ci_classes =& is_loaded(); + + log_message('info', 'Loader Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initializer + * + * @todo Figure out a way to move this to the constructor + * without breaking *package_path*() methods. + * @uses CI_Loader::_ci_autoloader() + * @used-by CI_Controller::__construct() + * @return void + */ + public function initialize() + { + $this->_ci_autoloader(); + } + + // -------------------------------------------------------------------- + + /** + * Is Loaded + * + * A utility method to test if a class is in the self::$_ci_classes array. + * + * @used-by Mainly used by Form Helper function _get_validation_object(). + * + * @param string $class Class name to check for + * @return string|bool Class object name if loaded or FALSE + */ + public function is_loaded($class) + { + return array_search(ucfirst($class), $this->_ci_classes, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Library Loader + * + * Loads and instantiates libraries. + * Designed to be called from application controllers. + * + * @param mixed $library Library name + * @param array $params Optional parameters to pass to the library class constructor + * @param string $object_name An optional object name to assign to + * @return object + */ + public function library($library, $params = NULL, $object_name = NULL) + { + if (empty($library)) + { + return $this; + } + elseif (is_array($library)) + { + foreach ($library as $key => $value) + { + if (is_int($key)) + { + $this->library($value, $params); + } + else + { + $this->library($key, $params, $value); + } + } + + return $this; + } + + if ($params !== NULL && ! is_array($params)) + { + $params = NULL; + } + + $this->_ci_load_library($library, $params, $object_name); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * Loads and instantiates models. + * + * @param mixed $model Model name + * @param string $name An optional object name to assign to + * @param bool $db_conn An optional database connection configuration to initialize + * @return object + */ + public function model($model, $name = '', $db_conn = FALSE) + { + if (empty($model)) + { + return $this; + } + elseif (is_array($model)) + { + foreach ($model as $key => $value) + { + is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn); + } + + return $this; + } + + $path = ''; + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (($last_slash = strrpos($model, '/')) !== FALSE) + { + // The path is in front of the last slash + $path = substr($model, 0, ++$last_slash); + + // And the model name behind it + $model = substr($model, $last_slash); + } + + if (empty($name)) + { + $name = $model; + } + + if (in_array($name, $this->_ci_models, TRUE)) + { + return $this; + } + + $CI =& get_instance(); + if (isset($CI->$name)) + { + throw new RuntimeException('The model name you are loading is the name of a resource that is already being used: '.$name); + } + + if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE)) + { + if ($db_conn === TRUE) + { + $db_conn = ''; + } + + $this->database($db_conn, FALSE, TRUE); + } + + // Note: All of the code under this condition used to be just: + // + // load_class('Model', 'core'); + // + // However, load_class() instantiates classes + // to cache them for later use and that prevents + // MY_Model from being an abstract class and is + // sub-optimal otherwise anyway. + if ( ! class_exists('CI_Model', FALSE)) + { + $app_path = APPPATH.'core'.DIRECTORY_SEPARATOR; + if (file_exists($app_path.'Model.php')) + { + require_once($app_path.'Model.php'); + if ( ! class_exists('CI_Model', FALSE)) + { + throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); + } + + log_message('info', 'CI_Model class loaded'); + } + elseif ( ! class_exists('CI_Model', FALSE)) + { + require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php'); + } + + $class = config_item('subclass_prefix').'Model'; + if (file_exists($app_path.$class.'.php')) + { + require_once($app_path.$class.'.php'); + if ( ! class_exists($class, FALSE)) + { + throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); + } + + log_message('info', config_item('subclass_prefix').'Model class loaded'); + } + } + + $model = ucfirst($model); + if ( ! class_exists($model, FALSE)) + { + foreach ($this->_ci_model_paths as $mod_path) + { + if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) + { + continue; + } + + require_once($mod_path.'models/'.$path.$model.'.php'); + if ( ! class_exists($model, FALSE)) + { + throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model); + } + + break; + } + + if ( ! class_exists($model, FALSE)) + { + throw new RuntimeException('Unable to locate the model you have specified: '.$model); + } + } + elseif ( ! is_subclass_of($model, 'CI_Model')) + { + throw new RuntimeException("Class ".$model." already exists and doesn't extend CI_Model"); + } + + $this->_ci_models[] = $name; + $model = new $model(); + $CI->$name = $model; + log_message('info', 'Model "'.get_class($model).'" initialized'); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @param mixed $params Database configuration options + * @param bool $return Whether to return the database object + * @param bool $query_builder Whether to enable Query Builder + * (overrides the configuration setting) + * + * @return object|bool Database object if $return is set to TRUE, + * FALSE on failure, CI_Loader instance in any other case + */ + public function database($params = '', $return = FALSE, $query_builder = NULL) + { + // Grab the super object + $CI =& get_instance(); + + // Do we even need to load the database class? + if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id)) + { + return FALSE; + } + + require_once(BASEPATH.'database/DB.php'); + + if ($return === TRUE) + { + return DB($params, $query_builder); + } + + // Initialize the db variable. Needed to prevent + // reference errors with some configurations + $CI->db = ''; + + // Load the DB class + $CI->db =& DB($params, $query_builder); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Utilities Class + * + * @param object $db Database object + * @param bool $return Whether to return the DB Utilities class object or not + * @return object + */ + public function dbutil($db = NULL, $return = FALSE) + { + $CI =& get_instance(); + + if ( ! is_object($db) OR ! ($db instanceof CI_DB)) + { + class_exists('CI_DB', FALSE) OR $this->database(); + $db =& $CI->db; + } + + require_once(BASEPATH.'database/DB_utility.php'); + require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php'); + $class = 'CI_DB_'.$db->dbdriver.'_utility'; + + if ($return === TRUE) + { + return new $class($db); + } + + $CI->dbutil = new $class($db); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Forge Class + * + * @param object $db Database object + * @param bool $return Whether to return the DB Forge class object or not + * @return object + */ + public function dbforge($db = NULL, $return = FALSE) + { + $CI =& get_instance(); + if ( ! is_object($db) OR ! ($db instanceof CI_DB)) + { + class_exists('CI_DB', FALSE) OR $this->database(); + $db =& $CI->db; + } + + require_once(BASEPATH.'database/DB_forge.php'); + require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php'); + + if ( ! empty($db->subdriver)) + { + $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php'; + if (file_exists($driver_path)) + { + require_once($driver_path); + $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge'; + } + } + else + { + $class = 'CI_DB_'.$db->dbdriver.'_forge'; + } + + if ($return === TRUE) + { + return new $class($db); + } + + $CI->dbforge = new $class($db); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * View Loader + * + * Loads "view" files. + * + * @param string $view View name + * @param array $vars An associative array of data + * to be extracted for use in the view + * @param bool $return Whether to return the view output + * or leave it to the Output class + * @return object|string + */ + public function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Generic File Loader + * + * @param string $path File path + * @param bool $return Whether to return the file output + * @return object|string + */ + public function file($path, $return = FALSE) + { + return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become available within + * the controller class and its "view" files. + * + * @param array|object|string $vars + * An associative array or object containing values + * to be set, or a value's name if string + * @param string $val Value to set, only used if $vars is a string + * @return object + */ + public function vars($vars, $val = '') + { + $vars = is_string($vars) + ? array($vars => $val) + : $this->_ci_prepare_view_vars($vars); + + foreach ($vars as $key => $val) + { + $this->_ci_cached_vars[$key] = $val; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Clear Cached Variables + * + * Clears the cached variables. + * + * @return CI_Loader + */ + public function clear_vars() + { + $this->_ci_cached_vars = array(); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Variable + * + * Check if a variable is set and retrieve it. + * + * @param string $key Variable name + * @return mixed The variable or NULL if not found + */ + public function get_var($key) + { + return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Get Variables + * + * Retrieves all loaded variables. + * + * @return array + */ + public function get_vars() + { + return $this->_ci_cached_vars; + } + + // -------------------------------------------------------------------- + + /** + * Helper Loader + * + * @param string|string[] $helpers Helper name(s) + * @return object + */ + public function helper($helpers = array()) + { + is_array($helpers) OR $helpers = array($helpers); + foreach ($helpers as &$helper) + { + $filename = basename($helper); + $filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename)); + $filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper'; + $helper = $filepath.$filename; + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + // Is this a helper extension request? + $ext_helper = config_item('subclass_prefix').$filename; + $ext_loaded = FALSE; + foreach ($this->_ci_helper_paths as $path) + { + if (file_exists($path.'helpers/'.$ext_helper.'.php')) + { + include_once($path.'helpers/'.$ext_helper.'.php'); + $ext_loaded = TRUE; + } + } + + // If we have loaded extensions - check if the base one is here + if ($ext_loaded === TRUE) + { + $base_helper = BASEPATH.'helpers/'.$helper.'.php'; + if ( ! file_exists($base_helper)) + { + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); + } + + include_once($base_helper); + $this->_ci_helpers[$helper] = TRUE; + log_message('info', 'Helper loaded: '.$helper); + continue; + } + + // No extensions found ... try loading regular helpers and/or overrides + foreach ($this->_ci_helper_paths as $path) + { + if (file_exists($path.'helpers/'.$helper.'.php')) + { + include_once($path.'helpers/'.$helper.'.php'); + + $this->_ci_helpers[$helper] = TRUE; + log_message('info', 'Helper loaded: '.$helper); + break; + } + } + + // unable to load the helper + if ( ! isset($this->_ci_helpers[$helper])) + { + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * An alias for the helper() method in case the developer has + * written the plural form of it. + * + * @uses CI_Loader::helper() + * @param string|string[] $helpers Helper name(s) + * @return object + */ + public function helpers($helpers = array()) + { + return $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Language Loader + * + * Loads language files. + * + * @param string|string[] $files List of language file names to load + * @param string Language name + * @return object + */ + public function language($files, $lang = '') + { + get_instance()->lang->load($files, $lang); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Config Loader + * + * Loads a config file (an alias for CI_Config::load()). + * + * @uses CI_Config::load() + * @param string $file Configuration file name + * @param bool $use_sections Whether configuration values should be loaded into their own section + * @param bool $fail_gracefully Whether to just return FALSE or display an error message + * @return bool TRUE if the file was loaded correctly or FALSE on failure + */ + public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) + { + return get_instance()->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Driver Loader + * + * Loads a driver library. + * + * @param string|string[] $library Driver name(s) + * @param array $params Optional parameters to pass to the driver + * @param string $object_name An optional object name to assign to + * + * @return object|bool Object or FALSE on failure if $library is a string + * and $object_name is set. CI_Loader instance otherwise. + */ + public function driver($library, $params = NULL, $object_name = NULL) + { + if (is_array($library)) + { + foreach ($library as $key => $value) + { + if (is_int($key)) + { + $this->driver($value, $params); + } + else + { + $this->driver($key, $params, $value); + } + } + + return $this; + } + elseif (empty($library)) + { + return FALSE; + } + + if ( ! class_exists('CI_Driver_Library', FALSE)) + { + // We aren't instantiating an object here, just making the base class available + require BASEPATH.'libraries/Driver.php'; + } + + // We can save the loader some time since Drivers will *always* be in a subfolder, + // and typically identically named to the library + if ( ! strpos($library, '/')) + { + $library = ucfirst($library).'/'.$library; + } + + return $this->library($library, $params, $object_name); + } + + // -------------------------------------------------------------------- + + /** + * Add Package Path + * + * Prepends a parent path to the library, model, helper and config + * path arrays. + * + * @see CI_Loader::$_ci_library_paths + * @see CI_Loader::$_ci_model_paths + * @see CI_Loader::$_ci_helper_paths + * @see CI_Config::$_config_paths + * + * @param string $path Path to add + * @param bool $view_cascade (default: TRUE) + * @return object + */ + public function add_package_path($path, $view_cascade = TRUE) + { + $path = rtrim($path, '/').'/'; + + array_unshift($this->_ci_library_paths, $path); + array_unshift($this->_ci_model_paths, $path); + array_unshift($this->_ci_helper_paths, $path); + + $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; + + // Add config file path + $config =& $this->_ci_get_component('config'); + $config->_config_paths[] = $path; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Package Paths + * + * Return a list of all package paths. + * + * @param bool $include_base Whether to include BASEPATH (default: FALSE) + * @return array + */ + public function get_package_paths($include_base = FALSE) + { + return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; + } + + // -------------------------------------------------------------------- + + /** + * Remove Package Path + * + * Remove a path from the library, model, helper and/or config + * path arrays if it exists. If no path is provided, the most recently + * added path will be removed removed. + * + * @param string $path Path to remove + * @return object + */ + public function remove_package_path($path = '') + { + $config =& $this->_ci_get_component('config'); + + if ($path === '') + { + array_shift($this->_ci_library_paths); + array_shift($this->_ci_model_paths); + array_shift($this->_ci_helper_paths); + array_shift($this->_ci_view_paths); + array_pop($config->_config_paths); + } + else + { + $path = rtrim($path, '/').'/'; + foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) + { + if (($key = array_search($path, $this->{$var})) !== FALSE) + { + unset($this->{$var}[$key]); + } + } + + if (isset($this->_ci_view_paths[$path.'views/'])) + { + unset($this->_ci_view_paths[$path.'views/']); + } + + if (($key = array_search($path, $config->_config_paths)) !== FALSE) + { + unset($config->_config_paths[$key]); + } + } + + // make sure the application default paths are still in the array + $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); + $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); + $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); + $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE)); + $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Data Loader + * + * Used to load views and files. + * + * Variables are prefixed with _ci_ to avoid symbol collision with + * variables made available to view files. + * + * @used-by CI_Loader::view() + * @used-by CI_Loader::file() + * @param array $_ci_data Data to load + * @return object + */ + protected function _ci_load($_ci_data) + { + // Set the default data variables + foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) + { + $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE; + } + + $file_exists = FALSE; + + // Set the path to the requested file + if (is_string($_ci_path) && $_ci_path !== '') + { + $_ci_x = explode('/', $_ci_path); + $_ci_file = end($_ci_x); + } + else + { + $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); + $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; + + foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) + { + if (file_exists($_ci_view_file.$_ci_file)) + { + $_ci_path = $_ci_view_file.$_ci_file; + $file_exists = TRUE; + break; + } + + if ( ! $cascade) + { + break; + } + } + } + + if ( ! $file_exists && ! file_exists($_ci_path)) + { + show_error('Unable to load the requested file: '.$_ci_file); + } + + // This allows anything loaded using $this->load (views, files, etc.) + // to become accessible from within the Controller and Model functions. + $_ci_CI =& get_instance(); + foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) + { + if ( ! isset($this->$_ci_key)) + { + $this->$_ci_key =& $_ci_CI->$_ci_key; + } + } + + /* + * Extract and cache variables + * + * You can either set variables using the dedicated $this->load->vars() + * function or via the second parameter of this function. We'll merge + * the two types and cache them so that views that are embedded within + * other views can have access to these variables. + */ + empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); + extract($this->_ci_cached_vars); + + /* + * Buffer the output + * + * We buffer the output for two reasons: + * 1. Speed. You get a significant speed boost. + * 2. So that the final rendered template can be post-processed by + * the output class. Why do we need post processing? For one thing, + * in order to show the elapsed page load time. Unless we can + * intercept the content right before it's sent to the browser and + * then stop the timer it won't be accurate. + */ + ob_start(); + + // If the PHP installation does not support short tags we'll + // do a little string replacement, changing the short tags + // to standard PHP echo statements. + if ( ! is_php('5.4') && ! ini_get('short_open_tag') && config_item('rewrite_short_tags') === TRUE) + { + echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace(' $this->_ci_ob_level + 1) + { + ob_end_flush(); + } + else + { + $_ci_CI->output->append_output(ob_get_contents()); + @ob_end_clean(); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Library Loader + * + * @used-by CI_Loader::library() + * @uses CI_Loader::_ci_init_library() + * + * @param string $class Class name to load + * @param mixed $params Optional parameters to pass to the class constructor + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_load_library($class, $params = NULL, $object_name = NULL) + { + // Get the class name, and while we're at it trim any slashes. + // The directory path can be included as part of the class name, + // but we don't want a leading slash + $class = str_replace('.php', '', trim($class, '/')); + + // Was the path included with the class name? + // We look for a slash to determine this + if (($last_slash = strrpos($class, '/')) !== FALSE) + { + // Extract the path + $subdir = substr($class, 0, ++$last_slash); + + // Get the filename from the path + $class = substr($class, $last_slash); + } + else + { + $subdir = ''; + } + + $class = ucfirst($class); + + // Is this a stock library? There are a few special conditions if so ... + if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php')) + { + return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); + } + + // Safety: Was the class already loaded by a previous call? + if (class_exists($class, FALSE)) + { + $property = $object_name; + if (empty($property)) + { + $property = strtolower($class); + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; + } + + $CI =& get_instance(); + if (isset($CI->$property)) + { + log_message('debug', $class.' class already loaded. Second attempt ignored.'); + return; + } + + return $this->_ci_init_library($class, '', $params, $object_name); + } + + // Let's search for the requested library file and load it. + foreach ($this->_ci_library_paths as $path) + { + // BASEPATH has already been checked for + if ($path === BASEPATH) + { + continue; + } + + $filepath = $path.'libraries/'.$subdir.$class.'.php'; + // Does the file exist? No? Bummer... + if ( ! file_exists($filepath)) + { + continue; + } + + include_once($filepath); + return $this->_ci_init_library($class, '', $params, $object_name); + } + + // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? + if ($subdir === '') + { + return $this->_ci_load_library($class.'/'.$class, $params, $object_name); + } + + // If we got this far we were unable to find the requested class. + log_message('error', 'Unable to load the requested class: '.$class); + show_error('Unable to load the requested class: '.$class); + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Stock Library Loader + * + * @used-by CI_Loader::_ci_load_library() + * @uses CI_Loader::_ci_init_library() + * + * @param string $library_name Library name to load + * @param string $file_path Path to the library filename, relative to libraries/ + * @param mixed $params Optional parameters to pass to the class constructor + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_load_stock_library($library_name, $file_path, $params, $object_name) + { + $prefix = 'CI_'; + + if (class_exists($prefix.$library_name, FALSE)) + { + if (class_exists(config_item('subclass_prefix').$library_name, FALSE)) + { + $prefix = config_item('subclass_prefix'); + } + + $property = $object_name; + if (empty($property)) + { + $property = strtolower($library_name); + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; + } + + $CI =& get_instance(); + if ( ! isset($CI->$property)) + { + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); + return; + } + + $paths = $this->_ci_library_paths; + array_pop($paths); // BASEPATH + array_pop($paths); // APPPATH (needs to be the first path checked) + array_unshift($paths, APPPATH); + + foreach ($paths as $path) + { + if (file_exists($path = $path.'libraries/'.$file_path.$library_name.'.php')) + { + // Override + include_once($path); + if (class_exists($prefix.$library_name, FALSE)) + { + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); + } + } + + include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); + + // Check for extensions + $subclass = config_item('subclass_prefix').$library_name; + foreach ($paths as $path) + { + if (file_exists($path = $path.'libraries/'.$file_path.$subclass.'.php')) + { + include_once($path); + if (class_exists($subclass, FALSE)) + { + $prefix = config_item('subclass_prefix'); + break; + } + + log_message('debug', $path.' exists, but does not declare '.$subclass); + } + } + + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Library Instantiator + * + * @used-by CI_Loader::_ci_load_stock_library() + * @used-by CI_Loader::_ci_load_library() + * + * @param string $class Class name + * @param string $prefix Class name prefix + * @param array|null|bool $config Optional configuration to pass to the class constructor: + * FALSE to skip; + * NULL to search in config paths; + * array containing configuration data + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_init_library($class, $prefix, $config = FALSE, $object_name = NULL) + { + // Is there an associated config file for this class? Note: these should always be lowercase + if ($config === NULL) + { + // Fetch the config paths containing any package paths + $config_component = $this->_ci_get_component('config'); + + if (is_array($config_component->_config_paths)) + { + $found = FALSE; + foreach ($config_component->_config_paths as $path) + { + // We test for both uppercase and lowercase, for servers that + // are case-sensitive with regard to file names. Load global first, + // override with environment next + if (file_exists($path.'config/'.strtolower($class).'.php')) + { + include($path.'config/'.strtolower($class).'.php'); + $found = TRUE; + } + elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php')) + { + include($path.'config/'.ucfirst(strtolower($class)).'.php'); + $found = TRUE; + } + + if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) + { + include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); + $found = TRUE; + } + elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) + { + include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); + $found = TRUE; + } + + // Break on the first found configuration, thus package + // files are not overridden by default paths + if ($found === TRUE) + { + break; + } + } + } + } + + $class_name = $prefix.$class; + + // Is the class name valid? + if ( ! class_exists($class_name, FALSE)) + { + log_message('error', 'Non-existent class: '.$class_name); + show_error('Non-existent class: '.$class_name); + } + + // Set the variable name we will assign the class to + // Was a custom class name supplied? If so we'll use it + if (empty($object_name)) + { + $object_name = strtolower($class); + if (isset($this->_ci_varmap[$object_name])) + { + $object_name = $this->_ci_varmap[$object_name]; + } + } + + // Don't overwrite existing properties + $CI =& get_instance(); + if (isset($CI->$object_name)) + { + if ($CI->$object_name instanceof $class_name) + { + log_message('debug', $class_name." has already been instantiated as '".$object_name."'. Second attempt aborted."); + return; + } + + show_error("Resource '".$object_name."' already exists and is not a ".$class_name." instance."); + } + + // Save the class name and object name + $this->_ci_classes[$object_name] = $class; + + // Instantiate the class + $CI->$object_name = isset($config) + ? new $class_name($config) + : new $class_name(); + } + + // -------------------------------------------------------------------- + + /** + * CI Autoloader + * + * Loads component listed in the config/autoload.php file. + * + * @used-by CI_Loader::initialize() + * @return void + */ + protected function _ci_autoloader() + { + if (file_exists(APPPATH.'config/autoload.php')) + { + include(APPPATH.'config/autoload.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); + } + + if ( ! isset($autoload)) + { + return; + } + + // Autoload packages + if (isset($autoload['packages'])) + { + foreach ($autoload['packages'] as $package_path) + { + $this->add_package_path($package_path); + } + } + + // Load any custom config file + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $val) + { + $this->config($val); + } + } + + // Autoload helpers and languages + foreach (array('helper', 'language') as $type) + { + if (isset($autoload[$type]) && count($autoload[$type]) > 0) + { + $this->$type($autoload[$type]); + } + } + + // Autoload drivers + if (isset($autoload['drivers'])) + { + $this->driver($autoload['drivers']); + } + + // Load libraries + if (isset($autoload['libraries']) && count($autoload['libraries']) > 0) + { + // Load the database driver. + if (in_array('database', $autoload['libraries'])) + { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + // Load all other libraries + $this->library($autoload['libraries']); + } + + // Autoload models + if (isset($autoload['model'])) + { + $this->model($autoload['model']); + } + } + + // -------------------------------------------------------------------- + + /** + * Prepare variables for _ci_vars, to be later extract()-ed inside views + * + * Converts objects to associative arrays and filters-out internal + * variable names (i.e. keys prefixed with '_ci_'). + * + * @param mixed $vars + * @return array + */ + protected function _ci_prepare_view_vars($vars) + { + if ( ! is_array($vars)) + { + $vars = is_object($vars) + ? get_object_vars($vars) + : array(); + } + + foreach (array_keys($vars) as $key) + { + if (strncmp($key, '_ci_', 4) === 0) + { + unset($vars[$key]); + } + } + + return $vars; + } + + // -------------------------------------------------------------------- + + /** + * CI Component getter + * + * Get a reference to a specific library or model. + * + * @param string $component Component name + * @return bool + */ + protected function &_ci_get_component($component) + { + $CI =& get_instance(); + return $CI->$component; + } } - -/* End of file Loader.php */ -/* Location: ./system/core/Loader.php */ \ No newline at end of file diff --git a/system/core/Log.php b/system/core/Log.php new file mode 100644 index 0000000..f37726e --- /dev/null +++ b/system/core/Log.php @@ -0,0 +1,296 @@ + 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + + /** + * mbstring.func_overload flag + * + * @var bool + */ + protected static $func_overload; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $config =& get_config(); + + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; + $this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '') + ? ltrim($config['log_file_extension'], '.') : 'php'; + + file_exists($this->_log_path) OR mkdir($this->_log_path, 0755, TRUE); + + if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) + { + $this->_enabled = FALSE; + } + + if (is_numeric($config['log_threshold'])) + { + $this->_threshold = (int) $config['log_threshold']; + } + elseif (is_array($config['log_threshold'])) + { + $this->_threshold = 0; + $this->_threshold_array = array_flip($config['log_threshold']); + } + + if ( ! empty($config['log_date_format'])) + { + $this->_date_fmt = $config['log_date_format']; + } + + if ( ! empty($config['log_file_permissions']) && is_int($config['log_file_permissions'])) + { + $this->_file_permissions = $config['log_file_permissions']; + } + } + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @param string $level The error level: 'error', 'debug' or 'info' + * @param string $msg The error message + * @return bool + */ + public function write_log($level, $msg) + { + if ($this->_enabled === FALSE) + { + return FALSE; + } + + $level = strtoupper($level); + + if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + && ! isset($this->_threshold_array[$this->_levels[$level]])) + { + return FALSE; + } + + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext; + $message = ''; + + if ( ! file_exists($filepath)) + { + $newfile = TRUE; + // Only add protection to php files + if ($this->_file_ext === 'php') + { + $message .= "\n\n"; + } + } + + if ( ! $fp = @fopen($filepath, 'ab')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + // Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format + if (strpos($this->_date_fmt, 'u') !== FALSE) + { + $microtime_full = microtime(TRUE); + $microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000); + $date = new DateTime(date('Y-m-d H:i:s.'.$microtime_short, $microtime_full)); + $date = $date->format($this->_date_fmt); + } + else + { + $date = date($this->_date_fmt); + } + + $message .= $this->_format_line($level, $date, $msg); + + for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result) + { + if (($result = fwrite($fp, self::substr($message, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + if (isset($newfile) && $newfile === TRUE) + { + chmod($filepath, $this->_file_permissions); + } + + return is_int($result); + } + + // -------------------------------------------------------------------- + + /** + * Format the log line. + * + * This is for extensibility of log formatting + * If you want to change the log format, extend the CI_Log class and override this method + * + * @param string $level The error level + * @param string $date Formatted date string + * @param string $message The log message + * @return string Formatted log line with a new line character at the end + */ + protected function _format_line($level, $date, $message) + { + return $level.' - '.$date.' --> '.$message.PHP_EOL; + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + 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'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } +} diff --git a/system/core/Model.php b/system/core/Model.php old mode 100755 new mode 100644 index 3aba05c..0aadbcd --- a/system/core/Model.php +++ b/system/core/Model.php @@ -1,58 +1,76 @@ -$key; - } -} -// END Model Class + /** + * __get magic + * + * Allows models to access CI's loaded classes using the same + * syntax as controllers. + * + * @param string $key + */ + public function __get($key) + { + // Debugging note: + // If you're here because you're getting an error message + // saying 'Undefined Property: system/core/Model.php', it's + // most likely a typo in your model code. + return get_instance()->$key; + } -/* End of file Model.php */ -/* Location: ./system/core/Model.php */ \ No newline at end of file +} diff --git a/system/core/Output.php b/system/core/Output.php old mode 100755 new mode 100644 index 638fec8..64e7ee1 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -1,575 +1,842 @@ -_zlib_oc = @ini_get('zlib.output_compression'); - - // Get mime types for later - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; - } - else - { - include APPPATH.'config/mimes.php'; - } - - - $this->mime_types = $mimes; - - log_message('debug', "Output Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Get Output - * - * Returns the current output string - * - * @access public - * @return string - */ - function get_output() - { - return $this->final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Append Output - * - * Appends data onto the output string - * - * @access public - * @param string - * @return void - */ - function append_output($output) - { - if ($this->final_output == '') - { - $this->final_output = $output; - } - else - { - $this->final_output .= $output; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Header - * - * Lets you set a server header which will be outputted with the final display. - * - * Note: If a file is cached, headers will not be sent. We need to figure out - * how to permit header data to be saved with the cache data... - * - * @access public - * @param string - * @param bool - * @return void - */ - function set_header($header, $replace = TRUE) - { - // If zlib.output_compression is enabled it will compress the output, - // but it will not modify the content-length header to compensate for - // the reduction, causing the browser to hang waiting for more data. - // We'll just skip content-length in those cases. - - if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0) - { - return; - } - - $this->headers[] = array($header, $replace); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Content Type Header - * - * @access public - * @param string extension of the file we're outputting - * @return void - */ - function set_content_type($mime_type) - { - if (strpos($mime_type, '/') === FALSE) - { - $extension = ltrim($mime_type, '.'); - - // Is this extension supported? - if (isset($this->mime_types[$extension])) - { - $mime_type =& $this->mime_types[$extension]; - - if (is_array($mime_type)) - { - $mime_type = current($mime_type); - } - } - } - - $header = 'Content-Type: '.$mime_type; - - $this->headers[] = array($header, TRUE); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set HTTP Status Header - * moved to Common procedural functions in 1.7.2 - * - * @access public - * @param int the status code - * @param string - * @return void - */ - function set_status_header($code = 200, $text = '') - { - set_status_header($code, $text); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Profiler Sections - * - * Allows override of default / config settings for Profiler section display - * - * @access public - * @param array - * @return void - */ - function set_profiler_sections($sections) - { - foreach ($sections as $section => $enable) - { - $this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Display Output - * - * All "view" data is automatically put into this variable by the controller class: - * - * $this->final_output - * - * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the - * benchmark timer so the page rendering speed and memory usage can be shown. - * - * @access public - * @param string - * @return mixed - */ - function _display($output = '') - { - // Note: We use globals because we can't use $CI =& get_instance() - // since this function is sometimes called by the caching mechanism, - // which happens before the CI super object is available. - global $BM, $CFG; - - // Grab the super object if we can. - if (class_exists('CI_Controller')) - { - $CI =& get_instance(); - } - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? Only if the controller does not have its - // own _output() method and we are not dealing with a cache file, which we - // can determine by the existence of the $CI object above - if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output')) - { - $this->_write_cache($output); - } - - // -------------------------------------------------------------------- - - // Parse out the elapsed time and memory usage, - // then swap the pseudo-variables with the data - - $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); - - if ($this->parse_exec_vars === TRUE) - { - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - - $output = str_replace('{elapsed_time}', $elapsed, $output); - $output = str_replace('{memory_usage}', $memory, $output); - } - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE) - { - if (extension_loaded('zlib')) - { - if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) - { - ob_start('ob_gzhandler'); - } - } - } - - // -------------------------------------------------------------------- - - // Are there any server headers to send? - if (count($this->headers) > 0) - { - foreach ($this->headers as $header) - { - @header($header[0], $header[1]); - } - } - - // -------------------------------------------------------------------- - - // Does the $CI object exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! isset($CI)) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Do we need to generate profile data? - // If so, load the Profile class and run it. - if ($this->enable_profiler == TRUE) - { - $CI->load->library('profiler'); - - if ( ! empty($this->_profiler_sections)) - { - $CI->profiler->set_sections($this->_profiler_sections); - } - - // If the output data contains closing and tags - // we will remove them and add them back after we insert the profile data - if (preg_match("|.*?|is", $output)) - { - $output = preg_replace("|.*?|is", '', $output); - $output .= $CI->profiler->run(); - $output .= ''; - } - else - { - $output .= $CI->profiler->run(); - } - } - - // -------------------------------------------------------------------- - - // Does the controller contain a function named _output()? - // If so send the output there. Otherwise, echo it. - if (method_exists($CI, '_output')) - { - $CI->_output($output); - } - else - { - echo $output; // Send it to the browser! - } - - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - } - - // -------------------------------------------------------------------- - - /** - * Write a Cache File - * - * @access public - * @param string - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? APPPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - log_message('error', "Unable to write cache file: ".$cache_path); - return; - } - - $uri = $CI->config->item('base_url'). - $CI->config->item('index_page'). - $CI->uri->uri_string(); - - $cache_path .= md5($uri); - - if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE)) - { - log_message('error', "Unable to write cache file: ".$cache_path); - return; - } - - $expire = time() + ($this->cache_expiration * 60); - - if (flock($fp, LOCK_EX)) - { - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); - } - else - { - log_message('error', "Unable to secure a file lock for file at: ".$cache_path); - return; - } - fclose($fp); - @chmod($cache_path, FILE_WRITE_MODE); - - log_message('debug', "Cache file written: ".$cache_path); - } - - // -------------------------------------------------------------------- - - /** - * Update/serve a cached file - * - * @access public - * @param object config class - * @param object uri class - * @return void - */ - function _display_cache(&$CFG, &$URI) - { - $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path'); - - // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url'). - $CFG->item('index_page'). - $URI->uri_string; - - $filepath = $cache_path.md5($uri); - - if ( ! @file_exists($filepath)) - { - return FALSE; - } - - if ( ! $fp = @fopen($filepath, FOPEN_READ)) - { - return FALSE; - } - - flock($fp, LOCK_SH); - - $cache = ''; - if (filesize($filepath) > 0) - { - $cache = fread($fp, filesize($filepath)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - // Strip out the embedded timestamp - if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) - { - return FALSE; - } - - // Has the file expired? If so we'll delete it. - if (time() >= trim(str_replace('TS--->', '', $match['1']))) - { - if (is_really_writable($cache_path)) - { - @unlink($filepath); - log_message('debug', "Cache file has expired. File deleted"); - return FALSE; - } - } - - // Display the cache - $this->_display(str_replace($match['0'], '', $cache)); - log_message('debug', "Cache file is current. Sending it to browser."); - return TRUE; - } - - + /** + * Final output string + * + * @var string + */ + public $final_output; + + /** + * Cache expiration time + * + * @var int + */ + public $cache_expiration = 0; + + /** + * List of server headers + * + * @var array + */ + public $headers = array(); + + /** + * List of mime types + * + * @var array + */ + public $mimes = array(); + + /** + * Mime-type for the current page + * + * @var string + */ + protected $mime_type = 'text/html'; + + /** + * Enable Profiler flag + * + * @var bool + */ + public $enable_profiler = FALSE; + + /** + * php.ini zlib.output_compression flag + * + * @var bool + */ + protected $_zlib_oc = FALSE; + + /** + * CI output compression flag + * + * @var bool + */ + protected $_compress_output = FALSE; + + /** + * List of profiler sections + * + * @var array + */ + protected $_profiler_sections = array(); + + /** + * Parse markers flag + * + * Whether or not to parse variables like {elapsed_time} and {memory_usage}. + * + * @var bool + */ + public $parse_exec_vars = TRUE; + + /** + * mbstring.func_overload flag + * + * @var bool + */ + protected static $func_overload; + + /** + * Class constructor + * + * Determines whether zLib output compression will be used. + * + * @return void + */ + public function __construct() + { + $this->_zlib_oc = (bool) ini_get('zlib.output_compression'); + $this->_compress_output = ( + $this->_zlib_oc === FALSE + && config_item('compress_output') === TRUE + && extension_loaded('zlib') + ); + + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + // Get mime types for later + $this->mimes =& get_mimes(); + + log_message('info', 'Output Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Get Output + * + * Returns the current output string. + * + * @return string + */ + public function get_output() + { + return $this->final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string. + * + * @param string $output Output data + * @return CI_Output + */ + public function set_output($output) + { + $this->final_output = $output; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Append Output + * + * Appends data onto the output string. + * + * @param string $output Data to append + * @return CI_Output + */ + public function append_output($output) + { + $this->final_output .= $output; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Header + * + * Lets you set a server header which will be sent with the final output. + * + * Note: If a file is cached, headers will not be sent. + * @todo We need to figure out how to permit headers to be cached. + * + * @param string $header Header + * @param bool $replace Whether to replace the old header value, if already set + * @return CI_Output + */ + public function set_header($header, $replace = TRUE) + { + // If zlib.output_compression is enabled it will compress the output, + // but it will not modify the content-length header to compensate for + // the reduction, causing the browser to hang waiting for more data. + // We'll just skip content-length in those cases. + if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0) + { + return $this; + } + + $this->headers[] = array($header, $replace); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Content-Type Header + * + * @param string $mime_type Extension of the file we're outputting + * @param string $charset Character set (default: NULL) + * @return CI_Output + */ + public function set_content_type($mime_type, $charset = NULL) + { + if (strpos($mime_type, '/') === FALSE) + { + $extension = ltrim($mime_type, '.'); + + // Is this extension supported? + if (isset($this->mimes[$extension])) + { + $mime_type =& $this->mimes[$extension]; + + if (is_array($mime_type)) + { + $mime_type = current($mime_type); + } + } + } + + $this->mime_type = $mime_type; + + if (empty($charset)) + { + $charset = config_item('charset'); + } + + $header = 'Content-Type: '.$mime_type + .(empty($charset) ? '' : '; charset='.$charset); + + $this->headers[] = array($header, TRUE); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Current Content-Type Header + * + * @return string 'text/html', if not already set + */ + public function get_content_type() + { + for ($i = 0, $c = count($this->headers); $i < $c; $i++) + { + if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1) + { + return $content_type; + } + } + + return 'text/html'; + } + + // -------------------------------------------------------------------- + + /** + * Get Header + * + * @param string $header + * @return string + */ + public function get_header($header) + { + // Combine headers already sent with our batched headers + $headers = array_merge( + // We only need [x][0] from our multi-dimensional array + array_map('array_shift', $this->headers), + headers_list() + ); + + if (empty($headers) OR empty($header)) + { + return NULL; + } + + // Count backwards, in order to get the last matching header + for ($c = count($headers) - 1; $c > -1; $c--) + { + if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0) + { + return trim(self::substr($headers[$c], $l+1)); + } + } + + return NULL; + } + + // -------------------------------------------------------------------- + + /** + * Set HTTP Status Header + * + * As of version 1.7.2, this is an alias for common function + * set_status_header(). + * + * @param int $code Status code (default: 200) + * @param string $text Optional message + * @return CI_Output + */ + public function set_status_header($code = 200, $text = '') + { + set_status_header($code, $text); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @param bool $val TRUE to enable or FALSE to disable + * @return CI_Output + */ + public function enable_profiler($val = TRUE) + { + $this->enable_profiler = is_bool($val) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Profiler Sections + * + * Allows override of default/config settings for + * Profiler section display. + * + * @param array $sections Profiler sections + * @return CI_Output + */ + public function set_profiler_sections($sections) + { + if (isset($sections['query_toggle_count'])) + { + $this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count']; + unset($sections['query_toggle_count']); + } + + foreach ($sections as $section => $enable) + { + $this->_profiler_sections[$section] = ($enable !== FALSE); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @param int $time Cache expiration time in minutes + * @return CI_Output + */ + public function cache($time) + { + $this->cache_expiration = is_numeric($time) ? $time : 0; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Display Output + * + * Processes and sends finalized output data to the browser along + * with any server headers and profile data. It also stops benchmark + * timers so the page rendering speed and memory usage can be shown. + * + * Note: All "view" data is automatically put into $this->final_output + * by controller class. + * + * @uses CI_Output::$final_output + * @param string $output Output data override + * @return void + */ + public function _display($output = '') + { + // Note: We use load_class() because we can't use $CI =& get_instance() + // since this function is sometimes called by the caching mechanism, + // which happens before the CI super object is available. + $BM =& load_class('Benchmark', 'core'); + $CFG =& load_class('Config', 'core'); + + // Grab the super object if we can. + if (class_exists('CI_Controller', FALSE)) + { + $CI =& get_instance(); + } + + // -------------------------------------------------------------------- + + // Set the output data + if ($output === '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? Only if the controller does not have its + // own _output() method and we are not dealing with a cache file, which we + // can determine by the existence of the $CI object above + if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output')) + { + $this->_write_cache($output); + } + + // -------------------------------------------------------------------- + + // Parse out the elapsed time and memory usage, + // then swap the pseudo-variables with the data + + $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); + + if ($this->parse_exec_vars === TRUE) + { + $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB'; + $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); + } + + // -------------------------------------------------------------------- + + // Is compression requested? + if (isset($CI) // This means that we're not serving a cache file, if we were, it would already be compressed + && $this->_compress_output === TRUE + && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + ob_start('ob_gzhandler'); + } + + // -------------------------------------------------------------------- + + // Are there any server headers to send? + if (count($this->headers) > 0) + { + foreach ($this->headers as $header) + { + @header($header[0], $header[1]); + } + } + + // -------------------------------------------------------------------- + + // Does the $CI object exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! isset($CI)) + { + if ($this->_compress_output === TRUE) + { + if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + header('Content-Encoding: gzip'); + header('Content-Length: '.self::strlen($output)); + } + else + { + // User agent doesn't support gzip compression, + // so we'll have to decompress our cache + $output = gzinflate(self::substr($output, 10, -8)); + } + } + + echo $output; + log_message('info', 'Final output sent to browser'); + log_message('debug', 'Total execution time: '.$elapsed); + return; + } + + // -------------------------------------------------------------------- + + // Do we need to generate profile data? + // If so, load the Profile class and run it. + if ($this->enable_profiler === TRUE) + { + $CI->load->library('profiler'); + if ( ! empty($this->_profiler_sections)) + { + $CI->profiler->set_sections($this->_profiler_sections); + } + + // If the output data contains closing and tags + // we will remove them and add them back after we insert the profile data + $output = preg_replace('|.*?|is', '', $output, -1, $count).$CI->profiler->run(); + if ($count > 0) + { + $output .= ''; + } + } + + // Does the controller contain a function named _output()? + // If so send the output there. Otherwise, echo it. + if (method_exists($CI, '_output')) + { + $CI->_output($output); + } + else + { + echo $output; // Send it to the browser! + } + + log_message('info', 'Final output sent to browser'); + log_message('debug', 'Total execution time: '.$elapsed); + } + + // -------------------------------------------------------------------- + + /** + * Write Cache + * + * @param string $output Output data to cache + * @return void + */ + public function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + $cache_path = ($path === '') ? APPPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + { + log_message('error', 'Unable to write cache file: '.$cache_path); + return; + } + + $uri = $CI->config->item('base_url') + .$CI->config->item('index_page') + .$CI->uri->uri_string(); + + if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + + $cache_path .= md5($uri); + + if ( ! $fp = @fopen($cache_path, 'w+b')) + { + log_message('error', 'Unable to write cache file: '.$cache_path); + return; + } + + if ( ! flock($fp, LOCK_EX)) + { + log_message('error', 'Unable to secure a file lock for file at: '.$cache_path); + fclose($fp); + return; + } + + // If output compression is enabled, compress the cache + // itself, so that we don't have to do that each time + // we're serving it + if ($this->_compress_output === TRUE) + { + $output = gzencode($output); + + if ($this->get_header('content-type') === NULL) + { + $this->set_content_type($this->mime_type); + } + } + + $expire = time() + ($this->cache_expiration * 60); + + // Put together our serialized info. + $cache_info = serialize(array( + 'expire' => $expire, + 'headers' => $this->headers + )); + + $output = $cache_info.'ENDCI--->'.$output; + + for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result) + { + if (($result = fwrite($fp, self::substr($output, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + if ( ! is_int($result)) + { + @unlink($cache_path); + log_message('error', 'Unable to write the complete cache content at: '.$cache_path); + return; + } + + chmod($cache_path, 0640); + log_message('debug', 'Cache file written: '.$cache_path); + + // Send HTTP cache-control headers to browser to match file cache settings. + $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve cached output + * + * @uses CI_Config + * @uses CI_URI + * + * @param object &$CFG CI_Config class instance + * @param object &$URI CI_URI class instance + * @return bool TRUE on success or FALSE on failure + */ + public function _display_cache(&$CFG, &$URI) + { + $cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path'); + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string; + + if (($cache_query_string = $CFG->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + + $filepath = $cache_path.md5($uri); + + if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_SH); + + $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : ''; + + flock($fp, LOCK_UN); + fclose($fp); + + // Look for embedded serialized file info. + if ( ! preg_match('/^(.*)ENDCI--->/', $cache, $match)) + { + return FALSE; + } + + $cache_info = unserialize($match[1]); + $expire = $cache_info['expire']; + + $last_modified = filemtime($filepath); + + // Has the file expired? + if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path)) + { + // If so we'll delete it. + @unlink($filepath); + log_message('debug', 'Cache file has expired. File deleted.'); + return FALSE; + } + + // Send the HTTP cache control headers + $this->set_cache_header($last_modified, $expire); + + // Add headers from cache file. + foreach ($cache_info['headers'] as $header) + { + $this->set_header($header[0], $header[1]); + } + + // Display the cache + $this->_display(self::substr($cache, self::strlen($match[0]))); + log_message('debug', 'Cache file is current. Sending it to browser.'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache + * + * @param string $uri URI string + * @return bool + */ + public function delete_cache($uri = '') + { + $CI =& get_instance(); + $cache_path = $CI->config->item('cache_path'); + if ($cache_path === '') + { + $cache_path = APPPATH.'cache/'; + } + + if ( ! is_dir($cache_path)) + { + log_message('error', 'Unable to find cache path: '.$cache_path); + return FALSE; + } + + if (empty($uri)) + { + $uri = $CI->uri->uri_string(); + + if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + } + + $cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').ltrim($uri, '/')); + + if ( ! @unlink($cache_path)) + { + log_message('error', 'Unable to delete cache file for '.$uri); + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Header + * + * Set the HTTP headers to match the server-side file cache settings + * in order to reduce bandwidth. + * + * @param int $last_modified Timestamp of when the page was last modified + * @param int $expiration Timestamp of when should the requested page expire from cache + * @return void + */ + public function set_cache_header($last_modified, $expiration) + { + $max_age = $expiration - $_SERVER['REQUEST_TIME']; + + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) + { + $this->set_status_header(304); + exit; + } + + header('Pragma: public'); + header('Cache-Control: max-age='.$max_age.', public'); + header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT'); + header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT'); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + 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'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } } -// END Output Class - -/* End of file Output.php */ -/* Location: ./system/core/Output.php */ \ No newline at end of file diff --git a/system/core/Router.php b/system/core/Router.php old mode 100755 new mode 100644 index 1437899..90b69d0 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -1,523 +1,515 @@ -config =& load_class('Config', 'core'); - $this->uri =& load_class('URI', 'core'); - log_message('debug', "Router Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set the route mapping - * - * This function determines what should be served based on the URI request, - * as well as any "routes" that have been set in the routing config file. - * - * @access private - * @return void - */ - function _set_routing() - { - // Are query strings enabled in the config file? Normally CI doesn't utilize query strings - // since URI segments are more search-engine friendly, but they can optionally be used. - // If this feature is enabled, we will gather the directory/class/method a little differently - $segments = array(); - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - if (isset($_GET[$this->config->item('directory_trigger')])) - { - $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); - $segments[] = $this->fetch_directory(); - } - - if (isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - $segments[] = $this->fetch_class(); - } - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); - $segments[] = $this->fetch_method(); - } - } - - // Load the routes.php file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); - } - elseif (is_file(APPPATH.'config/routes.php')) - { - include(APPPATH.'config/routes.php'); - } - - $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; - unset($route); - - // Set the default controller so we can display it in the event - // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - - // Were there any query string segments? If so, we'll validate them and bail out since we're done. - if (count($segments) > 0) - { - return $this->_validate_request($segments); - } - - // Fetch the complete URI string - $this->uri->_fetch_uri_string(); - - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri->uri_string == '') - { - return $this->_set_default_controller(); - } - - // Do we need to remove the URL suffix? - $this->uri->_remove_url_suffix(); - - // Compile the segments into an array - $this->uri->_explode_segments(); - - // Parse any custom routing that may exist - $this->_parse_routes(); - - // Re-index the segment array so that it starts with 1 rather than 0 - $this->uri->_reindex_segments(); - } - - // -------------------------------------------------------------------- - - /** - * Set the default controller - * - * @access private - * @return void - */ - function _set_default_controller() - { - if ($this->default_controller === FALSE) - { - show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); - } - // Is the method being specified? - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - - $this->set_class($x[0]); - $this->set_method($x[1]); - $this->_set_request($x); - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - $this->_set_request(array($this->default_controller, 'index')); - } - - // re-index the routed segments array so it starts with 1 rather than 0 - $this->uri->_reindex_segments(); - - log_message('debug', "No URI present. Default controller set."); - } - - // -------------------------------------------------------------------- - - /** - * Set the Route - * - * This function takes an array of URI segments as - * input, and sets the current class/method - * - * @access private - * @param array - * @param bool - * @return void - */ - function _set_request($segments = array()) - { - $segments = $this->_validate_request($segments); - - if (count($segments) == 0) - { - return $this->_set_default_controller(); - } - - $this->set_class($segments[0]); - - if (isset($segments[1])) - { - // A standard method request - $this->set_method($segments[1]); - } - else - { - // This lets the "routed" segment array identify that the default - // index method is being used. - $segments[1] = 'index'; - } - - // Update our "routed" segment array to contain the segments. - // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments - $this->uri->rsegments = $segments; - } - - // -------------------------------------------------------------------- - - /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. - * - * @access private - * @param array - * @return array - */ - function _validate_request($segments) - { - if (count($segments) == 0) - { - return $segments; - } - - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].'.php')) - { - return $segments; - } - - // Is the controller in a sub-folder? - if (is_dir(APPPATH.'controllers/'.$segments[0])) - { - // Set the directory and remove it from the segment array - $this->set_directory($segments[0]); - $segments = array_slice($segments, 1); - - if (count($segments) > 0) - { - // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) - { - if ( ! empty($this->routes['404_override'])) - { - $x = explode('/', $this->routes['404_override']); - - $this->set_directory(''); - $this->set_class($x[0]); - $this->set_method(isset($x[1]) ? $x[1] : 'index'); - - return $x; - } - else - { - show_404($this->fetch_directory().$segments[0]); - } - } - } - else - { - // Is the method being specified in the route? - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - - $this->set_class($x[0]); - $this->set_method($x[1]); - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - } - - // Does the default controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php')) - { - $this->directory = ''; - return array(); - } - - } - - return $segments; - } - - - // If we've gotten this far it means that the URI does not correlate to a valid - // controller class. We will now see if there is an override - if ( ! empty($this->routes['404_override'])) - { - $x = explode('/', $this->routes['404_override']); - - $this->set_class($x[0]); - $this->set_method(isset($x[1]) ? $x[1] : 'index'); - - return $x; - } - - - // Nothing else to do at this point but show a 404 - show_404($segments[0]); - } - - // -------------------------------------------------------------------- - - /** - * Parse Routes - * - * This function matches any routes that may exist in - * the config/routes.php file against the URI to - * determine if the class/method need to be remapped. - * - * @access private - * @return void - */ - function _parse_routes() - { - // Turn the segment array into a URI string - $uri = implode('/', $this->uri->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - return $this->_set_request(explode('/', $this->routes[$uri])); - } - - // Loop through the route array looking for wild-cards - foreach ($this->routes as $key => $val) - { - // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the RegEx match? - if (preg_match('#^'.$key.'$#', $uri)) - { - // Do we have a back-reference? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } - - return $this->_set_request(explode('/', $val)); - } - } - - // If we got this far it means we didn't encounter a - // matching route so we'll set the site default route - $this->_set_request($this->uri->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = str_replace(array('/', '.'), '', $class); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current class - * - * @access public - * @return string - */ - function fetch_class() - { - return $this->class; - } - - // -------------------------------------------------------------------- - - /** - * Set the method name - * - * @access public - * @param string - * @return void - */ - function set_method($method) - { - $this->method = $method; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current method - * - * @access public - * @return string - */ - function fetch_method() - { - if ($this->method == $this->fetch_class()) - { - return 'index'; - } - - return $this->method; - } - - // -------------------------------------------------------------------- - - /** - * Set the directory name - * - * @access public - * @param string - * @return void - */ - function set_directory($dir) - { - $this->directory = str_replace(array('/', '.'), '', $dir).'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - - // -------------------------------------------------------------------- - - /** - * Set the controller overrides - * - * @access public - * @param array - * @return null - */ - function _set_overrides($routing) - { - if ( ! is_array($routing)) - { - return; - } - - if (isset($routing['directory'])) - { - $this->set_directory($routing['directory']); - } - - if (isset($routing['controller']) AND $routing['controller'] != '') - { - $this->set_class($routing['controller']); - } - - if (isset($routing['function'])) - { - $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function']; - $this->set_method($routing['function']); - } - } - + /** + * CI_Config class object + * + * @var object + */ + public $config; + + /** + * List of routes + * + * @var array + */ + public $routes = array(); + + /** + * Current class name + * + * @var string + */ + public $class = ''; + + /** + * Current method name + * + * @var string + */ + public $method = 'index'; + + /** + * Sub-directory that contains the requested controller class + * + * @var string + */ + public $directory; + + /** + * Default controller (and method if specific) + * + * @var string + */ + public $default_controller; + + /** + * Translate URI dashes + * + * Determines whether dashes in controller & method segments + * should be automatically replaced by underscores. + * + * @var bool + */ + public $translate_uri_dashes = FALSE; + + /** + * Enable query strings flag + * + * Determines whether to use GET parameters or segment URIs + * + * @var bool + */ + public $enable_query_strings = FALSE; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Runs the route mapping function. + * + * @param array $routing + * @return void + */ + public function __construct($routing = NULL) + { + $this->config =& load_class('Config', 'core'); + $this->uri =& load_class('URI', 'core'); + + $this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE); + + // If a directory override is configured, it has to be set before any dynamic routing logic + is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']); + $this->_set_routing(); + + // Set any routing overrides that may exist in the main index file + if (is_array($routing)) + { + empty($routing['controller']) OR $this->set_class($routing['controller']); + empty($routing['function']) OR $this->set_method($routing['function']); + } + + log_message('info', 'Router Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set route mapping + * + * Determines what should be served based on the URI request, + * as well as any "routes" that have been set in the routing config file. + * + * @return void + */ + protected function _set_routing() + { + // Load the routes.php file. It would be great if we could + // skip this for enable_query_strings = TRUE, but then + // default_controller would be empty ... + if (file_exists(APPPATH.'config/routes.php')) + { + include(APPPATH.'config/routes.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + } + + // Validate & get reserved routes + if (isset($route) && is_array($route)) + { + isset($route['default_controller']) && $this->default_controller = $route['default_controller']; + isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; + unset($route['default_controller'], $route['translate_uri_dashes']); + $this->routes = $route; + } + + // Are query strings enabled in the config file? Normally CI doesn't utilize query strings + // since URI segments are more search-engine friendly, but they can optionally be used. + // If this feature is enabled, we will gather the directory/class/method a little differently + if ($this->enable_query_strings) + { + // If the directory is set at this time, it means an override exists, so skip the checks + if ( ! isset($this->directory)) + { + $_d = $this->config->item('directory_trigger'); + $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; + + if ($_d !== '') + { + $this->uri->filter_uri($_d); + $this->set_directory($_d); + } + } + + $_c = trim($this->config->item('controller_trigger')); + if ( ! empty($_GET[$_c])) + { + $this->uri->filter_uri($_GET[$_c]); + $this->set_class($_GET[$_c]); + + $_f = trim($this->config->item('function_trigger')); + if ( ! empty($_GET[$_f])) + { + $this->uri->filter_uri($_GET[$_f]); + $this->set_method($_GET[$_f]); + } + + $this->uri->rsegments = array( + 1 => $this->class, + 2 => $this->method + ); + } + else + { + $this->_set_default_controller(); + } + + // Routing rules don't apply to query strings and we don't need to detect + // directories, so we're done here + return; + } + + // Is there anything to parse? + if ($this->uri->uri_string !== '') + { + $this->_parse_routes(); + } + else + { + $this->_set_default_controller(); + } + } + + // -------------------------------------------------------------------- + + /** + * Set request route + * + * Takes an array of URI segments as input and sets the class/method + * to be called. + * + * @used-by CI_Router::_parse_routes() + * @param array $segments URI segments + * @return void + */ + protected function _set_request($segments = array()) + { + $segments = $this->_validate_request($segments); + // If we don't have any segments left - try the default controller; + // WARNING: Directories get shifted out of the segments array! + if (empty($segments)) + { + $this->_set_default_controller(); + return; + } + + if ($this->translate_uri_dashes === TRUE) + { + $segments[0] = str_replace('-', '_', $segments[0]); + if (isset($segments[1])) + { + $segments[1] = str_replace('-', '_', $segments[1]); + } + } + + $this->set_class($segments[0]); + if (isset($segments[1])) + { + $this->set_method($segments[1]); + } + else + { + $segments[1] = 'index'; + } + + array_unshift($segments, NULL); + unset($segments[0]); + $this->uri->rsegments = $segments; + } + + // -------------------------------------------------------------------- + + /** + * Set default controller + * + * @return void + */ + protected function _set_default_controller() + { + if (empty($this->default_controller)) + { + show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); + } + + // Is the method being specified? + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) + { + $method = 'index'; + } + + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) + { + // This will trigger 404 later + return; + } + + $this->set_class($class); + $this->set_method($method); + + // Assign routed segments, index starting from 1 + $this->uri->rsegments = array( + 1 => $class, + 2 => $method + ); + + log_message('debug', 'No URI present. Default controller set.'); + } + + // -------------------------------------------------------------------- + + /** + * Validate request + * + * Attempts validate the URI request and determine the controller path. + * + * @used-by CI_Router::_set_request() + * @param array $segments URI segments + * @return mixed URI segments + */ + protected function _validate_request($segments) + { + $c = count($segments); + $directory_override = isset($this->directory); + + // Loop through our segments and return as soon as a controller + // is found or when such a directory doesn't exist + while ($c-- > 0) + { + $test = $this->directory + .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); + + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') + && $directory_override === FALSE + && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]) + ) + { + $this->set_directory(array_shift($segments), TRUE); + continue; + } + + return $segments; + } + + // This means that all segments were actually directories + return $segments; + } + + // -------------------------------------------------------------------- + + /** + * Parse Routes + * + * Matches any routes that may exist in the config/routes.php file + * against the URI to determine if the class/method need to be remapped. + * + * @return void + */ + protected function _parse_routes() + { + // Turn the segment array into a URI string + $uri = implode('/', $this->uri->segments); + + // Get HTTP verb + $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; + + // Loop through the route array looking for wildcards + foreach ($this->routes as $key => $val) + { + // Check if route format is using HTTP verbs + if (is_array($val)) + { + $val = array_change_key_case($val, CASE_LOWER); + if (isset($val[$http_verb])) + { + $val = $val[$http_verb]; + } + else + { + continue; + } + } + + // Convert wildcards to RegEx + $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); + + // Does the RegEx match? + if (preg_match('#^'.$key.'$#', $uri, $matches)) + { + // Are we using callbacks to process back-references? + if ( ! is_string($val) && is_callable($val)) + { + // Remove the original string from the matches array. + array_shift($matches); + + // Execute the callback using the values in matches as its parameters. + $val = call_user_func_array($val, $matches); + } + // Are we using the default routing method for back-references? + elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } + + $this->_set_request(explode('/', $val)); + return; + } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_set_request(array_values($this->uri->segments)); + } + + // -------------------------------------------------------------------- + + /** + * Set class name + * + * @param string $class Class name + * @return void + */ + public function set_class($class) + { + $this->class = str_replace(array('/', '.'), '', $class); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current class + * + * @deprecated 3.0.0 Read the 'class' property instead + * @return string + */ + public function fetch_class() + { + return $this->class; + } + + // -------------------------------------------------------------------- + + /** + * Set method name + * + * @param string $method Method name + * @return void + */ + public function set_method($method) + { + $this->method = $method; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current method + * + * @deprecated 3.0.0 Read the 'method' property instead + * @return string + */ + public function fetch_method() + { + return $this->method; + } + + // -------------------------------------------------------------------- + + /** + * Set directory name + * + * @param string $dir Directory name + * @param bool $append Whether we're appending rather than setting the full value + * @return void + */ + public function set_directory($dir, $append = FALSE) + { + if ($append !== TRUE OR empty($this->directory)) + { + $this->directory = str_replace('.', '', trim($dir, '/')).'/'; + } + else + { + $this->directory .= str_replace('.', '', trim($dir, '/')).'/'; + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch directory + * + * Feches the sub-directory (if any) that contains the requested + * controller class. + * + * @deprecated 3.0.0 Read the 'directory' property instead + * @return string + */ + public function fetch_directory() + { + return $this->directory; + } } -// END Router Class - -/* End of file Router.php */ -/* Location: ./system/core/Router.php */ \ No newline at end of file diff --git a/system/core/Security.php b/system/core/Security.php old mode 100755 new mode 100644 index ddfeb01..6a81faf --- a/system/core/Security.php +++ b/system/core/Security.php @@ -1,875 +1,1091 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[', - '' => '<comment>' - ); - - /* never allowed, regex replacement */ - /** - * List of never allowed regex replacement - * - * @var array - * @access protected - */ - protected $_never_allowed_regex = array( - 'javascript\s*:', - '(document|(document\.)?window)\.(location|on\w*)', - 'expression\s*(\(|&\#40;)', // CSS and IE - 'vbscript\s*:', // IE, surprise! - 'wscript\s*:', // IE - 'jscript\s*:', // IE - 'vbs\s*:', // IE - 'Redirect\s+30\d:', - "([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?" - ); - - /** - * Constructor - * - * @return void - */ - public function __construct() - { - // Is CSRF protection enabled? - if (config_item('csrf_protection') === TRUE) - { - // CSRF config - foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key) - { - if (FALSE !== ($val = config_item($key))) - { - $this->{'_'.$key} = $val; - } - } - - // Append application specific cookie prefix - if (config_item('cookie_prefix')) - { - $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name; - } - - // Set the CSRF hash - $this->_csrf_set_hash(); - } - - log_message('debug', "Security Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Verify Cross Site Request Forgery Protection - * - * @return object - */ - public function csrf_verify() - { - // If it's not a POST request we will set the CSRF cookie - if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') - { - return $this->csrf_set_cookie(); - } - - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name])) - { - $this->csrf_show_error(); - } - - // Do the tokens match? - if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) - { - $this->csrf_show_error(); - } - - // We kill this since we're done and we don't want to - // polute the _POST array - unset($_POST[$this->_csrf_token_name]); - - // Nothing should last forever - unset($_COOKIE[$this->_csrf_cookie_name]); - $this->_csrf_set_hash(); - $this->csrf_set_cookie(); - - log_message('debug', 'CSRF token verified'); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Cross Site Request Forgery Protection Cookie - * - * @return object - */ - public function csrf_set_cookie() - { - $expire = time() + $this->_csrf_expire; - $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0; - - if ($secure_cookie && (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off')) - { - return FALSE; - } - - setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie); - - log_message('debug', "CRSF cookie Set"); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Show CSRF Error - * - * @return void - */ - public function csrf_show_error() - { - show_error('The action you have requested is not allowed.'); - } - - // -------------------------------------------------------------------- - - /** - * Get CSRF Hash - * - * Getter Method - * - * @return string self::_csrf_hash - */ - public function get_csrf_hash() - { - return $this->_csrf_hash; - } - - // -------------------------------------------------------------------- - - /** - * Get CSRF Token Name - * - * Getter Method - * - * @return string self::csrf_token_name - */ - public function get_csrf_token_name() - { - return $this->_csrf_token_name; - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented. This function does a fair amount of work but - * it is extremely thorough, designed to prevent even the - * most obscure XSS attempts. Nothing is ever 100% foolproof, - * of course, but I haven't been able to get anything passed - * the filter. - * - * Note: This function should only be used to deal with data - * upon submission. It's not something that should - * be used for general runtime processing. - * - * This function was based in part on some code and ideas I - * got from Bitflux: http://channel.bitflux.ch/wiki/XSS_Prevention - * - * To help develop this script I used this great list of - * vulnerabilities along with a few other hacks I've - * harvested from examining vulnerabilities in other programs: - * http://ha.ckers.org/xss.html - * - * @param mixed string or array - * @param bool - * @return string - */ - public function xss_clean($str, $is_image = FALSE) - { - // Is the string an array? - if (is_array($str)) - { - while (list($key) = each($str)) - { - $str[$key] = $this->xss_clean($str[$key]); - } - - return $str; - } - - //Remove Invisible Characters - $str = remove_invisible_characters($str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - */ - do - { - $str = rawurldecode($str); - } - while (preg_match('/%[0-9a-f]{2,}/i', $str)); - - /* - * Convert character entities to ASCII - * - * This permits our tests below to work reliably. - * We only convert entities that are within tags since - * these are the ones that will pose security problems. - */ - $str = preg_replace_callback("/[^a-z0-9>]+[a-z0-9]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - $str = preg_replace_callback('/<\w+.*/si', array($this, '_decode_entity'), $str); - - // Remove Invisible Characters Again! - $str = remove_invisible_characters($str); - - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * NOTE: we deal with spaces between characters later. - * NOTE: preg_replace was found to be amazingly slow here on - * large blocks of data, so we use str_replace. - */ - $str = str_replace("\t", ' ', $str); - - // Capture converted string for later comparison - $converted_string = $str; - - // Remove Strings that are never allowed - $str = $this->_do_never_allowed($str); - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?', '?>'), $str); - } - - /* - * Compact any exploded words - * - * This corrects words like: j a v a s c r i p t - * These words are compacted back to their correct state. - */ - $words = array( - 'javascript', 'expression', 'vbscript', 'jscript', 'wscript', - 'vbs', 'script', 'base64', 'applet', 'alert', 'document', - 'write', 'cookie', 'window', 'confirm', 'prompt' - ); - - foreach ($words as $word) - { - $word = implode('\s*', str_split($word)).'\s*'; - - // We only want to do this when it is followed by a non-word character - // That way valid stuff like "dealer to" does not become "dealerto" - $str = preg_replace_callback('#('.substr($word, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str); - } - - /* - * Remove disallowed Javascript in links or img tags - * We used to do some version comparisons and use of stripos(), - * but it is dog slow compared to these simplified non-capturing - * preg_match(), especially if the pattern exists in the string - * - * Note: It was reported that not only space characters, but all in - * the following pattern can be parsed as separators between a tag name - * and its attributes: [\d\s"\'`;,\/\=\(\x00\x0B\x09\x0C] - * ... however, remove_invisible_characters() above already strips the - * hex-encoded ones, so we'll skip them below. - */ - do - { - $original = $str; - - if (preg_match('/]+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str); - } - - if (preg_match('/]*?)(?:\s?/?>|$)#si', array($this, '_js_img_removal'), $str); - } - - if (preg_match('/script|xss/i', $str)) - { - $str = preg_replace('##si', '[removed]', $str); - } - } - while($original !== $str); - - unset($original); - - // Remove evil attributes such as style, onclick and xmlns - $str = $this->_remove_evil_attributes($str, $is_image); - - /* - * Sanitize naughty HTML elements - * - * If a tag containing any of the words in the list - * below is found, the tag gets converted to entities. - * - * So this: - * Becomes: <blink> - */ - $naughty = 'alert|prompt|confirm|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|button|select|isindex|layer|link|meta|keygen|object|plaintext|style|script|textarea|title|math|video|svg|xml|xss'; - $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); - - /* - * Sanitize naughty scripting elements - * - * Similar to above, only instead of looking for - * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the - * code, it simply converts the parenthesis to entities - * rendering the code un-executable. - * - * For example: eval('some code') - * Becomes: eval('some code') - */ - $str = preg_replace( - '#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', - '\\1\\2(\\3)', - $str - ); - - // Final clean up - // This adds a bit of extra precaution in case - // something got through the above filters - $str = $this->_do_never_allowed($str); - - /* - * Images are Handled in a Special Way - * - Essentially, we want to know that after all of the character - * conversion is done whether any unwanted, likely XSS, code was found. - * If not, we return TRUE, as the image is clean. - * However, if the string post-conversion does not matched the - * string post-removal of XSS, then it fails, as there was unwanted XSS - * code found and removed/changed during processing. - */ - - if ($is_image === TRUE) - { - return ($str === $converted_string); - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @return string - */ - public function xss_hash() - { - if ($this->_xss_hash == '') - { - mt_srand(); - $this->_xss_hash = md5(time() + mt_rand(0, 1999999999)); - } - - return $this->_xss_hash; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * The reason we are not using html_entity_decode() by itself is because - * while it is not technically correct to leave out the semicolon - * at the end of an entity most browsers will still interpret the entity - * correctly. html_entity_decode() does not convert entities without - * semicolons, so we are left with our own little solution here. Bummer. - * - * @param string - * @param string - * @return string - */ - public function entity_decode($str, $charset='UTF-8') - { - if (strpos($str, '&') === FALSE) - { - return $str; - } - - static $_entities; - - isset($charset) OR $charset = strtoupper(config_item('charset')); - $flag = is_php('5.4') - ? ENT_COMPAT | ENT_HTML5 - : ENT_COMPAT; - - do - { - $str_compare = $str; - - // Decode standard entities, avoiding false positives - if (preg_match_all('/\&[a-z]{2,}(?![a-z;])/i', $str, $matches)) - { - if ( ! isset($_entities)) - { - $_entities = array_map( - 'strtolower', - is_php('5.3.4') - ? get_html_translation_table(HTML_ENTITIES, $flag, $charset) - : get_html_translation_table(HTML_ENTITIES, $flag) - ); - - // If we're not on PHP 5.4+, add the possibly dangerous HTML 5 - // entities to the array manually - if ($flag === ENT_COMPAT) - { - $_entities[':'] = ':'; - $_entities['('] = '('; - $_entities[')'] = ')'; - $_entities["\n"] = '&newline;'; - $_entities["\t"] = '&tab;'; - } - } - - $replace = array(); - $matches = array_unique(array_map('strtolower', $matches[0])); - foreach ($matches as &$match) - { - if (($char = array_search($match.';', $_entities, TRUE)) !== FALSE) - { - $replace[$match] = $char; - } - } - - $str = str_ireplace(array_keys($replace), array_values($replace), $str); - } - - // Decode numeric & UTF16 two byte entities - $str = html_entity_decode( - preg_replace('/(&#(?:x0*[0-9a-f]{2,5}(?![0-9a-f;])|(?:0*\d{2,4}(?![0-9;]))))/iS', '$1;', $str), - $flag, - $charset - ); - } - while ($str_compare !== $str); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Filename Security - * - * @param string - * @param bool - * @return string - */ - public function sanitize_filename($str, $relative_path = FALSE) - { - $bad = array( - '../', '', '<', '>', - "'", '"', '&', '$', '#', - '{', '}', '[', ']', '=', - ';', '?', '%20', '%22', - '%3c', // < - '%253c', // < - '%3e', // > - '%0e', // > - '%28', // ( - '%29', // ) - '%2528', // ( - '%26', // & - '%24', // $ - '%3f', // ? - '%3b', // ; - '%3d' // = - ); - - if ( ! $relative_path) - { - $bad[] = './'; - $bad[] = '/'; - } - - $str = remove_invisible_characters($str, FALSE); - - do - { - $old = $str; - $str = str_replace($bad, '', $str); - } - while ($old !== $str); - - return stripslashes($str); - } - - // ---------------------------------------------------------------- - - /** - * Compact Exploded Words - * - * Callback function for xss_clean() to remove whitespace from - * things like j a v a s c r i p t - * - * @param type - * @return type - */ - protected function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /* - * Remove Evil HTML Attributes (like evenhandlers and style) - * - * It removes the evil attribute and either: - * - Everything up until a space - * For example, everything between the pipes: - * - * - Everything inside the quotes - * For example, everything between the pipes: - * - * - * @param string $str The string to check - * @param boolean $is_image TRUE if this is an image - * @return string The string with the evil attributes removed - */ - protected function _remove_evil_attributes($str, $is_image) - { - // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns - $evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, - * including namespacing, so we have to allow this for images. - */ - unset($evil_attributes[array_search('xmlns', $evil_attributes)]); - } - - do { - $count = 0; - $attribs = array(); - - // find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes) - preg_match_all('/(?]*)/is', $str, $matches, PREG_SET_ORDER); - - foreach ($matches as $attr) - { - $attribs[] = preg_quote($attr[0], '/'); - } - - // replace illegal attribute strings that are inside an html tag - if (count($attribs) > 0) - { - $str = preg_replace('/(<]+?)([^A-Za-z<>\-])(.*?)('.implode('|', $attribs).')(.*?)([\s><]?)([><]*)/i', '$1$2 $4$6$7$8', $str, -1, $count); - } - - } - while ($count); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @param array - * @return string - */ - protected function _sanitize_naughty_html($matches) - { - return '<'.$matches[1].$matches[2].$matches[3] // encode opening brace - // encode captured opening or closing brace to prevent recursive vectors: - .str_replace(array('>', '<'), array('>', '<'), $matches[4]); - } - - // -------------------------------------------------------------------- - - /** - * JS Link Removal - * - * Callback function for xss_clean() to sanitize links - * This limits the PCRE backtracks, making it more performance friendly - * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in - * PHP 5.2+ on link-heavy strings - * - * @param array - * @return string - */ - protected function _js_link_removal($match) - { - return str_replace( - $match[1], - preg_replace( - '#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])) - ), - $match[0] - ); - } - - // -------------------------------------------------------------------- - - /** - * JS Image Removal - * - * Callback function for xss_clean() to sanitize image tags - * This limits the PCRE backtracks, making it more performance friendly - * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in - * PHP 5.2+ on image tag heavy strings - * - * @param array - * @return string - */ - protected function _js_img_removal($match) - { - return str_replace( - $match[1], - preg_replace( - '#src=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])) - ), - $match[0] - ); - } - - // -------------------------------------------------------------------- - - /** - * Attribute Conversion - * - * Used as a callback for XSS Clean - * - * @param array - * @return string - */ - protected function _convert_attribute($match) - { - return str_replace(array('>', '<', '\\'), array('>', '<', '\\\\'), $match[0]); - } - - // -------------------------------------------------------------------- - - /** - * Filter Attributes - * - * Filters tag attributes for consistency and safety - * - * @param string - * @return string - */ - protected function _filter_attributes($str) - { - $out = ''; - - if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) - { - foreach ($matches[0] as $match) - { - $out .= preg_replace("#/\*.*?\*/#s", '', $match); - } - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @param array - * @return string - */ - protected function _decode_entity($match) - { - // Protect GET variables in URLs - // 901119URL5918AMP18930PROTECT8198 - $match = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-/]+)|i', $this->xss_hash().'\\1=\\2', $match[0]); - - // Decode, then un-protect URL GET vars - return str_replace( - $this->xss_hash(), - '&', - $this->entity_decode($match, strtoupper(config_item('charset'))) - ); - } - - // ---------------------------------------------------------------------- - - /** - * Do Never Allowed - * - * A utility function for xss_clean() - * - * @param string - * @return string - */ - protected function _do_never_allowed($str) - { - $str = str_replace(array_keys($this->_never_allowed_str), $this->_never_allowed_str, $str); - - foreach ($this->_never_allowed_regex as $regex) - { - $str = preg_replace('#'.$regex.'#is', '[removed]', $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Cross Site Request Forgery Protection Cookie - * - * @return string - */ - protected function _csrf_set_hash() - { - if ($this->_csrf_hash == '') - { - // If the cookie exists we will use it's value. - // We don't necessarily want to regenerate it with - // each page load since a page could contain embedded - // sub-pages causing this feature to fail - if (isset($_COOKIE[$this->_csrf_cookie_name]) && - preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1) - { - return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; - } - - return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); - } - - return $this->_csrf_hash; - } + /** + * List of sanitize filename strings + * + * @var array + */ + public $filename_bad_chars = array( + '../', '', '<', '>', + "'", '"', '&', '$', '#', + '{', '}', '[', ']', '=', + ';', '?', '%20', '%22', + '%3c', // < + '%253c', // < + '%3e', // > + '%0e', // > + '%28', // ( + '%29', // ) + '%2528', // ( + '%26', // & + '%24', // $ + '%3f', // ? + '%3b', // ; + '%3d' // = + ); + + /** + * Character set + * + * Will be overridden by the constructor. + * + * @var string + */ + public $charset = 'UTF-8'; + + /** + * XSS Hash + * + * Random Hash for protecting URLs. + * + * @var string + */ + protected $_xss_hash; + + /** + * CSRF Hash + * + * Random hash for Cross Site Request Forgery protection cookie + * + * @var string + */ + protected $_csrf_hash; + + /** + * CSRF Expire time + * + * Expiration time for Cross Site Request Forgery protection cookie. + * Defaults to two hours (in seconds). + * + * @var int + */ + protected $_csrf_expire = 7200; + + /** + * CSRF Token name + * + * Token name for Cross Site Request Forgery protection cookie. + * + * @var string + */ + protected $_csrf_token_name = 'ci_csrf_token'; + + /** + * CSRF Cookie name + * + * Cookie name for Cross Site Request Forgery protection cookie. + * + * @var string + */ + protected $_csrf_cookie_name = 'ci_csrf_token'; + + /** + * List of never allowed strings + * + * @var array + */ + protected $_never_allowed_str = array( + 'document.cookie' => '[removed]', + '(document).cookie' => '[removed]', + 'document.write' => '[removed]', + '(document).write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[', + '' => '<comment>', + '<%' => '<%' + ); + + /** + * List of never allowed regex replacements + * + * @var array + */ + protected $_never_allowed_regex = array( + 'javascript\s*:', + '(\(?document\)?|\(?window\)?(\.document)?)\.(location|on\w*)', + 'expression\s*(\(|&\#40;)', // CSS and IE + 'vbscript\s*:', // IE, surprise! + 'wscript\s*:', // IE + 'jscript\s*:', // IE + 'vbs\s*:', // IE + 'Redirect\s+30\d', + "([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?" + ); + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + // Is CSRF protection enabled? + if (config_item('csrf_protection')) + { + // CSRF config + foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key) + { + if (NULL !== ($val = config_item($key))) + { + $this->{'_'.$key} = $val; + } + } + + // Append application specific cookie prefix + if ($cookie_prefix = config_item('cookie_prefix')) + { + $this->_csrf_cookie_name = $cookie_prefix.$this->_csrf_cookie_name; + } + + // Set the CSRF hash + $this->_csrf_set_hash(); + } + + $this->charset = strtoupper(config_item('charset')); + + log_message('info', 'Security Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * CSRF Verify + * + * @return CI_Security + */ + public function csrf_verify() + { + // If it's not a POST request we will set the CSRF cookie + if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') + { + return $this->csrf_set_cookie(); + } + + // Check if URI has been whitelisted from CSRF checks + if ($exclude_uris = config_item('csrf_exclude_uris')) + { + $uri = load_class('URI', 'core'); + foreach ($exclude_uris as $excluded) + { + if (preg_match('#^'.$excluded.'$#i'.(UTF8_ENABLED ? 'u' : ''), $uri->uri_string())) + { + return $this; + } + } + } + + // Check CSRF token validity, but don't error on mismatch just yet - we'll want to regenerate + $valid = isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]) + && is_string($_POST[$this->_csrf_token_name]) && is_string($_COOKIE[$this->_csrf_cookie_name]) + && hash_equals($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]); + + // We kill this since we're done and we don't want to pollute the _POST array + unset($_POST[$this->_csrf_token_name]); + + // Regenerate on every submission? + if (config_item('csrf_regenerate')) + { + // Nothing should last forever + unset($_COOKIE[$this->_csrf_cookie_name]); + $this->_csrf_hash = NULL; + } + + $this->_csrf_set_hash(); + $this->csrf_set_cookie(); + + if ($valid !== TRUE) + { + $this->csrf_show_error(); + } + + log_message('info', 'CSRF token verified'); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * CSRF Set Cookie + * + * @codeCoverageIgnore + * @return CI_Security + */ + public function csrf_set_cookie() + { + $expire = time() + $this->_csrf_expire; + $secure_cookie = (bool) config_item('cookie_secure'); + + if ($secure_cookie && ! is_https()) + { + return FALSE; + } + + setcookie( + $this->_csrf_cookie_name, + $this->_csrf_hash, + $expire, + config_item('cookie_path'), + config_item('cookie_domain'), + $secure_cookie, + config_item('cookie_httponly') + ); + log_message('info', 'CSRF cookie sent'); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Show CSRF Error + * + * @return void + */ + public function csrf_show_error() + { + show_error('The action you have requested is not allowed.', 403); + } + + // -------------------------------------------------------------------- + + /** + * Get CSRF Hash + * + * @see CI_Security::$_csrf_hash + * @return string CSRF hash + */ + public function get_csrf_hash() + { + return $this->_csrf_hash; + } + + // -------------------------------------------------------------------- + + /** + * Get CSRF Token Name + * + * @see CI_Security::$_csrf_token_name + * @return string CSRF token name + */ + public function get_csrf_token_name() + { + return $this->_csrf_token_name; + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * Sanitizes data so that Cross Site Scripting Hacks can be + * prevented. This method does a fair amount of work but + * it is extremely thorough, designed to prevent even the + * most obscure XSS attempts. Nothing is ever 100% foolproof, + * of course, but I haven't been able to get anything passed + * the filter. + * + * Note: Should only be used to deal with data upon submission. + * It's not something that should be used for general + * runtime processing. + * + * @link http://channel.bitflux.ch/wiki/XSS_Prevention + * Based in part on some code and ideas from Bitflux. + * + * @link http://ha.ckers.org/xss.html + * To help develop this script I used this great list of + * vulnerabilities along with a few other hacks I've + * harvested from examining vulnerabilities in other programs. + * + * @param string|string[] $str Input data + * @param bool $is_image Whether the input is an image + * @return string + */ + public function xss_clean($str, $is_image = FALSE) + { + // Is the string an array? + if (is_array($str)) + { + foreach ($str as $key => &$value) + { + $str[$key] = $this->xss_clean($value); + } + + return $str; + } + + // Remove Invisible Characters + $str = remove_invisible_characters($str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + */ + if (stripos($str, '%') !== false) + { + do + { + $oldstr = $str; + $str = rawurldecode($str); + $str = preg_replace_callback('#%(?:\s*[0-9a-f]){2,}#i', array($this, '_urldecodespaces'), $str); + } + while ($oldstr !== $str); + unset($oldstr); + } + + /* + * Convert character entities to ASCII + * + * This permits our tests below to work reliably. + * We only convert entities that are within tags since + * these are the ones that will pose security problems. + */ + $str = preg_replace_callback("/[^a-z0-9>]+[a-z0-9]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); + $str = preg_replace_callback('/<\w+.*/si', array($this, '_decode_entity'), $str); + + // Remove Invisible Characters Again! + $str = remove_invisible_characters($str); + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * NOTE: we deal with spaces between characters later. + * NOTE: preg_replace was found to be amazingly slow here on + * large blocks of data, so we use str_replace. + */ + $str = str_replace("\t", ' ', $str); + + // Capture converted string for later comparison + $converted_string = $str; + + // Remove Strings that are never allowed + $str = $this->_do_never_allowed($str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?', '?>'), $str); + } + + /* + * Compact any exploded words + * + * This corrects words like: j a v a s c r i p t + * These words are compacted back to their correct state. + */ + $words = array( + 'javascript', 'expression', 'vbscript', 'jscript', 'wscript', + 'vbs', 'script', 'base64', 'applet', 'alert', 'document', + 'write', 'cookie', 'window', 'confirm', 'prompt', 'eval' + ); + + foreach ($words as $word) + { + $word = implode('\s*', str_split($word)).'\s*'; + + // We only want to do this when it is followed by a non-word character + // That way valid stuff like "dealer to" does not become "dealerto" + $str = preg_replace_callback('#('.substr($word, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str); + } + + /* + * Remove disallowed Javascript in links or img tags + * We used to do some version comparisons and use of stripos(), + * but it is dog slow compared to these simplified non-capturing + * preg_match(), especially if the pattern exists in the string + * + * Note: It was reported that not only space characters, but all in + * the following pattern can be parsed as separators between a tag name + * and its attributes: [\d\s"\'`;,\/\=\(\x00\x0B\x09\x0C] + * ... however, remove_invisible_characters() above already strips the + * hex-encoded ones, so we'll skip them below. + */ + do + { + $original = $str; + + if (preg_match('/]+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str); + } + + if (preg_match('/]*?)(?:\s?/?>|$)#si', array($this, '_js_img_removal'), $str); + } + + if (preg_match('/script|xss/i', $str)) + { + $str = preg_replace('##si', '[removed]', $str); + } + } + while ($original !== $str); + unset($original); + + /* + * Sanitize naughty HTML elements + * + * If a tag containing any of the words in the list + * below is found, the tag gets converted to entities. + * + * So this: + * Becomes: <blink> + */ + $pattern = '#' + .'<((?/*\s*)((?[a-z0-9]+)(?=[^a-z0-9]|$)|.+)' // tag start and name, followed by a non-tag character + .'[^\s\042\047a-z0-9>/=]*' // a valid attribute character immediately after the tag would count as a separator + // optional attributes + .'(?(?:[\s\042\047/=]*' // non-attribute characters, excluding > (tag close) for obvious reasons + .'[^\s\042\047>/=]+' // attribute characters + // optional attribute-value + .'(?:\s*=' // attribute-value separator + .'(?:[^\s\042\047=><`]+|\s*\042[^\042]*\042|\s*\047[^\047]*\047|\s*(?U:[^\s\042\047=><`]*))' // single, double or non-quoted value + .')?' // end optional attribute-value group + .')*)' // end optional attributes group + .'[^>]*)(?\>)?#isS'; + + // Note: It would be nice to optimize this for speed, BUT + // only matching the naughty elements here results in + // false positives and in turn - vulnerabilities! + do + { + $old_str = $str; + $str = preg_replace_callback($pattern, array($this, '_sanitize_naughty_html'), $str); + } + while ($old_str !== $str); + unset($old_str); + + /* + * Sanitize naughty scripting elements + * + * Similar to above, only instead of looking for + * tags it looks for PHP and JavaScript commands + * that are disallowed. Rather than removing the + * code, it simply converts the parenthesis to entities + * rendering the code un-executable. + * + * For example: eval('some code') + * Becomes: eval('some code') + */ + $str = preg_replace( + '#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', + '\\1\\2(\\3)', + $str + ); + + // Same thing, but for "tag functions" (e.g. eval`some code`) + // See https://github.com/bcit-ci/CodeIgniter/issues/5420 + $str = preg_replace( + '#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)`(.*?)`#si', + '\\1\\2`\\3`', + $str + ); + + // Final clean up + // This adds a bit of extra precaution in case + // something got through the above filters + $str = $this->_do_never_allowed($str); + + /* + * Images are Handled in a Special Way + * - Essentially, we want to know that after all of the character + * conversion is done whether any unwanted, likely XSS, code was found. + * If not, we return TRUE, as the image is clean. + * However, if the string post-conversion does not matched the + * string post-removal of XSS, then it fails, as there was unwanted XSS + * code found and removed/changed during processing. + */ + if ($is_image === TRUE) + { + return ($str === $converted_string); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * XSS Hash + * + * Generates the XSS hash if needed and returns it. + * + * @see CI_Security::$_xss_hash + * @return string XSS hash + */ + public function xss_hash() + { + if ($this->_xss_hash === NULL) + { + $rand = $this->get_random_bytes(16); + $this->_xss_hash = ($rand === FALSE) + ? md5(uniqid(mt_rand(), TRUE)) + : bin2hex($rand); + } + + return $this->_xss_hash; + } + + // -------------------------------------------------------------------- + + /** + * Get random bytes + * + * @param int $length Output length + * @return string + */ + public function get_random_bytes($length) + { + if (empty($length) OR ! ctype_digit((string) $length)) + { + return FALSE; + } + + if (function_exists('random_bytes')) + { + try + { + // The cast is required to avoid TypeError + return random_bytes((int) $length); + } + catch (Exception $e) + { + // If random_bytes() can't do the job, we can't either ... + // There's no point in using fallbacks. + log_message('error', $e->getMessage()); + return FALSE; + } + } + + // Unfortunately, none of the following PRNGs is guaranteed to exist ... + if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE) + { + return $output; + } + + + if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) + { + // Try not to waste entropy ... + is_php('5.4') && stream_set_chunk_size($fp, $length); + $output = fread($fp, $length); + fclose($fp); + if ($output !== FALSE) + { + return $output; + } + } + + if (function_exists('openssl_random_pseudo_bytes')) + { + return openssl_random_pseudo_bytes($length); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * A replacement for html_entity_decode() + * + * The reason we are not using html_entity_decode() by itself is because + * while it is not technically correct to leave out the semicolon + * at the end of an entity most browsers will still interpret the entity + * correctly. html_entity_decode() does not convert entities without + * semicolons, so we are left with our own little solution here. Bummer. + * + * @link http://php.net/html-entity-decode + * + * @param string $str Input + * @param string $charset Character set + * @return string + */ + public function entity_decode($str, $charset = NULL) + { + if (strpos($str, '&') === FALSE) + { + return $str; + } + + static $_entities; + + isset($charset) OR $charset = $this->charset; + $flag = is_php('5.4') + ? ENT_COMPAT | ENT_HTML5 + : ENT_COMPAT; + + if ( ! isset($_entities)) + { + $_entities = array_map('strtolower', get_html_translation_table(HTML_ENTITIES, $flag, $charset)); + + // If we're not on PHP 5.4+, add the possibly dangerous HTML 5 + // entities to the array manually + if ($flag === ENT_COMPAT) + { + $_entities[':'] = ':'; + $_entities['('] = '('; + $_entities[')'] = ')'; + $_entities["\n"] = ' '; + $_entities["\t"] = ' '; + } + } + + do + { + $str_compare = $str; + + // Decode standard entities, avoiding false positives + if (preg_match_all('/&[a-z]{2,}(?![a-z;])/i', $str, $matches)) + { + $replace = array(); + $matches = array_unique(array_map('strtolower', $matches[0])); + foreach ($matches as &$match) + { + if (($char = array_search($match.';', $_entities, TRUE)) !== FALSE) + { + $replace[$match] = $char; + } + } + + $str = str_replace(array_keys($replace), array_values($replace), $str); + } + + // Decode numeric & UTF16 two byte entities + $str = html_entity_decode( + preg_replace('/(&#(?:x0*[0-9a-f]{2,5}(?![0-9a-f;])|(?:0*\d{2,4}(?![0-9;]))))/iS', '$1;', $str), + $flag, + $charset + ); + + if ($flag === ENT_COMPAT) + { + $str = str_replace(array_values($_entities), array_keys($_entities), $str); + } + } + while ($str_compare !== $str); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Filename + * + * @param string $str Input file name + * @param bool $relative_path Whether to preserve paths + * @return string + */ + public function sanitize_filename($str, $relative_path = FALSE) + { + $bad = $this->filename_bad_chars; + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } + + $str = remove_invisible_characters($str, FALSE); + + do + { + $old = $str; + $str = str_replace($bad, '', $str); + } + while ($old !== $str); + + return stripslashes($str); + } + + // ---------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @param string $str + * @return string + */ + public function strip_image_tags($str) + { + return preg_replace( + array( + '##i', + '#`]+)).*?\>#i' + ), + '\\2', + $str + ); + } + + // ---------------------------------------------------------------- + + /** + * URL-decode taking spaces into account + * + * @see https://github.com/bcit-ci/CodeIgniter/issues/4877 + * @param array $matches + * @return string + */ + protected function _urldecodespaces($matches) + { + $input = $matches[0]; + $nospaces = preg_replace('#\s+#', '', $input); + return ($nospaces === $input) + ? $input + : rawurldecode($nospaces); + } + + // ---------------------------------------------------------------- + + /** + * Compact Exploded Words + * + * Callback method for xss_clean() to remove whitespace from + * things like 'j a v a s c r i p t'. + * + * @used-by CI_Security::xss_clean() + * @param array $matches + * @return string + */ + protected function _compact_exploded_words($matches) + { + return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback method for xss_clean() to remove naughty HTML elements. + * + * @used-by CI_Security::xss_clean() + * @param array $matches + * @return string + */ + protected function _sanitize_naughty_html($matches) + { + static $naughty_tags = array( + 'alert', 'area', 'prompt', 'confirm', 'applet', 'audio', 'basefont', 'base', 'behavior', 'bgsound', + 'blink', 'body', 'embed', 'expression', 'form', 'frameset', 'frame', 'head', 'html', 'ilayer', + 'iframe', 'input', 'button', 'select', 'isindex', 'layer', 'link', 'meta', 'keygen', 'object', + 'plaintext', 'style', 'script', 'textarea', 'title', 'math', 'video', 'svg', 'xml', 'xss' + ); + + static $evil_attributes = array( + 'on\w+', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime' + ); + + // First, escape unclosed tags + if (empty($matches['closeTag'])) + { + return '<'.$matches[1]; + } + // Is the element that we caught naughty? If so, escape it + elseif (in_array(strtolower($matches['tagName']), $naughty_tags, TRUE)) + { + return '<'.$matches[1].'>'; + } + // For other tags, see if their attributes are "evil" and strip those + elseif (isset($matches['attributes'])) + { + // We'll store the already filtered attributes here + $attributes = array(); + + // Attribute-catching pattern + $attributes_pattern = '#' + .'(?[^\s\042\047>/=]+)' // attribute characters + // optional attribute-value + .'(?:\s*=(?[^\s\042\047=><`]+|\s*\042[^\042]*\042|\s*\047[^\047]*\047|\s*(?U:[^\s\042\047=><`]*)))' // attribute-value separator + .'#i'; + + // Blacklist pattern for evil attribute names + $is_evil_pattern = '#^('.implode('|', $evil_attributes).')$#i'; + + // Each iteration filters a single attribute + do + { + // Strip any non-alpha characters that may precede an attribute. + // Browsers often parse these incorrectly and that has been a + // of numerous XSS issues we've had. + $matches['attributes'] = preg_replace('#^[^a-z]+#i', '', $matches['attributes']); + + if ( ! preg_match($attributes_pattern, $matches['attributes'], $attribute, PREG_OFFSET_CAPTURE)) + { + // No (valid) attribute found? Discard everything else inside the tag + break; + } + + if ( + // Is it indeed an "evil" attribute? + preg_match($is_evil_pattern, $attribute['name'][0]) + // Or does it have an equals sign, but no value and not quoted? Strip that too! + OR (trim($attribute['value'][0]) === '') + ) + { + $attributes[] = 'xss=removed'; + } + else + { + $attributes[] = $attribute[0][0]; + } + + $matches['attributes'] = substr($matches['attributes'], $attribute[0][1] + strlen($attribute[0][0])); + } + while ($matches['attributes'] !== ''); + + $attributes = empty($attributes) + ? '' + : ' '.implode(' ', $attributes); + return '<'.$matches['slash'].$matches['tagName'].$attributes.'>'; + } + + return $matches[0]; + } + + // -------------------------------------------------------------------- + + /** + * JS Link Removal + * + * Callback method for xss_clean() to sanitize links. + * + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on link-heavy strings. + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _js_link_removal($match) + { + return str_replace( + $match[1], + preg_replace( + '#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|_filter_attributes($match[1]) + ), + $match[0] + ); + } + + // -------------------------------------------------------------------- + + /** + * JS Image Removal + * + * Callback method for xss_clean() to sanitize image tags. + * + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on image tag heavy strings. + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _js_img_removal($match) + { + return str_replace( + $match[1], + preg_replace( + '#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|_filter_attributes($match[1]) + ), + $match[0] + ); + } + + // -------------------------------------------------------------------- + + /** + * Attribute Conversion + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _convert_attribute($match) + { + return str_replace(array('>', '<', '\\'), array('>', '<', '\\\\'), $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * Filter Attributes + * + * Filters tag attributes for consistency and safety. + * + * @used-by CI_Security::_js_img_removal() + * @used-by CI_Security::_js_link_removal() + * @param string $str + * @return string + */ + protected function _filter_attributes($str) + { + $out = ''; + if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) + { + foreach ($matches[0] as $match) + { + $out .= preg_replace('#/\*.*?\*/#s', '', $match); + } + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _decode_entity($match) + { + // Protect GET variables in URLs + // 901119URL5918AMP18930PROTECT8198 + $match = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-/]+)|i', $this->xss_hash().'\\1=\\2', $match[0]); + + // Decode, then un-protect URL GET vars + return str_replace( + $this->xss_hash(), + '&', + $this->entity_decode($match, $this->charset) + ); + } + + // -------------------------------------------------------------------- + + /** + * Do Never Allowed + * + * @used-by CI_Security::xss_clean() + * @param string + * @return string + */ + protected function _do_never_allowed($str) + { + $str = str_replace(array_keys($this->_never_allowed_str), $this->_never_allowed_str, $str); + + foreach ($this->_never_allowed_regex as $regex) + { + $str = preg_replace('#'.$regex.'#is', '[removed]', $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Set CSRF Hash and Cookie + * + * @return string + */ + protected function _csrf_set_hash() + { + if ($this->_csrf_hash === NULL) + { + // If the cookie exists we will use its value. + // We don't necessarily want to regenerate it with + // each page load since a page could contain embedded + // sub-pages causing this feature to fail + if (isset($_COOKIE[$this->_csrf_cookie_name]) && is_string($_COOKIE[$this->_csrf_cookie_name]) + && preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1) + { + return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; + } + + $rand = $this->get_random_bytes(16); + $this->_csrf_hash = ($rand === FALSE) + ? md5(uniqid(mt_rand(), TRUE)) + : bin2hex($rand); + } + + return $this->_csrf_hash; + } } - -/* End of file Security.php */ -/* Location: ./system/core/Security.php */ \ No newline at end of file diff --git a/system/core/URI.php b/system/core/URI.php old mode 100755 new mode 100644 index 21cf921..a8b98ae --- a/system/core/URI.php +++ b/system/core/URI.php @@ -1,655 +1,643 @@ -config =& load_class('Config', 'core'); - log_message('debug', "URI Class Initialized"); - } - - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _fetch_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // Is the request coming from the command line? - if (php_sapi_name() == 'cli' or defined('STDIN')) - { - $this->_set_uri_string($this->_parse_cli_args()); - return; - } - - // Let's try the REQUEST_URI first, this will work in most situations - if ($uri = $this->_detect_uri()) - { - $this->_set_uri_string($uri); - return; - } - - // Is there a PATH_INFO variable? - // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if (trim($path, '/') != '' && $path != "/".SELF) - { - $this->_set_uri_string($path); - return; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if (trim($path, '/') != '') - { - $this->_set_uri_string($path); - return; - } - - // As a last ditch effort lets try using the $_GET array - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') - { - $this->_set_uri_string(key($_GET)); - return; - } - - // We've exhausted all our options... - $this->uri_string = ''; - return; - } - - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - $this->_set_uri_string($this->_detect_uri()); - return; - } - elseif ($uri == 'CLI') - { - $this->_set_uri_string($this->_parse_cli_args()); - return; - } - - $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - $this->_set_uri_string($path); - } - - // -------------------------------------------------------------------- - - /** - * Set the URI String - * - * @access public - * @param string - * @return string - */ - function _set_uri_string($str) - { - // Filter out control characters - $str = remove_invisible_characters($str, FALSE); - - // If the URI contains only a slash we'll kill it - $this->uri_string = ($str == '/') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Detects the URI - * - * This function will detect the URI automatically and fix the query string - * if necessary. - * - * @access private - * @return string - */ - private function _detect_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME'])) - { - return ''; - } - - $uri = $_SERVER['REQUEST_URI']; - if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) - { - $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); - } - elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) - { - $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); - } - - // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct - // URI is found, and also fixes the QUERY_STRING server var and $_GET array. - if (strncmp($uri, '?/', 2) === 0) - { - $uri = substr($uri, 2); - } - $parts = preg_split('#\?#i', $uri, 2); - $uri = $parts[0]; - if (isset($parts[1])) - { - $_SERVER['QUERY_STRING'] = $parts[1]; - parse_str($_SERVER['QUERY_STRING'], $_GET); - } - else - { - $_SERVER['QUERY_STRING'] = ''; - $_GET = array(); - } - - if ($uri == '/' || empty($uri)) - { - return '/'; - } - - $uri = parse_url($uri, PHP_URL_PATH); - - // Do some final cleaning of the URI and return it - return str_replace(array('//', '../'), '/', trim($uri, '/')); - } - - // -------------------------------------------------------------------- - - /** - * Parse cli arguments - * - * Take each command line argument and assume it is a URI segment. - * - * @access private - * @return string - */ - private function _parse_cli_args() - { - $args = array_slice($_SERVER['argv'], 1); - - return $args ? '/' . implode('/', $args) : ''; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) - { - // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards - // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern - if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) - { - show_error('The URI you submitted has disallowed characters.', 400); - } - } - - // Convert programatic characters to entities - $bad = array('$', '(', ')', '%28', '%29'); - $good = array('$', '(', ')', '(', ')'); - - return str_replace($bad, $good, $str); - } - - // -------------------------------------------------------------------- - - /** - * Remove the suffix from the URL if needed - * - * @access private - * @return void - */ - function _remove_url_suffix() - { - if ($this->config->item('url_suffix') != "") - { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); - } - } - - // -------------------------------------------------------------------- - - /** - * Explode the URI Segments. The individual segments will - * be stored in the $this->segments array. - * - * @access private - * @return void - */ - function _explode_segments() - { - foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) - { - // Filter segments for security - $val = trim($this->_filter_uri($val)); - - if ($val != '') - { - $this->segments[] = $val; - } - } - } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather than 0. Doing so makes it simpler to - * use functions like $this->uri->segment(n) since there is - * a 1:1 relationship between the segment array and the actual segments. - * - * @access private - * @return void - */ - function _reindex_segments() - { - array_unshift($this->segments, NULL); - array_unshift($this->rsegments, NULL); - unset($this->segments[0]); - unset($this->rsegments[0]); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment - * - * This function returns the URI segment based on the number provided. - * - * @access public - * @param integer - * @param bool - * @return string - */ - function segment($n, $no_result = FALSE) - { - return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI "routed" Segment - * - * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the - * same result as $this->segment() - * - * @access public - * @param integer - * @param bool - * @return string - */ - function rsegment($n, $no_result = FALSE) - { - return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string - * - * This function generates and associative array of URI data starting - * at the supplied segment. For example, if this is your URI: - * - * example.com/user/search/name/joe/location/UK/gender/male - * - * You can use this function to generate an array with this prototype: - * - * array ( - * name => joe - * location => UK - * gender => male - * ) - * - * @access public - * @param integer the starting segment number - * @param array an array of default values - * @return array - */ - function uri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'segment'); - } - /** - * Identical to above only it uses the re-routed segment array - * - * @access public - * @param integer the starting segment number - * @param array an array of default values - * @return array - * - */ - function ruri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string or Re-routed URI string - * - * @access private - * @param integer the starting segment number - * @param array an array of default values - * @param string which array we should use - * @return array - */ - function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') - { - if ($which == 'segment') - { - $total_segments = 'total_segments'; - $segment_array = 'segment_array'; - } - else - { - $total_segments = 'total_rsegments'; - $segment_array = 'rsegment_array'; - } - - if ( ! is_numeric($n)) - { - return $default; - } - - if (isset($this->keyval[$n])) - { - return $this->keyval[$n]; - } - - if ($this->$total_segments() < $n) - { - if (count($default) == 0) - { - return array(); - } - - $retval = array(); - foreach ($default as $val) - { - $retval[$val] = FALSE; - } - return $retval; - } - - $segments = array_slice($this->$segment_array(), ($n - 1)); - - $i = 0; - $lastval = ''; - $retval = array(); - foreach ($segments as $seg) - { - if ($i % 2) - { - $retval[$lastval] = $seg; - } - else - { - $retval[$seg] = FALSE; - $lastval = $seg; - } - - $i++; - } - - if (count($default) > 0) - { - foreach ($default as $val) - { - if ( ! array_key_exists($val, $retval)) - { - $retval[$val] = FALSE; - } - } - } - - // Cache the array for reuse - $this->keyval[$n] = $retval; - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Generate a URI string from an associative array - * - * - * @access public - * @param array an associative array of key/values - * @return array - */ - function assoc_to_uri($array) - { - $temp = array(); - foreach ((array)$array as $key => $val) - { - $temp[] = $key; - $temp[] = $val; - } - - return implode('/', $temp); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_segment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'segment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_rsegment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - helper function - * - * @access private - * @param integer - * @param string - * @param string - * @return string - */ - function _slash_segment($n, $where = 'trailing', $which = 'segment') - { - $leading = '/'; - $trailing = '/'; - - if ($where == 'trailing') - { - $leading = ''; - } - elseif ($where == 'leading') - { - $trailing = ''; - } - - return $leading.$this->$which($n).$trailing; - } - - // -------------------------------------------------------------------- - - /** - * Segment Array - * - * @access public - * @return array - */ - function segment_array() - { - return $this->segments; - } - - // -------------------------------------------------------------------- - - /** - * Routed Segment Array - * - * @access public - * @return array - */ - function rsegment_array() - { - return $this->rsegments; - } - - // -------------------------------------------------------------------- - - /** - * Total number of segments - * - * @access public - * @return integer - */ - function total_segments() - { - return count($this->segments); - } - - // -------------------------------------------------------------------- - - /** - * Total number of routed segments - * - * @access public - * @return integer - */ - function total_rsegments() - { - return count($this->rsegments); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the entire URI string - * - * @access public - * @return string - */ - function uri_string() - { - return $this->uri_string; - } - - - // -------------------------------------------------------------------- - - /** - * Fetch the entire Re-routed URI string - * - * @access public - * @return string - */ - function ruri_string() - { - return '/'.implode('/', $this->rsegment_array()); - } + /** + * List of cached URI segments + * + * @var array + */ + public $keyval = array(); + + /** + * Current URI string + * + * @var string + */ + public $uri_string = ''; + + /** + * List of URI segments + * + * Starts at 1 instead of 0. + * + * @var array + */ + public $segments = array(); + + /** + * List of routed URI segments + * + * Starts at 1 instead of 0. + * + * @var array + */ + public $rsegments = array(); + + /** + * Permitted URI chars + * + * PCRE character group allowed in URI segments + * + * @var string + */ + protected $_permitted_uri_chars; + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $this->config =& load_class('Config', 'core'); + + // If query strings are enabled, we don't need to parse any segments. + // However, they don't make sense under CLI. + if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE) + { + $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars'); + + // If it's a CLI request, ignore the configuration + if (is_cli()) + { + $uri = $this->_parse_argv(); + } + else + { + $protocol = $this->config->item('uri_protocol'); + empty($protocol) && $protocol = 'REQUEST_URI'; + + switch ($protocol) + { + case 'AUTO': // For BC purposes only + case 'REQUEST_URI': + $uri = $this->_parse_request_uri(); + break; + case 'QUERY_STRING': + $uri = $this->_parse_query_string(); + break; + case 'PATH_INFO': + default: + $uri = isset($_SERVER[$protocol]) + ? $_SERVER[$protocol] + : $this->_parse_request_uri(); + break; + } + } + + $this->_set_uri_string($uri); + } + + log_message('info', 'URI Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set URI String + * + * @param string $str + * @return void + */ + protected function _set_uri_string($str) + { + // Filter out control characters and trim slashes + $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); + + if ($this->uri_string !== '') + { + // Remove the URL suffix, if present + if (($suffix = (string) $this->config->item('url_suffix')) !== '') + { + $slen = strlen($suffix); + + if (substr($this->uri_string, -$slen) === $suffix) + { + $this->uri_string = substr($this->uri_string, 0, -$slen); + } + } + + $this->segments[0] = NULL; + // Populate the segments array + foreach (explode('/', trim($this->uri_string, '/')) as $val) + { + $val = trim($val); + // Filter segments for security + $this->filter_uri($val); + + if ($val !== '') + { + $this->segments[] = $val; + } + } + + unset($this->segments[0]); + } + } + + // -------------------------------------------------------------------- + + /** + * Parse REQUEST_URI + * + * Will parse REQUEST_URI and automatically detect the URI from it, + * while fixing the query string if necessary. + * + * @return string + */ + protected function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) + { + return ''; + } + + // parse_url() returns false if no host is present, but the path or query string + // contains a colon followed by a number + $uri = parse_url('http://dummy'.$_SERVER['REQUEST_URI']); + $query = isset($uri['query']) ? $uri['query'] : ''; + $uri = isset($uri['path']) ? $uri['path'] : ''; + + if (isset($_SERVER['SCRIPT_NAME'][0])) + { + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + { + $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + } + elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + { + $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + } + } + + // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct + // URI is found, and also fixes the QUERY_STRING server var and $_GET array. + if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) + { + $query = explode('?', $query, 2); + $uri = $query[0]; + $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : ''; + } + else + { + $_SERVER['QUERY_STRING'] = $query; + } + + parse_str($_SERVER['QUERY_STRING'], $_GET); + + if ($uri === '/' OR $uri === '') + { + return '/'; + } + + // Do some final cleaning of the URI and return it + return $this->_remove_relative_directory($uri); + } + + // -------------------------------------------------------------------- + + /** + * Parse QUERY_STRING + * + * Will parse QUERY_STRING and automatically detect the URI from it. + * + * @return string + */ + protected function _parse_query_string() + { + $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + + if (trim($uri, '/') === '') + { + return ''; + } + elseif (strncmp($uri, '/', 1) === 0) + { + $uri = explode('?', $uri, 2); + $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : ''; + $uri = $uri[0]; + } + + parse_str($_SERVER['QUERY_STRING'], $_GET); + + return $this->_remove_relative_directory($uri); + } + + // -------------------------------------------------------------------- + + /** + * Parse CLI arguments + * + * Take each command line argument and assume it is a URI segment. + * + * @return string + */ + protected function _parse_argv() + { + $args = array_slice($_SERVER['argv'], 1); + return $args ? implode('/', $args) : ''; + } + + // -------------------------------------------------------------------- + + /** + * Remove relative directory (../) and multi slashes (///) + * + * Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri() + * + * @param string $uri + * @return string + */ + protected function _remove_relative_directory($uri) + { + $uris = array(); + $tok = strtok($uri, '/'); + while ($tok !== FALSE) + { + if (( ! empty($tok) OR $tok === '0') && $tok !== '..') + { + $uris[] = $tok; + } + $tok = strtok('/'); + } + + return implode('/', $uris); + } + + // -------------------------------------------------------------------- + + /** + * Filter URI + * + * Filters segments for malicious characters. + * + * @param string $str + * @return void + */ + public function filter_uri(&$str) + { + if ( ! empty($str) && ! empty($this->_permitted_uri_chars) && ! preg_match('/^['.$this->_permitted_uri_chars.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $str)) + { + show_error('The URI you submitted has disallowed characters.', 400); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI Segment + * + * @see CI_URI::$segments + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed + */ + public function segment($n, $no_result = NULL) + { + return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI "routed" Segment + * + * Returns the re-routed URI segment (assuming routing rules are used) + * based on the index provided. If there is no routing, will return + * the same result as CI_URI::segment(). + * + * @see CI_URI::$rsegments + * @see CI_URI::segment() + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed + */ + public function rsegment($n, $no_result = NULL) + { + return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; + } + + // -------------------------------------------------------------------- + + /** + * URI to assoc + * + * Generates an associative array of URI data starting at the supplied + * segment index. For example, if this is your URI: + * + * example.com/user/search/name/joe/location/UK/gender/male + * + * You can use this method to generate an array with this prototype: + * + * array ( + * name => joe + * location => UK + * gender => male + * ) + * + * @param int $n Index (default: 3) + * @param array $default Default values + * @return array + */ + public function uri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Routed URI to assoc + * + * Identical to CI_URI::uri_to_assoc(), only it uses the re-routed + * segment array. + * + * @see CI_URI::uri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values + * @return array + */ + public function ruri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Internal URI-to-assoc + * + * Generates a key/value pair from the URI string or re-routed URI string. + * + * @used-by CI_URI::uri_to_assoc() + * @used-by CI_URI::ruri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values + * @param string $which Array name ('segment' or 'rsegment') + * @return array + */ + protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') + { + if ( ! is_numeric($n)) + { + return $default; + } + + if (isset($this->keyval[$which], $this->keyval[$which][$n])) + { + return $this->keyval[$which][$n]; + } + + $total_segments = "total_{$which}s"; + $segment_array = "{$which}_array"; + + if ($this->$total_segments() < $n) + { + return (count($default) === 0) + ? array() + : array_fill_keys($default, NULL); + } + + $segments = array_slice($this->$segment_array(), ($n - 1)); + $i = 0; + $lastval = ''; + $retval = array(); + foreach ($segments as $seg) + { + if ($i % 2) + { + $retval[$lastval] = $seg; + } + else + { + $retval[$seg] = NULL; + $lastval = $seg; + } + + $i++; + } + + if (count($default) > 0) + { + foreach ($default as $val) + { + if ( ! array_key_exists($val, $retval)) + { + $retval[$val] = NULL; + } + } + } + + // Cache the array for reuse + isset($this->keyval[$which]) OR $this->keyval[$which] = array(); + $this->keyval[$which][$n] = $retval; + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Assoc to URI + * + * Generates a URI string from an associative array. + * + * @param array $array Input array of key/value pairs + * @return string URI string + */ + public function assoc_to_uri($array) + { + $temp = array(); + foreach ((array) $array as $key => $val) + { + $temp[] = $key; + $temp[] = $val; + } + + return implode('/', $temp); + } + + // -------------------------------------------------------------------- + + /** + * Slash segment + * + * Fetches an URI segment with a slash. + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @return string + */ + public function slash_segment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Slash routed segment + * + * Fetches an URI routed segment with a slash. + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @return string + */ + public function slash_rsegment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Internal Slash segment + * + * Fetches an URI Segment and adds a slash to it. + * + * @used-by CI_URI::slash_segment() + * @used-by CI_URI::slash_rsegment() + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @param string $which Array name ('segment' or 'rsegment') + * @return string + */ + protected function _slash_segment($n, $where = 'trailing', $which = 'segment') + { + $leading = $trailing = '/'; + + if ($where === 'trailing') + { + $leading = ''; + } + elseif ($where === 'leading') + { + $trailing = ''; + } + + return $leading.$this->$which($n).$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @return array CI_URI::$segments + */ + public function segment_array() + { + return $this->segments; + } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @return array CI_URI::$rsegments + */ + public function rsegment_array() + { + return $this->rsegments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @return int + */ + public function total_segments() + { + return count($this->segments); + } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @return int + */ + public function total_rsegments() + { + return count($this->rsegments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI string + * + * @return string CI_URI::$uri_string + */ + public function uri_string() + { + return $this->uri_string; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Re-routed URI string + * + * @return string + */ + public function ruri_string() + { + return ltrim(load_class('Router', 'core')->directory, '/').implode('/', $this->rsegments); + } } -// END URI Class - -/* End of file URI.php */ -/* Location: ./system/core/URI.php */ \ No newline at end of file diff --git a/system/core/Utf8.php b/system/core/Utf8.php old mode 100755 new mode 100644 index 9ecc4dd..9ee63e9 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -1,166 +1,164 @@ -item('charset') == 'UTF-8' // Application charset must be UTF-8 - ) - { - log_message('debug', "UTF-8 Support Enabled"); - - define('UTF8_ENABLED', TRUE); - - // set internal encoding for multibyte string functions if necessary - // and set a flag so we don't have to repeatedly use extension_loaded() - // or function_exists() - if (extension_loaded('mbstring')) - { - define('MB_ENABLED', TRUE); - mb_internal_encoding('UTF-8'); - } - else - { - define('MB_ENABLED', FALSE); - } - } - else - { - log_message('debug', "UTF-8 Support Disabled"); - define('UTF8_ENABLED', FALSE); - } - } - - // -------------------------------------------------------------------- - - /** - * Clean UTF-8 strings - * - * Ensures strings are UTF-8 - * - * @access public - * @param string - * @return string - */ - function clean_string($str) - { - if ($this->_is_ascii($str) === FALSE) - { - $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Remove ASCII control characters - * - * Removes all ASCII control characters except horizontal tabs, - * line feeds, and carriage returns, as all others can cause - * problems in XML - * - * @access public - * @param string - * @return string - */ - function safe_ascii_for_xml($str) - { - return remove_invisible_characters($str, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Convert to UTF-8 - * - * Attempts to convert a string to UTF-8 - * - * @access public - * @param string - * @param string - input encoding - * @return string - */ - function convert_to_utf8($str, $encoding) - { - if (function_exists('iconv')) - { - $str = @iconv($encoding, 'UTF-8', $str); - } - elseif (function_exists('mb_convert_encoding')) - { - $str = @mb_convert_encoding($str, 'UTF-8', $encoding); - } - else - { - return FALSE; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Is ASCII? - * - * Tests if a string is standard 7-bit ASCII or not - * - * @access public - * @param string - * @return bool - */ - function _is_ascii($str) - { - return (preg_match('/[^\x00-\x7F]/S', $str) == 0); - } - - // -------------------------------------------------------------------- + /** + * Class constructor + * + * Determines if UTF-8 support is to be enabled. + * + * @return void + */ + public function __construct() + { + if ( + defined('PREG_BAD_UTF8_ERROR') // PCRE must support UTF-8 + && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) // iconv or mbstring must be installed + && strtoupper(config_item('charset')) === 'UTF-8' // Application charset must be UTF-8 + ) + { + define('UTF8_ENABLED', TRUE); + log_message('debug', 'UTF-8 Support Enabled'); + } + else + { + define('UTF8_ENABLED', FALSE); + log_message('debug', 'UTF-8 Support Disabled'); + } + + log_message('info', 'Utf8 Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Clean UTF-8 strings + * + * Ensures strings contain only valid UTF-8 characters. + * + * @param string $str String to clean + * @return string + */ + public function clean_string($str) + { + if ($this->is_ascii($str) === FALSE) + { + if (MB_ENABLED) + { + $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8'); + } + elseif (ICONV_ENABLED) + { + $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str); + } + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Remove ASCII control characters + * + * Removes all ASCII control characters except horizontal tabs, + * line feeds, and carriage returns, as all others can cause + * problems in XML. + * + * @param string $str String to clean + * @return string + */ + public function safe_ascii_for_xml($str) + { + return remove_invisible_characters($str, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Convert to UTF-8 + * + * Attempts to convert a string to UTF-8. + * + * @param string $str Input string + * @param string $encoding Input encoding + * @return string $str encoded in UTF-8 or FALSE on failure + */ + public function convert_to_utf8($str, $encoding) + { + if (MB_ENABLED) + { + return mb_convert_encoding($str, 'UTF-8', $encoding); + } + elseif (ICONV_ENABLED) + { + return @iconv($encoding, 'UTF-8', $str); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Is ASCII? + * + * Tests if a string is standard 7-bit ASCII or not. + * + * @param string $str String to check + * @return bool + */ + public function is_ascii($str) + { + return (preg_match('/[^\x00-\x7F]/S', $str) === 0); + } } -// End Utf8 Class - -/* End of file Utf8.php */ -/* Location: ./system/core/Utf8.php */ \ No newline at end of file diff --git a/system/core/compat/hash.php b/system/core/compat/hash.php new file mode 100644 index 0000000..8f5510c --- /dev/null +++ b/system/core/compat/hash.php @@ -0,0 +1,254 @@ + 32, + 'haval128,3' => 128, + 'haval160,3' => 128, + 'haval192,3' => 128, + 'haval224,3' => 128, + 'haval256,3' => 128, + 'haval128,4' => 128, + 'haval160,4' => 128, + 'haval192,4' => 128, + 'haval224,4' => 128, + 'haval256,4' => 128, + 'haval128,5' => 128, + 'haval160,5' => 128, + 'haval192,5' => 128, + 'haval224,5' => 128, + 'haval256,5' => 128, + 'md2' => 16, + 'md4' => 64, + 'md5' => 64, + 'ripemd128' => 64, + 'ripemd160' => 64, + 'ripemd256' => 64, + 'ripemd320' => 64, + 'salsa10' => 64, + 'salsa20' => 64, + 'sha1' => 64, + 'sha224' => 64, + 'sha256' => 64, + 'sha384' => 128, + 'sha512' => 128, + 'snefru' => 32, + 'snefru256' => 32, + 'tiger128,3' => 64, + 'tiger160,3' => 64, + 'tiger192,3' => 64, + 'tiger128,4' => 64, + 'tiger160,4' => 64, + 'tiger192,4' => 64, + 'whirlpool' => 64 + ); + + if (isset($block_sizes[$algo], $password[$block_sizes[$algo]])) + { + $password = hash($algo, $password, TRUE); + } + + $hash = ''; + // Note: Blocks are NOT 0-indexed + for ($bc = (int) ceil($length / $hash_length), $bi = 1; $bi <= $bc; $bi++) + { + $key = $derived_key = hash_hmac($algo, $salt.pack('N', $bi), $password, TRUE); + for ($i = 1; $i < $iterations; $i++) + { + $derived_key ^= $key = hash_hmac($algo, $key, $password, TRUE); + } + + $hash .= $derived_key; + } + + // This is not RFC-compatible, but we're aiming for natural PHP compatibility + if ( ! $raw_output) + { + $hash = bin2hex($hash); + } + + return defined('MB_OVERLOAD_STRING') + ? mb_substr($hash, 0, $length, '8bit') + : substr($hash, 0, $length); + } +} diff --git a/system/core/compat/index.html b/system/core/compat/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/core/compat/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/system/core/compat/mbstring.php b/system/core/compat/mbstring.php new file mode 100644 index 0000000..552e727 --- /dev/null +++ b/system/core/compat/mbstring.php @@ -0,0 +1,149 @@ + 0, 'algoName' => 'unknown', 'options' => array()) + : array('algo' => 1, 'algoName' => 'bcrypt', 'options' => array('cost' => $hash)); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_hash')) +{ + /** + * password_hash() + * + * @link http://php.net/password_hash + * @param string $password + * @param int $algo + * @param array $options + * @return mixed + */ + function password_hash($password, $algo, array $options = array()) + { + static $func_overload; + isset($func_overload) OR $func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + if ($algo !== 1) + { + trigger_error('password_hash(): Unknown hashing algorithm: '.(int) $algo, E_USER_WARNING); + return NULL; + } + + if (isset($options['cost']) && ($options['cost'] < 4 OR $options['cost'] > 31)) + { + trigger_error('password_hash(): Invalid bcrypt cost parameter specified: '.(int) $options['cost'], E_USER_WARNING); + return NULL; + } + + if (isset($options['salt']) && ($saltlen = ($func_overload ? mb_strlen($options['salt'], '8bit') : strlen($options['salt']))) < 22) + { + trigger_error('password_hash(): Provided salt is too short: '.$saltlen.' expecting 22', E_USER_WARNING); + return NULL; + } + elseif ( ! isset($options['salt'])) + { + if (function_exists('random_bytes')) + { + try + { + $options['salt'] = random_bytes(16); + } + catch (Exception $e) + { + log_message('error', 'compat/password: Error while trying to use random_bytes(): '.$e->getMessage()); + return FALSE; + } + } + elseif (defined('MCRYPT_DEV_URANDOM')) + { + $options['salt'] = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); + } + elseif (DIRECTORY_SEPARATOR === '/' && (is_readable($dev = '/dev/arandom') OR is_readable($dev = '/dev/urandom'))) + { + if (($fp = fopen($dev, 'rb')) === FALSE) + { + log_message('error', 'compat/password: Unable to open '.$dev.' for reading.'); + return FALSE; + } + + // Try not to waste entropy ... + is_php('5.4') && stream_set_chunk_size($fp, 16); + + $options['salt'] = ''; + for ($read = 0; $read < 16; $read = ($func_overload) ? mb_strlen($options['salt'], '8bit') : strlen($options['salt'])) + { + if (($read = fread($fp, 16 - $read)) === FALSE) + { + log_message('error', 'compat/password: Error while reading from '.$dev.'.'); + return FALSE; + } + $options['salt'] .= $read; + } + + fclose($fp); + } + elseif (function_exists('openssl_random_pseudo_bytes')) + { + $is_secure = NULL; + $options['salt'] = openssl_random_pseudo_bytes(16, $is_secure); + if ($is_secure !== TRUE) + { + log_message('error', 'compat/password: openssl_random_pseudo_bytes() set the $cryto_strong flag to FALSE'); + return FALSE; + } + } + else + { + log_message('error', 'compat/password: No CSPRNG available.'); + return FALSE; + } + + $options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '=')); + } + elseif ( ! preg_match('#^[a-zA-Z0-9./]+$#D', $options['salt'])) + { + $options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '=')); + } + + isset($options['cost']) OR $options['cost'] = 10; + + return (strlen($password = crypt($password, sprintf('$2y$%02d$%s', $options['cost'], $options['salt']))) === 60) + ? $password + : FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_needs_rehash')) +{ + /** + * password_needs_rehash() + * + * @link http://php.net/password_needs_rehash + * @param string $hash + * @param int $algo + * @param array $options + * @return bool + */ + function password_needs_rehash($hash, $algo, array $options = array()) + { + $info = password_get_info($hash); + + if ($algo !== $info['algo']) + { + return TRUE; + } + elseif ($algo === 1) + { + $options['cost'] = isset($options['cost']) ? (int) $options['cost'] : 10; + return ($info['options']['cost'] !== $options['cost']); + } + + // Odd at first glance, but according to a comment in PHP's own unit tests, + // because it is an unknown algorithm - it's valid and therefore doesn't + // need rehashing. + return FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_verify')) +{ + /** + * password_verify() + * + * @link http://php.net/password_verify + * @param string $password + * @param string $hash + * @return bool + */ + function password_verify($password, $hash) + { + if (strlen($hash) !== 60 OR strlen($password = crypt($password, $hash)) !== 60) + { + return FALSE; + } + + $compare = 0; + for ($i = 0; $i < 60; $i++) + { + $compare |= (ord($password[$i]) ^ ord($hash[$i])); + } + + return ($compare === 0); + } +} diff --git a/system/core/compat/standard.php b/system/core/compat/standard.php new file mode 100644 index 0000000..2c528fd --- /dev/null +++ b/system/core/compat/standard.php @@ -0,0 +1,182 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/DB.php b/system/database/DB.php old mode 100755 new mode 100644 index cd0d5b9..02e0e1d --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,163 +1,218 @@ - $dns['scheme'], - 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', - 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', - 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', - 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' - ); - - // were additional config items set? - if (isset($dns['query'])) - { - parse_str($dns['query'], $extra); - - foreach ($extra as $key => $val) - { - // booleans please - if (strtoupper($val) == "TRUE") - { - $val = TRUE; - } - elseif (strtoupper($val) == "FALSE") - { - $val = FALSE; - } - - $params[$key] = $val; - } - } - } - - // No DB specified yet? Beat them senseless... - if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') - { - show_error('You have not selected a database type to connect to.'); - } - - // Load the DB classes. Note: Since the active record class is optional - // we need to dynamically create a class that extends proper parent class - // based on whether we're using the active record class or not. - // Kudos to Paul for discovering this clever use of eval() - - if ($active_record_override !== NULL) - { - $active_record = $active_record_override; - } - - require_once(BASEPATH.'database/DB_driver.php'); - - if ( ! isset($active_record) OR $active_record == TRUE) - { - require_once(BASEPATH.'database/DB_active_rec.php'); - - if ( ! class_exists('CI_DB')) - { - eval('class CI_DB extends CI_DB_active_record { }'); - } - } - else - { - if ( ! class_exists('CI_DB')) - { - eval('class CI_DB extends CI_DB_driver { }'); - } - } - - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); - - // Instantiate the DB adapter - $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); - - if ($DB->autoinit == TRUE) - { - $DB->initialize(); - } - - if (isset($params['stricton']) && $params['stricton'] == TRUE) - { - $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); - } - - return $DB; + // Load the DB config file if a DSN string wasn't passed + if (is_string($params) && strpos($params, '://') === FALSE) + { + // Is the config file in the environment folder? + if ( ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php') + && ! file_exists($file_path = APPPATH.'config/database.php')) + { + show_error('The configuration file database.php does not exist.'); + } + + include($file_path); + + // Make packages contain database config files, + // given that the controller instance already exists + if (class_exists('CI_Controller', FALSE)) + { + foreach (get_instance()->load->get_package_paths() as $path) + { + if ($path !== APPPATH) + { + if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php')) + { + include($file_path); + } + elseif (file_exists($file_path = $path.'config/database.php')) + { + include($file_path); + } + } + } + } + + if ( ! isset($db) OR count($db) === 0) + { + show_error('No database connection settings were found in the database config file.'); + } + + if ($params !== '') + { + $active_group = $params; + } + + if ( ! isset($active_group)) + { + show_error('You have not specified a database connection group via $active_group in your config/database.php file.'); + } + elseif ( ! isset($db[$active_group])) + { + show_error('You have specified an invalid database connection group ('.$active_group.') in your config/database.php file.'); + } + + $params = $db[$active_group]; + } + elseif (is_string($params)) + { + /** + * Parse the URL from the DSN string + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + if (($dsn = @parse_url($params)) === FALSE) + { + show_error('Invalid DB Connection String'); + } + + $params = array( + 'dbdriver' => $dsn['scheme'], + 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '', + 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '', + 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '', + 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '', + 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : '' + ); + + // Were additional config items set? + if (isset($dsn['query'])) + { + parse_str($dsn['query'], $extra); + + foreach ($extra as $key => $val) + { + if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL'))) + { + $val = var_export($val, TRUE); + } + + $params[$key] = $val; + } + } + } + + // No DB specified yet? Beat them senseless... + if (empty($params['dbdriver'])) + { + show_error('You have not selected a database type to connect to.'); + } + + // Load the DB classes. Note: Since the query builder class is optional + // we need to dynamically create a class that extends proper parent class + // based on whether we're using the query builder class or not. + if ($query_builder_override !== NULL) + { + $query_builder = $query_builder_override; + } + // Backwards compatibility work-around for keeping the + // $active_record config variable working. Should be + // removed in v3.1 + elseif ( ! isset($query_builder) && isset($active_record)) + { + $query_builder = $active_record; + } + + require_once(BASEPATH.'database/DB_driver.php'); + + if ( ! isset($query_builder) OR $query_builder === TRUE) + { + require_once(BASEPATH.'database/DB_query_builder.php'); + if ( ! class_exists('CI_DB', FALSE)) + { + /** + * CI_DB + * + * Acts as an alias for both CI_DB_driver and CI_DB_query_builder. + * + * @see CI_DB_query_builder + * @see CI_DB_driver + */ + class CI_DB extends CI_DB_query_builder { } + } + } + elseif ( ! class_exists('CI_DB', FALSE)) + { + /** + * @ignore + */ + class CI_DB extends CI_DB_driver { } + } + + // Load the DB driver + $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'; + + file_exists($driver_file) OR show_error('Invalid DB driver'); + require_once($driver_file); + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; + $DB = new $driver($params); + + // Check for a subdriver + if ( ! empty($DB->subdriver)) + { + $driver_file = BASEPATH.'database/drivers/'.$DB->dbdriver.'/subdrivers/'.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php'; + + if (file_exists($driver_file)) + { + require_once($driver_file); + $driver = 'CI_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver'; + $DB = new $driver($params); + } + } + + $DB->initialize(); + return $DB; } - - - -/* End of file DB.php */ -/* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php deleted file mode 100755 index acd623c..0000000 --- a/system/database/DB_active_rec.php +++ /dev/null @@ -1,2046 +0,0 @@ -ar_select[] = $val; - $this->ar_no_escape[] = $escape; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $val; - $this->ar_cache_exists[] = 'select'; - $this->ar_cache_no_escape[] = $escape; - } - } - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Select Max - * - * Generates a SELECT MAX(field) portion of a query - * - * @param string the field - * @param string an alias - * @return object - */ - public function select_max($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'MAX'); - } - - // -------------------------------------------------------------------- - - /** - * Select Min - * - * Generates a SELECT MIN(field) portion of a query - * - * @param string the field - * @param string an alias - * @return object - */ - public function select_min($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'MIN'); - } - - // -------------------------------------------------------------------- - - /** - * Select Average - * - * Generates a SELECT AVG(field) portion of a query - * - * @param string the field - * @param string an alias - * @return object - */ - public function select_avg($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'AVG'); - } - - // -------------------------------------------------------------------- - - /** - * Select Sum - * - * Generates a SELECT SUM(field) portion of a query - * - * @param string the field - * @param string an alias - * @return object - */ - public function select_sum($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'SUM'); - } - - // -------------------------------------------------------------------- - - /** - * Processing Function for the four functions above: - * - * select_max() - * select_min() - * select_avg() - * select_sum() - * - * @param string the field - * @param string an alias - * @return object - */ - protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') - { - if ( ! is_string($select) OR $select == '') - { - $this->display_error('db_invalid_query'); - } - - $type = strtoupper($type); - - if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) - { - show_error('Invalid function type: '.$type); - } - - if ($alias == '') - { - $alias = $this->_create_alias_from_table(trim($select)); - } - - $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; - - $this->ar_select[] = $sql; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $sql; - $this->ar_cache_exists[] = 'select'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Determines the alias name based on the table - * - * @param string - * @return string - */ - protected function _create_alias_from_table($item) - { - if (strpos($item, '.') !== FALSE) - { - return end(explode('.', $item)); - } - - return $item; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @param bool - * @return object - */ - public function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @param mixed can be a string or array - * @return object - */ - public function from($from) - { - foreach ((array) $from as $val) - { - if (strpos($val, ',') !== FALSE) - { - foreach (explode(',', $val) as $v) - { - $v = trim($v); - $this->_track_aliases($v); - - $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - $this->ar_cache_exists[] = 'from'; - } - } - - } - else - { - $val = trim($val); - - // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix - $this->_track_aliases($val); - - $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - $this->ar_cache_exists[] = 'from'; - } - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - public function join($table, $cond, $type = '') - { - if ($type != '') - { - $type = strtoupper(trim($type)); - - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) - { - $type = ''; - } - else - { - $type .= ' '; - } - } - - // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix - $this->_track_aliases($table); - - // Strip apart the condition and protect the identifiers - if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match)) - { - $match[1] = $this->_protect_identifiers($match[1]); - $match[3] = $this->_protect_identifiers($match[3]); - - $cond = $match[1].$match[2].$match[3]; - } - - // Assemble the JOIN statement - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; - - $this->ar_join[] = $join; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_join[] = $join; - $this->ar_cache_exists[] = 'join'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @param mixed - * @param mixed - * @return object - */ - public function where($key, $value = NULL, $escape = TRUE) - { - return $this->_where($key, $value, 'AND ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @param mixed - * @param mixed - * @return object - */ - public function or_where($key, $value = NULL, $escape = TRUE) - { - return $this->_where($key, $value, 'OR ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or or_where() - * - * @param mixed - * @param mixed - * @param string - * @return object - */ - protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - // If the escape value was not set will will base it on the global setting - if ( ! is_bool($escape)) - { - $escape = $this->_protect_identifiers; - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; - - if (is_null($v) && ! $this->_has_operator($k)) - { - // value appears not to have been set, assign the test to IS NULL - $k .= ' IS NULL'; - } - - if ( ! is_null($v)) - { - if ($escape === TRUE) - { - $k = $this->_protect_identifiers($k, FALSE, $escape); - - $v = ' '.$this->escape($v); - } - - if ( ! $this->_has_operator($k)) - { - $k .= ' = '; - } - } - else - { - $k = $this->_protect_identifiers($k, FALSE, $escape); - } - - $this->ar_where[] = $prefix.$k.$v; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_where[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'where'; - } - - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where_in - * - * Generates a WHERE field IN ('item', 'item') SQL query joined with - * AND if appropriate - * - * @param string The field to search - * @param array The values searched on - * @return object - */ - public function where_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values); - } - - // -------------------------------------------------------------------- - - /** - * Where_in_or - * - * Generates a WHERE field IN ('item', 'item') SQL query joined with - * OR if appropriate - * - * @param string The field to search - * @param array The values searched on - * @return object - */ - public function or_where_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, FALSE, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where_not_in - * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined - * with AND if appropriate - * - * @param string The field to search - * @param array The values searched on - * @return object - */ - public function where_not_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Where_not_in_or - * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined - * with OR if appropriate - * - * @param string The field to search - * @param array The values searched on - * @return object - */ - public function or_where_not_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, TRUE, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where_in - * - * Called by where_in, where_in_or, where_not_in, where_not_in_or - * - * @param string The field to search - * @param array The values searched on - * @param boolean If the statement would be IN or NOT IN - * @param string - * @return object - */ - protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') - { - if ($key === NULL OR $values === NULL) - { - return; - } - - if ( ! is_array($values)) - { - $values = array($values); - } - - $not = ($not) ? ' NOT' : ''; - - foreach ($values as $value) - { - $this->ar_wherein[] = $this->escape($value); - } - - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; - - $this->ar_where[] = $where_in; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_where[] = $where_in; - $this->ar_cache_exists[] = 'where'; - } - - // reset the array for multiple calls - $this->ar_wherein = array(); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @param mixed - * @param mixed - * @return object - */ - public function like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'AND ', $side); - } - - // -------------------------------------------------------------------- - - /** - * Not Like - * - * Generates a NOT LIKE portion of the query. Separates - * multiple calls with AND - * - * @param mixed - * @param mixed - * @return object - */ - public function not_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'AND ', $side, 'NOT'); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @param mixed - * @param mixed - * @return object - */ - public function or_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'OR ', $side); - } - - // -------------------------------------------------------------------- - - /** - * OR Not Like - * - * Generates a NOT LIKE portion of the query. Separates - * multiple calls with OR - * - * @param mixed - * @param mixed - * @return object - */ - public function or_not_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'OR ', $side, 'NOT'); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @param mixed - * @param mixed - * @param string - * @return object - */ - protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $k = $this->_protect_identifiers($k); - - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_like_str($v); - - if ($side == 'none') - { - $like_statement = $prefix." $k $not LIKE '{$v}'"; - } - elseif ($side == 'before') - { - $like_statement = $prefix." $k $not LIKE '%{$v}'"; - } - elseif ($side == 'after') - { - $like_statement = $prefix." $k $not LIKE '{$v}%'"; - } - else - { - $like_statement = $prefix." $k $not LIKE '%{$v}%'"; - } - - // some platforms require an escape sequence definition for LIKE wildcards - if ($this->_like_escape_str != '') - { - $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); - } - - $this->ar_like[] = $like_statement; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_like[] = $like_statement; - $this->ar_cache_exists[] = 'like'; - } - - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @param string - * @return object - */ - public function group_by($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - { - $this->ar_groupby[] = $this->_protect_identifiers($val); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_groupby[] = $this->_protect_identifiers($val); - $this->ar_cache_exists[] = 'groupby'; - } - } - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @param string - * @param string - * @return object - */ - public function having($key, $value = '', $escape = TRUE) - { - return $this->_having($key, $value, 'AND ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @param string - * @param string - * @return object - */ - public function or_having($key, $value = '', $escape = TRUE) - { - return $this->_having($key, $value, 'OR ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or or_having() - * - * @param string - * @param string - * @return object - */ - protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE) - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($escape === TRUE) - { - $k = $this->_protect_identifiers($k); - } - - if ( ! $this->_has_operator($k)) - { - $k .= ' = '; - } - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_having[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'having'; - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @param string - * @param string direction: asc or desc - * @return object - */ - public function order_by($orderby, $direction = '') - { - if (strtolower($direction) == 'random') - { - $orderby = ''; // Random results want or don't need a field name - $direction = $this->_random_keyword; - } - elseif (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; - } - - - if (strpos($orderby, ',') !== FALSE) - { - $temp = array(); - foreach (explode(',', $orderby) as $part) - { - $part = trim($part); - if ( ! in_array($part, $this->ar_aliased_tables)) - { - $part = $this->_protect_identifiers(trim($part)); - } - - $temp[] = $part; - } - - $orderby = implode(', ', $temp); - } - else if ($direction != $this->_random_keyword) - { - $orderby = $this->_protect_identifiers($orderby); - } - - $orderby_statement = $orderby.$direction; - - $this->ar_orderby[] = $orderby_statement; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_orderby[] = $orderby_statement; - $this->ar_cache_exists[] = 'orderby'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @param integer the limit value - * @param integer the offset value - * @return object - */ - public function limit($value, $offset = '') - { - $this->ar_limit = (int) $value; - - if ($offset != '') - { - $this->ar_offset = (int) $offset; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @param integer the offset value - * @return object - */ - public function offset($offset) - { - $this->ar_offset = $offset; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @param mixed - * @param string - * @param boolean - * @return object - */ - public function set($key, $value = '', $escape = TRUE) - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - if ($escape === FALSE) - { - $this->ar_set[$this->_protect_identifiers($k)] = $v; - } - else - { - $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v); - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @param string the table - * @param string the limit clause - * @param string the offset clause - * @return object - */ - public function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->_track_aliases($table); - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - /** - * "Count All Results" query - * - * Generates a platform-specific query string that counts all records - * returned by an Active Record query. - * - * @param string - * @return string - */ - public function count_all_results($table = '') - { - if ($table != '') - { - $this->_track_aliases($table); - $this->from($table); - } - - $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); - - $query = $this->query($sql); - $this->_reset_select(); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Get_Where - * - * Allows the where clause, limit and offset to be added directly - * - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - public function get_where($table = '', $where = null, $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($where)) - { - $this->where($where); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Insert_Batch - * - * Compiles batch insert strings and runs the queries - * - * @param string the table to retrieve the results from - * @param array an associative array of insert values - * @return object - */ - public function insert_batch($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set_insert_batch($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - //No valid data array. Folds in cases where keys and values did not match up - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) - { - - $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)); - - //echo $sql; - - $this->query($sql); - } - - $this->_reset_write(); - - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts - * - * @param mixed - * @param string - * @param boolean - * @return object - */ - public function set_insert_batch($key, $value = '', $escape = TRUE) - { - $key = $this->_object_to_array_batch($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - $keys = array_keys(current($key)); - sort($keys); - - foreach ($key as $row) - { - if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) - { - // batch function above returns an error on an empty array - $this->ar_set[] = array(); - return; - } - - ksort($row); // puts $row in the same order as our keys - - if ($escape === FALSE) - { - $this->ar_set[] = '('.implode(',', $row).')'; - } - else - { - $clean = array(); - - foreach ($row as $value) - { - $clean[] = $this->escape($value); - } - - $this->ar_set[] = '('.implode(',', $clean).')'; - } - } - - foreach ($keys as $k) - { - $this->ar_keys[] = $this->_protect_identifiers($k); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @param string the table to insert data into - * @param array an associative array of insert values - * @return object - */ - function insert($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Replace - * - * Compiles an replace into string and runs the query - * - * @param string the table to replace data into - * @param array an associative array of insert values - * @return object - */ - public function replace($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * Compiles an update string and runs the query - * - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != NULL) - { - $this->where($where); - } - - if ($limit != NULL) - { - $this->limit($limit); - } - - $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - - $this->_reset_write(); - return $this->query($sql); - } - - - // -------------------------------------------------------------------- - - /** - * Update_Batch - * - * Compiles an update string and runs the query - * - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param string the where key - * @return object - */ - public function update_batch($table = '', $set = NULL, $index = NULL) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - if (is_null($index)) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_index'); - } - - return FALSE; - } - - if ( ! is_null($set)) - { - $this->set_update_batch($set, $index); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) - { - $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where); - - $this->query($sql); - } - - $this->_reset_write(); - } - - // -------------------------------------------------------------------- - - /** - * The "set_update_batch" function. Allows key/value pairs to be set for batch updating - * - * @param array - * @param string - * @param boolean - * @return object - */ - public function set_update_batch($key, $index = '', $escape = TRUE) - { - $key = $this->_object_to_array_batch($key); - - if ( ! is_array($key)) - { - // @todo error - } - - foreach ($key as $k => $v) - { - $index_set = FALSE; - $clean = array(); - - foreach ($v as $k2 => $v2) - { - if ($k2 == $index) - { - $index_set = TRUE; - } - else - { - $not[] = $k2.'-'.$v2; - } - - if ($escape === FALSE) - { - $clean[$this->_protect_identifiers($k2)] = $v2; - } - else - { - $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); - } - } - - if ($index_set == FALSE) - { - return $this->display_error('db_batch_missing_index'); - } - - $this->ar_set[] = $clean; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Empty Table - * - * Compiles a delete string and runs "DELETE FROM table" - * - * @param string the table to empty - * @return object - */ - public function empty_table($table = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - $sql = $this->_delete($table); - - $this->_reset_write(); - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Truncate - * - * Compiles a truncate string and runs the query - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @param string the table to truncate - * @return object - */ - public function truncate($table = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - $sql = $this->_truncate($table); - - $this->_reset_write(); - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @param mixed the table(s) to delete from. String or array - * @param mixed the where clause - * @param mixed the limit clause - * @param boolean - * @return object - */ - public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - elseif (is_array($table)) - { - foreach ($table as $single_table) - { - $this->delete($single_table, $where, $limit, FALSE); - } - - $this->_reset_write(); - return; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - if ($where != '') - { - $this->where($where); - } - - if ($limit != NULL) - { - $this->limit($limit); - } - - if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - - return FALSE; - } - - $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); - - if ($reset_data) - { - $this->_reset_write(); - } - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * DB Prefix - * - * Prepends a database prefix if one exists in configuration - * - * @param string the table - * @return string - */ - public function dbprefix($table = '') - { - if ($table == '') - { - $this->display_error('db_table_name_required'); - } - - return $this->dbprefix.$table; - } - - // -------------------------------------------------------------------- - - /** - * Set DB Prefix - * - * Set's the DB Prefix to something new without needing to reconnect - * - * @param string the prefix - * @return string - */ - public function set_dbprefix($prefix = '') - { - return $this->dbprefix = $prefix; - } - - // -------------------------------------------------------------------- - - /** - * Track Aliases - * - * Used to track SQL statements written with aliased tables. - * - * @param string The table to inspect - * @return string - */ - protected function _track_aliases($table) - { - if (is_array($table)) - { - foreach ($table as $t) - { - $this->_track_aliases($t); - } - return; - } - - // Does the string contain a comma? If so, we need to separate - // the string into discreet statements - if (strpos($table, ',') !== FALSE) - { - return $this->_track_aliases(explode(',', $table)); - } - - // if a table alias is used we can recognize it by a space - if (strpos($table, " ") !== FALSE) - { - // if the alias is written with the AS keyword, remove it - $table = preg_replace('/\s+AS\s+/i', ' ', $table); - - // Grab the alias - $table = trim(strrchr($table, " ")); - - // Store the alias, if it doesn't already exist - if ( ! in_array($table, $this->ar_aliased_tables)) - { - $this->ar_aliased_tables[] = $table; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @return string - */ - protected function _compile_select($select_override = FALSE) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - // ---------------------------------------------------------------- - - // Write the "select" portion of the query - - if ($select_override !== FALSE) - { - $sql = $select_override; - } - else - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - if (count($this->ar_select) == 0) - { - $sql .= '*'; - } - else - { - // Cycle through the "select" portion of the query and prep each column name. - // The reason we protect identifiers here rather then in the select() function - // is because until the user calls the from() function we don't know if there are aliases - foreach ($this->ar_select as $key => $val) - { - $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL; - $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape); - } - - $sql .= implode(', ', $this->ar_select); - } - } - - // ---------------------------------------------------------------- - - // Write the "FROM" portion of the query - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - - $sql .= $this->_from_tables($this->ar_from); - } - - // ---------------------------------------------------------------- - - // Write the "JOIN" portion of the query - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - - $sql .= implode("\n", $this->ar_join); - } - - // ---------------------------------------------------------------- - - // Write the "WHERE" portion of the query - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - // ---------------------------------------------------------------- - - // Write the "LIKE" portion of the query - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= "\nAND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - // ---------------------------------------------------------------- - - // Write the "GROUP BY" portion of the query - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - - $sql .= implode(', ', $this->ar_groupby); - } - - // ---------------------------------------------------------------- - - // Write the "HAVING" portion of the query - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - // ---------------------------------------------------------------- - - // Write the "ORDER BY" portion of the query - - if (count($this->ar_orderby) > 0) - { - $sql .= "\nORDER BY "; - $sql .= implode(', ', $this->ar_orderby); - - if ($this->ar_order !== FALSE) - { - $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } - } - - // ---------------------------------------------------------------- - - // Write the "LIMIT" portion of the query - - if (is_numeric($this->ar_limit)) - { - $sql .= "\n"; - $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @param object - * @return array - */ - public function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name') - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @param object - * @return array - */ - public function _object_to_array_batch($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - $out = get_object_vars($object); - $fields = array_keys($out); - - foreach ($fields as $val) - { - // There are some built in keys we need to ignore for this conversion - if ($val != '_parent_name') - { - - $i = 0; - foreach ($out[$val] as $data) - { - $array[$i][$val] = $data; - $i++; - } - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Start Cache - * - * Starts AR caching - * - * @return void - */ - public function start_cache() - { - $this->ar_caching = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Stop Cache - * - * Stops AR caching - * - * @return void - */ - public function stop_cache() - { - $this->ar_caching = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Flush Cache - * - * Empties the AR cache - * - * @access public - * @return void - */ - public function flush_cache() - { - $this->_reset_run(array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array(), - 'ar_cache_exists' => array(), - 'ar_cache_no_escape' => array() - )); - } - - // -------------------------------------------------------------------- - - /** - * Merge Cache - * - * When called, this function merges any cached AR arrays with - * locally called ones. - * - * @return void - */ - protected function _merge_cache() - { - if (count($this->ar_cache_exists) == 0) - { - return; - } - - foreach ($this->ar_cache_exists as $val) - { - $ar_variable = 'ar_'.$val; - $ar_cache_var = 'ar_cache_'.$val; - - if (count($this->$ar_cache_var) == 0) - { - continue; - } - - $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); - } - - // If we are "protecting identifiers" we need to examine the "from" - // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) - { - $this->_track_aliases($this->ar_from); - } - - $this->ar_no_escape = $this->ar_cache_no_escape; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @param array An array of fields to reset - * @return void - */ - protected function _reset_run($ar_reset_items) - { - foreach ($ar_reset_items as $item => $default_value) - { - if ( ! in_array($item, $this->ar_store_array)) - { - $this->$item = $default_value; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @return void - */ - protected function _reset_select() - { - $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), - 'ar_aliased_tables' => array(), - 'ar_no_escape' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, - 'ar_order' => FALSE, - ); - - $this->_reset_run($ar_reset_items); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() update() insert_batch() update_batch() and delete() functions - * - * @return void - */ - protected function _reset_write() - { - $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_keys' => array(), - 'ar_limit' => FALSE, - 'ar_order' => FALSE - ); - - $this->_reset_run($ar_reset_items); - } -} - -/* End of file DB_active_rec.php */ -/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php old mode 100755 new mode 100644 index 46b909f..afcfc4c --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,196 +1,221 @@ -CI - // and load the file helper since we use it a lot - $this->CI =& get_instance(); - $this->db =& $db; - $this->CI->load->helper('file'); - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return bool - */ - function check_path($path = '') - { - if ($path == '') - { - if ($this->db->cachedir == '') - { - return $this->db->cache_off(); - } - - $path = $this->db->cachedir; - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_really_writable($path)) - { - // If the path is wrong we'll turn off caching - return $this->db->cache_off(); - } - - $this->db->cachedir = $path; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Retrieve a cached query - * - * The URI being requested will become the name of the cache sub-folder. - * An MD5 hash of the SQL statement will become the cache file name - * - * @access public - * @return string - */ - function read($sql) - { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); - - if (FALSE === ($cachedata = read_file($filepath))) - { - return FALSE; - } - - return unserialize($cachedata); - } - - // -------------------------------------------------------------------- - - /** - * Write a query to a cache file - * - * @access public - * @return bool - */ - function write($sql, $object) - { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - - $filename = md5($sql); - - if ( ! @is_dir($dir_path)) - { - if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) - { - return FALSE; - } - - @chmod($dir_path, DIR_WRITE_MODE); - } - - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, FILE_WRITE_MODE); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Delete cache files within a particular directory - * - * @access public - * @return bool - */ - function delete($segment_one = '', $segment_two = '') - { - if ($segment_one == '') - { - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - } - - if ($segment_two == '') - { - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - } - - $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - - delete_files($dir_path, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Delete all existing cache files - * - * @access public - * @return bool - */ - function delete_all() - { - delete_files($this->db->cachedir, TRUE); - } + /** + * CI Singleton + * + * @var object + */ + public $CI; + + /** + * Database object + * + * Allows passing of DB object so that multiple database connections + * and returned DB objects can be supported. + * + * @var object + */ + public $db; + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param object &$db + * @return void + */ + public function __construct(&$db) + { + // Assign the main CI object to $this->CI and load the file helper since we use it a lot + $this->CI =& get_instance(); + $this->db =& $db; + $this->CI->load->helper('file'); + + $this->check_path(); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @param string $path Path to the cache directory + * @return bool + */ + public function check_path($path = '') + { + if ($path === '') + { + if ($this->db->cachedir === '') + { + return $this->db->cache_off(); + } + + $path = $this->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = realpath($path) + ? rtrim(realpath($path), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR + : rtrim($path, '/').'/'; + + if ( ! is_dir($path)) + { + log_message('debug', 'DB cache path error: '.$path); + + // If the path is wrong we'll turn off caching + return $this->db->cache_off(); + } + + if ( ! is_really_writable($path)) + { + log_message('debug', 'DB cache dir not writable: '.$path); + + // If the path is not really writable we'll turn off caching + return $this->db->cache_off(); + } + + $this->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retrieve a cached query + * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name. + * + * @param string $sql + * @return string + */ + public function read($sql) + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); + + if ( ! is_file($filepath) OR FALSE === ($cachedata = file_get_contents($filepath))) + { + return FALSE; + } + + return unserialize($cachedata); + } + + // -------------------------------------------------------------------- + + /** + * Write a query to a cache file + * + * @param string $sql + * @param object $object + * @return bool + */ + public function write($sql, $object) + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + $filename = md5($sql); + + if ( ! is_dir($dir_path) && ! @mkdir($dir_path, 0750)) + { + return FALSE; + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + chmod($dir_path.$filename, 0640); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @param string $segment_one + * @param string $segment_two + * @return void + */ + public function delete($segment_one = '', $segment_two = '') + { + if ($segment_one === '') + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + } + + if ($segment_two === '') + { + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + } + + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @return void + */ + public function delete_all() + { + delete_files($this->db->cachedir, TRUE, TRUE); + } } - - -/* End of file DB_cache.php */ -/* Location: ./system/database/DB_cache.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php old mode 100755 new mode 100644 index 1ba70ce..5ae0442 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,20 +1,41 @@ - $val) - { - $this->$key = $val; - } - } - - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize() - { - // If an existing connection resource is available - // there is no need to connect and select the database - if (is_resource($this->conn_id) OR is_object($this->conn_id)) - { - return TRUE; - } - - // ---------------------------------------------------------------- - - // Connect to the database and set the connection ID - $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - - // No connection resource? Throw an error - if ( ! $this->conn_id) - { - log_message('error', 'Unable to connect to the database'); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_connect'); - } - return FALSE; - } - - // ---------------------------------------------------------------- - - // Select the DB... assuming a database name is specified in the config file - if ($this->database != '') - { - if ( ! $this->db_select()) - { - log_message('error', 'Unable to select database: '.$this->database); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_select', $this->database); - } - return FALSE; - } - else - { - // We've selected the DB. Now we set the character set - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) - { - return FALSE; - } - - return TRUE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) - { - log_message('error', 'Unable to set database connection charset: '.$this->char_set); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_set_charset', $this->char_set); - } - - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * The name of the platform in use (mysql, mssql, etc...) - * - * @access public - * @return string - */ - function platform() - { - return $this->dbdriver; - } - - // -------------------------------------------------------------------- - - /** - * Database Version Number. Returns a string containing the - * version of the database being used - * - * @access public - * @return string - */ - function version() - { - if (FALSE === ($sql = $this->_version())) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - // Some DBs have functions that return the version, and don't run special - // SQL queries per se. In these instances, just return the result. - $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid'); - - if (in_array($this->dbdriver, $driver_version_exceptions)) - { - return $sql; - } - else - { - $query = $this->query($sql); - return $query->row('ver'); - } - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE - * upon successful execution of a "write" type query. Returns boolean - * FALSE upon failure, and if the $db_debug variable is set to TRUE - * will raise an error. - * - * @access public - * @param string An SQL query string - * @param array An array of binding data - * @return mixed - */ - function query($sql, $binds = FALSE, $return_object = TRUE) - { - if ($sql == '') - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$sql); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // Verify table prefix and replace if necessary - if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) - { - $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); - } - - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - - // Is query caching enabled? If the query is a "read type" - // we will load the caching class and return the previously - // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { - if ($this->_cache_init()) - { - $this->load_rdriver(); - if (FALSE !== ($cache = $this->CACHE->read($sql))) - { - return $cache; - } - } - } - - // Save the query for debugging - if ($this->save_queries == TRUE) - { - $this->queries[] = $sql; - } - - // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - - // Run the Query - if (FALSE === ($this->result_id = $this->simple_query($sql))) - { - if ($this->save_queries == TRUE) - { - $this->query_times[] = 0; - } - - // This will trigger a rollback if transactions are being used - $this->_trans_status = FALSE; - - if ($this->db_debug) - { - // grab the error number and message now, as we might run some - // additional queries before displaying the error - $error_no = $this->_error_number(); - $error_msg = $this->_error_message(); - - // We call this function in order to roll-back queries - // if transactions are enabled. If we don't call this here - // the error message will trigger an exit, causing the - // transactions to remain in limbo. - $this->trans_complete(); - - // Log and display errors - log_message('error', 'Query error: '.$error_msg); - return $this->display_error( - array( - 'Error Number: '.$error_no, - $error_msg, - $sql - ) - ); - } - - return FALSE; - } - - // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($em + $es) - ($sm + $ss); - - if ($this->save_queries == TRUE) - { - $this->query_times[] = ($em + $es) - ($sm + $ss); - } - - // Increment the query counter - $this->query_count++; - - // Was the query a "write" type? - // If so we'll simply return true - if ($this->is_write_type($sql) === TRUE) - { - // If caching is enabled we'll auto-cleanup any - // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) - { - $this->CACHE->delete(); - } - - return TRUE; - } - - // Return TRUE if we don't need to create a result object - // Currently only the Oracle driver uses this when stored - // procedures are used - if ($return_object !== TRUE) - { - return TRUE; - } - - // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); - $RES->conn_id = $this->conn_id; - $RES->result_id = $this->result_id; - - if ($this->dbdriver == 'oci8') - { - $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; - $RES->limit_used = $this->limit_used; - $this->stmt_id = FALSE; - } - - // oci8 vars must be set before calling this - $RES->num_rows = $RES->num_rows(); - - // Is query caching enabled? If so, we'll serialize the - // result object and save it to a cache file. - if ($this->cache_on == TRUE AND $this->_cache_init()) - { - // We'll create a new instance of the result object - // only without the platform specific driver since - // we can't use it with cached data (the query result - // resource ID won't be any good once we've cached the - // result object, so we'll have to compile the data - // and save it) - $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); - $CR->result_object = $RES->result_object(); - $CR->result_array = $RES->result_array(); - - // Reset these since cached objects can not utilize resource IDs. - $CR->conn_id = NULL; - $CR->result_id = NULL; - - $this->CACHE->write($sql, $CR); - } - - return $RES; - } - - // -------------------------------------------------------------------- - - /** - * Load the result drivers - * - * @access public - * @return string the name of the result class - */ - function load_rdriver() - { - $driver = 'CI_DB_'.$this->dbdriver.'_result'; - - if ( ! class_exists($driver)) - { - include_once(BASEPATH.'database/DB_result.php'); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); - } - - return $driver; - } - - // -------------------------------------------------------------------- - - /** - * Simple Query - * This is a simplified version of the query() function. Internally - * we only use it when running transaction commands since they do - * not require all the features of the main query() function. - * - * @access public - * @param string the sql query - * @return mixed - */ - function simple_query($sql) - { - if ( ! $this->conn_id) - { - $this->initialize(); - } - - return $this->_execute($sql); - } - - // -------------------------------------------------------------------- - - /** - * Disable Transactions - * This permits transactions to be disabled at run-time. - * - * @access public - * @return void - */ - function trans_off() - { - $this->trans_enabled = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Transaction Strict Mode - * When strict mode is enabled, if you are running multiple groups of - * transactions, if one group fails all groups will be rolled back. - * If strict mode is disabled, each group is treated autonomously, meaning - * a failure of one group will not affect any others - * - * @access public - * @return void - */ - function trans_strict($mode = TRUE) - { - $this->trans_strict = is_bool($mode) ? $mode : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Start Transaction - * - * @access public - * @return void - */ - function trans_start($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - $this->_trans_depth += 1; - return; - } - - $this->trans_begin($test_mode); - } - - // -------------------------------------------------------------------- - - /** - * Complete Transaction - * - * @access public - * @return bool - */ - function trans_complete() - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 1) - { - $this->_trans_depth -= 1; - return TRUE; - } - - // The query() function will set this flag to FALSE in the event that a query failed - if ($this->_trans_status === FALSE) - { - $this->trans_rollback(); - - // If we are NOT running in strict mode, we will reset - // the _trans_status flag so that subsequent groups of transactions - // will be permitted. - if ($this->trans_strict === FALSE) - { - $this->_trans_status = TRUE; - } - - log_message('debug', 'DB Transaction Failure'); - return FALSE; - } - - $this->trans_commit(); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Lets you retrieve the transaction flag to determine if it has failed - * - * @access public - * @return bool - */ - function trans_status() - { - return $this->_trans_status; - } - - // -------------------------------------------------------------------- - - /** - * Compile Bindings - * - * @access public - * @param string the sql statement - * @param array an array of bind data - * @return string - */ - function compile_binds($sql, $binds) - { - if (strpos($sql, $this->bind_marker) === FALSE) - { - return $sql; - } - - if ( ! is_array($binds)) - { - $binds = array($binds); - } - - // Get the sql segments around the bind markers - $segments = explode($this->bind_marker, $sql); - - // The count of bind should be 1 less then the count of segments - // If there are more bind arguments trim it down - if (count($binds) >= count($segments)) { - $binds = array_slice($binds, 0, count($segments)-1); - } - - // Construct the binded query - $result = $segments[0]; - $i = 0; - foreach ($binds as $bind) - { - $result .= $this->escape($bind); - $result .= $segments[++$i]; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Determines if a query is a "write" type. - * - * @access public - * @param string An SQL query string - * @return boolean - */ - function is_write_type($sql) - { - if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Calculate the aggregate query elapsed time - * - * @access public - * @param integer The number of decimal places - * @return integer - */ - function elapsed_time($decimals = 6) - { - return number_format($this->benchmark, $decimals); - } - - // -------------------------------------------------------------------- - - /** - * Returns the total number of queries - * - * @access public - * @return integer - */ - function total_queries() - { - return $this->query_count; - } - - // -------------------------------------------------------------------- - - /** - * Returns the last query that was executed - * - * @access public - * @return void - */ - function last_query() - { - return end($this->queries); - } - - // -------------------------------------------------------------------- - - /** - * "Smart" Escape String - * - * Escapes data based on type - * Sets boolean and null types - * - * @access public - * @param string - * @return mixed - */ - function escape($str) - { - if (is_string($str)) - { - $str = "'".$this->escape_str($str)."'"; - } - elseif (is_bool($str)) - { - $str = ($str === FALSE) ? 0 : 1; - } - elseif (is_null($str)) - { - $str = 'NULL'; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Escape LIKE String - * - * Calls the individual driver for platform - * specific escaping for LIKE conditions - * - * @access public - * @param string - * @return mixed - */ - function escape_like_str($str) - { - return $this->escape_str($str, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Primary - * - * Retrieves the primary key. It assumes that the row in the first - * position is the primary key - * - * @access public - * @param string the table name - * @return string - */ - function primary($table = '') - { - $fields = $this->list_fields($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function list_tables($constrain_by_prefix = FALSE) - { - // Is there a cached result? - if (isset($this->data_cache['table_names'])) - { - return $this->data_cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $retval = array(); - $query = $this->query($sql); - - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } - } - } - - $this->data_cache['table_names'] = $retval; - return $this->data_cache['table_names']; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function list_fields($table = '') - { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_list_columns($table))) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $query = $this->query($sql); - - $retval = array(); - foreach ($query->result_array() as $row) - { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } - } - - $this->data_cache['field_names'][$table] = $retval; - return $this->data_cache['field_names'][$table]; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular field exists - * @access public - * @param string - * @param string - * @return boolean - */ - function field_exists($field_name, $table_name) - { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Returns an object with field data - * - * @access public - * @param string the table name - * @return object - */ - function field_data($table = '') - { - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); - - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Generate an insert string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @return string - */ - function insert_string($table, $data) - { - $fields = array(); - $values = array(); - - foreach ($data as $key => $val) - { - $fields[] = $this->_escape_identifiers($key); - $values[] = $this->escape($val); - } - - return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); - } - - // -------------------------------------------------------------------- - - /** - * Generate an update string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @param mixed the "where" statement - * @return string - */ - function update_string($table, $data, $where) - { - if ($where == '') - { - return false; - } - - $fields = array(); - foreach ($data as $key => $val) - { - $fields[$this->_protect_identifiers($key)] = $this->escape($val); - } - - if ( ! is_array($where)) - { - $dest = array($where); - } - else - { - $dest = array(); - foreach ($where as $key => $val) - { - $prefix = (count($dest) == 0) ? '' : ' AND '; - - if ($val !== '') - { - if ( ! $this->_has_operator($key)) - { - $key .= ' ='; - } - - $val = ' '.$this->escape($val); - } - - $dest[] = $prefix.$key.$val; - } - } - - return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); - } - - // -------------------------------------------------------------------- - - /** - * Tests whether the string has an SQL operator - * - * @access private - * @param string - * @return bool - */ - function _has_operator($str) - { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Enables a native PHP function to be run, using a platform agnostic wrapper. - * - * @access public - * @param string the function name - * @param mixed any parameters needed by the function - * @return mixed - */ - function call_function($function) - { - $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; - - if (FALSE === strpos($driver, $function)) - { - $function = $driver.$function; - } - - if ( ! function_exists($function)) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - else - { - $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - if (is_null($args)) - { - return call_user_func($function); - } - else - { - return call_user_func_array($function, $args); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return void - */ - function cache_set_path($path = '') - { - $this->cachedir = $path; - } - - // -------------------------------------------------------------------- - - /** - * Enable Query Caching - * - * @access public - * @return void - */ - function cache_on() - { - $this->cache_on = TRUE; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Disable Query Caching - * - * @access public - * @return void - */ - function cache_off() - { - $this->cache_on = FALSE; - return FALSE; - } - - - // -------------------------------------------------------------------- - - /** - * Delete the cache files associated with a particular URI - * - * @access public - * @return void - */ - function cache_delete($segment_one = '', $segment_two = '') - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - return $this->CACHE->delete($segment_one, $segment_two); - } - - // -------------------------------------------------------------------- - - /** - * Delete All cache files - * - * @access public - * @return void - */ - function cache_delete_all() - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - - return $this->CACHE->delete_all(); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Cache Class - * - * @access private - * @return void - */ - function _cache_init() - { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) - { - return TRUE; - } - - if ( ! class_exists('CI_DB_Cache')) - { - if ( ! @include(BASEPATH.'database/DB_cache.php')) - { - return $this->cache_off(); - } - } - - $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @return void - */ - function close() - { - if (is_resource($this->conn_id) OR is_object($this->conn_id)) - { - $this->_close($this->conn_id); - } - $this->conn_id = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Display an error message - * - * @access public - * @param string the error message - * @param string any "swap" values - * @param boolean whether to localize the message - * @return string sends the application/error_db.php template - */ - function display_error($error = '', $swap = '', $native = FALSE) - { - $LANG =& load_class('Lang', 'core'); - $LANG->load('db'); - - $heading = $LANG->line('db_error_heading'); - - if ($native == TRUE) - { - $message = $error; - } - else - { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; - } - - // Find the most likely culprit of the error by going through - // the backtrace until the source file is no longer in the - // database folder. - - $trace = debug_backtrace(); - - foreach ($trace as $call) - { - if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) - { - // Found it - use a relative path for safety - $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); - $message[] = 'Line Number: '.$call['line']; - - break; - } - } - - $error =& load_class('Exceptions', 'core'); - echo $error->show_error($heading, $message, 'error_db'); - exit; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @return mixed the item with backticks - */ - function protect_identifiers($item, $prefix_single = FALSE) - { - return $this->_protect_identifiers($item, $prefix_single); - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function is used extensively by the Active Record class, and by - * a couple functions in this class. - * It takes a column or table name (optionally with an alias) and inserts - * the table prefix onto it. Some logic is necessary in order to deal with - * column names that include the path. Consider a query like this: - * - * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table - * - * Or a query with aliasing: - * - * SELECT m.member_id, m.member_name FROM members AS m - * - * Since the column name can include up to four segments (host, DB, table, column) - * or also have an alias prefix, we need to do a bit of work to figure this out and - * insert the table prefix (if it exists) in the proper position, and escape only - * the correct identifiers. - * - * @access private - * @param string - * @param bool - * @param mixed - * @param bool - * @return string - */ - function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) - { - if ( ! is_bool($protect_identifiers)) - { - $protect_identifiers = $this->_protect_identifiers; - } - - if (is_array($item)) - { - $escaped_array = array(); - - foreach ($item as $k => $v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v); - } - - return $escaped_array; - } - - // Convert tabs or multiple spaces into single spaces - $item = preg_replace('/[\t ]+/', ' ', $item); - - // If the item has an alias declaration we remove it and set it aside. - // Basically we remove everything to the right of the first space - if (strpos($item, ' ') !== FALSE) - { - $alias = strstr($item, ' '); - $item = substr($item, 0, - strlen($alias)); - } - else - { - $alias = ''; - } - - // This is basically a bug fix for queries that use MAX, MIN, etc. - // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful - // way to deal with this, but I'm not thinking of it -- Rick - if (strpos($item, '(') !== FALSE) - { - return $item.$alias; - } - - // Break the string apart if it contains periods, then insert the table prefix - // in the correct location, assuming the period doesn't indicate that we're dealing - // with an alias. While we're at it, we will escape the components - if (strpos($item, '.') !== FALSE) - { - $parts = explode('.', $item); - - // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, - // we have nothing more to do other than escape the item - if (in_array($parts[0], $this->ar_aliased_tables)) - { - if ($protect_identifiers === TRUE) - { - foreach ($parts as $key => $val) - { - if ( ! in_array($val, $this->_reserved_identifiers)) - { - $parts[$key] = $this->_escape_identifiers($val); - } - } - - $item = implode('.', $parts); - } - return $item.$alias; - } - - // Is there a table prefix defined in the config file? If not, no need to do anything - if ($this->dbprefix != '') - { - // We now add the table prefix based on some logic. - // Do we have 4 segments (hostname.database.table.column)? - // If so, we add the table prefix to the column name in the 3rd segment. - if (isset($parts[3])) - { - $i = 2; - } - // Do we have 3 segments (database.table.column)? - // If so, we add the table prefix to the column name in 2nd position - elseif (isset($parts[2])) - { - $i = 1; - } - // Do we have 2 segments (table.column)? - // If so, we add the table prefix to the column name in 1st segment - else - { - $i = 0; - } - - // This flag is set when the supplied $item does not contain a field name. - // This can happen when this function is being called from a JOIN. - if ($field_exists == FALSE) - { - $i++; - } - - // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) - { - $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); - } - - // We only add the table prefix if it does not already exist - if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) - { - $parts[$i] = $this->dbprefix.$parts[$i]; - } - - // Put the parts back together - $item = implode('.', $parts); - } - - if ($protect_identifiers === TRUE) - { - $item = $this->_escape_identifiers($item); - } - - return $item.$alias; - } - - // Is there a table prefix? If not, no need to insert it - if ($this->dbprefix != '') - { - // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) - { - $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); - } - - // Do we prefix an item with no segments? - if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) - { - $item = $this->dbprefix.$item; - } - } - - if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) - { - $item = $this->_escape_identifiers($item); - } - - return $item.$alias; - } - - // -------------------------------------------------------------------- - - /** - * Dummy method that allows Active Record class to be disabled - * - * This function is used extensively by every db driver. - * - * @return void - */ - protected function _reset_select() - { - } +abstract class CI_DB_driver { + + /** + * Data Source Name / Connect string + * + * @var string + */ + public $dsn; + + /** + * Username + * + * @var string + */ + public $username; + + /** + * Password + * + * @var string + */ + public $password; + + /** + * Hostname + * + * @var string + */ + public $hostname; + + /** + * Database name + * + * @var string + */ + public $database; + + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'mysqli'; + + /** + * Sub-driver + * + * @used-by CI_DB_pdo_driver + * @var string + */ + public $subdriver; + + /** + * Table prefix + * + * @var string + */ + public $dbprefix = ''; + + /** + * Character set + * + * @var string + */ + public $char_set = 'utf8'; + + /** + * Collation + * + * @var string + */ + public $dbcollat = 'utf8_general_ci'; + + /** + * Encryption flag/data + * + * @var mixed + */ + public $encrypt = FALSE; + + /** + * Swap Prefix + * + * @var string + */ + public $swap_pre = ''; + + /** + * Database port + * + * @var int + */ + public $port = NULL; + + /** + * Persistent connection flag + * + * @var bool + */ + public $pconnect = FALSE; + + /** + * Connection ID + * + * @var object|resource + */ + public $conn_id = FALSE; + + /** + * Result ID + * + * @var object|resource + */ + public $result_id = FALSE; + + /** + * Debug flag + * + * Whether to display error messages. + * + * @var bool + */ + public $db_debug = FALSE; + + /** + * Benchmark time + * + * @var int + */ + public $benchmark = 0; + + /** + * Executed queries count + * + * @var int + */ + public $query_count = 0; + + /** + * Bind marker + * + * Character used to identify values in a prepared statement. + * + * @var string + */ + public $bind_marker = '?'; + + /** + * Save queries flag + * + * Whether to keep an in-memory history of queries for debugging purposes. + * + * @var bool + */ + public $save_queries = TRUE; + + /** + * Queries list + * + * @see CI_DB_driver::$save_queries + * @var string[] + */ + public $queries = array(); + + /** + * Query times + * + * A list of times that queries took to execute. + * + * @var array + */ + public $query_times = array(); + + /** + * Data cache + * + * An internal generic value cache. + * + * @var array + */ + public $data_cache = array(); + + /** + * Transaction enabled flag + * + * @var bool + */ + public $trans_enabled = TRUE; + + /** + * Strict transaction mode flag + * + * @var bool + */ + public $trans_strict = TRUE; + + /** + * Transaction depth level + * + * @var int + */ + protected $_trans_depth = 0; + + /** + * Transaction status flag + * + * Used with transactions to determine if a rollback should occur. + * + * @var bool + */ + protected $_trans_status = TRUE; + + /** + * Transaction failure flag + * + * Used with transactions to determine if a transaction has failed. + * + * @var bool + */ + protected $_trans_failure = FALSE; + + /** + * Cache On flag + * + * @var bool + */ + public $cache_on = FALSE; + + /** + * Cache directory path + * + * @var bool + */ + public $cachedir = ''; + + /** + * Cache auto-delete flag + * + * @var bool + */ + public $cache_autodel = FALSE; + + /** + * DB Cache object + * + * @see CI_DB_cache + * @var object + */ + public $CACHE; + + /** + * Protect identifiers flag + * + * @var bool + */ + protected $_protect_identifiers = TRUE; + + /** + * List of reserved identifiers + * + * Identifiers that must NOT be escaped. + * + * @var string[] + */ + protected $_reserved_identifiers = array('*'); + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '"'; + + /** + * ESCAPE statement string + * + * @var string + */ + protected $_like_escape_str = " ESCAPE '%s' "; + + /** + * ESCAPE character + * + * @var string + */ + protected $_like_escape_chr = '!'; + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('RAND()', 'RAND(%d)'); + + /** + * COUNT string + * + * @used-by CI_DB_driver::count_all() + * @used-by CI_DB_query_builder::count_all_results() + * + * @var string + */ + protected $_count_string = 'SELECT COUNT(*) AS '; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + if (is_array($params)) + { + foreach ($params as $key => $val) + { + $this->$key = $val; + } + } + + log_message('info', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @return bool + */ + public function initialize() + { + /* If an established connection is available, then there's + * no need to connect and select the database. + * + * Depending on the database driver, conn_id can be either + * boolean TRUE, a resource or an object. + */ + if ($this->conn_id) + { + return TRUE; + } + + // ---------------------------------------------------------------- + + // Connect to the database and set the connection ID + $this->conn_id = $this->db_connect($this->pconnect); + + // No connection resource? Check if there is a failover else throw an error + if ( ! $this->conn_id) + { + // Check if there is a failover set + if ( ! empty($this->failover) && is_array($this->failover)) + { + // Go over all the failovers + foreach ($this->failover as $failover) + { + // Replace the current settings with those of the failover + foreach ($failover as $key => $val) + { + $this->$key = $val; + } + + // Try to connect + $this->conn_id = $this->db_connect($this->pconnect); + + // If a connection is made break the foreach loop + if ($this->conn_id) + { + break; + } + } + } + + // We still don't have a connection? + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + + return FALSE; + } + } + + // Now we set the character set and that's all + return $this->db_set_charset($this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * DB connect + * + * This is just a dummy method that all drivers will override. + * + * @return mixed + */ + public function db_connect() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @return mixed + */ + public function db_pconnect() + { + return $this->db_connect(TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout. + * + * This is just a dummy method to allow drivers without such + * functionality to not declare it, while others will override it. + * + * @return void + */ + public function reconnect() + { + } + + // -------------------------------------------------------------------- + + /** + * Select database + * + * This is just a dummy method to allow drivers without such + * functionality to not declare it, while others will override it. + * + * @return bool + */ + public function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Last error + * + * @return array + */ + public function error() + { + return array('code' => NULL, 'message' => NULL); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string + * @return bool + */ + public function db_set_charset($charset) + { + if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset)) + { + log_message('error', 'Unable to set database connection charset: '.$charset); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $charset); + } + + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * The name of the platform in use (mysql, mssql, etc...) + * + * @return string + */ + public function platform() + { + return $this->dbdriver; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * Returns a string containing the version of the database being used. + * Most drivers will override this method. + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (FALSE === ($sql = $this->_version())) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $query = $this->query($sql)->row(); + return $this->data_cache['version'] = $query->ver; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return 'SELECT VERSION() AS ver'; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE + * will raise an error. + * + * @param string $sql + * @param array $binds = FALSE An array of binding data + * @param bool $return_object = NULL + * @return mixed + */ + public function query($sql, $binds = FALSE, $return_object = NULL) + { + if ($sql === '') + { + log_message('error', 'Invalid query: '.$sql); + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; + } + elseif ( ! is_bool($return_object)) + { + $return_object = ! $this->is_write_type($sql); + } + + // Verify table prefix and replace if necessary + if ($this->dbprefix !== '' && $this->swap_pre !== '' && $this->dbprefix !== $this->swap_pre) + { + $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously + // cached query if it exists + if ($this->cache_on === TRUE && $return_object === TRUE && $this->_cache_init()) + { + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) + { + return $cache; + } + } + + // Save the query for debugging + if ($this->save_queries === TRUE) + { + $this->queries[] = $sql; + } + + // Start the Query Timer + $time_start = microtime(TRUE); + + // Run the Query + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + if ($this->save_queries === TRUE) + { + $this->query_times[] = 0; + } + + // This will trigger a rollback if transactions are being used + if ($this->_trans_depth !== 0) + { + $this->_trans_status = FALSE; + } + + // Grab the error now, as we might run some additional queries before displaying the error + $error = $this->error(); + + // Log errors + log_message('error', 'Query error: '.$error['message'].' - Invalid query: '.$sql); + + if ($this->db_debug) + { + // We call this function in order to roll-back queries + // if transactions are enabled. If we don't call this here + // the error message will trigger an exit, causing the + // transactions to remain in limbo. + while ($this->_trans_depth !== 0) + { + $trans_depth = $this->_trans_depth; + $this->trans_complete(); + if ($trans_depth === $this->_trans_depth) + { + log_message('error', 'Database: Failure during an automated transaction commit/rollback!'); + break; + } + } + + // Display errors + return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql)); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = microtime(TRUE); + $this->benchmark += $time_end - $time_start; + + if ($this->save_queries === TRUE) + { + $this->query_times[] = $time_end - $time_start; + } + + // Increment the query counter + $this->query_count++; + + // Will we have a result object instantiated? If not - we'll simply return TRUE + if ($return_object !== TRUE) + { + // If caching is enabled we'll auto-cleanup any existing files related to this particular URI + if ($this->cache_on === TRUE && $this->cache_autodel === TRUE && $this->_cache_init()) + { + $this->CACHE->delete(); + } + + return TRUE; + } + + // Load and instantiate the result driver + $driver = $this->load_rdriver(); + $RES = new $driver($this); + + // Is query caching enabled? If so, we'll serialize the + // result object and save it to a cache file. + if ($this->cache_on === TRUE && $this->_cache_init()) + { + // We'll create a new instance of the result object + // only without the platform specific driver since + // we can't use it with cached data (the query result + // resource ID won't be any good once we've cached the + // result object, so we'll have to compile the data + // and save it) + $CR = new CI_DB_result($this); + $CR->result_object = $RES->result_object(); + $CR->result_array = $RES->result_array(); + $CR->num_rows = $RES->num_rows(); + + // Reset these since cached objects can not utilize resource IDs. + $CR->conn_id = NULL; + $CR->result_id = NULL; + + $this->CACHE->write($sql, $CR); + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Load the result drivers + * + * @return string the name of the result class + */ + public function load_rdriver() + { + $driver = 'CI_DB_'.$this->dbdriver.'_result'; + + if ( ! class_exists($driver, FALSE)) + { + require_once(BASEPATH.'database/DB_result.php'); + require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); + } + + return $driver; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simplified version of the query() function. Internally + * we only use it when running transaction commands since they do + * not require all the features of the main query() function. + * + * @param string the sql query + * @return mixed + */ + public function simple_query($sql) + { + if ( ! $this->conn_id) + { + if ( ! $this->initialize()) + { + return FALSE; + } + } + + return $this->_execute($sql); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @return void + */ + public function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Transaction Strict Mode + * + * When strict mode is enabled, if you are running multiple groups of + * transactions, if one group fails all subsequent groups will be + * rolled back. + * + * If strict mode is disabled, each group is treated autonomously, + * meaning a failure of one group will not affect any others + * + * @param bool $mode = TRUE + * @return void + */ + public function trans_strict($mode = TRUE) + { + $this->trans_strict = is_bool($mode) ? $mode : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @param bool $test_mode = FALSE + * @return bool + */ + public function trans_start($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + return $this->trans_begin($test_mode); + } + + // -------------------------------------------------------------------- + + /** + * Complete Transaction + * + * @return bool + */ + public function trans_complete() + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // The query() function will set this flag to FALSE in the event that a query failed + if ($this->_trans_status === FALSE OR $this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + // If we are NOT running in strict mode, we will reset + // the _trans_status flag so that subsequent groups of + // transactions will be permitted. + if ($this->trans_strict === FALSE) + { + $this->_trans_status = TRUE; + } + + log_message('debug', 'DB Transaction Failure'); + return FALSE; + } + + return $this->trans_commit(); + } + + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @return bool + */ + public function trans_status() + { + return $this->_trans_status; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @param bool $test_mode + * @return bool + */ + public function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 0) + { + $this->_trans_depth++; + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE); + + if ($this->_trans_begin()) + { + $this->_trans_status = TRUE; + $this->_trans_depth++; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + public function trans_commit() + { + if ( ! $this->trans_enabled OR $this->_trans_depth === 0) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 1 OR $this->_trans_commit()) + { + $this->_trans_depth--; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + public function trans_rollback() + { + if ( ! $this->trans_enabled OR $this->_trans_depth === 0) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 1 OR $this->_trans_rollback()) + { + $this->_trans_depth--; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + public function compile_binds($sql, $binds) + { + if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) + { + return $sql; + } + elseif ( ! is_array($binds)) + { + $binds = array($binds); + $bind_count = 1; + } + else + { + // Make sure we're using numeric keys + $binds = array_values($binds); + $bind_count = count($binds); + } + + // We'll need the marker length later + $ml = strlen($this->bind_marker); + + // Make sure not to replace a chunk inside a string that happens to match the bind marker + if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches)) + { + $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', + str_replace($matches[0], + str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), + $sql, $c), + $matches, PREG_OFFSET_CAPTURE); + + // Bind values' count must match the count of markers in the query + if ($bind_count !== $c) + { + return $sql; + } + } + elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) + { + return $sql; + } + + do + { + $c--; + $escaped_value = $this->escape($binds[$c]); + if (is_array($escaped_value)) + { + $escaped_value = '('.implode(',', $escaped_value).')'; + } + $sql = substr_replace($sql, $escaped_value, $matches[0][$c][1], $ml); + } + while ($c !== 0); + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s/i', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @param int The number of decimal places + * @return string + */ + public function elapsed_time($decimals = 6) + { + return number_format($this->benchmark, $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Returns the total number of queries + * + * @return int + */ + public function total_queries() + { + return $this->query_count; + } + + // -------------------------------------------------------------------- + + /** + * Returns the last query that was executed + * + * @return string + */ + public function last_query() + { + return end($this->queries); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @param string + * @return mixed + */ + public function escape($str) + { + if (is_array($str)) + { + $str = array_map(array(&$this, 'escape'), $str); + return $str; + } + elseif (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) + { + return "'".$this->escape_str($str)."'"; + } + elseif (is_bool($str)) + { + return ($str === FALSE) ? 0 : 1; + } + elseif ($str === NULL) + { + return 'NULL'; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @param string|string[] $str Input string + * @param bool $like Whether or not the string will be used in a LIKE condition + * @return string + */ + public function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = $this->_escape_str($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + return str_replace( + array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), + $str + ); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Escape LIKE String + * + * Calls the individual driver for platform + * specific escaping for LIKE conditions + * + * @param string|string[] + * @return mixed + */ + public function escape_like_str($str) + { + return $this->escape_str($str, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return str_replace("'", "''", remove_invisible_characters($str, FALSE)); + } + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @param string $table Table name + * @return string + */ + public function primary($table) + { + $fields = $this->list_fields($table); + return is_array($fields) ? current($fields) : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @param string + * @return int + */ + public function count_all($table = '') + { + if ($table === '') + { + return 0; + } + + $query = $this->query($this->_count_string.$this->escape_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); + if ($query->num_rows() === 0) + { + return 0; + } + + $query = $query->row(); + $this->_reset_select(); + return (int) $query->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @param string $constrain_by_prefix = FALSE + * @return array + */ + public function list_tables($constrain_by_prefix = FALSE) + { + // Is there a cached result? + if (isset($this->data_cache['table_names'])) + { + return $this->data_cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $this->data_cache['table_names'] = array(); + $query = $this->query($sql); + + foreach ($query->result_array() as $row) + { + // Do we know from which column to get the table name? + if ( ! isset($key)) + { + if (isset($row['table_name'])) + { + $key = 'table_name'; + } + elseif (isset($row['TABLE_NAME'])) + { + $key = 'TABLE_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting its argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } + } + + $this->data_cache['table_names'][] = $row[$key]; + } + + return $this->data_cache['table_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * + * @param string $table_name + * @return bool + */ + public function table_exists($table_name) + { + return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (FALSE === ($sql = $this->_list_columns($table))) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $query = $this->query($sql); + $fields = array(); + + foreach ($query->result_array() as $row) + { + // Do we know from where to get the column's name? + if ( ! isset($key)) + { + if (isset($row['column_name'])) + { + $key = 'column_name'; + } + elseif (isset($row['COLUMN_NAME'])) + { + $key = 'COLUMN_NAME'; + } + else + { + // We have no other choice but to just get the first element's key. + $key = key($row); + } + } + + $fields[] = $row[$key]; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular field exists + * + * @param string + * @param string + * @return bool + */ + public function field_exists($field_name, $table_name) + { + return in_array($field_name, $this->list_fields($table_name)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table the table name + * @return array + */ + public function field_data($table) + { + $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE))); + return ($query) ? $query->field_data() : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @param mixed + * @return mixed + */ + public function escape_identifiers($item) + { + if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers)) + { + return $item; + } + elseif (is_array($item)) + { + foreach ($item as $key => $value) + { + $item[$key] = $this->escape_identifiers($value); + } + + return $item; + } + // Avoid breaking functions and literal values inside queries + elseif (ctype_digit($item) OR $item[0] === "'" OR ($this->_escape_char !== '"' && $item[0] === '"') OR strpos($item, '(') !== FALSE) + { + return $item; + } + + static $preg_ec = array(); + + if (empty($preg_ec)) + { + if (is_array($this->_escape_char)) + { + $preg_ec = array( + preg_quote($this->_escape_char[0], '/'), + preg_quote($this->_escape_char[1], '/'), + $this->_escape_char[0], + $this->_escape_char[1] + ); + } + else + { + $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/'); + $preg_ec[2] = $preg_ec[3] = $this->_escape_char; + } + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item); + } + } + + return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item); + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + public function insert_string($table, $data) + { + $fields = $values = array(); + + foreach ($data as $key => $val) + { + $fields[] = $this->escape_identifiers($key); + $values[] = $this->escape($val); + } + + return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + public function update_string($table, $data, $where) + { + if (empty($where)) + { + return FALSE; + } + + $this->where($where); + + $fields = array(); + foreach ($data as $key => $val) + { + $fields[$this->protect_identifiers($key)] = $this->escape($val); + } + + $sql = $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields); + $this->_reset_write(); + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @return string + */ + protected function _update($table, $values) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .$this->_compile_wh('qb_where') + .$this->_compile_order_by() + .($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : ''); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @param string + * @return bool + */ + protected function _has_operator($str) + { + return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str)); + } + + // -------------------------------------------------------------------- + + /** + * Returns the SQL string operator + * + * @param string + * @return string + */ + protected function _get_operator($str) + { + static $_operators; + + if (empty($_operators)) + { + $_les = ($this->_like_escape_str !== '') + ? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/') + : ''; + $_operators = array( + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != + '\s*<>?\s*', // <, <> + '\s*>\s*', // > + '\s+IS NULL', // IS NULL + '\s+IS NOT NULL', // IS NOT NULL + '\s+EXISTS\s*\(.*\)', // EXISTS(sql) + '\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql) + '\s+BETWEEN\s+', // BETWEEN value AND value + '\s+IN\s*\(.*\)', // IN(list) + '\s+NOT IN\s*\(.*\)', // NOT IN (list) + '\s+LIKE\s+\S.*('.$_les.')?', // LIKE 'expr'[ ESCAPE '%s'] + '\s+NOT LIKE\s+\S.*('.$_les.')?' // NOT LIKE 'expr'[ ESCAPE '%s'] + ); + + } + + return preg_match('/'.implode('|', $_operators).'/i', $str, $match) + ? $match[0] : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Enables a native PHP function to be run, using a platform agnostic wrapper. + * + * @param string $function Function name + * @return mixed + */ + public function call_function($function) + { + $driver = ($this->dbdriver === 'postgre') ? 'pg_' : $this->dbdriver.'_'; + + if (FALSE === strpos($driver, $function)) + { + $function = $driver.$function; + } + + if ( ! function_exists($function)) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + return (func_num_args() > 1) + ? call_user_func_array($function, array_slice(func_get_args(), 1)) + : call_user_func($function); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @param string the path to the cache directory + * @return void + */ + public function cache_set_path($path = '') + { + $this->cachedir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @return bool cache_on value + */ + public function cache_on() + { + return $this->cache_on = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @return bool cache_on value + */ + public function cache_off() + { + return $this->cache_on = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Delete the cache files associated with a particular URI + * + * @param string $segment_one = '' + * @param string $segment_two = '' + * @return bool + */ + public function cache_delete($segment_one = '', $segment_two = '') + { + return $this->_cache_init() + ? $this->CACHE->delete($segment_one, $segment_two) + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Delete All cache files + * + * @return bool + */ + public function cache_delete_all() + { + return $this->_cache_init() + ? $this->CACHE->delete_all() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Cache Class + * + * @return bool + */ + protected function _cache_init() + { + if ( ! class_exists('CI_DB_Cache', FALSE)) + { + require_once(BASEPATH.'database/DB_cache.php'); + } + elseif (is_object($this->CACHE)) + { + return TRUE; + } + + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + public function close() + { + if ($this->conn_id) + { + $this->_close(); + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * This method would be overridden by most of the drivers. + * + * @return void + */ + protected function _close() + { + $this->conn_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Display an error message + * + * @param string the error message + * @param string any "swap" values + * @param bool whether to localize the message + * @return string sends the application/views/errors/error_db.php template + */ + public function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG =& load_class('Lang', 'core'); + $LANG->load('db'); + + $heading = $LANG->line('db_error_heading'); + + if ($native === TRUE) + { + $message = (array) $error; + } + else + { + $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error))); + } + + // Find the most likely culprit of the error by going through + // the backtrace until the source file is no longer in the + // database folder. + $trace = debug_backtrace(); + foreach ($trace as $call) + { + if (isset($call['file'], $call['class'])) + { + // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes + if (DIRECTORY_SEPARATOR !== '/') + { + $call['file'] = str_replace('\\', '/', $call['file']); + } + + if (strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') === FALSE) + { + // Found it - use a relative path for safety + $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); + $message[] = 'Line Number: '.$call['line']; + break; + } + } + } + + $error =& load_class('Exceptions', 'core'); + echo $error->show_error($heading, $message, 'error_db'); + exit(8); // EXIT_DATABASE + } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function is used extensively by the Query Builder class, and by + * a couple functions in this class. + * It takes a column or table name (optionally with an alias) and inserts + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: + * + * SELECT hostname.database.table.column AS c FROM hostname.database.table + * + * Or a query with aliasing: + * + * SELECT m.member_id, m.member_name FROM members AS m + * + * Since the column name can include up to four segments (host, DB, table, column) + * or also have an alias prefix, we need to do a bit of work to figure this out and + * insert the table prefix (if it exists) in the proper position, and escape only + * the correct identifiers. + * + * @param string + * @param bool + * @param mixed + * @param bool + * @return string + */ + public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + { + if ( ! is_bool($protect_identifiers)) + { + $protect_identifiers = $this->_protect_identifiers; + } + + if (is_array($item)) + { + $escaped_array = array(); + foreach ($item as $k => $v) + { + $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v, $prefix_single, $protect_identifiers, $field_exists); + } + + return $escaped_array; + } + + // This is basically a bug fix for queries that use MAX, MIN, etc. + // If a parenthesis is found we know that we do not need to + // escape the data or add a prefix. There's probably a more graceful + // way to deal with this, but I'm not thinking of it -- Rick + // + // Added exception for single quotes as well, we don't want to alter + // literal strings. -- Narf + if (strcspn($item, "()'") !== strlen($item)) + { + return $item; + } + + // Convert tabs or multiple spaces into single spaces + $item = preg_replace('/\s+/', ' ', trim($item)); + + // If the item has an alias declaration we remove it and set it aside. + // Note: strripos() is used in order to support spaces in table names + if ($offset = strripos($item, ' AS ')) + { + $alias = ($protect_identifiers) + ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4)) + : substr($item, $offset); + $item = substr($item, 0, $offset); + } + elseif ($offset = strrpos($item, ' ')) + { + $alias = ($protect_identifiers) + ? ' '.$this->escape_identifiers(substr($item, $offset + 1)) + : substr($item, $offset); + $item = substr($item, 0, $offset); + } + else + { + $alias = ''; + } + + // Break the string apart if it contains periods, then insert the table prefix + // in the correct location, assuming the period doesn't indicate that we're dealing + // with an alias. While we're at it, we will escape the components + if (strpos($item, '.') !== FALSE) + { + $parts = explode('.', $item); + + // Does the first segment of the exploded item match + // one of the aliases previously identified? If so, + // we have nothing more to do other than escape the item + // + // NOTE: The ! empty() condition prevents this method + // from breaking when QB isn't enabled. + if ( ! empty($this->qb_aliased_tables) && in_array($parts[0], $this->qb_aliased_tables)) + { + if ($protect_identifiers === TRUE) + { + foreach ($parts as $key => $val) + { + if ( ! in_array($val, $this->_reserved_identifiers)) + { + $parts[$key] = $this->escape_identifiers($val); + } + } + + $item = implode('.', $parts); + } + + return $item.$alias; + } + + // Is there a table prefix defined in the config file? If not, no need to do anything + if ($this->dbprefix !== '') + { + // We now add the table prefix based on some logic. + // Do we have 4 segments (hostname.database.table.column)? + // If so, we add the table prefix to the column name in the 3rd segment. + if (isset($parts[3])) + { + $i = 2; + } + // Do we have 3 segments (database.table.column)? + // If so, we add the table prefix to the column name in 2nd position + elseif (isset($parts[2])) + { + $i = 1; + } + // Do we have 2 segments (table.column)? + // If so, we add the table prefix to the column name in 1st segment + else + { + $i = 0; + } + + // This flag is set when the supplied $item does not contain a field name. + // This can happen when this function is being called from a JOIN. + if ($field_exists === FALSE) + { + $i++; + } + + // dbprefix may've already been applied, with or without the identifier escaped + $ec = '(?'.preg_quote(is_array($this->_escape_char) ? $this->_escape_char[0] : $this->_escape_char).')?'; + isset($ec[0]) && $ec .= '?'; // Just in case someone has disabled escaping by forcing an empty escape character + + // Verify table prefix and replace if necessary + if ($this->swap_pre !== '' && preg_match('#^'.$ec.preg_quote($this->swap_pre).'#', $parts[$i])) + { + $parts[$i] = preg_replace('#^'.$ec.preg_quote($this->swap_pre).'(\S+?)#', '\\1'.$this->dbprefix.'\\2', $parts[$i]); + } + // We only add the table prefix if it does not already exist + else + { + preg_match('#^'.$ec.preg_quote($this->dbprefix).'#', $parts[$i]) OR $parts[$i] = $this->dbprefix.$parts[$i]; + } + + // Put the parts back together + $item = implode('.', $parts); + } + + if ($protect_identifiers === TRUE) + { + $item = $this->escape_identifiers($item); + } + + return $item.$alias; + } + + // Is there a table prefix? If not, no need to insert it + if ($this->dbprefix !== '') + { + // Verify table prefix and replace if necessary + if ($this->swap_pre !== '' && strpos($item, $this->swap_pre) === 0) + { + $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); + } + // Do we prefix an item with no segments? + elseif ($prefix_single === TRUE && strpos($item, $this->dbprefix) !== 0) + { + $item = $this->dbprefix.$item; + } + } + + if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) + { + $item = $this->escape_identifiers($item); + } + + return $item.$alias; + } + + // -------------------------------------------------------------------- + + /** + * Dummy method that allows Query Builder class to be disabled + * and keep count_all() working. + * + * @return void + */ + protected function _reset_select() + { + } } - -/* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */ \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php old mode 100755 new mode 100644 index f158b5f..85b58fd --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,383 +1,1033 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - log_message('debug', "Database Forge Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Add Key - * - * @access public - * @param string key - * @param string type - * @return void - */ - function add_key($key = '', $primary = FALSE) - { - if (is_array($key)) - { - foreach ($key as $one) - { - $this->add_key($one, $primary); - } - - return; - } - - if ($key == '') - { - show_error('Key information is required for that operation.'); - } - - if ($primary === TRUE) - { - $this->primary_keys[] = $key; - } - else - { - $this->keys[] = $key; - } - } - - // -------------------------------------------------------------------- - - /** - * Add Field - * - * @access public - * @param string collation - * @return void - */ - function add_field($field = '') - { - if ($field == '') - { - show_error('Field information is required.'); - } - - if (is_string($field)) - { - if ($field == 'id') - { - $this->add_field(array( - 'id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - )); - $this->add_key('id', TRUE); - } - else - { - if (strpos($field, ' ') === FALSE) - { - show_error('Field information is required for that operation.'); - } - - $this->fields[] = $field; - } - } - - if (is_array($field)) - { - $this->fields = array_merge($this->fields, $field); - } - - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access public - * @param string the table name - * @return bool - */ - function create_table($table = '', $if_not_exists = FALSE) - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - - $this->_reset(); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($this->db->dbprefix.$table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Rename Table - * - * @access public - * @param string the old table name - * @param string the new table name - * @return bool - */ - function rename_table($table_name, $new_table_name) - { - if ($table_name == '' OR $new_table_name == '') - { - show_error('A table name is required for that operation.'); - } - - $sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Column Add - * - * @access public - * @param string the table name - * @param string the column name - * @param string the column definition - * @return bool - */ - function add_column($table = '', $field = array(), $after_field = '') - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - // add field info into field array, but we can only do one at a time - // so we cycle through - - foreach ($field as $k => $v) - { - $this->add_field(array($k => $field[$k])); - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); - - $this->_reset(); - - if ($this->db->query($sql) === FALSE) - { - return FALSE; - } - } - - return TRUE; - - } - - // -------------------------------------------------------------------- - - /** - * Column Drop - * - * @access public - * @param string the table name - * @param string the column name - * @return bool - */ - function drop_column($table = '', $column_name = '') - { - - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - if ($column_name == '') - { - show_error('A column name is required for that operation.'); - } - - $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Column Modify - * - * @access public - * @param string the table name - * @param string the column name - * @param string the column definition - * @return bool - */ - function modify_column($table = '', $field = array()) - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - // add field info into field array, but we can only do one at a time - // so we cycle through - - foreach ($field as $k => $v) - { - // If no name provided, use the current name - if ( ! isset($field[$k]['name'])) - { - $field[$k]['name'] = $k; - } - - $this->add_field(array($k => $field[$k])); - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); - - $this->_reset(); - - if ($this->db->query($sql) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Reset - * - * Resets table creation vars - * - * @access private - * @return void - */ - function _reset() - { - $this->fields = array(); - $this->keys = array(); - $this->primary_keys = array(); - } +abstract class CI_DB_forge { + + /** + * Database object + * + * @var object + */ + protected $db; + + /** + * Fields data + * + * @var array + */ + public $fields = array(); + + /** + * Keys data + * + * @var array + */ + public $keys = array(); + + /** + * Primary Keys data + * + * @var array + */ + public $primary_keys = array(); + + /** + * Database character set + * + * @var string + */ + public $db_char_set = ''; + + // -------------------------------------------------------------------- + + /** + * CREATE DATABASE statement + * + * @var string + */ + protected $_create_database = 'CREATE DATABASE %s'; + + /** + * DROP DATABASE statement + * + * @var string + */ + protected $_drop_database = 'DROP DATABASE %s'; + + /** + * CREATE TABLE statement + * + * @var string + */ + protected $_create_table = "%s %s (%s\n)"; + + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS'; + + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = FALSE; + + /** + * DROP TABLE IF EXISTS statement + * + * @var string + */ + protected $_drop_table_if = 'DROP TABLE IF EXISTS'; + + /** + * RENAME TABLE statement + * + * @var string + */ + protected $_rename_table = 'ALTER TABLE %s RENAME TO %s;'; + + /** + * UNSIGNED support + * + * @var bool|array + */ + protected $_unsigned = TRUE; + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = ''; + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = ' DEFAULT '; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + $this->db =& $db; + log_message('info', 'Database Forge Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + if ($this->_create_database === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + elseif ( ! $this->db->query(sprintf($this->_create_database, $this->db->escape_identifiers($db_name), $this->db->char_set, $this->db->dbcollat))) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + if ( ! empty($this->db->data_cache['db_names'])) + { + $this->db->data_cache['db_names'][] = $db_name; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name + * @return bool + */ + public function drop_database($db_name) + { + if ($this->_drop_database === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + elseif ( ! $this->db->query(sprintf($this->_drop_database, $this->db->escape_identifiers($db_name)))) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + if ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($db_name), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Add Key + * + * @param string $key + * @param bool $primary + * @return CI_DB_forge + */ + public function add_key($key, $primary = FALSE) + { + // DO NOT change this! This condition is only applicable + // for PRIMARY keys because you can only have one such, + // and therefore all fields you add to it will be included + // in the same, composite PRIMARY KEY. + // + // It's not the same for regular indexes. + if ($primary === TRUE && is_array($key)) + { + foreach ($key as $one) + { + $this->add_key($one, $primary); + } + + return $this; + } + + if ($primary === TRUE) + { + $this->primary_keys[] = $key; + } + else + { + $this->keys[] = $key; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Add Field + * + * @param array $field + * @return CI_DB_forge + */ + public function add_field($field) + { + if (is_string($field)) + { + if ($field === 'id') + { + $this->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); + $this->add_key('id', TRUE); + } + else + { + if (strpos($field, ' ') === FALSE) + { + show_error('Field information is required for that operation.'); + } + + $this->fields[] = $field; + } + } + + if (is_array($field)) + { + $this->fields = array_merge($this->fields, $field); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string $table Table name + * @param bool $if_not_exists Whether to add IF NOT EXISTS condition + * @param array $attributes Associative array of table attributes + * @return bool + */ + public function create_table($table, $if_not_exists = FALSE, array $attributes = array()) + { + if ($table === '') + { + show_error('A table name is required for that operation.'); + } + else + { + $table = $this->db->dbprefix.$table; + } + + if (count($this->fields) === 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_create_table($table, $if_not_exists, $attributes); + + if (is_bool($sql)) + { + $this->_reset(); + if ($sql === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + } + + if (($result = $this->db->query($sql)) !== FALSE) + { + if (isset($this->db->data_cache['table_names'])) + { + $this->db->data_cache['table_names'][] = $table; + } + + // Most databases don't support creating indexes from within the CREATE TABLE statement + if ( ! empty($this->keys)) + { + for ($i = 0, $sqls = $this->_process_indexes($table), $c = count($sqls); $i < $c; $i++) + { + $this->db->query($sqls[$i]); + } + } + } + + $this->_reset(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string $table Table name + * @param bool $if_not_exists Whether to add 'IF NOT EXISTS' condition + * @param array $attributes Associative array of table attributes + * @return mixed + */ + protected function _create_table($table, $if_not_exists, $attributes) + { + if ($if_not_exists === TRUE && $this->_create_table_if === FALSE) + { + if ($this->db->table_exists($table)) + { + return TRUE; + } + + $if_not_exists = FALSE; + } + + $sql = ($if_not_exists) + ? sprintf($this->_create_table_if, $this->db->escape_identifiers($table)) + : 'CREATE TABLE'; + + $columns = $this->_process_fields(TRUE); + for ($i = 0, $c = count($columns); $i < $c; $i++) + { + $columns[$i] = ($columns[$i]['_literal'] !== FALSE) + ? "\n\t".$columns[$i]['_literal'] + : "\n\t".$this->_process_column($columns[$i]); + } + + $columns = implode(',', $columns) + .$this->_process_primary_keys($table); + + // Are indexes created from within the CREATE TABLE statement? (e.g. in MySQL) + if ($this->_create_table_keys === TRUE) + { + $columns .= $this->_process_indexes($table); + } + + // _create_table will usually have the following format: "%s %s (%s\n)" + $sql = sprintf($this->_create_table.'%s', + $sql, + $this->db->escape_identifiers($table), + $columns, + $this->_create_table_attr($attributes) + ); + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * CREATE TABLE attributes + * + * @param array $attributes Associative array of table attributes + * @return string + */ + protected function _create_table_attr($attributes) + { + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' '.$attributes[$key]; + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @param string $table_name Table name + * @param bool $if_exists Whether to add an IF EXISTS condition + * @return bool + */ + public function drop_table($table_name, $if_exists = FALSE) + { + if ($table_name === '') + { + return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE; + } + + if (($query = $this->_drop_table($this->db->dbprefix.$table_name, $if_exists)) === TRUE) + { + return TRUE; + } + + $query = $this->db->query($query); + + // Update table list cache + if ($query && ! empty($this->db->data_cache['table_names'])) + { + $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['table_names'][$key]); + } + } + + return $query; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * Generates a platform-specific DROP TABLE string + * + * @param string $table Table name + * @param bool $if_exists Whether to add an IF EXISTS condition + * @return mixed (Returns a platform-specific DROP table string, or TRUE to indicate there's nothing to do) + */ + protected function _drop_table($table, $if_exists) + { + $sql = 'DROP TABLE'; + + if ($if_exists) + { + if ($this->_drop_table_if === FALSE) + { + if ( ! $this->db->table_exists($table)) + { + return TRUE; + } + } + else + { + $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table)); + } + } + + return $sql.' '.$this->db->escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Rename Table + * + * @param string $table_name Old table name + * @param string $new_table_name New table name + * @return bool + */ + public function rename_table($table_name, $new_table_name) + { + if ($table_name === '' OR $new_table_name === '') + { + show_error('A table name is required for that operation.'); + return FALSE; + } + elseif ($this->_rename_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $result = $this->db->query(sprintf($this->_rename_table, + $this->db->escape_identifiers($this->db->dbprefix.$table_name), + $this->db->escape_identifiers($this->db->dbprefix.$new_table_name)) + ); + + if ($result && ! empty($this->db->data_cache['table_names'])) + { + $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE); + if ($key !== FALSE) + { + $this->db->data_cache['table_names'][$key] = $this->db->dbprefix.$new_table_name; + } + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Column Add + * + * @todo Remove deprecated $_after option in 3.1+ + * @param string $table Table name + * @param array $field Column definition + * @param string $_after Column for AFTER clause (deprecated) + * @return bool + */ + public function add_column($table, $field, $_after = NULL) + { + // Work-around for literal column definitions + is_array($field) OR $field = array($field); + + foreach (array_keys($field) as $k) + { + // Backwards-compatibility work-around for MySQL/CUBRID AFTER clause (remove in 3.1+) + if ($_after !== NULL && is_array($field[$k]) && ! isset($field[$k]['after'])) + { + $field[$k]['after'] = $_after; + } + + $this->add_field(array($k => $field[$k])); + } + + $sqls = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->_process_fields()); + $this->_reset(); + if ($sqls === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { + if ($this->db->query($sqls[$i]) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Column Drop + * + * @param string $table Table name + * @param string $column_name Column name + * @return bool + */ + public function drop_column($table, $column_name) + { + $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); + if ($sql === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Modify + * + * @param string $table Table name + * @param string $field Column definition + * @return bool + */ + public function modify_column($table, $field) + { + // Work-around for literal column definitions + is_array($field) OR $field = array($field); + + foreach (array_keys($field) as $k) + { + $this->add_field(array($k => $field[$k])); + } + + if (count($this->fields) === 0) + { + show_error('Field information is required.'); + } + + $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->_process_fields()); + $this->_reset(); + if ($sqls === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { + if ($this->db->query($sqls[$i]) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '; + + // DROP has everything it needs now. + if ($alter_type === 'DROP') + { + return $sql.'DROP COLUMN '.$this->db->escape_identifiers($field); + } + + $sql .= ($alter_type === 'ADD') + ? 'ADD ' + : $alter_type.' COLUMN '; + + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql + .($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i])); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process fields + * + * @param bool $create_table + * @return array + */ + protected function _process_fields($create_table = FALSE) + { + $fields = array(); + + foreach ($this->fields as $key => $attributes) + { + if (is_int($key) && ! is_array($attributes)) + { + $fields[] = array('_literal' => $attributes); + continue; + } + + $attributes = array_change_key_case($attributes, CASE_UPPER); + + if ($create_table === TRUE && empty($attributes['TYPE'])) + { + continue; + } + + isset($attributes['TYPE']) && $this->_attr_type($attributes); + + $field = array( + 'name' => $key, + 'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : NULL, + 'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : NULL, + 'length' => '', + 'unsigned' => '', + 'null' => NULL, + 'unique' => '', + 'default' => '', + 'auto_increment' => '', + '_literal' => FALSE + ); + + isset($attributes['TYPE']) && $this->_attr_unsigned($attributes, $field); + + if ($create_table === FALSE) + { + if (isset($attributes['AFTER'])) + { + $field['after'] = $attributes['AFTER']; + } + elseif (isset($attributes['FIRST'])) + { + $field['first'] = (bool) $attributes['FIRST']; + } + } + + $this->_attr_default($attributes, $field); + + if (isset($attributes['NULL'])) + { + if ($attributes['NULL'] === TRUE) + { + $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; + } + else + { + $field['null'] = ' NOT NULL'; + } + } + elseif ($create_table === TRUE) + { + $field['null'] = ' NOT NULL'; + } + + $this->_attr_auto_increment($attributes, $field); + $this->_attr_unique($attributes, $field); + + if (isset($attributes['COMMENT'])) + { + $field['comment'] = $this->db->escape($attributes['COMMENT']); + } + + if (isset($attributes['TYPE']) && ! empty($attributes['CONSTRAINT'])) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']); + default: + $field['length'] = is_array($attributes['CONSTRAINT']) + ? '('.implode(',', $attributes['CONSTRAINT']).')' + : '('.$attributes['CONSTRAINT'].')'; + break; + } + } + + $fields[] = $field; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['default'] + .$field['null'] + .$field['auto_increment'] + .$field['unique']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Usually overridden by drivers + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNSIGNED + * + * Depending on the _unsigned property value: + * + * - TRUE will always set $field['unsigned'] to 'UNSIGNED' + * - FALSE will always set $field['unsigned'] to '' + * - array(TYPE) will set $field['unsigned'] to 'UNSIGNED', + * if $attributes['TYPE'] is found in the array + * - array(TYPE => UTYPE) will change $field['type'], + * from TYPE to UTYPE in case of a match + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unsigned(&$attributes, &$field) + { + if (empty($attributes['UNSIGNED']) OR $attributes['UNSIGNED'] !== TRUE) + { + return; + } + + // Reset the attribute in order to avoid issues if we do type conversion + $attributes['UNSIGNED'] = FALSE; + + if (is_array($this->_unsigned)) + { + foreach (array_keys($this->_unsigned) as $key) + { + if (is_int($key) && strcasecmp($attributes['TYPE'], $this->_unsigned[$key]) === 0) + { + $field['unsigned'] = ' UNSIGNED'; + return; + } + elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0) + { + $field['type'] = $key; + return; + } + } + + return; + } + + $field['unsigned'] = ($this->_unsigned === TRUE) ? ' UNSIGNED' : ''; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute DEFAULT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_default(&$attributes, &$field) + { + if ($this->_default === FALSE) + { + return; + } + + if (array_key_exists('DEFAULT', $attributes)) + { + if ($attributes['DEFAULT'] === NULL) + { + $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null; + + // Override the NULL attribute if that's our default + $attributes['NULL'] = TRUE; + $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; + } + else + { + $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' AUTO_INCREMENT'; + } + } + + // -------------------------------------------------------------------- + + /** + * Process primary keys + * + * @param string $table Table name + * @return string + */ + protected function _process_primary_keys($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->primary_keys); $i < $c; $i++) + { + if ( ! isset($this->fields[$this->primary_keys[$i]])) + { + unset($this->primary_keys[$i]); + } + } + + if (count($this->primary_keys) > 0) + { + $sql .= ",\n\tCONSTRAINT ".$this->db->escape_identifiers('pk_'.$table) + .' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($this->primary_keys)).')'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table Table name + * @return string[] list of SQL statements + */ + protected function _process_indexes($table) + { + $sqls = array(); + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers($table.'_'.implode('_', $this->keys[$i])) + .' ON '.$this->db->escape_identifiers($table) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');'; + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Reset + * + * Resets table creation vars + * + * @return void + */ + protected function _reset() + { + $this->fields = $this->keys = $this->primary_keys = array(); + } } - -/* End of file DB_forge.php */ -/* Location: ./system/database/DB_forge.php */ \ No newline at end of file diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php new file mode 100644 index 0000000..f35b9fd --- /dev/null +++ b/system/database/DB_query_builder.php @@ -0,0 +1,2808 @@ +_protect_identifiers; + + foreach ($select as $val) + { + $val = trim($val); + + if ($val !== '') + { + $this->qb_select[] = $val; + $this->qb_no_escape[] = $escape; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_select[] = $val; + $this->qb_cache_exists[] = 'select'; + $this->qb_cache_no_escape[] = $escape; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Select Max + * + * Generates a SELECT MAX(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_max($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MAX'); + } + + // -------------------------------------------------------------------- + + /** + * Select Min + * + * Generates a SELECT MIN(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_min($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MIN'); + } + + // -------------------------------------------------------------------- + + /** + * Select Average + * + * Generates a SELECT AVG(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_avg($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'AVG'); + } + + // -------------------------------------------------------------------- + + /** + * Select Sum + * + * Generates a SELECT SUM(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_sum($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'SUM'); + } + + // -------------------------------------------------------------------- + + /** + * SELECT [MAX|MIN|AVG|SUM]() + * + * @used-by select_max() + * @used-by select_min() + * @used-by select_avg() + * @used-by select_sum() + * + * @param string $select Field name + * @param string $alias + * @param string $type + * @return CI_DB_query_builder + */ + protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') + { + if ( ! is_string($select) OR $select === '') + { + $this->display_error('db_invalid_query'); + } + + $type = strtoupper($type); + + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) + { + show_error('Invalid function type: '.$type); + } + + if ($alias === '') + { + $alias = $this->_create_alias_from_table(trim($select)); + } + + $sql = $type.'('.$this->protect_identifiers(trim($select)).') AS '.$this->escape_identifiers(trim($alias)); + + $this->qb_select[] = $sql; + $this->qb_no_escape[] = NULL; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_select[] = $sql; + $this->qb_cache_exists[] = 'select'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Determines the alias name based on the table + * + * @param string $item + * @return string + */ + protected function _create_alias_from_table($item) + { + if (strpos($item, '.') !== FALSE) + { + $item = explode('.', $item); + return end($item); + } + + return $item; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @param bool $val + * @return CI_DB_query_builder + */ + public function distinct($val = TRUE) + { + $this->qb_distinct = is_bool($val) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @param mixed $from can be a string or array + * @return CI_DB_query_builder + */ + public function from($from) + { + foreach ((array) $from as $val) + { + if (strpos($val, ',') !== FALSE) + { + foreach (explode(',', $val) as $v) + { + $v = trim($v); + $this->_track_aliases($v); + + $this->qb_from[] = $v = $this->protect_identifiers($v, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_from[] = $v; + $this->qb_cache_exists[] = 'from'; + } + } + } + else + { + $val = trim($val); + + // Extract any aliases that might exist. We use this information + // in the protect_identifiers to know whether to add a table prefix + $this->_track_aliases($val); + + $this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_from[] = $val; + $this->qb_cache_exists[] = 'from'; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * JOIN + * + * Generates the JOIN portion of the query + * + * @param string + * @param string the join condition + * @param string the type of join + * @param string whether not to try to escape identifiers + * @return CI_DB_query_builder + */ + public function join($table, $cond, $type = '', $escape = NULL) + { + if ($type !== '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + // Extract any aliases that might exist. We use this information + // in the protect_identifiers to know whether to add a table prefix + $this->_track_aliases($table); + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if ( ! $this->_has_operator($cond)) + { + $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')'; + } + elseif ($escape === FALSE) + { + $cond = ' ON '.$cond; + } + else + { + // Split multiple conditions + if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) + { + $conditions = array(); + $joints = $joints[0]; + array_unshift($joints, array('', 0)); + + for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) + { + $joints[$i][1] += strlen($joints[$i][0]); // offset + $conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]); + $pos = $joints[$i][1] - strlen($joints[$i][0]); + $joints[$i] = $joints[$i][0]; + } + } + else + { + $conditions = array($cond); + $joints = array(''); + } + + $cond = ' ON '; + for ($i = 0, $c = count($conditions); $i < $c; $i++) + { + $operator = $this->_get_operator($conditions[$i]); + $cond .= $joints[$i]; + $cond .= preg_match("/(\(*)?([\[\]\w\.'-]+)".preg_quote($operator)."(.*)/i", $conditions[$i], $match) + ? $match[1].$this->protect_identifiers($match[2]).$operator.$this->protect_identifiers($match[3]) + : $conditions[$i]; + } + } + + // Do we want to escape the table name? + if ($escape === TRUE) + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // Assemble the JOIN statement + $this->qb_join[] = $join = $type.'JOIN '.$table.$cond; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_join[] = $join; + $this->qb_cache_exists[] = 'join'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * WHERE + * + * Generates the WHERE portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed + * @param mixed + * @param bool + * @return CI_DB_query_builder + */ + public function where($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_where', $key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE + * + * Generates the WHERE portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed + * @param mixed + * @param bool + * @return CI_DB_query_builder + */ + public function or_where($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_where', $key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * WHERE, HAVING + * + * @used-by where() + * @used-by or_where() + * @used-by having() + * @used-by or_having() + * + * @param string $qb_key 'qb_where' or 'qb_having' + * @param mixed $key + * @param mixed $value + * @param string $type + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL) + { + $qb_cache_key = ($qb_key === 'qb_having') ? 'qb_cache_having' : 'qb_cache_where'; + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + // If the escape value was not set will base it on the global setting + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $prefix = (count($this->$qb_key) === 0 && count($this->$qb_cache_key) === 0) + ? $this->_group_get_type('') + : $this->_group_get_type($type); + + if ($v !== NULL) + { + if ($escape === TRUE) + { + $v = $this->escape($v); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' = '; + } + } + elseif ( ! $this->_has_operator($k)) + { + // value appears not to have been set, assign the test to IS NULL + $k .= ' IS NULL'; + } + elseif (preg_match('/\s*(!?=|<>|\sIS(?:\s+NOT)?\s)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) + { + $k = substr($k, 0, $match[0][1]).($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL'); + } + + ${$qb_key} = array('condition' => $prefix.$k, 'value' => $v, 'escape' => $escape); + $this->{$qb_key}[] = ${$qb_key}; + if ($this->qb_caching === TRUE) + { + $this->{$qb_cache_key}[] = ${$qb_key}; + $this->qb_cache_exists[] = substr($qb_key, 3); + } + + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * WHERE IN + * + * Generates a WHERE field IN('item', 'item') SQL query, + * joined with 'AND' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function where_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, FALSE, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE IN + * + * Generates a WHERE field IN('item', 'item') SQL query, + * joined with 'OR' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_where_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, FALSE, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * WHERE NOT IN + * + * Generates a WHERE field NOT IN('item', 'item') SQL query, + * joined with 'AND' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function where_not_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, TRUE, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE NOT IN + * + * Generates a WHERE field NOT IN('item', 'item') SQL query, + * joined with 'OR' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, TRUE, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * Internal WHERE IN + * + * @used-by where_in() + * @used-by or_where_in() + * @used-by where_not_in() + * @used-by or_where_not_in() + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $not If the statement would be IN or NOT IN + * @param string $type + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL) + { + if ($key === NULL OR $values === NULL) + { + return $this; + } + + if ( ! is_array($values)) + { + $values = array($values); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + $not = ($not) ? ' NOT' : ''; + + if ($escape === TRUE) + { + $where_in = array(); + foreach ($values as $value) + { + $where_in[] = $this->escape($value); + } + } + else + { + $where_in = array_values($values); + } + + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') + : $this->_group_get_type($type); + + $where_in = array( + 'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')', + 'value' => NULL, + 'escape' => $escape + ); + + $this->qb_where[] = $where_in; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_where[] = $where_in; + $this->qb_cache_exists[] = 'where'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIKE + * + * Generates a %LIKE% portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'AND ', $side, '', $escape); + } + + // -------------------------------------------------------------------- + + /** + * NOT LIKE + * + * Generates a NOT LIKE portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function not_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'AND ', $side, 'NOT', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR LIKE + * + * Generates a %LIKE% portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'OR ', $side, '', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR NOT LIKE + * + * Generates a NOT LIKE portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_not_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'OR ', $side, 'NOT', $escape); + } + + // -------------------------------------------------------------------- + + /** + * Internal LIKE + * + * @used-by like() + * @used-by or_like() + * @used-by not_like() + * @used-by or_not_like() + * + * @param mixed $field + * @param string $match + * @param string $type + * @param string $side + * @param string $not + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL) + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + // lowercase $side in case somebody writes e.g. 'BEFORE' instead of 'before' (doh) + $side = strtolower($side); + + foreach ($field as $k => $v) + { + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') : $this->_group_get_type($type); + + if ($escape === TRUE) + { + $v = $this->escape_like_str($v); + } + + switch ($side) + { + case 'none': + $v = "'{$v}'"; + break; + case 'before': + $v = "'%{$v}'"; + break; + case 'after': + $v = "'{$v}%'"; + break; + case 'both': + default: + $v = "'%{$v}%'"; + break; + } + + // some platforms require an escape sequence definition for LIKE wildcards + if ($escape === TRUE && $this->_like_escape_str !== '') + { + $v .= sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + $qb_where = array('condition' => "{$prefix} {$k} {$not} LIKE {$v}", 'value' => NULL, 'escape' => $escape); + $this->qb_where[] = $qb_where; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_where[] = $qb_where; + $this->qb_cache_exists[] = 'where'; + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group. + * + * @param string $not (Internal use only) + * @param string $type (Internal use only) + * @return CI_DB_query_builder + */ + public function group_start($not = '', $type = 'AND ') + { + $type = $this->_group_get_type($type); + + $this->qb_where_group_started = TRUE; + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; + $where = array( + 'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (', + 'value' => NULL, + 'escape' => FALSE + ); + + $this->qb_where[] = $where; + if ($this->qb_caching) + { + $this->qb_cache_where[] = $where; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but ORs the group + * + * @return CI_DB_query_builder + */ + public function or_group_start() + { + return $this->group_start('', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but NOTs the group + * + * @return CI_DB_query_builder + */ + public function not_group_start() + { + return $this->group_start('NOT ', 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but OR NOTs the group + * + * @return CI_DB_query_builder + */ + public function or_not_group_start() + { + return $this->group_start('NOT ', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Ends a query group + * + * @return CI_DB_query_builder + */ + public function group_end() + { + $this->qb_where_group_started = FALSE; + $where = array( + 'condition' => str_repeat(' ', $this->qb_where_group_count--).')', + 'value' => NULL, + 'escape' => FALSE + ); + + $this->qb_where[] = $where; + if ($this->qb_caching) + { + $this->qb_cache_where[] = $where; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Group_get_type + * + * @used-by group_start() + * @used-by _like() + * @used-by _wh() + * @used-by _where_in() + * + * @param string $type + * @return string + */ + protected function _group_get_type($type) + { + if ($this->qb_where_group_started) + { + $type = ''; + $this->qb_where_group_started = FALSE; + } + + return $type; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @param string $by + * @param bool $escape + * @return CI_DB_query_builder + */ + public function group_by($by, $escape = NULL) + { + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if (is_string($by)) + { + $by = ($escape === TRUE) + ? explode(',', $by) + : array($by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val !== '') + { + $val = array('field' => $val, 'escape' => $escape); + + $this->qb_groupby[] = $val; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_groupby[] = $val; + $this->qb_cache_exists[] = 'groupby'; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * HAVING + * + * Separates multiple calls with 'AND'. + * + * @param string $key + * @param string $value + * @param bool $escape + * @return CI_DB_query_builder + */ + public function having($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_having', $key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR HAVING + * + * Separates multiple calls with 'OR'. + * + * @param string $key + * @param string $value + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_having($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_having', $key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return CI_DB_query_builder + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + + if ($direction === 'RANDOM') + { + $direction = ''; + + // Do we have a seed value? + $orderby = ctype_digit((string) $orderby) + ? sprintf($this->_random_keyword[1], $orderby) + : $this->_random_keyword[0]; + } + elseif (empty($orderby)) + { + return $this; + } + elseif ($direction !== '') + { + $direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : ''; + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if ($escape === FALSE) + { + $qb_orderby[] = array('field' => $orderby, 'direction' => $direction, 'escape' => FALSE); + } + else + { + $qb_orderby = array(); + foreach (explode(',', $orderby) as $field) + { + $qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) + ? array('field' => ltrim(substr($field, 0, $match[0][1])), 'direction' => ' '.$match[1][0], 'escape' => TRUE) + : array('field' => trim($field), 'direction' => $direction, 'escape' => TRUE); + } + } + + $this->qb_orderby = array_merge($this->qb_orderby, $qb_orderby); + if ($this->qb_caching === TRUE) + { + $this->qb_cache_orderby = array_merge($this->qb_cache_orderby, $qb_orderby); + $this->qb_cache_exists[] = 'orderby'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * @param int $value LIMIT value + * @param int $offset OFFSET value + * @return CI_DB_query_builder + */ + public function limit($value, $offset = 0) + { + is_null($value) OR $this->qb_limit = (int) $value; + empty($offset) OR $this->qb_offset = (int) $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @param int $offset OFFSET value + * @return CI_DB_query_builder + */ + public function offset($offset) + { + empty($offset) OR $this->qb_offset = (int) $offset; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIMIT string + * + * Generates a platform-specific LIMIT clause. + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.($this->qb_offset ? $this->qb_offset.', ' : '').(int) $this->qb_limit; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. + * + * Allows key/value pairs to be set for inserting or updating + * + * @param mixed + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set($key, $value = '', $escape = NULL) + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $this->qb_set[$this->protect_identifiers($k, FALSE, $escape)] = ($escape) + ? $this->escape($v) : $v; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get SELECT query string + * + * Compiles a SELECT query string and returns the sql. + * + * @param string the table name to select from (optional) + * @param bool TRUE: resets QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_select($table = '', $reset = TRUE) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + $select = $this->_compile_select(); + + if ($reset === TRUE) + { + $this->_reset_select(); + } + + return $select; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @param string the table + * @param string the limit clause + * @param string the offset clause + * @return CI_DB_result + */ + public function get($table = '', $limit = NULL, $offset = NULL) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + if ( ! empty($limit)) + { + $this->limit($limit, $offset); + } + + $result = $this->query($this->_compile_select()); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * "Count All Results" query + * + * Generates a platform-specific query string that counts all records + * returned by an Query Builder query. + * + * @param string + * @param bool the reset clause + * @return int + */ + public function count_all_results($table = '', $reset = TRUE) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + // ORDER BY usage is often problematic here (most notably + // on Microsoft SQL Server) and ultimately unnecessary + // for selecting COUNT(*) ... + $qb_orderby = $this->qb_orderby; + $qb_cache_orderby = $this->qb_cache_orderby; + $this->qb_orderby = $this->qb_cache_orderby = array(); + + $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset) + ? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results") + : $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows'))); + + if ($reset === TRUE) + { + $this->_reset_select(); + } + else + { + $this->qb_orderby = $qb_orderby; + $this->qb_cache_orderby = $qb_cache_orderby; + } + + if ($result->num_rows() === 0) + { + return 0; + } + + $row = $result->row(); + return (int) $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * get_where() + * + * Allows the where clause, limit and offset to be added directly + * + * @param string $table + * @param string $where + * @param int $limit + * @param int $offset + * @return CI_DB_result + */ + public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL) + { + if ($table !== '') + { + $this->from($table); + } + + if ($where !== NULL) + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit, $offset); + } + + $result = $this->query($this->_compile_select()); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Insert_Batch + * + * Compiles batch insert strings and runs the queries + * + * @param string $table Table to insert into + * @param array $set An associative array of insert values + * @param bool $escape Whether to escape values and identifiers + * @return int Number of rows inserted or FALSE on failure + */ + public function insert_batch($table, $set = NULL, $escape = NULL, $batch_size = 100) + { + if ($set === NULL) + { + if (empty($this->qb_set)) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + } + else + { + if (empty($set)) + { + return ($this->db_debug) ? $this->display_error('insert_batch() called with no data') : FALSE; + } + + $this->set_insert_batch($set, '', $escape); + } + + if (strlen($table) === 0) + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + // Batch this baby + $affected_rows = 0; + for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size) + { + if ($this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size)))) + { + $affected_rows += $this->affected_rows(); + } + } + + $this->_reset_write(); + return $affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); + } + + // -------------------------------------------------------------------- + + /** + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * + * @param mixed + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set_insert_batch($key, $value = '', $escape = NULL) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + $keys = array_keys($this->_object_to_array(reset($key))); + sort($keys); + + foreach ($key as $row) + { + $row = $this->_object_to_array($row); + if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) + { + // batch function above returns an error on an empty array + $this->qb_set[] = array(); + return; + } + + ksort($row); // puts $row in the same order as our keys + + if ($escape !== FALSE) + { + $clean = array(); + foreach ($row as $value) + { + $clean[] = $this->escape($value); + } + + $row = $clean; + } + + $this->qb_set[] = '('.implode(',', $row).')'; + } + + foreach ($keys as $k) + { + $this->qb_keys[] = $this->protect_identifiers($k, FALSE, $escape); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get INSERT query string + * + * Compiles an insert query and returns the sql + * + * @param string the table to insert into + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_insert($table = '', $reset = TRUE) + { + if ($this->_validate_insert($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_insert( + $this->protect_identifiers( + $this->qb_from[0], TRUE, NULL, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) + ); + + if ($reset === TRUE) + { + $this->_reset_write(); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @param string the table to insert data into + * @param array an associative array of insert values + * @param bool $escape Whether to escape values and identifiers + * @return bool TRUE on success, FALSE on failure + */ + public function insert($table = '', $set = NULL, $escape = NULL) + { + if ($set !== NULL) + { + $this->set($set, '', $escape); + } + + if ($this->_validate_insert($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_insert( + $this->protect_identifiers( + $this->qb_from[0], TRUE, $escape, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) + ); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Validate Insert + * + * This method is used by both insert() and get_compiled_insert() to + * validate that the there data is actually being set and that table + * has been chosen to be inserted into. + * + * @param string the table to insert data into + * @return string + */ + protected function _validate_insert($table = '') + { + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table !== '') + { + $this->qb_from[0] = $table; + } + elseif ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Replace + * + * Compiles an replace into string and runs the query + * + * @param string the table to replace data into + * @param array an associative array of insert values + * @return bool TRUE on success, FALSE on failure + */ + public function replace($table = '', $set = NULL) + { + if ($set !== NULL) + { + $this->set($set); + } + + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * Note: This is only used (and overridden) by MySQL and CUBRID. + * + * @return string + */ + protected function _from_tables() + { + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Get UPDATE query string + * + * Compiles an update query and returns the sql + * + * @param string the table to update + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_update($table = '', $reset = TRUE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($this->_validate_update($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_update($this->qb_from[0], $this->qb_set); + + if ($reset === TRUE) + { + $this->_reset_write(); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * UPDATE + * + * Compiles an update string and runs the query. + * + * @param string $table + * @param array $set An associative array of update values + * @param mixed $where + * @param int $limit + * @return bool TRUE on success, FALSE on failure + */ + public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($set !== NULL) + { + $this->set($set); + } + + if ($this->_validate_update($table) === FALSE) + { + return FALSE; + } + + if ($where !== NULL) + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit); + } + + $sql = $this->_update($this->qb_from[0], $this->qb_set); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Validate Update + * + * This method is used by both update() and get_compiled_update() to + * validate that data is actually being set and that a table has been + * chosen to be update. + * + * @param string the table to update data on + * @return bool + */ + protected function _validate_update($table) + { + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table !== '') + { + $this->qb_from = array($this->protect_identifiers($table, TRUE, NULL, FALSE)); + } + elseif ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch + * + * Compiles an update string and runs the query + * + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param string the where key + * @return int number of rows affected or FALSE on failure + */ + public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($index === NULL) + { + return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE; + } + + if ($set === NULL) + { + if (empty($this->qb_set_ub)) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + } + else + { + if (empty($set)) + { + return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE; + } + + $this->set_update_batch($set, $index); + } + + if (strlen($table) === 0) + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + // Batch this baby + $affected_rows = 0; + for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size) + { + if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index))) + { + $affected_rows += $this->affected_rows(); + } + + $this->qb_where = array(); + } + + $this->_reset_write(); + return $affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['field'].' = '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k." = CASE \n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END, '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * + * @param array + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set_update_batch($key, $index = '', $escape = NULL) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + // @todo error + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $index_set = FALSE; + $clean = array(); + foreach ($v as $k2 => $v2) + { + if ($k2 === $index) + { + $index_set = TRUE; + } + + $clean[$k2] = array( + 'field' => $this->protect_identifiers($k2, FALSE, $escape), + 'value' => ($escape === FALSE ? $v2 : $this->escape($v2)) + ); + } + + if ($index_set === FALSE) + { + return $this->display_error('db_batch_missing_index'); + } + + $this->qb_set_ub[] = $clean; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Empty Table + * + * Compiles a delete string and runs "DELETE FROM table" + * + * @param string the table to empty + * @return bool TRUE on success, FALSE on failure + */ + public function empty_table($table = '') + { + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_delete($table); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate + * + * Compiles a truncate string and runs the query + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @param string the table to truncate + * @return bool TRUE on success, FALSE on failure + */ + public function truncate($table = '') + { + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_truncate($table); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' + * + * @param string the table name + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Get DELETE query string + * + * Compiles a delete query string and returns the sql + * + * @param string the table to delete from + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_delete($table = '', $reset = TRUE) + { + $this->return_delete_sql = TRUE; + $sql = $this->delete($table, '', NULL, $reset); + $this->return_delete_sql = FALSE; + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @param mixed the table(s) to delete from. String or array + * @param mixed the where clause + * @param mixed the limit clause + * @param bool + * @return mixed + */ + public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + elseif (is_array($table)) + { + empty($where) && $reset_data = FALSE; + + foreach ($table as $single_table) + { + $this->delete($single_table, $where, $limit, $reset_data); + } + + return; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + if ($where !== '') + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit); + } + + if (count($this->qb_where) === 0) + { + return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; + } + + $sql = $this->_delete($table); + if ($reset_data) + { + $this->_reset_write(); + } + + return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string the table name + * @return string + */ + protected function _delete($table) + { + return 'DELETE FROM '.$table.$this->_compile_wh('qb_where') + .($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : ''); + } + + // -------------------------------------------------------------------- + + /** + * DB Prefix + * + * Prepends a database prefix if one exists in configuration + * + * @param string the table + * @return string + */ + public function dbprefix($table = '') + { + if ($table === '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + + /** + * Set DB Prefix + * + * Set's the DB Prefix to something new without needing to reconnect + * + * @param string the prefix + * @return string + */ + public function set_dbprefix($prefix = '') + { + return $this->dbprefix = $prefix; + } + + // -------------------------------------------------------------------- + + /** + * Track Aliases + * + * Used to track SQL statements written with aliased tables. + * + * @param string The table to inspect + * @return string + */ + protected function _track_aliases($table) + { + if (is_array($table)) + { + foreach ($table as $t) + { + $this->_track_aliases($t); + } + return; + } + + // Does the string contain a comma? If so, we need to separate + // the string into discreet statements + if (strpos($table, ',') !== FALSE) + { + return $this->_track_aliases(explode(',', $table)); + } + + // if a table alias is used we can recognize it by a space + if (strpos($table, ' ') !== FALSE) + { + // if the alias is written with the AS keyword, remove it + $table = preg_replace('/\s+AS\s+/i', ' ', $table); + + // Grab the alias + $table = trim(strrchr($table, ' ')); + + // Store the alias, if it doesn't already exist + if ( ! in_array($table, $this->qb_aliased_tables, TRUE)) + { + $this->qb_aliased_tables[] = $table; + if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables, TRUE)) + { + $this->qb_cache_aliased_tables[] = $table; + $this->qb_cache_exists[] = 'aliased_tables'; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. + * + * @param bool $select_override + * @return string + */ + protected function _compile_select($select_override = FALSE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + // Write the "select" portion of the query + if ($select_override !== FALSE) + { + $sql = $select_override; + } + else + { + $sql = ( ! $this->qb_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + if (count($this->qb_select) === 0) + { + $sql .= '*'; + } + else + { + // Cycle through the "select" portion of the query and prep each column name. + // The reason we protect identifiers here rather than in the select() function + // is because until the user calls the from() function we don't know if there are aliases + foreach ($this->qb_select as $key => $val) + { + $no_escape = isset($this->qb_no_escape[$key]) ? $this->qb_no_escape[$key] : NULL; + $this->qb_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape); + } + + $sql .= implode(', ', $this->qb_select); + } + } + + // Write the "FROM" portion of the query + if (count($this->qb_from) > 0) + { + $sql .= "\nFROM ".$this->_from_tables(); + } + + // Write the "JOIN" portion of the query + if (count($this->qb_join) > 0) + { + $sql .= "\n".implode("\n", $this->qb_join); + } + + $sql .= $this->_compile_wh('qb_where') + .$this->_compile_group_by() + .$this->_compile_wh('qb_having') + .$this->_compile_order_by(); // ORDER BY + + // LIMIT + if ($this->qb_limit !== FALSE OR $this->qb_offset) + { + return $this->_limit($sql."\n"); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Compile WHERE, HAVING statements + * + * Escapes identifiers in WHERE and HAVING statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * where(), or_where(), having(), or_having are called prior to from(), + * join() and dbprefix is added only if needed. + * + * @param string $qb_key 'qb_where' or 'qb_having' + * @return string SQL statement + */ + protected function _compile_wh($qb_key) + { + if (count($this->$qb_key) > 0) + { + for ($i = 0, $c = count($this->$qb_key); $i < $c; $i++) + { + // Is this condition already compiled? + if (is_string($this->{$qb_key}[$i])) + { + continue; + } + elseif ($this->{$qb_key}[$i]['escape'] === FALSE) + { + $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'].(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : ''); + continue; + } + + // Split multiple conditions + $conditions = preg_split( + '/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i', + $this->{$qb_key}[$i]['condition'], + -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY + ); + + for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci++) + { + if (($op = $this->_get_operator($conditions[$ci])) === FALSE + OR ! preg_match('/^(\(?)(.*)('.preg_quote($op, '/').')\s*(.*(? '(test <= foo)', /* the whole thing */ + // 1 => '(', /* optional */ + // 2 => 'test', /* the field name */ + // 3 => ' <= ', /* $op */ + // 4 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ + // 5 => ')' /* optional */ + // ); + + if ( ! empty($matches[4])) + { + $this->_is_literal($matches[4]) OR $matches[4] = $this->protect_identifiers(trim($matches[4])); + $matches[4] = ' '.$matches[4]; + } + + $conditions[$ci] = $matches[1].$this->protect_identifiers(trim($matches[2])) + .' '.trim($matches[3]).$matches[4].$matches[5]; + } + + $this->{$qb_key}[$i] = implode('', $conditions).(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : ''); + } + + return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ") + .implode("\n", $this->$qb_key); + } + + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Compile GROUP BY + * + * Escapes identifiers in GROUP BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * group_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_group_by() + { + if (count($this->qb_groupby) > 0) + { + for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) + { + // Is it already compiled? + if (is_string($this->qb_groupby[$i])) + { + continue; + } + + $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE OR $this->_is_literal($this->qb_groupby[$i]['field'])) + ? $this->qb_groupby[$i]['field'] + : $this->protect_identifiers($this->qb_groupby[$i]['field']); + } + + return "\nGROUP BY ".implode(', ', $this->qb_groupby); + } + + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Compile ORDER BY + * + * Escapes identifiers in ORDER BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * order_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_order_by() + { + if (empty($this->qb_orderby)) + { + return ''; + } + + for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) + { + if (is_string($this->qb_orderby[$i])) + { + continue; + } + + if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) + { + $this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']); + } + + $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; + } + + return "\nORDER BY ".implode(', ', $this->qb_orderby); + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @param object + * @return array + */ + protected function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + // There are some built in keys we need to ignore for this conversion + if ( ! is_object($val) && ! is_array($val) && $key !== '_parent_name') + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @param object + * @return array + */ + protected function _object_to_array_batch($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + $out = get_object_vars($object); + $fields = array_keys($out); + + foreach ($fields as $val) + { + // There are some built in keys we need to ignore for this conversion + if ($val !== '_parent_name') + { + $i = 0; + foreach ($out[$val] as $data) + { + $array[$i++][$val] = $data; + } + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Start Cache + * + * Starts QB caching + * + * @return CI_DB_query_builder + */ + public function start_cache() + { + $this->qb_caching = TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Stop Cache + * + * Stops QB caching + * + * @return CI_DB_query_builder + */ + public function stop_cache() + { + $this->qb_caching = FALSE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Flush Cache + * + * Empties the QB cache + * + * @return CI_DB_query_builder + */ + public function flush_cache() + { + $this->_reset_run(array( + 'qb_cache_select' => array(), + 'qb_cache_from' => array(), + 'qb_cache_join' => array(), + 'qb_cache_where' => array(), + 'qb_cache_groupby' => array(), + 'qb_cache_having' => array(), + 'qb_cache_orderby' => array(), + 'qb_cache_set' => array(), + 'qb_cache_exists' => array(), + 'qb_cache_no_escape' => array(), + 'qb_cache_aliased_tables' => array() + )); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Merge Cache + * + * When called, this function merges any cached QB arrays with + * locally called ones. + * + * @return void + */ + protected function _merge_cache() + { + if (count($this->qb_cache_exists) === 0) + { + return; + } + elseif (in_array('select', $this->qb_cache_exists, TRUE)) + { + $qb_no_escape = $this->qb_cache_no_escape; + } + + foreach (array_unique($this->qb_cache_exists) as $val) // select, from, etc. + { + $qb_variable = 'qb_'.$val; + $qb_cache_var = 'qb_cache_'.$val; + $qb_new = $this->$qb_cache_var; + + for ($i = 0, $c = count($this->$qb_variable); $i < $c; $i++) + { + if ( ! in_array($this->{$qb_variable}[$i], $qb_new, TRUE)) + { + $qb_new[] = $this->{$qb_variable}[$i]; + if ($val === 'select') + { + $qb_no_escape[] = $this->qb_no_escape[$i]; + } + } + } + + $this->$qb_variable = $qb_new; + if ($val === 'select') + { + $this->qb_no_escape = $qb_no_escape; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Is literal + * + * Determines if a string represents a literal value or a field name + * + * @param string $str + * @return bool + */ + protected function _is_literal($str) + { + $str = trim($str); + + if (empty($str) OR ctype_digit($str) OR (string) (float) $str === $str OR in_array(strtoupper($str), array('TRUE', 'FALSE'), TRUE)) + { + return TRUE; + } + + static $_str; + + if (empty($_str)) + { + $_str = ($this->_escape_char !== '"') + ? array('"', "'") : array("'"); + } + + return in_array($str[0], $_str, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Reset Query Builder values. + * + * Publicly-visible method to reset the QB values. + * + * @return CI_DB_query_builder + */ + public function reset_query() + { + $this->_reset_select(); + $this->_reset_write(); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder values. Called by the get() function + * + * @param array An array of fields to reset + * @return void + */ + protected function _reset_run($qb_reset_items) + { + foreach ($qb_reset_items as $item => $default_value) + { + $this->$item = $default_value; + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder values. Called by the get() function + * + * @return void + */ + protected function _reset_select() + { + $this->_reset_run(array( + 'qb_select' => array(), + 'qb_from' => array(), + 'qb_join' => array(), + 'qb_where' => array(), + 'qb_groupby' => array(), + 'qb_having' => array(), + 'qb_orderby' => array(), + 'qb_aliased_tables' => array(), + 'qb_no_escape' => array(), + 'qb_distinct' => FALSE, + 'qb_limit' => FALSE, + 'qb_offset' => FALSE + )); + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder "write" values. + * + * Called by the insert() update() insert_batch() update_batch() and delete() functions + * + * @return void + */ + protected function _reset_write() + { + $this->_reset_run(array( + 'qb_set' => array(), + 'qb_set_ub' => array(), + 'qb_from' => array(), + 'qb_join' => array(), + 'qb_where' => array(), + 'qb_orderby' => array(), + 'qb_keys' => array(), + 'qb_limit' => FALSE + )); + } + +} diff --git a/system/database/DB_result.php b/system/database/DB_result.php old mode 100755 new mode 100644 index 6d3ec77..ed5252d --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,20 +1,41 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); - } - - // -------------------------------------------------------------------- - - /** - * Custom query result. - * - * @param class_name A string that represents the type of object you want back - * @return array of objects - */ - public function custom_result_object($class_name) - { - if (array_key_exists($class_name, $this->custom_result_object)) - { - return $this->custom_result_object[$class_name]; - } - - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - // add the data to the object - $this->_data_seek(0); - $result_object = array(); - - while ($row = $this->_fetch_object()) - { - $object = new $class_name(); - - foreach ($row as $key => $value) - { - $object->$key = $value; - } - - $result_object[] = $object; - } - - // return the array - return $this->custom_result_object[$class_name] = $result_object; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "object" version. - * - * @access public - * @return object - */ - public function result_object() - { - if (count($this->result_object) > 0) - { - return $this->result_object; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_object()) - { - $this->result_object[] = $row; - } - - return $this->result_object; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - public function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Query result. Acts as a wrapper function for the following functions. - * - * @access public - * @param string - * @param string can be "object" or "array" - * @return mixed either a result object or array - */ - public function row($n = 0, $type = 'object') - { - if ( ! is_numeric($n)) - { - // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) - { - $this->row_data = $this->row_array(0); - } - - // array_key_exists() instead of isset() to allow for MySQL NULL values - if (array_key_exists($n, $this->row_data)) - { - return $this->row_data[$n]; - } - // reset the $n variable if the result was not achieved - $n = 0; - } - - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); - else return $this->custom_row_object($n, $type); - } - - // -------------------------------------------------------------------- - - /** - * Assigns an item into a particular column slot - * - * @access public - * @return object - */ - public function set_row($key, $value = NULL) - { - // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) - { - $this->row_data = $this->row_array(0); - } - - if (is_array($key)) - { - foreach ($key as $k => $v) - { - $this->row_data[$k] = $v; - } - - return; - } - - if ($key != '' AND ! is_null($value)) - { - $this->row_data[$key] = $value; - } - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - custom object version - * - * @access public - * @return object - */ - public function custom_row_object($n, $type) - { - $result = $this->custom_result_object($type); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - /** - * Returns a single result row - object version - * - * @access public - * @return object - */ - public function row_object($n = 0) - { - $result = $this->result_object(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - array version - * - * @access public - * @return array - */ - public function row_array($n = 0) - { - $result = $this->result_array(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - - // -------------------------------------------------------------------- - - /** - * Returns the "first" row - * - * @access public - * @return object - */ - public function first_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[0]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "last" row - * - * @access public - * @return object - */ - public function last_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[count($result) -1]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "next" row - * - * @access public - * @return object - */ - public function next_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row + 1])) - { - ++$this->current_row; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "previous" row - * - * @access public - * @return object - */ - public function previous_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row - 1])) - { - --$this->current_row; - } - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * The following functions are normally overloaded by the identically named - * methods in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully - * operational due to the unavailability of the database resource IDs with - * cached results. - */ - public function num_rows() { return $this->num_rows; } - public function num_fields() { return 0; } - public function list_fields() { return array(); } - public function field_data() { return array(); } - public function free_result() { return TRUE; } - protected function _data_seek() { return TRUE; } - protected function _fetch_assoc() { return array(); } - protected function _fetch_object() { return array(); } + /** + * Connection ID + * + * @var resource|object + */ + public $conn_id; + + /** + * Result ID + * + * @var resource|object + */ + public $result_id; + + /** + * Result Array + * + * @var array[] + */ + public $result_array = array(); + + /** + * Result Object + * + * @var object[] + */ + public $result_object = array(); + + /** + * Custom Result Object + * + * @var object[] + */ + public $custom_result_object = array(); + + /** + * Current Row index + * + * @var int + */ + public $current_row = 0; + + /** + * Number of rows + * + * @var int + */ + public $num_rows; + + /** + * Row data + * + * @var array + */ + public $row_data; + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param object $driver_object + * @return void + */ + public function __construct(&$driver_object) + { + $this->conn_id = $driver_object->conn_id; + $this->result_id = $driver_object->result_id; + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + if (is_int($this->num_rows)) + { + return $this->num_rows; + } + elseif (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @param string $type 'object', 'array' or a custom class name + * @return array + */ + public function result($type = 'object') + { + if ($type === 'array') + { + return $this->result_array(); + } + elseif ($type === 'object') + { + return $this->result_object(); + } + + return $this->custom_result_object($type); + } + + // -------------------------------------------------------------------- + + /** + * Custom query result. + * + * @param string $class_name + * @return array + */ + public function custom_result_object($class_name) + { + if (isset($this->custom_result_object[$class_name])) + { + return $this->custom_result_object[$class_name]; + } + elseif ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + // Don't fetch the result set again if we already have it + $_data = NULL; + if (($c = count($this->result_array)) > 0) + { + $_data = 'result_array'; + } + elseif (($c = count($this->result_object)) > 0) + { + $_data = 'result_object'; + } + + if ($_data !== NULL) + { + for ($i = 0; $i < $c; $i++) + { + $this->custom_result_object[$class_name][$i] = new $class_name(); + + foreach ($this->{$_data}[$i] as $key => $value) + { + $this->custom_result_object[$class_name][$i]->$key = $value; + } + } + + return $this->custom_result_object[$class_name]; + } + + is_null($this->row_data) OR $this->data_seek(0); + $this->custom_result_object[$class_name] = array(); + + while ($row = $this->_fetch_object($class_name)) + { + $this->custom_result_object[$class_name][] = $row; + } + + return $this->custom_result_object[$class_name]; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + // In the event that query caching is on, the result_id variable + // will not be a valid resource so we'll simply return an empty + // array. + if ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + if (($c = count($this->result_array)) > 0) + { + for ($i = 0; $i < $c; $i++) + { + $this->result_object[$i] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + + is_null($this->row_data) OR $this->data_seek(0); + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @return array + */ + public function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // In the event that query caching is on, the result_id variable + // will not be a valid resource so we'll simply return an empty + // array. + if ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + if (($c = count($this->result_object)) > 0) + { + for ($i = 0; $i < $c; $i++) + { + $this->result_array[$i] = (array) $this->result_object[$i]; + } + + return $this->result_array; + } + + is_null($this->row_data) OR $this->data_seek(0); + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Row + * + * A wrapper method. + * + * @param mixed $n + * @param string $type 'object' or 'array' + * @return mixed + */ + public function row($n = 0, $type = 'object') + { + if ( ! is_numeric($n)) + { + // We cache the row data for subsequent uses + is_array($this->row_data) OR $this->row_data = $this->row_array(0); + + // array_key_exists() instead of isset() to allow for NULL values + if (empty($this->row_data) OR ! array_key_exists($n, $this->row_data)) + { + return NULL; + } + + return $this->row_data[$n]; + } + + if ($type === 'object') return $this->row_object($n); + elseif ($type === 'array') return $this->row_array($n); + + return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /** + * Assigns an item into a particular column slot + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function set_row($key, $value = NULL) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (is_array($key)) + { + foreach ($key as $k => $v) + { + $this->row_data[$k] = $v; + } + return; + } + + if ($key !== '' && $value !== NULL) + { + $this->row_data[$key] = $value; + } + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - custom object version + * + * @param int $n + * @param string $type + * @return object + */ + public function custom_row_object($n, $type) + { + isset($this->custom_result_object[$type]) OR $this->custom_result_object[$type] = $this->custom_result_object($type); + + if (count($this->custom_result_object[$type]) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($this->custom_result_object[$type][$n])) + { + $this->current_row = $n; + } + + return $this->custom_result_object[$type][$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @param int $n + * @return object + */ + public function row_object($n = 0) + { + $result = $this->result_object(); + if (count($result) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - array version + * + * @param int $n + * @return array + */ + public function row_array($n = 0) + { + $result = $this->result_array(); + if (count($result) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @param string $type + * @return mixed + */ + public function first_row($type = 'object') + { + $result = $this->result($type); + return (count($result) === 0) ? NULL : $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @param string $type + * @return mixed + */ + public function last_row($type = 'object') + { + $result = $this->result($type); + return (count($result) === 0) ? NULL : $result[count($result) - 1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @param string $type + * @return mixed + */ + public function next_row($type = 'object') + { + $result = $this->result($type); + if (count($result) === 0) + { + return NULL; + } + + return isset($result[$this->current_row + 1]) + ? $result[++$this->current_row] + : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @param string $type + * @return mixed + */ + public function previous_row($type = 'object') + { + $result = $this->result($type); + if (count($result) === 0) + { + return NULL; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns an unbuffered row and move pointer to next row + * + * @param string $type 'array', 'object' or a custom class name + * @return mixed + */ + public function unbuffered_row($type = 'object') + { + if ($type === 'array') + { + return $this->_fetch_assoc(); + } + elseif ($type === 'object') + { + return $this->_fetch_object(); + } + + return $this->_fetch_object($type); + } + + // -------------------------------------------------------------------- + + /** + * The following methods are normally overloaded by the identically named + * methods in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver. + * These functions are primarily here to prevent undefined function errors + * when a cached result object is in use. They are not otherwise fully + * operational due to the unavailability of the database resource IDs with + * cached results. + */ + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * Overridden by driver result classes. + * + * @return int + */ + public function num_fields() + { + return 0; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names. + * + * Overridden by driver result classes. + * + * @return array + */ + public function list_fields() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data. + * + * Overridden by driver result classes. + * + * @return array + */ + public function field_data() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * Overridden by driver result classes. + * + * @return void + */ + public function free_result() + { + $this->result_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * Overridden by driver result classes. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array. + * + * Overridden by driver result classes. + * + * @return array + */ + protected function _fetch_assoc() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object. + * + * Overridden by driver result classes. + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return new $class_name(); + } } -// END DB_result class - -/* End of file DB_result.php */ -/* Location: ./system/database/DB_result.php */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php old mode 100755 new mode 100644 index 88b33ce..6642fda --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,415 +1,424 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->data_cache['db_names'])) - { - return $this->data_cache['db_names']; - } - - $query = $this->db->query($this->_list_databases()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular database exists - * - * @access public - * @param string - * @return boolean - */ - function database_exists($database_name) - { - // Some databases won't have access to the list_databases() function, so - // this is intended to allow them to override with their own functions as - // defined in $driver_utility.php - if (method_exists($this, '_database_exists')) - { - return $this->_database_exists($database_name); - } - else - { - return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; - } - } - - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - function optimize_table($table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - show_error('db_must_use_set'); - } - - $query = $this->db->query($sql); - $res = $query->result_array(); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Optimize Database - * - * @access public - * @return array - */ - function optimize_database() - { - $result = array(); - foreach ($this->db->list_tables() as $table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Build the result array... - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - $res = current($res); - $key = str_replace($this->db->database.'.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); - - $result[$key] = $res; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Repair Table - * - * @access public - * @param string the table name - * @return bool - */ - function repair_table($table_name) - { - $sql = $this->_repair_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - comma by default - * @param string The newline character - \n by default - * @param string The enclosure - double quote by default - * @return string - */ - function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') - { - if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) - { - show_error('You must submit a valid result object'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; - } - - $out = rtrim($out); - $out .= $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; - } - $out = rtrim($out); - $out .= $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $CI =& get_instance(); - $CI->load->helper('xml'); - - // Generate the result - $xml = "<{$root}>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - - // -------------------------------------------------------------------- - - /** - * Database Backup - * - * @access public - * @return void - */ - function backup($params = array()) - { - // If the parameters have not been submitted as an - // array then we know that it is simply the table - // name, which is a valid short cut. - if (is_string($params)) - { - $params = array('tables' => $params); - } - - // ------------------------------------------------------ - - // Set up our default preferences - $prefs = array( - 'tables' => array(), - 'ignore' => array(), - 'filename' => '', - 'format' => 'gzip', // gzip, zip, txt - 'add_drop' => TRUE, - 'add_insert' => TRUE, - 'newline' => "\n" - ); - - // Did the user submit any preferences? If so set them.... - if (count($params) > 0) - { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } - } - - // ------------------------------------------------------ - - // Are we backing up a complete database or individual tables? - // If no table names were submitted we'll fetch the entire table list - if (count($prefs['tables']) == 0) - { - $prefs['tables'] = $this->db->list_tables(); - } - - // ------------------------------------------------------ - - // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) - { - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Is the encoder supported? If not, we'll either issue an - // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_compression'); - } - - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Set the filename if not provided - Only needed with Zip files - if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') - { - $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; - $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); - } - - // ------------------------------------------------------ - - // Was a Gzip file requested? - if ($prefs['format'] == 'gzip') - { - return gzencode($this->_backup($prefs)); - } - - // ------------------------------------------------------ - - // Was a text file requested? - if ($prefs['format'] == 'txt') - { - return $this->_backup($prefs); - } - - // ------------------------------------------------------ - - // Was a Zip file requested? - if ($prefs['format'] == 'zip') - { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) - { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); - } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) - { - $prefs['filename'] .= '.sql'; - } - - // Load the Zip class and output it - - $CI =& get_instance(); - $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $CI->zip->get_zip(); - } - - } +abstract class CI_DB_utility { + + /** + * Database object + * + * @var object + */ + protected $db; + + // -------------------------------------------------------------------- + + /** + * List databases statement + * + * @var string + */ + protected $_list_databases = FALSE; + + /** + * OPTIMIZE TABLE statement + * + * @var string + */ + protected $_optimize_table = FALSE; + + /** + * REPAIR TABLE statement + * + * @var string + */ + protected $_repair_table = FALSE; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + $this->db =& $db; + log_message('info', 'Database Utility Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @return array + */ + public function list_databases() + { + // Is there a cached result? + if (isset($this->db->data_cache['db_names'])) + { + return $this->db->data_cache['db_names']; + } + elseif ($this->_list_databases === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $this->db->data_cache['db_names'] = array(); + + $query = $this->db->query($this->_list_databases); + if ($query === FALSE) + { + return $this->db->data_cache['db_names']; + } + + for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++) + { + $this->db->data_cache['db_names'][] = current($query[$i]); + } + + return $this->db->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular database exists + * + * @param string $database_name + * @return bool + */ + public function database_exists($database_name) + { + return in_array($database_name, $this->list_databases()); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @param string $table_name + * @return mixed + */ + public function optimize_table($table_name) + { + if ($this->_optimize_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name))); + if ($query !== FALSE) + { + $query = $query->result_array(); + return current($query); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @return mixed + */ + public function optimize_database() + { + if ($this->_optimize_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name))); + if (is_bool($res)) + { + return $res; + } + + // Build the result array... + $res = $res->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Repair Table + * + * @param string $table_name + * @return mixed + */ + public function repair_table($table_name) + { + if ($this->_repair_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name))); + if (is_bool($query)) + { + return $query; + } + + $query = $query->result_array(); + return current($query); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @param object $query Query result object + * @param string $delim Delimiter (default: ,) + * @param string $newline Newline character (default: \n) + * @param string $enclosure Enclosure (default: ") + * @return string + */ + public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"') + { + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; + } + + $out = substr($out, 0, -strlen($delim)).$newline; + + // Next blast through the result array and build out the rows + while ($row = $query->unbuffered_row('array')) + { + $line = array(); + foreach ($row as $item) + { + $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure; + } + $out .= implode($delim, $line).$newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @param object $query Query result object + * @param array $params Any preferences + * @return string + */ + public function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + get_instance()->load->helper('xml'); + + // Generate the result + $xml = '<'.$root.'>'.$newline; + while ($row = $query->unbuffered_row()) + { + $xml .= $tab.'<'.$element.'>'.$newline; + foreach ($row as $key => $val) + { + $xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).''.$newline; + } + $xml .= $tab.''.$newline; + } + + return $xml.''.$newline; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @param array $params + * @return string + */ + public function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // Set up our default preferences + $prefs = array( + 'tables' => array(), + 'ignore' => array(), + 'filename' => '', + 'format' => 'gzip', // gzip, zip, txt + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n", + 'foreign_key_checks' => TRUE + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) === 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] === 'gzip' && ! function_exists('gzencode')) + OR ($prefs['format'] === 'zip' && ! function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsupported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // Was a Zip file requested? + if ($prefs['format'] === 'zip') + { + // Set the filename if not provided (only needed with Zip files) + if ($prefs['filename'] === '') + { + $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) + .date('Y-m-d_H-i', time()).'.sql'; + } + else + { + // If they included the .zip file extension we'll remove it + if (preg_match('|.+?\.zip$|', $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match('|.+?\.sql$|', $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + } + + // Load the Zip class and output it + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + elseif ($prefs['format'] === 'txt') // Was a text file requested? + { + return $this->_backup($prefs); + } + elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested? + { + return gzencode($this->_backup($prefs)); + } + + return; + } } - - -/* End of file DB_utility.php */ -/* Location: ./system/database/DB_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php old mode 100755 new mode 100644 index 7132856..b3b436f --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -1,793 +1,405 @@ -port == '') - { - $this->port = self::DEFAULT_PORT; - } - - $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password); - - if ($conn) - { - // Check if a user wants to run queries in dry, i.e. run the - // queries but not commit them. - if (isset($this->auto_commit) && ! $this->auto_commit) - { - cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE); - } - else - { - cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE); - $this->auto_commit = TRUE; - } - } - - return $conn; - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * In CUBRID persistent DB connection is supported natively in CUBRID - * engine which can be configured in the CUBRID Broker configuration - * file by setting the CCI_PCONNECT parameter to ON. In that case, all - * connections established between the client application and the - * server will become persistent. This is calling the same - * @cubrid_connect function will establish persisten connection - * considering that the CCI_PCONNECT is ON. - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - if (cubrid_ping($this->conn_id) === FALSE) - { - $this->conn_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // In CUBRID there is no need to select a database as the database - // is chosen at the connection time. - // So, to determine if the database is "selected", all we have to - // do is ping the server and return that value. - return cubrid_ping($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // In CUBRID, there is no need to set charset or collation. - // This is why returning true will allow the application continue - // its normal process. - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - // To obtain the CUBRID Server version, no need to run the SQL query. - // CUBRID PHP API provides a function to determin this value. - // This is why we also need to add 'cubrid' value to the list of - // $driver_version_exceptions array in DB_driver class in - // version() function. - return cubrid_get_server_info($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @cubrid_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - // No need to prepare - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - if (cubrid_get_autocommit($this->conn_id)) - { - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - cubrid_commit($this->conn_id); - - if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) - { - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - cubrid_rollback($this->conn_id); - - if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) - { - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - if (function_exists('cubrid_real_escape_string') AND is_resource($this->conn_id)) - { - $str = cubrid_real_escape_string($str, $this->conn_id); - } - else - { - $str = addslashes($str); - } - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @cubrid_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @cubrid_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified table - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return cubrid_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return cubrid_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _replace($table, $keys, $values) - { - return "REPLACE INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = sprintf('"%s" = %s', $key, $val); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update_batch($table, $values, $index, $where = NULL) - { - $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field != $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $sql = "UPDATE ".$table." SET "; - $cases = ''; - - foreach ($final as $k => $v) - { - $cases .= $k.' = CASE '."\n"; - foreach ($v as $row) - { - $cases .= $row."\n"; - } - - $cases .= 'ELSE '.$k.' END, '; - } - - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; - } - - // -------------------------------------------------------------------- - - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @cubrid_close($conn_id); - } + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'cubrid'; + + /** + * Auto-commit flag + * + * @var bool + */ + public $auto_commit = TRUE; + + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '`'; + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)'); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches)) + { + if (stripos($matches[2], 'autocommit=off') !== FALSE) + { + $this->auto_commit = FALSE; + } + } + else + { + // If no port is defined by the user, use the default value + empty($this->port) OR $this->port = 33000; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) + { + $func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; + return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') + ? $func($this->dsn, $this->username, $this->password) + : $func($this->dsn); + } + + $func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; + return ($this->username !== '') + ? $func($this->hostname, $this->port, $this->database, $this->username, $this->password) + : $func($this->hostname, $this->port, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (cubrid_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE) + ? FALSE + : $this->data_cache['version'] = $version; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return cubrid_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + if (($autocommit = cubrid_get_autocommit($this->conn_id)) === NULL) + { + return FALSE; + } + elseif ($autocommit === TRUE) + { + return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ( ! cubrid_commit($this->conn_id)) + { + return FALSE; + } + + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ( ! cubrid_rollback($this->conn_id)) + { + return FALSE; + } + + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return cubrid_real_escape_string($str, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return cubrid_affected_rows(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return cubrid_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES'; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + cubrid_close($this->conn_id); + } } - - -/* End of file cubrid_driver.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php old mode 100755 new mode 100644 index 1e04a23..69b53dd --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -1,289 +1,230 @@ -$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t\"" . $this->db->_protect_identifiers($field) . "\""; - - if (array_key_exists('NAME', $attributes)) - { - $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; - } - - if (array_key_exists('TYPE', $attributes)) - { - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - switch ($attributes['TYPE']) - { - case 'decimal': - case 'float': - case 'numeric': - $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; - break; - case 'enum': // As of version 8.4.0 CUBRID does not support - // enum data type. - break; - case 'set': - $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; - break; - default: - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - } - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - //$sql .= ' UNSIGNED'; - // As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type. - // Will be supported in the next release as a part of MySQL Compatibility. - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - - if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) - { - $sql .= ' UNIQUE'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param mixed the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - //$sql .= 'IF NOT EXISTS '; - // As of version 8.4.0 CUBRID does not support this SQL syntax. - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); - - // If there is a PK defined - if (count($primary_keys) > 0) - { - $key_name = "pk_" . $table . "_" . - $this->db->_protect_identifiers(implode('_', $primary_keys)); - - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->_protect_identifiers(implode('_', $key)); - $key = $this->db->_protect_identifiers($key); - } - else - { - $key_name = $this->db->_protect_identifiers($key); - $key = array($key_name); - } - - $sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n);"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return string - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql.$this->db->_protect_identifiers($fields); - } - - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'RENAME TABLE '.$this->db->_protect_identifiers($table_name)." AS ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } + /** + * CREATE DATABASE statement + * + * @var string + */ + protected $_create_database = FALSE; + + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + + /** + * DROP DATABASE statement + * + * @var string + */ + protected $_drop_database = FALSE; + + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'SHORT' => 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'BIGINT' => 'NUMERIC', + 'FLOAT' => 'DOUBLE', + 'REAL' => 'DOUBLE' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; + } + else + { + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'LONGTEXT': + $attributes['TYPE'] = 'STRING'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } } - -/* End of file cubrid_forge.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php old mode 100755 new mode 100644 index 0b3b942..75d7025 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -1,203 +1,177 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @cubrid_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - return cubrid_column_names($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - - $tablePrimaryKeys = array(); - - while ($field = cubrid_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->default = $field->def; - $F->max_length = $field->max_length; - - // At this moment primary_key property is not returned when - // cubrid_fetch_field is called. The following code will - // provide a patch for it. primary_key property will be added - // in the next release. - - // TODO: later version of CUBRID will provide primary_key - // property. - // When PK is defined in CUBRID, an index is automatically - // created in the db_index system table in the form of - // pk_tblname_fieldname. So the following will count how many - // columns are there which satisfy this format. - // The query will search for exact single columns, thus - // compound PK is not supported. - $res = cubrid_query($this->conn_id, - "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table . - "' AND is_primary_key = 'YES' AND index_name = 'pk_" . - $field->table . "_" . $field->name . "'" - ); - - if ($res) - { - $row = cubrid_fetch_array($res, CUBRID_NUM); - $F->primary_key = ($row[0] > 0 ? 1 : null); - } - else - { - $F->primary_key = null; - } - - if (is_resource($res)) - { - cubrid_close_request($res); - $this->result_id = FALSE; - } - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if(is_resource($this->result_id) || - get_resource_type($this->result_id) == "Unknown" && - preg_match('/Resource id #/', strval($this->result_id))) - { - cubrid_close_request($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return cubrid_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return cubrid_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return cubrid_fetch_object($this->result_id); - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = cubrid_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return cubrid_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + return cubrid_column_names($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = cubrid_field_name($this->result_id, $i); + $retval[$i]->type = cubrid_field_type($this->result_id, $i); + $retval[$i]->max_length = cubrid_field_len($this->result_id, $i); + $retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id) OR + (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id)))) + { + cubrid_close_request($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return cubrid_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return cubrid_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return cubrid_fetch_object($this->result_id, $class_name); + } } - - -/* End of file cubrid_result.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_result.php */ \ No newline at end of file diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php old mode 100755 new mode 100644 index b1ea1c7..ccf794b --- a/system/database/drivers/cubrid/cubrid_utility.php +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -1,109 +1,79 @@ -conn_id) - { - return "SELECT '" . $this->database . "'"; - } - else - { - return FALSE; - } - } - - // -------------------------------------------------------------------- + /** + * List databases + * + * @return array + */ + public function list_databases() + { + if (isset($this->db->data_cache['db_names'])) + { + return $this->db->data_cache['db_names']; + } - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - * @link http://www.cubrid.org/manual/840/en/Optimize%20Database - */ - function _optimize_table($table) - { - // No SQL based support in CUBRID as of version 8.4.0. Database or - // table optimization can be performed using CUBRID Manager - // database administration tool. See the link above for more info. - return FALSE; - } + return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id); + } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - * @link http://www.cubrid.org/manual/840/en/Checking%20Database%20Consistency - */ - function _repair_table($table) - { - // Not supported in CUBRID as of version 8.4.0. Database or - // table consistency can be checked using CUBRID Manager - // database administration tool. See the link above for more info. - return FALSE; - } - - // -------------------------------------------------------------------- - /** - * CUBRID Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // No SQL based support in CUBRID as of version 8.4.0. Database or - // table backup can be performed using CUBRID Manager - // database administration tool. - return $this->db->display_error('db_unsuported_feature'); - } + /** + * CUBRID Export + * + * @param array Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // No SQL based support in CUBRID as of version 8.4.0. Database or + // table backup can be performed using CUBRID Manager + // database administration tool. + return $this->db->display_error('db_unsupported_feature'); + } } - -/* End of file cubrid_utility.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/cubrid/index.html b/system/database/drivers/cubrid/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/cubrid/index.html +++ b/system/database/drivers/cubrid/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php new file mode 100644 index 0000000..27e87d4 --- /dev/null +++ b/system/database/drivers/ibase/ibase_driver.php @@ -0,0 +1,413 @@ +hostname.':'.$this->database, $this->username, $this->password, $this->char_set) + : ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) + { + $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); + + // Don't keep the service open + ibase_service_detach($service); + return $this->data_cache['version']; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return ibase_query(isset($this->_ibase_trans) ? $this->_ibase_trans : $this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + if (($trans_handle = ibase_trans($this->conn_id)) === FALSE) + { + return FALSE; + } + + $this->_ibase_trans = $trans_handle; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if (ibase_commit($this->_ibase_trans)) + { + $this->_ibase_trans = NULL; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if (ibase_rollback($this->_ibase_trans)) + { + $this->_ibase_trans = NULL; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return ibase_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $generator_name + * @param int $inc_by + * @return int + */ + public function insert_id($generator_name, $inc_by = 0) + { + //If a generator hasn't been used before it will return 0 + return ibase_gen_id('"'.$generator_name.'"', $inc_by); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT TRIM("RDB$RELATION_NAME") AS TABLE_NAME FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\''; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' AND TRIM("RDB$RELATION_NAME") AS TABLE_NAME LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT TRIM("RDB$FIELD_NAME") AS COLUMN_NAME FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name", + CASE "fields"."RDB$FIELD_TYPE" + WHEN 7 THEN \'SMALLINT\' + WHEN 8 THEN \'INTEGER\' + WHEN 9 THEN \'QUAD\' + WHEN 10 THEN \'FLOAT\' + WHEN 11 THEN \'DFLOAT\' + WHEN 12 THEN \'DATE\' + WHEN 13 THEN \'TIME\' + WHEN 14 THEN \'CHAR\' + WHEN 16 THEN \'INT64\' + WHEN 27 THEN \'DOUBLE\' + WHEN 35 THEN \'TIMESTAMP\' + WHEN 37 THEN \'VARCHAR\' + WHEN 40 THEN \'CSTRING\' + WHEN 261 THEN \'BLOB\' + ELSE NULL + END AS "type", + "fields"."RDB$FIELD_LENGTH" AS "max_length", + "rfields"."RDB$DEFAULT_VALUE" AS "default" + FROM "RDB$RELATION_FIELDS" "rfields" + JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME" + WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).' + ORDER BY "rfields"."RDB$FIELD_POSITION"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => ibase_errcode(), 'message' => ibase_errmsg()); + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // Limit clause depends on if Interbase or Firebird + if (stripos($this->version(), 'firebird') !== FALSE) + { + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset ? ' SKIP '.$this->qb_offset : ''); + } + else + { + $select = 'ROWS ' + .($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); + } + + return preg_replace('`SELECT`i', 'SELECT '.$select, $sql, 1); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + ibase_close($this->conn_id); + } + +} diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php new file mode 100644 index 0000000..29a3acf --- /dev/null +++ b/system/database/drivers/ibase/ibase_forge.php @@ -0,0 +1,251 @@ + 'INTEGER', + 'INTEGER' => 'INT64', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + // Firebird databases are flat files, so a path is required + + // Hostname is needed for remote access + empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name; + + return parent::create_database('"'.$db_name.'"'); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + if ( ! ibase_drop_db($this->conn_id)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' + .($field[$i]['null'] === TRUE ? 'NULL' : '1') + .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name']) + .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INT': + $attributes['TYPE'] = 'INTEGER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/ibase/ibase_result.php b/system/database/drivers/ibase/ibase_result.php new file mode 100644 index 0000000..8653097 --- /dev/null +++ b/system/database/drivers/ibase/ibase_result.php @@ -0,0 +1,161 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) + { + $info = ibase_field_info($this->result_id, $i); + $field_names[] = $info['name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $info = ibase_field_info($this->result_id, $i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $info['name']; + $retval[$i]->type = $info['type']; + $retval[$i]->max_length = $info['length']; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + ibase_free_result($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } + +} diff --git a/system/database/drivers/ibase/ibase_utility.php b/system/database/drivers/ibase/ibase_utility.php new file mode 100644 index 0000000..a808749 --- /dev/null +++ b/system/database/drivers/ibase/ibase_utility.php @@ -0,0 +1,69 @@ +db->hostname, $this->db->username, $this->db->password)) + { + $res = ibase_backup($service, $this->db->database, $filename.'.fbk'); + + // Close the service connection + ibase_service_detach($service); + return $res; + } + + return FALSE; + } + +} diff --git a/system/database/drivers/ibase/index.html b/system/database/drivers/ibase/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/ibase/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/index.html +++ b/system/database/drivers/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/mssql/index.html b/system/database/drivers/mssql/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/mssql/index.html +++ b/system/database/drivers/mssql/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php old mode 100755 new mode 100644 index d1b3ebe..e197cfb --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,668 +1,518 @@ -port != '') - { - $this->hostname .= ','.$this->port; - } - - return @mssql_connect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ($this->port != '') - { - $this->hostname .= ','.$this->port; - } - - return @mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - // not implemented in MSSQL - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Note: The brackets are required in the event that the DB name - // contains reserved characters - return @mssql_select_db('['.$this->database.']', $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @mssql_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - $this->simple_query('BEGIN TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - // Escape single quotes - $str = str_replace("'", "''", remove_invisible_characters($str)); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( - array($this->_like_escape_chr, '%', '_'), - array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), - $str - ); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * Returns the last id created in the Identity column. - * - * @access public - * @return integer - */ - function insert_id() - { - $ver = self::_parse_major_version($this->version()); - $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); - $query = $this->query($sql); - $row = $query->row(); - return $row->last_id; - } - - // -------------------------------------------------------------------- - - /** - * Parse major version - * - * Grabs the major version number from the - * database server version string passed in. - * - * @access private - * @param string $version - * @return int16 major version number - */ - function _parse_major_version($version) - { - preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); - return $ver_info[1]; // return the major version b/c that's all we're interested in. - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT @@VERSION AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - - // for future compatibility - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - return FALSE; // not currently supported - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * List column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access private - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 * FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mssql_get_last_message(); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mssql_close($conn_id); - } + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'mssql'; + + // -------------------------------------------------------------------- + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('NEWID()', 'RAND(%d)'); + + /** + * Quoted identifier flag + * + * Whether to use SQL-92 standard quoted identifier + * (double quotes) or brackets for identifier escaping. + * + * @var bool + */ + protected $_quoted_identifier = TRUE; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Appends the port number to the hostname, if needed. + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + if ( ! empty($this->port)) + { + $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = ($persistent) + ? mssql_pconnect($this->hostname, $this->username, $this->password) + : mssql_connect($this->hostname, $this->username, $this->password); + + if ( ! $this->conn_id) + { + return FALSE; + } + + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file + if ($this->database !== '' && ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + return ($this->db_debug === TRUE) + ? $this->display_error('db_unable_to_select', $this->database) + : FALSE; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + // Note: Escaping is required in the event that the DB name + // contains reserved characters. + if (mssql_select_db('['.$database.']', $this->conn_id)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed resource if rows are returned, bool otherwise + */ + protected function _execute($sql) + { + return mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->simple_query('BEGIN TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->simple_query('COMMIT TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->simple_query('ROLLBACK TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @return string + */ + public function insert_id() + { + $query = version_compare($this->version(), '8', '>=') + ? 'SELECT SCOPE_IDENTITY() AS last_id' + : 'SELECT @@IDENTITY AS last_id'; + + $query = $this->query($query); + $query = $query->row(); + return $query->last_id; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return (ini_set('mssql.charset', $charset) !== FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return "SELECT SERVERPROPERTY('ProductVersion') AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + // We need this because the error info is discarded by the + // server the first time you request it, and query() already + // calls error() once for logging purposes when a query fails. + static $error = array('code' => 0, 'message' => NULL); + + $message = mssql_get_last_message(); + if ( ! empty($message)) + { + $error['code'] = $this->query('SELECT @@ERROR AS code')->row()->code; + $error['message'] = $message; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $limit = $this->qb_offset + $this->qb_limit; + + // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, + // however an ORDER BY clause is required for it to work + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + mssql_close($this->conn_id); + } } - - - -/* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php old mode 100755 new mode 100644 index fab3ce6..07b93c2 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -1,249 +1,151 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - // I think this syntax will work, but can find little documentation on renaming tables in MSSQL - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE"; + + /** + * DROP TABLE IF statement + * + * @var string + */ + protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE"; + + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'TINYINT' => 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } } - -/* End of file mssql_forge.php */ -/* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php old mode 100755 new mode 100644 index 8262195..5d7d3be --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,170 +1,198 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mssql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->max_length = $field->max_length; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - mssql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mssql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mssql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mssql_fetch_object($this->result_id); - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = mssql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + mssql_field_seek($this->result_id, 0); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field = mssql_fetch_field($this->result_id, $i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $field->name; + $retval[$i]->type = $field->type; + $retval[$i]->max_length = $field->max_length; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return mssql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = mssql_fetch_object($this->result_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } } - - -/* End of file mssql_result.php */ -/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php old mode 100755 new mode 100644 index 1eb97e1..5c9941a --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -1,89 +1,77 @@ -db->display_error('db_unsuported_feature'); - } + /** + * Export + * + * @param array $params Preferences + * @return bool + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } } - -/* End of file mssql_utility.php */ -/* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/index.html b/system/database/drivers/mysql/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/mysql/index.html +++ b/system/database/drivers/mysql/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php old mode 100755 new mode 100644 index c585783..440715a --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,780 +1,494 @@ -port != '') - { - $this->hostname .= ':'.$this->port; - } - - return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ($this->port != '') - { - $this->hostname .= ':'.$this->port; - } - - return @mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - if (mysql_ping($this->conn_id) === FALSE) - { - $this->conn_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - if ( ! isset($this->use_set_names)) - { - // mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback - $this->use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; - } - - if ($this->use_set_names === TRUE) - { - return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); - } - else - { - return @mysql_set_charset($charset, $this->conn_id); - } - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @mysql_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - // "DELETE FROM TABLE" returns 0 affected rows This hack modifies - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - $this->simple_query('SET AUTOCOMMIT=0'); - $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) - { - $str = mysql_real_escape_string($str, $this->conn_id); - } - elseif (function_exists('mysql_escape_string')) - { - $str = mysql_escape_string($str); - } - else - { - $str = addslashes($str); - } - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysql_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysql_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "DESCRIBE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _replace($table, $keys, $values) - { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key . ' = ' . $val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update_batch($table, $values, $index, $where = NULL) - { - $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field != $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $sql = "UPDATE ".$table." SET "; - $cases = ''; - - foreach ($final as $k => $v) - { - $cases .= $k.' = CASE '."\n"; - foreach ($v as $row) - { - $cases .= $row."\n"; - } - - $cases .= 'ELSE '.$k.' END, '; - } - - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; - } - - // -------------------------------------------------------------------- - - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysql_close($conn_id); - } + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'mysql'; + + /** + * Compression flag + * + * @var bool + */ + public $compress = FALSE; + + /** + * DELETE hack flag + * + * Whether to use the MySQL "delete hack" which allows the number + * of affected rows to be shown. Uses a preg_replace when enabled, + * adding a bit more processing to all queries. + * + * @var bool + */ + public $delete_hack = TRUE; + + /** + * Strict ON flag + * + * Whether we're running in strict SQL mode. + * + * @var bool + */ + public $stricton; + + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '`'; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + if ( ! empty($this->port)) + { + $this->hostname .= ':'.$this->port; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS; + + if ($this->encrypt === TRUE) + { + $client_flags = $client_flags | MYSQL_CLIENT_SSL; + } + + // Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages + $this->conn_id = ($persistent === TRUE) + ? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags) + : mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags); + + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file + if ($this->database !== '' && ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + return ($this->db_debug === TRUE) + ? $this->display_error('db_unable_to_select', $this->database) + : FALSE; + } + + if (isset($this->stricton) && is_resource($this->conn_id)) + { + if ($this->stricton) + { + $this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); + } + else + { + $this->simple_query( + 'SET SESSION sql_mode = + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")' + ); + } + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (mysql_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (mysql_select_db($database, $this->conn_id)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return mysql_set_charset($charset, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($version = mysql_get_server_info($this->conn_id)) === FALSE) + { + return FALSE; + } + + return $this->data_cache['version'] = $version; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed + */ + protected function _execute($sql) + { + return mysql_query($this->_prep_query($sql), $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @param string $sql an SQL query + * @return string + */ + protected function _prep_query($sql) + { + // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + return trim($sql).' WHERE 1=1'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->simple_query('SET AUTOCOMMIT=0'); + return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->simple_query('COMMIT')) + { + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->simple_query('ROLLBACK')) + { + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return mysql_real_escape_string($str, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + // Error suppression to avoid annoying E_WARNINGs in cases + // where the connection has already been closed for some reason. + @mysql_close($this->conn_id); + } } - - -/* End of file mysql_driver.php */ -/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php old mode 100755 new mode 100644 index 6d95611..b69aa36 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,274 +1,243 @@ -$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - if (array_key_exists('NAME', $attributes)) - { - $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; - } - - if (array_key_exists('TYPE', $attributes)) - { - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - switch ($attributes['TYPE']) - { - case 'decimal': - case 'float': - case 'numeric': - $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; - break; - - case 'enum': - case 'set': - $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; - break; - - default: - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - } - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param mixed the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); - - if (count($primary_keys) > 0) - { - $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->_protect_identifiers(implode('_', $key)); - $key = $this->db->_protect_identifiers($key); - } - else - { - $key_name = $this->db->_protect_identifiers($key); - $key = array($key_name); - } - - $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return string - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql.$this->db->_protect_identifiers($fields); - } - - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } + /** + * CREATE DATABASE statement + * + * @var string + */ + protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; + + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'INTEGER', + 'BIGINT', + 'REAL', + 'DOUBLE', + 'DOUBLE PRECISION', + 'FLOAT', + 'DECIMAL', + 'NUMERIC' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * CREATE TABLE attributes + * + * @param array $attributes Associative array of table attributes + * @return string + */ + protected function _create_table_attr($attributes) + { + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' = '.$attributes[$key]; + } + } + + if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } } - -/* End of file mysql_forge.php */ -/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php old mode 100755 new mode 100644 index 955b4e4..842d7d3 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,175 +1,199 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysql_fetch_object($this->result_id)) - { - preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - - $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; - $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = $type; - $F->default = $field->Default; - $F->max_length = $length; - $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - mysql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysql_fetch_object($this->result_id); - } + /** + * Class constructor + * + * @param object &$driver_object + * @return void + */ + public function __construct(&$driver_object) + { + parent::__construct($driver_object); + + // Required, due to mysql_data_seek() causing nightmares + // with empty result sets + $this->num_rows = mysql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return $this->num_rows; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + mysql_field_seek($this->result_id, 0); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = mysql_field_name($this->result_id, $i); + $retval[$i]->type = mysql_field_type($this->result_id, $i); + $retval[$i]->max_length = mysql_field_len($this->result_id, $i); + $retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + mysql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return $this->num_rows + ? mysql_data_seek($this->result_id, $n) + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return mysql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return mysql_fetch_object($this->result_id, $class_name); + } } - - -/* End of file mysql_result.php */ -/* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php old mode 100755 new mode 100644 index d23aa5c..a548929 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,211 +1,211 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - /** - * MySQL Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - if (count($params) == 0) - { - return FALSE; - } - - // Extract the prefs for simplicity - extract($params); - - // Build the output - $output = ''; - foreach ((array)$tables as $table) - { - // Is the table in the "ignore" list? - if (in_array($table, (array)$ignore, TRUE)) - { - continue; - } - - // Get the table schema - $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`'); - - // No result means the table name was invalid - if ($query === FALSE) - { - continue; - } - - // Write out the table schema - $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; - - if ($add_drop == TRUE) - { - $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; - } - - $i = 0; - $result = $query->result_array(); - foreach ($result[0] as $val) - { - if ($i++ % 2) - { - $output .= $val.';'.$newline.$newline; - } - } - - // If inserts are not needed we're done... - if ($add_insert == FALSE) - { - continue; - } - - // Grab all the data from the current table - $query = $this->db->query("SELECT * FROM $table"); - - if ($query->num_rows() == 0) - { - continue; - } - - // Fetch the field names and determine if the field is an - // integer type. We use this info to decide whether to - // surround the data with quotes or not - - $i = 0; - $field_str = ''; - $is_int = array(); - while ($field = mysql_fetch_field($query->result_id)) - { - // Most versions of MySQL store timestamp as a string - $is_int[$i] = (in_array( - strtolower(mysql_field_type($query->result_id, $i)), - array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), - TRUE) - ) ? TRUE : FALSE; - - // Create a string of field names - $field_str .= '`'.$field->name.'`, '; - $i++; - } - - // Trim off the end comma - $field_str = preg_replace( "/, $/" , "" , $field_str); - - - // Build the insert string - foreach ($query->result_array() as $row) - { - $val_str = ''; - - $i = 0; - foreach ($row as $v) - { - // Is the value NULL? - if ($v === NULL) - { - $val_str .= 'NULL'; - } - else - { - // Escape the data if it's not an integer - if ($is_int[$i] == FALSE) - { - $val_str .= $this->db->escape($v); - } - else - { - $val_str .= $v; - } - } - - // Append a comma - $val_str .= ', '; - $i++; - } - - // Remove the comma at the end of the string - $val_str = preg_replace( "/, $/" , "" , $val_str); - - // Build the INSERT string - $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; - } - - $output .= $newline.$newline; - } - - return $output; - } -} + /** + * List databases statement + * + * @var string + */ + protected $_list_databases = 'SHOW DATABASES'; + + /** + * OPTIMIZE TABLE statement + * + * @var string + */ + protected $_optimize_table = 'OPTIMIZE TABLE %s'; + + /** + * REPAIR TABLE statement + * + * @var string + */ + protected $_repair_table = 'REPAIR TABLE %s'; + + // -------------------------------------------------------------------- + + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + if (count($params) === 0) + { + return FALSE; + } + + // Extract the prefs for simplicity + extract($params); + + // Build the output + $output = ''; + + // Do we need to include a statement to disable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 0;'.$newline; + } + + foreach ( (array) $tables as $table) + { + // Is the table in the "ignore" list? + if (in_array($table, (array) $ignore, TRUE)) + { + continue; + } + + // Get the table schema + $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table)); + + // No result means the table name was invalid + if ($query === FALSE) + { + continue; + } + + // Write out the table schema + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop === TRUE) + { + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } + } + + // If inserts are not needed we're done... + if ($add_insert === FALSE) + { + continue; + } + + // Grab all the data from the current table + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); + + if ($query->num_rows() === 0) + { + continue; + } + + // Fetch the field names and determine if the field is an + // integer type. We use this info to decide whether to + // surround the data with quotes or not + + $i = 0; + $field_str = ''; + $is_int = array(); + while ($field = mysql_fetch_field($query->result_id)) + { + // Most versions of MySQL store timestamp as a string + $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), + TRUE); + + // Create a string of field names + $field_str .= $this->db->escape_identifiers($field->name).', '; + $i++; + } + + // Trim off the end comma + $field_str = preg_replace('/, $/' , '', $field_str); + + // Build the insert string + foreach ($query->result_array() as $row) + { + $val_str = ''; + + $i = 0; + foreach ($row as $v) + { + // Is the value NULL? + if ($v === NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v; + } + + // Append a comma + $val_str .= ', '; + $i++; + } + + // Remove the comma at the end of the string + $val_str = preg_replace('/, $/' , '', $val_str); + + // Build the INSERT string + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + } + + $output .= $newline.$newline; + } + + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 1;'.$newline; + } + + return $output; + } -/* End of file mysql_utility.php */ -/* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file +} diff --git a/system/database/drivers/mysqli/index.html b/system/database/drivers/mysqli/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/mysqli/index.html +++ b/system/database/drivers/mysqli/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php old mode 100755 new mode 100644 index f88dbf5..0ca0f48 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,767 +1,546 @@ -port != '') - { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); - } - else - { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); - } - - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - if (mysqli_ping($this->conn_id) === FALSE) - { - $this->conn_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access private - * @param string - * @param string - * @return resource - */ - function _db_set_charset($charset, $collation) - { - if ( ! isset($this->use_set_names)) - { - // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback - $this->use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE; - } - - if ($this->use_set_names === TRUE) - { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); - } - else - { - return @mysqli_set_charset($this->conn_id, $charset); - } - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - $result = @mysqli_query($this->conn_id, $sql); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - // "DELETE FROM TABLE" returns 0 affected rows This hack modifies - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - $this->simple_query('SET AUTOCOMMIT=0'); - $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - - $str = mysqli_real_escape_string($this->conn_id, $str); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysqli_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysqli_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "DESCRIBE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _replace($table, $keys, $values) - { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update_batch($table, $values, $index, $where = NULL) - { - $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field != $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $sql = "UPDATE ".$table." SET "; - $cases = ''; - - foreach ($final as $k => $v) - { - $cases .= $k.' = CASE '."\n"; - foreach ($v as $row) - { - $cases .= $row."\n"; - } - - $cases .= 'ELSE '.$k.' END, '; - } - - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysqli_close($conn_id); - } - + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'mysqli'; + + /** + * Compression flag + * + * @var bool + */ + public $compress = FALSE; + + /** + * DELETE hack flag + * + * Whether to use the MySQL "delete hack" which allows the number + * of affected rows to be shown. Uses a preg_replace when enabled, + * adding a bit more processing to all queries. + * + * @var bool + */ + public $delete_hack = TRUE; + + /** + * Strict ON flag + * + * Whether we're running in strict SQL mode. + * + * @var bool + */ + public $stricton; + + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '`'; + + // -------------------------------------------------------------------- + + /** + * MySQLi object + * + * Has to be preserved without being assigned to $conn_id. + * + * @var MySQLi + */ + protected $_mysqli; + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + // Do we have a socket path? + if ($this->hostname[0] === '/') + { + $hostname = NULL; + $port = NULL; + $socket = $this->hostname; + } + else + { + $hostname = ($persistent === TRUE) + ? 'p:'.$this->hostname : $this->hostname; + $port = empty($this->port) ? NULL : $this->port; + $socket = NULL; + } + + $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0; + $this->_mysqli = mysqli_init(); + + $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10); + + if (isset($this->stricton)) + { + if ($this->stricton) + { + $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); + } + else + { + $this->_mysqli->options(MYSQLI_INIT_COMMAND, + 'SET SESSION sql_mode = + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")' + ); + } + } + + if (is_array($this->encrypt)) + { + $ssl = array(); + empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key']; + empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert']; + empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca']; + empty($this->encrypt['ssl_capath']) OR $ssl['capath'] = $this->encrypt['ssl_capath']; + empty($this->encrypt['ssl_cipher']) OR $ssl['cipher'] = $this->encrypt['ssl_cipher']; + + if (isset($this->encrypt['ssl_verify'])) + { + $client_flags |= MYSQLI_CLIENT_SSL; + + if ($this->encrypt['ssl_verify']) + { + defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE); + } + // Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT + // to FALSE didn't do anything, so PHP 5.6.16 introduced yet another + // constant ... + // + // https://secure.php.net/ChangeLog-5.php#5.6.16 + // https://bugs.php.net/bug.php?id=68344 + elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) + { + $client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; + } + } + + if ( ! empty($ssl)) + { + $client_flags |= MYSQLI_CLIENT_SSL; + $this->_mysqli->ssl_set( + isset($ssl['key']) ? $ssl['key'] : NULL, + isset($ssl['cert']) ? $ssl['cert'] : NULL, + isset($ssl['ca']) ? $ssl['ca'] : NULL, + isset($ssl['capath']) ? $ssl['capath'] : NULL, + isset($ssl['cipher']) ? $ssl['cipher'] : NULL + ); + } + } + + if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) + { + // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails + if ( + ($client_flags & MYSQLI_CLIENT_SSL) + && version_compare($this->_mysqli->client_info, '5.7.3', '<=') + && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value) + ) + { + $this->_mysqli->close(); + $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!'; + log_message('error', $message); + return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE; + } + + return $this->_mysqli; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if ($this->conn_id->select_db($database)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return $this->conn_id->set_charset($charset); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return $this->data_cache['version'] = $this->conn_id->server_info; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed + */ + protected function _execute($sql) + { + return $this->conn_id->query($this->_prep_query($sql)); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @param string $sql an SQL query + * @return string + */ + protected function _prep_query($sql) + { + // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + return trim($sql).' WHERE 1=1'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->conn_id->autocommit(FALSE); + return is_php('5.5') + ? $this->conn_id->begin_transaction() + : $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->conn_id->commit()) + { + $this->conn_id->autocommit(TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->conn_id->rollback()) + { + $this->conn_id->autocommit(TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return $this->conn_id->real_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->insert_id; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + if ( ! empty($this->_mysqli->connect_errno)) + { + return array( + 'code' => $this->_mysqli->connect_errno, + 'message' => $this->_mysqli->connect_error + ); + } + + return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } } - - -/* End of file mysqli_driver.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php old mode 100755 new mode 100644 index 34574bb..92b1e94 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,259 +1,244 @@ -$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - if (array_key_exists('NAME', $attributes)) - { - $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; - } - - if (array_key_exists('TYPE', $attributes)) - { - $sql .= ' '.$attributes['TYPE']; - } - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param mixed the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); - - if (count($primary_keys) > 0) - { - $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->_protect_identifiers(implode('_', $key)); - $key = $this->db->_protect_identifiers($key); - } - else - { - $key_name = $this->db->_protect_identifiers($key); - $key = array($key_name); - } - - $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return string - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql.$this->db->_protect_identifiers($fields); - } - - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } + /** + * CREATE DATABASE statement + * + * @var string + */ + protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; + + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'INTEGER', + 'BIGINT', + 'REAL', + 'DOUBLE', + 'DOUBLE PRECISION', + 'FLOAT', + 'DECIMAL', + 'NUMERIC' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * CREATE TABLE attributes + * + * @param array $attributes Associative array of table attributes + * @return string + */ + protected function _create_table_attr($attributes) + { + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' = '.$attributes[$key]; + } + } + + if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } } - -/* End of file mysqli_forge.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php old mode 100755 new mode 100644 index 646ce6a..0856eca --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,175 +1,232 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysqli_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysqli_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysqli_fetch_object($this->result_id)) - { - preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - - $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; - $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = $type; - $F->default = $field->Default; - $F->max_length = $length; - $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_object($this->result_id)) - { - mysqli_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysqli_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysqli_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysqli_fetch_object($this->result_id); - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = $this->result_id->num_rows; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return $this->result_id->field_count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + $this->result_id->field_seek(0); + while ($field = $this->result_id->fetch_field()) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + $field_data = $this->result_id->fetch_fields(); + for ($i = 0, $c = count($field_data); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $field_data[$i]->name; + $retval[$i]->type = static::_get_field_type($field_data[$i]->type); + $retval[$i]->max_length = $field_data[$i]->max_length; + $retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG); + $retval[$i]->default = $field_data[$i]->def; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Get field type + * + * Extracts field type info from the bitflags returned by + * mysqli_result::fetch_fields() + * + * @used-by CI_DB_mysqli_result::field_data() + * @param int $type + * @return string + */ + private static function _get_field_type($type) + { + static $map; + isset($map) OR $map = array( + MYSQLI_TYPE_DECIMAL => 'decimal', + MYSQLI_TYPE_BIT => 'bit', + MYSQLI_TYPE_TINY => 'tinyint', + MYSQLI_TYPE_SHORT => 'smallint', + MYSQLI_TYPE_INT24 => 'mediumint', + MYSQLI_TYPE_LONG => 'int', + MYSQLI_TYPE_LONGLONG => 'bigint', + MYSQLI_TYPE_FLOAT => 'float', + MYSQLI_TYPE_DOUBLE => 'double', + MYSQLI_TYPE_TIMESTAMP => 'timestamp', + MYSQLI_TYPE_DATE => 'date', + MYSQLI_TYPE_TIME => 'time', + MYSQLI_TYPE_DATETIME => 'datetime', + MYSQLI_TYPE_YEAR => 'year', + MYSQLI_TYPE_NEWDATE => 'date', + MYSQLI_TYPE_INTERVAL => 'interval', + MYSQLI_TYPE_ENUM => 'enum', + MYSQLI_TYPE_SET => 'set', + MYSQLI_TYPE_TINY_BLOB => 'tinyblob', + MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob', + MYSQLI_TYPE_BLOB => 'blob', + MYSQLI_TYPE_LONG_BLOB => 'longblob', + MYSQLI_TYPE_STRING => 'char', + MYSQLI_TYPE_VAR_STRING => 'varchar', + MYSQLI_TYPE_GEOMETRY => 'geometry' + ); + + return isset($map[$type]) ? $map[$type] : $type; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->free(); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return $this->result_id->data_seek($n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetch_assoc(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return $this->result_id->fetch_object($class_name); + } } - - -/* End of file mysqli_result.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php old mode 100755 new mode 100644 index 97fe9c2..6064246 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,88 +1,211 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * MySQLi Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } -} + /** + * List databases statement + * + * @var string + */ + protected $_list_databases = 'SHOW DATABASES'; + + /** + * OPTIMIZE TABLE statement + * + * @var string + */ + protected $_optimize_table = 'OPTIMIZE TABLE %s'; + + /** + * REPAIR TABLE statement + * + * @var string + */ + protected $_repair_table = 'REPAIR TABLE %s'; + + // -------------------------------------------------------------------- + + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + if (count($params) === 0) + { + return FALSE; + } + + // Extract the prefs for simplicity + extract($params); + + // Build the output + $output = ''; + + // Do we need to include a statement to disable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 0;'.$newline; + } + + foreach ( (array) $tables as $table) + { + // Is the table in the "ignore" list? + if (in_array($table, (array) $ignore, TRUE)) + { + continue; + } + + // Get the table schema + $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table)); + + // No result means the table name was invalid + if ($query === FALSE) + { + continue; + } + + // Write out the table schema + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; -/* End of file mysqli_utility.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file + if ($add_drop === TRUE) + { + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } + } + + // If inserts are not needed we're done... + if ($add_insert === FALSE) + { + continue; + } + + // Grab all the data from the current table + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); + + if ($query->num_rows() === 0) + { + continue; + } + + // Fetch the field names and determine if the field is an + // integer type. We use this info to decide whether to + // surround the data with quotes or not + + $i = 0; + $field_str = ''; + $is_int = array(); + while ($field = $query->result_id->fetch_field()) + { + // Most versions of MySQL store timestamp as a string + $is_int[$i] = in_array($field->type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_INT24, MYSQLI_TYPE_LONG), TRUE); + + // Create a string of field names + $field_str .= $this->db->escape_identifiers($field->name).', '; + $i++; + } + + // Trim off the end comma + $field_str = preg_replace('/, $/' , '', $field_str); + + // Build the insert string + foreach ($query->result_array() as $row) + { + $val_str = ''; + + $i = 0; + foreach ($row as $v) + { + // Is the value NULL? + if ($v === NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v; + } + + // Append a comma + $val_str .= ', '; + $i++; + } + + // Remove the comma at the end of the string + $val_str = preg_replace('/, $/' , '', $val_str); + + // Build the INSERT string + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + } + + $output .= $newline.$newline; + } + + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 1;'.$newline; + } + + return $output; + } + +} diff --git a/system/database/drivers/oci8/index.html b/system/database/drivers/oci8/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/oci8/index.html +++ b/system/database/drivers/oci8/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php old mode 100755 new mode 100644 index 269cb3b..a825c4a --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -1,33 +1,54 @@ -username, $this->password, $this->hostname, $this->char_set); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - public function db_pconnect() - { - return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - public function reconnect() - { - // not implemented in oracle - return; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - public function db_select() - { - // Not in Oracle - schemas are actually usernames - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - public function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access protected - * @return string - */ - protected function _version() - { - return oci_server_version($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access protected called by the base class - * @param string an SQL query - * @return resource - */ - protected function _execute($sql) - { - // oracle must parse the query before it is run. All of the actions with - // the query are based on the statement id returned by ociparse - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - oci_set_prefetch($this->stmt_id, 1000); - return @oci_execute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - private function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = oci_parse($this->conn_id, $this->_prep_query($sql)); - } - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - private function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - public function get_cursor() - { - $this->curs_id = oci_new_cursor($this->conn_id); - return $this->curs_id; - } - - // -------------------------------------------------------------------- - - /** - * Stored Procedure. Executes a stored procedure - * - * @access public - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array - * - * params array keys - * - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter - */ - public function stored_procedure($package, $procedure, $params) - { - if ($package == '' OR $procedure == '' OR ! is_array($params)) - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // build the query string - $sql = "begin $package.$procedure("; - - $have_cursor = FALSE; - foreach ($params as $param) - { - $sql .= $param['name'] . ","; - - if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR)) - { - $have_cursor = TRUE; - } - } - $sql = trim($sql, ",") . "); end;"; - - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); - } - - // -------------------------------------------------------------------- - - /** - * Bind parameters - * - * @access private - * @return none - */ - private function _bind_params($params) - { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) - { - return; - } - - foreach ($params as $param) - { - foreach (array('name', 'value', 'type', 'length') as $val) - { - if ( ! isset($param[$val])) - { - $param[$val] = ''; - } - } - - oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - public function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - $this->_commit = OCI_DEFAULT; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - public function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = oci_commit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - public function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = oci_rollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - public function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - $str = remove_invisible_characters($str); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - public function affected_rows() - { - return @oci_num_rows($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - public function insert_id() - { - // not supported in oracle - return $this->display_error('db_unsupported_function'); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - public function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access protected - * @param boolean - * @return string - */ - protected function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access protected - * @param string the table name - * @return string - */ - protected function _list_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - protected function _field_data($table) - { - return "SELECT * FROM ".$table." where rownum = 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access protected - * @return string - */ - protected function _error_message() - { - // If the error was during connection, no conn_id should be passed - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access protected - * @return integer - */ - protected function _error_number() - { - // Same as _error_message() - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access protected - * @param string - * @return string - */ - protected function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access protected - * @param type - * @return type - */ - protected function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access protected - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - $keys = implode(', ', $keys); - $sql = "INSERT ALL\n"; - - for ($i = 0, $c = count($values); $i < $c; $i++) - { - $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; - } - - $sql .= 'SELECT * FROM dual'; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access protected - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access protected - * @param string the table name - * @return string - */ - protected function _truncate($table) - { - return "TRUNCATE TABLE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access protected - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access protected - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - protected function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access protected - * @param resource - * @return void - */ - protected function _close($conn_id) - { - @oci_close($conn_id); - } - - + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'oci8'; + + /** + * Statement ID + * + * @var resource + */ + public $stmt_id; + + /** + * Cursor ID + * + * @var resource + */ + public $curs_id; + + /** + * Commit mode flag + * + * @var int + */ + public $commit_mode = OCI_COMMIT_ON_SUCCESS; + + /** + * Limit used flag + * + * If we use LIMIT, we'll add a field that will + * throw off num_fields later. + * + * @var bool + */ + public $limit_used = FALSE; + + // -------------------------------------------------------------------- + + /** + * Reset $stmt_id flag + * + * Used by stored_procedure() to prevent _execute() from + * re-setting the statement ID. + */ + protected $_reset_stmt_id = TRUE; + + /** + * List of reserved identifiers + * + * Identifiers that must NOT be escaped. + * + * @var string[] + */ + protected $_reserved_identifiers = array('*', 'rownum'); + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('ASC', 'ASC'); // not currently supported + + /** + * COUNT string + * + * @used-by CI_DB_driver::count_all() + * @used-by CI_DB_query_builder::count_all_results() + * + * @var string + */ + protected $_count_string = 'SELECT COUNT(1) AS '; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + $valid_dsns = array( + 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS + // Easy Connect string (Oracle 10g+) + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', + 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora) + ); + + /* Space characters don't have any effect when actually + * connecting, but can be a hassle while validating the DSN. + */ + $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn); + + if ($this->dsn !== '') + { + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->dsn)) + { + return; + } + } + } + + // Legacy support for TNS in the hostname configuration field + $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname); + if (preg_match($valid_dsns['tns'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE + && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== '')) + { + /* If the hostname field isn't empty, doesn't contain + * ':' and/or '/' and if port and/or database aren't + * empty, then the hostname field is most likely indeed + * just a hostname. Therefore we'll try and build an + * Easy Connect string from these 3 settings, assuming + * that the database field is a service name. + */ + $this->dsn = $this->hostname + .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '') + .($this->database !== '' ? '/'.ltrim($this->database, '/') : ''); + + if (preg_match($valid_dsns['ec'], $this->dsn)) + { + return; + } + } + + /* At this point, we can only try and validate the hostname and + * database fields separately as DSNs. + */ + if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + + $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database); + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->database)) + { + return; + } + } + + /* Well - OK, an empty string should work as well. + * PHP will try to use environment variables to + * determine which Oracle instance to connect to. + */ + $this->dsn = ''; + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect'; + return empty($this->char_set) + ? $func($this->username, $this->password, $this->dsn) + : $func($this->username, $this->password, $this->dsn, $this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE) + { + return FALSE; + } + elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match)) + { + return $this->data_cache['version'] = $match[1]; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + /* Oracle must parse the query before it is run. All of the actions with + * the query are based on the statement id returned by oci_parse(). + */ + if ($this->_reset_stmt_id === TRUE) + { + $this->stmt_id = oci_parse($this->conn_id, $sql); + } + + oci_set_prefetch($this->stmt_id, 1000); + return oci_execute($this->stmt_id, $this->commit_mode); + } + + // -------------------------------------------------------------------- + + /** + * Get cursor. Returns a cursor from the database + * + * @return resource + */ + public function get_cursor() + { + return $this->curs_id = oci_new_cursor($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @param string package name in which the stored procedure is in + * @param string stored procedure name to execute + * @param array parameters + * @return mixed + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + public function stored_procedure($package, $procedure, array $params) + { + if ($package === '' OR $procedure === '') + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; + } + + // Build the query string + $sql = 'BEGIN '.$package.'.'.$procedure.'('; + + $have_cursor = FALSE; + foreach ($params as $param) + { + $sql .= $param['name'].','; + + if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ',').'); END;'; + + $this->_reset_stmt_id = FALSE; + $this->stmt_id = oci_parse($this->conn_id, $sql); + $this->_bind_params($params); + $result = $this->query($sql, FALSE, $have_cursor); + $this->_reset_stmt_id = TRUE; + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @param array $params + * @return void + */ + protected function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->commit_mode = OCI_NO_AUTO_COMMIT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + + return oci_commit($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + return oci_rollback($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return oci_num_rows($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + // not supported in oracle + return $this->display_error('db_unsupported_function'); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE + FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + + $length = ($query[$i]->CHAR_LENGTH > 0) + ? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION; + if ($length === NULL) + { + $length = $query[$i]->DATA_LENGTH; + } + $retval[$i]->max_length = $length; + + $default = $query[$i]->DATA_DEFAULT; + if ($default === NULL && $query[$i]->NULLABLE === 'N') + { + $default = ''; + } + $retval[$i]->default = $default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + // oci_error() returns an array that already contains + // 'code' and 'message' keys, but it can return false + // if there was no error .... + if (is_resource($this->curs_id)) + { + $error = oci_error($this->curs_id); + } + elseif (is_resource($this->stmt_id)) + { + $error = oci_error($this->stmt_id); + } + elseif (is_resource($this->conn_id)) + { + $error = oci_error($this->conn_id); + } + else + { + $error = oci_error(); + } + + return is_array($error) + ? $error + : array('code' => '', 'message' => ''); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + $keys = implode(', ', $keys); + $sql = "INSERT ALL\n"; + + for ($i = 0, $c = count($values); $i < $c; $i++) + { + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; + } + + return $sql.'SELECT * FROM dual'; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + $this->where('rownum <= ',$this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + if (version_compare($this->version(), '12.1', '>=')) + { + // OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $this->limit_used = TRUE; + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : ''); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + oci_close($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * We need to reset our $limit_used hack flag, so it doesn't propagate + * to subsequent queries. + * + * @return void + */ + protected function _reset_select() + { + $this->limit_used = FALSE; + parent::_reset_select(); + } } - - - -/* End of file oci8_driver.php */ -/* Location: ./system/database/drivers/oci8/oci8_driver.php */ diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php old mode 100755 new mode 100644 index a3c0cea..58f3c39 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,249 +1,194 @@ -db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - - + /** + * CREATE DATABASE statement + * + * @var string + */ + protected $_create_database = FALSE; + + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * DROP DATABASE statement + * + * @var string + */ + protected $_drop_database = FALSE; + + /** + * DROP TABLE IF statement + * + * @var string + */ + protected $_drop_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var bool|array + */ + protected $_unsigned = FALSE; + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + elseif ($alter_type === 'CHANGE') + { + $alter_type = 'MODIFY'; + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = "\n\t".$field[$i]['_literal']; + } + else + { + $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]); + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + + if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + $field[$i] = "\n\t".$field[$i]['_literal']; + } + } + + $sql .= ' '.$alter_type.' '; + $sql .= (count($field) === 1) + ? $field[0] + : '('.implode(',', $field).')'; + + // RENAME COLUMN must be executed after MODIFY + array_unshift($sqls, $sql); + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported - sequences and triggers must be used instead + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'INT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'NUMBER'; + return; + default: return; + } + } } - -/* End of file oci8_forge.php */ -/* Location: ./system/database/drivers/oci8/oci8_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php old mode 100755 new mode 100644 index 36f2ae8..3da49aa --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,218 +1,229 @@ -num_rows === 0 && count($this->result_array()) > 0) - { - $this->num_rows = count($this->result_array()); - @oci_execute($this->stmt_id, OCI_DEFAULT); - - if ($this->curs_id) - { - @oci_execute($this->curs_id, OCI_DEFAULT); - } - } - - return $this->num_rows; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - public function num_fields() - { - $count = @oci_num_fields($this->stmt_id); - - // if we used a limit we subtract it - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - public function list_fields() - { - $field_names = array(); - for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) - { - $field_names[] = oci_field_name($this->stmt_id, $c); - } - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - public function field_data() - { - $retval = array(); - for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = oci_field_name($this->stmt_id, $c); - $F->type = oci_field_type($this->stmt_id, $c); - $F->max_length = oci_field_size($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - public function free_result() - { - if (is_resource($this->result_id)) - { - oci_free_statement($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access protected - * @return array - */ - protected function _fetch_assoc() - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return oci_fetch_assoc($id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access protected - * @return object - */ - protected function _fetch_object() - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return @oci_fetch_object($id); - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - public function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - $row = NULL; - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access protected - * @return array - */ - protected function _data_seek($n = 0) - { - return FALSE; // Not needed - } + /** + * Statement ID + * + * @var resource + */ + public $stmt_id; + + /** + * Cursor ID + * + * @var resource + */ + public $curs_id; + + /** + * Limit used flag + * + * @var bool + */ + public $limit_used; + + /** + * Commit mode flag + * + * @var int + */ + public $commit_mode; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$driver_object + * @return void + */ + public function __construct(&$driver_object) + { + parent::__construct($driver_object); + + $this->stmt_id = $driver_object->stmt_id; + $this->curs_id = $driver_object->curs_id; + $this->limit_used = $driver_object->limit_used; + $this->commit_mode =& $driver_object->commit_mode; + $driver_object->stmt_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + $count = oci_num_fields($this->stmt_id); + + // if we used a limit we subtract it + return ($this->limit_used) ? $count - 1 : $count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) + { + $field_names[] = oci_field_name($this->stmt_id, $c); + } + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = oci_field_name($this->stmt_id, $c); + $F->type = oci_field_type($this->stmt_id, $c); + $F->max_length = oci_field_size($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + oci_free_statement($this->result_id); + $this->result_id = FALSE; + } + + if (is_resource($this->stmt_id)) + { + oci_free_statement($this->stmt_id); + } + + if (is_resource($this->curs_id)) + { + oci_cancel($this->curs_id); + $this->curs_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + return oci_fetch_assoc($id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = ($this->curs_id) + ? oci_fetch_object($this->curs_id) + : oci_fetch_object($this->stmt_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } } - - -/* End of file oci8_result.php */ -/* Location: ./system/database/drivers/oci8/oci8_result.php */ diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php old mode 100755 new mode 100644 index d4da4ca..3a7261c --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,88 +1,68 @@ -db->display_error('db_unsupported_feature'); + } - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; // Is this supported in Oracle? - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return FALSE; // Is this supported in Oracle? - } - - // -------------------------------------------------------------------- - - /** - * Oracle Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } } - -/* End of file oci8_utility.php */ -/* Location: ./system/database/drivers/oci8/oci8_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/index.html b/system/database/drivers/odbc/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/odbc/index.html +++ b/system/database/drivers/odbc/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php old mode 100755 new mode 100644 index 07603f1..72289bf --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,638 +1,425 @@ -_random_keyword = ' RND('.time().')'; // database specific random keyword - } - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @odbc_connect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @odbc_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - // not implemented in odbc - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @odbc_exec($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return odbc_autocommit($this->conn_id, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_commit($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_rollback($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - // ODBC doesn't require escaping - $str = remove_invisible_characters($str); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @odbc_num_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @odbc_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM `".$this->database."`"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - return FALSE; // not currently supported - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return $this->_delete($table); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - // Does ODBC doesn't use the LIMIT clause? - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @odbc_close($conn_id); - } - - +class CI_DB_odbc_driver extends CI_DB_driver { + + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'odbc'; + + /** + * Database schema + * + * @var string + */ + public $schema = 'public'; + + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * Must be empty for ODBC. + * + * @var string + */ + protected $_escape_char = ''; + + /** + * ESCAPE statement string + * + * @var string + */ + protected $_like_escape_str = " {escape '%s'} "; + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('RND()', 'RND(%d)'); + + // -------------------------------------------------------------------- + + /** + * ODBC result ID resource returned from odbc_prepare() + * + * @var resource + */ + private $odbc_result; + + /** + * Values to use with odbc_execute() for prepared statements + * + * @var array + */ + private $binds = array(); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + // Legacy support for DSN in the hostname field + if (empty($this->dsn)) + { + $this->dsn = $this->hostname; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + return ($persistent === TRUE) + ? odbc_pconnect($this->dsn, $this->username, $this->password) + : odbc_connect($this->dsn, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @param string $sql SQL statement + * @param array $binds An array of values to bind + * @return string + */ + public function compile_binds($sql, $binds) + { + if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) + { + return $sql; + } + elseif ( ! is_array($binds)) + { + $binds = array($binds); + $bind_count = 1; + } + else + { + // Make sure we're using numeric keys + $binds = array_values($binds); + $bind_count = count($binds); + } + + // We'll need the marker length later + $ml = strlen($this->bind_marker); + + // Make sure not to replace a chunk inside a string that happens to match the bind marker + if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches)) + { + $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', + str_replace($matches[0], + str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), + $sql, $c), + $matches, PREG_OFFSET_CAPTURE); + + // Bind values' count must match the count of markers in the query + if ($bind_count !== $c) + { + return $sql; + } + } + elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) + { + return $sql; + } + + if ($this->bind_marker !== '?') + { + do + { + $c--; + $sql = substr_replace($sql, '?', $matches[0][$c][1], $ml); + } + while ($c !== 0); + } + + if (FALSE !== ($this->odbc_result = odbc_prepare($this->conn_id, $sql))) + { + $this->binds = array_values($binds); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + if ( ! isset($this->odbc_result)) + { + return odbc_exec($this->conn_id, $sql); + } + elseif ($this->odbc_result === FALSE) + { + return FALSE; + } + + if (TRUE === ($success = odbc_execute($this->odbc_result, $this->binds))) + { + // For queries that return result sets, return the result_id resource on success + $this->is_write_type($sql) OR $success = $this->odbc_result; + } + + $this->odbc_result = NULL; + $this->binds = array(); + + return $success; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if (odbc_commit($this->conn_id)) + { + odbc_autocommit($this->conn_id, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if (odbc_rollback($this->conn_id)) + { + odbc_autocommit($this->conn_id, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + $this->display_error('db_unsupported_feature'); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return odbc_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return bool + */ + public function insert_id() + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT TOP 1 FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + odbc_close($this->conn_id); + } } - - - -/* End of file odbc_driver.php */ -/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php old mode 100755 new mode 100644 index b0766f4..05f9c76 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -1,267 +1,86 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * DROP TABLE IF statement + * + * @var string + */ + protected $_drop_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var bool|array + */ + protected $_unsigned = FALSE; + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported (in most databases at least) + } } - -/* End of file odbc_forge.php */ -/* Location: ./system/database/drivers/odbc/odbc_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php old mode 100755 new mode 100644 index 09f6ee7..a06ac4b --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,229 +1,268 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @odbc_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = odbc_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = odbc_field_name($this->result_id, $i); - $F->type = odbc_field_type($this->result_id, $i); - $F->max_length = odbc_field_len($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - odbc_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_array($this->result_id); - } - else - { - return $this->_odbc_fetch_array($this->result_id); - } - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_object($this->result_id); - } - else - { - return $this->_odbc_fetch_object($this->result_id); - } - } - - - /** - * Result - object - * - * subsititutes the odbc_fetch_object function when - * not available (odbc_fetch_object requires unixODBC) - * - * @access private - * @return object - */ - function _odbc_fetch_object(& $odbc_result) { - $rs = array(); - $rs_obj = FALSE; - if (odbc_fetch_into($odbc_result, $rs)) { - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_obj->$field_name = $v; - } - } - return $rs_obj; - } - - - /** - * Result - array - * - * subsititutes the odbc_fetch_array function when - * not available (odbc_fetch_array requires unixODBC) - * - * @access private - * @return array - */ - function _odbc_fetch_array(& $odbc_result) { - $rs = array(); - $rs_assoc = FALSE; - if (odbc_fetch_into($odbc_result, $rs)) { - $rs_assoc=array(); - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_assoc[$field_name] = $v; - } - } - return $rs_assoc; - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + if (is_int($this->num_rows)) + { + return $this->num_rows; + } + elseif (($this->num_rows = odbc_num_rows($this->result_id)) !== -1) + { + return $this->num_rows; + } + + // Work-around for ODBC subdrivers that don't support num_rows() + if (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + $num_fields = $this->num_fields(); + + if ($num_fields > 0) + { + for ($i = 1; $i <= $num_fields; $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); + $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); + $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + odbc_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return odbc_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = odbc_fetch_object($this->result_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } } +// -------------------------------------------------------------------- -/* End of file odbc_result.php */ -/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file +if ( ! function_exists('odbc_fetch_array')) +{ + /** + * ODBC Fetch array + * + * Emulates the native odbc_fetch_array() function when + * it is not available (odbc_fetch_array() requires unixODBC) + * + * @param resource &$result + * @param int $rownumber + * @return array + */ + function odbc_fetch_array(&$result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_assoc = array(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_assoc[$field_name] = $v; + } + + return $rs_assoc; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('odbc_fetch_object')) +{ + /** + * ODBC Fetch object + * + * Emulates the native odbc_fetch_object() function when + * it is not available. + * + * @param resource &$result + * @param int $rownumber + * @return object + */ + function odbc_fetch_object(&$result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_object = new stdClass(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_object->$field_name = $v; + } + + return $rs_object; + } +} diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php old mode 100755 new mode 100644 index d9d3322..7872010 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -1,104 +1,63 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * ODBC Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } } - -/* End of file odbc_utility.php */ -/* Location: ./system/database/drivers/odbc/odbc_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/index.html b/system/database/drivers/pdo/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/pdo/index.html +++ b/system/database/drivers/pdo/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php old mode 100755 new mode 100644 index 2d39f1e..c5d120f --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -1,812 +1,329 @@ -hostname, 'mysql') !== FALSE) - { - $this->_like_escape_str = ''; - $this->_like_escape_chr = ''; - - //Prior to this version, the charset can't be set in the dsn - if(is_php('5.3.6')) - { - $this->hostname .= ";charset={$this->char_set}"; - } - - //Set the charset with the connection options - $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}"; - } - elseif (strpos($this->hostname, 'odbc') !== FALSE) - { - $this->_like_escape_str = " {escape '%s'} "; - $this->_like_escape_chr = '!'; - } - else - { - $this->_like_escape_str = " ESCAPE '%s' "; - $this->_like_escape_chr = '!'; - } - - empty($this->database) OR $this->hostname .= ';dbname='.$this->database; - - $this->trans_enabled = FALSE; - - $this->_random_keyword = ' RND('.time().')'; // database specific random keyword - } - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - - return new PDO($this->hostname, $this->username, $this->password, $this->options); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - $this->options['PDO::ATTR_PERSISTENT'] = TRUE; - - return new PDO($this->hostname, $this->username, $this->password, $this->options); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for PDO - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return object - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - $result_id = $this->conn_id->prepare($sql); - - if (is_object($result_id) && $result_id->execute()) - { - if (is_numeric(stripos($sql, 'SELECT'))) - { - $this->affect_rows = count($result_id->fetchAll()); - } - else - { - $this->affect_rows = $result_id->rowCount(); - } - } - else - { - $this->affect_rows = 0; - return FALSE; - } - - return $result_id; - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = (bool) ($test_mode === TRUE); - - return $this->conn_id->beginTransaction(); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = $this->conn->commit(); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = $this->conn_id->rollBack(); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - //Escape the string - $str = $this->conn_id->quote($str); - - //If there are duplicated quotes, trim them away - if (strpos($str, "'") === 0) - { - $str = substr($str, 1, -1); - } - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return $this->affect_rows; - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id($name=NULL) - { - //Convenience method for postgres insertid - if (strpos($this->hostname, 'pgsql') !== FALSE) - { - $v = $this->_version(); - - $table = func_num_args() > 0 ? func_get_arg(0) : NULL; - - if ($table == NULL && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - else - { - return $this->conn_id->lastInsertId($name); - } - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM `".$this->database."`"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - return FALSE; // not currently supported - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error_array = $this->conn_id->errorInfo(); - return $error_array[2]; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return $this->conn_id->errorCode(); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update_batch($table, $values, $index, $where = NULL) - { - $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field != $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $sql = "UPDATE ".$table." SET "; - $cases = ''; - - foreach ($final as $k => $v) - { - $cases .= $k.' = CASE '."\n"; - foreach ($v as $row) - { - $cases .= $row."\n"; - } - - $cases .= 'ELSE '.$k.' END, '; - } - - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return $this->_delete($table); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - else - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - $this->conn_id = null; - } - + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'pdo'; + + /** + * PDO Options + * + * @var array + */ + public $options = array(); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Validates the DSN string and/or detects the subdriver. + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + if (preg_match('/([^:]+):/', $this->dsn, $match) && count($match) === 2) + { + // If there is a minimum valid dsn string pattern found, we're done + // This is for general PDO users, who tend to have a full DSN string. + $this->subdriver = $match[1]; + return; + } + // Legacy support for DSN specified in the hostname field + elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2) + { + $this->dsn = $this->hostname; + $this->hostname = NULL; + $this->subdriver = $match[1]; + return; + } + elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE)) + { + $this->subdriver = 'dblib'; + } + elseif ($this->subdriver === '4D') + { + $this->subdriver = '4d'; + } + elseif ( ! in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE)) + { + log_message('error', 'PDO: Invalid or non-existent subdriver'); + + if ($this->db_debug) + { + show_error('Invalid or non-existent PDO subdriver'); + } + } + + $this->dsn = NULL; + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ($persistent === TRUE) + { + $this->options[PDO::ATTR_PERSISTENT] = TRUE; + } + + try + { + return new PDO($this->dsn, $this->username, $this->password, $this->options); + } + catch (PDOException $e) + { + if ($this->db_debug && empty($this->failover)) + { + $this->display_error($e->getMessage(), '', TRUE); + } + + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + // Not all subdrivers support the getAttribute() method + try + { + return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); + } + catch (PDOException $e) + { + return parent::version(); + } + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql SQL query + * @return mixed + */ + protected function _execute($sql) + { + return $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->conn_id->beginTransaction(); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->conn_id->commit(); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->conn_id->rollBack(); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + // Escape the string + $str = $this->conn_id->quote($str); + + // If there are duplicated quotes, trim them away + return ($str[0] === "'") + ? substr($str, 1, -1) + : $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return is_object($this->result_id) ? $this->result_id->rowCount() : 0; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $name + * @return int + */ + public function insert_id($name = NULL) + { + return $this->conn_id->lastInsertId($name); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + $error = array('code' => '00000', 'message' => ''); + $pdo_error = $this->conn_id->errorInfo(); + + if (empty($pdo_error[0])) + { + return $error; + } + + $error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0]; + if (isset($pdo_error[2])) + { + $error['message'] = $pdo_error[2]; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } } - - - -/* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php old mode 100755 new mode 100644 index 321f3a6..e512d3d --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -1,267 +1,65 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // PDO has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported PDO feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = FALSE; + /** + * DROP TABLE IF statement + * + * @var string + */ + protected $_drop_table_if = FALSE; } - -/* End of file pdo_forge.php */ -/* Location: ./system/database/drivers/pdo/pdo_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php old mode 100755 new mode 100644 index 82e1706..b3973da --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -1,184 +1,198 @@ -num_rows)) - { - return $this->num_rows; - } - elseif (($this->num_rows = $this->result_id->rowCount()) > 0) - { - return $this->num_rows; - } - - $this->num_rows = count($this->result_id->fetchAll()); - $this->result_id->execute(); - return $this->num_rows; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return $this->result_id->columnCount(); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $data = array(); - - try - { - for($i = 0; $i < $this->num_fields(); $i++) - { - $data[] = $this->result_id->getColumnMeta($i); - } - - return $data; - } - catch (Exception $e) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_object($this->result_id)) - { - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return $this->result_id->fetch(PDO::FETCH_ASSOC); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return $this->result_id->fetchObject(); - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + if (is_int($this->num_rows)) + { + return $this->num_rows; + } + elseif (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + elseif (($num_rows = $this->result_id->rowCount()) > 0) + { + return $this->num_rows = $num_rows; + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return $this->result_id->columnCount(); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return bool + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + // Might trigger an E_WARNING due to not all subdrivers + // supporting getColumnMeta() + $field_names[$i] = @$this->result_id->getColumnMeta($i); + $field_names[$i] = $field_names[$i]['name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + try + { + $retval = array(); + + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field = $this->result_id->getColumnMeta($i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $field['name']; + $retval[$i]->type = isset($field['native_type']) ? $field['native_type'] : null; + $retval[$i]->max_length = ($field['len'] > 0) ? $field['len'] : NULL; + $retval[$i]->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'], TRUE)); + } + + return $retval; + } + catch (Exception $e) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsupported_feature'); + } + + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetch(PDO::FETCH_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return $this->result_id->fetchObject($class_name); + } } - - -/* End of file pdo_result.php */ -/* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php old mode 100755 new mode 100644 index be6c679..6c40cf3 --- a/system/database/drivers/pdo/pdo_utility.php +++ b/system/database/drivers/pdo/pdo_utility.php @@ -1,104 +1,63 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - // Not a supported PDO feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - // Not a supported PDO feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * PDO Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } } - -/* End of file pdo_utility.php */ -/* Location: ./system/database/drivers/pdo/pdo_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/subdrivers/index.html b/system/database/drivers/pdo/subdrivers/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php new file mode 100644 index 0000000..2e39bb2 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -0,0 +1,200 @@ +dsn)) + { + $this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES'); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' WHERE '.$this->escape_identifiers('TABLE_NAME')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS') + .' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1'; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php new file mode 100644 index 0000000..306150b --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php @@ -0,0 +1,217 @@ + 'INT', + 'SMALLINT' => 'INT', + 'INT' => 'INT64', + 'INT32' => 'INT64' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = FALSE; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + // No method of modifying columns is supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['auto_increment']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + + // UNIQUE must be used with NOT NULL + $field['null'] = ' NOT NULL'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + if (stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' AUTO_INCREMENT'; + } + elseif (strcasecmp($field['type'], 'UUID') === 0) + { + $field['auto_increment'] = ' AUTO_GENERATE'; + } + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php new file mode 100644 index 0000000..9a6b643 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -0,0 +1,209 @@ +dsn)) + { + $this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES'; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php new file mode 100644 index 0000000..f2ee3f5 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -0,0 +1,230 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'BIGINT' => 'NUMERIC', + 'FLOAT' => 'DOUBLE', + 'REAL' => 'DOUBLE' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; + } + else + { + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'LONGTEXT': + $attributes['TYPE'] = 'STRING'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php new file mode 100644 index 0000000..09dbdf0 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -0,0 +1,353 @@ +dsn)) + { + $this->dsn = $params['subdriver'].':host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + if ( ! empty($this->port)) + { + $this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port; + } + + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + empty($this->appname) OR $this->dsn .= ';appname='.$this->appname; + } + else + { + if ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + + $this->subdriver = 'dblib'; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ($persistent === TRUE) + { + log_message('debug', "dblib driver doesn't support persistent connections"); + } + + $this->conn_id = parent::db_connect(FALSE); + + if ( ! is_object($this->conn_id)) + { + return $this->conn_id; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $limit = $this->qb_offset + $this->qb_limit; + + // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, + // however an ORDER BY clause is required for it to work + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return $this->data_cache['version'] = $this->conn_id->query("SELECT SERVERPROPERTY('ProductVersion') AS ver")->fetchColumn(0); + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php new file mode 100644 index 0000000..f38ac99 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php @@ -0,0 +1,149 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php new file mode 100644 index 0000000..2c49f12 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -0,0 +1,279 @@ +dsn)) + { + $this->dsn = 'firebird:'; + + if ( ! empty($this->database)) + { + $this->dsn .= 'dbname='.$this->database; + } + elseif ( ! empty($this->hostname)) + { + $this->dsn .= 'dbname='.$this->hostname; + } + + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + empty($this->role) OR $this->dsn .= ';role='.$this->role; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\''; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name", + CASE "fields"."RDB$FIELD_TYPE" + WHEN 7 THEN \'SMALLINT\' + WHEN 8 THEN \'INTEGER\' + WHEN 9 THEN \'QUAD\' + WHEN 10 THEN \'FLOAT\' + WHEN 11 THEN \'DFLOAT\' + WHEN 12 THEN \'DATE\' + WHEN 13 THEN \'TIME\' + WHEN 14 THEN \'CHAR\' + WHEN 16 THEN \'INT64\' + WHEN 27 THEN \'DOUBLE\' + WHEN 35 THEN \'TIMESTAMP\' + WHEN 37 THEN \'VARCHAR\' + WHEN 40 THEN \'CSTRING\' + WHEN 261 THEN \'BLOB\' + ELSE NULL + END AS "type", + "fields"."RDB$FIELD_LENGTH" AS "max_length", + "rfields"."RDB$DEFAULT_VALUE" AS "default" + FROM "RDB$RELATION_FIELDS" "rfields" + JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME" + WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).' + ORDER BY "rfields"."RDB$FIELD_POSITION"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // Limit clause depends on if Interbase or Firebird + if (stripos($this->version(), 'firebird') !== FALSE) + { + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : ''); + } + else + { + $select = 'ROWS ' + .($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); + } + + return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php new file mode 100644 index 0000000..eceb597 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php @@ -0,0 +1,237 @@ + 'INTEGER', + 'INTEGER' => 'INT64', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return string + */ + public function create_database($db_name) + { + // Firebird databases are flat files, so a path is required + + // Hostname is needed for remote access + empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name; + + return parent::create_database('"'.$db_name.'"'); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + if ( ! ibase_drop_db($this->conn_id)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' + .($field[$i]['null'] === TRUE ? 'NULL' : '1') + .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name']) + .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INT': + $attributes['TYPE'] = 'INTEGER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php new file mode 100644 index 0000000..00654d7 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php @@ -0,0 +1,244 @@ +dsn)) + { + $this->dsn = 'ibm:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';'; + + if (isset($this->DATABASE)) + { + $this->dsn .= 'DATABASE='.$this->DATABASE.';'; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DATABASE='.$this->database.';'; + } + + if (isset($this->HOSTNAME)) + { + $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';'; + } + else + { + $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';'); + } + + if (isset($this->PORT)) + { + $this->dsn .= 'PORT='.$this->port.';'; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= ';PORT='.$this->port.';'; + } + + $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;'); + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "tabname" FROM "syscat"."tables" + WHERE "type" = \'T\' AND LOWER("tabschema") = '.$this->escape(strtolower($this->database)); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return array + */ + protected function _list_columns($table = '') + { + return 'SELECT "colname" FROM "syscat"."columns" + WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).' + AND LOWER("tabname") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length", + CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key" + FROM "syscat"."columns" + WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).' + AND LOWER("tabname") = '.$this->escape(strtolower($table)).' + ORDER BY "colno"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY'; + + return ($this->qb_offset) + ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset + : $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php new file mode 100644 index 0000000..99d75b6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php @@ -0,0 +1,154 @@ + 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = FALSE; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'CHANGE') + { + $alter_type = 'MODIFY'; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + + // UNIQUE must be used with NOT NULL + $field['null'] = ' NOT NULL'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php new file mode 100644 index 0000000..114eb74 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -0,0 +1,309 @@ +dsn)) + { + $this->dsn = 'informix:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + if (isset($this->host)) + { + $this->dsn .= 'host='.$this->host; + } + else + { + $this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + } + + if (isset($this->service)) + { + $this->dsn .= '; service='.$this->service; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= '; service='.$this->port; + } + + empty($this->database) OR $this->dsn .= '; database='.$this->database; + empty($this->server) OR $this->dsn .= '; server='.$this->server; + + $this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp') + .'; EnableScrollableCursors=1'; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "tabname" FROM "systables" + WHERE "tabid" > 99 AND "tabtype" = \'T\' AND LOWER("owner") = '.$this->escape(strtolower($this->username)); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT "colname" FROM "systables", "syscolumns" + WHERE "systables"."tabid" = "syscolumns"."tabid" + AND "systables"."tabtype" = \'T\' + AND LOWER("systables"."owner") = '.$this->escape(strtolower($owner)).' + AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "syscolumns"."colname" AS "name", + CASE "syscolumns"."coltype" + WHEN 0 THEN \'CHAR\' + WHEN 1 THEN \'SMALLINT\' + WHEN 2 THEN \'INTEGER\' + WHEN 3 THEN \'FLOAT\' + WHEN 4 THEN \'SMALLFLOAT\' + WHEN 5 THEN \'DECIMAL\' + WHEN 6 THEN \'SERIAL\' + WHEN 7 THEN \'DATE\' + WHEN 8 THEN \'MONEY\' + WHEN 9 THEN \'NULL\' + WHEN 10 THEN \'DATETIME\' + WHEN 11 THEN \'BYTE\' + WHEN 12 THEN \'TEXT\' + WHEN 13 THEN \'VARCHAR\' + WHEN 14 THEN \'INTERVAL\' + WHEN 15 THEN \'NCHAR\' + WHEN 16 THEN \'NVARCHAR\' + WHEN 17 THEN \'INT8\' + WHEN 18 THEN \'SERIAL8\' + WHEN 19 THEN \'SET\' + WHEN 20 THEN \'MULTISET\' + WHEN 21 THEN \'LIST\' + WHEN 22 THEN \'Unnamed ROW\' + WHEN 40 THEN \'LVARCHAR\' + WHEN 41 THEN \'BLOB/CLOB/BOOLEAN\' + WHEN 4118 THEN \'Named ROW\' + ELSE "syscolumns"."coltype" + END AS "type", + "syscolumns"."collength" as "max_length", + CASE "sysdefaults"."type" + WHEN \'L\' THEN "sysdefaults"."default" + ELSE NULL + END AS "default" + FROM "syscolumns", "systables", "sysdefaults" + WHERE "syscolumns"."tabid" = "systables"."tabid" + AND "systables"."tabid" = "sysdefaults"."tabid" + AND "syscolumns"."colno" = "sysdefaults"."colno" + AND "systables"."tabtype" = \'T\' + AND LOWER("systables"."owner") = '.$this->escape(strtolower($this->username)).' + AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)).' + ORDER BY "syscolumns"."colno"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE ONLY '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql $SQL Query + * @return string + */ + protected function _limit($sql) + { + $select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' '; + return preg_replace('/^(SELECT\s)/i', $select, $sql, 1); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php new file mode 100644 index 0000000..1f4bcd1 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php @@ -0,0 +1,163 @@ + 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'REAL' => 'DOUBLE PRECISION', + 'SMALLFLOAT' => 'DOUBLE PRECISION' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = ', '; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'CHANGE') + { + $alter_type = 'MODIFY'; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'BYTE': + case 'TEXT': + case 'BLOB': + case 'CLOB': + $attributes['UNIQUE'] = FALSE; + if (isset($attributes['DEFAULT'])) + { + unset($attributes['DEFAULT']); + } + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']); + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php new file mode 100644 index 0000000..73b88bc --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -0,0 +1,379 @@ +dsn)) + { + $this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if (isset($this->stricton)) + { + if ($this->stricton) + { + $sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'; + } + else + { + $sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")'; + } + + if ( ! empty($sql)) + { + if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) + { + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = '.$sql; + } + else + { + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = '.$sql; + } + } + } + + if ($this->compress === TRUE) + { + $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE; + } + + if (is_array($this->encrypt)) + { + $ssl = array(); + empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key']; + empty($this->encrypt['ssl_cert']) OR $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert']; + empty($this->encrypt['ssl_ca']) OR $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca']; + empty($this->encrypt['ssl_capath']) OR $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath']; + empty($this->encrypt['ssl_cipher']) OR $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher']; + + if (defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') && isset($this->encrypt['ssl_verify'])) + { + $ssl[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $this->encrypt['ssl_verify']; + } + + // DO NOT use array_merge() here! + // It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers. + empty($ssl) OR $this->options += $ssl; + } + + // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails + if ( + ($pdo = parent::db_connect($persistent)) !== FALSE + && ! empty($ssl) + && version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=') + && empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value) + ) + { + $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!'; + log_message('error', $message); + return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE; + } + + return $pdo; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); + return $this->conn_id->beginTransaction(); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->conn_id->commit()) + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->conn_id->rollBack()) + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php new file mode 100644 index 0000000..01595a6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -0,0 +1,256 @@ +db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php new file mode 100644 index 0000000..dba4958 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -0,0 +1,326 @@ +dsn)) + { + $this->dsn = 'oci:dbname='; + + // Oracle has a slightly different PDO DSN format (Easy Connect), + // which also supports pre-defined DSNs. + if (empty($this->hostname) && empty($this->port)) + { + $this->dsn .= $this->database; + } + else + { + $this->dsn .= '//'.(empty($this->hostname) ? '127.0.0.1' : $this->hostname) + .(empty($this->port) ? '' : ':'.$this->port).'/'; + + empty($this->database) OR $this->dsn .= $this->database; + } + + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + $version_string = parent::version(); + if (preg_match('#Release\s(?\d+(?:\.\d+)+)#', $version_string, $match)) + { + return $this->data_cache['version'] = $match[1]; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE + FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + + $length = ($query[$i]->CHAR_LENGTH > 0) + ? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION; + if ($length === NULL) + { + $length = $query[$i]->DATA_LENGTH; + } + $retval[$i]->max_length = $length; + + $default = $query[$i]->DATA_DEFAULT; + if ($default === NULL && $query[$i]->NULLABLE === 'N') + { + $default = ''; + } + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + $keys = implode(', ', $keys); + $sql = "INSERT ALL\n"; + + for ($i = 0, $c = count($values); $i < $c; $i++) + { + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; + } + + return $sql.'SELECT * FROM dual'; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + $this->where('rownum <= ',$this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + if (version_compare($this->version(), '12.1', '>=')) + { + // OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php new file mode 100644 index 0000000..b5d3eb1 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -0,0 +1,183 @@ +db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = "\n\t".$field[$i]['_literal']; + } + else + { + $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]); + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + + if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + } + + $sql .= ' '.$alter_type.' '; + $sql .= (count($field) === 1) + ? $field[0] + : '('.implode(',', $field).')'; + + // RENAME COLUMN must be executed after MODIFY + array_unshift($sqls, $sql); + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported - sequences and triggers must be used instead + } + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'INT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'NUMBER'; + return; + default: return; + } + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php new file mode 100644 index 0000000..93a6420 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -0,0 +1,229 @@ +dsn)) + { + $this->dsn = 'odbc:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + // If the DSN is not pre-configured - try to build an IBM DB2 connection string + $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';'; + + if (isset($this->DATABASE)) + { + $this->dsn .= 'DATABASE='.$this->DATABASE.';'; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DATABASE='.$this->database.';'; + } + + if (isset($this->HOSTNAME)) + { + $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';'; + } + else + { + $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';'); + } + + if (isset($this->PORT)) + { + $this->dsn .= 'PORT='.$this->port.';'; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= ';PORT='.$this->port.';'; + } + + $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;'); + } + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + $this->display_error('db_unsupported_feature'); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table); + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php new file mode 100644 index 0000000..47226d7 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php @@ -0,0 +1,70 @@ +dsn)) + { + $this->dsn = 'pgsql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + + if ( ! empty($this->username)) + { + $this->dsn .= ';user='.$this->username; + empty($this->password) OR $this->dsn .= ';password='.$this->password; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = parent::db_connect($persistent); + + if (is_object($this->conn_id) && ! empty($this->schema)) + { + $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $name + * @return int + */ + public function insert_id($name = NULL) + { + if ($name === NULL && version_compare($this->version(), '8.1', '>=')) + { + $query = $this->query('SELECT LASTVAL() AS ins_id'); + $query = $query->row(); + return $query->ins_id; + } + + return $this->conn_id->lastInsertId($name); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * + * @param string $str + * @return mixed + */ + public function escape($str) + { + if (is_bool($str)) + { + return ($str) ? 'TRUE' : 'FALSE'; + } + + return parent::escape($str); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return object + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + if ($direction === 'RANDOM') + { + if ( ! is_float($orderby) && ctype_digit((string) $orderby)) + { + $orderby = ($orderby > 1) + ? (float) '0.'.$orderby + : (float) $orderby; + } + + if (is_float($orderby)) + { + $this->simple_query('SET SEED '.$orderby); + } + + $orderby = $this->_random_keyword[0]; + $direction = ''; + $escape = FALSE; + } + + return parent::order_by($orderby, $direction, $escape); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "table_name" LIKE \'' + .$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "column_name" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->column_name; + $retval[$i]->type = $query[$i]->data_type; + $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retval[$i]->default = $query[$i]->column_default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k.' = (CASE '.$val[$index]['field']."\n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END), '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php new file mode 100644 index 0000000..a4ccff4 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php @@ -0,0 +1,210 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INT4' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'INT8' => 'NUMERIC', + 'BIGINT' => 'NUMERIC', + 'REAL' => 'DOUBLE PRECISION', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + parent::__construct($db); + + if (version_compare($this->db->version(), '9.0', '>')) + { + $this->create_table_if = 'CREATE TABLE IF NOT EXISTS'; + } + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .(trim($field[$i]['null']) === $this->_null ? ' DROP NOT NULL' : ' SET NOT NULL'); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Reset field lengths for data types that don't support it + if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) + { + $attributes['CONSTRAINT'] = NULL; + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $field['type'] = ($field['type'] === 'NUMERIC') + ? 'BIGSERIAL' + : 'SERIAL'; + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php new file mode 100644 index 0000000..f55d9a6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -0,0 +1,213 @@ +dsn)) + { + $this->dsn = 'sqlite:'; + + if (empty($this->database) && empty($this->hostname)) + { + $this->database = ':memory:'; + } + + $this->database = empty($this->database) ? $this->hostname : $this->database; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\''; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $fields = array(); + foreach ($result->result_array() as $row) + { + $fields[] = $row['name']; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php new file mode 100644 index 0000000..545b2a3 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php @@ -0,0 +1,238 @@ +db->version(), '3.3', '<')) + { + $this->_create_table_if = FALSE; + $this->_drop_table_if = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name (ignored) + * @return bool + */ + public function create_database($db_name) + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + // In SQLite, a database is dropped when we delete a file + if (file_exists($this->db->database)) + { + // We need to close the pseudo-connection first + $this->db->close(); + if ( ! @unlink($this->db->database)) + { + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php new file mode 100644 index 0000000..84109ae --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -0,0 +1,369 @@ +dsn)) + { + $this->dsn = 'sqlsrv:Server='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ','.$this->port; + empty($this->database) OR $this->dsn .= ';Database='.$this->database; + + // Some custom options + + if (isset($this->QuotedId)) + { + $this->dsn .= ';QuotedId='.$this->QuotedId; + $this->_quoted_identifier = (bool) $this->QuotedId; + } + + if (isset($this->ConnectionPooling)) + { + $this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling; + } + + if ($this->encrypt === TRUE) + { + $this->dsn .= ';Encrypt=1'; + } + + if (isset($this->TraceOn)) + { + $this->dsn .= ';TraceOn='.$this->TraceOn; + } + + if (isset($this->TrustServerCertificate)) + { + $this->dsn .= ';TrustServerCertificate='.$this->TrustServerCertificate; + } + + empty($this->APP) OR $this->dsn .= ';APP='.$this->APP; + empty($this->Failover_Partner) OR $this->dsn .= ';Failover_Partner='.$this->Failover_Partner; + empty($this->LoginTimeout) OR $this->dsn .= ';LoginTimeout='.$this->LoginTimeout; + empty($this->MultipleActiveResultSets) OR $this->dsn .= ';MultipleActiveResultSets='.$this->MultipleActiveResultSets; + empty($this->TraceFile) OR $this->dsn .= ';TraceFile='.$this->TraceFile; + empty($this->WSID) OR $this->dsn .= ';WSID='.$this->WSID; + } + elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match)) + { + $this->_quoted_identifier = (bool) $match[1]; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ( ! empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set)) + { + $this->options[PDO::SQLSRV_ENCODING_UTF8] = 1; + } + + $this->conn_id = parent::db_connect($persistent); + + if ( ! is_object($this->conn_id) OR is_bool($this->_quoted_identifier)) + { + return $this->conn_id; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // As of SQL Server 2012 (11.0.*) OFFSET is supported + if (version_compare($this->version(), '11', '>=')) + { + // SQL Server OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $limit = $this->qb_offset + $this->qb_limit; + + // An ORDER BY clause is required for ROW_NUMBER() to work + if ($this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php new file mode 100644 index 0000000..b23c6d4 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php @@ -0,0 +1,149 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/postgre/index.html +++ b/system/database/drivers/postgre/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php old mode 100755 new mode 100644 index a88db11..5ce2761 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,704 +1,619 @@ - 'host', - 'port' => 'port', - 'database' => 'dbname', - 'username' => 'user', - 'password' => 'password' - ); - - $connect_string = ""; - foreach ($components as $key => $val) - { - if (isset($this->$key) && $this->$key != '') - { - $connect_string .= " $val=".$this->$key; - } - } - return trim($connect_string); - } - - // -------------------------------------------------------------------- - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @pg_connect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @pg_pconnect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - if (pg_ping($this->conn_id) === FALSE) - { - $this->conn_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - $str = pg_escape_string($str); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = $this->_version(); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : NULL; - $column = func_num_args() > 1 ? func_get_arg(1) : NULL; - - if ($table == NULL && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != NULL && $column != NULL && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != NULL) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'postgre'; + + /** + * Database schema + * + * @var string + */ + public $schema = 'public'; + + // -------------------------------------------------------------------- + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('RANDOM()', 'RANDOM()'); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Creates a DSN string to be used for db_connect() and db_pconnect() + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + if ( ! empty($this->dsn)) + { + return; + } + + $this->dsn === '' OR $this->dsn = ''; + + if (strpos($this->hostname, '/') !== FALSE) + { + // If UNIX sockets are used, we shouldn't set a port + $this->port = ''; + } + + $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' '; + + if ( ! empty($this->port) && ctype_digit($this->port)) + { + $this->dsn .= 'port='.$this->port.' '; + } + + if ($this->username !== '') + { + $this->dsn .= 'user='.$this->username.' '; + + /* An empty password is valid! + * + * $db['password'] = NULL must be done in order to ignore it. + */ + $this->password === NULL OR $this->dsn .= "password='".$this->password."' "; + } + + $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' '; + + /* We don't have these options as elements in our standard configuration + * array, but they might be set by parse_url() if the configuration was + * provided via string. Example: + * + * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1 + */ + foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key) + { + if (isset($this->$key) && is_string($this->$key) && $this->$key !== '') + { + $this->dsn .= $key."='".$this->$key."' "; + } + } + + $this->dsn = rtrim($this->dsn); + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = ($persistent === TRUE) + ? pg_pconnect($this->dsn) + : pg_connect($this->dsn); + + if ($this->conn_id !== FALSE) + { + if ($persistent === TRUE + && pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD + && pg_ping($this->conn_id) === FALSE + ) + { + return FALSE; + } + + empty($this->schema) OR $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (pg_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return (pg_set_client_encoding($this->conn_id, $charset) === 0); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE) + { + return FALSE; + } + + /* If PHP was compiled with PostgreSQL lib versions earlier + * than 7.4, pg_version() won't return the server version + * and so we'll have to fall back to running a query in + * order to get it. + */ + return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match)) + ? $this->data_cache['version'] = $match[1] + : parent::version(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return (bool) pg_query($this->conn_id, 'BEGIN'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return (bool) pg_query($this->conn_id, 'COMMIT'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return (bool) pg_query($this->conn_id, 'ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return pg_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * + * @param string $str + * @return mixed + */ + public function escape($str) + { + if (is_php('5.4.4') && (is_string($str) OR (is_object($str) && method_exists($str, '__toString')))) + { + return pg_escape_literal($this->conn_id, $str); + } + elseif (is_bool($str)) + { + return ($str) ? 'TRUE' : 'FALSE'; + } + + return parent::escape($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return string + */ + public function insert_id() + { + $v = $this->version(); + + $table = (func_num_args() > 0) ? func_get_arg(0) : NULL; + $column = (func_num_args() > 1) ? func_get_arg(1) : NULL; + + if ($table === NULL && $v >= '8.1') + { + $sql = 'SELECT LASTVAL() AS ins_id'; + } + elseif ($table !== NULL) + { + if ($column !== NULL && $v >= '8.0') + { + $sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq"; + $query = $this->query($sql); + $query = $query->row(); + $seq = $query->seq; + } + else + { + // seq_name passed in table parameter + $seq = $table; + } + + $sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id"; + } + else + { + return pg_last_oid($this->result_id); + } + + $query = $this->query($sql); + $query = $query->row(); + return (int) $query->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' AND "table_name" LIKE \'' + .$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "column_name" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->column_name; + $retval[$i]->type = $query[$i]->data_type; + $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retval[$i]->default = $query[$i]->column_default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => '', 'message' => pg_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return object + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + if ($direction === 'RANDOM') + { + if ( ! is_float($orderby) && ctype_digit((string) $orderby)) + { + $orderby = ($orderby > 1) + ? (float) '0.'.$orderby + : (float) $orderby; + } + + if (is_float($orderby)) + { + $this->simple_query('SET SEED '.$orderby); + } + + $orderby = $this->_random_keyword[0]; + $direction = ''; + $escape = FALSE; + } + + return parent::order_by($orderby, $direction, $escape); + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k.' = (CASE '.$val[$index]['field']."\n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END), '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + pg_close($this->conn_id); + } } - - -/* End of file postgre_driver.php */ -/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php old mode 100755 new mode 100644 index 4af0360..481e222 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -1,300 +1,205 @@ -db->table_exists($table)) - { - return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement - } - } - - $sql .= $this->db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE); - - // Convert datatypes to be PostgreSQL-compatible - switch (strtoupper($attributes['TYPE'])) - { - case 'TINYINT': - $attributes['TYPE'] = 'SMALLINT'; - break; - case 'SMALLINT': - $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT'; - break; - case 'MEDIUMINT': - $attributes['TYPE'] = 'INTEGER'; - break; - case 'INT': - $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER'; - break; - case 'BIGINT': - $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT'; - break; - case 'DOUBLE': - $attributes['TYPE'] = 'DOUBLE PRECISION'; - break; - case 'DATETIME': - $attributes['TYPE'] = 'TIMESTAMP'; - break; - case 'LONGTEXT': - $attributes['TYPE'] = 'TEXT'; - break; - case 'BLOB': - $attributes['TYPE'] = 'BYTEA'; - break; - } - - // If this is an auto-incrementing primary key, use the serial data type instead - if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes) - && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' SERIAL'; - } - else - { - $sql .= ' '.$attributes['TYPE']; - } - - // Modified to prevent constraints with integer data types - if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - // Added new attribute to create unqite fields. Also works with MySQL - if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) - { - $sql .= ' UNIQUE'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - // Something seems to break when passing an array to _protect_identifiers() - foreach ($primary_keys as $index => $key) - { - $primary_keys[$index] = $this->db->_protect_identifiers($key); - } - - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - $sql .= "\n);"; - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - foreach ($key as $field) - { - $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); "; - } - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'INT2' => 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INT4' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'INT8' => 'NUMERIC', + 'BIGINT' => 'NUMERIC', + 'REAL' => 'DOUBLE PRECISION', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + parent::__construct($db); + + if (version_compare($this->db->version(), '9.0', '>')) + { + $this->create_table_if = 'CREATE TABLE IF NOT EXISTS'; + } + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .(trim($field[$i]['null']) === $this->_null ? ' DROP NOT NULL' : ' SET NOT NULL'); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Reset field lengths for data types that don't support it + if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) + { + $attributes['CONSTRAINT'] = NULL; + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $field['type'] = ($field['type'] === 'NUMERIC') + ? 'BIGSERIAL' + : 'SERIAL'; + } + } } - -/* End of file postgre_forge.php */ -/* Location: ./system/database/drivers/postgre/postgre_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php old mode 100755 new mode 100644 index 0a68ce0..b0054dd --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -1,170 +1,182 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - pg_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return pg_result_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return pg_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return pg_fetch_object($this->result_id); - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = pg_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = pg_field_name($this->result_id, $i); + $retval[$i]->type = pg_field_type($this->result_id, $i); + $retval[$i]->max_length = pg_field_size($this->result_id, $i); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return pg_fetch_object($this->result_id, NULL, $class_name); + } } - - -/* End of file postgre_result.php */ -/* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php old mode 100755 new mode 100644 index da95535..450aa36 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,89 +1,78 @@ -db->display_error('db_unsuported_feature'); - } + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } } - - -/* End of file postgre_utility.php */ -/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/index.html b/system/database/drivers/sqlite/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/sqlite/index.html +++ b/system/database/drivers/sqlite/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php old mode 100755 new mode 100644 index 3cb874f..aec3d74 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -1,659 +1,330 @@ -database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - // not implemented in SQLite - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @sqlite_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - $this->simple_query('BEGIN TRANSACTION'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - - $str = sqlite_escape_string($str); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return sqlite_changes($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @sqlite_last_insert_rowid($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT name from sqlite_master WHERE type='table'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - } - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return $this->_delete($table); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @sqlite_close($conn_id); - } - + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'sqlite'; + + // -------------------------------------------------------------------- + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('RANDOM()', 'RANDOM()'); + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $error = NULL; + $conn_id = ($persistent === TRUE) + ? sqlite_popen($this->database, 0666, $error) + : sqlite_open($this->database, 0666, $error); + + isset($error) && log_message('error', $error); + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return $this->is_write_type($sql) + ? sqlite_exec($this->conn_id, $sql) + : sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->simple_query('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->simple_query('COMMIT'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->simple_query('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependant string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT name FROM sqlite_master WHERE type='table'"; + + if ($prefix_limit !== FALSE && $this->dbprefix != '') + { + return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return bool + */ + protected function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occured. + * + * @return array + */ + public function error() + { + $error = array('code' => sqlite_last_error($this->conn_id)); + $error['message'] = sqlite_error_string($error['code']); + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this function maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + sqlite_close($this->conn_id); + } } - - -/* End of file sqlite_driver.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php old mode 100755 new mode 100644 index c7e187e..6aa9c61 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -1,266 +1,205 @@ -db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - // IF NOT EXISTS added to SQLite in 3.3.0 - if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)."("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var bool|array + */ + protected $_unsigned = FALSE; + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name (ignored) + * @return bool + */ + public function create_database($db_name) + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + if ( ! file_exists($this->db->database) OR ! @unlink($this->db->database)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @todo implement drop_column(), modify_column() + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * Unsupported feature in SQLite - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - // SQLite does not support dropping columns - // http://www.sqlite.org/omitted.html - // http://www.sqlite.org/faq.html#q11 - return FALSE; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } } - -/* End of file sqlite_forge.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php old mode 100755 new mode 100644 index 223173f..30c93a2 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,180 +1,164 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @sqlite_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = sqlite_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = sqlite_field_name($this->result_id, $i); - $F->type = 'varchar'; - $F->max_length = 0; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - // Not implemented in SQLite - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return sqlite_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return sqlite_fetch_array($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('sqlite_fetch_object')) - { - return sqlite_fetch_object($this->result_id); - } - else - { - $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); - if (is_array($arr)) - { - $obj = (object) $arr; - return $obj; - } else { - return NULL; - } - } - } + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = @sqlite_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[$i] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = sqlite_field_name($this->result_id, $i); + $retval[$i]->type = NULL; + $retval[$i]->max_length = NULL; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return sqlite_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return sqlite_fetch_object($this->result_id, $class_name); + } } - - -/* End of file sqlite_result.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php old mode 100755 new mode 100644 index 733e61c..2c7f809 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -1,97 +1,61 @@ -db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); - } + /** + * Export + * + * @param array $params Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is optimization even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * SQLite Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } } - -/* End of file sqlite_utility.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite3/index.html b/system/database/drivers/sqlite3/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/sqlite3/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php new file mode 100644 index 0000000..5d057ba --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -0,0 +1,344 @@ +password) + ? new SQLite3($this->database) + : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); + } + catch (Exception $e) + { + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + $version = SQLite3::version(); + return $this->data_cache['version'] = $version['versionString']; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @todo Implement use of SQLite3::querySingle(), if needed + * @param string $sql + * @return mixed SQLite3Result object or bool + */ + protected function _execute($sql) + { + return $this->is_write_type($sql) + ? $this->conn_id->exec($sql) + : $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->conn_id->exec('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->conn_id->exec('END TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->conn_id->exec('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return $this->conn_id->escapeString($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->changes(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->lastInsertRowID(); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' + .(($prefix_limit !== FALSE && $this->dbprefix != '') + ? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr) + : ''); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $fields = array(); + foreach ($result->result_array() as $row) + { + $fields[] = $row['name']; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg()); + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php new file mode 100644 index 0000000..4019a95 --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -0,0 +1,225 @@ +db->version(), '3.3', '<')) + { + $this->_create_table_if = FALSE; + $this->_drop_table_if = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + // In SQLite, a database is dropped when we delete a file + if (file_exists($this->db->database)) + { + // We need to close the pseudo-connection first + $this->db->close(); + if ( ! @unlink($this->db->database)) + { + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @todo implement drop_column(), modify_column() + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php new file mode 100644 index 0000000..d656fed --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -0,0 +1,194 @@ +result_id->numColumns(); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[] = $this->result_id->columnName($i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + static $data_types = array( + SQLITE3_INTEGER => 'integer', + SQLITE3_FLOAT => 'float', + SQLITE3_TEXT => 'text', + SQLITE3_BLOB => 'blob', + SQLITE3_NULL => 'null' + ); + + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $this->result_id->columnName($i); + + $type = $this->result_id->columnType($i); + $retval[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; + + $retval[$i]->max_length = NULL; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->finalize(); + $this->result_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetchArray(SQLITE3_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + // No native support for fetching rows as objects + if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE) + { + return FALSE; + } + elseif ($class_name === 'stdClass') + { + return (object) $row; + } + + $class_name = new $class_name(); + foreach (array_keys($row) as $key) + { + $class_name->$key = $row[$key]; + } + + return $class_name; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n (ignored) + * @return array + */ + public function data_seek($n = 0) + { + // Only resetting to the start of the result set is supported + return ($n > 0) ? FALSE : $this->result_id->reset(); + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php new file mode 100644 index 0000000..1bdf3ae --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -0,0 +1,61 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/sqlsrv/index.html b/system/database/drivers/sqlsrv/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/drivers/sqlsrv/index.html +++ b/system/database/drivers/sqlsrv/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php old mode 100755 new mode 100644 index 2fd8b09..a22a8b3 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -1,604 +1,543 @@ -char_set)) ? 'UTF-8' : $this->char_set; - - $connection = array( - 'UID' => empty($this->username) ? '' : $this->username, - 'PWD' => empty($this->password) ? '' : $this->password, - 'Database' => $this->database, - 'ConnectionPooling' => $pooling ? 1 : 0, - 'CharacterSet' => $character_set, - 'ReturnDatesAsStrings' => 1 - ); - - // If the username and password are both empty, assume this is a - // 'Windows Authentication Mode' connection. - if(empty($connection['UID']) && empty($connection['PWD'])) { - unset($connection['UID'], $connection['PWD']); - } - - return sqlsrv_connect($this->hostname, $connection); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @access public - * @return void - */ - function reconnect() - { - // not implemented in MSSQL - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return $this->_execute('USE ' . $this->database); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return sqlsrv_query($this->conn_id, $sql, null, array( - 'Scrollable' => SQLSRV_CURSOR_STATIC, - 'SendStreamParamsAtExec' => true - )); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return sqlsrv_begin_transaction($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return sqlsrv_commit($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return sqlsrv_rollback($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string - */ - function escape_str($str, $like = FALSE) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @sqlrv_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * Returns the last id created in the Identity column. - * - * @access public - * @return integer - */ - function insert_id() - { - return $this->query('select @@IDENTITY as insert_id')->row('insert_id'); - } - - // -------------------------------------------------------------------- - - /** - * Parse major version - * - * Grabs the major version number from the - * database server version string passed in. - * - * @access private - * @param string $version - * @return int16 major version number - */ - function _parse_major_version($version) - { - preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); - return $ver_info[1]; // return the major version b/c that's all we're interested in. - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $info = sqlsrv_server_info($this->conn_id); - return sprintf("select '%s' as ver", $info['SQLServerVersion']); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * List column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access private - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 * FROM " . $this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error = array_shift(sqlsrv_errors()); - return !empty($error['message']) ? $error['message'] : null; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - $error = array_shift(sqlsrv_errors()); - return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - return $table; - } - - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - return $item; - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE TABLE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @sqlsrv_close($conn_id); - } + /** + * Database driver + * + * @var string + */ + public $dbdriver = 'sqlsrv'; + + /** + * Scrollable flag + * + * Determines what cursor type to use when executing queries. + * + * FALSE or SQLSRV_CURSOR_FORWARD would increase performance, + * but would disable num_rows() (and possibly insert_id()) + * + * @var mixed + */ + public $scrollable; + + // -------------------------------------------------------------------- + + /** + * ORDER BY random keyword + * + * @var array + */ + protected $_random_keyword = array('NEWID()', 'RAND(%d)'); + + /** + * Quoted identifier flag + * + * Whether to use SQL-92 standard quoted identifier + * (double quotes) or brackets for identifier escaping. + * + * @var bool + */ + protected $_quoted_identifier = TRUE; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + parent::__construct($params); + + // This is only supported as of SQLSRV 3.0 + if ($this->scrollable === NULL) + { + $this->scrollable = defined('SQLSRV_CURSOR_CLIENT_BUFFERED') + ? SQLSRV_CURSOR_CLIENT_BUFFERED + : FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $pooling + * @return resource + */ + public function db_connect($pooling = FALSE) + { + $charset = in_array(strtolower($this->char_set), array('utf-8', 'utf8'), TRUE) + ? 'UTF-8' : SQLSRV_ENC_CHAR; + + $connection = array( + 'UID' => empty($this->username) ? '' : $this->username, + 'PWD' => empty($this->password) ? '' : $this->password, + 'Database' => $this->database, + 'ConnectionPooling' => ($pooling === TRUE) ? 1 : 0, + 'CharacterSet' => $charset, + 'Encrypt' => ($this->encrypt === TRUE) ? 1 : 0, + 'ReturnDatesAsStrings' => 1 + ); + + // If the username and password are both empty, assume this is a + // 'Windows Authentication Mode' connection. + if (empty($connection['UID']) && empty($connection['PWD'])) + { + unset($connection['UID'], $connection['PWD']); + } + + if (FALSE !== ($this->conn_id = sqlsrv_connect($this->hostname, $connection))) + { + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if ($this->_execute('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return ($this->scrollable === FALSE OR $this->is_write_type($sql)) + ? sqlsrv_query($this->conn_id, $sql) + : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable)); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return sqlsrv_begin_transaction($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return sqlsrv_commit($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return sqlsrv_rollback($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return sqlsrv_rows_affected($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @return string + */ + public function insert_id() + { + return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->row()->insert_id; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($info = sqlsrv_server_info($this->conn_id)) === FALSE) + { + return FALSE; + } + + return $this->data_cache['version'] = $info['SQLServerVersion']; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool + * @return string $prefix_limit + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_escape_like_str, $this->_escape_like_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + $error = array('code' => '00000', 'message' => ''); + $sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); + + if ( ! is_array($sqlsrv_errors)) + { + return $error; + } + + $sqlsrv_error = array_shift($sqlsrv_errors); + if (isset($sqlsrv_error['SQLSTATE'])) + { + $error['code'] = isset($sqlsrv_error['code']) ? $sqlsrv_error['SQLSTATE'].'/'.$sqlsrv_error['code'] : $sqlsrv_error['SQLSTATE']; + } + elseif (isset($sqlsrv_error['code'])) + { + $error['code'] = $sqlsrv_error['code']; + } + + if (isset($sqlsrv_error['message'])) + { + $error['message'] = $sqlsrv_error['message']; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // As of SQL Server 2012 (11.0.*) OFFSET is supported + if (version_compare($this->version(), '11', '>=')) + { + // SQL Server OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $limit = $this->qb_offset + $this->qb_limit; + + // An ORDER BY clause is required for ROW_NUMBER() to work + if ($this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + sqlsrv_close($this->conn_id); + } } - - - -/* End of file sqlsrv_driver.php */ -/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php old mode 100755 new mode 100644 index 95b5e24..90c3120 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -1,246 +1,149 @@ -db->_escape_identifiers($table).")) CREATE TABLE ".$this->db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' IDENTITY(1,1)'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - return 'EXEC sp_rename '.$this->db->_protect_identifiers($table_name).", ".$this->db->_protect_identifiers($new_table_name); - } + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE"; + + /** + * DROP TABLE IF statement + * + * @var string + */ + protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE"; + + /** + * UNSIGNED support + * + * @var array + */ + protected $_unsigned = array( + 'TINYINT' => 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } } - -/* End of file sqlsrv_forge.php */ -/* Location: ./system/database/drivers/sqlsrv/sqlsrv_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php old mode 100755 new mode 100644 index 7dd2119..e2649c6 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -1,170 +1,193 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @sqlsrv_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) - { - $field_names[] = $field['Name']; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) - { - $F = new stdClass(); - $F->name = $field['Name']; - $F->type = $field['Type']; - $F->max_length = $field['Size']; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - sqlsrv_free_stmt($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - // Not implemented - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return sqlsrv_fetch_object($this->result_id); - } + /** + * Scrollable flag + * + * @var mixed + */ + public $scrollable; + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param object $driver_object + * @return void + */ + public function __construct(&$driver_object) + { + parent::__construct($driver_object); + + $this->scrollable = $driver_object->scrollable; + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + // sqlsrv_num_rows() doesn't work with the FORWARD and DYNAMIC cursors (FALSE is the same as FORWARD) + if ( ! in_array($this->scrollable, array(FALSE, SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_DYNAMIC), TRUE)) + { + return parent::num_rows(); + } + + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = sqlsrv_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return @sqlsrv_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) + { + $field_names[] = $field['Name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + foreach (sqlsrv_field_metadata($this->result_id) as $i => $field) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $field['Name']; + $retval[$i]->type = $field['Type']; + $retval[$i]->max_length = $field['Size']; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + sqlsrv_free_stmt($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return sqlsrv_fetch_object($this->result_id, $class_name); + } } - - -/* End of file mssql_result.php */ -/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php old mode 100755 new mode 100644 index fd8ba96..6dd01a9 --- a/system/database/drivers/sqlsrv/sqlsrv_utility.php +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -1,89 +1,77 @@ -db->display_error('db_unsuported_feature'); - } + /** + * Export + * + * @param array $params Preferences + * @return bool + */ + protected function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsupported_feature'); + } } - -/* End of file mssql_utility.php */ -/* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file diff --git a/system/database/index.html b/system/database/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/database/index.html +++ b/system/database/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/fonts/index.html b/system/fonts/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/fonts/index.html +++ b/system/fonts/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

Directory access is forbidden.

- \ No newline at end of file + diff --git a/system/fonts/texb.ttf b/system/fonts/texb.ttf old mode 100755 new mode 100644 diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php old mode 100755 new mode 100644 index 434b38d..cb7eca6 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,120 +1,115 @@ - '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); - - foreach ($defaults as $key => $val) - { - if ( ! is_array($data)) - { - if ( ! isset($$key) OR $$key == '') - { - $$key = $val; - } - } - else - { - $$key = ( ! isset($data[$key])) ? $val : $data[$key]; - } - } - - if ($img_path == '' OR $img_url == '') - { - return FALSE; - } - - if ( ! @is_dir($img_path)) - { - return FALSE; - } - - if ( ! is_writable($img_path)) - { - return FALSE; - } - - if ( ! extension_loaded('gd')) - { - return FALSE; - } - - // ----------------------------------- - // Remove old images - // ----------------------------------- - - list($usec, $sec) = explode(" ", microtime()); - $now = ((float)$usec + (float)$sec); - - $current_dir = @opendir($img_path); - - while ($filename = @readdir($current_dir)) - { - if ($filename != "." and $filename != ".." and $filename != "index.html") - { - $name = str_replace(".jpg", "", $filename); - - if (($name + $expiration) < $now) - { - @unlink($img_path.$filename); - } - } - } - - @closedir($current_dir); - - // ----------------------------------- - // Do we have a "word" yet? - // ----------------------------------- - - if ($word == '') - { - $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - $str = ''; - for ($i = 0; $i < 8; $i++) - { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); - } - - $word = $str; - } - - // ----------------------------------- - // Determine angle and position - // ----------------------------------- - - $length = strlen($word); - $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; - $x_axis = rand(6, (360/$length)-16); - $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); - - // ----------------------------------- - // Create image - // ----------------------------------- - - // PHP.net recommends imagecreatetruecolor(), but it isn't always available - if (function_exists('imagecreatetruecolor')) - { - $im = imagecreatetruecolor($img_width, $img_height); - } - else - { - $im = imagecreate($img_width, $img_height); - } - - // ----------------------------------- - // Assign colors - // ----------------------------------- - - $bg_color = imagecolorallocate ($im, 255, 255, 255); - $border_color = imagecolorallocate ($im, 153, 102, 102); - $text_color = imagecolorallocate ($im, 204, 153, 153); - $grid_color = imagecolorallocate($im, 255, 182, 182); - $shadow_color = imagecolorallocate($im, 255, 240, 240); - - // ----------------------------------- - // Create the rectangle - // ----------------------------------- - - ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); - - // ----------------------------------- - // Create the spiral pattern - // ----------------------------------- - - $theta = 1; - $thetac = 7; - $radius = 16; - $circles = 20; - $points = 32; - - for ($i = 0; $i < ($circles * $points) - 1; $i++) - { - $theta = $theta + $thetac; - $rad = $radius * ($i / $points ); - $x = ($rad * cos($theta)) + $x_axis; - $y = ($rad * sin($theta)) + $y_axis; - $theta = $theta + $thetac; - $rad1 = $radius * (($i + 1) / $points); - $x1 = ($rad1 * cos($theta)) + $x_axis; - $y1 = ($rad1 * sin($theta )) + $y_axis; - imageline($im, $x, $y, $x1, $y1, $grid_color); - $theta = $theta - $thetac; - } - - // ----------------------------------- - // Write the text - // ----------------------------------- - - $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; - - if ($use_font == FALSE) - { - $font_size = 5; - $x = rand(0, $img_width/($length/3)); - $y = 0; - } - else - { - $font_size = 16; - $x = rand(0, $img_width/($length/1.5)); - $y = $font_size+2; - } - - for ($i = 0; $i < strlen($word); $i++) - { - if ($use_font == FALSE) - { - $y = rand(0 , $img_height/2); - imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); - $x += ($font_size*2); - } - else - { - $y = rand($img_height/2, $img_height-3); - imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); - $x += $font_size; - } - } - - - // ----------------------------------- - // Create the border - // ----------------------------------- - - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); - - // ----------------------------------- - // Generate the image - // ----------------------------------- - - $img_name = $now.'.jpg'; - - ImageJPEG($im, $img_path.$img_name); - - $img = "\""; - - ImageDestroy($im); - - return array('word' => $word, 'time' => $now, 'image' => $img); - } + /** + * Create CAPTCHA + * + * @param array $data Data for the CAPTCHA + * @param string $img_path Path to create the image in (deprecated) + * @param string $img_url URL to the CAPTCHA image folder (deprecated) + * @param string $font_path Server path to font (deprecated) + * @return string + */ + function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') + { + $defaults = array( + 'word' => '', + 'img_path' => '', + 'img_url' => '', + 'img_width' => '150', + 'img_height' => '30', + 'font_path' => '', + 'expiration' => 7200, + 'word_length' => 8, + 'font_size' => 16, + 'img_id' => '', + 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'colors' => array( + 'background' => array(255,255,255), + 'border' => array(153,102,102), + 'text' => array(204,153,153), + 'grid' => array(255,182,182) + ) + ); + + foreach ($defaults as $key => $val) + { + if ( ! is_array($data) && empty($$key)) + { + $$key = $val; + } + else + { + $$key = isset($data[$key]) ? $data[$key] : $val; + } + } + + if ($img_path === '' OR $img_url === '' + OR ! is_dir($img_path) OR ! is_really_writable($img_path) + OR ! extension_loaded('gd')) + { + return FALSE; + } + + // ----------------------------------- + // Remove old images + // ----------------------------------- + + $now = microtime(TRUE); + + $current_dir = @opendir($img_path); + while ($filename = @readdir($current_dir)) + { + if (in_array(substr($filename, -4), array('.jpg', '.png')) + && (str_replace(array('.jpg', '.png'), '', $filename) + $expiration) < $now) + { + @unlink($img_path.$filename); + } + } + + @closedir($current_dir); + + // ----------------------------------- + // Do we have a "word" yet? + // ----------------------------------- + + if (empty($word)) + { + $word = ''; + $pool_length = strlen($pool); + $rand_max = $pool_length - 1; + + // PHP7 or a suitable polyfill + if (function_exists('random_int')) + { + try + { + for ($i = 0; $i < $word_length; $i++) + { + $word .= $pool[random_int(0, $rand_max)]; + } + } + catch (Exception $e) + { + // This means fallback to the next possible + // alternative to random_int() + $word = ''; + } + } + } + + if (empty($word)) + { + // Nobody will have a larger character pool than + // 256 characters, but let's handle it just in case ... + // + // No, I do not care that the fallback to mt_rand() can + // handle it; if you trigger this, you're very obviously + // trying to break it. -- Narf + if ($pool_length > 256) + { + return FALSE; + } + + // We'll try using the operating system's PRNG first, + // which we can access through CI_Security::get_random_bytes() + $security = get_instance()->security; + + // To avoid numerous get_random_bytes() calls, we'll + // just try fetching as much bytes as we need at once. + if (($bytes = $security->get_random_bytes($pool_length)) !== FALSE) + { + $byte_index = $word_index = 0; + while ($word_index < $word_length) + { + // Do we have more random data to use? + // It could be exhausted by previous iterations + // ignoring bytes higher than $rand_max. + if ($byte_index === $pool_length) + { + // No failures should be possible if the + // first get_random_bytes() call didn't + // return FALSE, but still ... + for ($i = 0; $i < 5; $i++) + { + if (($bytes = $security->get_random_bytes($pool_length)) === FALSE) + { + continue; + } + + $byte_index = 0; + break; + } + + if ($bytes === FALSE) + { + // Sadly, this means fallback to mt_rand() + $word = ''; + break; + } + } + + list(, $rand_index) = unpack('C', $bytes[$byte_index++]); + if ($rand_index > $rand_max) + { + continue; + } + + $word .= $pool[$rand_index]; + $word_index++; + } + } + } + + if (empty($word)) + { + for ($i = 0; $i < $word_length; $i++) + { + $word .= $pool[mt_rand(0, $rand_max)]; + } + } + elseif ( ! is_string($word)) + { + $word = (string) $word; + } + + // ----------------------------------- + // Determine angle and position + // ----------------------------------- + $length = strlen($word); + $angle = ($length >= 6) ? mt_rand(-($length-6), ($length-6)) : 0; + $x_axis = mt_rand(6, (360/$length)-16); + $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height); + + // Create image + // PHP.net recommends imagecreatetruecolor(), but it isn't always available + $im = function_exists('imagecreatetruecolor') + ? imagecreatetruecolor($img_width, $img_height) + : imagecreate($img_width, $img_height); + + // ----------------------------------- + // Assign colors + // ---------------------------------- + + is_array($colors) OR $colors = $defaults['colors']; + + foreach (array_keys($defaults['colors']) as $key) + { + // Check for a possible missing value + is_array($colors[$key]) OR $colors[$key] = $defaults['colors'][$key]; + $colors[$key] = imagecolorallocate($im, $colors[$key][0], $colors[$key][1], $colors[$key][2]); + } + + // Create the rectangle + ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $colors['background']); + + // ----------------------------------- + // Create the spiral pattern + // ----------------------------------- + $theta = 1; + $thetac = 7; + $radius = 16; + $circles = 20; + $points = 32; + + for ($i = 0, $cp = ($circles * $points) - 1; $i < $cp; $i++) + { + $theta += $thetac; + $rad = $radius * ($i / $points); + $x = ($rad * cos($theta)) + $x_axis; + $y = ($rad * sin($theta)) + $y_axis; + $theta += $thetac; + $rad1 = $radius * (($i + 1) / $points); + $x1 = ($rad1 * cos($theta)) + $x_axis; + $y1 = ($rad1 * sin($theta)) + $y_axis; + imageline($im, $x, $y, $x1, $y1, $colors['grid']); + $theta -= $thetac; + } + + // ----------------------------------- + // Write the text + // ----------------------------------- + + $use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext')); + if ($use_font === FALSE) + { + ($font_size > 5) && $font_size = 5; + $x = mt_rand(0, $img_width / ($length / 3)); + $y = 0; + } + else + { + ($font_size > 30) && $font_size = 30; + $x = mt_rand(0, $img_width / ($length / 1.5)); + $y = $font_size + 2; + } + + for ($i = 0; $i < $length; $i++) + { + if ($use_font === FALSE) + { + $y = mt_rand(0 , $img_height / 2); + imagestring($im, $font_size, $x, $y, $word[$i], $colors['text']); + $x += ($font_size * 2); + } + else + { + $y = mt_rand($img_height / 2, $img_height - 3); + imagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]); + $x += $font_size; + } + } + + // Create the border + imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $colors['border']); + + // ----------------------------------- + // Generate the image + // ----------------------------------- + $img_url = rtrim($img_url, '/').'/'; + + if (function_exists('imagejpeg')) + { + $img_filename = $now.'.jpg'; + imagejpeg($im, $img_path.$img_filename); + } + elseif (function_exists('imagepng')) + { + $img_filename = $now.'.png'; + imagepng($im, $img_path.$img_filename); + } + else + { + return FALSE; + } + + $img = ' '; + ImageDestroy($im); + + return array('word' => $word, 'time' => $now, 'image' => $img, 'filename' => $img_filename); + } } - -// ------------------------------------------------------------------------ - -/* End of file captcha_helper.php */ -/* Location: ./system/heleprs/captcha_helper.php */ \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php old mode 100755 new mode 100644 index d101765..b9c2cb6 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -1,104 +1,113 @@ -input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); - } + /** + * Set cookie + * + * Accepts seven parameters, or you can submit an associative + * array in the first parameter containing all the values. + * + * @param mixed + * @param string the value of the cookie + * @param string the number of seconds until expiration + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @param bool true makes the cookie secure + * @param bool true makes the cookie accessible via http(s) only (no javascript) + * @return void + */ + function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) + { + // Set the config file options + get_instance()->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly); + } } // -------------------------------------------------------------------- -/** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return mixed - */ if ( ! function_exists('get_cookie')) { - function get_cookie($index = '', $xss_clean = FALSE) - { - $CI =& get_instance(); - - $prefix = ''; - - if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') - { - $prefix = config_item('cookie_prefix'); - } - - return $CI->input->cookie($prefix.$index, $xss_clean); - } + /** + * Fetch an item from the COOKIE array + * + * @param string + * @param bool + * @return mixed + */ + function get_cookie($index, $xss_clean = NULL) + { + is_bool($xss_clean) OR $xss_clean = (config_item('global_xss_filtering') === TRUE); + $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); + return get_instance()->input->cookie($prefix.$index, $xss_clean); + } } // -------------------------------------------------------------------- -/** - * Delete a COOKIE - * - * @param mixed - * @param string the cookie domain. Usually: .yourdomain.com - * @param string the cookie path - * @param string the cookie prefix - * @return void - */ if ( ! function_exists('delete_cookie')) { - function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') - { - set_cookie($name, '', '', $domain, $path, $prefix); - } + /** + * Delete a COOKIE + * + * @param mixed + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @return void + */ + function delete_cookie($name, $domain = '', $path = '/', $prefix = '') + { + set_cookie($name, '', '', $domain, $path, $prefix); + } } - - -/* End of file cookie_helper.php */ -/* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php old mode 100755 new mode 100644 index e445b38..5c660e2 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,612 +1,742 @@ -config->item('time_reference')) == 'gmt') - { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($system_time) < 10) - { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } - - return $system_time; - } - else - { - return time(); - } - } + /** + * Get "now" time + * + * Returns time() based on the timezone parameter or on the + * "time_reference" setting + * + * @param string + * @return int + */ + function now($timezone = NULL) + { + if (empty($timezone)) + { + $timezone = config_item('time_reference'); + } + + if ($timezone === 'local' OR $timezone === date_default_timezone_get()) + { + return time(); + } + + $datetime = new DateTime('now', new DateTimeZone($timezone)); + sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); + + return mktime($hour, $minute, $second, $month, $day, $year); + } } // ------------------------------------------------------------------------ -/** - * Convert MySQL Style Datecodes - * - * This function is identical to PHPs date() function, - * except that it allows date codes to be formatted using - * the MySQL style, where each code letter is preceded - * with a percent sign: %Y %m %d etc... - * - * The benefit of doing dates this way is that you don't - * have to worry about escaping your text letters that - * match the date codes. - * - * @access public - * @param string - * @param integer - * @return integer - */ if ( ! function_exists('mdate')) { - function mdate($datestr = '', $time = '') - { - if ($datestr == '') - return ''; - - if ($time == '') - $time = now(); - - $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); - return date($datestr, $time); - } + /** + * Convert MySQL Style Datecodes + * + * This function is identical to PHPs date() function, + * except that it allows date codes to be formatted using + * the MySQL style, where each code letter is preceded + * with a percent sign: %Y %m %d etc... + * + * The benefit of doing dates this way is that you don't + * have to worry about escaping your text letters that + * match the date codes. + * + * @param string + * @param int + * @return int + */ + function mdate($datestr = '', $time = '') + { + if ($datestr === '') + { + return ''; + } + elseif (empty($time)) + { + $time = now(); + } + + $datestr = str_replace( + '%\\', + '', + preg_replace('/([a-z]+?){1}/i', '\\\\\\1', $datestr) + ); + + return date($datestr, $time); + } } // ------------------------------------------------------------------------ -/** - * Standard Date - * - * Returns a date formatted according to the submitted standard. - * - * @access public - * @param string the chosen format - * @param integer Unix timestamp - * @return string - */ if ( ! function_exists('standard_date')) { - function standard_date($fmt = 'DATE_RFC822', $time = '') - { - $formats = array( - 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q', - 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', - 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q', - 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC', - 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' - ); - - if ( ! isset($formats[$fmt])) - { - return FALSE; - } - - return mdate($formats[$fmt], $time); - } + /** + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * As of PHP 5.2, the DateTime extension provides constants that + * serve for the exact same purpose and are used with date(). + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 Use PHP's native date() instead. + * @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types + * + * @example date(DATE_RFC822, now()); // default + * @example date(DATE_W3C, $time); // a different format and time + * + * @param string $fmt = 'DATE_RFC822' the chosen format + * @param int $time = NULL Unix timestamp + * @return string + */ + function standard_date($fmt = 'DATE_RFC822', $time = NULL) + { + if (empty($time)) + { + $time = now(); + } + + // Procedural style pre-defined constants from the DateTime extension + if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === FALSE) + { + return FALSE; + } + + return date(constant($fmt), $time); + } } // ------------------------------------------------------------------------ -/** - * Timespan - * - * Returns a span of seconds in this format: - * 10 days 14 hours 36 minutes 47 seconds - * - * @access public - * @param integer a number of seconds - * @param integer Unix timestamp - * @return integer - */ if ( ! function_exists('timespan')) { - function timespan($seconds = 1, $time = '') - { - $CI =& get_instance(); - $CI->lang->load('date'); - - if ( ! is_numeric($seconds)) - { - $seconds = 1; - } - - if ( ! is_numeric($time)) - { - $time = time(); - } - - if ($time <= $seconds) - { - $seconds = 1; - } - else - { - $seconds = $time - $seconds; - } - - $str = ''; - $years = floor($seconds / 31536000); - - if ($years > 0) - { - $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; - } - - $seconds -= $years * 31536000; - $months = floor($seconds / 2628000); - - if ($years > 0 OR $months > 0) - { - if ($months > 0) - { - $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; - } - - $seconds -= $months * 2628000; - } - - $weeks = floor($seconds / 604800); - - if ($years > 0 OR $months > 0 OR $weeks > 0) - { - if ($weeks > 0) - { - $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; - } - - $seconds -= $weeks * 604800; - } - - $days = floor($seconds / 86400); - - if ($months > 0 OR $weeks > 0 OR $days > 0) - { - if ($days > 0) - { - $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; - } - - $seconds -= $days * 86400; - } - - $hours = floor($seconds / 3600); - - if ($days > 0 OR $hours > 0) - { - if ($hours > 0) - { - $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; - } - - $seconds -= $hours * 3600; - } - - $minutes = floor($seconds / 60); - - if ($days > 0 OR $hours > 0 OR $minutes > 0) - { - if ($minutes > 0) - { - $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; - } - - $seconds -= $minutes * 60; - } - - if ($str == '') - { - $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; - } - - return substr(trim($str), 0, -1); - } + /** + * Timespan + * + * Returns a span of seconds in this format: + * 10 days 14 hours 36 minutes 47 seconds + * + * @param int a number of seconds + * @param int Unix timestamp + * @param int a number of display units + * @return string + */ + function timespan($seconds = 1, $time = '', $units = 7) + { + $CI =& get_instance(); + $CI->lang->load('date'); + + is_numeric($seconds) OR $seconds = 1; + is_numeric($time) OR $time = time(); + is_numeric($units) OR $units = 7; + + $seconds = ($time <= $seconds) ? 1 : $time - $seconds; + + $str = array(); + $years = floor($seconds / 31557600); + + if ($years > 0) + { + $str[] = $years.' '.$CI->lang->line($years > 1 ? 'date_years' : 'date_year'); + } + + $seconds -= $years * 31557600; + $months = floor($seconds / 2629743); + + if (count($str) < $units && ($years > 0 OR $months > 0)) + { + if ($months > 0) + { + $str[] = $months.' '.$CI->lang->line($months > 1 ? 'date_months' : 'date_month'); + } + + $seconds -= $months * 2629743; + } + + $weeks = floor($seconds / 604800); + + if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0)) + { + if ($weeks > 0) + { + $str[] = $weeks.' '.$CI->lang->line($weeks > 1 ? 'date_weeks' : 'date_week'); + } + + $seconds -= $weeks * 604800; + } + + $days = floor($seconds / 86400); + + if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0)) + { + if ($days > 0) + { + $str[] = $days.' '.$CI->lang->line($days > 1 ? 'date_days' : 'date_day'); + } + + $seconds -= $days * 86400; + } + + $hours = floor($seconds / 3600); + + if (count($str) < $units && ($days > 0 OR $hours > 0)) + { + if ($hours > 0) + { + $str[] = $hours.' '.$CI->lang->line($hours > 1 ? 'date_hours' : 'date_hour'); + } + + $seconds -= $hours * 3600; + } + + $minutes = floor($seconds / 60); + + if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0)) + { + if ($minutes > 0) + { + $str[] = $minutes.' '.$CI->lang->line($minutes > 1 ? 'date_minutes' : 'date_minute'); + } + + $seconds -= $minutes * 60; + } + + if (count($str) === 0) + { + $str[] = $seconds.' '.$CI->lang->line($seconds > 1 ? 'date_seconds' : 'date_second'); + } + + return implode(', ', $str); + } } // ------------------------------------------------------------------------ -/** - * Number of days in a month - * - * Takes a month/year as input and returns the number of days - * for the given month/year. Takes leap years into consideration. - * - * @access public - * @param integer a numeric month - * @param integer a numeric year - * @return integer - */ if ( ! function_exists('days_in_month')) { - function days_in_month($month = 0, $year = '') - { - if ($month < 1 OR $month > 12) - { - return 0; - } - - if ( ! is_numeric($year) OR strlen($year) != 4) - { - $year = date('Y'); - } - - if ($month == 2) - { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) - { - return 29; - } - } - - $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - return $days_in_month[$month - 1]; - } + /** + * Number of days in a month + * + * Takes a month/year as input and returns the number of days + * for the given month/year. Takes leap years into consideration. + * + * @param int a numeric month + * @param int a numeric year + * @return int + */ + function days_in_month($month = 0, $year = '') + { + if ($month < 1 OR $month > 12) + { + return 0; + } + elseif ( ! is_numeric($year) OR strlen($year) !== 4) + { + $year = date('Y'); + } + + if (defined('CAL_GREGORIAN')) + { + return cal_days_in_month(CAL_GREGORIAN, $month, $year); + } + + if ($year >= 1970) + { + return (int) date('t', mktime(12, 0, 0, $month, 1, $year)); + } + + if ($month == 2) + { + if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0)) + { + return 29; + } + } + + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + return $days_in_month[$month - 1]; + } } // ------------------------------------------------------------------------ -/** - * Converts a local Unix timestamp to GMT - * - * @access public - * @param integer Unix timestamp - * @return integer - */ if ( ! function_exists('local_to_gmt')) { - function local_to_gmt($time = '') - { - if ($time == '') - $time = time(); - - return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time)); - } + /** + * Converts a local Unix timestamp to GMT + * + * @param int Unix timestamp + * @return int + */ + function local_to_gmt($time = '') + { + if ($time === '') + { + $time = time(); + } + + return mktime( + gmdate('G', $time), + gmdate('i', $time), + gmdate('s', $time), + gmdate('n', $time), + gmdate('j', $time), + gmdate('Y', $time) + ); + } } // ------------------------------------------------------------------------ -/** - * Converts GMT time to a localized value - * - * Takes a Unix timestamp (in GMT) as input, and returns - * at the local value based on the timezone and DST setting - * submitted - * - * @access public - * @param integer Unix timestamp - * @param string timezone - * @param bool whether DST is active - * @return integer - */ if ( ! function_exists('gmt_to_local')) { - function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) - { - if ($time == '') - { - return now(); - } - - $time += timezones($timezone) * 3600; - - if ($dst == TRUE) - { - $time += 3600; - } - - return $time; - } + /** + * Converts GMT time to a localized value + * + * Takes a Unix timestamp (in GMT) as input, and returns + * at the local value based on the timezone and DST setting + * submitted + * + * @param int Unix timestamp + * @param string timezone + * @param bool whether DST is active + * @return int + */ + function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) + { + if ($time === '') + { + return now(); + } + + $time += timezones($timezone) * 3600; + + return ($dst === TRUE) ? $time + 3600 : $time; + } } // ------------------------------------------------------------------------ -/** - * Converts a MySQL Timestamp to Unix - * - * @access public - * @param integer Unix timestamp - * @return integer - */ if ( ! function_exists('mysql_to_unix')) { - function mysql_to_unix($time = '') - { - // We'll remove certain characters for backward compatibility - // since the formatting changed with MySQL 4.1 - // YYYY-MM-DD HH:MM:SS - - $time = str_replace('-', '', $time); - $time = str_replace(':', '', $time); - $time = str_replace(' ', '', $time); - - // YYYYMMDDHHMMSS - return mktime( - substr($time, 8, 2), - substr($time, 10, 2), - substr($time, 12, 2), - substr($time, 4, 2), - substr($time, 6, 2), - substr($time, 0, 4) - ); - } + /** + * Converts a MySQL Timestamp to Unix + * + * @param int MySQL timestamp YYYY-MM-DD HH:MM:SS + * @return int Unix timstamp + */ + function mysql_to_unix($time = '') + { + // We'll remove certain characters for backward compatibility + // since the formatting changed with MySQL 4.1 + // YYYY-MM-DD HH:MM:SS + + $time = str_replace(array('-', ':', ' '), '', $time); + + // YYYYMMDDHHMMSS + return mktime( + substr($time, 8, 2), + substr($time, 10, 2), + substr($time, 12, 2), + substr($time, 4, 2), + substr($time, 6, 2), + substr($time, 0, 4) + ); + } } // ------------------------------------------------------------------------ -/** - * Unix to "Human" - * - * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM - * - * @access public - * @param integer Unix timestamp - * @param bool whether to show seconds - * @param string format: us or euro - * @return string - */ if ( ! function_exists('unix_to_human')) { - function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') - { - $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - - if ($fmt == 'us') - { - $r .= date('h', $time).':'.date('i', $time); - } - else - { - $r .= date('H', $time).':'.date('i', $time); - } - - if ($seconds) - { - $r .= ':'.date('s', $time); - } - - if ($fmt == 'us') - { - $r .= ' '.date('A', $time); - } - - return $r; - } + /** + * Unix to "Human" + * + * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM + * + * @param int Unix timestamp + * @param bool whether to show seconds + * @param string format: us or euro + * @return string + */ + function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') + { + $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; + + if ($fmt === 'us') + { + $r .= date('h', $time).':'.date('i', $time); + } + else + { + $r .= date('H', $time).':'.date('i', $time); + } + + if ($seconds) + { + $r .= ':'.date('s', $time); + } + + if ($fmt === 'us') + { + return $r.' '.date('A', $time); + } + + return $r; + } } // ------------------------------------------------------------------------ -/** - * Convert "human" date to GMT - * - * Reverses the above process - * - * @access public - * @param string format: us or euro - * @return integer - */ if ( ! function_exists('human_to_unix')) { - function human_to_unix($datestr = '') - { - if ($datestr == '') - { - return FALSE; - } - - $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", ' ', $datestr); - - if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) - { - return FALSE; - } - - $split = explode(' ', $datestr); - - $ex = explode("-", $split['0']); - - $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; - $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; - - $ex = explode(":", $split['1']); - - $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; - $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - - if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2'])) - { - $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; - } - else - { - // Unless specified, seconds get set to zero. - $sec = '00'; - } - - if (isset($split['2'])) - { - $ampm = strtolower($split['2']); - - if (substr($ampm, 0, 1) == 'p' AND $hour < 12) - $hour = $hour + 12; - - if (substr($ampm, 0, 1) == 'a' AND $hour == 12) - $hour = '00'; + /** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @param string format: us or euro + * @return int + */ + function human_to_unix($datestr = '') + { + if ($datestr === '') + { + return FALSE; + } + + $datestr = preg_replace('/\040+/', ' ', trim($datestr)); + + if ( ! preg_match('/^(\d{2}|\d{4})\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) + { + return FALSE; + } + + sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm); + sscanf($time, '%d:%d:%d', $hour, $min, $sec); + isset($sec) OR $sec = 0; + + if (isset($ampm)) + { + $ampm = strtolower($ampm); + + if ($ampm[0] === 'p' && $hour < 12) + { + $hour += 12; + } + elseif ($ampm[0] === 'a' && $hour === 12) + { + $hour = 0; + } + } + + return mktime($hour, $min, $sec, $month, $day, $year); + } +} - if (strlen($hour) == 1) - $hour = '0'.$hour; - } +// ------------------------------------------------------------------------ - return mktime($hour, $min, $sec, $month, $day, $year); - } +if ( ! function_exists('nice_date')) +{ + /** + * Turns many "reasonably-date-like" strings into something + * that is actually useful. This only works for dates after unix epoch. + * + * @deprecated 3.1.3 Use DateTime::createFromFormat($input_format, $input)->format($output_format); + * @param string The terribly formatted date-like string + * @param string Date format to return (same as php date function) + * @return string + */ + function nice_date($bad_date = '', $format = FALSE) + { + if (empty($bad_date)) + { + return 'Unknown'; + } + elseif (empty($format)) + { + $format = 'U'; + } + + // Date like: YYYYMM + if (preg_match('/^\d{6}$/i', $bad_date)) + { + if (in_array(substr($bad_date, 0, 2), array('19', '20'))) + { + $year = substr($bad_date, 0, 4); + $month = substr($bad_date, 4, 2); + } + else + { + $month = substr($bad_date, 0, 2); + $year = substr($bad_date, 2, 4); + } + + return date($format, strtotime($year.'-'.$month.'-01')); + } + + // Date Like: YYYYMMDD + if (preg_match('/^\d{8}$/i', $bad_date, $matches)) + { + return DateTime::createFromFormat('Ymd', $bad_date)->format($format); + } + + // Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between) + if (preg_match('/^(\d{1,2})-(\d{1,2})-(\d{4})$/i', $bad_date, $matches)) + { + return date($format, strtotime($matches[3].'-'.$matches[1].'-'.$matches[2])); + } + + // Any other kind of string, when converted into UNIX time, + // produces "0 seconds after epoc..." is probably bad... + // return "Invalid Date". + if (date('U', strtotime($bad_date)) === '0') + { + return 'Invalid Date'; + } + + // It's probably a valid-ish date format already + return date($format, strtotime($bad_date)); + } } // ------------------------------------------------------------------------ -/** - * Timezone Menu - * - * Generates a drop-down menu of timezones. - * - * @access public - * @param string timezone - * @param string classname - * @param string menu name - * @return string - */ if ( ! function_exists('timezone_menu')) { - function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') - { - $CI =& get_instance(); - $CI->lang->load('date'); - - if ($default == 'GMT') - $default = 'UTC'; - - $menu = '"; - - return $menu; - } + /** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @param string timezone + * @param string classname + * @param string menu name + * @param mixed attributes + * @return string + */ + function timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '') + { + $CI =& get_instance(); + $CI->lang->load('date'); + + $default = ($default === 'GMT') ? 'UTC' : $default; + + $menu = ''; + } } // ------------------------------------------------------------------------ -/** - * Timezones - * - * Returns an array of timezones. This is a helper function - * for various other ones in this library - * - * @access public - * @param string timezone - * @return string - */ if ( ! function_exists('timezones')) { - function timezones($tz = '') - { - // Note: Don't change the order of these even though - // some items appear to be in the wrong order - - $zones = array( - 'UM12' => -12, - 'UM11' => -11, - 'UM10' => -10, - 'UM95' => -9.5, - 'UM9' => -9, - 'UM8' => -8, - 'UM7' => -7, - 'UM6' => -6, - 'UM5' => -5, - 'UM45' => -4.5, - 'UM4' => -4, - 'UM35' => -3.5, - 'UM3' => -3, - 'UM2' => -2, - 'UM1' => -1, - 'UTC' => 0, - 'UP1' => +1, - 'UP2' => +2, - 'UP3' => +3, - 'UP35' => +3.5, - 'UP4' => +4, - 'UP45' => +4.5, - 'UP5' => +5, - 'UP55' => +5.5, - 'UP575' => +5.75, - 'UP6' => +6, - 'UP65' => +6.5, - 'UP7' => +7, - 'UP8' => +8, - 'UP875' => +8.75, - 'UP9' => +9, - 'UP95' => +9.5, - 'UP10' => +10, - 'UP105' => +10.5, - 'UP11' => +11, - 'UP115' => +11.5, - 'UP12' => +12, - 'UP1275' => +12.75, - 'UP13' => +13, - 'UP14' => +14 - ); - - if ($tz == '') - { - return $zones; - } - - if ($tz == 'GMT') - $tz = 'UTC'; - - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; - } + /** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for various other ones in this library + * + * @param string timezone + * @return string + */ + function timezones($tz = '') + { + // Note: Don't change the order of these even though + // some items appear to be in the wrong order + + $zones = array( + 'UM12' => -12, + 'UM11' => -11, + 'UM10' => -10, + 'UM95' => -9.5, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM45' => -4.5, + 'UM4' => -4, + 'UM35' => -3.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP35' => +3.5, + 'UP4' => +4, + 'UP45' => +4.5, + 'UP5' => +5, + 'UP55' => +5.5, + 'UP575' => +5.75, + 'UP6' => +6, + 'UP65' => +6.5, + 'UP7' => +7, + 'UP8' => +8, + 'UP875' => +8.75, + 'UP9' => +9, + 'UP95' => +9.5, + 'UP10' => +10, + 'UP105' => +10.5, + 'UP11' => +11, + 'UP115' => +11.5, + 'UP12' => +12, + 'UP1275' => +12.75, + 'UP13' => +13, + 'UP14' => +14 + ); + + if ($tz === '') + { + return $zones; + } + + return isset($zones[$tz]) ? $zones[$tz] : 0; + } } +// ------------------------------------------------------------------------ -/* End of file date_helper.php */ -/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file +if ( ! function_exists('date_range')) +{ + /** + * Date range + * + * Returns a list of dates within a specified period. + * + * @param int unix_start UNIX timestamp of period start date + * @param int unix_end|days UNIX timestamp of period end date + * or interval in days. + * @param mixed is_unix Specifies whether the second parameter + * is a UNIX timestamp or a day interval + * - TRUE or 'unix' for a timestamp + * - FALSE or 'days' for an interval + * @param string date_format Output date format, same as in date() + * @return array + */ + function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') + { + if ($unix_start == '' OR $mixed == '' OR $format == '') + { + return FALSE; + } + + $is_unix = ! ( ! $is_unix OR $is_unix === 'days'); + + // Validate input and try strtotime() on invalid timestamps/intervals, just in case + if ( ( ! ctype_digit((string) $unix_start) && ($unix_start = @strtotime($unix_start)) === FALSE) + OR ( ! ctype_digit((string) $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) + OR ($is_unix === TRUE && $mixed < $unix_start)) + { + return FALSE; + } + + if ($is_unix && ($unix_start == $mixed OR date($format, $unix_start) === date($format, $mixed))) + { + return array(date($format, $unix_start)); + } + + $range = array(); + + $from = new DateTime(); + $from->setTimestamp($unix_start); + + if ($is_unix) + { + $arg = new DateTime(); + $arg->setTimestamp($mixed); + } + else + { + $arg = (int) $mixed; + } + + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + foreach ($period as $date) + { + $range[] = $date->format($format); + } + + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { + $range[] = $arg->format($format); + } + + return $range; + } +} diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php old mode 100755 new mode 100644 index bf90250..73777bf --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -1,81 +1,101 @@ - 0) && @is_dir($source_dir.$file)) - { - $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); - } - else - { - $filedata[] = $file; - } - } + is_dir($source_dir.$file) && $file .= DIRECTORY_SEPARATOR; - closedir($fp); - return $filedata; - } - - return FALSE; - } -} + if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir.$file)) + { + $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); + } + else + { + $filedata[] = $file; + } + } + closedir($fp); + return $filedata; + } -/* End of file directory_helper.php */ -/* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file + return FALSE; + } +} diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php old mode 100755 new mode 100644 index 6c84266..d8e30ae --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,107 +1,158 @@ - 0) - { - $data =& fread($fp, filesize($file)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - return $data; - } + /** + * Read File + * + * Opens the file specified in the path and returns it as a string. + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents(). + * @param string $file Path to file + * @return string File contents + */ + function read_file($file) + { + return @file_get_contents($file); + } } // ------------------------------------------------------------------------ -/** - * Write File - * - * Writes data to the file specified in the path. - * Creates a new file if non-existent. - * - * @access public - * @param string path to file - * @param string file data - * @return bool - */ if ( ! function_exists('write_file')) { - function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) - { - if ( ! $fp = @fopen($path, $mode)) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - - return TRUE; - } + /** + * Write File + * + * Writes data to the file specified in the path. + * Creates a new file if non-existent. + * + * @param string $path File path + * @param string $data Data to write + * @param string $mode fopen() mode (default: 'wb') + * @return bool + */ + function write_file($path, $data, $mode = 'wb') + { + if ( ! $fp = @fopen($path, $mode)) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($data, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + return is_int($result); + } } // ------------------------------------------------------------------------ -/** - * Delete Files - * - * Deletes all files contained in the supplied directory path. - * Files must be writable or owned by the system in order to be deleted. - * If the second parameter is set to TRUE, any directories contained - * within the supplied base directory will be nuked as well. - * - * @access public - * @param string path to file - * @param bool whether to delete any directories found in the path - * @return bool - */ if ( ! function_exists('delete_files')) { - function delete_files($path, $del_dir = FALSE, $level = 0) - { - // Trim the trailing slash - $path = rtrim($path, DIRECTORY_SEPARATOR); - - if ( ! $current_dir = @opendir($path)) - { - return FALSE; - } - - while (FALSE !== ($filename = @readdir($current_dir))) - { - if ($filename != "." and $filename != "..") - { - if (is_dir($path.DIRECTORY_SEPARATOR.$filename)) - { - // Ignore empty folders - if (substr($filename, 0, 1) != '.') - { - delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); - } - } - else - { - unlink($path.DIRECTORY_SEPARATOR.$filename); - } - } - } - @closedir($current_dir); - - if ($del_dir == TRUE AND $level > 0) - { - return @rmdir($path); - } - - return TRUE; - } + /** + * Delete Files + * + * Deletes all files contained in the supplied directory path. + * Files must be writable or owned by the system in order to be deleted. + * If the second parameter is set to TRUE, any directories contained + * within the supplied base directory will be nuked as well. + * + * @param string $path File path + * @param bool $del_dir Whether to delete any directories found in the path + * @param bool $htdocs Whether to skip deleting .htaccess and index page files + * @param int $_level Current directory depth level (default: 0; internal use only) + * @return bool + */ + function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0) + { + // Trim the trailing slash + $path = rtrim($path, '/\\'); + + if ( ! $current_dir = @opendir($path)) + { + return FALSE; + } + + while (FALSE !== ($filename = @readdir($current_dir))) + { + if ($filename !== '.' && $filename !== '..') + { + $filepath = $path.DIRECTORY_SEPARATOR.$filename; + + if (is_dir($filepath) && $filename[0] !== '.' && ! is_link($filepath)) + { + delete_files($filepath, $del_dir, $htdocs, $_level + 1); + } + elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) + { + @unlink($filepath); + } + } + } + + closedir($current_dir); + + return ($del_dir === TRUE && $_level > 0) + ? @rmdir($path) + : TRUE; + } } // ------------------------------------------------------------------------ -/** - * Get Filenames - * - * Reads the specified directory and builds an array containing the filenames. - * Any sub-folders contained within the specified path are read as well. - * - * @access public - * @param string path to source - * @param bool whether to include the path as part of the filename - * @param bool internal variable to determine recursion status - do not use in calls - * @return array - */ if ( ! function_exists('get_filenames')) { - function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) - { - static $_filedata = array(); - - if ($fp = @opendir($source_dir)) - { - // reset the array and make sure $source_dir has a trailing slash on the initial call - if ($_recursion === FALSE) - { - $_filedata = array(); - $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - } - - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) - { - get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) - { - $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; - } - } - return $_filedata; - } - else - { - return FALSE; - } - } + /** + * Get Filenames + * + * Reads the specified directory and builds an array containing the filenames. + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool whether to include the path as part of the filename + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ + function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) + { + static $_filedata = array(); + + if ($fp = @opendir($source_dir)) + { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + } + + while (FALSE !== ($file = readdir($fp))) + { + if (is_dir($source_dir.$file) && $file[0] !== '.') + { + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); + } + elseif ($file[0] !== '.') + { + $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file; + } + } + + closedir($fp); + return $_filedata; + } + + return FALSE; + } } // -------------------------------------------------------------------- -/** - * Get Directory File Information - * - * Reads the specified directory and builds an array containing the filenames, - * filesize, dates, and permissions - * - * Any sub-folders contained within the specified path are read as well. - * - * @access public - * @param string path to source - * @param bool Look only at the top level directory specified? - * @param bool internal variable to determine recursion status - do not use in calls - * @return array - */ if ( ! function_exists('get_dir_file_info')) { - function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) - { - static $_filedata = array(); - $relative_path = $source_dir; - - if ($fp = @opendir($source_dir)) - { - // reset the array and make sure $source_dir has a trailing slash on the initial call - if ($_recursion === FALSE) - { - $_filedata = array(); - $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - } - - // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) - { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) - { - $_filedata[$file] = get_file_info($source_dir.$file); - $_filedata[$file]['relative_path'] = $relative_path; - } - } - - return $_filedata; - } - else - { - return FALSE; - } - } + /** + * Get Directory File Information + * + * Reads the specified directory and builds an array containing the filenames, + * filesize, dates, and permissions + * + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool Look only at the top level directory specified? + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ + function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) + { + static $_filedata = array(); + $relative_path = $source_dir; + + if ($fp = @opendir($source_dir)) + { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + } + + // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast + while (FALSE !== ($file = readdir($fp))) + { + if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE) + { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif ($file[0] !== '.') + { + $_filedata[$file] = get_file_info($source_dir.$file); + $_filedata[$file]['relative_path'] = $relative_path; + } + } + + closedir($fp); + return $_filedata; + } + + return FALSE; + } } // -------------------------------------------------------------------- -/** -* Get File Info -* -* Given a file and path, returns the name, path, size, date modified -* Second parameter allows you to explicitly declare what information you want returned -* Options are: name, server_path, size, date, readable, writable, executable, fileperms -* Returns FALSE if the file cannot be found. -* -* @access public -* @param string path to file -* @param mixed array or comma separated string of information returned -* @return array -*/ if ( ! function_exists('get_file_info')) { - function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) - { - - if ( ! file_exists($file)) - { - return FALSE; - } - - if (is_string($returned_values)) - { - $returned_values = explode(',', $returned_values); - } - - foreach ($returned_values as $key) - { - switch ($key) - { - case 'name': - $fileinfo['name'] = substr(strrchr($file, DIRECTORY_SEPARATOR), 1); - break; - case 'server_path': - $fileinfo['server_path'] = $file; - break; - case 'size': - $fileinfo['size'] = filesize($file); - break; - case 'date': - $fileinfo['date'] = filemtime($file); - break; - case 'readable': - $fileinfo['readable'] = is_readable($file); - break; - case 'writable': - // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms() - $fileinfo['writable'] = is_writable($file); - break; - case 'executable': - $fileinfo['executable'] = is_executable($file); - break; - case 'fileperms': - $fileinfo['fileperms'] = fileperms($file); - break; - } - } - - return $fileinfo; - } + /** + * Get File Info + * + * Given a file and path, returns the name, path, size, date modified + * Second parameter allows you to explicitly declare what information you want returned + * Options are: name, server_path, size, date, readable, writable, executable, fileperms + * Returns FALSE if the file cannot be found. + * + * @param string path to file + * @param mixed array or comma separated string of information returned + * @return array + */ + function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) + { + if ( ! file_exists($file)) + { + return FALSE; + } + + if (is_string($returned_values)) + { + $returned_values = explode(',', $returned_values); + } + + foreach ($returned_values as $key) + { + switch ($key) + { + case 'name': + $fileinfo['name'] = basename($file); + break; + case 'server_path': + $fileinfo['server_path'] = $file; + break; + case 'size': + $fileinfo['size'] = filesize($file); + break; + case 'date': + $fileinfo['date'] = filemtime($file); + break; + case 'readable': + $fileinfo['readable'] = is_readable($file); + break; + case 'writable': + $fileinfo['writable'] = is_really_writable($file); + break; + case 'executable': + $fileinfo['executable'] = is_executable($file); + break; + case 'fileperms': + $fileinfo['fileperms'] = fileperms($file); + break; + } + } + + return $fileinfo; + } } // -------------------------------------------------------------------- -/** - * Get Mime by Extension - * - * Translates a file extension into a mime type based on config/mimes.php. - * Returns FALSE if it can't determine the type, or open the mime config file - * - * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience - * It should NOT be trusted, and should certainly NOT be used for security - * - * @access public - * @param string path to file - * @return mixed - */ if ( ! function_exists('get_mime_by_extension')) { - function get_mime_by_extension($file) - { - $extension = strtolower(substr(strrchr($file, '.'), 1)); - - global $mimes; - - if ( ! is_array($mimes)) - { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); - } - elseif (is_file(APPPATH.'config/mimes.php')) - { - include(APPPATH.'config/mimes.php'); - } - - if ( ! is_array($mimes)) - { - return FALSE; - } - } - - if (array_key_exists($extension, $mimes)) - { - if (is_array($mimes[$extension])) - { - // Multiple mime types, just give the first one - return current($mimes[$extension]); - } - else - { - return $mimes[$extension]; - } - } - else - { - return FALSE; - } - } + /** + * Get Mime by Extension + * + * Translates a file extension into a mime type based on config/mimes.php. + * Returns FALSE if it can't determine the type, or open the mime config file + * + * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience + * It should NOT be trusted, and should certainly NOT be used for security + * + * @param string $filename File name + * @return string + */ + function get_mime_by_extension($filename) + { + static $mimes; + + if ( ! is_array($mimes)) + { + $mimes = get_mimes(); + + if (empty($mimes)) + { + return FALSE; + } + } + + $extension = strtolower(substr(strrchr($filename, '.'), 1)); + + if (isset($mimes[$extension])) + { + return is_array($mimes[$extension]) + ? current($mimes[$extension]) // Multiple mime types, just give the first one + : $mimes[$extension]; + } + + return FALSE; + } } // -------------------------------------------------------------------- -/** - * Symbolic Permissions - * - * Takes a numeric value representing a file's permissions and returns - * standard symbolic notation representing that value - * - * @access public - * @param int - * @return string - */ if ( ! function_exists('symbolic_permissions')) { - function symbolic_permissions($perms) - { - if (($perms & 0xC000) == 0xC000) - { - $symbolic = 's'; // Socket - } - elseif (($perms & 0xA000) == 0xA000) - { - $symbolic = 'l'; // Symbolic Link - } - elseif (($perms & 0x8000) == 0x8000) - { - $symbolic = '-'; // Regular - } - elseif (($perms & 0x6000) == 0x6000) - { - $symbolic = 'b'; // Block special - } - elseif (($perms & 0x4000) == 0x4000) - { - $symbolic = 'd'; // Directory - } - elseif (($perms & 0x2000) == 0x2000) - { - $symbolic = 'c'; // Character special - } - elseif (($perms & 0x1000) == 0x1000) - { - $symbolic = 'p'; // FIFO pipe - } - else - { - $symbolic = 'u'; // Unknown - } - - // Owner - $symbolic .= (($perms & 0x0100) ? 'r' : '-'); - $symbolic .= (($perms & 0x0080) ? 'w' : '-'); - $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); - - // Group - $symbolic .= (($perms & 0x0020) ? 'r' : '-'); - $symbolic .= (($perms & 0x0010) ? 'w' : '-'); - $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); - - // World - $symbolic .= (($perms & 0x0004) ? 'r' : '-'); - $symbolic .= (($perms & 0x0002) ? 'w' : '-'); - $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); - - return $symbolic; - } + /** + * Symbolic Permissions + * + * Takes a numeric value representing a file's permissions and returns + * standard symbolic notation representing that value + * + * @param int $perms Permissions + * @return string + */ + function symbolic_permissions($perms) + { + if (($perms & 0xC000) === 0xC000) + { + $symbolic = 's'; // Socket + } + elseif (($perms & 0xA000) === 0xA000) + { + $symbolic = 'l'; // Symbolic Link + } + elseif (($perms & 0x8000) === 0x8000) + { + $symbolic = '-'; // Regular + } + elseif (($perms & 0x6000) === 0x6000) + { + $symbolic = 'b'; // Block special + } + elseif (($perms & 0x4000) === 0x4000) + { + $symbolic = 'd'; // Directory + } + elseif (($perms & 0x2000) === 0x2000) + { + $symbolic = 'c'; // Character special + } + elseif (($perms & 0x1000) === 0x1000) + { + $symbolic = 'p'; // FIFO pipe + } + else + { + $symbolic = 'u'; // Unknown + } + + // Owner + $symbolic .= (($perms & 0x0100) ? 'r' : '-') + .(($perms & 0x0080) ? 'w' : '-') + .(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); + + // Group + $symbolic .= (($perms & 0x0020) ? 'r' : '-') + .(($perms & 0x0010) ? 'w' : '-') + .(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); + + // World + $symbolic .= (($perms & 0x0004) ? 'r' : '-') + .(($perms & 0x0002) ? 'w' : '-') + .(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); + + return $symbolic; + } } // -------------------------------------------------------------------- -/** - * Octal Permissions - * - * Takes a numeric value representing a file's permissions and returns - * a three character string representing the file's octal permissions - * - * @access public - * @param int - * @return string - */ if ( ! function_exists('octal_permissions')) { - function octal_permissions($perms) - { - return substr(sprintf('%o', $perms), -3); - } + /** + * Octal Permissions + * + * Takes a numeric value representing a file's permissions and returns + * a three character string representing the file's octal permissions + * + * @param int $perms Permissions + * @return string + */ + function octal_permissions($perms) + { + return substr(sprintf('%o', $perms), -3); + } } - - -/* End of file file_helper.php */ -/* Location: ./system/helpers/file_helper.php */ \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php old mode 100755 new mode 100644 index bca6a88..5910d8e --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,1055 +1,1055 @@ -config->site_url($action); - } - - // If no action is provided then set to the current url - $action OR $action = $CI->config->site_url($CI->uri->uri_string()); - - $form = '
config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) - { - $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); - } - - if (is_array($hidden) AND count($hidden) > 0) - { - $form .= sprintf("
%s
", form_hidden($hidden)); - } - - return $form; - } + /** + * Form Declaration + * + * Creates the opening portion of the form. + * + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ + function form_open($action = '', $attributes = array(), $hidden = array()) + { + $CI =& get_instance(); + + // If no action is provided then set to the current url + if ( ! $action) + { + $action = $CI->config->site_url($CI->uri->uri_string()); + } + // If an action is not a full URL then turn it into one + elseif (strpos($action, '://') === FALSE) + { + $action = $CI->config->site_url($action); + } + + $attributes = _attributes_to_string($attributes); + + if (stripos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + if (stripos($attributes, 'accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + + $form = '\n"; + + if (is_array($hidden)) + { + foreach ($hidden as $name => $value) + { + $form .= ''."\n"; + } + } + + // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites + if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"')) + { + // Prepend/append random-length "white noise" around the CSRF + // token input, as a form of protection against BREACH attacks + if (FALSE !== ($noise = $CI->security->get_random_bytes(1))) + { + list(, $noise) = unpack('c', $noise); + } + else + { + $noise = mt_rand(-128, 127); + } + + // Prepend if $noise has a negative value, append if positive, do nothing for zero + $prepend = $append = ''; + if ($noise < 0) + { + $prepend = str_repeat(" ", abs($noise)); + } + elseif ($noise > 0) + { + $append = str_repeat(" ", $noise); + } + + $form .= sprintf( + '%s%s%s', + $prepend, + $CI->security->get_csrf_token_name(), + $CI->security->get_csrf_hash(), + $append, + "\n" + ); + } + + return $form; + } } // ------------------------------------------------------------------------ -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ if ( ! function_exists('form_open_multipart')) { - function form_open_multipart($action = '', $attributes = array(), $hidden = array()) - { - if (is_string($attributes)) - { - $attributes .= ' enctype="multipart/form-data"'; - } - else - { - $attributes['enctype'] = 'multipart/form-data'; - } - - return form_open($action, $attributes, $hidden); - } + /** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ + function form_open_multipart($action = '', $attributes = array(), $hidden = array()) + { + if (is_string($attributes)) + { + $attributes .= ' enctype="multipart/form-data"'; + } + else + { + $attributes['enctype'] = 'multipart/form-data'; + } + + return form_open($action, $attributes, $hidden); + } } // ------------------------------------------------------------------------ -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ if ( ! function_exists('form_hidden')) { - function form_hidden($name, $value = '', $recursing = FALSE) - { - static $form; - - if ($recursing === FALSE) - { - $form = "\n"; - } - - if (is_array($name)) - { - foreach ($name as $key => $val) - { - form_hidden($key, $val, TRUE); - } - return $form; - } - - if ( ! is_array($value)) - { - $form .= ''."\n"; - } - else - { - foreach ($value as $k => $v) - { - $k = (is_int($k)) ? '' : $k; - form_hidden($name.'['.$k.']', $v, TRUE); - } - } - - return $form; - } + /** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or + * an associative array with multiple values. + * + * @param mixed $name Field name + * @param string $value Field value + * @param bool $recursing + * @return string + */ + function form_hidden($name, $value = '', $recursing = FALSE) + { + static $form; + + if ($recursing === FALSE) + { + $form = "\n"; + } + + if (is_array($name)) + { + foreach ($name as $key => $val) + { + form_hidden($key, $val, TRUE); + } + + return $form; + } + + if ( ! is_array($value)) + { + $form .= '\n"; + } + else + { + foreach ($value as $k => $v) + { + $k = is_int($k) ? '' : $k; + form_hidden($name.'['.$k.']', $v, TRUE); + } + } + + return $form; + } } // ------------------------------------------------------------------------ -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_input')) { - function form_input($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } + /** + * Text Input Field + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_input($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'text', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_password')) { - function form_password($data = '', $value = '', $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); - } + /** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_password($data = '', $value = '', $extra = '') + { + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'password'; + return form_input($data, $value, $extra); + } } // ------------------------------------------------------------------------ -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_upload')) { - function form_upload($data = '', $value = '', $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); - } + /** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_upload($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'file', 'name' => ''); + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'file'; + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_textarea')) { - function form_textarea($data = '', $value = '', $extra = '') - { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '40', 'rows' => '10'); - - if ( ! is_array($data) OR ! isset($data['value'])) - { - $val = $value; - } - else - { - $val = $data['value']; - unset($data['value']); // textareas don't use the value attribute - } - - $name = (is_array($data)) ? $data['name'] : $data; - return ""; - } + /** + * Textarea field + * + * @param mixed $data + * @param string $value + * @param mixed $extra + * @return string + */ + function form_textarea($data = '', $value = '', $extra = '') + { + $defaults = array( + 'name' => is_array($data) ? '' : $data, + 'cols' => '40', + 'rows' => '10' + ); + + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Multi-select menu - * - * @access public - * @param string - * @param array - * @param mixed - * @param string - * @return type - */ if ( ! function_exists('form_multiselect')) { - function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') - { - if ( ! strpos($extra, 'multiple')) - { - $extra .= ' multiple="multiple"'; - } - - return form_dropdown($name, $options, $selected, $extra); - } + /** + * Multi-select menu + * + * @param string + * @param array + * @param mixed + * @param mixed + * @return string + */ + function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') + { + $extra = _attributes_to_string($extra); + if (stripos($extra, 'multiple') === FALSE) + { + $extra .= ' multiple="multiple"'; + } + + return form_dropdown($name, $options, $selected, $extra); + } } // -------------------------------------------------------------------- -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_dropdown')) { - function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') - { - if ( ! is_array($selected)) - { - $selected = array($selected); - } - - // If no selected state was submitted we will attempt to set it automatically - if (count($selected) === 0) - { - // If the form name appears in the $_POST array we have a winner! - if (isset($_POST[$name])) - { - $selected = array($_POST[$name]); - } - } - - if ($extra != '') $extra = ' '.$extra; - - $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; - - $form = ''; - - return $form; - } + /** + * Drop-down Menu + * + * @param mixed $data + * @param mixed $options + * @param mixed $selected + * @param mixed $extra + * @return string + */ + function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '') + { + $defaults = array(); + + if (is_array($data)) + { + if (isset($data['selected'])) + { + $selected = $data['selected']; + unset($data['selected']); // select tags don't have a selected attribute + } + + if (isset($data['options'])) + { + $options = $data['options']; + unset($data['options']); // select tags don't use an options attribute + } + } + else + { + $defaults = array('name' => $data); + } + + is_array($selected) OR $selected = array($selected); + is_array($options) OR $options = array($options); + + // If no selected state was submitted we will attempt to set it automatically + if (empty($selected)) + { + if (is_array($data)) + { + if (isset($data['name'], $_POST[$data['name']])) + { + $selected = array($_POST[$data['name']]); + } + } + elseif (isset($_POST[$data])) + { + $selected = array($_POST[$data]); + } + } + + $extra = _attributes_to_string($extra); + + $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; + + $form = '\n"; + } } // ------------------------------------------------------------------------ -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ if ( ! function_exists('form_checkbox')) { - function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') - { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else - { - $data['checked'] = 'checked'; - } - } - - if ($checked == TRUE) - { - $defaults['checked'] = 'checked'; - } - else - { - unset($defaults['checked']); - } - - return ""; - } + /** + * Checkbox Field + * + * @param mixed + * @param string + * @param bool + * @param mixed + * @return string + */ + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') + { + $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); + + if (is_array($data) && array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } + } + + if ($checked == TRUE) + { + $defaults['checked'] = 'checked'; + } + else + { + unset($defaults['checked']); + } + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ if ( ! function_exists('form_radio')) { - function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); - } + /** + * Radio Button + * + * @param mixed + * @param string + * @param bool + * @param mixed + * @return string + */ + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') + { + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'radio'; + + return form_checkbox($data, $value, $checked, $extra); + } } // ------------------------------------------------------------------------ -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_submit')) { - function form_submit($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } + /** + * Submit Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_submit($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'submit', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Reset Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_reset')) { - function form_reset($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } + /** + * Reset Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_reset($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'reset', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Form Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_button')) { - function form_button($data = '', $content = '', $extra = '') - { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); - - if ( is_array($data) AND isset($data['content'])) - { - $content = $data['content']; - unset($data['content']); // content is not an attribute - } - - return ""; - } + /** + * Form Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array( + 'name' => is_array($data) ? '' : $data, + 'type' => 'button' + ); + + if (is_array($data) && isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return '\n"; + } } // ------------------------------------------------------------------------ -/** - * Form Label Tag - * - * @access public - * @param string The text to appear onscreen - * @param string The id the label applies to - * @param string Additional attributes - * @return string - */ if ( ! function_exists('form_label')) { - function form_label($label_text = '', $id = '', $attributes = array()) - { - - $label = ' 0) - { - foreach ($attributes as $key => $val) - { - $label .= ' '.$key.'="'.$val.'"'; - } - } - - $label .= ">$label_text"; - - return $label; - } + /** + * Form Label Tag + * + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param mixed Additional attributes + * @return string + */ + function form_label($label_text = '', $id = '', $attributes = array()) + { + + $label = ''.$label_text.''; + } } // ------------------------------------------------------------------------ -/** - * Fieldset Tag - * - * Used to produce
text. To close fieldset - * use form_fieldset_close() - * - * @access public - * @param string The legend text - * @param string Additional attributes - * @return string - */ + if ( ! function_exists('form_fieldset')) { - function form_fieldset($legend_text = '', $attributes = array()) - { - $fieldset = "text. To close fieldset + * use form_fieldset_close() + * + * @param string The legend text + * @param array Additional attributes + * @return string + */ + function form_fieldset($legend_text = '', $attributes = array()) + { + $fieldset = '\n"; + if ($legend_text !== '') + { + return $fieldset.''.$legend_text."\n"; + } + + return $fieldset; + } } // ------------------------------------------------------------------------ -/** - * Fieldset Close Tag - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('form_fieldset_close')) { - function form_fieldset_close($extra = '') - { - return "
".$extra; - } + /** + * Fieldset Close Tag + * + * @param string + * @return string + */ + function form_fieldset_close($extra = '') + { + return ''.$extra; + } } // ------------------------------------------------------------------------ -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('form_close')) { - function form_close($extra = '') - { - return "".$extra; - } + /** + * Form Close Tag + * + * @param string + * @return string + */ + function form_close($extra = '') + { + return ''.$extra; + } } // ------------------------------------------------------------------------ -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('form_prep')) { - function form_prep($str = '', $field_name = '') - { - static $prepped_fields = array(); - - // if the field name is an array we do this recursively - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = form_prep($val); - } - - return $str; - } - - if ($str === '') - { - return ''; - } - - // we've already prepped a field with this name - // @todo need to figure out a way to namespace this so - // that we know the *exact* field and not just one with - // the same name - if (isset($prepped_fields[$field_name])) - { - return $str; - } - - $str = htmlspecialchars($str); - - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - - if ($field_name != '') - { - $prepped_fields[$field_name] = $field_name; - } - - return $str; - } + /** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @deprecated 3.0.0 An alias for html_escape() + * @param string|string[] $str Value to escape + * @return string|string[] Escaped values + */ + function form_prep($str) + { + return html_escape($str, TRUE); + } } // ------------------------------------------------------------------------ -/** - * Form Value - * - * Grabs a value from the POST array for the specified field so you can - * re-populate an input field or textarea. If Form Validation - * is active it retrieves the info from the validation class - * - * @access public - * @param string - * @return mixed - */ if ( ! function_exists('set_value')) { - function set_value($field = '', $default = '') - { - if (FALSE === ($OBJ =& _get_validation_object())) - { - if ( ! isset($_POST[$field])) - { - return $default; - } - - return form_prep($_POST[$field], $field); - } - - return form_prep($OBJ->set_value($field, $default), $field); - } + /** + * Form Value + * + * Grabs a value from the POST array for the specified field so you can + * re-populate an input field or textarea. If Form Validation + * is active it retrieves the info from the validation class + * + * @param string $field Field name + * @param string $default Default value + * @param bool $html_escape Whether to escape HTML special characters or not + * @return string + */ + function set_value($field, $default = '', $html_escape = TRUE) + { + $CI =& get_instance(); + + $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) + ? $CI->form_validation->set_value($field, $default) + : $CI->input->post($field, FALSE); + + isset($value) OR $value = $default; + return ($html_escape) ? html_escape($value) : $value; + } } // ------------------------------------------------------------------------ -/** - * Set Select - * - * Let's you set the selected value of a menu via data in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string + * @param string + * @param bool + * @return string + */ + function set_select($field, $value = '', $default = FALSE) + { + $CI =& get_instance(); + + if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) + { + return $CI->form_validation->set_select($field, $value, $default); + } + elseif (($input = $CI->input->post($field, FALSE)) === NULL) + { + return ($default === TRUE) ? ' selected="selected"' : ''; + } + + $value = (string) $value; + if (is_array($input)) + { + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($input as &$v) + { + if ($value === $v) + { + return ' selected="selected"'; + } + } + + return ''; + } + + return ($input === $value) ? ' selected="selected"' : ''; + } } // ------------------------------------------------------------------------ -/** - * Set Checkbox - * - * Let's you set the selected value of a checkbox via the value in the POST array. - * If Form Validation is active it retrieves the info from the validation class - * - * @access public - * @param string - * @param string - * @param bool - * @return string - */ if ( ! function_exists('set_checkbox')) { - function set_checkbox($field = '', $value = '', $default = FALSE) - { - $OBJ =& _get_validation_object(); - - if ($OBJ === FALSE) - { - if ( ! isset($_POST[$field])) - { - if (count($_POST) === 0 AND $default == TRUE) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $_POST[$field]; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - return $OBJ->set_checkbox($field, $value, $default); - } + /** + * Set Checkbox + * + * Let's you set the selected value of a checkbox via the value in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string + * @param string + * @param bool + * @return string + */ + function set_checkbox($field, $value = '', $default = FALSE) + { + $CI =& get_instance(); + + if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) + { + return $CI->form_validation->set_checkbox($field, $value, $default); + } + + // Form inputs are always strings ... + $value = (string) $value; + $input = $CI->input->post($field, FALSE); + + if (is_array($input)) + { + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($input as &$v) + { + if ($value === $v) + { + return ' checked="checked"'; + } + } + + return ''; + } + + // Unchecked checkbox and radio inputs are not even submitted by browsers ... + if ($CI->input->method() === 'post') + { + return ($input === $value) ? ' checked="checked"' : ''; + } + + return ($default === TRUE) ? ' checked="checked"' : ''; + } } // ------------------------------------------------------------------------ -/** - * Set Radio - * - * Let's you set the selected value of a radio field via info in the POST array. - * If Form Validation is active it retrieves the info from the validation class - * - * @access public - * @param string - * @param string - * @param bool - * @return string - */ if ( ! function_exists('set_radio')) { - function set_radio($field = '', $value = '', $default = FALSE) - { - $OBJ =& _get_validation_object(); - - if ($OBJ === FALSE) - { - if ( ! isset($_POST[$field])) - { - if (count($_POST) === 0 AND $default == TRUE) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $_POST[$field]; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - return $OBJ->set_radio($field, $value, $default); - } + /** + * Set Radio + * + * Let's you set the selected value of a radio field via info in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string $field + * @param string $value + * @param bool $default + * @return string + */ + function set_radio($field, $value = '', $default = FALSE) + { + $CI =& get_instance(); + + if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) + { + return $CI->form_validation->set_radio($field, $value, $default); + } + + // Form inputs are always strings ... + $value = (string) $value; + $input = $CI->input->post($field, FALSE); + + if (is_array($input)) + { + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($input as &$v) + { + if ($value === $v) + { + return ' checked="checked"'; + } + } + + return ''; + } + + // Unchecked checkbox and radio inputs are not even submitted by browsers ... + if ($CI->input->method() === 'post') + { + return ($input === $value) ? ' checked="checked"' : ''; + } + + return ($default === TRUE) ? ' checked="checked"' : ''; + } } // ------------------------------------------------------------------------ -/** - * Form Error - * - * Returns the error for a specific form field. This is a helper for the - * form validation class. - * - * @access public - * @param string - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_error')) { - function form_error($field = '', $prefix = '', $suffix = '') - { - if (FALSE === ($OBJ =& _get_validation_object())) - { - return ''; - } - - return $OBJ->error($field, $prefix, $suffix); - } + /** + * Form Error + * + * Returns the error for a specific form field. This is a helper for the + * form validation class. + * + * @param string + * @param string + * @param string + * @return string + */ + function form_error($field = '', $prefix = '', $suffix = '') + { + if (FALSE === ($OBJ =& _get_validation_object())) + { + return ''; + } + + return $OBJ->error($field, $prefix, $suffix); + } } // ------------------------------------------------------------------------ -/** - * Validation Error String - * - * Returns all the errors associated with a form submission. This is a helper - * function for the form validation class. - * - * @access public - * @param string - * @param string - * @return string - */ if ( ! function_exists('validation_errors')) { - function validation_errors($prefix = '', $suffix = '') - { - if (FALSE === ($OBJ =& _get_validation_object())) - { - return ''; - } - - return $OBJ->error_string($prefix, $suffix); - } + /** + * Validation Error String + * + * Returns all the errors associated with a form submission. This is a helper + * function for the form validation class. + * + * @param string + * @param string + * @return string + */ + function validation_errors($prefix = '', $suffix = '') + { + if (FALSE === ($OBJ =& _get_validation_object())) + { + return ''; + } + + return $OBJ->error_string($prefix, $suffix); + } } // ------------------------------------------------------------------------ -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @return string - */ if ( ! function_exists('_parse_form_attributes')) { - function _parse_form_attributes($attributes, $default) - { - if (is_array($attributes)) - { - foreach ($default as $key => $val) - { - if (isset($attributes[$key])) - { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); - } - } - - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); - } - } - - $att = ''; - - foreach ($default as $key => $val) - { - if ($key == 'value') - { - $val = form_prep($val, $default['name']); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; - } + /** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @param array $attributes List of attributes + * @param array $default Default values + * @return string + */ + function _parse_form_attributes($attributes, $default) + { + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + + foreach ($default as $key => $val) + { + if ($key === 'value') + { + $val = html_escape($val); + } + elseif ($key === 'name' && ! strlen($default['name'])) + { + continue; + } + + $att .= $key.'="'.$val.'" '; + } + + return $att; + } } // ------------------------------------------------------------------------ -/** - * Attributes To String - * - * Helper function used by some of the form helpers - * - * @access private - * @param mixed - * @param bool - * @return string - */ if ( ! function_exists('_attributes_to_string')) { - function _attributes_to_string($attributes, $formtag = FALSE) - { - if (is_string($attributes) AND strlen($attributes) > 0) - { - if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) - { - $attributes .= ' method="post"'; - } - - if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) - { - $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; - } - - return ' '.$attributes; - } - - if (is_object($attributes) AND count($attributes) > 0) - { - $attributes = (array)$attributes; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - $atts = ''; - - if ( ! isset($attributes['method']) AND $formtag === TRUE) - { - $atts .= ' method="post"'; - } - - if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE) - { - $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"'; - } - - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - - return $atts; - } - } + /** + * Attributes To String + * + * Helper function used by some of the form helpers + * + * @param mixed + * @return string + */ + function _attributes_to_string($attributes) + { + if (empty($attributes)) + { + return ''; + } + + if (is_object($attributes)) + { + $attributes = (array) $attributes; + } + + if (is_array($attributes)) + { + $atts = ''; + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + + return $atts; + } + + if (is_string($attributes)) + { + return ' '.$attributes; + } + + return FALSE; + } } // ------------------------------------------------------------------------ -/** - * Validation Object - * - * Determines what the form validation class was instantiated as, fetches - * the object and returns it. - * - * @access private - * @return mixed - */ if ( ! function_exists('_get_validation_object')) { - function &_get_validation_object() - { - $CI =& get_instance(); - - // We set this as a variable since we're returning by reference. - $return = FALSE; - - if (FALSE !== ($object = $CI->load->is_loaded('form_validation'))) - { - if ( ! isset($CI->$object) OR ! is_object($CI->$object)) - { - return $return; - } - - return $CI->$object; - } - - return $return; - } + /** + * Validation Object + * + * Determines what the form validation class was instantiated as, fetches + * the object and returns it. + * + * @return mixed + */ + function &_get_validation_object() + { + $CI =& get_instance(); + + // We set this as a variable since we're returning by reference. + $return = FALSE; + + if (FALSE !== ($object = $CI->load->is_loaded('Form_validation'))) + { + if ( ! isset($CI->$object) OR ! is_object($CI->$object)) + { + return $return; + } + + return $CI->$object; + } + + return $return; + } } - - -/* End of file form_helper.php */ -/* Location: ./system/helpers/form_helper.php */ diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php old mode 100755 new mode 100644 index ecd07fc..76adcb2 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -1,437 +1,410 @@ -".$data.""; - } + /** + * Heading + * + * Generates an HTML heading tag. + * + * @param string content + * @param int heading level + * @param string + * @return string + */ + function heading($data = '', $h = '1', $attributes = '') + { + return ''.$data.''; + } } // ------------------------------------------------------------------------ -/** - * Unordered List - * - * Generates an HTML unordered list from an single or multi-dimensional array. - * - * @access public - * @param array - * @param mixed - * @return string - */ if ( ! function_exists('ul')) { - function ul($list, $attributes = '') - { - return _list('ul', $list, $attributes); - } + /** + * Unordered List + * + * Generates an HTML unordered list from an single or multi-dimensional array. + * + * @param array + * @param mixed + * @return string + */ + function ul($list, $attributes = '') + { + return _list('ul', $list, $attributes); + } } // ------------------------------------------------------------------------ -/** - * Ordered List - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @access public - * @param array - * @param mixed - * @return string - */ if ( ! function_exists('ol')) { - function ol($list, $attributes = '') - { - return _list('ol', $list, $attributes); - } + /** + * Ordered List + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @param array + * @param mixed + * @return string + */ + function ol($list, $attributes = '') + { + return _list('ol', $list, $attributes); + } } // ------------------------------------------------------------------------ -/** - * Generates the list - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @access private - * @param string - * @param mixed - * @param mixed - * @param integer - * @return string - */ if ( ! function_exists('_list')) { - function _list($type = 'ul', $list, $attributes = '', $depth = 0) - { - // If an array wasn't submitted there's nothing to do... - if ( ! is_array($list)) - { - return $list; - } - - // Set the indentation based on the depth - $out = str_repeat(" ", $depth); - - // Were any attributes submitted? If so generate a string - if (is_array($attributes)) - { - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' ' . $key . '="' . $val . '"'; - } - $attributes = $atts; - } - elseif (is_string($attributes) AND strlen($attributes) > 0) - { - $attributes = ' '. $attributes; - } - - // Write the opening list tag - $out .= "<".$type.$attributes.">\n"; - - // Cycle through the list elements. If an array is - // encountered we will recursively call _list() - - static $_last_list_item = ''; - foreach ($list as $key => $val) - { - $_last_list_item = $key; - - $out .= str_repeat(" ", $depth + 2); - $out .= "
  • "; - - if ( ! is_array($val)) - { - $out .= $val; - } - else - { - $out .= $_last_list_item."\n"; - $out .= _list($type, $val, '', $depth + 4); - $out .= str_repeat(" ", $depth + 2); - } - - $out .= "
  • \n"; - } - - // Set the indentation for the closing tag - $out .= str_repeat(" ", $depth); - - // Write the closing list tag - $out .= "\n"; - - return $out; - } + /** + * Generates the list + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @param string + * @param mixed + * @param mixed + * @param int + * @return string + */ + function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0) + { + // If an array wasn't submitted there's nothing to do... + if ( ! is_array($list)) + { + return $list; + } + + // Set the indentation based on the depth + $out = str_repeat(' ', $depth) + // Write the opening list tag + .'<'.$type._stringify_attributes($attributes).">\n"; + + + // Cycle through the list elements. If an array is + // encountered we will recursively call _list() + + static $_last_list_item = ''; + foreach ($list as $key => $val) + { + $_last_list_item = $key; + + $out .= str_repeat(' ', $depth + 2).'
  • '; + + if ( ! is_array($val)) + { + $out .= $val; + } + else + { + $out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2); + } + + $out .= "
  • \n"; + } + + // Set the indentation for the closing tag and apply it + return $out.str_repeat(' ', $depth).'\n"; + } } // ------------------------------------------------------------------------ -/** - * Generates HTML BR tags based on number supplied - * - * @access public - * @param integer - * @return string - */ -if ( ! function_exists('br')) -{ - function br($num = 1) - { - return str_repeat("
    ", $num); - } -} - -// ------------------------------------------------------------------------ - -/** - * Image - * - * Generates an element - * - * @access public - * @param mixed - * @return string - */ if ( ! function_exists('img')) { - function img($src = '', $index_page = FALSE) - { - if ( ! is_array($src) ) - { - $src = array('src' => $src); - } - - // If there is no alt attribute defined, set it to an empty string - if ( ! isset($src['alt'])) - { - $src['alt'] = ''; - } - - $img = '$v) - { - - if ($k == 'src' AND strpos($v, '://') === FALSE) - { - $CI =& get_instance(); - - if ($index_page === TRUE) - { - $img .= ' src="'.$CI->config->site_url($v).'"'; - } - else - { - $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"'; - } - } - else - { - $img .= " $k=\"$v\""; - } - } - - $img .= '/>'; - - return $img; - } + /** + * Image + * + * Generates an element + * + * @param mixed + * @param bool + * @param mixed + * @return string + */ + function img($src = '', $index_page = FALSE, $attributes = '') + { + if ( ! is_array($src) ) + { + $src = array('src' => $src); + } + + // If there is no alt attribute defined, set it to an empty string + if ( ! isset($src['alt'])) + { + $src['alt'] = ''; + } + + $img = ' $v) + { + if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?config->site_url($v).'"'; + } + else + { + $img .= ' src="'.get_instance()->config->base_url($v).'"'; + } + } + else + { + $img .= ' '.$k.'="'.$v.'"'; + } + } + + return $img._stringify_attributes($attributes).' />'; + } } // ------------------------------------------------------------------------ -/** - * Doctype - * - * Generates a page document type declaration - * - * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, - * html4-strict, html4-trans, and html4-frame. Values are saved in the - * doctypes config file. - * - * @access public - * @param string type The doctype to be generated - * @return string - */ if ( ! function_exists('doctype')) { - function doctype($type = 'xhtml1-strict') - { - global $_doctypes; - - if ( ! is_array($_doctypes)) - { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); - } - elseif (is_file(APPPATH.'config/doctypes.php')) - { - include(APPPATH.'config/doctypes.php'); - } - - if ( ! is_array($_doctypes)) - { - return FALSE; - } - } - - if (isset($_doctypes[$type])) - { - return $_doctypes[$type]; - } - else - { - return FALSE; - } - } + /** + * Doctype + * + * Generates a page document type declaration + * + * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans, + * xhtml-frame, html4-strict, html4-trans, and html4-frame. + * All values are saved in the doctypes config file. + * + * @param string type The doctype to be generated + * @return string + */ + function doctype($type = 'xhtml1-strict') + { + static $doctypes; + + if ( ! is_array($doctypes)) + { + if (file_exists(APPPATH.'config/doctypes.php')) + { + include(APPPATH.'config/doctypes.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); + } + + if (empty($_doctypes) OR ! is_array($_doctypes)) + { + $doctypes = array(); + return FALSE; + } + + $doctypes = $_doctypes; + } + + return isset($doctypes[$type]) ? $doctypes[$type] : FALSE; + } } // ------------------------------------------------------------------------ -/** - * Link - * - * Generates link to a CSS file - * - * @access public - * @param mixed stylesheet hrefs or an array - * @param string rel - * @param string type - * @param string title - * @param string media - * @param boolean should index_page be added to the css path - * @return string - */ if ( ! function_exists('link_tag')) { - function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) - { - $CI =& get_instance(); - - $link = '$v) - { - if ($k == 'href' AND strpos($v, '://') === FALSE) - { - if ($index_page === TRUE) - { - $link .= 'href="'.$CI->config->site_url($v).'" '; - } - else - { - $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; - } - } - else - { - $link .= "$k=\"$v\" "; - } - } - - $link .= "/>"; - } - else - { - if ( strpos($href, '://') !== FALSE) - { - $link .= 'href="'.$href.'" '; - } - elseif ($index_page === TRUE) - { - $link .= 'href="'.$CI->config->site_url($href).'" '; - } - else - { - $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; - } - - $link .= 'rel="'.$rel.'" type="'.$type.'" '; - - if ($media != '') - { - $link .= 'media="'.$media.'" '; - } - - if ($title != '') - { - $link .= 'title="'.$title.'" '; - } - - $link .= '/>'; - } - - - return $link; - } + /** + * Link + * + * Generates link to a CSS file + * + * @param mixed stylesheet hrefs or an array + * @param string rel + * @param string type + * @param string title + * @param string media + * @param bool should index_page be added to the css path + * @return string + */ + function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) + { + $CI =& get_instance(); + $link = ' $v) + { + if ($k === 'href' && ! preg_match('#^([a-z]+:)?//#i', $v)) + { + if ($index_page === TRUE) + { + $link .= 'href="'.$CI->config->site_url($v).'" '; + } + else + { + $link .= 'href="'.$CI->config->base_url($v).'" '; + } + } + else + { + $link .= $k.'="'.$v.'" '; + } + } + } + else + { + if (preg_match('#^([a-z]+:)?//#i', $href)) + { + $link .= 'href="'.$href.'" '; + } + elseif ($index_page === TRUE) + { + $link .= 'href="'.$CI->config->site_url($href).'" '; + } + else + { + $link .= 'href="'.$CI->config->base_url($href).'" '; + } + + $link .= 'rel="'.$rel.'" type="'.$type.'" '; + + if ($media !== '') + { + $link .= 'media="'.$media.'" '; + } + + if ($title !== '') + { + $link .= 'title="'.$title.'" '; + } + } + + return $link."/>\n"; + } } // ------------------------------------------------------------------------ -/** - * Generates meta tags from an array of key/values - * - * @access public - * @param array - * @return string - */ if ( ! function_exists('meta')) { - function meta($name = '', $content = '', $type = 'name', $newline = "\n") - { - // Since we allow the data to be passes as a string, a simple array - // or a multidimensional one, we need to do a little prepping. - if ( ! is_array($name)) - { - $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); - } - else - { - // Turn single array into multidimensional - if (isset($name['name'])) - { - $name = array($name); - } - } - - $str = ''; - foreach ($name as $meta) - { - $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; - $name = ( ! isset($meta['name'])) ? '' : $meta['name']; - $content = ( ! isset($meta['content'])) ? '' : $meta['content']; - $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline']; - - $str .= ''.$newline; - } - - return $str; - } + /** + * Generates meta tags from an array of key/values + * + * @param array + * @param string + * @param string + * @param string + * @return string + */ + function meta($name = '', $content = '', $type = 'name', $newline = "\n") + { + // Since we allow the data to be passes as a string, a simple array + // or a multidimensional one, we need to do a little prepping. + if ( ! is_array($name)) + { + $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); + } + elseif (isset($name['name'])) + { + // Turn single array into multidimensional + $name = array($name); + } + + $str = ''; + foreach ($name as $meta) + { + $type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name'; + $name = isset($meta['name']) ? $meta['name'] : ''; + $content = isset($meta['content']) ? $meta['content'] : ''; + $newline = isset($meta['newline']) ? $meta['newline'] : "\n"; + + $str .= ''.$newline; + } + + return $str; + } } // ------------------------------------------------------------------------ -/** - * Generates non-breaking space entities based on number supplied - * - * @access public - * @param integer - * @return string - */ -if ( ! function_exists('nbs')) +if ( ! function_exists('br')) { - function nbs($num = 1) - { - return str_repeat(" ", $num); - } + /** + * Generates HTML BR tags based on number supplied + * + * @deprecated 3.0.0 Use str_repeat() instead + * @param int $count Number of times to repeat the tag + * @return string + */ + function br($count = 1) + { + return str_repeat('
    ', $count); + } } +// ------------------------------------------------------------------------ -/* End of file html_helper.php */ -/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file +if ( ! function_exists('nbs')) +{ + /** + * Generates non-breaking space entities based on number supplied + * + * @deprecated 3.0.0 Use str_repeat() instead + * @param int + * @return string + */ + function nbs($num = 1) + { + return str_repeat(' ', $num); + } +} diff --git a/system/helpers/index.html b/system/helpers/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/helpers/index.html +++ b/system/helpers/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php old mode 100755 new mode 100644 index dd2c8db..1c14f4a --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,204 +1,287 @@ - '\1ix', - '/(vert|ind)ices$/' => '\1ex', - '/^(ox)en/' => '\1', - '/(alias)es$/' => '\1', - '/([octop|vir])i$/' => '\1us', - '/(cris|ax|test)es$/' => '\1is', - '/(shoe)s$/' => '\1', - '/(o)es$/' => '\1', - '/(bus|campus)es$/' => '\1', - '/([m|l])ice$/' => '\1ouse', - '/(x|ch|ss|sh)es$/' => '\1', - '/(m)ovies$/' => '\1\2ovie', - '/(s)eries$/' => '\1\2eries', - '/([^aeiouy]|qu)ies$/' => '\1y', - '/([lr])ves$/' => '\1f', - '/(tive)s$/' => '\1', - '/(hive)s$/' => '\1', - '/([^f])ves$/' => '\1fe', - '/(^analy)ses$/' => '\1sis', - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', - '/([ti])a$/' => '\1um', - '/(p)eople$/' => '\1\2erson', - '/(m)en$/' => '\1an', - '/(s)tatuses$/' => '\1\2tatus', - '/(c)hildren$/' => '\1\2hild', - '/(n)ews$/' => '\1\2ews', - '/([^u])s$/' => '\1', - ); - - foreach ($singular_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; - } + /** + * Singular + * + * Takes a plural word and makes it singular + * + * @param string $str Input string + * @return string + */ + function singular($str) + { + $result = strval($str); + + if ( ! word_is_countable($result)) + { + return $result; + } + + $singular_rules = array( + '/(matr)ices$/' => '\1ix', + '/(vert|ind)ices$/' => '\1ex', + '/^(ox)en/' => '\1', + '/(alias)es$/' => '\1', + '/([octop|vir])i$/' => '\1us', + '/(cris|ax|test)es$/' => '\1is', + '/(shoe)s$/' => '\1', + '/(o)es$/' => '\1', + '/(bus|campus)es$/' => '\1', + '/([m|l])ice$/' => '\1ouse', + '/(x|ch|ss|sh)es$/' => '\1', + '/(m)ovies$/' => '\1\2ovie', + '/(s)eries$/' => '\1\2eries', + '/([^aeiouy]|qu)ies$/' => '\1y', + '/([lr])ves$/' => '\1f', + '/(tive)s$/' => '\1', + '/(hive)s$/' => '\1', + '/([^f])ves$/' => '\1fe', + '/(^analy)ses$/' => '\1sis', + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', + '/([ti])a$/' => '\1um', + '/(p)eople$/' => '\1\2erson', + '/(m)en$/' => '\1an', + '/(s)tatuses$/' => '\1\2tatus', + '/(c)hildren$/' => '\1\2hild', + '/(n)ews$/' => '\1\2ews', + '/(quiz)zes$/' => '\1', + '/([^us])s$/' => '\1' + ); + + foreach ($singular_rules as $rule => $replacement) + { + if (preg_match($rule, $result)) + { + $result = preg_replace($rule, $replacement, $result); + break; + } + } + + return $result; + } } // -------------------------------------------------------------------- -/** - * Plural - * - * Takes a singular word and makes it plural - * - * @access public - * @param string - * @param bool - * @return str - */ if ( ! function_exists('plural')) { - function plural($str, $force = FALSE) - { - $result = strval($str); - - $plural_rules = array( - '/^(ox)$/' => '\1\2en', // ox - '/([m|l])ouse$/' => '\1ice', // mouse, louse - '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index - '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address - '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency - '/(hive)$/' => '\1s', // archive, hive - '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife - '/sis$/' => 'ses', // basis, diagnosis - '/([ti])um$/' => '\1a', // datum, medium - '/(p)erson$/' => '\1eople', // person, salesperson - '/(m)an$/' => '\1en', // man, woman, spokesman - '/(c)hild$/' => '\1hildren', // child - '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato - '/(bu|campu)s$/' => '\1\2ses', // bus, campus - '/(alias|status|virus)/' => '\1es', // alias - '/(octop)us$/' => '\1i', // octopus - '/(ax|cris|test)is$/' => '\1es', // axis, crisis - '/s$/' => 's', // no change (compatibility) - '/$/' => 's', - ); - - foreach ($plural_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; - } + /** + * Plural + * + * Takes a singular word and makes it plural + * + * @param string $str Input string + * @return string + */ + function plural($str) + { + $result = strval($str); + + if ( ! word_is_countable($result)) + { + return $result; + } + + $plural_rules = array( + '/(quiz)$/' => '\1zes', // quizzes + '/^(ox)$/' => '\1\2en', // ox + '/([m|l])ouse$/' => '\1ice', // mouse, louse + '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index + '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address + '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency + '/(hive)$/' => '\1s', // archive, hive + '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife + '/sis$/' => 'ses', // basis, diagnosis + '/([ti])um$/' => '\1a', // datum, medium + '/(p)erson$/' => '\1eople', // person, salesperson + '/(m)an$/' => '\1en', // man, woman, spokesman + '/(c)hild$/' => '\1hildren', // child + '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato + '/(bu|campu)s$/' => '\1\2ses', // bus, campus + '/(alias|status|virus)$/' => '\1es', // alias + '/(octop)us$/' => '\1i', // octopus + '/(ax|cris|test)is$/' => '\1es', // axis, crisis + '/s$/' => 's', // no change (compatibility) + '/$/' => 's', + ); + + foreach ($plural_rules as $rule => $replacement) + { + if (preg_match($rule, $result)) + { + $result = preg_replace($rule, $replacement, $result); + break; + } + } + + return $result; + } } // -------------------------------------------------------------------- -/** - * Camelize - * - * Takes multiple words separated by spaces or underscores and camelizes them - * - * @access public - * @param string - * @return str - */ if ( ! function_exists('camelize')) { - function camelize($str) - { - $str = 'x'.strtolower(trim($str)); - $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); - return substr(str_replace(' ', '', $str), 1); - } + /** + * Camelize + * + * Takes multiple words separated by spaces or underscores and camelizes them + * + * @param string $str Input string + * @return string + */ + function camelize($str) + { + return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1); + } } // -------------------------------------------------------------------- -/** - * Underscore - * - * Takes multiple words separated by spaces and underscores them - * - * @access public - * @param string - * @return str - */ if ( ! function_exists('underscore')) { - function underscore($str) - { - return preg_replace('/[\s]+/', '_', strtolower(trim($str))); - } + /** + * Underscore + * + * Takes multiple words separated by spaces and underscores them + * + * @param string $str Input string + * @return string + */ + function underscore($str) + { + return preg_replace('/[\s]+/', '_', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str))); + } } // -------------------------------------------------------------------- -/** - * Humanize - * - * Takes multiple words separated by underscores and changes them to spaces - * - * @access public - * @param string - * @return str - */ if ( ! function_exists('humanize')) { - function humanize($str) - { - return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); - } + /** + * Humanize + * + * Takes multiple words separated by the separator and changes them to spaces + * + * @param string $str Input string + * @param string $separator Input separator + * @return string + */ + function humanize($str, $separator = '_') + { + return ucwords(preg_replace('/['.preg_quote($separator).']+/', ' ', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str)))); + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('word_is_countable')) +{ + /** + * Checks if the given word has a plural version. + * + * @param string $word Word to check + * @return bool + */ + function word_is_countable($word) + { + return ! in_array( + strtolower($word), + array( + 'audio', + 'bison', + 'chassis', + 'compensation', + 'coreopsis', + 'data', + 'deer', + 'education', + 'emoji', + 'equipment', + 'fish', + 'furniture', + 'gold', + 'information', + 'knowledge', + 'love', + 'rain', + 'money', + 'moose', + 'nutrition', + 'offspring', + 'plankton', + 'pokemon', + 'police', + 'rice', + 'series', + 'sheep', + 'species', + 'swine', + 'traffic', + 'wheat' + ) + ); + } } +// -------------------------------------------------------------------- -/* End of file inflector_helper.php */ -/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file +if ( ! function_exists('is_countable')) +{ + function is_countable($word) + { + trigger_error('is_countable() is a native PHP function since version 7.3.0; use word_is_countable() instead', E_USER_WARNING); + return word_is_countable($word); + } +} diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php old mode 100755 new mode 100644 index 6056610..2cefcc2 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -1,59 +1,75 @@ -lang->line($line); + /** + * Lang + * + * Fetches a language variable and optionally outputs a form label + * + * @param string $line The language line + * @param string $for The "for" value (id of the form element) + * @param array $attributes Any additional HTML attributes + * @return string + */ + function lang($line, $for = '', $attributes = array()) + { + $line = get_instance()->lang->line($line); - if ($id != '') - { - $line = '"; - } + if ($for !== '') + { + $line = ''; + } - return $line; - } + return $line; + } } - -// ------------------------------------------------------------------------ -/* End of file language_helper.php */ -/* Location: ./system/helpers/language_helper.php */ \ No newline at end of file diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php old mode 100755 new mode 100644 index 3dc08e3..15a53ff --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -1,77 +1,94 @@ -lang->load('number'); + /** + * Formats a numbers as bytes, based on size, and adds the appropriate suffix + * + * @param mixed will be cast as int + * @param int + * @return string + */ + function byte_format($num, $precision = 1) + { + $CI =& get_instance(); + $CI->lang->load('number'); - if ($num >= 1000000000000) - { - $num = round($num / 1099511627776, $precision); - $unit = $CI->lang->line('terabyte_abbr'); - } - elseif ($num >= 1000000000) - { - $num = round($num / 1073741824, $precision); - $unit = $CI->lang->line('gigabyte_abbr'); - } - elseif ($num >= 1000000) - { - $num = round($num / 1048576, $precision); - $unit = $CI->lang->line('megabyte_abbr'); - } - elseif ($num >= 1000) - { - $num = round($num / 1024, $precision); - $unit = $CI->lang->line('kilobyte_abbr'); - } - else - { - $unit = $CI->lang->line('bytes'); - return number_format($num).' '.$unit; - } + if ($num >= 1000000000000) + { + $num = round($num / 1099511627776, $precision); + $unit = $CI->lang->line('terabyte_abbr'); + } + elseif ($num >= 1000000000) + { + $num = round($num / 1073741824, $precision); + $unit = $CI->lang->line('gigabyte_abbr'); + } + elseif ($num >= 1000000) + { + $num = round($num / 1048576, $precision); + $unit = $CI->lang->line('megabyte_abbr'); + } + elseif ($num >= 1000) + { + $num = round($num / 1024, $precision); + $unit = $CI->lang->line('kilobyte_abbr'); + } + else + { + $unit = $CI->lang->line('bytes'); + return number_format($num).' '.$unit; + } - return number_format($num, $precision).' '.$unit; - } + return number_format($num, $precision).' '.$unit; + } } - - -/* End of file number_helper.php */ -/* Location: ./system/helpers/number_helper.php */ \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php old mode 100755 new mode 100644 index 32eb9bf..543e4c0 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -1,73 +1,82 @@ -security->xss_clean($str, $is_image); - } + /** + * XSS Filtering + * + * @param string + * @param bool whether or not the content is an image file + * @return string + */ + function xss_clean($str, $is_image = FALSE) + { + return get_instance()->security->xss_clean($str, $is_image); + } } // ------------------------------------------------------------------------ -/** - * Sanitize Filename - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('sanitize_filename')) { - function sanitize_filename($filename) - { - $CI =& get_instance(); - return $CI->security->sanitize_filename($filename); - } + /** + * Sanitize Filename + * + * @param string + * @return string + */ + function sanitize_filename($filename) + { + return get_instance()->security->sanitize_filename($filename); + } } // -------------------------------------------------------------------- -/** - * Hash encode a string - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('do_hash')) { - function do_hash($str, $type = 'sha1') - { - if ($type == 'sha1') - { - return sha1($str); - } - else - { - return md5($str); - } - } + /** + * Hash encode a string + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 Use PHP's native hash() instead. + * @param string $str + * @param string $type = 'sha1' + * @return string + */ + function do_hash($str, $type = 'sha1') + { + if ( ! in_array(strtolower($type), hash_algos())) + { + $type = 'md5'; + } + + return hash($type, $str); + } } // ------------------------------------------------------------------------ -/** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('strip_image_tags')) { - function strip_image_tags($str) - { - $str = preg_replace("##", "\\1", $str); - $str = preg_replace("##", "\\1", $str); - - return $str; - } + /** + * Strip Image Tags + * + * @param string + * @return string + */ + function strip_image_tags($str) + { + return get_instance()->security->strip_image_tags($str); + } } // ------------------------------------------------------------------------ -/** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('encode_php_tags')) { - function encode_php_tags($str) - { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } + /** + * Convert PHP tags to entities + * + * @param string + * @return string + */ + function encode_php_tags($str) + { + return str_replace(array(''), array('<?', '?>'), $str); + } } - - -/* End of file security_helper.php */ -/* Location: ./system/helpers/security_helper.php */ \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php old mode 100755 new mode 100644 index acacfa2..321e59c --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,282 +1,255 @@ -field_id pairs - * @param string field_id if alias name was passed in - * @return array - */ if ( ! function_exists('smiley_js')) { - function smiley_js($alias = '', $field_id = '', $inline = TRUE) - { - static $do_setup = TRUE; - - $r = ''; - - if ($alias != '' && ! is_array($alias)) - { - $alias = array($alias => $field_id); - } - - if ($do_setup === TRUE) - { - $do_setup = FALSE; - - $m = array(); - - if (is_array($alias)) - { - foreach ($alias as $name => $id) - { - $m[] = '"'.$name.'" : "'.$id.'"'; - } - } - - $m = '{'.implode(',', $m).'}'; - - $r .= <<field_id pairs + * @param string field_id if alias name was passed in + * @param bool + * @return array + */ + function smiley_js($alias = '', $field_id = '', $inline = TRUE) + { + static $do_setup = TRUE; + $r = ''; + + if ($alias !== '' && ! is_array($alias)) + { + $alias = array($alias => $field_id); + } + + if ($do_setup === TRUE) + { + $do_setup = FALSE; + $m = array(); + + if (is_array($alias)) + { + foreach ($alias as $name => $id) + { + $m[] = '"'.$name.'" : "'.$id.'"'; + } + } + + $m = '{'.implode(',', $m).'}'; + + $r .= << $id) - { - $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; - } - } - } - - if ($inline) - { - return ''; - } - else - { - return $r; - } - } + } + elseif (is_array($alias)) + { + foreach ($alias as $name => $id) + { + $r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n"; + } + } + + return ($inline) + ? '' + : $r; + } } // ------------------------------------------------------------------------ -/** - * Get Clickable Smileys - * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. - * - * @access public - * @param string the URL to the folder containing the smiley images - * @return array - */ if ( ! function_exists('get_clickable_smileys')) { - function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) - { - // For backward compatibility with js_insert_smiley - - if (is_array($alias)) - { - $smileys = $alias; - } - - if ( ! is_array($smileys)) - { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $smileys; - } - } - - // 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; - } + /** + * 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; + } } // ------------------------------------------------------------------------ -/** - * Parse Smileys - * - * Takes a string as input and swaps any contained smileys for the actual image - * - * @access public - * @param string the text to be parsed - * @param string the URL to the folder containing the smiley images - * @return string - */ if ( ! function_exists('parse_smileys')) { - function parse_smileys($str = '', $image_url = '', $smileys = NULL) - { - if ($image_url == '') - { - return $str; - } - - if ( ! is_array($smileys)) - { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $str; - } - } - - // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); - - foreach ($smileys as $key => $val) - { - $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); - } - - return $str; - } + /** + * 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; + } } // ------------------------------------------------------------------------ -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @access private - * @return mixed - */ if ( ! function_exists('_get_smiley_array')) { - function _get_smiley_array() - { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); - } - elseif (file_exists(APPPATH.'config/smileys.php')) - { - include(APPPATH.'config/smileys.php'); - } - - if (isset($smileys) AND is_array($smileys)) - { - return $smileys; - } - - return FALSE; - } -} - -// ------------------------------------------------------------------------ - -/** - * JS Insert Smiley - * - * Generates the javascript function needed to insert smileys into a form field - * - * DEPRECATED as of version 1.7.2, use smiley_js instead - * - * @access public - * @param string form name - * @param string field name - * @return string - */ -if ( ! function_exists('js_insert_smiley')) -{ - function js_insert_smiley($form_name = '', $form_field = '') - { - return << - function insert_smiley(smiley) - { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - -EOF; - } + /** + * 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; + } } - - -/* End of file smiley_helper.php */ -/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php old mode 100755 new mode 100644 index 0b680b9..c7dd969 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,308 +1,304 @@ - $val) - { - $str[$key] = strip_slashes($val); - } - } - else - { - $str = stripslashes($str); - } - - return $str; - } + /** + * Strip Slashes + * + * Removes slashes contained in a string or in an array + * + * @param mixed string or array + * @return mixed string or array + */ + function strip_slashes($str) + { + if ( ! is_array($str)) + { + return stripslashes($str); + } + + foreach ($str as $key => $val) + { + $str[$key] = strip_slashes($val); + } + + return $str; + } } // ------------------------------------------------------------------------ -/** - * Strip Quotes - * - * Removes single and double quotes from a string - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('strip_quotes')) { - function strip_quotes($str) - { - return str_replace(array('"', "'"), '', $str); - } + /** + * Strip Quotes + * + * Removes single and double quotes from a string + * + * @param string + * @return string + */ + function strip_quotes($str) + { + return str_replace(array('"', "'"), '', $str); + } } // ------------------------------------------------------------------------ -/** - * Quotes to Entities - * - * Converts single and double quotes to entities - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('quotes_to_entities')) { - function quotes_to_entities($str) - { - return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); - } + /** + * Quotes to Entities + * + * Converts single and double quotes to entities + * + * @param string + * @return string + */ + function quotes_to_entities($str) + { + return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); + } } // ------------------------------------------------------------------------ -/** - * Reduce Double Slashes - * - * Converts double slashes in a string to a single slash, - * except those found in http:// - * - * http://www.some-site.com//index.php - * - * becomes: - * - * http://www.some-site.com/index.php - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('reduce_double_slashes')) { - function reduce_double_slashes($str) - { - return preg_replace("#(^|[^:])//+#", "\\1/", $str); - } + /** + * Reduce Double Slashes + * + * Converts double slashes in a string to a single slash, + * except those found in http:// + * + * http://www.some-site.com//index.php + * + * becomes: + * + * http://www.some-site.com/index.php + * + * @param string + * @return string + */ + function reduce_double_slashes($str) + { + return preg_replace('#(^|[^:])//+#', '\\1/', $str); + } } // ------------------------------------------------------------------------ -/** - * Reduce Multiples - * - * Reduces multiple instances of a particular character. Example: - * - * Fred, Bill,, Joe, Jimmy - * - * becomes: - * - * Fred, Bill, Joe, Jimmy - * - * @access public - * @param string - * @param string the character you wish to reduce - * @param bool TRUE/FALSE - whether to trim the character from the beginning/end - * @return string - */ if ( ! function_exists('reduce_multiples')) { - function reduce_multiples($str, $character = ',', $trim = FALSE) - { - $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); - - if ($trim === TRUE) - { - $str = trim($str, $character); - } - - return $str; - } + /** + * Reduce Multiples + * + * Reduces multiple instances of a particular character. Example: + * + * Fred, Bill,, Joe, Jimmy + * + * becomes: + * + * Fred, Bill, Joe, Jimmy + * + * @param string + * @param string the character you wish to reduce + * @param bool TRUE/FALSE - whether to trim the character from the beginning/end + * @return string + */ + function reduce_multiples($str, $character = ',', $trim = FALSE) + { + $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); + return ($trim === TRUE) ? trim($str, $character) : $str; + } } // ------------------------------------------------------------------------ -/** - * Create a Random String - * - * Useful for generating passwords or hashes. - * - * @access public - * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 - * @param integer number of characters - * @return string - */ if ( ! function_exists('random_string')) { - function random_string($type = 'alnum', $len = 8) - { - switch($type) - { - case 'basic' : return mt_rand(); - break; - case 'alnum' : - case 'numeric' : - case 'nozero' : - case 'alpha' : - - switch ($type) - { - case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - break; - case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - break; - case 'numeric' : $pool = '0123456789'; - break; - case 'nozero' : $pool = '123456789'; - break; - } - - $str = ''; - for ($i=0; $i < $len; $i++) - { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); - } - return $str; - break; - case 'unique' : - case 'md5' : - - return md5(uniqid(mt_rand())); - break; - case 'encrypt' : - case 'sha1' : - - $CI =& get_instance(); - $CI->load->helper('security'); - - return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); - break; - } - } + /** + * Create a "Random" String + * + * @param string type of random string. basic, alpha, alnum, numeric, nozero, unique, md5, encrypt and sha1 + * @param int number of characters + * @return string + */ + function random_string($type = 'alnum', $len = 8) + { + switch ($type) + { + case 'basic': + return mt_rand(); + case 'alnum': + case 'numeric': + case 'nozero': + case 'alpha': + switch ($type) + { + case 'alpha': + $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; + case 'alnum': + $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; + case 'numeric': + $pool = '0123456789'; + break; + case 'nozero': + $pool = '123456789'; + break; + } + return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len); + case 'unique': // todo: remove in 3.1+ + case 'md5': + return md5(uniqid(mt_rand())); + case 'encrypt': // todo: remove in 3.1+ + case 'sha1': + return sha1(uniqid(mt_rand(), TRUE)); + } + } } // ------------------------------------------------------------------------ -/** - * Add's _1 to a string or increment the ending number to allow _2, _3, etc - * - * @param string $str required - * @param string $separator What should the duplicate number be appended with - * @param string $first Which number should be used for the first dupe increment - * @return string - */ -function increment_string($str, $separator = '_', $first = 1) +if ( ! function_exists('increment_string')) { - preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); - - return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + /** + * Add's _1 to a string or increment the ending number to allow _2, _3, etc + * + * @param string required + * @param string What should the duplicate number be appended with + * @param string Which number should be used for the first dupe increment + * @return string + */ + function increment_string($str, $separator = '_', $first = 1) + { + preg_match('/(.+)'.preg_quote($separator, '/').'([0-9]+)$/', $str, $match); + return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + } } // ------------------------------------------------------------------------ -/** - * Alternator - * - * Allows strings to be alternated. See docs... - * - * @access public - * @param string (as many parameters as needed) - * @return string - */ if ( ! function_exists('alternator')) { - function alternator() - { - static $i; - - if (func_num_args() == 0) - { - $i = 0; - return ''; - } - $args = func_get_args(); - return $args[($i++ % count($args))]; - } + /** + * Alternator + * + * Allows strings to be alternated. See docs... + * + * @param string (as many parameters as needed) + * @return string + */ + function alternator() + { + static $i; + + if (func_num_args() === 0) + { + $i = 0; + return ''; + } + + $args = func_get_args(); + return $args[($i++ % count($args))]; + } } // ------------------------------------------------------------------------ -/** - * Repeater function - * - * @access public - * @param string - * @param integer number of repeats - * @return string - */ if ( ! function_exists('repeater')) { - function repeater($data, $num = 1) - { - return (($num > 0) ? str_repeat($data, $num) : ''); - } + /** + * 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) : ''; + } } - - -/* End of file string_helper.php */ -/* Location: ./system/helpers/string_helper.php */ \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php old mode 100755 new mode 100644 index 55af95d..e1c5e24 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,527 +1,567 @@ -= $n) - { - $out = trim($out); - return (strlen($out) == strlen($str)) ? $out : $out.$end_char; - } - } - } + /** + * Character Limiter + * + * Limits the string based on the character count. Preserves complete words + * so the character count may not be exactly as specified. + * + * @param string + * @param int + * @param string the end character. Usually an ellipsis + * @return string + */ + function character_limiter($str, $n = 500, $end_char = '…') + { + if (mb_strlen($str) < $n) + { + return $str; + } + + // a bit complicated, but faster than preg_replace with \s+ + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\v", "\f"), ' ', $str)); + + if (mb_strlen($str) <= $n) + { + return $str; + } + + $out = ''; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + + if (mb_strlen($out) >= $n) + { + $out = trim($out); + return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char; + } + } + } } // ------------------------------------------------------------------------ -/** - * High ASCII to Entities - * - * Converts High ascii text and MS Word special characters to character entities - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('ascii_to_entities')) { - function ascii_to_entities($str) - { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - /* - If the $temp array has a value but we have moved on, then it seems only - fair that we output that entity and restart $temp before continuing. -Paul - */ - if (count($temp) == 1) - { - $out .= '&#'.array_shift($temp).';'; - $count = 1; - } - - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; - } + /** + * High ASCII to Entities + * + * Converts high ASCII text and MS Word special characters to character entities + * + * @param string $str + * @return string + */ + function ascii_to_entities($str) + { + $out = ''; + $length = defined('MB_OVERLOAD_STRING') + ? mb_strlen($str, '8bit') - 1 + : strlen($str) - 1; + for ($i = 0, $count = 1, $temp = array(); $i <= $length; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + /* + If the $temp array has a value but we have moved on, then it seems only + fair that we output that entity and restart $temp before continuing. -Paul + */ + if (count($temp) === 1) + { + $out .= '&#'.array_shift($temp).';'; + $count = 1; + } + + $out .= $str[$i]; + } + else + { + if (count($temp) === 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) === $count) + { + $number = ($count === 3) + ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) + : (($temp[0] % 32) * 64) + ($temp[1] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + // If this is the last iteration, just output whatever we have + elseif ($i === $length) + { + $out .= '&#'.implode(';', $temp).';'; + } + } + } + + return $out; + } } // ------------------------------------------------------------------------ -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @access public - * @param string - * @param bool - * @return string - */ if ( ! function_exists('entities_to_ascii')) { - function entities_to_ascii($str, $all = TRUE) - { - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; - } + /** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @param string + * @param bool + * @return string + */ + function entities_to_ascii($str, $all = TRUE) + { + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches[0]); $i < $s; $i++) + { + $digits = $matches[1][$i]; + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)).chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)) + .chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)) + .chr(128 + ($digits % 64)); + } + + $str = str_replace($matches[0][$i], $out, $str); + } + } + + if ($all) + { + return str_replace( + array('&', '<', '>', '"', ''', '-'), + array('&', '<', '>', '"', "'", '-'), + $str + ); + } + + return $str; + } } // ------------------------------------------------------------------------ -/** - * Word Censoring Function - * - * Supply a string and an array of disallowed words and any - * matched words will be converted to #### or to the replacement - * word you've submitted. - * - * @access public - * @param string the text string - * @param string the array of censoered words - * @param string the optional replacement value - * @return string - */ if ( ! function_exists('word_censor')) { - function word_censor($str, $censored, $replacement = '') - { - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - - // \w, \b and a few others do not match on a unicode character - // set for performance reasons. As a result words like über - // will not match on a word boundary. Instead, we'll assume that - // a bad word will be bookeneded by any of these characters. - $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; - - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str); - } - else - { - $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str); - } - } - - return trim($str); - } + /** + * Word Censoring Function + * + * Supply a string and an array of disallowed words and any + * matched words will be converted to #### or to the replacement + * word you've submitted. + * + * @param string the text string + * @param string the array of censored words + * @param string the optional replacement value + * @return string + */ + function word_censor($str, $censored, $replacement = '') + { + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + + // \w, \b and a few others do not match on a unicode character + // set for performance reasons. As a result words like über + // will not match on a word boundary. Instead, we'll assume that + // a bad word will be bookeneded by any of these characters. + $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; + + foreach ($censored as $badword) + { + $badword = str_replace('\*', '\w*?', preg_quote($badword, '/')); + if ($replacement !== '') + { + $str = preg_replace( + "/({$delim})(".$badword.")({$delim})/i", + "\\1{$replacement}\\3", + $str + ); + } + elseif (preg_match_all("/{$delim}(".$badword."){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) + { + $matches = $matches[1]; + for ($i = count($matches) - 1; $i >= 0; $i--) + { + $length = strlen($matches[$i][0]); + $str = substr_replace( + $str, + str_repeat('#', $length), + $matches[$i][1], + $length + ); + } + } + } + + return trim($str); + } } // ------------------------------------------------------------------------ -/** - * Code Highlighter - * - * Colorizes code strings - * - * @access public - * @param string the text string - * @return string - */ if ( ! function_exists('highlight_code')) { - function highlight_code($str) - { - // The highlight string function encodes and highlights - // brackets so we need them to start raw - $str = str_replace(array('<', '>'), array('<', '>'), $str); - - // Replace any existing PHP tags to temporary markers so they don't accidentally - // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('', '<%', '%>', '\\', ''), - array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); - - // The highlight_string function requires that the text be surrounded - // by PHP tags, which we will remove later - $str = ''; // <\?php( | )/i', '', $str); - $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); - $str = preg_replace('/<\/span>/i', '', $str); - - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), - array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - - return $str; - } + /** + * Code Highlighter + * + * Colorizes code strings + * + * @param string the text string + * @return string + */ + function highlight_code($str) + { + /* The highlight string function encodes and highlights + * brackets so we need them to start raw. + * + * Also replace any existing PHP tags to temporary markers + * so they don't accidentally break the string out of PHP, + * and thus, thwart the highlighting. + */ + $str = str_replace( + array('<', '>', '', '<%', '%>', '\\', ''), + array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + $str + ); + + // The highlight_string function requires that the text be surrounded + // by PHP tags, which we will remove later + $str = highlight_string('', TRUE); + + // Remove our artificially added PHP, and the syntax highlighting that came with it + $str = preg_replace( + array( + '/<\?php( | )/i', + '/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', + '/<\/span>/i' + ), + array( + '', + "$1\n\n", + '' + ), + $str + ); + + // Replace our markers back to PHP tags. + return str_replace( + array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + array('<?', '?>', '<%', '%>', '\\', '</script>'), + $str + ); + } } // ------------------------------------------------------------------------ -/** - * Phrase Highlighter - * - * Highlights a phrase within a text string - * - * @access public - * @param string the text string - * @param string the phrase you'd like to highlight - * @param string the openging tag to precede the phrase with - * @param string the closing tag to end the phrase with - * @return string - */ if ( ! function_exists('highlight_phrase')) { - function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') - { - if ($str == '') - { - return ''; - } - - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); - } - - return $str; - } + /** + * Phrase Highlighter + * + * Highlights a phrase within a text string + * + * @param string $str the text string + * @param string $phrase the phrase you'd like to highlight + * @param string $tag_open the openging tag to precede the phrase with + * @param string $tag_close the closing tag to end the phrase with + * @return string + */ + function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') + { + return ($str !== '' && $phrase !== '') + ? preg_replace('/('.preg_quote($phrase, '/').')/i'.(UTF8_ENABLED ? 'u' : ''), $tag_open.'\\1'.$tag_close, $str) + : $str; + } } // ------------------------------------------------------------------------ -/** - * Convert Accented Foreign Characters to ASCII - * - * @access public - * @param string the text string - * @return string - */ if ( ! function_exists('convert_accented_characters')) { - function convert_accented_characters($str) - { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); - } - elseif (is_file(APPPATH.'config/foreign_chars.php')) - { - include(APPPATH.'config/foreign_chars.php'); - } - - if ( ! isset($foreign_characters)) - { - return $str; - } - - return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str); - } + /** + * Convert Accented Foreign Characters to ASCII + * + * @param string $str Input string + * @return string + */ + function convert_accented_characters($str) + { + static $array_from, $array_to; + + if ( ! is_array($array_from)) + { + if (file_exists(APPPATH.'config/foreign_chars.php')) + { + include(APPPATH.'config/foreign_chars.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); + } + + if (empty($foreign_characters) OR ! is_array($foreign_characters)) + { + $array_from = array(); + $array_to = array(); + + return $str; + } + + $array_from = array_keys($foreign_characters); + $array_to = array_values($foreign_characters); + } + + return preg_replace($array_from, $array_to, $str); + } } // ------------------------------------------------------------------------ -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @access public - * @param string the text string - * @param integer the number of characters to wrap at - * @return string - */ if ( ! function_exists('word_wrap')) { - function word_wrap($str, $charlim = '76') - { - // Se the character limit - if ( ! is_numeric($charlim)) - $charlim = 76; - - // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); - - // Standardize newlines - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $str); - } - - // If the current word is surrounded by {unwrap} tags we'll - // strip the entire chunk and replace it with a marker. - $unwrap = array(); - if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); - } - } - - // Use PHP's native function to do the initial wordwrap. - // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. - $str = wordwrap($str, $charlim, "\n", FALSE); - - // Split the string into individual lines of text and cycle through them - $output = ""; - foreach (explode("\n", $str) as $line) - { - // Is the line within the allowed character count? - // If so we'll join it to the output and continue - if (strlen($line) <= $charlim) - { - $output .= $line."\n"; - continue; - } - - $temp = ''; - while ((strlen($line)) > $charlim) - { - // If the over-length word is a URL we won't wrap it - if (preg_match("!\[url.+\]|://|wwww.!", $line)) - { - break; - } - - // Trim the word down - $temp .= substr($line, 0, $charlim-1); - $line = substr($line, $charlim-1); - } - - // If $temp contains data it means we had to split up an over-length - // word into smaller chunks so we'll add it back to our current line - if ($temp != '') - { - $output .= $temp."\n".$line; - } - else - { - $output .= $line; - } - - $output .= "\n"; - } - - // Put our markers back - if (count($unwrap) > 0) - { - foreach ($unwrap as $key => $val) - { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); - } - } - - // Remove the unwrap tags - $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - - return $output; - } + /** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. + * + * @param string $str the text string + * @param int $charlim = 76 the number of characters to wrap at + * @return string + */ + function word_wrap($str, $charlim = 76) + { + // Set the character limit + is_numeric($charlim) OR $charlim = 76; + + // Reduce multiple spaces + $str = preg_replace('| +|', ' ', $str); + + // Standardize newlines + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $str); + } + + // If the current word is surrounded by {unwrap} tags we'll + // strip the entire chunk and replace it with a marker. + $unwrap = array(); + if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) + { + for ($i = 0, $c = count($matches[0]); $i < $c; $i++) + { + $unwrap[] = $matches[1][$i]; + $str = str_replace($matches[0][$i], '{{unwrapped'.$i.'}}', $str); + } + } + + // Use PHP's native function to do the initial wordwrap. + // We set the cut flag to FALSE so that any individual words that are + // too long get left alone. In the next step we'll deal with them. + $str = wordwrap($str, $charlim, "\n", FALSE); + + // Split the string into individual lines of text and cycle through them + $output = ''; + foreach (explode("\n", $str) as $line) + { + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (mb_strlen($line) <= $charlim) + { + $output .= $line."\n"; + continue; + } + + $temp = ''; + while (mb_strlen($line) > $charlim) + { + // If the over-length word is a URL we won't wrap it + if (preg_match('!\[url.+\]|://|www\.!', $line)) + { + break; + } + + // Trim the word down + $temp .= mb_substr($line, 0, $charlim - 1); + $line = mb_substr($line, $charlim - 1); + } + + // If $temp contains data it means we had to split up an over-length + // word into smaller chunks so we'll add it back to our current line + if ($temp !== '') + { + $output .= $temp."\n".$line."\n"; + } + else + { + $output .= $line."\n"; + } + } + + // Put our markers back + if (count($unwrap) > 0) + { + foreach ($unwrap as $key => $val) + { + $output = str_replace('{{unwrapped'.$key.'}}', $val, $output); + } + } + + return $output; + } } // ------------------------------------------------------------------------ -/** - * Ellipsize String - * - * This function will strip tags from a string, split it at its max_length and ellipsize - * - * @param string string to ellipsize - * @param integer max length of string - * @param mixed int (1|0) or float, .5, .2, etc for position to split - * @param string ellipsis ; Default '...' - * @return string ellipsized string - */ if ( ! function_exists('ellipsize')) { - function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') - { - // Strip tags - $str = trim(strip_tags($str)); - - // Is the string long enough to ellipsize? - if (strlen($str) <= $max_length) - { - return $str; - } - - $beg = substr($str, 0, floor($max_length * $position)); - - $position = ($position > 1) ? 1 : $position; - - if ($position === 1) - { - $end = substr($str, 0, -($max_length - strlen($beg))); - } - else - { - $end = substr($str, -($max_length - strlen($beg))); - } - - return $beg.$ellipsis.$end; - } + /** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param int max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string + */ + function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') + { + // Strip tags + $str = trim(strip_tags($str)); + + // Is the string long enough to ellipsize? + if (mb_strlen($str) <= $max_length) + { + return $str; + } + + $beg = mb_substr($str, 0, floor($max_length * $position)); + $position = ($position > 1) ? 1 : $position; + + if ($position === 1) + { + $end = mb_substr($str, 0, -($max_length - mb_strlen($beg))); + } + else + { + $end = mb_substr($str, -($max_length - mb_strlen($beg))); + } + + return $beg.$ellipsis.$end; + } } - -/* End of file text_helper.php */ -/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php old mode 100755 new mode 100644 index c15a8bb..d308a57 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,94 +1,104 @@ -load->library('typography'); - - return $CI->typography->nl2br_except_pre($str); - } + /** + * Convert newlines to HTML line breaks except within PRE tags + * + * @param string + * @return string + */ + function nl2br_except_pre($str) + { + $CI =& get_instance(); + $CI->load->library('typography'); + return $CI->typography->nl2br_except_pre($str); + } } // ------------------------------------------------------------------------ -/** - * Auto Typography Wrapper Function - * - * - * @access public - * @param string - * @param bool whether to allow javascript event handlers - * @param bool whether to reduce multiple instances of double newlines to two - * @return string - */ if ( ! function_exists('auto_typography')) { - function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) - { - $CI =& get_instance(); - $CI->load->library('typography'); - return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); - } + /** + * Auto Typography Wrapper Function + * + * @param string $str + * @param bool $reduce_linebreaks = FALSE whether to reduce multiple instances of double newlines to two + * @return string + */ + function auto_typography($str, $reduce_linebreaks = FALSE) + { + $CI =& get_instance(); + $CI->load->library('typography'); + return $CI->typography->auto_typography($str, $reduce_linebreaks); + } } - // -------------------------------------------------------------------- -/** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('entity_decode')) { - function entity_decode($str, $charset='UTF-8') - { - global $SEC; - return $SEC->entity_decode($str, $charset); - } + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * @param string + * @param string + * @return string + */ + function entity_decode($str, $charset = NULL) + { + return get_instance()->security->entity_decode($str, $charset); + } } - -/* End of file typography_helper.php */ -/* Location: ./system/helpers/typography_helper.php */ \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php old mode 100755 new mode 100644 index faf177a..bebfd25 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,595 +1,569 @@ -config->site_url($uri); - } + /** + * Site URL + * + * Create a local URL based on your basepath. Segments can be passed via the + * first parameter either as a string or an array. + * + * @param string $uri + * @param string $protocol + * @return string + */ + function site_url($uri = '', $protocol = NULL) + { + return get_instance()->config->site_url($uri, $protocol); + } } // ------------------------------------------------------------------------ -/** - * Base URL - * - * Create a local URL based on your basepath. - * Segments can be passed in as a string or an array, same as site_url - * or a URL to a file can be passed in, e.g. to an image file. - * - * @access public - * @param string - * @return string - */ if ( ! function_exists('base_url')) { - function base_url($uri = '') - { - $CI =& get_instance(); - return $CI->config->base_url($uri); - } + /** + * Base URL + * + * Create a local URL based on your basepath. + * Segments can be passed in as a string or an array, same as site_url + * or a URL to a file can be passed in, e.g. to an image file. + * + * @param string $uri + * @param string $protocol + * @return string + */ + function base_url($uri = '', $protocol = NULL) + { + return get_instance()->config->base_url($uri, $protocol); + } } // ------------------------------------------------------------------------ -/** - * Current URL - * - * Returns the full URL (including segments) of the page where this - * function is placed - * - * @access public - * @return string - */ if ( ! function_exists('current_url')) { - function current_url() - { - $CI =& get_instance(); - return $CI->config->site_url($CI->uri->uri_string()); - } + /** + * Current URL + * + * Returns the full URL (including segments) of the page where this + * function is placed + * + * @return string + */ + function current_url() + { + $CI =& get_instance(); + return $CI->config->site_url($CI->uri->uri_string()); + } } // ------------------------------------------------------------------------ -/** - * URL String - * - * Returns the URI segments. - * - * @access public - * @return string - */ + if ( ! function_exists('uri_string')) { - function uri_string() - { - $CI =& get_instance(); - return $CI->uri->uri_string(); - } + /** + * URL String + * + * Returns the URI segments. + * + * @return string + */ + function uri_string() + { + return get_instance()->uri->uri_string(); + } } // ------------------------------------------------------------------------ -/** - * Index page - * - * Returns the "index_page" from your config file - * - * @access public - * @return string - */ if ( ! function_exists('index_page')) { - function index_page() - { - $CI =& get_instance(); - return $CI->config->item('index_page'); - } + /** + * Index page + * + * Returns the "index_page" from your config file + * + * @return string + */ + function index_page() + { + return get_instance()->config->item('index_page'); + } } // ------------------------------------------------------------------------ -/** - * Anchor Link - * - * Creates an anchor based on the local URL. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('anchor')) { - function anchor($uri = '', $title = '', $attributes = '') - { - $title = (string) $title; - - if ( ! is_array($uri)) - { - $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; - } - else - { - $site_url = site_url($uri); - } - - if ($title == '') - { - $title = $site_url; - } - - if ($attributes != '') - { - $attributes = _parse_attributes($attributes); - } - - return ''.$title.''; - } + /** + * Anchor Link + * + * Creates an anchor based on the local URL. + * + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ + function anchor($uri = '', $title = '', $attributes = '') + { + $title = (string) $title; + + $site_url = is_array($uri) + ? site_url($uri) + : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri)); + + if ($title === '') + { + $title = $site_url; + } + + if ($attributes !== '') + { + $attributes = _stringify_attributes($attributes); + } + + return ''.$title.''; + } } // ------------------------------------------------------------------------ -/** - * Anchor Link - Pop-up version - * - * Creates an anchor based on the local URL. The link - * opens a new window based on the attributes specified. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('anchor_popup')) { - function anchor_popup($uri = '', $title = '', $attributes = FALSE) - { - $title = (string) $title; - - $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; - - if ($title == '') - { - $title = $site_url; - } - - if ($attributes === FALSE) - { - return "".$title.""; - } - - if ( ! is_array($attributes)) - { - $attributes = array(); - } - - foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val) - { - $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; - unset($attributes[$key]); - } - - if ($attributes != '') - { - $attributes = _parse_attributes($attributes); - } - - return "".$title.""; - } + /** + * Anchor Link - Pop-up version + * + * Creates an anchor based on the local URL. The link + * opens a new window based on the attributes specified. + * + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ + function anchor_popup($uri = '', $title = '', $attributes = FALSE) + { + $title = (string) $title; + $site_url = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri); + + if ($title === '') + { + $title = $site_url; + } + + if ($attributes === FALSE) + { + return '".$title.''; + } + + if ( ! is_array($attributes)) + { + $attributes = array($attributes); + + // Ref: http://www.w3schools.com/jsref/met_win_open.asp + $window_name = '_blank'; + } + elseif ( ! empty($attributes['window_name'])) + { + $window_name = $attributes['window_name']; + unset($attributes['window_name']); + } + else + { + $window_name = '_blank'; + } + + foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'menubar' => 'no', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0') as $key => $val) + { + $atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val; + unset($attributes[$key]); + } + + $attributes = _stringify_attributes($attributes); + + return ''.$title.''; + } } // ------------------------------------------------------------------------ -/** - * Mailto Link - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('mailto')) { - function mailto($email, $title = '', $attributes = '') - { - $title = (string) $title; - - if ($title == "") - { - $title = $email; - } - - $attributes = _parse_attributes($attributes); - - return ''.$title.''; - } + /** + * Mailto Link + * + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ + function mailto($email, $title = '', $attributes = '') + { + $title = (string) $title; + + if ($title === '') + { + $title = $email; + } + + return ''.$title.''; + } } // ------------------------------------------------------------------------ -/** - * Encoded Mailto Link - * - * Create a spam-protected mailto link written in Javascript - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('safe_mailto')) { - function safe_mailto($email, $title = '', $attributes = '') - { - $title = (string) $title; - - if ($title == "") - { - $title = $email; - } - - for ($i = 0; $i < 16; $i++) - { - $x[] = substr(' $val) - { - $x[] = ' '.$key.'="'; - for ($i = 0; $i < strlen($val); $i++) - { - $x[] = "|".ord(substr($val, $i, 1)); - } - $x[] = '"'; - } - } - else - { - for ($i = 0; $i < strlen($attributes); $i++) - { - $x[] = substr($attributes, $i, 1); - } - } - } - - $x[] = '>'; - - $temp = array(); - for ($i = 0; $i < strlen($title); $i++) - { - $ordinal = ord($title[$i]); - - if ($ordinal < 128) - { - $x[] = "|".$ordinal; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - $x[] = "|".$number; - $count = 1; - $temp = array(); - } - } - } - - $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; - - $x = array_reverse($x); - ob_start(); - - ?> $val) + { + $x[] = ' '.$key.'="'; + for ($i = 0, $l = strlen($val); $i < $l; $i++) + { + $x[] = '|'.ord($val[$i]); + } + $x[] = '"'; + } + } + else + { + for ($i = 0, $l = strlen($attributes); $i < $l; $i++) + { + $x[] = $attributes[$i]; + } + } + } + + $x[] = '>'; + + $temp = array(); + for ($i = 0, $l = strlen($title); $i < $l; $i++) + { + $ordinal = ord($title[$i]); + + if ($ordinal < 128) + { + $x[] = '|'.$ordinal; + } + else + { + if (count($temp) === 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + if (count($temp) === $count) + { + $number = ($count === 3) + ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) + : (($temp[0] % 32) * 64) + ($temp[1] % 64); + $x[] = '|'.$number; + $count = 1; + $temp = array(); + } + } + } + + $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; + + $x = array_reverse($x); + + $output = "'; + + return $output; + } } // ------------------------------------------------------------------------ -/** - * Auto-linker - * - * Automatically links URL and Email addresses. - * Note: There's a bit of extra code here to deal with - * URLs or emails that end in a period. We'll strip these - * off and add them after the link. - * - * @access public - * @param string the string - * @param string the type: email, url, or both - * @param bool whether to create pop-up links - * @return string - */ if ( ! function_exists('auto_link')) { - function auto_link($str, $type = 'both', $popup = FALSE) - { - if ($type != 'email') - { - if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) - { - $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; - - for ($i = 0; $i < count($matches['0']); $i++) - { - $period = ''; - if (preg_match("|\.$|", $matches['6'][$i])) - { - $period = '.'; - $matches['6'][$i] = substr($matches['6'][$i], 0, -1); - } - - $str = str_replace($matches['0'][$i], - $matches['1'][$i].'http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $period, $str); - } - } - } - - if ($type != 'url') - { - if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $period = ''; - if (preg_match("|\.$|", $matches['3'][$i])) - { - $period = '.'; - $matches['3'][$i] = substr($matches['3'][$i], 0, -1); - } - - $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); - } - } - } - - return $str; - } + /** + * Auto-linker + * + * Automatically links URL and Email addresses. + * Note: There's a bit of extra code here to deal with + * URLs or emails that end in a period. We'll strip these + * off and add them after the link. + * + * @param string the string + * @param string the type: email, url, or both + * @param bool whether to create pop-up links + * @return string + */ + function auto_link($str, $type = 'both', $popup = FALSE) + { + // Find and replace any URLs. + if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[a-z0-9]+(-+[a-z0-9]+)*(\.[a-z0-9]+(-+[a-z0-9]+)*)+(/([^\s()<>;]+\w)?/?)?#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) + { + // Set our target HTML if using popup links. + $target = ($popup) ? ' target="_blank" rel="noopener"' : ''; + + // We process the links in reverse order (last -> first) so that + // the returned string offsets from preg_match_all() are not + // moved as we add more HTML. + foreach (array_reverse($matches) as $match) + { + // $match[0] is the matched string/link + // $match[1] is either a protocol prefix or 'www.' + // + // With PREG_OFFSET_CAPTURE, both of the above is an array, + // where the actual value is held in [0] and its offset at the [1] index. + $a = ''.$match[0][0].''; + $str = substr_replace($str, $a, $match[0][1], strlen($match[0][0])); + } + } + + // Find and replace any emails. + if ($type !== 'url' && preg_match_all('#([\w\.\-\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+[^[:punct:]\s])#i', $str, $matches, PREG_OFFSET_CAPTURE)) + { + foreach (array_reverse($matches[0]) as $match) + { + if (filter_var($match[0], FILTER_VALIDATE_EMAIL) !== FALSE) + { + $str = substr_replace($str, safe_mailto($match[0]), $match[1], strlen($match[0])); + } + } + } + + return $str; + } } // ------------------------------------------------------------------------ -/** - * Prep URL - * - * Simply adds the http:// part if no scheme is included - * - * @access public - * @param string the URL - * @return string - */ if ( ! function_exists('prep_url')) { - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - return ''; - } - - $url = parse_url($str); - - if ( ! $url OR ! isset($url['scheme'])) - { - $str = 'http://'.$str; - } - - return $str; - } + /** + * Prep URL + * + * Simply adds the http:// part if no scheme is included + * + * @param string the URL + * @return string + */ + function prep_url($str = '') + { + if ($str === 'http://' OR $str === '') + { + return ''; + } + + $url = parse_url($str); + + if ( ! $url OR ! isset($url['scheme'])) + { + return 'http://'.$str; + } + + return $str; + } } // ------------------------------------------------------------------------ -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with a "separator" string - * as the word separator. - * - * @access public - * @param string the string - * @param string the separator - * @return string - */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = '-', $lowercase = FALSE) - { - if ($separator == 'dash') - { - $separator = '-'; - } - else if ($separator == 'underscore') - { - $separator = '_'; - } - - $q_separator = preg_quote($separator); - - $trans = array( - '&.+?;' => '', - '[^a-z0-9 _-]' => '', - '\s+' => $separator, - '('.$q_separator.')+' => $separator - ); - - $str = strip_tags($str); - - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - if ($lowercase === TRUE) - { - $str = strtolower($str); - } - - return trim($str, $separator); - } + /** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with a "separator" string + * as the word separator. + * + * @todo Remove old 'dash' and 'underscore' usage in 3.1+. + * @param string $str Input string + * @param string $separator Word separator + * (usually '-' or '_') + * @param bool $lowercase Whether to transform the output string to lowercase + * @return string + */ + function url_title($str, $separator = '-', $lowercase = FALSE) + { + if ($separator === 'dash') + { + $separator = '-'; + } + elseif ($separator === 'underscore') + { + $separator = '_'; + } + + $q_separator = preg_quote($separator, '#'); + + $trans = array( + '&.+?;' => '', + '[^\w\d _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator + ); + + $str = strip_tags($str); + foreach ($trans as $key => $val) + { + $str = preg_replace('#'.$key.'#i'.(UTF8_ENABLED ? 'u' : ''), $val, $str); + } + + if ($lowercase === TRUE) + { + $str = strtolower($str); + } + + return trim(trim($str, $separator)); + } } // ------------------------------------------------------------------------ -/** - * Header Redirect - * - * Header redirect in two flavors - * For very fine grained control over headers, you could use the Output - * Library's set_header() function. - * - * @access public - * @param string the URL - * @param string the method: location or redirect - * @return string - */ if ( ! function_exists('redirect')) { - function redirect($uri = '', $method = 'location', $http_response_code = 302) - { - if ( ! preg_match('#^https?://#i', $uri)) - { - $uri = site_url($uri); - } - - switch($method) - { - case 'refresh' : header("Refresh:0;url=".$uri); - break; - default : header("Location: ".$uri, TRUE, $http_response_code); - break; - } - exit; - } -} - -// ------------------------------------------------------------------------ - -/** - * Parse out the attributes - * - * Some of the functions use this - * - * @access private - * @param array - * @param bool - * @return string - */ -if ( ! function_exists('_parse_attributes')) -{ - function _parse_attributes($attributes, $javascript = FALSE) - { - if (is_string($attributes)) - { - return ($attributes != '') ? ' '.$attributes : ''; - } - - $att = ''; - foreach ($attributes as $key => $val) - { - if ($javascript == TRUE) - { - $att .= $key . '=' . $val . ','; - } - else - { - $att .= ' ' . $key . '="' . $val . '"'; - } - } - - if ($javascript == TRUE AND $att != '') - { - $att = substr($att, 0, -1); - } - - return $att; - } + /** + * Header Redirect + * + * Header redirect in two flavors + * For very fine grained control over headers, you could use the Output + * Library's set_header() function. + * + * @param string $uri URL + * @param string $method Redirect method + * 'auto', 'location' or 'refresh' + * @param int $code HTTP Response status code + * @return void + */ + function redirect($uri = '', $method = 'auto', $code = NULL) + { + if ( ! preg_match('#^(\w+:)?//#i', $uri)) + { + $uri = site_url($uri); + } + + // IIS environment likely? Use 'refresh' for better compatibility + if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) + { + $method = 'refresh'; + } + elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) + { + if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') + { + $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') + ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get + : 307; + } + else + { + $code = 302; + } + } + + switch ($method) + { + case 'refresh': + header('Refresh:0;url='.$uri); + break; + default: + header('Location: '.$uri, TRUE, $code); + break; + } + exit; + } } - - -/* End of file url_helper.php */ -/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php old mode 100755 new mode 100644 index 1db7030..2639956 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,72 +1,90 @@ -","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + $str = str_replace( + array('&', '<', '>', '"', "'", '-'), + array('&', '<', '>', '"', ''', '-'), + $str + ); - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + // Decode the temp markers back to entities + $str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str); - if ($protect_all === TRUE) - { - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - } + if ($protect_all === TRUE) + { + return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str); + } - return $str; - } + return $str; + } } - -// ------------------------------------------------------------------------ - -/* End of file xml_helper.php */ -/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file diff --git a/system/index.html b/system/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/index.html +++ b/system/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php old mode 100755 new mode 100644 index b545aaa..ce83814 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -1,51 +1,84 @@ - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php old mode 100755 new mode 100644 index a276c7d..967d59c --- a/system/language/english/migration_lang.php +++ b/system/language/english/migration_lang.php @@ -1,13 +1,47 @@ - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php old mode 100755 new mode 100644 index 12e468c..450d57b --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -1,216 +1,255 @@ -_initialize($config); - } - } - - // ------------------------------------------------------------------------ - - /** - * 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) - { - return $this->{$this->_adapter}->get($id); - } - - // ------------------------------------------------------------------------ - - /** - * Cache Save - * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data - * - * @return boolean true on success/false on failure - */ - public function save($id, $data, $ttl = 60) - { - return $this->{$this->_adapter}->save($id, $data, $ttl); - } - - // ------------------------------------------------------------------------ - - /** - * Delete from Cache - * - * @param mixed unique identifier of the item in the cache - * @return boolean true on success/false on failure - */ - public function delete($id) - { - return $this->{$this->_adapter}->delete($id); - } - - // ------------------------------------------------------------------------ - - /** - * Clean the cache - * - * @return boolean false on failure/true on success - */ - public function clean() - { - return $this->{$this->_adapter}->clean(); - } - - // ------------------------------------------------------------------------ - - /** - * Cache Info - * - * @param string user/filehits - * @return mixed array on success, false on failure - */ - public function cache_info($type = 'user') - { - return $this->{$this->_adapter}->cache_info($type); - } - - // ------------------------------------------------------------------------ - - /** - * Get Cache Metadata - * - * @param mixed key to get cache metadata on - * @return mixed return value from child method - */ - public function get_metadata($id) - { - return $this->{$this->_adapter}->get_metadata($id); - } - - // ------------------------------------------------------------------------ - - /** - * Initialize - * - * Initialize class properties based on the configuration array. - * - * @param array - * @return void - */ - private function _initialize($config) - { - $default_config = array( - 'adapter', - 'memcached' - ); - - foreach ($default_config as $key) - { - if (isset($config[$key])) - { - $param = '_'.$key; - - $this->{$param} = $config[$key]; - } - } - - if (isset($config['backup'])) - { - if (in_array('cache_'.$config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Is the requested driver supported in this environment? - * - * @param string The driver to test. - * @return array - */ - public function is_supported($driver) - { - static $support = array(); - - if ( ! isset($support[$driver])) - { - $support[$driver] = $this->{$driver}->is_supported(); - } - - return $support[$driver]; - } - - // ------------------------------------------------------------------------ - - /** - * __get() - * - * @param child - * @return object - */ - public function __get($child) - { - $obj = parent::__get($child); - - if ( ! $this->is_supported($child)) - { - $this->_adapter = $this->_backup_driver; - $obj = parent::__get($this->_adapter); - } - - return $obj; - } - + /** + * Valid cache drivers + * + * @var array + */ + protected $valid_drivers = array( + 'apc', + 'dummy', + 'file', + 'memcached', + 'redis', + 'wincache' + ); + + /** + * Path of cache files (if file-based cache) + * + * @var string + */ + protected $_cache_path = NULL; + + /** + * Reference to the driver + * + * @var mixed + */ + protected $_adapter = 'dummy'; + + /** + * Fallback driver + * + * @var string + */ + protected $_backup_driver = 'dummy'; + + /** + * Cache key prefix + * + * @var string + */ + public $key_prefix = ''; + + /** + * Constructor + * + * Initialize class properties based on the configuration array. + * + * @param array $config = array() + * @return void + */ + public function __construct($config = array()) + { + isset($config['adapter']) && $this->_adapter = $config['adapter']; + isset($config['backup']) && $this->_backup_driver = $config['backup']; + isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; + + // If the specified adapter isn't available, check the backup. + if ( ! $this->is_supported($this->_adapter)) + { + if ( ! $this->is_supported($this->_backup_driver)) + { + // Backup isn't supported either. Default to 'Dummy' driver. + log_message('error', 'Cache adapter "'.$this->_adapter.'" and backup "'.$this->_backup_driver.'" are both unavailable. Cache is now using "Dummy" adapter.'); + $this->_adapter = 'dummy'; + } + else + { + // Backup is supported. Set it to primary. + log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.'); + $this->_adapter = $this->_backup_driver; + } + } + } + + // ------------------------------------------------------------------------ + + /** + * Get + * + * Look for a value in the cache. If it exists, return the data + * if not, return FALSE + * + * @param string $id + * @return mixed value matching $id or FALSE on failure + */ + public function get($id) + { + return $this->{$this->_adapter}->get($this->key_prefix.$id); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Save + * + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Cache TTL (in seconds) + * @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) + { + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param string $id Cache ID + * @return bool TRUE on success, FALSE on failure + */ + public function delete($id) + { + return $this->{$this->_adapter}->delete($this->key_prefix.$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 $this->{$this->_adapter}->increment($this->key_prefix.$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 $this->{$this->_adapter}->decrement($this->key_prefix.$id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the cache + * + * @return bool TRUE on success, FALSE on failure + */ + public function clean() + { + return $this->{$this->_adapter}->clean(); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @param string $type = 'user' user/filehits + * @return mixed array containing cache info on success OR FALSE on failure + */ + public function cache_info($type = 'user') + { + return $this->{$this->_adapter}->cache_info($type); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param string $id key to get cache metadata on + * @return mixed cache item metadata + */ + public function get_metadata($id) + { + return $this->{$this->_adapter}->get_metadata($this->key_prefix.$id); + } + + // ------------------------------------------------------------------------ + + /** + * Is the requested driver supported in this environment? + * + * @param string $driver The driver to test + * @return array + */ + public function is_supported($driver) + { + static $support; + + if ( ! isset($support, $support[$driver])) + { + $support[$driver] = $this->{$driver}->is_supported(); + } + + return $support[$driver]; + } } - -/* End of file Cache.php */ -/* Location: ./system/libraries/Cache/Cache.php */ diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php old mode 100755 new mode 100644 index 0268613..8da8854 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -1,147 +1,217 @@ - $time + $ttl, - 'mtime' => $time, - 'data' => $data - ); - } - - // ------------------------------------------------------------------------ - - /** - * is_supported() - * - * Check to see if APC is available on this system, bail if it isn't. - */ - public function is_supported() - { - if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1") - { - log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); - return FALSE; - } - - return TRUE; - } - + /** + * Class constructor + * + * Only present so that an error message is logged + * if APC is not available. + * + * @return void + */ + public function __construct() + { + if ( ! $this->is_supported()) + { + log_message('error', 'Cache: Failed to initialize APC; 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 = apc_fetch($id, $success); + + return ($success === TRUE) ? $data : 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 (unused) + * @return bool TRUE on success, FALSE on failure + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + return apc_store($id, $data, (int) $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 apc_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 apc_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 apc_dec($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the cache + * + * @return bool false on failure/true on success + */ + public function clean() + { + return apc_clear_cache('user'); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @param string user/filehits + * @return mixed array on success, false on failure + */ + public function cache_info($type = NULL) + { + return apc_cache_info($type); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed array on success/false on failure + */ + public function get_metadata($id) + { + $cache_info = apc_cache_info('user', FALSE); + if (empty($cache_info) OR empty($cache_info['cache_list'])) + { + return FALSE; + } + + foreach ($cache_info['cache_list'] as &$entry) + { + if ($entry['info'] !== $id) + { + continue; + } + + $success = FALSE; + $metadata = array( + 'expire' => ($entry['ttl'] ? $entry['mtime'] + $entry['ttl'] : 0), + 'mtime' => $entry['ttl'], + 'data' => apc_fetch($id, $success) + ); + + return ($success === TRUE) ? $metadata : FALSE; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * is_supported() + * + * Check to see if APC is available on this system, bail if it isn't. + * + * @return bool + */ + public function is_supported() + { + return (extension_loaded('apc') && ini_get('apc.enabled')); + } } - -/* End of file Cache_apc.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php old mode 100755 new mode 100644 index d006f2c..fdb9042 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -1,126 +1,172 @@ -load->helper('file'); - - $path = $CI->config->item('cache_path'); - - $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; - } - - // ------------------------------------------------------------------------ - - /** - * Fetch from cache - * - * @param mixed unique key id - * @return mixed data on success/false on failure - */ - public function get($id) - { - if ( ! file_exists($this->_cache_path.$id)) - { - return FALSE; - } - - $data = read_file($this->_cache_path.$id); - $data = unserialize($data); - - if (time() > $data['time'] + $data['ttl']) - { - unlink($this->_cache_path.$id); - return FALSE; - } - - return $data['data']; - } - - // ------------------------------------------------------------------------ - - /** - * Save into cache - * - * @param string unique key - * @param mixed data to store - * @param int length of time (in seconds) the cache is valid - * - Default is 60 seconds - * @return boolean true on success/false on failure - */ - public function save($id, $data, $ttl = 60) - { - $contents = array( - 'time' => time(), - 'ttl' => $ttl, - 'data' => $data - ); - - if (write_file($this->_cache_path.$id, serialize($contents))) - { - @chmod($this->_cache_path.$id, 0777); - return TRUE; - } - - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Delete from Cache - * - * @param mixed unique identifier of item in cache - * @return boolean true on success/false on failure - */ - public function delete($id) - { - return unlink($this->_cache_path.$id); - } - - // ------------------------------------------------------------------------ - - /** - * Clean the Cache - * - * @return boolean false on failure/true on success - */ - public function clean() - { - return delete_files($this->_cache_path); - } - - // ------------------------------------------------------------------------ - - /** - * Cache Info - * - * Not supported by file-based caching - * - * @param string user/filehits - * @return mixed FALSE - */ - public function cache_info($type = NULL) - { - return get_dir_file_info($this->_cache_path); - } - - // ------------------------------------------------------------------------ - - /** - * Get Cache Metadata - * - * @param mixed key to get cache metadata on - * @return mixed FALSE on failure, array on success. - */ - public function get_metadata($id) - { - if ( ! file_exists($this->_cache_path.$id)) - { - return FALSE; - } - - $data = read_file($this->_cache_path.$id); - $data = unserialize($data); - - if (is_array($data)) - { - $mtime = filemtime($this->_cache_path.$id); - - if ( ! isset($data['ttl'])) - { - return FALSE; - } - - return array( - 'expire' => $mtime + $data['ttl'], - 'mtime' => $mtime - ); - } - - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Is supported - * - * In the file driver, check to see that the cache directory is indeed writable - * - * @return boolean - */ - public function is_supported() - { - return is_really_writable($this->_cache_path); - } + /** + * Directory in which to save cache files + * + * @var string + */ + protected $_cache_path; + + /** + * Initialize file-based cache + * + * @return void + */ + public function __construct() + { + $CI =& get_instance(); + $CI->load->helper('file'); + $path = $CI->config->item('cache_path'); + $this->_cache_path = ($path === '') ? APPPATH.'cache/' : $path; + } + + // ------------------------------------------------------------------------ + + /** + * Fetch from cache + * + * @param string $id Cache ID + * @return mixed Data on success, FALSE on failure + */ + public function get($id) + { + $data = $this->_get($id); + return is_array($data) ? $data['data'] : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Save into cache + * + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Time to live in seconds + * @param bool $raw Whether to store the raw value (unused) + * @return bool TRUE on success, FALSE on failure + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + $contents = array( + 'time' => time(), + 'ttl' => $ttl, + 'data' => $data + ); + + if (write_file($this->_cache_path.$id, serialize($contents))) + { + chmod($this->_cache_path.$id, 0640); + return TRUE; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed unique identifier of item in cache + * @return bool true on success/false on failure + */ + public function delete($id) + { + return is_file($this->_cache_path.$id) ? unlink($this->_cache_path.$id) : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return New value on success, FALSE on failure + */ + public function increment($id, $offset = 1) + { + $data = $this->_get($id); + + if ($data === FALSE) + { + $data = array('data' => 0, 'ttl' => 60); + } + elseif ( ! is_int($data['data'])) + { + return FALSE; + } + + $new_value = $data['data'] + $offset; + return $this->save($id, $new_value, $data['ttl']) + ? $new_value + : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return New value on success, FALSE on failure + */ + public function decrement($id, $offset = 1) + { + $data = $this->_get($id); + + if ($data === FALSE) + { + $data = array('data' => 0, 'ttl' => 60); + } + elseif ( ! is_int($data['data'])) + { + return FALSE; + } + + $new_value = $data['data'] - $offset; + return $this->save($id, $new_value, $data['ttl']) + ? $new_value + : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Clean the Cache + * + * @return bool false on failure/true on success + */ + public function clean() + { + return delete_files($this->_cache_path, FALSE, TRUE); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * Not supported by file-based caching + * + * @param string user/filehits + * @return mixed FALSE + */ + public function cache_info($type = NULL) + { + return get_dir_file_info($this->_cache_path); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed FALSE on failure, array on success. + */ + public function get_metadata($id) + { + if ( ! is_file($this->_cache_path.$id)) + { + return FALSE; + } + + $data = unserialize(file_get_contents($this->_cache_path.$id)); + + if (is_array($data)) + { + $mtime = filemtime($this->_cache_path.$id); + + if ( ! isset($data['ttl'], $data['time'])) + { + return FALSE; + } + + return array( + 'expire' => $data['time'] + $data['ttl'], + 'mtime' => $mtime + ); + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Is supported + * + * In the file driver, check to see that the cache directory is indeed writable + * + * @return bool + */ + public function is_supported() + { + return is_really_writable($this->_cache_path); + } + + // ------------------------------------------------------------------------ + + /** + * Get all data + * + * Internal method to get all the relevant data about a cache item + * + * @param string $id Cache ID + * @return mixed Data array on success or FALSE on failure + */ + protected function _get($id) + { + if ( ! is_file($this->_cache_path.$id)) + { + return FALSE; + } + + $data = unserialize(file_get_contents($this->_cache_path.$id)); + + if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) + { + file_exists($this->_cache_path.$id) && unlink($this->_cache_path.$id); + return FALSE; + } + + return $data; + } } - -/* End of file Cache_file.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php old mode 100755 new mode 100644 index c81adda..bdc86a5 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -1,214 +1,313 @@ - array( - 'default_host' => '127.0.0.1', - 'default_port' => 11211, - 'default_weight' => 1 - ) - ); - - // ------------------------------------------------------------------------ - - /** - * Fetch from cache - * - * @param mixed unique key id - * @return mixed data on success/false on failure - */ - public function get($id) - { - $data = $this->_memcached->get($id); - - return (is_array($data)) ? $data[0] : FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Save - * - * @param string unique identifier - * @param mixed data being cached - * @param int time to live - * @return boolean true on success, false on failure - */ - public function save($id, $data, $ttl = 60) - { - if (get_class($this->_memcached) == 'Memcached') - { - return $this->_memcached->set($id, array($data, time(), $ttl), $ttl); - } - else if (get_class($this->_memcached) == 'Memcache') - { - return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl); - } - - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Delete from Cache - * - * @param mixed key to be deleted. - * @return boolean true on success, false on failure - */ - public function delete($id) - { - return $this->_memcached->delete($id); - } - - // ------------------------------------------------------------------------ - - /** - * Clean the Cache - * - * @return boolean false on failure/true on success - */ - public function clean() - { - return $this->_memcached->flush(); - } - - // ------------------------------------------------------------------------ - - /** - * Cache Info - * - * @param null type not supported in memcached - * @return mixed array on success, false on failure - */ - public function cache_info($type = NULL) - { - return $this->_memcached->getStats(); - } - - // ------------------------------------------------------------------------ - - /** - * Get Cache Metadata - * - * @param mixed key to get cache metadata on - * @return mixed FALSE on failure, array on success. - */ - public function get_metadata($id) - { - $stored = $this->_memcached->get($id); - - if (count($stored) !== 3) - { - return FALSE; - } - - list($data, $time, $ttl) = $stored; - - return array( - 'expire' => $time + $ttl, - 'mtime' => $time, - 'data' => $data - ); - } - - // ------------------------------------------------------------------------ - - /** - * Setup memcached. - */ - private function _setup_memcached() - { - // Try to load memcached server info from the config file. - $CI =& get_instance(); - if ($CI->config->load('memcached', TRUE, TRUE)) - { - if (is_array($CI->config->config['memcached'])) - { - $this->_memcache_conf = NULL; - - foreach ($CI->config->config['memcached'] as $name => $conf) - { - $this->_memcache_conf[$name] = $conf; - } - } - } - - $this->_memcached = new Memcached(); - - foreach ($this->_memcache_conf as $name => $cache_server) - { - if ( ! array_key_exists('hostname', $cache_server)) - { - $cache_server['hostname'] = $this->_default_options['default_host']; - } - - if ( ! array_key_exists('port', $cache_server)) - { - $cache_server['port'] = $this->_default_options['default_port']; - } - - if ( ! array_key_exists('weight', $cache_server)) - { - $cache_server['weight'] = $this->_default_options['default_weight']; - } - - $this->_memcached->addServer( - $cache_server['hostname'], $cache_server['port'], $cache_server['weight'] - ); - } - } - - // ------------------------------------------------------------------------ - - - /** - * Is supported - * - * Returns FALSE if memcached is not supported on the system. - * If it is, we setup the memcached object & return TRUE - */ - public function is_supported() - { - if ( ! extension_loaded('memcached')) - { - log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.'); - return FALSE; - } - - $this->_setup_memcached(); - return TRUE; - } - + /** + * Holds the memcached object + * + * @var object + */ + protected $_memcached; + + /** + * Memcached configuration + * + * @var array + */ + protected $_config = array( + 'default' => array( + 'host' => '127.0.0.1', + 'port' => 11211, + 'weight' => 1 + ) + ); + + // ------------------------------------------------------------------------ + + /** + * Class constructor + * + * Setup Memcache(d) + * + * @return void + */ + public function __construct() + { + // Try to load memcached server info from the config file. + $CI =& get_instance(); + $defaults = $this->_config['default']; + + if ($CI->config->load('memcached', TRUE, TRUE)) + { + $this->_config = $CI->config->config['memcached']; + } + + if (class_exists('Memcached', FALSE)) + { + $this->_memcached = new Memcached(); + } + elseif (class_exists('Memcache', FALSE)) + { + $this->_memcached = new Memcache(); + } + else + { + log_message('error', 'Cache: Failed to create Memcache(d) object; extension not loaded?'); + return; + } + + foreach ($this->_config as $cache_server) + { + 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) + { + // Third parameter is persistence and defaults to TRUE. + $this->_memcached->addServer( + $cache_server['hostname'], + $cache_server['port'], + TRUE, + $cache_server['weight'] + ); + } + elseif ($this->_memcached instanceof Memcached) + { + $this->_memcached->addServer( + $cache_server['hostname'], + $cache_server['port'], + $cache_server['weight'] + ); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * Fetch from cache + * + * @param string $id Cache ID + * @return mixed Data on success, FALSE on failure + */ + public function get($id) + { + $data = $this->_memcached->get($id); + + return is_array($data) ? $data[0] : $data; + } + + // ------------------------------------------------------------------------ + + /** + * Save + * + * @param string $id Cache ID + * @param mixed $data Data being cached + * @param int $ttl Time to live + * @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) + { + if ($raw !== TRUE) + { + $data = array($data, time(), $ttl); + } + + if ($this->_memcached instanceof Memcached) + { + return $this->_memcached->set($id, $data, $ttl); + } + elseif ($this->_memcached instanceof Memcache) + { + return $this->_memcached->set($id, $data, 0, $ttl); + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed $id key to be deleted. + * @return bool true on success, false on failure + */ + public function delete($id) + { + return $this->_memcached->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) + { + if (($result = $this->_memcached->increment($id, $offset)) === FALSE) + { + return $this->_memcached->add($id, $offset) ? $offset : FALSE; + } + + return $result; + } + + // ------------------------------------------------------------------------ + + /** + * 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) + { + if (($result = $this->_memcached->decrement($id, $offset)) === FALSE) + { + return $this->_memcached->add($id, 0) ? 0 : FALSE; + } + + return $result; + } + + // ------------------------------------------------------------------------ + + /** + * Clean the Cache + * + * @return bool false on failure/true on success + */ + public function clean() + { + return $this->_memcached->flush(); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @return mixed array on success, false on failure + */ + public function cache_info() + { + return $this->_memcached->getStats(); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed $id key to get cache metadata on + * @return mixed FALSE on failure, array on success. + */ + public function get_metadata($id) + { + $stored = $this->_memcached->get($id); + + if (count($stored) !== 3) + { + return FALSE; + } + + list($data, $time, $ttl) = $stored; + + return array( + 'expire' => $time + $ttl, + 'mtime' => $time, + 'data' => $data + ); + } + + // ------------------------------------------------------------------------ + + /** + * Is supported + * + * Returns FALSE if memcached is not supported on the system. + * If it is, we setup the memcached object & return TRUE + * + * @return bool + */ + public function is_supported() + { + return (extension_loaded('memcached') OR extension_loaded('memcache')); + } + + // ------------------------------------------------------------------------ + + /** + * Class destructor + * + * Closes the connection to Memcache(d) if present. + * + * @return void + */ + public function __destruct() + { + if ($this->_memcached instanceof Memcache) + { + $this->_memcached->close(); + } + elseif ($this->_memcached instanceof Memcached && method_exists($this->_memcached, 'quit')) + { + $this->_memcached->quit(); + } + } } - -/* End of file Cache_memcached.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php new file mode 100644 index 0000000..bff96fb --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -0,0 +1,330 @@ + + * @link + */ +class CI_Cache_redis extends CI_Driver +{ + /** + * Default config + * + * @static + * @var array + */ + protected static $_default_config = array( + 'socket_type' => 'tcp', + 'host' => '127.0.0.1', + 'password' => NULL, + 'port' => 6379, + 'timeout' => 0 + ); + + /** + * Redis connection + * + * @var Redis + */ + protected $_redis; + + /** + * An internal cache for storing keys of serialized values. + * + * @var array + */ + protected $_serialized = array(); + + /** + * del()/delete() method name depending on phpRedis version + * + * @var string + */ + protected static $_delete_name; + + // ------------------------------------------------------------------------ + + /** + * Class constructor + * + * Setup Redis + * + * Loads Redis config file if present. Will halt execution + * if a Redis connection can't be established. + * + * @return void + * @see Redis::connect() + */ + public function __construct() + { + if ( ! $this->is_supported()) + { + log_message('error', 'Cache: Failed to create Redis object; extension not loaded?'); + return; + } + + isset(static::$_delete_name) OR static::$_delete_name = version_compare(phpversion('phpredis'), '5', '>=') + ? 'del' + : 'delete'; + + $CI =& get_instance(); + + if ($CI->config->load('redis', TRUE, TRUE)) + { + $config = array_merge(self::$_default_config, $CI->config->item('redis')); + } + else + { + $config = self::$_default_config; + } + + $this->_redis = new Redis(); + + try + { + if ($config['socket_type'] === 'unix') + { + $success = $this->_redis->connect($config['socket']); + } + else // tcp socket + { + $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } + + if ( ! $success) + { + log_message('error', 'Cache: Redis connection failed. Check your configuration.'); + } + + if (isset($config['password']) && ! $this->_redis->auth($config['password'])) + { + log_message('error', 'Cache: Redis authentication failed.'); + } + } + catch (RedisException $e) + { + log_message('error', 'Cache: Redis connection refused ('.$e->getMessage().')'); + } + } + + // ------------------------------------------------------------------------ + + /** + * Get cache + * + * @param string $key Cache ID + * @return mixed + */ + public function get($key) + { + $value = $this->_redis->get($key); + + if ($value !== FALSE && $this->_redis->sIsMember('_ci_redis_serialized', $key)) + { + return unserialize($value); + } + + return $value; + } + + // ------------------------------------------------------------------------ + + /** + * Save cache + * + * @param string $id Cache ID + * @param mixed $data Data to save + * @param int $ttl Time to live in seconds + * @param bool $raw Whether to store the raw value (unused) + * @return bool TRUE on success, FALSE on failure + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + if (is_array($data) OR is_object($data)) + { + if ( ! $this->_redis->sIsMember('_ci_redis_serialized', $id) && ! $this->_redis->sAdd('_ci_redis_serialized', $id)) + { + return FALSE; + } + + isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE; + $data = serialize($data); + } + else + { + $this->_redis->sRemove('_ci_redis_serialized', $id); + } + + return $this->_redis->set($id, $data, $ttl); + } + + // ------------------------------------------------------------------------ + + /** + * Delete from cache + * + * @param string $key Cache key + * @return bool + */ + public function delete($key) + { + if ($this->_redis->{static::$_delete_name}($key) !== 1) + { + return FALSE; + } + + $this->_redis->sRemove('_ci_redis_serialized', $key); + + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * 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 $this->_redis->incrBy($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 $this->_redis->decrBy($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Clean cache + * + * @return bool + * @see Redis::flushDB() + */ + public function clean() + { + return $this->_redis->flushDB(); + } + + // ------------------------------------------------------------------------ + + /** + * Get cache driver info + * + * @param string $type Not supported in Redis. + * Only included in order to offer a + * consistent cache API. + * @return array + * @see Redis::info() + */ + public function cache_info($type = NULL) + { + return $this->_redis->info(); + } + + // ------------------------------------------------------------------------ + + /** + * Get cache metadata + * + * @param string $key Cache key + * @return array + */ + public function get_metadata($key) + { + $value = $this->get($key); + + if ($value !== FALSE) + { + return array( + 'expire' => time() + $this->_redis->ttl($key), + 'data' => $value + ); + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Check if Redis driver is supported + * + * @return bool + */ + public function is_supported() + { + return extension_loaded('redis'); + } + + // ------------------------------------------------------------------------ + + /** + * Class destructor + * + * Closes the connection to Redis if present. + * + * @return void + */ + public function __destruct() + { + if ($this->_redis) + { + $this->_redis->close(); + } + } +} diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php new file mode 100644 index 0000000..1feaa15 --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -0,0 +1,217 @@ +is_supported()) + { + log_message('error', 'Cache: Failed to initialize Wincache; extension not loaded/enabled?'); + } + } + + // ------------------------------------------------------------------------ + + /** + * Get + * + * Look for a value in the cache. If it exists, return the data, + * if not, return FALSE + * + * @param string $id Cache Ide + * @return mixed Value that is stored/FALSE on failure + */ + public function get($id) + { + $success = FALSE; + $data = wincache_ucache_get($id, $success); + + // Success returned by reference from wincache_ucache_get() + return ($success) ? $data : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Cache Save + * + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Time to live (in seconds) + * @param bool $raw Whether to store the raw value (unused) + * @return bool true on success/false on failure + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + return wincache_ucache_set($id, $data, $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 wincache_ucache_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) + { + $success = FALSE; + $value = wincache_ucache_inc($id, $offset, $success); + + return ($success === TRUE) ? $value : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * 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) + { + $success = FALSE; + $value = wincache_ucache_dec($id, $offset, $success); + + return ($success === TRUE) ? $value : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Clean the cache + * + * @return bool false on failure/true on success + */ + public function clean() + { + return wincache_ucache_clear(); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @return mixed array on success, false on failure + */ + public function cache_info() + { + return wincache_ucache_info(TRUE); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed array on success/false on failure + */ + public function get_metadata($id) + { + if ($stored = wincache_ucache_info(FALSE, $id)) + { + $age = $stored['ucache_entries'][1]['age_seconds']; + $ttl = $stored['ucache_entries'][1]['ttl_seconds']; + $hitcount = $stored['ucache_entries'][1]['hitcount']; + + return array( + 'expire' => $ttl - $age, + 'hitcount' => $hitcount, + 'age' => $age, + 'ttl' => $ttl + ); + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * is_supported() + * + * Check to see if WinCache is available on this system, bail if it isn't. + * + * @return bool + */ + public function is_supported() + { + return (extension_loaded('wincache') && ini_get('wincache.ucenabled')); + } +} diff --git a/system/libraries/Cache/drivers/index.html b/system/libraries/Cache/drivers/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/libraries/Cache/drivers/index.html +++ b/system/libraries/Cache/drivers/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/libraries/Cache/index.html b/system/libraries/Cache/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/libraries/Cache/index.html +++ b/system/libraries/Cache/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php old mode 100755 new mode 100644 index e6c6c10..a6bdae5 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,476 +1,546 @@ -CI =& get_instance(); - - if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) - { - $this->CI->lang->load('calendar'); - } - - $this->local_time = time(); - - if (count($config) > 0) - { - $this->initialize($config); - } - - log_message('debug', "Calendar Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the user preferences - * - * Accepts an associative array as input, containing display preferences - * - * @access public - * @param array config preferences - * @return void - */ - function initialize($config = array()) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Generate the calendar - * - * @access public - * @param integer the year - * @param integer the month - * @param array the data to be shown in the calendar cells - * @return string - */ - function generate($year = '', $month = '', $data = array()) - { - // Set and validate the supplied month/year - if ($year == '') - $year = date("Y", $this->local_time); - - if ($month == '') - $month = date("m", $this->local_time); - - if (strlen($year) == 1) - $year = '200'.$year; - - if (strlen($year) == 2) - $year = '20'.$year; - - if (strlen($month) == 1) - $month = '0'.$month; - - $adjusted_date = $this->adjust_date($month, $year); - - $month = $adjusted_date['month']; - $year = $adjusted_date['year']; - - // Determine the total days in the month - $total_days = $this->get_total_days($month, $year); - - // Set the starting day of the week - $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); - $start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day]; - - // Set the starting day number - $local_date = mktime(12, 0, 0, $month, 1, $year); - $date = getdate($local_date); - $day = $start_day + 1 - $date["wday"]; - - while ($day > 1) - { - $day -= 7; - } - - // Set the current month/year/day - // We use this to determine the "today" date - $cur_year = date("Y", $this->local_time); - $cur_month = date("m", $this->local_time); - $cur_day = date("j", $this->local_time); - - $is_current_month = ($cur_year == $year AND $cur_month == $month) ? TRUE : FALSE; - - // Generate the template data array - $this->parse_template(); - - // Begin building the calendar output - $out = $this->temp['table_open']; - $out .= "\n"; - - $out .= "\n"; - $out .= $this->temp['heading_row_start']; - $out .= "\n"; - - // "previous" month link - if ($this->show_next_prev == TRUE) - { - // Add a trailing slash to the URL if needed - $this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->next_prev_url); - - $adjusted_date = $this->adjust_date($month - 1, $year); - $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell']); - $out .= "\n"; - } - - // Heading containing the month/year - $colspan = ($this->show_next_prev == TRUE) ? 5 : 7; - - $this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['heading_title_cell']); - $this->temp['heading_title_cell'] = str_replace('{heading}', $this->get_month_name($month)." ".$year, $this->temp['heading_title_cell']); - - $out .= $this->temp['heading_title_cell']; - $out .= "\n"; - - // "next" month link - if ($this->show_next_prev == TRUE) - { - $adjusted_date = $this->adjust_date($month + 1, $year); - $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']); - } - - $out .= "\n"; - $out .= $this->temp['heading_row_end']; - $out .= "\n"; - - // Write the cells containing the days of the week - $out .= "\n"; - $out .= $this->temp['week_row_start']; - $out .= "\n"; - - $day_names = $this->get_day_names(); - - for ($i = 0; $i < 7; $i ++) - { - $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']); - } - - $out .= "\n"; - $out .= $this->temp['week_row_end']; - $out .= "\n"; - - // Build the main body of the calendar - while ($day <= $total_days) - { - $out .= "\n"; - $out .= $this->temp['cal_row_start']; - $out .= "\n"; - - for ($i = 0; $i < 7; $i++) - { - $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; - - if ($day > 0 AND $day <= $total_days) - { - if (isset($data[$day])) - { - // Cells with content - $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content']; - $out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp)); - } - else - { - // Cells with no content - $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; - $out .= str_replace('{day}', $day, $temp); - } - } - else - { - // Blank cells - $out .= $this->temp['cal_cell_blank']; - } - - $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; - $day++; - } - - $out .= "\n"; - $out .= $this->temp['cal_row_end']; - $out .= "\n"; - } - - $out .= "\n"; - $out .= $this->temp['table_close']; - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Get Month Name - * - * Generates a textual month name based on the numeric - * month provided. - * - * @access public - * @param integer the month - * @return string - */ - function get_month_name($month) - { - if ($this->month_type == 'short') - { - $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec'); - } - else - { - $month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december'); - } - - $month = $month_names[$month]; - - if ($this->CI->lang->line($month) === FALSE) - { - return ucfirst(str_replace('cal_', '', $month)); - } - - return $this->CI->lang->line($month); - } - - // -------------------------------------------------------------------- - - /** - * Get Day Names - * - * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev - * - * @access public - * @param string - * @return array - */ - function get_day_names($day_type = '') - { - if ($day_type != '') - $this->day_type = $day_type; - - if ($this->day_type == 'long') - { - $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); - } - elseif ($this->day_type == 'short') - { - $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); - } - else - { - $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'); - } - - $days = array(); - foreach ($day_names as $val) - { - $days[] = ($this->CI->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->CI->lang->line('cal_'.$val); - } - - return $days; - } - - // -------------------------------------------------------------------- - - /** - * Adjust Date - * - * This function makes sure that we have a valid month/year. - * For example, if you submit 13 as the month, the year will - * increment and the month will become January. - * - * @access public - * @param integer the month - * @param integer the year - * @return array - */ - function adjust_date($month, $year) - { - $date = array(); - - $date['month'] = $month; - $date['year'] = $year; - - while ($date['month'] > 12) - { - $date['month'] -= 12; - $date['year']++; - } - - while ($date['month'] <= 0) - { - $date['month'] += 12; - $date['year']--; - } - - if (strlen($date['month']) == 1) - { - $date['month'] = '0'.$date['month']; - } - - return $date; - } - - // -------------------------------------------------------------------- - - /** - * Total days in a given month - * - * @access public - * @param integer the month - * @param integer the year - * @return integer - */ - function get_total_days($month, $year) - { - $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - - if ($month < 1 OR $month > 12) - { - return 0; - } - - // Is the year a leap year? - if ($month == 2) - { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) - { - return 29; - } - } - - return $days_in_month[$month - 1]; - } - - // -------------------------------------------------------------------- - - /** - * Set Default Template Data - * - * This is used in the event that the user has not created their own template - * - * @access public - * @return array - */ - function default_template() - { - return array ( - 'table_open' => '', - 'heading_row_start' => '', - 'heading_previous_cell' => '', - 'heading_title_cell' => '', - 'heading_next_cell' => '', - 'heading_row_end' => '', - 'week_row_start' => '', - 'week_day_cell' => '', - 'week_row_end' => '', - 'cal_row_start' => '', - 'cal_cell_start' => '', - 'cal_cell_end_today' => '', - 'cal_row_end' => '', - 'table_close' => '
    <<{heading}>>
    {week_day}
    ', - 'cal_cell_start_today' => '', - 'cal_cell_content' => '{day}', - 'cal_cell_content_today' => '{day}', - 'cal_cell_no_content' => '{day}', - 'cal_cell_no_content_today' => '{day}', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '
    ' - ); - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * used to display the calendar - * - * @access public - * @return void - */ - function parse_template() - { - $this->temp = $this->default_template(); - - if ($this->template == '') - { - return; - } - - $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); - - foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val) - { - if (preg_match("/\{".$val."\}(.*?)\{\/".$val."\}/si", $this->template, $match)) - { - $this->temp[$val] = $match['1']; - } - else - { - if (in_array($val, $today, TRUE)) - { - $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; - } - } - } - } + /** + * Calendar layout template + * + * @var mixed + */ + public $template = ''; + + /** + * Replacements array for template + * + * @var array + */ + public $replacements = array(); + + /** + * Day of the week to start the calendar on + * + * @var string + */ + public $start_day = 'sunday'; + + /** + * How to display months + * + * @var string + */ + public $month_type = 'long'; + + /** + * How to display names of days + * + * @var string + */ + public $day_type = 'abr'; + + /** + * Whether to show next/prev month links + * + * @var bool + */ + public $show_next_prev = FALSE; + + /** + * Url base to use for next/prev month links + * + * @var bool + */ + public $next_prev_url = ''; + + /** + * Show days of other months + * + * @var bool + */ + public $show_other_days = FALSE; + + // -------------------------------------------------------------------- + + /** + * CI Singleton + * + * @var object + */ + protected $CI; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Loads the calendar language file and sets the default time reference. + * + * @uses CI_Lang::$is_loaded + * + * @param array $config Calendar options + * @return void + */ + public function __construct($config = array()) + { + $this->CI =& get_instance(); + $this->CI->lang->load('calendar'); + + empty($config) OR $this->initialize($config); + + log_message('info', 'Calendar Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the user preferences + * + * Accepts an associative array as input, containing display preferences + * + * @param array config preferences + * @return CI_Calendar + */ + public function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + + // Set the next_prev_url to the controller if required but not defined + if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) + { + $this->next_prev_url = $this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Generate the calendar + * + * @param int the year + * @param int the month + * @param array the data to be shown in the calendar cells + * @return string + */ + public function generate($year = '', $month = '', $data = array()) + { + $local_time = time(); + + // Set and validate the supplied month/year + if (empty($year)) + { + $year = date('Y', $local_time); + } + elseif (strlen($year) === 1) + { + $year = '200'.$year; + } + elseif (strlen($year) === 2) + { + $year = '20'.$year; + } + + if (empty($month)) + { + $month = date('m', $local_time); + } + elseif (strlen($month) === 1) + { + $month = '0'.$month; + } + + $adjusted_date = $this->adjust_date($month, $year); + + $month = $adjusted_date['month']; + $year = $adjusted_date['year']; + + // Determine the total days in the month + $total_days = $this->get_total_days($month, $year); + + // Set the starting day of the week + $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); + $start_day = isset($start_days[$this->start_day]) ? $start_days[$this->start_day] : 0; + + // Set the starting day number + $local_date = mktime(12, 0, 0, $month, 1, $year); + $date = getdate($local_date); + $day = $start_day + 1 - $date['wday']; + + while ($day > 1) + { + $day -= 7; + } + + // Set the current month/year/day + // We use this to determine the "today" date + $cur_year = date('Y', $local_time); + $cur_month = date('m', $local_time); + $cur_day = date('j', $local_time); + + $is_current_month = ($cur_year == $year && $cur_month == $month); + + // Generate the template data array + $this->parse_template(); + + // Begin building the calendar output + $out = $this->replacements['table_open']."\n\n".$this->replacements['heading_row_start']."\n"; + + // "previous" month link + if ($this->show_next_prev === TRUE) + { + // Add a trailing slash to the URL if needed + $this->next_prev_url = preg_replace('/(.+?)\/*$/', '\\1/', $this->next_prev_url); + + $adjusted_date = $this->adjust_date($month - 1, $year); + $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_previous_cell'])."\n"; + } + + // Heading containing the month/year + $colspan = ($this->show_next_prev === TRUE) ? 5 : 7; + + $this->replacements['heading_title_cell'] = str_replace('{colspan}', $colspan, + str_replace('{heading}', $this->get_month_name($month).' '.$year, $this->replacements['heading_title_cell'])); + + $out .= $this->replacements['heading_title_cell']."\n"; + + // "next" month link + if ($this->show_next_prev === TRUE) + { + $adjusted_date = $this->adjust_date($month + 1, $year); + $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_next_cell']); + } + + $out .= "\n".$this->replacements['heading_row_end']."\n\n" + // Write the cells containing the days of the week + .$this->replacements['week_row_start']."\n"; + + $day_names = $this->get_day_names(); + + for ($i = 0; $i < 7; $i ++) + { + $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->replacements['week_day_cell']); + } + + $out .= "\n".$this->replacements['week_row_end']."\n"; + + // Build the main body of the calendar + while ($day <= $total_days) + { + $out .= "\n".$this->replacements['cal_row_start']."\n"; + + for ($i = 0; $i < 7; $i++) + { + if ($day > 0 && $day <= $total_days) + { + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->replacements['cal_cell_start_today'] : $this->replacements['cal_cell_start']; + + if (isset($data[$day])) + { + // Cells with content + $temp = ($is_current_month === TRUE && $day == $cur_day) ? + $this->replacements['cal_cell_content_today'] : $this->replacements['cal_cell_content']; + $out .= str_replace(array('{content}', '{day}'), array($data[$day], $day), $temp); + } + else + { + // Cells with no content + $temp = ($is_current_month === TRUE && $day == $cur_day) ? + $this->replacements['cal_cell_no_content_today'] : $this->replacements['cal_cell_no_content']; + $out .= str_replace('{day}', $day, $temp); + } + + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->replacements['cal_cell_end_today'] : $this->replacements['cal_cell_end']; + } + elseif ($this->show_other_days === TRUE) + { + $out .= $this->replacements['cal_cell_start_other']; + + if ($day <= 0) + { + // Day of previous month + $prev_month = $this->adjust_date($month - 1, $year); + $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); + $out .= str_replace('{day}', $prev_month_days + $day, $this->replacements['cal_cell_other']); + } + else + { + // Day of next month + $out .= str_replace('{day}', $day - $total_days, $this->replacements['cal_cell_other']); + } + + $out .= $this->replacements['cal_cell_end_other']; + } + else + { + // Blank cells + $out .= $this->replacements['cal_cell_start'].$this->replacements['cal_cell_blank'].$this->replacements['cal_cell_end']; + } + + $day++; + } + + $out .= "\n".$this->replacements['cal_row_end']."\n"; + } + + return $out .= "\n".$this->replacements['table_close']; + } + + // -------------------------------------------------------------------- + + /** + * Get Month Name + * + * Generates a textual month name based on the numeric + * month provided. + * + * @param int the month + * @return string + */ + public function get_month_name($month) + { + if ($this->month_type === 'short') + { + $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec'); + } + else + { + $month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december'); + } + + return ($this->CI->lang->line($month_names[$month]) === FALSE) + ? ucfirst(substr($month_names[$month], 4)) + : $this->CI->lang->line($month_names[$month]); + } + + // -------------------------------------------------------------------- + + /** + * Get Day Names + * + * Returns an array of day names (Sunday, Monday, etc.) based + * on the type. Options: long, short, abr + * + * @param string + * @return array + */ + public function get_day_names($day_type = '') + { + if ($day_type !== '') + { + $this->day_type = $day_type; + } + + if ($this->day_type === 'long') + { + $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); + } + elseif ($this->day_type === 'short') + { + $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); + } + else + { + $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'); + } + + $days = array(); + for ($i = 0, $c = count($day_names); $i < $c; $i++) + { + $days[] = ($this->CI->lang->line('cal_'.$day_names[$i]) === FALSE) ? ucfirst($day_names[$i]) : $this->CI->lang->line('cal_'.$day_names[$i]); + } + + return $days; + } + + // -------------------------------------------------------------------- + + /** + * Adjust Date + * + * This function makes sure that we have a valid month/year. + * For example, if you submit 13 as the month, the year will + * increment and the month will become January. + * + * @param int the month + * @param int the year + * @return array + */ + public function adjust_date($month, $year) + { + $date = array(); + + $date['month'] = $month; + $date['year'] = $year; + + while ($date['month'] > 12) + { + $date['month'] -= 12; + $date['year']++; + } + + while ($date['month'] <= 0) + { + $date['month'] += 12; + $date['year']--; + } + + if (strlen($date['month']) === 1) + { + $date['month'] = '0'.$date['month']; + } + + return $date; + } + + // -------------------------------------------------------------------- + + /** + * Total days in a given month + * + * @param int the month + * @param int the year + * @return int + */ + public function get_total_days($month, $year) + { + $this->CI->load->helper('date'); + return days_in_month($month, $year); + } + + // -------------------------------------------------------------------- + + /** + * Set Default Template Data + * + * This is used in the event that the user has not created their own template + * + * @return array + */ + public function default_template() + { + return array( + 'table_open' => '', + 'heading_row_start' => '', + 'heading_previous_cell' => '', + 'heading_title_cell' => '', + 'heading_next_cell' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', + 'cal_cell_end_today' => '', + 'cal_cell_end_other' => '', + 'cal_row_end' => '', + 'table_close' => '
    <<{heading}>>
    {week_day}
    ', + 'cal_cell_start_today' => '', + 'cal_cell_start_other' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_other' => '{day}', + 'cal_cell_end' => '
    ' + ); + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * used to display the calendar + * + * @return CI_Calendar + */ + public function parse_template() + { + $this->replacements = $this->default_template(); + + if (empty($this->template)) + { + return $this; + } + + if (is_string($this->template)) + { + $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); + + foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today', 'cal_cell_start_other', 'cal_cell_other', 'cal_cell_end_other') as $val) + { + if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match)) + { + $this->replacements[$val] = $match[1]; + } + elseif (in_array($val, $today, TRUE)) + { + $this->replacements[$val] = $this->replacements[substr($val, 0, -6)]; + } + } + } + elseif (is_array($this->template)) + { + $this->replacements = array_merge($this->replacements, $this->template); + } + + return $this; + } } - -// END CI_Calendar class - -/* End of file Calendar.php */ -/* Location: ./system/libraries/Calendar.php */ \ No newline at end of file diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php old mode 100755 new mode 100644 index 9e5bd2d..6a10775 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,552 +1,567 @@ -CI =& get_instance(); - - // Are any config settings being passed manually? If so, set them - $config = array(); - if (count($params) > 0) - { - foreach ($params as $key => $val) - { - $config[$key] = $val; - } - } - - // Load the Sessions class - $this->CI->load->library('session', $config); - - // Grab the shopping cart array from the session table, if it exists - if ($this->CI->session->userdata('cart_contents') !== FALSE) - { - $this->_cart_contents = $this->CI->session->userdata('cart_contents'); - } - else - { - // No cart exists so we'll set some base values - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; - } - - log_message('debug', "Cart Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Insert items into the cart and save it to the session table - * - * @access public - * @param array - * @return bool - */ - 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) AND 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 - * - * @access private - * @param array - * @return bool - */ - 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']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($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... - $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); - // Trim any leading zeros - $items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty'])); - - // If the quantity is zero or blank there's nothing for us to do - if ( ! is_numeric($items['qty']) OR $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 ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $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 anything that isn't a number or decimal point. - $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price'])); - // Trim any leading zeros - $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price'])); - - // Is the price a valid number? - if ( ! is_numeric($items['price'])) - { - log_message('error', 'An invalid price was submitted for product ID: '.$items['id']); - return FALSE; - } - - // -------------------------------------------------------------------- - - // 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']) AND count($items['options']) > 0) - { - $rowid = md5($items['id'].implode('', $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 - - // let's unset this first, just to make sure our index contains only the data from this submission - unset($this->_cart_contents[$rowid]); - - // Create a new index with our new row ID - $this->_cart_contents[$rowid]['rowid'] = $rowid; - - // And add the new items to the cart array - foreach ($items as $key => $val) - { - $this->_cart_contents[$rowid][$key] = $val; - } - - // Woot! - 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. - * - * @access public - * @param array - * @param string - * @return bool - */ - 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 "id". - // If it's not found we assume it's a multi-dimensional array - $save_cart = FALSE; - if (isset($items['rowid']) AND isset($items['qty'])) - { - if ($this->_update($items) == TRUE) - { - $save_cart = TRUE; - } - } - else - { - foreach ($items as $val) - { - if (is_array($val) AND isset($val['rowid']) AND isset($val['qty'])) - { - 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 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. - * - * @access private - * @param array - * @return bool - */ - function _update($items = array()) - { - // Without these array indexes there is nothing we can do - if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']])) - { - return FALSE; - } - - // Prep the quantity - $items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']); - - // Is the quantity a number? - if ( ! is_numeric($items['qty'])) - { - return FALSE; - } - - // Is the new quantity different than what is already saved in the cart? - // If it's the same there's nothing to do - if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) - { - return FALSE; - } - - // Is the quantity zero? If so we will remove the item from the cart. - // If the quantity is greater than zero we are updating - if ($items['qty'] == 0) - { - unset($this->_cart_contents[$items['rowid']]); - } - else - { - $this->_cart_contents[$items['rowid']]['qty'] = $items['qty']; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Save the cart array to the session DB - * - * @access private - * @return bool - */ - function _save_cart() - { - // Unset these so our total can be calculated correctly below - unset($this->_cart_contents['total_items']); - unset($this->_cart_contents['cart_total']); - - // Lets add up the individual prices and set the cart sub-total - $total = 0; - $items = 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']) OR ! isset($val['qty'])) - { - continue; - } - - $total += ($val['price'] * $val['qty']); - $items += $val['qty']; - - // Set the subtotal - $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); - } - - // Set the cart total and total items. - $this->_cart_contents['total_items'] = $items; - $this->_cart_contents['cart_total'] = $total; - - // 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 - * - * @access public - * @return integer - */ - function total() - { - return $this->_cart_contents['cart_total']; - } - - // -------------------------------------------------------------------- - - /** - * Total Items - * - * Returns the total item count - * - * @access public - * @return integer - */ - function total_items() - { - return $this->_cart_contents['total_items']; - } - - // -------------------------------------------------------------------- - - /** - * Cart Contents - * - * Returns the entire cart array - * - * @access public - * @return array - */ - function contents() - { - $cart = $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; - } - - // -------------------------------------------------------------------- - - /** - * Has options - * - * Returns TRUE if the rowid passed to this function correlates to an item - * that has options associated with it. - * - * @access public - * @return array - */ - function has_options($rowid = '') - { - if ( ! isset($this->_cart_contents[$rowid]['options']) OR count($this->_cart_contents[$rowid]['options']) === 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Product options - * - * Returns the an array of options, for a particular product row ID - * - * @access public - * @return array - */ - function product_options($rowid = '') - { - if ( ! isset($this->_cart_contents[$rowid]['options'])) - { - return array(); - } - - return $this->_cart_contents[$rowid]['options']; - } - - // -------------------------------------------------------------------- - - /** - * Format Number - * - * Returns the supplied number with commas and a decimal point. - * - * @access public - * @return integer - */ - function format_number($n = '') - { - if ($n == '') - { - return ''; - } - - // Remove anything that isn't a number or decimal point. - $n = trim(preg_replace('/([^0-9\.])/i', '', $n)); - - return number_format($n, 2, '.', ','); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the cart - * - * Empties the cart and kills the session - * - * @access public - * @return null - */ - function destroy() - { - unset($this->_cart_contents); - - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; - - $this->CI->session->unset_userdata('cart_contents'); - } - + /** + * These are the regular expression rules that we use to validate the product ID and product name + * alpha-numeric, dashes, underscores, or periods + * + * @var string + */ + public $product_id_rules = '\.a-z0-9_-'; + + /** + * These are the regular expression rules that we use to validate the product ID and product name + * alpha-numeric, dashes, underscores, colons or periods + * + * @var string + */ + public $product_name_rules = '\w \-\.\:'; + + /** + * only allow safe product names + * + * @var bool + */ + public $product_name_safe = TRUE; + + // -------------------------------------------------------------------------- + + /** + * Reference to CodeIgniter instance + * + * @var object + */ + protected $CI; + + /** + * Contents of the cart + * + * @var array + */ + protected $_cart_contents = array(); + + /** + * Shopping Class Constructor + * + * The constructor loads the Session class, used to store the shopping cart contents. + * + * @param array + * @return void + */ + public function __construct($params = array()) + { + // Set the super object to a local variable for use later + $this->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'); + } } - -/* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ \ No newline at end of file diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php old mode 100755 new mode 100644 index dacb170..7e6cf4f --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,20 +1,41 @@ -lib_name)) - { - $this->lib_name = get_class($this); - } - - // The class will be prefixed with the parent lib - $child_class = $this->lib_name.'_'.$child; - - // Remove the CI_ prefix and lowercase - $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name))); - $driver_name = strtolower(str_replace('CI_', '', $child_class)); - - if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) - { - // check and see if the driver is in a separate file - if ( ! class_exists($child_class)) - { - // check application path first - foreach (get_instance()->load->get_package_paths(TRUE) as $path) - { - // loves me some nesting! - foreach (array(ucfirst($driver_name), $driver_name) as $class) - { - $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php'; - - if (file_exists($filepath)) - { - include_once $filepath; - break; - } - } - } - - // it's a valid driver, but the file simply can't be found - if ( ! class_exists($child_class)) - { - log_message('error', "Unable to load the requested driver: ".$child_class); - show_error("Unable to load the requested driver: ".$child_class); - } - } - - $obj = new $child_class; - $obj->decorate($this); - $this->$child = $obj; - return $this->$child; - } - - // The requested driver isn't valid! - log_message('error', "Invalid driver requested: ".$child_class); - show_error("Invalid driver requested: ".$child_class); - } - - // -------------------------------------------------------------------- + /** + * Array of drivers that are available to use with the driver class + * + * @var array + */ + protected $valid_drivers = array(); + + /** + * Name of the current class - usually the driver class + * + * @var string + */ + protected $lib_name; + + /** + * Get magic method + * + * The first time a child is used it won't exist, so we instantiate it + * subsequents calls will go straight to the proper child. + * + * @param string Child class name + * @return object Child class + */ + public function __get($child) + { + // Try to load the driver + return $this->load_driver($child); + } + + /** + * Load driver + * + * Separate load_driver call to support explicit driver load by library or user + * + * @param string Driver name (w/o parent prefix) + * @return object Child class + */ + public function load_driver($child) + { + // Get CodeIgniter instance and subclass prefix + $prefix = config_item('subclass_prefix'); + + if ( ! isset($this->lib_name)) + { + // Get library name without any prefix + $this->lib_name = str_replace(array('CI_', $prefix), '', get_class($this)); + } + + // The child will be prefixed with the parent lib + $child_name = $this->lib_name.'_'.$child; + + // See if requested child is a valid driver + if ( ! in_array($child, $this->valid_drivers)) + { + // The requested driver isn't valid! + $msg = 'Invalid driver requested: '.$child_name; + log_message('error', $msg); + show_error($msg); + } + + // Get package paths and filename case variations to search + $CI = get_instance(); + $paths = $CI->load->get_package_paths(TRUE); + + // Is there an extension? + $class_name = $prefix.$child_name; + $found = class_exists($class_name, FALSE); + if ( ! $found) + { + // Check for subclass file + foreach ($paths as $path) + { + // Does the file exist? + $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$prefix.$child_name.'.php'; + if (file_exists($file)) + { + // Yes - require base class from BASEPATH + $basepath = BASEPATH.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; + if ( ! file_exists($basepath)) + { + $msg = 'Unable to load the requested class: CI_'.$child_name; + log_message('error', $msg); + show_error($msg); + } + + // Include both sources and mark found + include_once($basepath); + include_once($file); + $found = TRUE; + break; + } + } + } + + // Do we need to search for the class? + if ( ! $found) + { + // Use standard class name + $class_name = 'CI_'.$child_name; + if ( ! class_exists($class_name, FALSE)) + { + // Check package paths + foreach ($paths as $path) + { + // Does the file exist? + $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; + if (file_exists($file)) + { + // Include source + include_once($file); + break; + } + } + } + } + + // Did we finally find the class? + if ( ! class_exists($class_name, FALSE)) + { + if (class_exists($child_name, FALSE)) + { + $class_name = $child_name; + } + else + { + $msg = 'Unable to load the requested driver: '.$class_name; + log_message('error', $msg); + show_error($msg); + } + } + + // Instantiate, decorate and add child + $obj = new $class_name(); + $obj->decorate($this); + $this->$child = $obj; + return $this->$child; + } } -// END CI_Driver_Library CLASS +// -------------------------------------------------------------------------- /** * CodeIgniter Driver Class @@ -101,128 +199,144 @@ function __get($child) * This class enables you to create drivers for a Library based on the Driver Library. * It handles the drivers' access to the parent library * - * @package CodeIgniter - * @subpackage Libraries - * @category Libraries - * @author EllisLab Dev Team + * @package CodeIgniter + * @subpackage Libraries + * @category Libraries + * @author EllisLab Dev Team * @link */ class CI_Driver { - protected $parent; - - private $methods = array(); - private $properties = array(); - - private static $reflections = array(); - - /** - * Decorate - * - * Decorates the child with the parent driver lib's methods and properties - * - * @param object - * @return void - */ - public function decorate($parent) - { - $this->parent = $parent; - - // Lock down attributes to what is defined in the class - // and speed up references in magic methods - - $class_name = get_class($parent); - - if ( ! isset(self::$reflections[$class_name])) - { - $r = new ReflectionObject($parent); - - foreach ($r->getMethods() as $method) - { - if ($method->isPublic()) - { - $this->methods[] = $method->getName(); - } - } - - foreach ($r->getProperties() as $prop) - { - if ($prop->isPublic()) - { - $this->properties[] = $prop->getName(); - } - } - - self::$reflections[$class_name] = array($this->methods, $this->properties); - } - else - { - list($this->methods, $this->properties) = self::$reflections[$class_name]; - } - } - - // -------------------------------------------------------------------- - - /** - * __call magic method - * - * Handles access to the parent driver library's methods - * - * @access public - * @param string - * @param array - * @return mixed - */ - public function __call($method, $args = array()) - { - if (in_array($method, $this->methods)) - { - return call_user_func_array(array($this->parent, $method), $args); - } - - $trace = debug_backtrace(); - _exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']); - exit; - } - - // -------------------------------------------------------------------- - - /** - * __get magic method - * - * Handles reading of the parent driver library's properties - * - * @param string - * @return mixed - */ - public function __get($var) - { - if (in_array($var, $this->properties)) - { - return $this->parent->$var; - } - } - - // -------------------------------------------------------------------- - - /** - * __set magic method - * - * Handles writing to the parent driver library's properties - * - * @param string - * @param array - * @return mixed - */ - public function __set($var, $val) - { - if (in_array($var, $this->properties)) - { - $this->parent->$var = $val; - } - } -} -// END CI_Driver CLASS + /** + * Instance of the parent class + * + * @var object + */ + protected $_parent; + + /** + * List of methods in the parent class + * + * @var array + */ + protected $_methods = array(); + + /** + * List of properties in the parent class + * + * @var array + */ + protected $_properties = array(); + + /** + * Array of methods and properties for the parent class(es) + * + * @static + * @var array + */ + protected static $_reflections = array(); + + /** + * Decorate + * + * Decorates the child with the parent driver lib's methods and properties + * + * @param object + * @return void + */ + public function decorate($parent) + { + $this->_parent = $parent; + + // Lock down attributes to what is defined in the class + // and speed up references in magic methods + + $class_name = get_class($parent); + + if ( ! isset(self::$_reflections[$class_name])) + { + $r = new ReflectionObject($parent); + + foreach ($r->getMethods() as $method) + { + if ($method->isPublic()) + { + $this->_methods[] = $method->getName(); + } + } + + foreach ($r->getProperties() as $prop) + { + if ($prop->isPublic()) + { + $this->_properties[] = $prop->getName(); + } + } + + self::$_reflections[$class_name] = array($this->_methods, $this->_properties); + } + else + { + list($this->_methods, $this->_properties) = self::$_reflections[$class_name]; + } + } + + // -------------------------------------------------------------------- + + /** + * __call magic method + * + * Handles access to the parent driver library's methods + * + * @param string + * @param array + * @return mixed + */ + public function __call($method, $args = array()) + { + if (in_array($method, $this->_methods)) + { + return call_user_func_array(array($this->_parent, $method), $args); + } + + throw new BadMethodCallException('No such method: '.$method.'()'); + } + + // -------------------------------------------------------------------- + + /** + * __get magic method + * + * Handles reading of the parent driver library's properties + * + * @param string + * @return mixed + */ + public function __get($var) + { + if (in_array($var, $this->_properties)) + { + return $this->_parent->$var; + } + } + + // -------------------------------------------------------------------- + + /** + * __set magic method + * + * Handles writing to the parent driver library's properties + * + * @param string + * @param array + * @return mixed + */ + public function __set($var, $val) + { + if (in_array($var, $this->_properties)) + { + $this->_parent->$var = $val; + } + } -/* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ \ No newline at end of file +} diff --git a/system/libraries/Email.php b/system/libraries/Email.php old mode 100755 new mode 100644 index 6b5f803..10b7477 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,2093 +1,2490 @@ - 0) - { - $this->initialize($config); - } - else - { - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - } - - log_message('debug', "Email Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - public function initialize($config = array()) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $method = 'set_'.$key; - - if (method_exists($this, $method)) - { - $this->$method($val); - } - else - { - $this->$key = $val; - } - } - } - $this->clear(); - - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - public function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = array(); - $this->_cc_array = array(); - $this->_bcc_array = array(); - $this->_headers = array(); - $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); - $this->_set_header('Date', $this->_set_date()); - - if ($clear_attachments !== FALSE) - { - $this->_attach_name = array(); - $this->_attach_type = array(); - $this->_attach_disp = array(); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - public function from($from, $name = '') - { - if (preg_match( '/\<(.*)\>/', $from, $match)) - { - $from = $match['1']; - } - - if ($this->validate) - { - $this->validate_email($this->_str_to_array($from)); - } - - // prepare the display name - if ($name != '') - { - // only use Q encoding if there are characters that would require it - if ( ! preg_match('/[\200-\377]/', $name)) - { - // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes - $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; - } - else - { - $name = $this->_prep_q_encoding($name, TRUE); - } - } - - $this->_set_header('From', $name.' <'.$from.'>'); - $this->_set_header('Return-Path', '<'.$from.'>'); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - public function reply_to($replyto, $name = '') - { - if (preg_match( '/\<(.*)\>/', $replyto, $match)) - { - $replyto = $match['1']; - } - - if ($this->validate) - { - $this->validate_email($this->_str_to_array($replyto)); - } - - if ($name == '') - { - $name = $replyto; - } - - if (strncmp($name, '"', 1) != 0) - { - $name = '"'.$name.'"'; - } - - $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); - $this->_replyto_flag = TRUE; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - public function to($to) - { - $to = $this->_str_to_array($to); - $to = $this->clean_email($to); - - if ($this->validate) - { - $this->validate_email($to); - } - - if ($this->_get_protocol() != 'mail') - { - $this->_set_header('To', implode(", ", $to)); - } - - switch ($this->_get_protocol()) - { - case 'smtp' : - $this->_recipients = $to; - break; - case 'sendmail' : - case 'mail' : - $this->_recipients = implode(", ", $to); - break; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - public function cc($cc) - { - $cc = $this->_str_to_array($cc); - $cc = $this->clean_email($cc); - - if ($this->validate) - { - $this->validate_email($cc); - } - - $this->_set_header('Cc', implode(", ", $cc)); - - if ($this->_get_protocol() == "smtp") - { - $this->_cc_array = $cc; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - public function bcc($bcc, $limit = '') - { - if ($limit != '' && is_numeric($limit)) - { - $this->bcc_batch_mode = TRUE; - $this->bcc_batch_size = $limit; - } - - $bcc = $this->_str_to_array($bcc); - $bcc = $this->clean_email($bcc); - - if ($this->validate) - { - $this->validate_email($bcc); - } - - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) - { - $this->_bcc_array = $bcc; - } - else - { - $this->_set_header('Bcc', implode(", ", $bcc)); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - public function subject($subject) - { - $subject = $this->_prep_q_encoding($subject); - $this->_set_header('Subject', $subject); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return void - */ - public function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access protected - * @param string - * @param string - * @return void - */ - protected function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access protected - * @param string - * @return array - */ - protected function _str_to_array($email) - { - if ( ! is_array($email)) - { - if (strpos($email, ',') !== FALSE) - { - $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); - } - else - { - $email = trim($email); - settype($email, "array"); - } - } - return $email; - } - - // -------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @access public - * @param string - * @return void - */ - public function set_alt_message($str = '') - { - $this->alt_message = $str; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - public function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - public function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - public function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - public function set_priority($n = 3) - { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) - { - $this->priority = 3; - return; - } - - $this->priority = $n; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - public function set_newline($newline = "\n") - { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set CRLF - * - * @access public - * @param string - * @return void - */ - public function set_crlf($crlf = "\n") - { - if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") - { - $this->crlf = "\n"; - return; - } - - $this->crlf = $crlf; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access protected - * @return void - */ - protected function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access protected - * @return string - */ - protected function _get_message_id() - { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); - - return "<".uniqid('').strstr($from, '@').">"; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Protocol - * - * @access protected - * @param bool - * @return string - */ - protected function _get_protocol($return = TRUE) - { - $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - - if ($return == TRUE) - { - return $this->protocol; - } - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Encoding - * - * @access protected - * @param bool - * @return string - */ - protected function _get_encoding($return = TRUE) - { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; - - foreach ($this->_base_charsets as $charset) - { - if (strncmp($charset, $this->charset, strlen($charset)) == 0) - { - $this->_encoding = '7bit'; - } - } - - if ($return == TRUE) - { - return $this->_encoding; - } - } - - // -------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @access protected - * @return string - */ - protected function _get_content_type() - { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) - { - return 'html'; - } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) - { - return 'html-attach'; - } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) - { - return 'plain-attach'; - } - else - { - return 'plain'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set RFC 822 Date - * - * @access protected - * @return string - */ - protected function _set_date() - { - $timezone = date("Z"); - $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; - $timezone = abs($timezone); - $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; - - return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); - } - - // -------------------------------------------------------------------- - - /** - * Mime message - * - * @access protected - * @return string - */ - protected function _get_mime_message() - { - return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; - } - - // -------------------------------------------------------------------- - - /** - * Validate Email Address - * - * @access public - * @param string - * @return bool - */ - public function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('lang:email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('lang:email_invalid_address', $val); - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - public function valid_email($address) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @access public - * @param string - * @return string - */ - public function clean_email($email) - { - if ( ! is_array($email)) - { - if (preg_match('/\<(.*)\>/', $email, $match)) - { - return $match['1']; - } - else - { - return $email; - } - } - - $clean_email = array(); - - foreach ($email as $addy) - { - if (preg_match( '/\<(.*)\>/', $addy, $match)) - { - $clean_email[] = $match['1']; - } - else - { - $clean_email[] = $addy; - } - } - - return $clean_email; - } - - // -------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * This public function provides the raw message for use - * in plain-text headers of HTML-formatted emails. - * If the user hasn't specified his own alternative message - * it creates one by stripping the HTML - * - * @access protected - * @return string - */ - protected function _get_alt_message() - { - if ($this->alt_message != "") - { - return $this->word_wrap($this->alt_message, '76'); - } - - if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) - { - $body = $match['1']; - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '# '.$msg."\n"; - - flock($fp, LOCK_EX); - fwrite($fp, $message); - flock($fp, LOCK_UN); - fclose($fp); - - @chmod($filepath, FILE_WRITE_MODE); - return TRUE; - } - -} -// END Log Class - -/* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php old mode 100755 new mode 100644 index eedaede..1b78089 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -1,20 +1,41 @@ - $val) - { - $this->{'_' . $key} = $val; - } - - log_message('debug', 'Migrations class initialized'); - - // Are they trying to use migrations while it is disabled? - if ($this->_migration_enabled !== TRUE) - { - show_error('Migrations has been loaded but is disabled or set up incorrectly.'); - } - - // If not set, set it - $this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/'; - - // Add trailing slash if not set - $this->_migration_path = rtrim($this->_migration_path, '/').'/'; - - // Load migration language - $this->lang->load('migration'); - - // They'll probably be using dbforge - $this->load->dbforge(); - - // If the migrations table is missing, make it - if ( ! $this->db->table_exists('migrations')) - { - $this->dbforge->add_field(array( - 'version' => array('type' => 'INT', 'constraint' => 3), - )); - - $this->dbforge->create_table('migrations', TRUE); - - $this->db->insert('migrations', array('version' => 0)); - } - } - - // -------------------------------------------------------------------- - - /** - * Migrate to a schema version - * - * Calls each migration step required to get to the schema version of - * choice - * - * @param int Target schema version - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded - */ - public function version($target_version) - { - $start = $current_version = $this->_get_version(); - $stop = $target_version; - - if ($target_version > $current_version) - { - // Moving Up - ++$start; - ++$stop; - $step = 1; - } - else - { - // Moving Down - $step = -1; - } - - $method = ($step === 1) ? 'up' : 'down'; - $migrations = array(); - - // We now prepare to actually DO the migrations - // But first let's make sure that everything is the way it should be - for ($i = $start; $i != $stop; $i += $step) - { - $f = glob(sprintf($this->_migration_path . '%03d_*.php', $i)); - - // Only one migration per step is permitted - if (count($f) > 1) - { - $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $i); - return FALSE; - } - - // Migration step not found - if (count($f) == 0) - { - // If trying to migrate up to a version greater than the last - // existing one, migrate to the last one. - if ($step == 1) - { - break; - } - - // If trying to migrate down but we're missing a step, - // something must definitely be wrong. - $this->_error_string = sprintf($this->lang->line('migration_not_found'), $i); - return FALSE; - } - - $file = basename($f[0]); - $name = basename($f[0], '.php'); - - // Filename validations - if (preg_match('/^\d{3}_(\w+)$/', $name, $match)) - { - $match[1] = strtolower($match[1]); - - // Cannot repeat a migration at different steps - if (in_array($match[1], $migrations)) - { - $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $match[1]); - return FALSE; - } - - include $f[0]; - $class = 'Migration_' . ucfirst($match[1]); - - if ( ! class_exists($class)) - { - $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); - return FALSE; - } - - if ( ! is_callable(array($class, $method))) - { - $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); - return FALSE; - } - - $migrations[] = $match[1]; - } - else - { - $this->_error_string = sprintf($this->lang->line('migration_invalid_filename'), $file); - return FALSE; - } - } - - log_message('debug', 'Current migration: ' . $current_version); - - $version = $i + ($step == 1 ? -1 : 0); - - // If there is nothing to do so quit - if ($migrations === array()) - { - return TRUE; - } - - log_message('debug', 'Migrating from ' . $method . ' to version ' . $version); - - // Loop through the migrations - foreach ($migrations AS $migration) - { - // Run the migration class - $class = 'Migration_' . ucfirst(strtolower($migration)); - call_user_func(array(new $class, $method)); - - $current_version += $step; - $this->_update_version($current_version); - } - - log_message('debug', 'Finished migrating to '.$current_version); - - return $current_version; - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the latest migration - * - * @return mixed true if already latest, false if failed, int if upgraded - */ - public function latest() - { - if ( ! $migrations = $this->find_migrations()) - { - $this->_error_string = $this->lang->line('migration_none_found'); - return false; - } - - $last_migration = basename(end($migrations)); - - // Calculate the last migration step from existing migration - // filenames and procceed to the standard version migration - return $this->version((int) substr($last_migration, 0, 3)); - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the migration version set in config - * - * @return mixed true if already current, false if failed, int if upgraded - */ - public function current() - { - return $this->version($this->_migration_version); - } - - // -------------------------------------------------------------------- - - /** - * Error string - * - * @return string Error message returned as a string - */ - public function error_string() - { - return $this->_error_string; - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the latest migration - * - * @return mixed true if already latest, false if failed, int if upgraded - */ - protected function find_migrations() - { - // Load all *_*.php files in the migrations path - $files = glob($this->_migration_path . '*_*.php'); - $file_count = count($files); - - for ($i = 0; $i < $file_count; $i++) - { - // Mark wrongly formatted files as false for later filtering - $name = basename($files[$i], '.php'); - if ( ! preg_match('/^\d{3}_(\w+)$/', $name)) - { - $files[$i] = FALSE; - } - } - - sort($files); - return $files; - } - - // -------------------------------------------------------------------- - - /** - * Retrieves current schema version - * - * @return int Current Migration - */ - protected function _get_version() - { - $row = $this->db->get('migrations')->row(); - return $row ? $row->version : 0; - } - - // -------------------------------------------------------------------- - - /** - * Stores the current schema version - * - * @param int Migration reached - * @return bool - */ - protected function _update_version($migrations) - { - return $this->db->update('migrations', array( - 'version' => $migrations - )); - } - - // -------------------------------------------------------------------- - - /** - * Enable the use of CI super-global - * - * @param mixed $var - * @return mixed - */ - public function __get($var) - { - return get_instance()->$var; - } + /** + * Whether the library is enabled + * + * @var bool + */ + protected $_migration_enabled = FALSE; + + /** + * Migration numbering type + * + * @var bool + */ + protected $_migration_type = 'sequential'; + + /** + * Path to migration classes + * + * @var string + */ + protected $_migration_path = NULL; + + /** + * Current migration version + * + * @var mixed + */ + protected $_migration_version = 0; + + /** + * Database table with migration info + * + * @var string + */ + protected $_migration_table = 'migrations'; + + /** + * Whether to automatically run migrations + * + * @var bool + */ + protected $_migration_auto_latest = FALSE; + + /** + * Migration basename regex + * + * @var string + */ + protected $_migration_regex; + + /** + * Error message + * + * @var string + */ + protected $_error_string = ''; + + /** + * Initialize Migration Class + * + * @param array $config + * @return void + */ + public function __construct($config = array()) + { + // Only run this constructor on main library load + if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE)) + { + return; + } + + foreach ($config as $key => $val) + { + $this->{'_'.$key} = $val; + } + + log_message('info', 'Migrations Class Initialized'); + + // Are they trying to use migrations while it is disabled? + if ($this->_migration_enabled !== TRUE) + { + show_error('Migrations has been loaded but is disabled or set up incorrectly.'); + } + + // If not set, set it + $this->_migration_path !== '' OR $this->_migration_path = APPPATH.'migrations/'; + + // Add trailing slash if not set + $this->_migration_path = rtrim($this->_migration_path, '/').'/'; + + // Load migration language + $this->lang->load('migration'); + + // They'll probably be using dbforge + $this->load->dbforge(); + + // Make sure the migration table name was set. + if (empty($this->_migration_table)) + { + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); + } + + // Migration basename regex + $this->_migration_regex = ($this->_migration_type === 'timestamp') + ? '/^\d{14}_(\w+)$/' + : '/^\d{3}_(\w+)$/'; + + // Make sure a valid migration numbering type was set. + if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) + { + show_error('An invalid migration numbering type was specified: '.$this->_migration_type); + } + + // If the migrations table is missing, make it + if ( ! $this->db->table_exists($this->_migration_table)) + { + $this->dbforge->add_field(array( + 'version' => array('type' => 'BIGINT', 'constraint' => 20), + )); + + $this->dbforge->create_table($this->_migration_table, TRUE); + + $this->db->insert($this->_migration_table, array('version' => 0)); + } + + // Do we auto migrate to the latest migration? + if ($this->_migration_auto_latest === TRUE && ! $this->latest()) + { + show_error($this->error_string()); + } + } + + // -------------------------------------------------------------------- + + /** + * Migrate to a schema version + * + * Calls each migration step required to get to the schema version of + * choice + * + * @param string $target_version Target schema version + * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure + */ + public function version($target_version) + { + // Note: We use strings, so that timestamp versions work on 32-bit systems + $current_version = $this->_get_version(); + + if ($this->_migration_type === 'sequential') + { + $target_version = sprintf('%03d', $target_version); + } + else + { + $target_version = (string) $target_version; + } + + $migrations = $this->find_migrations(); + + if ($target_version > 0 && ! isset($migrations[$target_version])) + { + $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); + return FALSE; + } + + if ($target_version > $current_version) + { + $method = 'up'; + } + elseif ($target_version < $current_version) + { + $method = 'down'; + // We need this so that migrations are applied in reverse order + krsort($migrations); + } + else + { + // Well, there's nothing to migrate then ... + return TRUE; + } + + // Validate all available migrations within our target range. + // + // Unfortunately, we'll have to use another loop to run them + // in order to avoid leaving the procedure in a broken state. + // + // See https://github.com/bcit-ci/CodeIgniter/issues/4539 + $pending = array(); + foreach ($migrations as $number => $file) + { + // Ignore versions out of our range. + // + // Because we've previously sorted the $migrations array depending on the direction, + // we can safely break the loop once we reach $target_version ... + if ($method === 'up') + { + if ($number <= $current_version) + { + continue; + } + elseif ($number > $target_version) + { + break; + } + } + else + { + if ($number > $current_version) + { + continue; + } + elseif ($number <= $target_version) + { + break; + } + } + + // Check for sequence gaps + if ($this->_migration_type === 'sequential') + { + if (isset($previous) && abs($number - $previous) > 1) + { + $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); + return FALSE; + } + + $previous = $number; + } + + include_once($file); + $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); + + // Validate the migration file structure + if ( ! class_exists($class, FALSE)) + { + $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); + return FALSE; + } + elseif ( ! is_callable(array($class, $method))) + { + $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); + return FALSE; + } + + $pending[$number] = array($class, $method); + } + + // Now just run the necessary migrations + foreach ($pending as $number => $migration) + { + log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); + + $migration[0] = new $migration[0]; + call_user_func($migration); + $current_version = $number; + $this->_update_version($current_version); + } + + // This is necessary when moving down, since the the last migration applied + // will be the down() method for the next migration up from the target + if ($current_version <> $target_version) + { + $current_version = $target_version; + $this->_update_version($current_version); + } + + log_message('debug', 'Finished migrating to '.$current_version); + return $current_version; + } + + // -------------------------------------------------------------------- + + /** + * Sets the schema to the latest migration + * + * @return mixed Current version string on success, FALSE on failure + */ + public function latest() + { + $migrations = $this->find_migrations(); + + if (empty($migrations)) + { + $this->_error_string = $this->lang->line('migration_none_found'); + return FALSE; + } + + $last_migration = basename(end($migrations)); + + // Calculate the last migration step from existing migration + // filenames and proceed to the standard version migration + return $this->version($this->_get_migration_number($last_migration)); + } + + // -------------------------------------------------------------------- + + /** + * Sets the schema to the migration version set in config + * + * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure + */ + public function current() + { + return $this->version($this->_migration_version); + } + + // -------------------------------------------------------------------- + + /** + * Error string + * + * @return string Error message returned as a string + */ + public function error_string() + { + return $this->_error_string; + } + + // -------------------------------------------------------------------- + + /** + * Retrieves list of available migration scripts + * + * @return array list of migration file paths sorted by version + */ + public function find_migrations() + { + $migrations = array(); + + // Load all *_*.php files in the migrations path + foreach (glob($this->_migration_path.'*_*.php') as $file) + { + $name = basename($file, '.php'); + + // Filter out non-migration files + if (preg_match($this->_migration_regex, $name)) + { + $number = $this->_get_migration_number($name); + + // There cannot be duplicate migration numbers + if (isset($migrations[$number])) + { + $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number); + show_error($this->_error_string); + } + + $migrations[$number] = $file; + } + } + + ksort($migrations); + return $migrations; + } + + // -------------------------------------------------------------------- + + /** + * Extracts the migration number from a filename + * + * @param string $migration + * @return string Numeric portion of a migration filename + */ + protected function _get_migration_number($migration) + { + return sscanf($migration, '%[0-9]+', $number) + ? $number : '0'; + } + + // -------------------------------------------------------------------- + + /** + * Extracts the migration class name from a filename + * + * @param string $migration + * @return string text portion of a migration filename + */ + protected function _get_migration_name($migration) + { + $parts = explode('_', $migration); + array_shift($parts); + return implode('_', $parts); + } + + // -------------------------------------------------------------------- + + /** + * Retrieves current schema version + * + * @return string Current migration version + */ + protected function _get_version() + { + $row = $this->db->select('version')->get($this->_migration_table)->row(); + return $row ? $row->version : '0'; + } + + // -------------------------------------------------------------------- + + /** + * Stores the current schema version + * + * @param string $migration Migration reached + * @return void + */ + protected function _update_version($migration) + { + $this->db->update($this->_migration_table, array( + 'version' => $migration + )); + } + + // -------------------------------------------------------------------- + + /** + * Enable the use of CI super-global + * + * @param string $var + * @return mixed + */ + public function __get($var) + { + return get_instance()->$var; + } } - -/* End of file Migration.php */ -/* Location: ./system/libraries/Migration.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php old mode 100755 new mode 100644 index 662e3d2..5d501a9 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,341 +1,704 @@ -'; - var $cur_tag_close = ''; - var $next_tag_open = ' '; - var $next_tag_close = ' '; - var $prev_tag_open = ' '; - var $prev_tag_close = ''; - var $num_tag_open = ' '; - var $num_tag_close = ''; - var $page_query_string = FALSE; - var $query_string_segment = 'per_page'; - var $display_pages = TRUE; - var $anchor_class = ''; - - /** - * Constructor - * - * @access public - * @param array initialization parameters - */ - public function __construct($params = array()) - { - if (count($params) > 0) - { - $this->initialize($params); - } - - if ($this->anchor_class != '') - { - $this->anchor_class = 'class="'.$this->anchor_class.'" '; - } - - log_message('debug', "Pagination Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Preferences - * - * @access public - * @param array initialization parameters - * @return void - */ - function initialize($params = array()) - { - if (count($params) > 0) - { - foreach ($params as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Generate the pagination links - * - * @access public - * @return string - */ - function create_links() - { - // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows == 0 OR $this->per_page == 0) - { - return ''; - } - - // Calculate the total number of pages - $num_pages = ceil($this->total_rows / $this->per_page); - - // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) - { - return ''; - } - - // Set the base page index for starting page number - if ($this->use_page_numbers) - { - $base_page = 1; - } - else - { - $base_page = 0; - } - - // Determine the current page number. - $CI =& get_instance(); - - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - if ($CI->input->get($this->query_string_segment) != $base_page) - { - $this->cur_page = $CI->input->get($this->query_string_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } - } - else - { - if ($CI->uri->segment($this->uri_segment) != $base_page) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } - } - - // Set current page to 1 if using page numbers instead of offset - if ($this->use_page_numbers AND $this->cur_page == 0) - { - $this->cur_page = $base_page; - } - - $this->num_links = (int)$this->num_links; - - if ($this->num_links < 1) - { - show_error('Your number of links must be a positive number.'); - } - - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = $base_page; - } - - // Is the page number beyond the result range? - // If so we show the last page - if ($this->use_page_numbers) - { - if ($this->cur_page > $num_pages) - { - $this->cur_page = $num_pages; - } - } - else - { - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } - } - - $uri_page_number = $this->cur_page; - - if ( ! $this->use_page_numbers) - { - $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); - } - - // Calculate the start and end numbers. These determine - // which number to start and end the digit links with - $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - - // Is pagination being used over GET or POST? If get, add a per_page query - // string. If post, add a trailing slash to the base URL if needed - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; - } - else - { - $this->base_url = rtrim($this->base_url, '/') .'/'; - } - - // And here we go... - $output = ''; - - // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) - { - $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; - } - - // Render the "previous" link - if ($this->prev_link !== FALSE AND $this->cur_page != 1) - { - if ($this->use_page_numbers) - { - $i = $uri_page_number - 1; - } - else - { - $i = $uri_page_number - $this->per_page; - } - - if ($i == 0 && $this->first_url != '') - { - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; - } - else - { - $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; - } - - } - - // Render the pages - if ($this->display_pages !== FALSE) - { - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { - if ($this->use_page_numbers) - { - $i = $loop; - } - else - { - $i = ($loop * $this->per_page) - $this->per_page; - } - - if ($i >= $base_page) - { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else - { - $n = ($i == $base_page) ? '' : $i; - - if ($n == '' && $this->first_url != '') - { - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; - } - else - { - $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; - - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; - } - } - } - } - } - - // Render the "next" link - if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) - { - if ($this->use_page_numbers) - { - $i = $this->cur_page + 1; - } - else - { - $i = ($this->cur_page * $this->per_page); - } - - $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; - } - - // Render the "Last" link - if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) - { - if ($this->use_page_numbers) - { - $i = $num_pages; - } - else - { - $i = (($num_pages * $this->per_page) - $this->per_page); - } - $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; - } - - // Kill double slashes. Note: Sometimes we can end up with a double slash - // in the penultimate link so we'll kill all double slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); - - // Add the wrapper HTML if exists - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; - } -} -// END Pagination Class + /** + * Base URL + * + * The page that we're linking to + * + * @var string + */ + protected $base_url = ''; + + /** + * Prefix + * + * @var string + */ + protected $prefix = ''; + + /** + * Suffix + * + * @var string + */ + protected $suffix = ''; + + /** + * Total number of items + * + * @var int + */ + protected $total_rows = 0; + + /** + * Number of links to show + * + * Relates to "digit" type links shown before/after + * the currently viewed page. + * + * @var int + */ + protected $num_links = 2; + + /** + * Items per page + * + * @var int + */ + public $per_page = 10; + + /** + * Current page + * + * @var int + */ + public $cur_page = 0; + + /** + * Use page numbers flag + * + * Whether to use actual page numbers instead of an offset + * + * @var bool + */ + protected $use_page_numbers = FALSE; + + /** + * First link + * + * @var string + */ + protected $first_link = '‹ First'; + + /** + * Next link + * + * @var string + */ + protected $next_link = '>'; + + /** + * Previous link + * + * @var string + */ + protected $prev_link = '<'; + + /** + * Last link + * + * @var string + */ + protected $last_link = 'Last ›'; + + /** + * URI Segment + * + * @var int + */ + protected $uri_segment = 0; + + /** + * Full tag open + * + * @var string + */ + protected $full_tag_open = ''; + + /** + * Full tag close + * + * @var string + */ + protected $full_tag_close = ''; + + /** + * First tag open + * + * @var string + */ + protected $first_tag_open = ''; + + /** + * First tag close + * + * @var string + */ + protected $first_tag_close = ''; + + /** + * Last tag open + * + * @var string + */ + protected $last_tag_open = ''; + + /** + * Last tag close + * + * @var string + */ + protected $last_tag_close = ''; + + /** + * First URL + * + * An alternative URL for the first page + * + * @var string + */ + protected $first_url = ''; + + /** + * Current tag open + * + * @var string + */ + protected $cur_tag_open = ''; + + /** + * Current tag close + * + * @var string + */ + protected $cur_tag_close = ''; + + /** + * Next tag open + * + * @var string + */ + protected $next_tag_open = ''; + + /** + * Next tag close + * + * @var string + */ + protected $next_tag_close = ''; + + /** + * Previous tag open + * + * @var string + */ + protected $prev_tag_open = ''; + + /** + * Previous tag close + * + * @var string + */ + protected $prev_tag_close = ''; + + /** + * Number tag open + * + * @var string + */ + protected $num_tag_open = ''; + + /** + * Number tag close + * + * @var string + */ + protected $num_tag_close = ''; + + /** + * Page query string flag + * + * @var bool + */ + protected $page_query_string = FALSE; + + /** + * Query string segment + * + * @var string + */ + protected $query_string_segment = 'per_page'; + + /** + * Display pages flag + * + * @var bool + */ + protected $display_pages = TRUE; + + /** + * Attributes + * + * @var string + */ + protected $_attributes = ''; + + /** + * Link types + * + * "rel" attribute + * + * @see CI_Pagination::_attr_rel() + * @var array + */ + protected $_link_types = array(); + + /** + * Reuse query string flag + * + * @var bool + */ + protected $reuse_query_string = FALSE; + + /** + * Use global URL suffix flag + * + * @var bool + */ + protected $use_global_url_suffix = FALSE; + + /** + * Data page attribute + * + * @var string + */ + protected $data_page_attr = 'data-ci-pagination-page'; + + /** + * CI Singleton + * + * @var object + */ + protected $CI; + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param array $params Initialization parameters + * @return void + */ + public function __construct($params = array()) + { + $this->CI =& get_instance(); + $this->CI->load->language('pagination'); + foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) + { + if (($val = $this->CI->lang->line('pagination_'.$key)) !== FALSE) + { + $this->$key = $val; + } + } + + // _parse_attributes(), called by initialize(), needs to run at least once + // in order to enable "rel" attributes, and this triggers it. + isset($params['attributes']) OR $params['attributes'] = array(); + + $this->initialize($params); + log_message('info', 'Pagination Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Preferences + * + * @param array $params Initialization parameters + * @return CI_Pagination + */ + public function initialize(array $params = array()) + { + if (isset($params['attributes']) && is_array($params['attributes'])) + { + $this->_parse_attributes($params['attributes']); + unset($params['attributes']); + } + + // Deprecated legacy support for the anchor_class option + // Should be removed in CI 3.1+ + if (isset($params['anchor_class'])) + { + empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class']; + unset($params['anchor_class']); + } + + foreach ($params as $key => $val) + { + if (property_exists($this, $key)) + { + $this->$key = $val; + } + } + + if ($this->CI->config->item('enable_query_strings') === TRUE) + { + $this->page_query_string = TRUE; + } + + if ($this->use_global_url_suffix === TRUE) + { + $this->suffix = $this->CI->config->item('url_suffix'); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Generate the pagination links + * + * @return string + */ + public function create_links() + { + // If our item count or per-page total is zero there is no need to continue. + // Note: DO NOT change the operator to === here! + if ($this->total_rows == 0 OR $this->per_page == 0) + { + return ''; + } + + // Calculate the total number of pages + $num_pages = (int) ceil($this->total_rows / $this->per_page); + + // Is there only one page? Hm... nothing more to do here then. + if ($num_pages === 1) + { + return ''; + } + + // Check the user defined number of links. + $this->num_links = (int) $this->num_links; + + if ($this->num_links < 0) + { + show_error('Your number of links must be a non-negative number.'); + } + + // Keep any existing query string items. + // Note: Has nothing to do with any other query string option. + if ($this->reuse_query_string === TRUE) + { + $get = $this->CI->input->get(); + + // Unset the control, method, old-school routing options + unset($get['c'], $get['m'], $get[$this->query_string_segment]); + } + else + { + $get = array(); + } + + // Put together our base and first URLs. + // Note: DO NOT append to the properties as that would break successive calls + $base_url = trim($this->base_url); + $first_url = $this->first_url; + + $query_string = ''; + $query_string_sep = (strpos($base_url, '?') === FALSE) ? '?' : '&'; + + // Are we using query strings? + if ($this->page_query_string === TRUE) + { + // If a custom first_url hasn't been specified, we'll create one from + // the base_url, but without the page item. + if ($first_url === '') + { + $first_url = $base_url; + + // If we saved any GET items earlier, make sure they're appended. + if ( ! empty($get)) + { + $first_url .= $query_string_sep.http_build_query($get); + } + } + + // Add the page segment to the end of the query string, where the + // page number will be appended. + $base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); + } + else + { + // Standard segment mode. + // Generate our saved query string to append later after the page number. + if ( ! empty($get)) + { + $query_string = $query_string_sep.http_build_query($get); + $this->suffix .= $query_string; + } + + // Does the base_url have the query string in it? + // If we're supposed to save it, remove it so we can append it later. + if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($base_url, '?')) !== FALSE) + { + $base_url = substr($base_url, 0, $base_query_pos); + } + + if ($first_url === '') + { + $first_url = $base_url.$query_string; + } + + $base_url = rtrim($base_url, '/').'/'; + } + + // Determine the current page number. + $base_page = ($this->use_page_numbers) ? 1 : 0; + + // Are we using query strings? + if ($this->page_query_string === TRUE) + { + $this->cur_page = $this->CI->input->get($this->query_string_segment); + } + elseif (empty($this->cur_page)) + { + // Default to the last segment number if one hasn't been defined. + if ($this->uri_segment === 0) + { + $this->uri_segment = count($this->CI->uri->segment_array()); + } + + $this->cur_page = $this->CI->uri->segment($this->uri_segment); + + // Remove any specified prefix/suffix from the segment. + if ($this->prefix !== '' OR $this->suffix !== '') + { + $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $this->cur_page); + } + } + else + { + $this->cur_page = (string) $this->cur_page; + } + + // If something isn't quite right, back to the default base page. + if ( ! ctype_digit($this->cur_page) OR ($this->use_page_numbers && (int) $this->cur_page === 0)) + { + $this->cur_page = $base_page; + } + else + { + // Make sure we're using integers for comparisons later. + $this->cur_page = (int) $this->cur_page; + } + + // Is the page number beyond the result range? + // If so, we show the last page. + if ($this->use_page_numbers) + { + if ($this->cur_page > $num_pages) + { + $this->cur_page = $num_pages; + } + } + elseif ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } + + $uri_page_number = $this->cur_page; + + // If we're using offset instead of page numbers, convert it + // to a page number, so we can generate the surrounding number links. + if ( ! $this->use_page_numbers) + { + $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1); + } + + // Calculate the start and end numbers. These determine + // which number to start and end the digit links with. + $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + + // And here we go... + $output = ''; + + // Render the "First" link. + if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1 + ! $this->num_links)) + { + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + + $output .= $this->first_tag_open.'_attr_rel('start').'>' + .$this->first_link.''.$this->first_tag_close; + } + + // Render the "Previous" link. + if ($this->prev_link !== FALSE && $this->cur_page !== 1) + { + $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; + + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, ($this->cur_page - 1)); + + if ($i === $base_page) + { + // First page + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + .$this->prev_link.''.$this->prev_tag_close; + } + else + { + $append = $this->prefix.$i.$this->suffix; + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + .$this->prev_link.''.$this->prev_tag_close; + } + + } + + // Render the pages + if ($this->display_pages !== FALSE) + { + // Write the digit links + for ($loop = $start - 1; $loop <= $end; $loop++) + { + $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; + + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $loop); + + if ($i >= $base_page) + { + if ($this->cur_page === $loop) + { + // Current page + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; + } + elseif ($i === $base_page) + { + // First page + $output .= $this->num_tag_open.'_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; + } + else + { + $append = $this->prefix.$i.$this->suffix; + $output .= $this->num_tag_open.'' + .$loop.''.$this->num_tag_close; + } + } + } + } + + // Render the "next" link + if ($this->next_link !== FALSE && $this->cur_page < $num_pages) + { + $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; + + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $this->cur_page + 1); + + $output .= $this->next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links + ! $this->num_links) < $num_pages) + { + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $num_pages); + + $output .= $this->last_tag_open.'' + .$this->last_link.''.$this->last_tag_close; + } + + // Kill double slashes. Note: Sometimes we can end up with a double slash + // in the penultimate link so we'll kill all double slashes. + $output = preg_replace('#([^:"])//+#', '\\1/', $output); + + // Add the wrapper HTML if exists + return $this->full_tag_open.$output.$this->full_tag_close; + } + + // -------------------------------------------------------------------- + + /** + * Parse attributes + * + * @param array $attributes + * @return void + */ + protected function _parse_attributes($attributes) + { + isset($attributes['rel']) OR $attributes['rel'] = TRUE; + $this->_link_types = ($attributes['rel']) + ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') + : array(); + unset($attributes['rel']); + + $this->_attributes = ''; + foreach ($attributes as $key => $value) + { + $this->_attributes .= ' '.$key.'="'.$value.'"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Add "rel" attribute + * + * @link http://www.w3.org/TR/html5/links.html#linkTypes + * @param string $type + * @return string + */ + protected function _attr_rel($type) + { + if (isset($this->_link_types[$type])) + { + unset($this->_link_types[$type]); + return ' rel="'.$type.'"'; + } + + return ''; + } -/* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file +} diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php old mode 100755 new mode 100644 index 45bde7a..d3c6500 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,213 +1,248 @@ -load->view($template, $data, TRUE); - - return $this->_parse($template, $data, $return); - } - - // -------------------------------------------------------------------- - - /** - * Parse a String - * - * Parses pseudo-variables contained in the specified string, - * replacing them with the data in the second param - * - * @access public - * @param string - * @param array - * @param bool - * @return string - */ - function parse_string($template, $data, $return = FALSE) - { - return $this->_parse($template, $data, $return); - } - - // -------------------------------------------------------------------- - - /** - * Parse a template - * - * Parses pseudo-variables contained in the specified template, - * replacing them with the data in the second param - * - * @access public - * @param string - * @param array - * @param bool - * @return string - */ - function _parse($template, $data, $return = FALSE) - { - if ($template == '') - { - return FALSE; - } - - foreach ($data as $key => $val) - { - if (is_array($val)) - { - $template = $this->_parse_pair($key, $val, $template); - } - else - { - $template = $this->_parse_single($key, (string)$val, $template); - } - } - - if ($return == FALSE) - { - $CI =& get_instance(); - $CI->output->append_output($template); - } - - return $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the left/right variable delimiters - * - * @access public - * @param string - * @param string - * @return void - */ - function set_delimiters($l = '{', $r = '}') - { - $this->l_delim = $l; - $this->r_delim = $r; - } - - // -------------------------------------------------------------------- - - /** - * Parse a single key/value - * - * @access private - * @param string - * @param string - * @param string - * @return string - */ - function _parse_single($key, $val, $string) - { - return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); - } - - // -------------------------------------------------------------------- - - /** - * Parse a tag pair - * - * Parses tag pairs: {some_tag} string... {/some_tag} - * - * @access private - * @param string - * @param array - * @param string - * @return string - */ - function _parse_pair($variable, $data, $string) - { - if (FALSE === ($match = $this->_match_pair($string, $variable))) - { - return $string; - } - - $str = ''; - foreach ($data as $row) - { - $temp = $match['1']; - foreach ($row as $key => $val) - { - if ( ! is_array($val)) - { - $temp = $this->_parse_single($key, $val, $temp); - } - else - { - $temp = $this->_parse_pair($key, $val, $temp); - } - } - - $str .= $temp; - } - - return str_replace($match['0'], $str, $string); - } - - // -------------------------------------------------------------------- - - /** - * Matches a variable pair - * - * @access private - * @param string - * @param string - * @return mixed - */ - function _match_pair($string, $variable) - { - if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match)) - { - return FALSE; - } - - return $match; - } + /** + * Left delimiter character for pseudo vars + * + * @var string + */ + public $l_delim = '{'; + + /** + * Right delimiter character for pseudo vars + * + * @var string + */ + public $r_delim = '}'; + + /** + * Reference to CodeIgniter instance + * + * @var object + */ + protected $CI; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $this->CI =& get_instance(); + log_message('info', 'Parser Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Parse a template + * + * Parses pseudo-variables contained in the specified template view, + * replacing them with the data in the second param + * + * @param string + * @param array + * @param bool + * @return string + */ + public function parse($template, $data, $return = FALSE) + { + $template = $this->CI->load->view($template, $data, TRUE); + + return $this->_parse($template, $data, $return); + } + + // -------------------------------------------------------------------- + + /** + * Parse a String + * + * Parses pseudo-variables contained in the specified string, + * replacing them with the data in the second param + * + * @param string + * @param array + * @param bool + * @return string + */ + public function parse_string($template, $data, $return = FALSE) + { + return $this->_parse($template, $data, $return); + } + + // -------------------------------------------------------------------- + + /** + * Parse a template + * + * Parses pseudo-variables contained in the specified template, + * replacing them with the data in the second param + * + * @param string + * @param array + * @param bool + * @return string + */ + protected function _parse($template, $data, $return = FALSE) + { + if ($template === '') + { + return FALSE; + } + + $replace = array(); + foreach ($data as $key => $val) + { + $replace = array_merge( + $replace, + is_array($val) + ? $this->_parse_pair($key, $val, $template) + : $this->_parse_single($key, (string) $val, $template) + ); + } + + unset($data); + $template = strtr($template, $replace); + + if ($return === FALSE) + { + $this->CI->output->append_output($template); + } + + return $template; + } + + // -------------------------------------------------------------------- + + /** + * Set the left/right variable delimiters + * + * @param string + * @param string + * @return void + */ + public function set_delimiters($l = '{', $r = '}') + { + $this->l_delim = $l; + $this->r_delim = $r; + } + + // -------------------------------------------------------------------- + + /** + * Parse a single key/value + * + * @param string + * @param string + * @param string + * @return string + */ + protected function _parse_single($key, $val, $string) + { + return array($this->l_delim.$key.$this->r_delim => (string) $val); + } + + // -------------------------------------------------------------------- + + /** + * Parse a tag pair + * + * Parses tag pairs: {some_tag} string... {/some_tag} + * + * @param string + * @param array + * @param string + * @return string + */ + protected function _parse_pair($variable, $data, $string) + { + $replace = array(); + preg_match_all( + '#'.preg_quote($this->l_delim.$variable.$this->r_delim).'(.+?)'.preg_quote($this->l_delim.'/'.$variable.$this->r_delim).'#s', + $string, + $matches, + PREG_SET_ORDER + ); + + foreach ($matches as $match) + { + $str = ''; + foreach ($data as $row) + { + $temp = array(); + foreach ($row as $key => $val) + { + if (is_array($val)) + { + $pair = $this->_parse_pair($key, $val, $match[1]); + if ( ! empty($pair)) + { + $temp = array_merge($temp, $pair); + } + + continue; + } + + $temp[$this->l_delim.$key.$this->r_delim] = $val; + } + + $str .= strtr($match[1], $temp); + } + + $replace[$match[0]] = $str; + } + + return $replace; + } } -// END Parser Class - -/* End of file Parser.php */ -/* Location: ./system/libraries/Parser.php */ diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php old mode 100755 new mode 100644 index 0680f4f..77af7b9 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,20 +1,41 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - - if (isset($config['query_toggle_count'])) - { - $this->_query_toggle_count = (int) $config['query_toggle_count']; - unset($config['query_toggle_count']); - } - - // default all sections to display - foreach ($this->_available_sections as $section) - { - if ( ! isset($config[$section])) - { - $this->_compile_{$section} = TRUE; - } - } - - $this->set_sections($config); - } - - // -------------------------------------------------------------------- - - /** - * Set Sections - * - * Sets the private _compile_* properties to enable/disable Profiler sections - * - * @param mixed - * @return void - */ - public function set_sections($config) - { - foreach ($config as $method => $enable) - { - if (in_array($method, $this->_available_sections)) - { - $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identically (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @return array - */ - protected function _compile_benchmarks() - { - $profile = array(); - foreach ($this->CI->benchmark->marker as $key => $val) - { - // We match the "end" marker so that the list ends - // up in the order that it was defined - if (preg_match("/(.+?)_end/i", $key, $match)) - { - if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) - { - $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); - } - } - } - - // Build a table containing the profile data. - // Note: At some point we should turn this into a template that can - // be modified. We also might want to make this data available to be logged - - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
    ".$key."  ".$val."
    \n"; - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile Queries - * - * @return string - */ - protected function _compile_queries() - { - $dbs = array(); - - // Let's determine which databases are currently connected to - foreach (get_object_vars($this->CI) as $CI_object) - { - if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) - { - $dbs[] = $CI_object; - } - } - - if (count($dbs) == 0) - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - $output .="\n"; - $output .= "
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; - $output .= "
    "; - - return $output; - } - - // Load the text helper so we can highlight the SQL - $this->CI->load->helper('text'); - - // Key words we want bolded - $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); - - $output = "\n\n"; - - $count = 0; - - foreach ($dbs as $db) - { - $count++; - - $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - - $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; - - if ($hide_queries != '') - { - $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; - } - - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.''; - $output .= "\n"; - $output .= "\n\n\n"; - - if (count($db->queries) == 0) - { - $output .= "\n"; - } - else - { - foreach ($db->queries as $key => $val) - { - $time = number_format($db->query_times[$key], 4); - - $val = highlight_code($val, ENT_QUOTES); - - foreach ($highlight as $bold) - { - $val = str_replace($bold, ''.$bold.'', $val); - } - - $output .= "\n"; - } - } - - $output .= "
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$time."  ".$val."
    \n"; - $output .= "
    "; - - } - - return $output; - } - - - // -------------------------------------------------------------------- - - /** - * Compile $_GET Data - * - * @return string - */ - protected function _compile_get() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; - $output .= "\n"; - - if (count($_GET) == 0) - { - $output .= "
    ".$this->CI->lang->line('profiler_no_get')."
    "; - } - else - { - $output .= "\n\n\n"; - - foreach ($_GET as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
    $_GET[".$key."]   "; - if (is_array($val)) - { - $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; - } - else - { - $output .= htmlspecialchars(stripslashes($val)); - } - $output .= "
    \n"; - } - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile $_POST Data - * - * @return string - */ - protected function _compile_post() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; - $output .= "\n"; - - if (count($_POST) == 0) - { - $output .= "
    ".$this->CI->lang->line('profiler_no_post')."
    "; - } - else - { - $output .= "\n\n\n"; - - foreach ($_POST as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
    $_POST[".$key."]   "; - if (is_array($val)) - { - $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "
    "; - } - else - { - $output .= htmlspecialchars(stripslashes($val)); - } - $output .= "
    \n"; - } - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Show query string - * - * @return string - */ - protected function _compile_uri_string() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; - $output .= "\n"; - - if ($this->CI->uri->uri_string == '') - { - $output .= "
    ".$this->CI->lang->line('profiler_no_uri')."
    "; - } - else - { - $output .= "
    ".$this->CI->uri->uri_string."
    "; - } - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Show the controller and function that were called - * - * @return string - */ - protected function _compile_controller_info() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; - $output .= "\n"; - - $output .= "
    ".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
    "; - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile memory usage - * - * Display total used memory - * - * @return string - */ - protected function _compile_memory_usage() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; - $output .= "\n"; - - if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') - { - $output .= "
    ".number_format($usage).' bytes
    '; - } - else - { - $output .= "
    ".$this->CI->lang->line('profiler_no_memory')."
    "; - } - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile header information - * - * Lists HTTP headers - * - * @return string - */ - protected function _compile_http_headers() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= "\n"; - - $output .= "\n\n\n"; - - foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) - { - $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; - $output .= "\n"; - } - - $output .= "\n"; - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile config information - * - * Lists developer config variables - * - * @return string - */ - protected function _compile_config() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= "\n"; - - $output .= "\n\n\n"; - - foreach ($this->CI->config->config as $config=>$val) - { - if (is_array($val)) - { - $val = print_r($val, TRUE); - } - - $output .= "\n"; - } - - $output .= "\n"; - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile session userdata - * - * @return string - */ - private function _compile_session_data() - { - if ( ! isset($this->CI->session)) - { - return; - } - - $output = '
    '; - $output .= '  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= ""; - - foreach ($this->CI->session->all_userdata() as $key => $val) - { - if (is_array($val) OR is_object($val)) - { - $val = print_r($val, TRUE); - } - - $output .= "\n"; - } - - $output .= ''; - $output .= "
    "; - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @return string - */ - public function run() - { - $output = "
    "; - $fields_displayed = 0; - - foreach ($this->_available_sections as $section) - { - if ($this->_compile_{$section} !== FALSE) - { - $func = "_compile_{$section}"; - $output .= $this->{$func}(); - $fields_displayed++; - } - } - - if ($fields_displayed == 0) - { - $output .= '

    '.$this->CI->lang->line('profiler_no_profiles').'

    '; - } - - $output .= '
    '; - - return $output; - } -} - -// END CI_Profiler class + /** + * List of profiler sections available to show + * + * @var array + */ + protected $_available_sections = array( + 'benchmarks', + 'get', + 'memory_usage', + 'post', + 'uri_string', + 'controller_info', + 'queries', + 'http_headers', + 'session_data', + 'config' + ); + + /** + * Number of queries to show before making the additional queries togglable + * + * @var int + */ + protected $_query_toggle_count = 25; + + /** + * Reference to the CodeIgniter singleton + * + * @var object + */ + protected $CI; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Initialize Profiler + * + * @param array $config Parameters + */ + public function __construct($config = array()) + { + $this->CI =& get_instance(); + $this->CI->load->language('profiler'); + + // default all sections to display + foreach ($this->_available_sections as $section) + { + if ( ! isset($config[$section])) + { + $this->_compile_{$section} = TRUE; + } + } + + $this->set_sections($config); + log_message('info', 'Profiler Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set Sections + * + * Sets the private _compile_* properties to enable/disable Profiler sections + * + * @param mixed $config + * @return void + */ + public function set_sections($config) + { + if (isset($config['query_toggle_count'])) + { + $this->_query_toggle_count = (int) $config['query_toggle_count']; + unset($config['query_toggle_count']); + } + + foreach ($config as $method => $enable) + { + if (in_array($method, $this->_available_sections)) + { + $this->_compile_{$method} = ($enable !== FALSE); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Auto Profiler + * + * This function cycles through the entire array of mark points and + * matches any two points that are named identically (ending in "_start" + * and "_end" respectively). It then compiles the execution times for + * all points and returns it as an array + * + * @return array + */ + protected function _compile_benchmarks() + { + $profile = array(); + foreach ($this->CI->benchmark->marker as $key => $val) + { + // We match the "end" marker so that the list ends + // up in the order that it was defined + if (preg_match('/(.+?)_end$/i', $key, $match) + && isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) + { + $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); + } + } + + // Build a table containing the profile data. + // Note: At some point we should turn this into a template that can + // be modified. We also might want to make this data available to be logged + + $output = "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_benchmarks')."  " + ."\n\n\n\n"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= '\n"; + } + + return $output."
    ' + .$key.'  ' + .$val."
    \n
    "; + } + + // -------------------------------------------------------------------- + + /** + * Compile Queries + * + * @return string + */ + protected function _compile_queries() + { + $dbs = array(); + + // Let's determine which databases are currently connected to + foreach (get_object_vars($this->CI) as $name => $cobject) + { + if (is_object($cobject)) + { + if ($cobject instanceof CI_DB) + { + $dbs[get_class($this->CI).':$'.$name] = $cobject; + } + elseif ($cobject instanceof CI_Model) + { + foreach (get_object_vars($cobject) as $mname => $mobject) + { + if ($mobject instanceof CI_DB) + { + $dbs[get_class($cobject).':$'.$mname] = $mobject; + } + } + } + } + } + + if (count($dbs) === 0) + { + return "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_queries').'  ' + ."\n\n\n\n" + .'\n
    ' + .$this->CI->lang->line('profiler_no_db') + ."
    \n
    "; + } + + // Load the text helper so we can highlight the SQL + $this->CI->load->helper('text'); + + // Key words we want bolded + $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); + + $output = "\n\n"; + $count = 0; + + foreach ($dbs as $name => $db) + { + $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; + $total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds'); + + $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; + + if ($hide_queries !== '') + { + $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; + } + + $output .= '
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_database') + .':  '.$db->database.' ('.$name.')   '.$this->CI->lang->line('profiler_queries') + .': '.count($db->queries).' ('.$total_time.')  '.$show_hide_js."\n\n\n" + .'\n"; + + if (count($db->queries) === 0) + { + $output .= '\n"; + } + else + { + foreach ($db->queries as $key => $val) + { + $time = number_format($db->query_times[$key], 4); + $val = highlight_code($val); + + foreach ($highlight as $bold) + { + $val = str_replace($bold, ''.$bold.'', $val); + } + + $output .= '\n"; + } + } + + $output .= "
    ' + .$this->CI->lang->line('profiler_no_queries')."
    ' + .$time.'  ' + .$val."
    \n
    "; + $count++; + } + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile $_GET Data + * + * @return string + */ + protected function _compile_get() + { + $output = "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_get_data')."  \n"; + + if (count($_GET) === 0) + { + $output .= '
    '.$this->CI->lang->line('profiler_no_get').'
    '; + } + else + { + $output .= "\n\n\n"; + + foreach ($_GET as $key => $val) + { + is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; + $val = (is_array($val) OR is_object($val)) + ? '
    '.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'
    ' + : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); + + $output .= '\n"; + } + + $output .= "
    $_GET[' + .$key.']   ' + .$val."
    \n"; + } + + return $output.'
    '; + } + + // -------------------------------------------------------------------- + + /** + * Compile $_POST Data + * + * @return string + */ + protected function _compile_post() + { + $output = "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_post_data')."  \n"; + + if (count($_POST) === 0 && count($_FILES) === 0) + { + $output .= '
    '.$this->CI->lang->line('profiler_no_post').'
    '; + } + else + { + $output .= "\n\n\n"; + + foreach ($_POST as $key => $val) + { + is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; + $val = (is_array($val) OR is_object($val)) + ? '
    '.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'
    ' + : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); + + $output .= '\n"; + } + + foreach ($_FILES as $key => $val) + { + is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; + $val = (is_array($val) OR is_object($val)) + ? '
    '.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'
    ' + : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); + + $output .= '\n"; + } + + $output .= "
    $_POST[' + .$key.']   ' + .$val."
    $_FILES[' + .$key.']   ' + .$val."
    \n"; + } + + return $output.'
    '; + } + + // -------------------------------------------------------------------- + + /** + * Show query string + * + * @return string + */ + protected function _compile_uri_string() + { + return "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_uri_string')."  \n" + .'
    ' + .($this->CI->uri->uri_string === '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) + .'
    '; + } + + // -------------------------------------------------------------------- + + /** + * Show the controller and function that were called + * + * @return string + */ + protected function _compile_controller_info() + { + return "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_controller_info')."  \n" + .'
    '.$this->CI->router->class.'/'.$this->CI->router->method + .'
    '; + } + + // -------------------------------------------------------------------- + + /** + * Compile memory usage + * + * Display total used memory + * + * @return string + */ + protected function _compile_memory_usage() + { + return "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_memory_usage')."  \n" + .'
    ' + .(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) + .'
    '; + } + + // -------------------------------------------------------------------- + + /** + * Compile header information + * + * Lists HTTP headers + * + * @return string + */ + protected function _compile_http_headers() + { + $output = "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_headers') + .'  ('.$this->CI->lang->line('profiler_section_show').")\n\n\n" + .''."\n"; + + foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR', 'HTTP_DNT') as $header) + { + $val = isset($_SERVER[$header]) ? htmlspecialchars($_SERVER[$header], ENT_QUOTES, config_item('charset')) : ''; + $output .= '\n"; + } + + return $output."\n
    "; + } + + // -------------------------------------------------------------------- + + /** + * Compile config information + * + * Lists developer config variables + * + * @return string + */ + protected function _compile_config() + { + $output = "\n\n" + .'
    ' + ."\n" + .'  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').")\n\n\n" + .''."\n"; + + foreach ($this->CI->config->config as $config => $val) + { + $pre = ''; + $pre_close = ''; + + if (is_array($val) OR is_object($val)) + { + $val = print_r($val, TRUE); + + $pre = '
    ' ;
    + 				$pre_close = '
    '; + } + + $output .= '\n"; + } + + return $output."\n
    "; + } + + // -------------------------------------------------------------------- + + /** + * Compile session userdata + * + * @return string + */ + protected function _compile_session_data() + { + if ( ! isset($this->CI->session)) + { + return; + } + + $output = '
    ' + .'  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')' + .''; + + foreach ($this->CI->session->userdata() as $key => $val) + { + $pre = ''; + $pre_close = ''; + + if (is_array($val) OR is_object($val)) + { + $val = print_r($val, TRUE); + + $pre = '
    ' ;
    + 				$pre_close = '
    '; + } + + $output .= '\n"; + } + + return $output."\n
    "; + } + + // -------------------------------------------------------------------- + + /** + * Run the Profiler + * + * @return string + */ + public function run() + { + $output = '
    '; + $fields_displayed = 0; + + foreach ($this->_available_sections as $section) + { + if ($this->_compile_{$section} !== FALSE) + { + $func = '_compile_'.$section; + $output .= $this->{$func}(); + $fields_displayed++; + } + } + + if ($fields_displayed === 0) + { + $output .= '

    ' + .$this->CI->lang->line('profiler_no_profiles').'

    '; + } + + return $output.'
    '; + } -/* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file +} diff --git a/system/libraries/Session.php b/system/libraries/Session.php deleted file mode 100755 index 3a9ba04..0000000 --- a/system/libraries/Session.php +++ /dev/null @@ -1,794 +0,0 @@ -CI =& get_instance(); - - // Set all the session preferences, which can either be set - // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) - { - $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); - } - - if ($this->encryption_key == '') - { - show_error('In order to use the Session class you are required to set an encryption key in your config file.'); - } - - // Load the string helper so we can use the strip_slashes() function - $this->CI->load->helper('string'); - - // Do we need encryption? If so, load the encryption class - if ($this->sess_encrypt_cookie == TRUE) - { - $this->CI->load->library('encrypt'); - } - - // Are we using a database? If so, load it - if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') - { - $this->CI->load->database(); - } - - // Set the "now" time. Can either be GMT or server time, based on the - // config prefs. We use this to set the "last activity" time - $this->now = $this->_get_time(); - - // Set the session length. If the session expiration is - // set to zero we'll set the expiration two years from now. - if ($this->sess_expiration == 0) - { - $this->sess_expiration = (60*60*24*365*2); - } - - // Set the cookie name - $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; - - // Run the Session routine. If a session doesn't exist we'll - // create a new one. If it does, we'll update it. - if ( ! $this->sess_read()) - { - $this->sess_create(); - } - else - { - $this->sess_update(); - } - - // Delete 'old' flashdata (from last request) - $this->_flashdata_sweep(); - - // Mark all new flashdata as old (data will be deleted before next request) - $this->_flashdata_mark(); - - // Delete expired sessions if necessary - $this->_sess_gc(); - - log_message('debug', "Session routines successfully run"); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current session data if it exists - * - * @access public - * @return bool - */ - function sess_read() - { - // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie_name); - - // No cookie? Goodbye cruel world!... - if ($session === FALSE) - { - log_message('debug', 'A session cookie was not found.'); - return FALSE; - } - - // HMAC authentication - $len = strlen($session) - 40; - - if ($len <= 0) - { - log_message('error', 'Session: The session cookie was not signed.'); - return FALSE; - } - - // Check cookie authentication - $hmac = substr($session, $len); - $session = substr($session, 0, $len); - - // Time-attack-safe comparison - $hmac_check = hash_hmac('sha1', $session, $this->encryption_key); - $diff = 0; - - for ($i = 0; $i < 40; $i++) - { - $xor = ord($hmac[$i]) ^ ord($hmac_check[$i]); - $diff |= $xor; - } - - if ($diff !== 0) - { - log_message('error', 'Session: HMAC mismatch. The session cookie data did not match what was expected.'); - $this->sess_destroy(); - return FALSE; - } - - // Decrypt the cookie data - if ($this->sess_encrypt_cookie == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - - // Unserialize the session array - $session = $this->_unserialize($session); - - // Is the session data we unserialized an array with the correct format? - if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity'])) - { - $this->sess_destroy(); - return FALSE; - } - - // Is the session current? - if (($session['last_activity'] + $this->sess_expiration) < $this->now) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the IP Match? - if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the User Agent Match? - if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120))) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there a corresponding session in the DB? - if ($this->sess_use_database === TRUE) - { - $this->CI->db->where('session_id', $session['session_id']); - - if ($this->sess_match_ip == TRUE) - { - $this->CI->db->where('ip_address', $session['ip_address']); - } - - if ($this->sess_match_useragent == TRUE) - { - $this->CI->db->where('user_agent', $session['user_agent']); - } - - $query = $this->CI->db->get($this->sess_table_name); - - // No result? Kill it! - if ($query->num_rows() == 0) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there custom data? If so, add it to the main session array - $row = $query->row(); - if (isset($row->user_data) AND $row->user_data != '') - { - $custom_data = $this->_unserialize($row->user_data); - - if (is_array($custom_data)) - { - foreach ($custom_data as $key => $val) - { - $session[$key] = $val; - } - } - } - } - - // Session is valid! - $this->userdata = $session; - unset($session); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Write the session data - * - * @access public - * @return void - */ - function sess_write() - { - // Are we saving custom data to the DB? If not, all we do is update the cookie - if ($this->sess_use_database === FALSE) - { - $this->_set_cookie(); - return; - } - - // set the custom userdata, the session data we will set in a second - $custom_userdata = $this->userdata; - $cookie_userdata = array(); - - // Before continuing, we need to determine if there is any custom data to deal with. - // Let's determine this by removing the default indexes to see if there's anything left in the array - // and set the session data while we're at it - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - unset($custom_userdata[$val]); - $cookie_userdata[$val] = $this->userdata[$val]; - } - - // Did we find any custom data? If not, we turn the empty array into a string - // since there's no reason to serialize and store an empty array in the DB - if (count($custom_userdata) === 0) - { - $custom_userdata = ''; - } - else - { - // Serialize the custom data array so we can store it - $custom_userdata = $this->_serialize($custom_userdata); - } - - // Run the update query - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - - // Write the cookie. Notice that we manually pass the cookie data array to the - // _set_cookie() function. Normally that function will store $this->userdata, but - // in this case that array contains custom data, which we do not want in the cookie. - $this->_set_cookie($cookie_userdata); - } - - // -------------------------------------------------------------------- - - /** - * Create a new session - * - * @access public - * @return void - */ - function sess_create() - { - $sessid = ''; - while (strlen($sessid) < 32) - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $sessid .= $this->CI->input->ip_address(); - - $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->CI->input->ip_address(), - 'user_agent' => substr($this->CI->input->user_agent(), 0, 120), - 'last_activity' => $this->now, - 'user_data' => '' - ); - - - // Save the data to the DB if needed - if ($this->sess_use_database === TRUE) - { - $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata)); - } - - // Write the cookie - $this->_set_cookie(); - } - - // -------------------------------------------------------------------- - - /** - * Update an existing session - * - * @access public - * @return void - */ - function sess_update() - { - // We only update the session every five minutes by default - if ($this->CI->input->is_ajax_request() OR ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) - { - return; - } - - // Save the old session id so we know which record to - // update in the database if we need it - $old_sessid = $this->userdata['session_id']; - $new_sessid = ''; - while (strlen($new_sessid) < 32) - { - $new_sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $new_sessid .= $this->CI->input->ip_address(); - - // Turn it into a hash - $new_sessid = md5(uniqid($new_sessid, TRUE)); - - // Update the session data in the session data array - $this->userdata['session_id'] = $new_sessid; - $this->userdata['last_activity'] = $this->now; - - // _set_cookie() will handle this for us if we aren't using database sessions - // by pushing all userdata to the cookie. - $cookie_data = NULL; - - // Update the session ID and last_activity field in the DB if needed - if ($this->sess_use_database === TRUE) - { - // set cookie explicitly to only have our session data - $cookie_data = array(); - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - $cookie_data[$val] = $this->userdata[$val]; - } - - $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); - } - - // Write the cookie - $this->_set_cookie($cookie_data); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the current session - * - * @access public - * @return void - */ - function sess_destroy() - { - // Kill the session DB row - if ($this->sess_use_database === TRUE && isset($this->userdata['session_id'])) - { - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->delete($this->sess_table_name); - } - - // Kill the cookie - setcookie( - $this->sess_cookie_name, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->cookie_path, - $this->cookie_domain, - 0 - ); - - // Kill session data - $this->userdata = array(); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a specific item from the session array - * - * @access public - * @param string - * @return string - */ - function userdata($item) - { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch all session data - * - * @access public - * @return array - */ - function all_userdata() - { - return $this->userdata; - } - - // -------------------------------------------------------------------- - - /** - * Add or change data in the "userdata" array - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_userdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $this->userdata[$key] = $val; - } - } - - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Delete a session variable from the "userdata" array - * - * @access array - * @return void - */ - function unset_userdata($newdata = array()) - { - if (is_string($newdata)) - { - $newdata = array($newdata => ''); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - unset($this->userdata[$key]); - } - } - - $this->sess_write(); - } - - // ------------------------------------------------------------------------ - - /** - * Add or change flashdata, only available - * until the next request - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_flashdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($flashdata_key, $val); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Keeps existing flashdata available to next request. - * - * @access public - * @param string - * @return void - */ - function keep_flashdata($key) - { - // 'old' flashdata gets removed. Here we mark all - // flashdata as 'new' to preserve it from _flashdata_sweep() - // Note the function will return FALSE if the $key - // provided cannot be found - $old_flashdata_key = $this->flashdata_key.':old:'.$key; - $value = $this->userdata($old_flashdata_key); - - $new_flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($new_flashdata_key, $value); - } - - // ------------------------------------------------------------------------ - - /** - * Fetch a specific flashdata item from the session array - * - * @access public - * @param string - * @return string - */ - function flashdata($key) - { - $flashdata_key = $this->flashdata_key.':old:'.$key; - return $this->userdata($flashdata_key); - } - - // ------------------------------------------------------------------------ - - /** - * Identifies flashdata as 'old' for removal - * when _flashdata_sweep() runs. - * - * @access private - * @return void - */ - function _flashdata_mark() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $name => $value) - { - $parts = explode(':new:', $name); - if (is_array($parts) && count($parts) === 2) - { - $new_name = $this->flashdata_key.':old:'.$parts[1]; - $this->set_userdata($new_name, $value); - $this->unset_userdata($name); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Removes all flashdata marked as 'old' - * - * @access private - * @return void - */ - - function _flashdata_sweep() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) - { - if (strpos($key, ':old:')) - { - $this->unset_userdata($key); - } - } - - } - - // -------------------------------------------------------------------- - - /** - * Get the "now" time - * - * @access private - * @return string - */ - function _get_time() - { - if (strtolower($this->time_reference) == 'gmt') - { - $now = time(); - $time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - } - else - { - $time = time(); - } - - return $time; - } - - // -------------------------------------------------------------------- - - /** - * Write the session cookie - * - * @access public - * @return void - */ - function _set_cookie($cookie_data = NULL) - { - if (is_null($cookie_data)) - { - $cookie_data = $this->userdata; - } - - // Serialize the userdata for the cookie - $cookie_data = $this->_serialize($cookie_data); - - if ($this->sess_encrypt_cookie == TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - - $cookie_data .= hash_hmac('sha1', $cookie_data, $this->encryption_key); - - $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); - - // Set the cookie - setcookie( - $this->sess_cookie_name, - $cookie_data, - $expire, - $this->cookie_path, - $this->cookie_domain, - $this->cookie_secure - ); - } - - // -------------------------------------------------------------------- - - /** - * Serialize an array - * - * This function first converts any slashes found in the array to a temporary - * marker, so when it gets unserialized the slashes will be preserved - * - * @access private - * @param array - * @return string - */ - function _serialize($data) - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $data[$key] = str_replace('\\', '{{slash}}', $val); - } - } - } - else - { - if (is_string($data)) - { - $data = str_replace('\\', '{{slash}}', $data); - } - } - - return serialize($data); - } - - // -------------------------------------------------------------------- - - /** - * Unserialize - * - * This function unserializes a data string, then converts any - * temporary slash markers back to actual slashes - * - * @access private - * @param array - * @return string - */ - function _unserialize($data) - { - $data = @unserialize(strip_slashes($data)); - - if (is_array($data)) - { - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $data[$key] = str_replace('{{slash}}', '\\', $val); - } - } - - return $data; - } - - return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data; - } - - // -------------------------------------------------------------------- - - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function _sess_gc() - { - if ($this->sess_use_database != TRUE) - { - return; - } - - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_expiration; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->sess_table_name); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - -} -// END Session Class - -/* End of file Session.php */ -/* Location: ./system/libraries/Session.php */ diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php new file mode 100644 index 0000000..9b834f8 --- /dev/null +++ b/system/libraries/Session/Session.php @@ -0,0 +1,983 @@ +_driver = $params['driver']; + unset($params['driver']); + } + elseif ($driver = config_item('sess_driver')) + { + $this->_driver = $driver; + } + // Note: BC workaround + elseif (config_item('sess_use_database')) + { + log_message('debug', 'Session: "sess_driver" is empty; using BC fallback to "sess_use_database".'); + $this->_driver = 'database'; + } + + $class = $this->_ci_load_classes($this->_driver); + + // Configuration ... + $this->_configure($params); + $this->_config['_sid_regexp'] = $this->_sid_regexp; + + $class = new $class($this->_config); + if ($class instanceof SessionHandlerInterface) + { + 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 + { + log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting."); + return; + } + + // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers + if (isset($_COOKIE[$this->_config['cookie_name']]) + && ( + ! is_string($_COOKIE[$this->_config['cookie_name']]) + OR ! preg_match('#\A'.$this->_sid_regexp.'\z#', $_COOKIE[$this->_config['cookie_name']]) + ) + ) + { + unset($_COOKIE[$this->_config['cookie_name']]); + } + + session_start(); + + // Is session ID auto-regeneration configured? (ignoring ajax requests) + if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') + && ($regenerate_time = config_item('sess_time_to_update')) > 0 + ) + { + if ( ! isset($_SESSION['__ci_last_regenerate'])) + { + $_SESSION['__ci_last_regenerate'] = time(); + } + elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time)) + { + $this->sess_regenerate((bool) config_item('sess_regenerate_destroy')); + } + } + // Another work-around ... PHP doesn't seem to send the session cookie + // unless it is being currently created or regenerated + elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id()) + { + setcookie( + $this->_config['cookie_name'], + session_id(), + (empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']), + $this->_config['cookie_path'], + $this->_config['cookie_domain'], + $this->_config['cookie_secure'], + TRUE + ); + } + + $this->_ci_init_vars(); + + log_message('info', "Session: Class initialized using '".$this->_driver."' driver."); + } + + // ------------------------------------------------------------------------ + + /** + * CI Load Classes + * + * An internal method to load all possible dependency and extension + * classes. It kind of emulates the CI_Driver library, but is + * self-sufficient. + * + * @param string $driver Driver name + * @return string Driver class name + */ + 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)) + { + require_once( + file_exists(APPPATH.'libraries/Session/Session_driver.php') + ? APPPATH.'libraries/Session/Session_driver.php' + : BASEPATH.'libraries/Session/Session_driver.php' + ); + + if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php')) + { + require_once($file_path); + } + } + + $class = 'Session_'.$driver.'_driver'; + + // Allow custom drivers without the CI_ or MY_ prefix + if ( ! class_exists($class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php')) + { + require_once($file_path); + if (class_exists($class, FALSE)) + { + return $class; + } + } + + if ( ! class_exists('CI_'.$class, FALSE)) + { + if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php')) + { + require_once($file_path); + } + + if ( ! class_exists('CI_'.$class, FALSE) && ! class_exists($class, FALSE)) + { + throw new UnexpectedValueException("Session: Configured driver '".$driver."' was not found. Aborting."); + } + } + + if ( ! class_exists($prefix.$class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php')) + { + require_once($file_path); + if (class_exists($prefix.$class, FALSE)) + { + return $prefix.$class; + } + + log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.'); + } + + return 'CI_'.$class; + } + + // ------------------------------------------------------------------------ + + /** + * Configuration + * + * Handle input parameters and configuration defaults + * + * @param array &$params Input parameters + * @return void + */ + protected function _configure(&$params) + { + $expiration = config_item('sess_expiration'); + + if (isset($params['cookie_lifetime'])) + { + $params['cookie_lifetime'] = (int) $params['cookie_lifetime']; + } + else + { + $params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close')) + ? 0 : (int) $expiration; + } + + isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name'); + if (empty($params['cookie_name'])) + { + $params['cookie_name'] = ini_get('session.name'); + } + else + { + ini_set('session.name', $params['cookie_name']); + } + + isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path'); + isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain'); + isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure'); + + session_set_cookie_params( + $params['cookie_lifetime'], + $params['cookie_path'], + $params['cookie_domain'], + $params['cookie_secure'], + TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons + ); + + if (empty($expiration)) + { + $params['expiration'] = (int) ini_get('session.gc_maxlifetime'); + } + else + { + $params['expiration'] = (int) $expiration; + ini_set('session.gc_maxlifetime', $expiration); + } + + $params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip')); + + isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path'); + + $this->_config = $params; + + // Security is king + ini_set('session.use_trans_sid', 0); + ini_set('session.use_strict_mode', 1); + ini_set('session.use_cookies', 1); + ini_set('session.use_only_cookies', 1); + + $this->_configure_sid_length(); + } + + // ------------------------------------------------------------------------ + + /** + * Configure session ID length + * + * To make life easier, we used to force SHA-1 and 4 bits per + * character on everyone. And of course, someone was unhappy. + * + * Then PHP 7.1 broke backwards-compatibility because ext/session + * is such a mess that nobody wants to touch it with a pole stick, + * and the one guy who does, nobody has the energy to argue with. + * + * So we were forced to make changes, and OF COURSE something was + * going to break and now we have this pile of shit. -- Narf + * + * @return void + */ + protected function _configure_sid_length() + { + if (PHP_VERSION_ID < 70100) + { + $hash_function = ini_get('session.hash_function'); + if (ctype_digit($hash_function)) + { + if ($hash_function !== '1') + { + ini_set('session.hash_function', 1); + } + + $bits = 160; + } + elseif ( ! in_array($hash_function, hash_algos(), TRUE)) + { + ini_set('session.hash_function', 1); + $bits = 160; + } + elseif (($bits = strlen(hash($hash_function, 'dummy', false)) * 4) < 160) + { + ini_set('session.hash_function', 1); + $bits = 160; + } + + $bits_per_character = (int) ini_get('session.hash_bits_per_character'); + $sid_length = (int) ceil($bits / $bits_per_character); + } + else + { + $bits_per_character = (int) ini_get('session.sid_bits_per_character'); + $sid_length = (int) ini_get('session.sid_length'); + if (($bits = $sid_length * $bits_per_character) < 160) + { + // Add as many more characters as necessary to reach at least 160 bits + $sid_length += (int) ceil((160 % $bits) / $bits_per_character); + ini_set('session.sid_length', $sid_length); + } + } + + // Yes, 4,5,6 are the only known possible values as of 2016-10-27 + switch ($bits_per_character) + { + case 4: + $this->_sid_regexp = '[0-9a-f]'; + break; + case 5: + $this->_sid_regexp = '[0-9a-v]'; + break; + case 6: + $this->_sid_regexp = '[0-9a-zA-Z,-]'; + break; + } + + $this->_sid_regexp .= '{'.$sid_length.'}'; + } + + // ------------------------------------------------------------------------ + + /** + * Handle temporary variables + * + * Clears old "flash" data, marks the new one for deletion and handles + * "temp" data deletion. + * + * @return void + */ + protected function _ci_init_vars() + { + if ( ! empty($_SESSION['__ci_vars'])) + { + $current_time = time(); + + foreach ($_SESSION['__ci_vars'] as $key => &$value) + { + if ($value === 'new') + { + $_SESSION['__ci_vars'][$key] = 'old'; + } + // Hacky, but 'old' will (implicitly) always be less than time() ;) + // DO NOT move this above the 'new' check! + elseif ($value < $current_time) + { + unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]); + } + } + + if (empty($_SESSION['__ci_vars'])) + { + unset($_SESSION['__ci_vars']); + } + } + + $this->userdata =& $_SESSION; + } + + // ------------------------------------------------------------------------ + + /** + * Mark as flash + * + * @param mixed $key Session data key(s) + * @return bool + */ + public function mark_as_flash($key) + { + if (is_array($key)) + { + for ($i = 0, $c = count($key); $i < $c; $i++) + { + if ( ! isset($_SESSION[$key[$i]])) + { + return FALSE; + } + } + + $new = array_fill_keys($key, 'new'); + + $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) + ? array_merge($_SESSION['__ci_vars'], $new) + : $new; + + return TRUE; + } + + if ( ! isset($_SESSION[$key])) + { + return FALSE; + } + + $_SESSION['__ci_vars'][$key] = 'new'; + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Get flash keys + * + * @return array + */ + public function get_flash_keys() + { + if ( ! isset($_SESSION['__ci_vars'])) + { + return array(); + } + + $keys = array(); + foreach (array_keys($_SESSION['__ci_vars']) as $key) + { + is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key; + } + + return $keys; + } + + // ------------------------------------------------------------------------ + + /** + * Unmark flash + * + * @param mixed $key Session data key(s) + * @return void + */ + public function unmark_flash($key) + { + if (empty($_SESSION['__ci_vars'])) + { + return; + } + + is_array($key) OR $key = array($key); + + foreach ($key as $k) + { + if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k])) + { + unset($_SESSION['__ci_vars'][$k]); + } + } + + if (empty($_SESSION['__ci_vars'])) + { + unset($_SESSION['__ci_vars']); + } + } + + // ------------------------------------------------------------------------ + + /** + * Mark as temp + * + * @param mixed $key Session data key(s) + * @param int $ttl Time-to-live in seconds + * @return bool + */ + public function mark_as_temp($key, $ttl = 300) + { + $ttl += time(); + + if (is_array($key)) + { + $temp = array(); + + foreach ($key as $k => $v) + { + // Do we have a key => ttl pair, or just a key? + if (is_int($k)) + { + $k = $v; + $v = $ttl; + } + else + { + $v += time(); + } + + if ( ! isset($_SESSION[$k])) + { + return FALSE; + } + + $temp[$k] = $v; + } + + $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) + ? array_merge($_SESSION['__ci_vars'], $temp) + : $temp; + + return TRUE; + } + + if ( ! isset($_SESSION[$key])) + { + return FALSE; + } + + $_SESSION['__ci_vars'][$key] = $ttl; + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Get temp keys + * + * @return array + */ + public function get_temp_keys() + { + if ( ! isset($_SESSION['__ci_vars'])) + { + return array(); + } + + $keys = array(); + foreach (array_keys($_SESSION['__ci_vars']) as $key) + { + is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key; + } + + return $keys; + } + + // ------------------------------------------------------------------------ + + /** + * Unmark temp + * + * @param mixed $key Session data key(s) + * @return void + */ + public function unmark_temp($key) + { + if (empty($_SESSION['__ci_vars'])) + { + return; + } + + is_array($key) OR $key = array($key); + + foreach ($key as $k) + { + if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k])) + { + unset($_SESSION['__ci_vars'][$k]); + } + } + + if (empty($_SESSION['__ci_vars'])) + { + unset($_SESSION['__ci_vars']); + } + } + + // ------------------------------------------------------------------------ + + /** + * __get() + * + * @param string $key 'session_id' or a session data key + * @return mixed + */ + public function __get($key) + { + // Note: Keep this order the same, just in case somebody wants to + // use 'session_id' as a session data key, for whatever reason + if (isset($_SESSION[$key])) + { + return $_SESSION[$key]; + } + elseif ($key === 'session_id') + { + return session_id(); + } + + return NULL; + } + + // ------------------------------------------------------------------------ + + /** + * __isset() + * + * @param string $key 'session_id' or a session data key + * @return bool + */ + public function __isset($key) + { + if ($key === 'session_id') + { + return (session_status() === PHP_SESSION_ACTIVE); + } + + return isset($_SESSION[$key]); + } + + // ------------------------------------------------------------------------ + + /** + * __set() + * + * @param string $key Session data key + * @param mixed $value Session data value + * @return void + */ + public function __set($key, $value) + { + $_SESSION[$key] = $value; + } + + // ------------------------------------------------------------------------ + + /** + * Session destroy + * + * Legacy CI_Session compatibility method + * + * @return void + */ + public function sess_destroy() + { + session_destroy(); + } + + // ------------------------------------------------------------------------ + + /** + * Session regenerate + * + * Legacy CI_Session compatibility method + * + * @param bool $destroy Destroy old session data flag + * @return void + */ + public function sess_regenerate($destroy = FALSE) + { + $_SESSION['__ci_last_regenerate'] = time(); + session_regenerate_id($destroy); + } + + // ------------------------------------------------------------------------ + + /** + * Get userdata reference + * + * Legacy CI_Session compatibility method + * + * @returns array + */ + public function &get_userdata() + { + return $_SESSION; + } + + // ------------------------------------------------------------------------ + + /** + * Userdata (fetch) + * + * Legacy CI_Session compatibility method + * + * @param string $key Session data key + * @return mixed Session data value or NULL if not found + */ + public function userdata($key = NULL) + { + if (isset($key)) + { + return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL; + } + elseif (empty($_SESSION)) + { + return array(); + } + + $userdata = array(); + $_exclude = array_merge( + array('__ci_vars'), + $this->get_flash_keys(), + $this->get_temp_keys() + ); + + foreach (array_keys($_SESSION) as $key) + { + if ( ! in_array($key, $_exclude, TRUE)) + { + $userdata[$key] = $_SESSION[$key]; + } + } + + return $userdata; + } + + // ------------------------------------------------------------------------ + + /** + * Set userdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $data Session data key or an associative array + * @param mixed $value Value to store + * @return void + */ + public function set_userdata($data, $value = NULL) + { + if (is_array($data)) + { + foreach ($data as $key => &$value) + { + $_SESSION[$key] = $value; + } + + return; + } + + $_SESSION[$data] = $value; + } + + // ------------------------------------------------------------------------ + + /** + * Unset userdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $key Session data key(s) + * @return void + */ + public function unset_userdata($key) + { + if (is_array($key)) + { + foreach ($key as $k) + { + unset($_SESSION[$k]); + } + + return; + } + + unset($_SESSION[$key]); + } + + // ------------------------------------------------------------------------ + + /** + * All userdata (fetch) + * + * Legacy CI_Session compatibility method + * + * @return array $_SESSION, excluding flash data items + */ + public function all_userdata() + { + return $this->userdata(); + } + + // ------------------------------------------------------------------------ + + /** + * Has userdata + * + * Legacy CI_Session compatibility method + * + * @param string $key Session data key + * @return bool + */ + public function has_userdata($key) + { + return isset($_SESSION[$key]); + } + + // ------------------------------------------------------------------------ + + /** + * Flashdata (fetch) + * + * Legacy CI_Session compatibility method + * + * @param string $key Session data key + * @return mixed Session data value or NULL if not found + */ + public function flashdata($key = NULL) + { + if (isset($key)) + { + return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && ! is_int($_SESSION['__ci_vars'][$key])) + ? $_SESSION[$key] + : NULL; + } + + $flashdata = array(); + + if ( ! empty($_SESSION['__ci_vars'])) + { + foreach ($_SESSION['__ci_vars'] as $key => &$value) + { + is_int($value) OR $flashdata[$key] = $_SESSION[$key]; + } + } + + return $flashdata; + } + + // ------------------------------------------------------------------------ + + /** + * Set flashdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $data Session data key or an associative array + * @param mixed $value Value to store + * @return void + */ + public function set_flashdata($data, $value = NULL) + { + $this->set_userdata($data, $value); + $this->mark_as_flash(is_array($data) ? array_keys($data) : $data); + } + + // ------------------------------------------------------------------------ + + /** + * Keep flashdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $key Session data key(s) + * @return void + */ + public function keep_flashdata($key) + { + $this->mark_as_flash($key); + } + + // ------------------------------------------------------------------------ + + /** + * Temp data (fetch) + * + * Legacy CI_Session compatibility method + * + * @param string $key Session data key + * @return mixed Session data value or NULL if not found + */ + public function tempdata($key = NULL) + { + if (isset($key)) + { + return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && is_int($_SESSION['__ci_vars'][$key])) + ? $_SESSION[$key] + : NULL; + } + + $tempdata = array(); + + if ( ! empty($_SESSION['__ci_vars'])) + { + foreach ($_SESSION['__ci_vars'] as $key => &$value) + { + is_int($value) && $tempdata[$key] = $_SESSION[$key]; + } + } + + return $tempdata; + } + + // ------------------------------------------------------------------------ + + /** + * Set tempdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $data Session data key or an associative array of items + * @param mixed $value Value to store + * @param int $ttl Time-to-live in seconds + * @return void + */ + public function set_tempdata($data, $value = NULL, $ttl = 300) + { + $this->set_userdata($data, $value); + $this->mark_as_temp(is_array($data) ? array_keys($data) : $data, $ttl); + } + + // ------------------------------------------------------------------------ + + /** + * Unset tempdata + * + * Legacy CI_Session compatibility method + * + * @param mixed $data Session data key(s) + * @return void + */ + public function unset_tempdata($key) + { + $this->unmark_temp($key); + } + +} diff --git a/system/libraries/Session/SessionHandlerInterface.php b/system/libraries/Session/SessionHandlerInterface.php new file mode 100644 index 0000000..240c5f5 --- /dev/null +++ b/system/libraries/Session/SessionHandlerInterface.php @@ -0,0 +1,59 @@ +_config =& $params; + + if (is_php('7')) + { + $this->_success = TRUE; + $this->_failure = FALSE; + } + else + { + $this->_success = 0; + $this->_failure = -1; + } + } + + // ------------------------------------------------------------------------ + + /** + * PHP 5.x validate ID + * + * Enforces session.use_strict_mode + * + * @return void + */ + public function php5_validate_id() + { + if (isset($_COOKIE[$this->_config['cookie_name']]) && ! $this->validateSessionId($_COOKIE[$this->_config['cookie_name']])) + { + unset($_COOKIE[$this->_config['cookie_name']]); + } + } + + // ------------------------------------------------------------------------ + + /** + * Cookie destroy + * + * Internal method to force removal of a cookie by the client + * when session_destroy() is called. + * + * @return bool + */ + protected function _cookie_destroy() + { + return setcookie( + $this->_config['cookie_name'], + NULL, + 1, + $this->_config['cookie_path'], + $this->_config['cookie_domain'], + $this->_config['cookie_secure'], + TRUE + ); + } + + // ------------------------------------------------------------------------ + + /** + * Get lock + * + * A dummy method allowing drivers with no locking functionality + * (databases other than PostgreSQL and MySQL) to act as if they + * do acquire a lock. + * + * @param string $session_id + * @return bool + */ + protected function _get_lock($session_id) + { + $this->_lock = TRUE; + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Release lock + * + * @return bool + */ + protected function _release_lock() + { + if ($this->_lock) + { + $this->_lock = FALSE; + } + + return TRUE; + } +} diff --git a/system/libraries/Session/drivers/Session_database_driver.php b/system/libraries/Session/drivers/Session_database_driver.php new file mode 100644 index 0000000..89afe34 --- /dev/null +++ b/system/libraries/Session/drivers/Session_database_driver.php @@ -0,0 +1,445 @@ +db) OR $CI->load->database(); + $this->_db = $CI->db; + + if ( ! $this->_db instanceof CI_DB_query_builder) + { + throw new Exception('Query Builder not enabled for the configured database. Aborting.'); + } + elseif ($this->_db->pconnect) + { + throw new Exception('Configured database connection is persistent. Aborting.'); + } + elseif ($this->_db->cache_on) + { + throw new Exception('Configured database connection has cache enabled. Aborting.'); + } + + $db_driver = $this->_db->dbdriver.(empty($this->_db->subdriver) ? '' : '_'.$this->_db->subdriver); + if (strpos($db_driver, 'mysql') !== FALSE) + { + $this->_platform = 'mysql'; + } + elseif (in_array($db_driver, array('postgre', 'pdo_pgsql'), TRUE)) + { + $this->_platform = 'postgre'; + } + + // Note: BC work-around for the old 'sess_table_name' setting, should be removed in the future. + if ( ! isset($this->_config['save_path']) && ($this->_config['save_path'] = config_item('sess_table_name'))) + { + log_message('debug', 'Session: "sess_save_path" is empty; using BC fallback to "sess_table_name".'); + } + } + + // ------------------------------------------------------------------------ + + /** + * Open + * + * Initializes the database connection + * + * @param string $save_path Table name + * @param string $name Session cookie name, unused + * @return bool + */ + public function open($save_path, $name) + { + if (empty($this->_db->conn_id) && ! $this->_db->db_connect()) + { + return $this->_failure; + } + + $this->php5_validate_id(); + + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Read + * + * Reads session data and acquires a lock + * + * @param string $session_id Session ID + * @return string Serialized session data + */ + public function read($session_id) + { + if ($this->_get_lock($session_id) === FALSE) + { + return $this->_failure; + } + + // Prevent previous QB calls from messing with our queries + $this->_db->reset_query(); + + // Needed by write() to detect session_regenerate_id() calls + $this->_session_id = $session_id; + + $this->_db + ->select('data') + ->from($this->_config['save_path']) + ->where('id', $session_id); + + if ($this->_config['match_ip']) + { + $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); + } + + if ( ! ($result = $this->_db->get()) OR ($result = $result->row()) === NULL) + { + // PHP7 will reuse the same SessionHandler object after + // ID regeneration, so we need to explicitly set this to + // FALSE instead of relying on the default ... + $this->_row_exists = FALSE; + $this->_fingerprint = md5(''); + return ''; + } + + // PostgreSQL's variant of a BLOB datatype is Bytea, which is a + // PITA to work with, so we use base64-encoded data in a TEXT + // field instead. + $result = ($this->_platform === 'postgre') + ? base64_decode(rtrim($result->data)) + : $result->data; + + $this->_fingerprint = md5($result); + $this->_row_exists = TRUE; + return $result; + } + + // ------------------------------------------------------------------------ + + /** + * Write + * + * Writes (create / update) session data + * + * @param string $session_id Session ID + * @param string $session_data Serialized session data + * @return bool + */ + public function write($session_id, $session_data) + { + // Prevent previous QB calls from messing with our queries + $this->_db->reset_query(); + + // Was the ID regenerated? + if (isset($this->_session_id) && $session_id !== $this->_session_id) + { + if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) + { + return $this->_failure; + } + + $this->_row_exists = FALSE; + $this->_session_id = $session_id; + } + elseif ($this->_lock === FALSE) + { + return $this->_failure; + } + + if ($this->_row_exists === FALSE) + { + $insert_data = array( + 'id' => $session_id, + 'ip_address' => $_SERVER['REMOTE_ADDR'], + 'timestamp' => time(), + 'data' => ($this->_platform === 'postgre' ? base64_encode($session_data) : $session_data) + ); + + if ($this->_db->insert($this->_config['save_path'], $insert_data)) + { + $this->_fingerprint = md5($session_data); + $this->_row_exists = TRUE; + return $this->_success; + } + + return $this->_failure; + } + + $this->_db->where('id', $session_id); + if ($this->_config['match_ip']) + { + $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); + } + + $update_data = array('timestamp' => time()); + if ($this->_fingerprint !== md5($session_data)) + { + $update_data['data'] = ($this->_platform === 'postgre') + ? base64_encode($session_data) + : $session_data; + } + + if ($this->_db->update($this->_config['save_path'], $update_data)) + { + $this->_fingerprint = md5($session_data); + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Close + * + * Releases locks + * + * @return bool + */ + public function close() + { + return ($this->_lock && ! $this->_release_lock()) + ? $this->_failure + : $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Destroy + * + * Destroys the current session. + * + * @param string $session_id Session ID + * @return bool + */ + public function destroy($session_id) + { + if ($this->_lock) + { + // Prevent previous QB calls from messing with our queries + $this->_db->reset_query(); + + $this->_db->where('id', $session_id); + if ($this->_config['match_ip']) + { + $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); + } + + if ( ! $this->_db->delete($this->_config['save_path'])) + { + return $this->_failure; + } + } + + if ($this->close() === $this->_success) + { + $this->_cookie_destroy(); + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Garbage Collector + * + * Deletes expired sessions + * + * @param int $maxlifetime Maximum lifetime of sessions + * @return bool + */ + public function gc($maxlifetime) + { + // Prevent previous QB calls from messing with our queries + $this->_db->reset_query(); + + return ($this->_db->delete($this->_config['save_path'], 'timestamp < '.(time() - $maxlifetime))) + ? $this->_success + : $this->_failure; + } + + // -------------------------------------------------------------------- + + /** + * Validate ID + * + * Checks whether a session ID record exists server-side, + * to enforce session.use_strict_mode. + * + * @param string $id + * @return bool + */ + public function validateSessionId($id) + { + // Prevent previous QB calls from messing with our queries + $this->_db->reset_query(); + + $this->_db->select('1')->from($this->_config['save_path'])->where('id', $id); + empty($this->_config['match_ip']) OR $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); + $result = $this->_db->get(); + empty($result) OR $result = $result->row(); + + return ! empty($result); + } + + // ------------------------------------------------------------------------ + + /** + * Get lock + * + * Acquires a lock, depending on the underlying platform. + * + * @param string $session_id Session ID + * @return bool + */ + protected function _get_lock($session_id) + { + if ($this->_platform === 'mysql') + { + $arg = md5($session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : '')); + if ($this->_db->query("SELECT GET_LOCK('".$arg."', 300) AS ci_session_lock")->row()->ci_session_lock) + { + $this->_lock = $arg; + return TRUE; + } + + return FALSE; + } + elseif ($this->_platform === 'postgre') + { + $arg = "hashtext('".$session_id."')".($this->_config['match_ip'] ? ", hashtext('".$_SERVER['REMOTE_ADDR']."')" : ''); + if ($this->_db->simple_query('SELECT pg_advisory_lock('.$arg.')')) + { + $this->_lock = $arg; + return TRUE; + } + + return FALSE; + } + + return parent::_get_lock($session_id); + } + + // ------------------------------------------------------------------------ + + /** + * Release lock + * + * Releases a previously acquired lock + * + * @return bool + */ + protected function _release_lock() + { + if ( ! $this->_lock) + { + return TRUE; + } + + if ($this->_platform === 'mysql') + { + if ($this->_db->query("SELECT RELEASE_LOCK('".$this->_lock."') AS ci_session_lock")->row()->ci_session_lock) + { + $this->_lock = FALSE; + return TRUE; + } + + return FALSE; + } + elseif ($this->_platform === 'postgre') + { + if ($this->_db->simple_query('SELECT pg_advisory_unlock('.$this->_lock.')')) + { + $this->_lock = FALSE; + return TRUE; + } + + return FALSE; + } + + return parent::_release_lock(); + } +} diff --git a/system/libraries/Session/drivers/Session_files_driver.php b/system/libraries/Session/drivers/Session_files_driver.php new file mode 100644 index 0000000..2899b7d --- /dev/null +++ b/system/libraries/Session/drivers/Session_files_driver.php @@ -0,0 +1,428 @@ +_config['save_path'])) + { + $this->_config['save_path'] = rtrim($this->_config['save_path'], '/\\'); + ini_set('session.save_path', $this->_config['save_path']); + } + else + { + log_message('debug', 'Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.'); + $this->_config['save_path'] = rtrim(ini_get('session.save_path'), '/\\'); + } + + $this->_sid_regexp = $this->_config['_sid_regexp']; + + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + } + + // ------------------------------------------------------------------------ + + /** + * Open + * + * Sanitizes the save_path directory. + * + * @param string $save_path Path to session files' directory + * @param string $name Session cookie name + * @return bool + */ + public function open($save_path, $name) + { + if ( ! is_dir($save_path)) + { + if ( ! mkdir($save_path, 0700, TRUE)) + { + log_message('error', "Session: Configured save path '".$this->_config['save_path']."' is not a directory, doesn't exist or cannot be created."); + return $this->_failure; + } + } + elseif ( ! is_writable($save_path)) + { + log_message('error', "Session: Configured save path '".$this->_config['save_path']."' is not writable by the PHP process."); + return $this->_failure; + } + + $this->_config['save_path'] = $save_path; + $this->_file_path = $this->_config['save_path'].DIRECTORY_SEPARATOR + .$name // we'll use the session cookie name as a prefix to avoid collisions + .($this->_config['match_ip'] ? md5($_SERVER['REMOTE_ADDR']) : ''); + + $this->php5_validate_id(); + + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Read + * + * Reads session data and acquires a lock + * + * @param string $session_id Session ID + * @return string Serialized session data + */ + public function read($session_id) + { + // This might seem weird, but PHP 5.6 introduces session_reset(), + // which re-reads session data + if ($this->_file_handle === NULL) + { + $this->_file_new = ! file_exists($this->_file_path.$session_id); + + if (($this->_file_handle = fopen($this->_file_path.$session_id, 'c+b')) === FALSE) + { + log_message('error', "Session: Unable to open file '".$this->_file_path.$session_id."'."); + return $this->_failure; + } + + if (flock($this->_file_handle, LOCK_EX) === FALSE) + { + log_message('error', "Session: Unable to obtain lock for file '".$this->_file_path.$session_id."'."); + fclose($this->_file_handle); + $this->_file_handle = NULL; + return $this->_failure; + } + + // Needed by write() to detect session_regenerate_id() calls + $this->_session_id = $session_id; + + if ($this->_file_new) + { + chmod($this->_file_path.$session_id, 0600); + $this->_fingerprint = md5(''); + return ''; + } + } + // We shouldn't need this, but apparently we do ... + // See https://github.com/bcit-ci/CodeIgniter/issues/4039 + elseif ($this->_file_handle === FALSE) + { + return $this->_failure; + } + else + { + rewind($this->_file_handle); + } + + $session_data = ''; + for ($read = 0, $length = filesize($this->_file_path.$session_id); $read < $length; $read += self::strlen($buffer)) + { + if (($buffer = fread($this->_file_handle, $length - $read)) === FALSE) + { + break; + } + + $session_data .= $buffer; + } + + $this->_fingerprint = md5($session_data); + return $session_data; + } + + // ------------------------------------------------------------------------ + + /** + * Write + * + * Writes (create / update) session data + * + * @param string $session_id Session ID + * @param string $session_data Serialized session data + * @return bool + */ + public function write($session_id, $session_data) + { + // If the two IDs don't match, we have a session_regenerate_id() call + // and we need to close the old handle and open a new one + if ($session_id !== $this->_session_id && ($this->close() === $this->_failure OR $this->read($session_id) === $this->_failure)) + { + return $this->_failure; + } + + if ( ! is_resource($this->_file_handle)) + { + return $this->_failure; + } + elseif ($this->_fingerprint === md5($session_data)) + { + return ( ! $this->_file_new && ! touch($this->_file_path.$session_id)) + ? $this->_failure + : $this->_success; + } + + if ( ! $this->_file_new) + { + ftruncate($this->_file_handle, 0); + rewind($this->_file_handle); + } + + if (($length = strlen($session_data)) > 0) + { + for ($written = 0; $written < $length; $written += $result) + { + if (($result = fwrite($this->_file_handle, substr($session_data, $written))) === FALSE) + { + break; + } + } + + if ( ! is_int($result)) + { + $this->_fingerprint = md5(substr($session_data, 0, $written)); + log_message('error', 'Session: Unable to write data.'); + return $this->_failure; + } + } + + $this->_fingerprint = md5($session_data); + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Close + * + * Releases locks and closes file descriptor. + * + * @return bool + */ + public function close() + { + if (is_resource($this->_file_handle)) + { + flock($this->_file_handle, LOCK_UN); + fclose($this->_file_handle); + + $this->_file_handle = $this->_file_new = $this->_session_id = NULL; + } + + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Destroy + * + * Destroys the current session. + * + * @param string $session_id Session ID + * @return bool + */ + public function destroy($session_id) + { + if ($this->close() === $this->_success) + { + if (file_exists($this->_file_path.$session_id)) + { + $this->_cookie_destroy(); + return unlink($this->_file_path.$session_id) + ? $this->_success + : $this->_failure; + } + + return $this->_success; + } + elseif ($this->_file_path !== NULL) + { + clearstatcache(); + if (file_exists($this->_file_path.$session_id)) + { + $this->_cookie_destroy(); + return unlink($this->_file_path.$session_id) + ? $this->_success + : $this->_failure; + } + + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Garbage Collector + * + * Deletes expired sessions + * + * @param int $maxlifetime Maximum lifetime of sessions + * @return bool + */ + public function gc($maxlifetime) + { + if ( ! is_dir($this->_config['save_path']) OR ($directory = opendir($this->_config['save_path'])) === FALSE) + { + log_message('debug', "Session: Garbage collector couldn't list files under directory '".$this->_config['save_path']."'."); + return $this->_failure; + } + + $ts = time() - $maxlifetime; + + $pattern = ($this->_config['match_ip'] === TRUE) + ? '[0-9a-f]{32}' + : ''; + + $pattern = sprintf( + '#\A%s'.$pattern.$this->_sid_regexp.'\z#', + preg_quote($this->_config['cookie_name']) + ); + + while (($file = readdir($directory)) !== FALSE) + { + // If the filename doesn't match this pattern, it's either not a session file or is not ours + if ( ! preg_match($pattern, $file) + OR ! is_file($this->_config['save_path'].DIRECTORY_SEPARATOR.$file) + OR ($mtime = filemtime($this->_config['save_path'].DIRECTORY_SEPARATOR.$file)) === FALSE + OR $mtime > $ts) + { + continue; + } + + unlink($this->_config['save_path'].DIRECTORY_SEPARATOR.$file); + } + + closedir($directory); + + return $this->_success; + } + + // -------------------------------------------------------------------- + + /** + * Validate ID + * + * Checks whether a session ID record exists server-side, + * to enforce session.use_strict_mode. + * + * @param string $id + * @return bool + */ + public function validateSessionId($id) + { + $result = is_file($this->_file_path.$id); + clearstatcache(TRUE, $this->_file_path.$id); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } +} diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php new file mode 100644 index 0000000..854adf8 --- /dev/null +++ b/system/libraries/Session/drivers/Session_memcached_driver.php @@ -0,0 +1,397 @@ +_config['save_path'])) + { + log_message('error', 'Session: No Memcached save path configured.'); + } + + if ($this->_config['match_ip'] === TRUE) + { + $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; + } + } + + // ------------------------------------------------------------------------ + + /** + * Open + * + * Sanitizes save_path and initializes connections. + * + * @param string $save_path Server path(s) + * @param string $name Session cookie name, unused + * @return bool + */ + public function open($save_path, $name) + { + $this->_memcached = new Memcached(); + $this->_memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, TRUE); // required for touch() usage + $server_list = array(); + foreach ($this->_memcached->getServerList() as $server) + { + $server_list[] = $server['host'].':'.$server['port']; + } + + if ( ! preg_match_all('#,?([^,:]+)\:(\d{1,5})(?:\:(\d+))?#', $this->_config['save_path'], $matches, PREG_SET_ORDER)) + { + $this->_memcached = NULL; + log_message('error', 'Session: Invalid Memcached save path format: '.$this->_config['save_path']); + return $this->_failure; + } + + foreach ($matches as $match) + { + // If Memcached already has this server (or if the port is invalid), skip it + if (in_array($match[1].':'.$match[2], $server_list, TRUE)) + { + log_message('debug', 'Session: Memcached server pool already has '.$match[1].':'.$match[2]); + continue; + } + + if ( ! $this->_memcached->addServer($match[1], $match[2], isset($match[3]) ? $match[3] : 0)) + { + log_message('error', 'Could not add '.$match[1].':'.$match[2].' to Memcached server pool.'); + } + else + { + $server_list[] = $match[1].':'.$match[2]; + } + } + + if (empty($server_list)) + { + log_message('error', 'Session: Memcached server pool is empty.'); + return $this->_failure; + } + + $this->php5_validate_id(); + + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Read + * + * Reads session data and acquires a lock + * + * @param string $session_id Session ID + * @return string Serialized session data + */ + public function read($session_id) + { + if (isset($this->_memcached) && $this->_get_lock($session_id)) + { + // Needed by write() to detect session_regenerate_id() calls + $this->_session_id = $session_id; + + $session_data = (string) $this->_memcached->get($this->_key_prefix.$session_id); + $this->_fingerprint = md5($session_data); + return $session_data; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Write + * + * Writes (create / update) session data + * + * @param string $session_id Session ID + * @param string $session_data Serialized session data + * @return bool + */ + public function write($session_id, $session_data) + { + if ( ! isset($this->_memcached, $this->_lock_key)) + { + return $this->_failure; + } + // Was the ID regenerated? + elseif ($session_id !== $this->_session_id) + { + if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) + { + return $this->_failure; + } + + $this->_fingerprint = md5(''); + $this->_session_id = $session_id; + } + + $key = $this->_key_prefix.$session_id; + + $this->_memcached->replace($this->_lock_key, time(), 300); + if ($this->_fingerprint !== ($fingerprint = md5($session_data))) + { + if ($this->_memcached->set($key, $session_data, $this->_config['expiration'])) + { + $this->_fingerprint = $fingerprint; + return $this->_success; + } + + return $this->_failure; + } + elseif ( + $this->_memcached->touch($key, $this->_config['expiration']) + OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration'])) + ) + { + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Close + * + * Releases locks and closes connection. + * + * @return bool + */ + public function close() + { + if (isset($this->_memcached)) + { + $this->_release_lock(); + if ( ! $this->_memcached->quit()) + { + return $this->_failure; + } + + $this->_memcached = NULL; + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Destroy + * + * Destroys the current session. + * + * @param string $session_id Session ID + * @return bool + */ + public function destroy($session_id) + { + if (isset($this->_memcached, $this->_lock_key)) + { + $this->_memcached->delete($this->_key_prefix.$session_id); + $this->_cookie_destroy(); + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Garbage Collector + * + * Deletes expired sessions + * + * @param int $maxlifetime Maximum lifetime of sessions + * @return bool + */ + public function gc($maxlifetime) + { + // Not necessary, Memcached takes care of that. + return $this->_success; + } + + // -------------------------------------------------------------------- + + /** + * Validate ID + * + * Checks whether a session ID record exists server-side, + * to enforce session.use_strict_mode. + * + * @param string $id + * @return bool + */ + public function validateSessionId($id) + { + $this->_memcached->get($this->_key_prefix.$id); + return ($this->_memcached->getResultCode() === Memcached::RES_SUCCESS); + } + + // ------------------------------------------------------------------------ + + /** + * Get lock + * + * Acquires an (emulated) lock. + * + * @param string $session_id Session ID + * @return bool + */ + protected function _get_lock($session_id) + { + // PHP 7 reuses the SessionHandler object on regeneration, + // so we need to check here if the lock key is for the + // correct session ID. + if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') + { + if ( ! $this->_memcached->replace($this->_lock_key, time(), 300)) + { + return ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND) + ? $this->_memcached->add($this->_lock_key, time(), 300) + : FALSE; + } + + return TRUE; + } + + // 30 attempts to obtain a lock, in case another request already has it + $lock_key = $this->_key_prefix.$session_id.':lock'; + $attempt = 0; + do + { + if ($this->_memcached->get($lock_key)) + { + sleep(1); + continue; + } + + $method = ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND) ? 'add' : 'set'; + if ( ! $this->_memcached->$method($lock_key, time(), 300)) + { + log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); + return FALSE; + } + + $this->_lock_key = $lock_key; + break; + } + while (++$attempt < 30); + + if ($attempt === 30) + { + log_message('error', 'Session: Unable to obtain lock for '.$this->_key_prefix.$session_id.' after 30 attempts, aborting.'); + return FALSE; + } + + $this->_lock = TRUE; + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Release lock + * + * Releases a previously acquired lock + * + * @return bool + */ + protected function _release_lock() + { + if (isset($this->_memcached, $this->_lock_key) && $this->_lock) + { + if ( ! $this->_memcached->delete($this->_lock_key) && $this->_memcached->getResultCode() !== Memcached::RES_NOTFOUND) + { + log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key); + return FALSE; + } + + $this->_lock_key = NULL; + $this->_lock = FALSE; + } + + return TRUE; + } +} diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php new file mode 100644 index 0000000..df38174 --- /dev/null +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -0,0 +1,459 @@ +=')) + { + $this->_setTimeout_name = 'expire'; + $this->_delete_name = 'del'; + $this->_ping_success = TRUE; + } + else + { + $this->_setTimeout_name = 'setTimeout'; + $this->_delete_name = 'delete'; + $this->_ping_success = '+PONG'; + } + + if (empty($this->_config['save_path'])) + { + log_message('error', 'Session: No Redis save path configured.'); + } + elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches)) + { + 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 ($this->_config['match_ip'] === TRUE) + { + $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; + } + } + + // ------------------------------------------------------------------------ + + /** + * Open + * + * Sanitizes save_path and initializes connection. + * + * @param string $save_path Server path + * @param string $name Session cookie name, unused + * @return bool + */ + public function open($save_path, $name) + { + if (empty($this->_config['save_path'])) + { + return $this->_failure; + } + + $redis = new Redis(); + if ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) + { + 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 + { + $this->_redis = $redis; + $this->php5_validate_id(); + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Read + * + * Reads session data and acquires a lock + * + * @param string $session_id Session ID + * @return string Serialized session data + */ + public function read($session_id) + { + if (isset($this->_redis) && $this->_get_lock($session_id)) + { + // Needed by write() to detect session_regenerate_id() calls + $this->_session_id = $session_id; + + $session_data = $this->_redis->get($this->_key_prefix.$session_id); + + is_string($session_data) + ? $this->_key_exists = TRUE + : $session_data = ''; + + $this->_fingerprint = md5($session_data); + return $session_data; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Write + * + * Writes (create / update) session data + * + * @param string $session_id Session ID + * @param string $session_data Serialized session data + * @return bool + */ + public function write($session_id, $session_data) + { + if ( ! isset($this->_redis, $this->_lock_key)) + { + return $this->_failure; + } + // Was the ID regenerated? + elseif ($session_id !== $this->_session_id) + { + if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) + { + return $this->_failure; + } + + $this->_key_exists = FALSE; + $this->_session_id = $session_id; + } + + $this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300); + if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) + { + if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) + { + $this->_fingerprint = $fingerprint; + $this->_key_exists = TRUE; + return $this->_success; + } + + return $this->_failure; + } + + return ($this->_redis->{$this->_setTimeout_name}($this->_key_prefix.$session_id, $this->_config['expiration'])) + ? $this->_success + : $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Close + * + * Releases locks and closes connection. + * + * @return bool + */ + public function close() + { + if (isset($this->_redis)) + { + try { + if ($this->_redis->ping() === $this->_ping_success) + { + $this->_release_lock(); + if ($this->_redis->close() === FALSE) + { + return $this->_failure; + } + } + } + catch (RedisException $e) + { + log_message('error', 'Session: Got RedisException on close(): '.$e->getMessage()); + } + + $this->_redis = NULL; + return $this->_success; + } + + return $this->_success; + } + + // ------------------------------------------------------------------------ + + /** + * Destroy + * + * Destroys the current session. + * + * @param string $session_id Session ID + * @return bool + */ + public function destroy($session_id) + { + if (isset($this->_redis, $this->_lock_key)) + { + if (($result = $this->_redis->{$this->_delete_name}($this->_key_prefix.$session_id)) !== 1) + { + log_message('debug', 'Session: Redis::'.$this->_delete_name.'() expected to return 1, got '.var_export($result, TRUE).' instead.'); + } + + $this->_cookie_destroy(); + return $this->_success; + } + + return $this->_failure; + } + + // ------------------------------------------------------------------------ + + /** + * Garbage Collector + * + * Deletes expired sessions + * + * @param int $maxlifetime Maximum lifetime of sessions + * @return bool + */ + public function gc($maxlifetime) + { + // Not necessary, Redis takes care of that. + return $this->_success; + } + + // -------------------------------------------------------------------- + + /** + * Validate ID + * + * Checks whether a session ID record exists server-side, + * to enforce session.use_strict_mode. + * + * @param string $id + * @return bool + */ + public function validateSessionId($id) + { + return (bool) $this->_redis->exists($this->_key_prefix.$id); + } + + // ------------------------------------------------------------------------ + + /** + * Get lock + * + * Acquires an (emulated) lock. + * + * @param string $session_id Session ID + * @return bool + */ + protected function _get_lock($session_id) + { + // PHP 7 reuses the SessionHandler object on regeneration, + // so we need to check here if the lock key is for the + // correct session ID. + if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') + { + return $this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300); + } + + // 30 attempts to obtain a lock, in case another request already has it + $lock_key = $this->_key_prefix.$session_id.':lock'; + $attempt = 0; + do + { + if (($ttl = $this->_redis->ttl($lock_key)) > 0) + { + sleep(1); + continue; + } + + if ($ttl === -2 && ! $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300))) + { + // Sleep for 1s to wait for lock releases. + sleep(1); + continue; + } + elseif ( ! $this->_redis->setex($lock_key, 300, time())) + { + log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); + return FALSE; + } + + $this->_lock_key = $lock_key; + break; + } + while (++$attempt < 30); + + if ($attempt === 30) + { + log_message('error', 'Session: Unable to obtain lock for '.$this->_key_prefix.$session_id.' after 30 attempts, aborting.'); + return FALSE; + } + elseif ($ttl === -1) + { + log_message('debug', 'Session: Lock for '.$this->_key_prefix.$session_id.' had no TTL, overriding.'); + } + + $this->_lock = TRUE; + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Release lock + * + * Releases a previously acquired lock + * + * @return bool + */ + protected function _release_lock() + { + if (isset($this->_redis, $this->_lock_key) && $this->_lock) + { + if ( ! $this->_redis->{$this->_delete_name}($this->_lock_key)) + { + log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key); + return FALSE; + } + + $this->_lock_key = NULL; + $this->_lock = FALSE; + } + + return TRUE; + } + +} diff --git a/system/libraries/Session/drivers/index.html b/system/libraries/Session/drivers/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/libraries/Session/drivers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/libraries/Session/index.html b/system/libraries/Session/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/libraries/Session/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php deleted file mode 100755 index 5696f4a..0000000 --- a/system/libraries/Sha1.php +++ /dev/null @@ -1,252 +0,0 @@ -> 6) + 1; - - for ($i = 0; $i < $n * 16; $i++) - { - $x[$i] = 0; - } - - for ($i = 0; $i < strlen($str); $i++) - { - $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); - } - - $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); - - $x[$n * 16 - 1] = strlen($str) * 8; - - $a = 1732584193; - $b = -271733879; - $c = -1732584194; - $d = 271733878; - $e = -1009589776; - - for ($i = 0; $i < count($x); $i += 16) - { - $olda = $a; - $oldb = $b; - $oldc = $c; - $oldd = $d; - $olde = $e; - - for ($j = 0; $j < 80; $j++) - { - if ($j < 16) - { - $w[$j] = $x[$i + $j]; - } - else - { - $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); - } - - $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); - - $e = $d; - $d = $c; - $c = $this->_rol($b, 30); - $b = $a; - $a = $t; - } - - $a = $this->_safe_add($a, $olda); - $b = $this->_safe_add($b, $oldb); - $c = $this->_safe_add($c, $oldc); - $d = $this->_safe_add($d, $oldd); - $e = $this->_safe_add($e, $olde); - } - - return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); - } - - // -------------------------------------------------------------------- - - /** - * Convert a decimal to hex - * - * @access private - * @param string - * @return string - */ - function _hex($str) - { - $str = dechex($str); - - if (strlen($str) == 7) - { - $str = '0'.$str; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Return result based on iteration - * - * @access private - * @return string - */ - function _ft($t, $b, $c, $d) - { - if ($t < 20) - return ($b & $c) | ((~$b) & $d); - if ($t < 40) - return $b ^ $c ^ $d; - if ($t < 60) - return ($b & $c) | ($b & $d) | ($c & $d); - - return $b ^ $c ^ $d; - } - - // -------------------------------------------------------------------- - - /** - * Determine the additive constant - * - * @access private - * @return string - */ - function _kt($t) - { - if ($t < 20) - { - return 1518500249; - } - else if ($t < 40) - { - return 1859775393; - } - else if ($t < 60) - { - return -1894007588; - } - else - { - return -899497514; - } - } - - // -------------------------------------------------------------------- - - /** - * Add integers, wrapping at 2^32 - * - * @access private - * @return string - */ - function _safe_add($x, $y) - { - $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); - $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); - - return ($msw << 16) | ($lsw & 0xFFFF); - } - - // -------------------------------------------------------------------- - - /** - * Bitwise rotate a 32-bit number - * - * @access private - * @return integer - */ - function _rol($num, $cnt) - { - return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); - } - - // -------------------------------------------------------------------- - - /** - * Pad string with zero - * - * @access private - * @return string - */ - function _zero_fill($a, $b) - { - $bin = decbin($a); - - if (strlen($bin) < $b) - { - $bin = 0; - } - else - { - $bin = substr($bin, 0, strlen($bin) - $b); - } - - for ($i=0; $i < $b; $i++) - { - $bin = "0".$bin; - } - - return bindec($bin); - } -} -// END CI_SHA - -/* End of file Sha1.php */ -/* Location: ./system/libraries/Sha1.php */ \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php old mode 100755 new mode 100644 index 203f25b..06e8d70 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,532 +1,538 @@ -template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the table heading - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_heading() - { - $args = func_get_args(); - $this->heading = $this->_prep_args($args); - } - - // -------------------------------------------------------------------- - - /** - * Set columns. Takes a one-dimensional array as input and creates - * a multi-dimensional array with a depth equal to the number of - * columns. This allows a single array with many elements to be - * displayed in a table that has a fixed column count. - * - * @access public - * @param array - * @param int - * @return void - */ - function make_columns($array = array(), $col_limit = 0) - { - if ( ! is_array($array) OR count($array) == 0) - { - return FALSE; - } - - // Turn off the auto-heading feature since it's doubtful we - // will want headings from a one-dimensional array - $this->auto_heading = FALSE; - - if ($col_limit == 0) - { - return $array; - } - - $new = array(); - while (count($array) > 0) - { - $temp = array_splice($array, 0, $col_limit); - - if (count($temp) < $col_limit) - { - for ($i = count($temp); $i < $col_limit; $i++) - { - $temp[] = ' '; - } - } - - $new[] = $temp; - } - - return $new; - } - - // -------------------------------------------------------------------- - - /** - * Set "empty" cells - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_empty($value) - { - $this->empty_cells = $value; - } - - // -------------------------------------------------------------------- - - /** - * Add a table row - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function add_row() - { - $args = func_get_args(); - $this->rows[] = $this->_prep_args($args); - } - - // -------------------------------------------------------------------- - - /** - * Prep Args - * - * Ensures a standard associative array format for all cell data - * - * @access public - * @param type - * @return type - */ - function _prep_args($args) - { - // If there is no $args[0], skip this and treat as an associative array - // This can happen if there is only a single key, for example this is passed to table->generate - // array(array('foo'=>'bar')) - if (isset($args[0]) AND (count($args) == 1 && is_array($args[0]))) - { - // args sent as indexed array - if ( ! isset($args[0]['data'])) - { - foreach ($args[0] as $key => $val) - { - if (is_array($val) && isset($val['data'])) - { - $args[$key] = $val; - } - else - { - $args[$key] = array('data' => $val); - } - } - } - } - else - { - foreach ($args as $key => $val) - { - if ( ! is_array($val)) - { - $args[$key] = array('data' => $val); - } - } - } - - return $args; - } - - // -------------------------------------------------------------------- - - /** - * Add a table caption - * - * @access public - * @param string - * @return void - */ - function set_caption($caption) - { - $this->caption = $caption; - } - - // -------------------------------------------------------------------- - - /** - * Generate the table - * - * @access public - * @param mixed - * @return string - */ - function generate($table_data = NULL) - { - // The table data can optionally be passed to this function - // either as a database result object or an array - if ( ! is_null($table_data)) - { - if (is_object($table_data)) - { - $this->_set_from_object($table_data); - } - elseif (is_array($table_data)) - { - $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; - $this->_set_from_array($table_data, $set_heading); - } - } - - // Is there anything to display? No? Smite them! - if (count($this->heading) == 0 AND count($this->rows) == 0) - { - return 'Undefined table data'; - } - - // Compile and validate the template date - $this->_compile_template(); - - // set a custom cell manipulation function to a locally scoped variable so its callable - $function = $this->function; - - // Build the table! - - $out = $this->template['table_open']; - $out .= $this->newline; - - // Add any caption here - if ($this->caption) - { - $out .= $this->newline; - $out .= '' . $this->caption . ''; - $out .= $this->newline; - } - - // Is there a table heading to display? - if (count($this->heading) > 0) - { - $out .= $this->template['thead_open']; - $out .= $this->newline; - $out .= $this->template['heading_row_start']; - $out .= $this->newline; - - foreach ($this->heading as $heading) - { - $temp = $this->template['heading_cell_start']; - - foreach ($heading as $key => $val) - { - if ($key != 'data') - { - $temp = str_replace('template['heading_cell_end']; - } - - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - $out .= $this->template['thead_close']; - $out .= $this->newline; - } - - // Build the table rows - if (count($this->rows) > 0) - { - $out .= $this->template['tbody_open']; - $out .= $this->newline; - - $i = 1; - foreach ($this->rows as $row) - { - if ( ! is_array($row)) - { - break; - } - - // We use modulus to alternate the row colors - $name = (fmod($i++, 2)) ? '' : 'alt_'; - - $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; - - foreach ($row as $cell) - { - $temp = $this->template['cell_'.$name.'start']; - - foreach ($cell as $key => $val) - { - if ($key != 'data') - { - $temp = str_replace('empty_cells; - } - else - { - if ($function !== FALSE && is_callable($function)) - { - $out .= call_user_func($function, $cell); - } - else - { - $out .= $cell; - } - } - - $out .= $this->template['cell_'.$name.'end']; - } - - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; - } - - $out .= $this->template['tbody_close']; - $out .= $this->newline; - } - - $out .= $this->template['table_close']; - - // Clear table class properties before generating the table - $this->clear(); - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Clears the table arrays. Useful if multiple tables are being generated - * - * @access public - * @return void - */ - function clear() - { - $this->rows = array(); - $this->heading = array(); - $this->auto_heading = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set table data from a database result object - * - * @access public - * @param object - * @return void - */ - function _set_from_object($query) - { - if ( ! is_object($query)) - { - return FALSE; - } - - // First generate the headings from the table column names - if (count($this->heading) == 0) - { - if ( ! method_exists($query, 'list_fields')) - { - return FALSE; - } - - $this->heading = $this->_prep_args($query->list_fields()); - } - - // Next blast through the result array and build out the rows - - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $this->rows[] = $this->_prep_args($row); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set table data from an array - * - * @access public - * @param array - * @return void - */ - function _set_from_array($data, $set_heading = TRUE) - { - if ( ! is_array($data) OR count($data) == 0) - { - return FALSE; - } - - $i = 0; - foreach ($data as $row) - { - // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE) - { - $this->heading = $this->_prep_args($row); - } - else - { - $this->rows[] = $this->_prep_args($row); - } - - $i++; - } - } - - // -------------------------------------------------------------------- - - /** - * Compile Template - * - * @access private - * @return void - */ - function _compile_template() - { - if ($this->template == NULL) - { - $this->template = $this->_default_template(); - return; - } - - $this->temp = $this->_default_template(); - foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) - { - if ( ! isset($this->template[$val])) - { - $this->template[$val] = $this->temp[$val]; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Default Template - * - * @access private - * @return void - */ - function _default_template() - { - return array ( - 'table_open' => '', - - 'thead_open' => '', - 'thead_close' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', - - 'tbody_open' => '', - 'tbody_close' => '', - - 'row_start' => '', - 'row_end' => '', - 'cell_start' => '', - - 'row_alt_start' => '', - 'row_alt_end' => '', - 'cell_alt_start' => '', - - 'table_close' => '
    ', - 'heading_cell_end' => '
    ', - 'cell_end' => '
    ', - 'cell_alt_end' => '
    ' - ); - } - + /** + * Data for table rows + * + * @var array + */ + public $rows = array(); + + /** + * Data for table heading + * + * @var array + */ + public $heading = array(); + + /** + * Whether or not to automatically create the table header + * + * @var bool + */ + public $auto_heading = TRUE; + + /** + * Table caption + * + * @var string + */ + public $caption = NULL; + + /** + * Table layout template + * + * @var array + */ + public $template = NULL; + + /** + * Newline setting + * + * @var string + */ + public $newline = "\n"; + + /** + * Contents of empty cells + * + * @var string + */ + public $empty_cells = ''; + + /** + * Callback for custom table layout + * + * @var function + */ + public $function = NULL; + + /** + * Set the template from the table config file if it exists + * + * @param array $config (default: array()) + * @return void + */ + public function __construct($config = array()) + { + // initialize config + foreach ($config as $key => $val) + { + $this->template[$key] = $val; + } + + log_message('info', 'Table Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * @param array $template + * @return bool + */ + public function set_template($template) + { + if ( ! is_array($template)) + { + return FALSE; + } + + $this->template = $template; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set the table heading + * + * Can be passed as an array or discreet params + * + * @param mixed + * @return CI_Table + */ + public function set_heading($args = array()) + { + $this->heading = $this->_prep_args(func_get_args()); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set columns. Takes a one-dimensional array as input and creates + * a multi-dimensional array with a depth equal to the number of + * columns. This allows a single array with many elements to be + * displayed in a table that has a fixed column count. + * + * @param array $array + * @param int $col_limit + * @return array + */ + public function make_columns($array = array(), $col_limit = 0) + { + if ( ! is_array($array) OR count($array) === 0 OR ! is_int($col_limit)) + { + return FALSE; + } + + // Turn off the auto-heading feature since it's doubtful we + // will want headings from a one-dimensional array + $this->auto_heading = FALSE; + + if ($col_limit === 0) + { + return $array; + } + + $new = array(); + do + { + $temp = array_splice($array, 0, $col_limit); + + if (count($temp) < $col_limit) + { + for ($i = count($temp); $i < $col_limit; $i++) + { + $temp[] = ' '; + } + } + + $new[] = $temp; + } + while (count($array) > 0); + + return $new; + } + + // -------------------------------------------------------------------- + + /** + * Set "empty" cells + * + * Can be passed as an array or discreet params + * + * @param mixed $value + * @return CI_Table + */ + public function set_empty($value) + { + $this->empty_cells = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Add a table row + * + * Can be passed as an array or discreet params + * + * @param mixed + * @return CI_Table + */ + public function add_row($args = array()) + { + $this->rows[] = $this->_prep_args(func_get_args()); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Prep Args + * + * Ensures a standard associative array format for all cell data + * + * @param array + * @return array + */ + protected function _prep_args($args) + { + // If there is no $args[0], skip this and treat as an associative array + // This can happen if there is only a single key, for example this is passed to table->generate + // array(array('foo'=>'bar')) + if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) + { + $args = $args[0]; + } + + foreach ($args as $key => $val) + { + is_array($val) OR $args[$key] = array('data' => $val); + } + + return $args; + } + + // -------------------------------------------------------------------- + + /** + * Add a table caption + * + * @param string $caption + * @return CI_Table + */ + public function set_caption($caption) + { + $this->caption = $caption; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Generate the table + * + * @param mixed $table_data + * @return string + */ + public function generate($table_data = NULL) + { + // The table data can optionally be passed to this function + // either as a database result object or an array + if ( ! empty($table_data)) + { + if ($table_data instanceof CI_DB_result) + { + $this->_set_from_db_result($table_data); + } + elseif (is_array($table_data)) + { + $this->_set_from_array($table_data); + } + } + + // Is there anything to display? No? Smite them! + if (empty($this->heading) && empty($this->rows)) + { + return 'Undefined table data'; + } + + // Compile and validate the template date + $this->_compile_template(); + + // Validate a possibly existing custom cell manipulation function + if (isset($this->function) && ! is_callable($this->function)) + { + $this->function = NULL; + } + + // Build the table! + + $out = $this->template['table_open'].$this->newline; + + // Add any caption here + if ($this->caption) + { + $out .= ''.$this->caption.''.$this->newline; + } + + // Is there a table heading to display? + if ( ! empty($this->heading)) + { + $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline; + + foreach ($this->heading as $heading) + { + $temp = $this->template['heading_cell_start']; + + foreach ($heading as $key => $val) + { + if ($key !== 'data') + { + $temp = str_replace('template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end'].$this->newline.$this->template['thead_close'].$this->newline; + } + + // Build the table rows + if ( ! empty($this->rows)) + { + $out .= $this->template['tbody_open'].$this->newline; + + $i = 1; + foreach ($this->rows as $row) + { + if ( ! is_array($row)) + { + break; + } + + // We use modulus to alternate the row colors + $name = fmod($i++, 2) ? '' : 'alt_'; + + $out .= $this->template['row_'.$name.'start'].$this->newline; + + foreach ($row as $cell) + { + $temp = $this->template['cell_'.$name.'start']; + + foreach ($cell as $key => $val) + { + if ($key !== 'data') + { + $temp = str_replace('empty_cells; + } + elseif (isset($this->function)) + { + $out .= call_user_func($this->function, $cell); + } + else + { + $out .= $cell; + } + + $out .= $this->template['cell_'.$name.'end']; + } + + $out .= $this->template['row_'.$name.'end'].$this->newline; + } + + $out .= $this->template['tbody_close'].$this->newline; + } + + $out .= $this->template['table_close']; + + // Clear table class properties before generating the table + $this->clear(); + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Clears the table arrays. Useful if multiple tables are being generated + * + * @return CI_Table + */ + public function clear() + { + $this->rows = array(); + $this->heading = array(); + $this->auto_heading = TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set table data from a database result object + * + * @param CI_DB_result $object Database result object + * @return void + */ + protected function _set_from_db_result($object) + { + // First generate the headings from the table column names + if ($this->auto_heading === TRUE && empty($this->heading)) + { + $this->heading = $this->_prep_args($object->list_fields()); + } + + foreach ($object->result_array() as $row) + { + $this->rows[] = $this->_prep_args($row); + } + } + + // -------------------------------------------------------------------- + + /** + * Set table data from an array + * + * @param array $data + * @return void + */ + protected function _set_from_array($data) + { + if ($this->auto_heading === TRUE && empty($this->heading)) + { + $this->heading = $this->_prep_args(array_shift($data)); + } + + foreach ($data as &$row) + { + $this->rows[] = $this->_prep_args($row); + } + } + + // -------------------------------------------------------------------- + + /** + * Compile Template + * + * @return void + */ + protected function _compile_template() + { + if ($this->template === NULL) + { + $this->template = $this->_default_template(); + return; + } + + $this->temp = $this->_default_template(); + foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) + { + if ( ! isset($this->template[$val])) + { + $this->template[$val] = $this->temp[$val]; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Default Template + * + * @return array + */ + protected function _default_template() + { + return array( + 'table_open' => '', + + 'thead_open' => '', + 'thead_close' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + 'tbody_open' => '', + 'tbody_close' => '', + + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', + + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', + + 'table_close' => '
    ', + 'heading_cell_end' => '
    ', + 'cell_end' => '
    ', + 'cell_alt_end' => '
    ' + ); + } } - - -/* End of file Table.php */ -/* Location: ./system/libraries/Table.php */ \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php old mode 100755 new mode 100644 index d02c4d1..07f066d --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,549 +1,556 @@ - '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); - var $convert_ascii = TRUE; - var $response = ''; - var $error_msg = array(); - - /** - * Constructor - * - * @access public - */ - public function __construct() - { - log_message('debug', "Trackback Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback - * - * @access public - * @param array - * @return bool - */ - function send($tb_data) - { - if ( ! is_array($tb_data)) - { - $this->set_error('The send() method must be passed an array'); - return FALSE; - } - - // Pre-process the Trackback Data - foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) - { - if ( ! isset($tb_data[$item])) - { - $this->set_error('Required item missing: '.$item); - return FALSE; - } - - switch ($item) - { - case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]); - break; - case 'excerpt' : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); - break; - case 'url' : $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); - break; - default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); - break; - } - - // Convert High ASCII Characters - if ($this->convert_ascii == TRUE) - { - if ($item == 'excerpt') - { - $$item = $this->convert_ascii($$item); - } - elseif ($item == 'title') - { - $$item = $this->convert_ascii($$item); - } - elseif ($item == 'blog_name') - { - $$item = $this->convert_ascii($$item); - } - } - } - - // Build the Trackback data string - $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; - - $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset); - - // Send Trackback(s) - $return = TRUE; - if (count($ping_url) > 0) - { - foreach ($ping_url as $url) - { - if ($this->process($url, $data) == FALSE) - { - $return = FALSE; - } - } - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Receive Trackback Data - * - * This function simply validates the incoming TB data. - * It returns FALSE on failure and TRUE on success. - * If the data is valid it is set to the $this->data array - * so that it can be inserted into a database. - * - * @access public - * @return bool - */ - function receive() - { - foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) - { - if ( ! isset($_POST[$val]) OR $_POST[$val] == '') - { - $this->set_error('The following required POST variable is missing: '.$val); - return FALSE; - } - - $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); - - if ($val != 'url' && function_exists('mb_convert_encoding')) - { - $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); - } - - $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]); - - if ($val == 'excerpt') - { - $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']); - } - - $this->data[$val] = $_POST[$val]; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback Error Message - * - * Allows custom errors to be set. By default it - * sends the "incomplete information" error, as that's - * the most common one. - * - * @access public - * @param string - * @return void - */ - function send_error($message = 'Incomplete Information') - { - echo "\n\n1\n".$message."\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback Success Message - * - * This should be called when a trackback has been - * successfully received and inserted. - * - * @access public - * @return void - */ - function send_success() - { - echo "\n\n0\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a particular item - * - * @access public - * @param string - * @return string - */ - function data($item) - { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Process Trackback - * - * Opens a socket connection and passes the data to - * the server. Returns TRUE on success, FALSE on failure - * - * @access public - * @param string - * @param string - * @return bool - */ - function process($url, $data) - { - $target = parse_url($url); - - // Open the socket - if ( ! $fp = @fsockopen($target['host'], 80)) - { - $this->set_error('Invalid Connection: '.$url); - return FALSE; - } - - // Build the path - $ppath = ( ! isset($target['path'])) ? $url : $target['path']; - - $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; - - // Add the Trackback ID to the data string - if ($id = $this->get_id($url)) - { - $data = "tb_id=".$id."&".$data; - } - - // Transfer the data - fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); - fputs ($fp, "Host: " . $target['host'] . "\r\n" ); - fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); - fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); - fputs ($fp, "Connection: close\r\n\r\n" ); - fputs ($fp, $data); - - // Was it successful? - $this->response = ""; - - while ( ! feof($fp)) - { - $this->response .= fgets($fp, 128); - } - @fclose($fp); - - - if (stristr($this->response, '0') === FALSE) - { - $message = 'An unknown error was encountered'; - - if (preg_match("/(.*?)<\/message>/is", $this->response, $match)) - { - $message = trim($match['1']); - } - - $this->set_error($message); - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract Trackback URLs - * - * This function lets multiple trackbacks be sent. - * It takes a string of URLs (separated by comma or - * space) and puts each URL into an array - * - * @access public - * @param string - * @return string - */ - function extract_urls($urls) - { - // Remove the pesky white space and replace with a comma. - $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls); - - // If they use commas get rid of the doubles. - $urls = str_replace(",,", ",", $urls); - - // Remove any comma that might be at the end - if (substr($urls, -1) == ",") - { - $urls = substr($urls, 0, -1); - } - - // Break into an array via commas - $urls = preg_split('/[,]/', $urls); - - // Removes duplicates - $urls = array_unique($urls); - - array_walk($urls, array($this, 'validate_url')); - - return $urls; - } - - // -------------------------------------------------------------------- - - /** - * Validate URL - * - * Simply adds "http://" if missing - * - * @access public - * @param string - * @return string - */ - function validate_url($url) - { - $url = trim($url); - - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - } - - // -------------------------------------------------------------------- - - /** - * Find the Trackback URL's ID - * - * @access public - * @param string - * @return string - */ - function get_id($url) - { - $tb_id = ""; - - if (strpos($url, '?') !== FALSE) - { - $tb_array = explode('/', $url); - $tb_end = $tb_array[count($tb_array)-1]; - - if ( ! is_numeric($tb_end)) - { - $tb_end = $tb_array[count($tb_array)-2]; - } - - $tb_array = explode('=', $tb_end); - $tb_id = $tb_array[count($tb_array)-1]; - } - else - { - $url = rtrim($url, '/'); - - $tb_array = explode('/', $url); - $tb_id = $tb_array[count($tb_array)-1]; - - if ( ! is_numeric($tb_id)) - { - $tb_id = $tb_array[count($tb_array)-2]; - } - } - - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) - { - return FALSE; - } - else - { - return $tb_id; - } - } - - // -------------------------------------------------------------------- - - /** - * Convert Reserved XML characters to Entities - * - * @access public - * @param string - * @return string - */ - function convert_xml($str) - { - $temp = '__TEMP_AMPERSANDS__'; - - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Character limiter - * - * Limits the string based on the character count. Will preserve complete words. - * - * @access public - * @param string - * @param integer - * @param string - * @return string - */ - function limit_characters($str, $n = 500, $end_char = '…') - { - if (strlen($str) < $n) - { - return $str; - } - - $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); - - if (strlen($str) <= $n) - { - return $str; - } - - $out = ""; - foreach (explode(' ', trim($str)) as $val) - { - $out .= $val.' '; - if (strlen($out) >= $n) - { - return trim($out).$end_char; - } - } - } - - // -------------------------------------------------------------------- - - /** - * High ASCII to Entities - * - * Converts Hight ascii text and MS Word special chars - * to character entities - * - * @access public - * @param string - * @return string - */ - function convert_ascii($str) - { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - log_message('error', $msg); - $this->error_msg[] = $msg; - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @param string - * @return string - */ - function display_errors($open = '

    ', $close = '

    ') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } + /** + * Character set + * + * @var string + */ + public $charset = 'UTF-8'; + + /** + * Trackback data + * + * @var array + */ + public $data = array( + 'url' => '', + 'title' => '', + 'excerpt' => '', + 'blog_name' => '', + 'charset' => '' + ); + + /** + * Convert ASCII flag + * + * Whether to convert high-ASCII and MS Word + * characters to HTML entities. + * + * @var bool + */ + public $convert_ascii = TRUE; + + /** + * Response + * + * @var string + */ + public $response = ''; + + /** + * Error messages list + * + * @var string[] + */ + public $error_msg = array(); + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @return void + */ + public function __construct() + { + log_message('info', 'Trackback Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Send Trackback + * + * @param array + * @return bool + */ + public function send($tb_data) + { + if ( ! is_array($tb_data)) + { + $this->set_error('The send() method must be passed an array'); + return FALSE; + } + + // Pre-process the Trackback Data + foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) + { + if ( ! isset($tb_data[$item])) + { + $this->set_error('Required item missing: '.$item); + return FALSE; + } + + switch ($item) + { + case 'ping_url': + $$item = $this->extract_urls($tb_data[$item]); + break; + case 'excerpt': + $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); + break; + case 'url': + $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); + break; + default: + $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); + break; + } + + // Convert High ASCII Characters + if ($this->convert_ascii === TRUE && in_array($item, array('excerpt', 'title', 'blog_name'), TRUE)) + { + $$item = $this->convert_ascii($$item); + } + } + + // Build the Trackback data string + $charset = isset($tb_data['charset']) ? $tb_data['charset'] : $this->charset; + + $data = 'url='.rawurlencode($url).'&title='.rawurlencode($title).'&blog_name='.rawurlencode($blog_name) + .'&excerpt='.rawurlencode($excerpt).'&charset='.rawurlencode($charset); + + // Send Trackback(s) + $return = TRUE; + if (count($ping_url) > 0) + { + foreach ($ping_url as $url) + { + if ($this->process($url, $data) === FALSE) + { + $return = FALSE; + } + } + } + + return $return; + } + + // -------------------------------------------------------------------- + + /** + * Receive Trackback Data + * + * This function simply validates the incoming TB data. + * It returns FALSE on failure and TRUE on success. + * If the data is valid it is set to the $this->data array + * so that it can be inserted into a database. + * + * @return bool + */ + public function receive() + { + foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) + { + if (empty($_POST[$val])) + { + $this->set_error('The following required POST variable is missing: '.$val); + return FALSE; + } + + $this->data['charset'] = isset($_POST['charset']) ? strtoupper(trim($_POST['charset'])) : 'auto'; + + if ($val !== 'url' && MB_ENABLED === TRUE) + { + if (MB_ENABLED === TRUE) + { + $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); + } + elseif (ICONV_ENABLED === TRUE) + { + $_POST[$val] = @iconv($this->data['charset'], $this->charset.'//IGNORE', $_POST[$val]); + } + } + + $_POST[$val] = ($val !== 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]); + + if ($val === 'excerpt') + { + $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']); + } + + $this->data[$val] = $_POST[$val]; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Send Trackback Error Message + * + * Allows custom errors to be set. By default it + * sends the "incomplete information" error, as that's + * the most common one. + * + * @param string + * @return void + */ + public function send_error($message = 'Incomplete Information') + { + exit('\n\n1\n".$message."\n"); + } + + // -------------------------------------------------------------------- + + /** + * Send Trackback Success Message + * + * This should be called when a trackback has been + * successfully received and inserted. + * + * @return void + */ + public function send_success() + { + exit('\n\n0\n"); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a particular item + * + * @param string + * @return string + */ + public function data($item) + { + return isset($this->data[$item]) ? $this->data[$item] : ''; + } + + // -------------------------------------------------------------------- + + /** + * Process Trackback + * + * Opens a socket connection and passes the data to + * the server. Returns TRUE on success, FALSE on failure + * + * @param string + * @param string + * @return bool + */ + public function process($url, $data) + { + $target = parse_url($url); + + // Open the socket + if ( ! $fp = @fsockopen($target['host'], 80)) + { + $this->set_error('Invalid Connection: '.$url); + return FALSE; + } + + // Build the path + $path = isset($target['path']) ? $target['path'] : $url; + empty($target['query']) OR $path .= '?'.$target['query']; + + // Add the Trackback ID to the data string + if ($id = $this->get_id($url)) + { + $data = 'tb_id='.$id.'&'.$data; + } + + // Transfer the data + fputs($fp, 'POST '.$path." HTTP/1.0\r\n"); + fputs($fp, 'Host: '.$target['host']."\r\n"); + fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); + fputs($fp, 'Content-length: '.strlen($data)."\r\n"); + fputs($fp, "Connection: close\r\n\r\n"); + fputs($fp, $data); + + // Was it successful? + + $this->response = ''; + while ( ! feof($fp)) + { + $this->response .= fgets($fp, 128); + } + @fclose($fp); + + if (stripos($this->response, '0') === FALSE) + { + $message = preg_match('/(.*?)<\/message>/is', $this->response, $match) + ? trim($match[1]) + : 'An unknown error was encountered'; + $this->set_error($message); + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Extract Trackback URLs + * + * This function lets multiple trackbacks be sent. + * It takes a string of URLs (separated by comma or + * space) and puts each URL into an array + * + * @param string + * @return string + */ + public function extract_urls($urls) + { + // Remove the pesky white space and replace with a comma, then replace doubles. + $urls = str_replace(',,', ',', preg_replace('/\s*(\S+)\s*/', '\\1,', $urls)); + + // Break into an array via commas and remove duplicates + $urls = array_unique(preg_split('/[,]/', rtrim($urls, ','))); + + array_walk($urls, array($this, 'validate_url')); + return $urls; + } + + // -------------------------------------------------------------------- + + /** + * Validate URL + * + * Simply adds "http://" if missing + * + * @param string + * @return void + */ + public function validate_url(&$url) + { + $url = trim($url); + + if (stripos($url, 'http') !== 0) + { + $url = 'http://'.$url; + } + } + + // -------------------------------------------------------------------- + + /** + * Find the Trackback URL's ID + * + * @param string + * @return string + */ + public function get_id($url) + { + $tb_id = ''; + + if (strpos($url, '?') !== FALSE) + { + $tb_array = explode('/', $url); + $tb_end = $tb_array[count($tb_array)-1]; + + if ( ! is_numeric($tb_end)) + { + $tb_end = $tb_array[count($tb_array)-2]; + } + + $tb_array = explode('=', $tb_end); + $tb_id = $tb_array[count($tb_array)-1]; + } + else + { + $url = rtrim($url, '/'); + + $tb_array = explode('/', $url); + $tb_id = $tb_array[count($tb_array)-1]; + + if ( ! is_numeric($tb_id)) + { + $tb_id = $tb_array[count($tb_array)-2]; + } + } + + return ctype_digit((string) $tb_id) ? $tb_id : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Convert Reserved XML characters to Entities + * + * @param string + * @return string + */ + public function convert_xml($str) + { + $temp = '__TEMP_AMPERSANDS__'; + + $str = preg_replace(array('/&#(\d+);/', '/&(\w+);/'), $temp.'\\1;', $str); + + $str = str_replace(array('&', '<', '>', '"', "'", '-'), + array('&', '<', '>', '"', ''', '-'), + $str); + + return preg_replace(array('/'.$temp.'(\d+);/', '/'.$temp.'(\w+);/'), array('&#\\1;', '&\\1;'), $str); + } + + // -------------------------------------------------------------------- + + /** + * Character limiter + * + * Limits the string based on the character count. Will preserve complete words. + * + * @param string + * @param int + * @param string + * @return string + */ + public function limit_characters($str, $n = 500, $end_char = '…') + { + if (strlen($str) < $n) + { + return $str; + } + + $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); + + if (strlen($str) <= $n) + { + return $str; + } + + $out = ''; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + if (strlen($out) >= $n) + { + return rtrim($out).$end_char; + } + } + } + + // -------------------------------------------------------------------- + + /** + * High ASCII to Entities + * + * Converts Hight ascii text and MS Word special chars + * to character entities + * + * @param string + * @return string + */ + public function convert_ascii($str) + { + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + $out .= $str[$i]; + } + else + { + if (count($temp) === 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) === $count) + { + $number = ($count === 3) + ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) + : (($temp[0] % 32) * 64) + ($temp[1] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @param string + * @return void + */ + public function set_error($msg) + { + log_message('error', $msg); + $this->error_msg[] = $msg; + } + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @param string + * @param string + * @return string + */ + public function display_errors($open = '

    ', $close = '

    ') + { + return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; + } } -// END Trackback Class - -/* End of file Trackback.php */ -/* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php old mode 100755 new mode 100644 index ecfd36a..e67138c --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,409 +1,424 @@ - tags - var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul'; - - // Elements that should not have

    and
    tags within them. - var $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d'; - - // Tags we want the parser to completely ignore when splitting the string. - var $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var'; - - // array of block level elements that require inner content to be within another block level element - var $inner_block_required = array('blockquote'); - - // the last block element parsed - var $last_block_element = ''; - - // whether or not to protect quotes within { curly braces } - var $protect_braced_quotes = FALSE; - - /** - * Auto Typography - * - * This function converts text, making it typographically correct: - * - Converts double spaces into paragraphs. - * - Converts single line breaks into
    tags - * - Converts single and double quotes into correctly facing curly quote entities. - * - Converts three dots into ellipsis. - * - Converts double dashes into em-dashes. - * - Converts two spaces into entities - * - * @access public - * @param string - * @param bool whether to reduce more then two consecutive newlines to two - * @return string - */ - function auto_typography($str, $reduce_linebreaks = FALSE) - { - if ($str == '') - { - return ''; - } - - // Standardize Newlines to make matching easier - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $str); - } - - // Reduce line breaks. If there are more than two consecutive linebreaks - // we'll compress them down to a maximum of two since there's no benefit to more. - if ($reduce_linebreaks === TRUE) - { - $str = preg_replace("/\n\n+/", "\n\n", $str); - } - - // HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed - $html_comments = array(); - if (strpos($str, '\n"; - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Executes the Method - * - * @access protected - * @param object - * @return mixed - */ - function _execute($m) - { - $methName = $m->method_name; - - // Check to see if it is a system call - $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE; - - if ($this->xss_clean == FALSE) - { - $m->xss_clean = FALSE; - } - - //------------------------------------- - // Valid Method - //------------------------------------- - - if ( ! isset($this->methods[$methName]['function'])) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - - //------------------------------------- - // Check for Method (and Object) - //------------------------------------- - - $method_parts = explode(".", $this->methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE; - - if ($system_call === TRUE) - { - if ( ! is_callable(array($this,$method_parts['1']))) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - } - else - { - if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1']))) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - } - - //------------------------------------- - // Checking Methods Signature - //------------------------------------- - - if (isset($this->methods[$methName]['signature'])) - { - $sig = $this->methods[$methName]['signature']; - for ($i=0; $iparams)+1) - { - for ($n=0; $n < count($m->params); $n++) - { - $p = $m->params[$n]; - $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); - - if ($pt != $current_sig[$n+1]) - { - $pno = $n+1; - $wanted = $current_sig[$n+1]; - - return new XML_RPC_Response(0, - $this->xmlrpcerr['incorrect_params'], - $this->xmlrpcstr['incorrect_params'] . - ": Wanted {$wanted}, got {$pt} at param {$pno})"); - } - } - } - } - } - - //------------------------------------- - // Calls the Function - //------------------------------------- - - if ($objectCall === TRUE) - { - if ($method_parts[0] == "this" && $system_call == TRUE) - { - return call_user_func(array($this, $method_parts[1]), $m); - } - else - { - if ($this->object === FALSE) - { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - } - else - { - return $this->object->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); - } - } - } - else - { - return call_user_func($this->methods[$methName]['function'], $m); - } - } - - // -------------------------------------------------------------------- - - /** - * Server Function: List Methods - * - * @access public - * @param mixed - * @return object - */ - function listMethods($m) - { - $v = new XML_RPC_Values(); - $output = array(); - - foreach ($this->methods as $key => $value) - { - $output[] = new XML_RPC_Values($key, 'string'); - } - - foreach ($this->system_methods as $key => $value) - { - $output[]= new XML_RPC_Values($key, 'string'); - } - - $v->addArray($output); - return new XML_RPC_Response($v); - } - - // -------------------------------------------------------------------- - - /** - * Server Function: Return Signature for Method - * - * @access public - * @param mixed - * @return object - */ - function methodSignature($m) - { - $parameters = $m->output_parameters(); - $method_name = $parameters[0]; - - if (isset($this->methods[$method_name])) - { - if ($this->methods[$method_name]['signature']) - { - $sigs = array(); - $signature = $this->methods[$method_name]['signature']; - - for ($i=0; $i < count($signature); $i++) - { - $cursig = array(); - $inSig = $signature[$i]; - for ($j=0; $jxmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Server Function: Doc String for Method - * - * @access public - * @param mixed - * @return object - */ - function methodHelp($m) - { - $parameters = $m->output_parameters(); - $method_name = $parameters[0]; - - if (isset($this->methods[$method_name])) - { - $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; - - return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); - } - else - { - return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - } - - // -------------------------------------------------------------------- - - /** - * Server Function: Multi-call - * - * @access public - * @param mixed - * @return object - */ - function multicall($m) - { - // Disabled - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - - $parameters = $m->output_parameters(); - $calls = $parameters[0]; - - $result = array(); - - foreach ($calls as $value) - { - //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1])); - - $m = new XML_RPC_Message($value[0]); - $plist=''; - - for ($i=0; $i < count($value[1]); $i++) - { - $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); - } - - $attempt = $this->_execute($m); - - if ($attempt->faultCode() != 0) - { - return $attempt; - } - - $result[] = new XML_RPC_Values(array($attempt->value()), 'array'); - } - - return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); - } - - // -------------------------------------------------------------------- - - /** - * Multi-call Function: Error Handling - * - * @access public - * @param mixed - * @return object - */ - function multicall_error($err) - { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); - $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); - - $struct['faultCode'] = new XML_RPC_Values($code, 'int'); - $struct['faultString'] = new XML_RPC_Values($str, 'string'); - - return new XML_RPC_Values($struct, 'struct'); - } - - // -------------------------------------------------------------------- - - /** - * Multi-call Function: Processes method - * - * @access public - * @param mixed - * @return object - */ - function do_multicall($call) - { - if ($call->kindOf() != 'struct') - { - return $this->multicall_error('notstruct'); - } - elseif ( ! $methName = $call->me['struct']['methodName']) - { - return $this->multicall_error('nomethod'); - } - - list($scalar_type,$scalar_value)=each($methName->me); - $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; - - if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') - { - return $this->multicall_error('notstring'); - } - elseif ($scalar_value == 'system.multicall') - { - return $this->multicall_error('recursion'); - } - elseif ( ! $params = $call->me['struct']['params']) - { - return $this->multicall_error('noparams'); - } - elseif ($params->kindOf() != 'array') - { - return $this->multicall_error('notarray'); - } - - list($a,$b)=each($params->me); - $numParams = count($b); - - $msg = new XML_RPC_Message($scalar_value); - for ($i = 0; $i < $numParams; $i++) - { - $msg->params[] = $params->me['array'][$i]; - } - - $result = $this->_execute($msg); - - if ($result->faultCode() != 0) - { - return $this->multicall_error($result); - } - - return new XML_RPC_Values(array($result->value()), 'array'); - } +class CI_Xmlrpcs extends CI_Xmlrpc { + + /** + * Array of methods mapped to function names and signatures + * + * @var array + */ + public $methods = array(); + + /** + * Debug Message + * + * @var string + */ + public $debug_msg = ''; + + /** + * XML RPC Server methods + * + * @var array + */ + public $system_methods = array(); + + /** + * Configuration object + * + * @var object + */ + public $object = FALSE; + + /** + * Initialize XMLRPC class + * + * @param array $config + * @return void + */ + public function __construct($config = array()) + { + parent::__construct(); + $this->set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = array_merge($this->methods, $config['functions']); + } + + log_message('info', 'XML-RPC Server Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Prefs and Serve + * + * @param mixed + * @return void + */ + public function initialize($config = array()) + { + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = array_merge($this->methods, $config['functions']); + } + + if (isset($config['debug'])) + { + $this->debug = $config['debug']; + } + + if (isset($config['object']) && is_object($config['object'])) + { + $this->object = $config['object']; + } + + if (isset($config['xss_clean'])) + { + $this->xss_clean = $config['xss_clean']; + } + } + + // -------------------------------------------------------------------- + + /** + * Setting of System Methods + * + * @return void + */ + public function set_system_methods() + { + $this->methods = array( + 'system.listMethods' => array( + 'function' => 'this.listMethods', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), + 'docstring' => 'Returns an array of available methods on this server'), + 'system.methodHelp' => array( + 'function' => 'this.methodHelp', + 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), + 'docstring' => 'Returns a documentation string for the specified method'), + 'system.methodSignature' => array( + 'function' => 'this.methodSignature', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), + 'docstring' => 'Returns an array describing the return type and required parameters of a method'), + 'system.multicall' => array( + 'function' => 'this.multicall', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), + 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') + ); + } + + // -------------------------------------------------------------------- + + /** + * Main Server Function + * + * @return void + */ + public function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response(); + + header('Content-Type: text/xml'); + header('Content-Length: '.strlen($payload)); + exit($payload); + } + + // -------------------------------------------------------------------- + + /** + * Add Method to Class + * + * @param string method name + * @param string function + * @param string signature + * @param string docstring + * @return void + */ + public function add_to_map($methodname, $function, $sig, $doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + // -------------------------------------------------------------------- + + /** + * Parse Server Request + * + * @param string data + * @return object xmlrpc response + */ + public function parseRequest($data = '') + { + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data === '') + { + $CI =& get_instance(); + if ($CI->input->method() === 'post') + { + $data = $CI->input->raw_input_stream; + } + } + + //------------------------------------- + // Set up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + $parser_object = new XML_RPC_Message('filler'); + $pname = (string) $parser; + + $parser_object->xh[$pname] = array( + 'isf' => 0, + 'isf_reason' => '', + 'params' => array(), + 'stack' => array(), + 'valuestack' => array(), + 'method' => '' + ); + + xml_set_object($parser, $parser_object); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE); + xml_set_element_handler($parser, 'open_tag', 'closing_tag'); + xml_set_character_data_handler($parser, 'character_data'); + //xml_set_default_handler($parser, 'default_handler'); + + //------------------------------------- + // PARSE + PROCESS XML DATA + //------------------------------------- + + if ( ! xml_parse($parser, $data, 1)) + { + // Return XML error as a faultCode + $r = new XML_RPC_Response(0, + $this->xmlrpcerrxml + xml_get_error_code($parser), + sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser))); + xml_parser_free($parser); + } + elseif ($parser_object->xh[$pname]['isf']) + { + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + } + else + { + xml_parser_free($parser); + + $m = new XML_RPC_Message($parser_object->xh[$pname]['method']); + $plist = ''; + + for ($i = 0, $c = count($parser_object->xh[$pname]['params']); $i < $c; $i++) + { + if ($this->debug === TRUE) + { + $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$pname]['params'][$i]), TRUE).";\n"; + } + + $m->addParam($parser_object->xh[$pname]['params'][$i]); + } + + if ($this->debug === TRUE) + { + echo "

    ---PLIST---\n".$plist."\n---PLIST END---\n\n
    "; + } + + $r = $this->_execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Executes the Method + * + * @param object + * @return mixed + */ + protected function _execute($m) + { + $methName = $m->method_name; + + // Check to see if it is a system call + $system_call = (strpos($methName, 'system') === 0); + + if ($this->xss_clean === FALSE) + { + $m->xss_clean = FALSE; + } + + //------------------------------------- + // Valid Method + //------------------------------------- + + if ( ! isset($this->methods[$methName]['function'])) + { + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + } + + //------------------------------------- + // Check for Method (and Object) + //------------------------------------- + + $method_parts = explode('.', $this->methods[$methName]['function']); + $objectCall = ! empty($method_parts[1]); + + if ($system_call === TRUE) + { + if ( ! is_callable(array($this, $method_parts[1]))) + { + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + } + } + elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1]))) + OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) + ) + { + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + } + + //------------------------------------- + // Checking Methods Signature + //------------------------------------- + + if (isset($this->methods[$methName]['signature'])) + { + $sig = $this->methods[$methName]['signature']; + for ($i = 0, $c = count($sig); $i < $c; $i++) + { + $current_sig = $sig[$i]; + + if (count($current_sig) === count($m->params)+1) + { + for ($n = 0, $mc = count($m->params); $n < $mc; $n++) + { + $p = $m->params[$n]; + $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf(); + + if ($pt !== $current_sig[$n+1]) + { + $pno = $n+1; + $wanted = $current_sig[$n+1]; + + return new XML_RPC_Response(0, + $this->xmlrpcerr['incorrect_params'], + $this->xmlrpcstr['incorrect_params'] . + ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')'); + } + } + } + } + } + + //------------------------------------- + // Calls the Function + //------------------------------------- + + if ($objectCall === TRUE) + { + if ($method_parts[0] === 'this' && $system_call === TRUE) + { + return call_user_func(array($this, $method_parts[1]), $m); + } + elseif ($this->object === FALSE) + { + return get_instance()->{$method_parts[1]}($m); + } + + return $this->object->{$method_parts[1]}($m); + } + + return call_user_func($this->methods[$methName]['function'], $m); + } + + // -------------------------------------------------------------------- + + /** + * Server Function: List Methods + * + * @param mixed + * @return object + */ + public function listMethods($m) + { + $v = new XML_RPC_Values(); + $output = array(); + + foreach ($this->methods as $key => $value) + { + $output[] = new XML_RPC_Values($key, 'string'); + } + + foreach ($this->system_methods as $key => $value) + { + $output[] = new XML_RPC_Values($key, 'string'); + } + + $v->addArray($output); + return new XML_RPC_Response($v); + } + + // -------------------------------------------------------------------- + + /** + * Server Function: Return Signature for Method + * + * @param mixed + * @return object + */ + public function methodSignature($m) + { + $parameters = $m->output_parameters(); + $method_name = $parameters[0]; + + if (isset($this->methods[$method_name])) + { + if ($this->methods[$method_name]['signature']) + { + $sigs = array(); + $signature = $this->methods[$method_name]['signature']; + + for ($i = 0, $c = count($signature); $i < $c; $i++) + { + $cursig = array(); + $inSig = $signature[$i]; + for ($j = 0, $jc = count($inSig); $j < $jc; $j++) + { + $cursig[]= new XML_RPC_Values($inSig[$j], 'string'); + } + $sigs[] = new XML_RPC_Values($cursig, 'array'); + } + + return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array')); + } + + return new XML_RPC_Response(new XML_RPC_Values('undef', 'string')); + } + + return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + + // -------------------------------------------------------------------- + + /** + * Server Function: Doc String for Method + * + * @param mixed + * @return object + */ + public function methodHelp($m) + { + $parameters = $m->output_parameters(); + $method_name = $parameters[0]; + + if (isset($this->methods[$method_name])) + { + $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; + + return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + } + + return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + + // -------------------------------------------------------------------- + + /** + * Server Function: Multi-call + * + * @param mixed + * @return object + */ + public function multicall($m) + { + // Disabled + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + + $parameters = $m->output_parameters(); + $calls = $parameters[0]; + + $result = array(); + + foreach ($calls as $value) + { + $m = new XML_RPC_Message($value[0]); + $plist = ''; + + for ($i = 0, $c = count($value[1]); $i < $c; $i++) + { + $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); + } + + $attempt = $this->_execute($m); + + if ($attempt->faultCode() !== 0) + { + return $attempt; + } + + $result[] = new XML_RPC_Values(array($attempt->value()), 'array'); + } + + return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); + } + + // -------------------------------------------------------------------- + + /** + * Multi-call Function: Error Handling + * + * @param mixed + * @return object + */ + public function multicall_error($err) + { + $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); + $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); + + $struct['faultCode'] = new XML_RPC_Values($code, 'int'); + $struct['faultString'] = new XML_RPC_Values($str, 'string'); + + return new XML_RPC_Values($struct, 'struct'); + } + + // -------------------------------------------------------------------- + + /** + * Multi-call Function: Processes method + * + * @param mixed + * @return object + */ + public function do_multicall($call) + { + if ($call->kindOf() !== 'struct') + { + return $this->multicall_error('notstruct'); + } + elseif ( ! $methName = $call->me['struct']['methodName']) + { + return $this->multicall_error('nomethod'); + } + + list($scalar_value, $scalar_type) = array(reset($methName->me), key($methName->me)); + $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; + + if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string') + { + return $this->multicall_error('notstring'); + } + elseif ($scalar_value === 'system.multicall') + { + return $this->multicall_error('recursion'); + } + elseif ( ! $params = $call->me['struct']['params']) + { + return $this->multicall_error('noparams'); + } + elseif ($params->kindOf() !== 'array') + { + return $this->multicall_error('notarray'); + } + + list($b, $a) = array(reset($params->me), key($params->me)); + + $msg = new XML_RPC_Message($scalar_value); + for ($i = 0, $numParams = count($b); $i < $numParams; $i++) + { + $msg->params[] = $params->me['array'][$i]; + } + + $result = $this->_execute($msg); + + if ($result->faultCode() !== 0) + { + return $this->multicall_error($result); + } + + return new XML_RPC_Values(array($result->value()), 'array'); + } } -// END XML_RPC_Server class - - -/* End of file Xmlrpcs.php */ -/* Location: ./system/libraries/Xmlrpcs.php */ \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php old mode 100755 new mode 100644 index ae9f52b..c0a1402 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,20 +1,41 @@ -now = time(); - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * Lets you add a virtual directory into which you can place files. - * - * @access public - * @param mixed the directory name. Can be string or array - * @return void - */ - function add_dir($directory) - { - foreach ((array)$directory as $dir) - { - if ( ! preg_match("|.+/$|", $dir)) - { - $dir .= '/'; - } - - $dir_time = $this->_get_mod_time($dir); - - $this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']); - } - } - - // -------------------------------------------------------------------- - - /** - * Get file/directory modification time - * - * If this is a newly created file/dir, we will set the time to 'now' - * - * @param string path to file - * @return array filemtime/filemdate - */ - function _get_mod_time($dir) - { - // filemtime() will return false, but it does raise an error. - $date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now); - - $time['file_mtime'] = ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2; - $time['file_mdate'] = (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']; - - return $time; - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * @access private - * @param string the directory name - * @return void - */ - function _add_dir($dir, $file_mtime, $file_mdate) - { - $dir = str_replace("\\", "/", $dir); - - $this->zipdata .= - "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00" - .pack('v', $file_mtime) - .pack('v', $file_mdate) - .pack('V', 0) // crc32 - .pack('V', 0) // compressed filesize - .pack('V', 0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname - .pack('v', 0) // extra field length - .$dir - // below is "data descriptor" segment - .pack('V', 0) // crc32 - .pack('V', 0) // compressed filesize - .pack('V', 0); // uncompressed filesize - - $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00" - .pack('v', $file_mtime) - .pack('v', $file_mdate) - .pack('V',0) // crc32 - .pack('V',0) // compressed filesize - .pack('V',0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname - .pack('v', 0) // extra field length - .pack('v', 0) // file comment length - .pack('v', 0) // disk number start - .pack('v', 0) // internal file attributes - .pack('V', 16) // external file attributes - 'directory' bit set - .pack('V', $this->offset) // relative offset of local header - .$dir; - - $this->offset = strlen($this->zipdata); - $this->entries++; - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * Lets you add files to the archive. If the path is included - * in the filename it will be placed within a directory. Make - * sure you use add_dir() first to create the folder. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function add_data($filepath, $data = NULL) - { - if (is_array($filepath)) - { - foreach ($filepath as $path => $data) - { - $file_data = $this->_get_mod_time($path); - - $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); - } - } - else - { - $file_data = $this->_get_mod_time($filepath); - - $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * @access private - * @param string the file name/path - * @param string the data to be encoded - * @return void - */ - function _add_data($filepath, $data, $file_mtime, $file_mdate) - { - $filepath = str_replace("\\", "/", $filepath); - - $uncompressed_size = strlen($data); - $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr($gzdata, 2, -4); - $compressed_size = strlen($gzdata); - - $this->zipdata .= - "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00" - .pack('v', $file_mtime) - .pack('v', $file_mdate) - .pack('V', $crc32) - .pack('V', $compressed_size) - .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename - .pack('v', 0) // extra field length - .$filepath - .$gzdata; // "file data" segment - - $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00" - .pack('v', $file_mtime) - .pack('v', $file_mdate) - .pack('V', $crc32) - .pack('V', $compressed_size) - .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename - .pack('v', 0) // extra field length - .pack('v', 0) // file comment length - .pack('v', 0) // disk number start - .pack('v', 0) // internal file attributes - .pack('V', 32) // external file attributes - 'archive' bit set - .pack('V', $this->offset) // relative offset of local header - .$filepath; - - $this->offset = strlen($this->zipdata); - $this->entries++; - $this->file_num++; - } - - // -------------------------------------------------------------------- - - /** - * Read the contents of a file and add it to the zip - * - * @access public - * @return bool - */ - function read_file($path, $preserve_filepath = FALSE) - { - if ( ! file_exists($path)) - { - return FALSE; - } - - if (FALSE !== ($data = file_get_contents($path))) - { - $name = str_replace("\\", "/", $path); - - if ($preserve_filepath === FALSE) - { - $name = preg_replace("|.*/(.+)|", "\\1", $name); - } - - $this->add_data($name, $data); - return TRUE; - } - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Read a directory and add it to the zip. - * - * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a zip based on it. Whatever directory structure - * is in the original file path will be recreated in the zip file. - * - * @access public - * @param string path to source - * @return bool - */ - function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) - { - if ( ! $fp = @opendir($path)) - { - return FALSE; - } - - // Set the original directory root for child dir's to use as relative - if ($root_path === NULL) - { - $root_path = dirname($path).'/'; - } - - while (FALSE !== ($file = readdir($fp))) - { - if (substr($file, 0, 1) == '.') - { - continue; - } - - if (@is_dir($path.$file)) - { - $this->read_dir($path.$file."/", $preserve_filepath, $root_path); - } - else - { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $name = str_replace("\\", "/", $path); - - if ($preserve_filepath === FALSE) - { - $name = str_replace($root_path, '', $name); - } - - $this->add_data($name.$file, $data); - } - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Get the Zip file - * - * @access public - * @return binary string - */ - function get_zip() - { - // Is there any data to return? - if ($this->entries == 0) - { - return FALSE; - } - - $zip_data = $this->zipdata; - $zip_data .= $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"; - $zip_data .= pack('v', $this->entries); // total # of entries "on this disk" - $zip_data .= pack('v', $this->entries); // total # of entries overall - $zip_data .= pack('V', strlen($this->directory)); // size of central dir - $zip_data .= pack('V', strlen($this->zipdata)); // offset to start of central dir - $zip_data .= "\x00\x00"; // .zip file comment length - - return $zip_data; - } - - // -------------------------------------------------------------------- - - /** - * Write File to the specified directory - * - * Lets you write a file - * - * @access public - * @param string the file name - * @return bool - */ - function archive($filepath) - { - if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $this->get_zip()); - flock($fp, LOCK_UN); - fclose($fp); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Download - * - * @access public - * @param string the file name - * @param string the data to be encoded - * @return bool - */ - function download($filename = 'backup.zip') - { - if ( ! preg_match("|.+?\.zip$|", $filename)) - { - $filename .= '.zip'; - } - - $CI =& get_instance(); - $CI->load->helper('download'); - - $get_zip = $this->get_zip(); - - $zip_content =& $get_zip; - - force_download($filename, $zip_content); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Data - * - * Lets you clear current zip data. Useful if you need to create - * multiple zips with different data. - * - * @access public - * @return void - */ - function clear_data() - { - $this->zipdata = ''; - $this->directory = ''; - $this->entries = 0; - $this->file_num = 0; - $this->offset = 0; - } - +class CI_Zip { + + /** + * Zip data in string form + * + * @var string + */ + public $zipdata = ''; + + /** + * Zip data for a directory in string form + * + * @var string + */ + public $directory = ''; + + /** + * Number of files/folder in zip file + * + * @var int + */ + public $entries = 0; + + /** + * Number of files in zip + * + * @var int + */ + public $file_num = 0; + + /** + * relative offset of local header + * + * @var int + */ + public $offset = 0; + + /** + * Reference to time at init + * + * @var int + */ + public $now; + + /** + * The level of compression + * + * Ranges from 0 to 9, with 9 being the highest level. + * + * @var int + */ + public $compression_level = 2; + + /** + * mbstring.func_overload flag + * + * @var bool + */ + protected static $func_overload; + + /** + * Initialize zip compression class + * + * @return void + */ + public function __construct() + { + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + $this->now = time(); + log_message('info', 'Zip Compression Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * Lets you add a virtual directory into which you can place files. + * + * @param mixed $directory the directory name. Can be string or array + * @return void + */ + public function add_dir($directory) + { + foreach ((array) $directory as $dir) + { + if ( ! preg_match('|.+/$|', $dir)) + { + $dir .= '/'; + } + + $dir_time = $this->_get_mod_time($dir); + $this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']); + } + } + + // -------------------------------------------------------------------- + + /** + * Get file/directory modification time + * + * If this is a newly created file/dir, we will set the time to 'now' + * + * @param string $dir path to file + * @return array filemtime/filemdate + */ + protected function _get_mod_time($dir) + { + // filemtime() may return false, but raises an error for non-existing files + $date = file_exists($dir) ? getdate(filemtime($dir)) : getdate($this->now); + + return array( + 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, + 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'] + ); + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @param string $dir the directory name + * @param int $file_mtime + * @param int $file_mdate + * @return void + */ + protected function _add_dir($dir, $file_mtime, $file_mdate) + { + $dir = str_replace('\\', '/', $dir); + + $this->zipdata .= + "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00" + .pack('v', $file_mtime) + .pack('v', $file_mdate) + .pack('V', 0) // crc32 + .pack('V', 0) // compressed filesize + .pack('V', 0) // uncompressed filesize + .pack('v', self::strlen($dir)) // length of pathname + .pack('v', 0) // extra field length + .$dir + // below is "data descriptor" segment + .pack('V', 0) // crc32 + .pack('V', 0) // compressed filesize + .pack('V', 0); // uncompressed filesize + + $this->directory .= + "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00" + .pack('v', $file_mtime) + .pack('v', $file_mdate) + .pack('V',0) // crc32 + .pack('V',0) // compressed filesize + .pack('V',0) // uncompressed filesize + .pack('v', self::strlen($dir)) // length of pathname + .pack('v', 0) // extra field length + .pack('v', 0) // file comment length + .pack('v', 0) // disk number start + .pack('v', 0) // internal file attributes + .pack('V', 16) // external file attributes - 'directory' bit set + .pack('V', $this->offset) // relative offset of local header + .$dir; + + $this->offset = self::strlen($this->zipdata); + $this->entries++; + } + + // -------------------------------------------------------------------- + + /** + * Add Data to Zip + * + * Lets you add files to the archive. If the path is included + * in the filename it will be placed within a directory. Make + * sure you use add_dir() first to create the folder. + * + * @param mixed $filepath A single filepath or an array of file => data pairs + * @param string $data Single file contents + * @return void + */ + public function add_data($filepath, $data = NULL) + { + if (is_array($filepath)) + { + foreach ($filepath as $path => $data) + { + $file_data = $this->_get_mod_time($path); + $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); + } + } + else + { + $file_data = $this->_get_mod_time($filepath); + $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Data to Zip + * + * @param string $filepath the file name/path + * @param string $data the data to be encoded + * @param int $file_mtime + * @param int $file_mdate + * @return void + */ + protected function _add_data($filepath, $data, $file_mtime, $file_mdate) + { + $filepath = str_replace('\\', '/', $filepath); + + $uncompressed_size = self::strlen($data); + $crc32 = crc32($data); + $gzdata = self::substr(gzcompress($data, $this->compression_level), 2, -4); + $compressed_size = self::strlen($gzdata); + + $this->zipdata .= + "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00" + .pack('v', $file_mtime) + .pack('v', $file_mdate) + .pack('V', $crc32) + .pack('V', $compressed_size) + .pack('V', $uncompressed_size) + .pack('v', self::strlen($filepath)) // length of filename + .pack('v', 0) // extra field length + .$filepath + .$gzdata; // "file data" segment + + $this->directory .= + "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00" + .pack('v', $file_mtime) + .pack('v', $file_mdate) + .pack('V', $crc32) + .pack('V', $compressed_size) + .pack('V', $uncompressed_size) + .pack('v', self::strlen($filepath)) // length of filename + .pack('v', 0) // extra field length + .pack('v', 0) // file comment length + .pack('v', 0) // disk number start + .pack('v', 0) // internal file attributes + .pack('V', 32) // external file attributes - 'archive' bit set + .pack('V', $this->offset) // relative offset of local header + .$filepath; + + $this->offset = self::strlen($this->zipdata); + $this->entries++; + $this->file_num++; + } + + // -------------------------------------------------------------------- + + /** + * Read the contents of a file and add it to the zip + * + * @param string $path + * @param bool $archive_filepath + * @return bool + */ + public function read_file($path, $archive_filepath = FALSE) + { + if (file_exists($path) && FALSE !== ($data = file_get_contents($path))) + { + if (is_string($archive_filepath)) + { + $name = str_replace('\\', '/', $archive_filepath); + } + else + { + $name = str_replace('\\', '/', $path); + + if ($archive_filepath === FALSE) + { + $name = preg_replace('|.*/(.+)|', '\\1', $name); + } + } + + $this->add_data($name, $data); + return TRUE; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Read a directory and add it to the zip. + * + * This function recursively reads a folder and everything it contains (including + * sub-folders) and creates a zip based on it. Whatever directory structure + * is in the original file path will be recreated in the zip file. + * + * @param string $path path to source directory + * @param bool $preserve_filepath + * @param string $root_path + * @return bool + */ + public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) + { + $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; + if ( ! $fp = @opendir($path)) + { + return FALSE; + } + + // Set the original directory root for child dir's to use as relative + if ($root_path === NULL) + { + $root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR; + } + + while (FALSE !== ($file = readdir($fp))) + { + if ($file[0] === '.') + { + continue; + } + + if (is_dir($path.$file)) + { + $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); + } + elseif (FALSE !== ($data = file_get_contents($path.$file))) + { + $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path); + if ($preserve_filepath === FALSE) + { + $name = str_replace($root_path, '', $name); + } + + $this->add_data($name.$file, $data); + } + } + + closedir($fp); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Get the Zip file + * + * @return string (binary encoded) + */ + public function get_zip() + { + // Is there any data to return? + if ($this->entries === 0) + { + return FALSE; + } + + return $this->zipdata + .$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', $this->entries) // total # of entries "on this disk" + .pack('v', $this->entries) // total # of entries overall + .pack('V', self::strlen($this->directory)) // size of central dir + .pack('V', self::strlen($this->zipdata)) // offset to start of central dir + ."\x00\x00"; // .zip file comment length + } + + // -------------------------------------------------------------------- + + /** + * Write File to the specified directory + * + * Lets you write a file + * + * @param string $filepath the file name + * @return bool + */ + public function archive($filepath) + { + if ( ! ($fp = @fopen($filepath, 'w+b'))) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + for ($result = $written = 0, $data = $this->get_zip(), $length = self::strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, self::substr($data, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + return is_int($result); + } + + // -------------------------------------------------------------------- + + /** + * Download + * + * @param string $filename the file name + * @return void + */ + public function download($filename = 'backup.zip') + { + if ( ! preg_match('|.+?\.zip$|', $filename)) + { + $filename .= '.zip'; + } + + get_instance()->load->helper('download'); + $get_zip = $this->get_zip(); + $zip_content =& $get_zip; + + force_download($filename, $zip_content); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Data + * + * Lets you clear current zip data. Useful if you need to create + * multiple zips with different data. + * + * @return CI_Zip + */ + public function clear_data() + { + $this->zipdata = ''; + $this->directory = ''; + $this->entries = 0; + $this->file_num = 0; + $this->offset = 0; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + 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'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } } - -/* End of file Zip.php */ -/* Location: ./system/libraries/Zip.php */ \ No newline at end of file diff --git a/system/libraries/index.html b/system/libraries/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/libraries/index.html +++ b/system/libraries/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php old mode 100755 new mode 100644 index 411f3b7..485d1dc --- a/system/libraries/javascript/Jquery.php +++ b/system/libraries/javascript/Jquery.php @@ -1,1072 +1,1076 @@ -CI =& get_instance(); - extract($params); - - if ($autoload === TRUE) - { - $this->script(); - } - - log_message('debug', "Jquery Class Initialized"); - } - - // -------------------------------------------------------------------- - // Event Code - // -------------------------------------------------------------------- - - /** - * Blur - * - * Outputs a jQuery blur event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _blur($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'blur'); - } - - // -------------------------------------------------------------------- - - /** - * Change - * - * Outputs a jQuery change event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _change($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'change'); - } - - // -------------------------------------------------------------------- - - /** - * Click - * - * Outputs a jQuery click event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @param boolean whether or not to return false - * @return string - */ - function _click($element = 'this', $js = '', $ret_false = TRUE) - { - if ( ! is_array($js)) - { - $js = array($js); - } - - if ($ret_false) - { - $js[] = "return false;"; - } - - return $this->_add_event($element, $js, 'click'); - } - - // -------------------------------------------------------------------- - - /** - * Double Click - * - * Outputs a jQuery dblclick event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _dblclick($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'dblclick'); - } - - // -------------------------------------------------------------------- - - /** - * Error - * - * Outputs a jQuery error event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _error($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'error'); - } - - // -------------------------------------------------------------------- - - /** - * Focus - * - * Outputs a jQuery focus event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _focus($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'focus'); - } - - // -------------------------------------------------------------------- - - /** - * Hover - * - * Outputs a jQuery hover event - * - * @access private - * @param string - element - * @param string - Javascript code for mouse over - * @param string - Javascript code for mouse out - * @return string - */ - 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 - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _keydown($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'keydown'); - } - - // -------------------------------------------------------------------- - - /** - * Keyup - * - * Outputs a jQuery keydown event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _keyup($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'keyup'); - } - - // -------------------------------------------------------------------- - - /** - * Load - * - * Outputs a jQuery load event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _load($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'load'); - } - - // -------------------------------------------------------------------- - - /** - * Mousedown - * - * Outputs a jQuery mousedown event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _mousedown($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mousedown'); - } - - // -------------------------------------------------------------------- - - /** - * Mouse Out - * - * Outputs a jQuery mouseout event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _mouseout($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseout'); - } - - // -------------------------------------------------------------------- - - /** - * Mouse Over - * - * Outputs a jQuery mouseover event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _mouseover($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseover'); - } - - // -------------------------------------------------------------------- - - /** - * Mouseup - * - * Outputs a jQuery mouseup event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _mouseup($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseup'); - } - - // -------------------------------------------------------------------- - - /** - * Output - * - * Outputs script directly - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _output($array_js = '') - { - 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 - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _resize($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'resize'); - } - - // -------------------------------------------------------------------- - - /** - * Scroll - * - * Outputs a jQuery scroll event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _scroll($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'scroll'); - } - - // -------------------------------------------------------------------- - - /** - * Unload - * - * Outputs a jQuery unload event - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - function _unload($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'unload'); - } - - // -------------------------------------------------------------------- - // Effects - // -------------------------------------------------------------------- - - /** - * Add Class - * - * Outputs a jQuery addClass event - * - * @access private - * @param string - element - * @return string - */ - function _addClass($element = 'this', $class='') - { - $element = $this->_prep_element($element); - $str = "$({$element}).addClass(\"$class\");"; - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Animate - * - * Outputs a jQuery animate event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - 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; - } - - $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Fade In - * - * Outputs a jQuery hide event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _fadeIn($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).fadeIn({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Fade Out - * - * Outputs a jQuery hide event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _fadeOut($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).fadeOut({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Hide - * - * Outputs a jQuery hide action - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _hide($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).hide({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Remove Class - * - * Outputs a jQuery remove class event - * - * @access private - * @param string - element - * @return string - */ - function _removeClass($element = 'this', $class='') - { - $element = $this->_prep_element($element); - $str = "$({$element}).removeClass(\"$class\");"; - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Slide Up - * - * Outputs a jQuery slideUp event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _slideUp($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).slideUp({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Slide Down - * - * Outputs a jQuery slideDown event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _slideDown($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).slideDown({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Slide Toggle - * - * Outputs a jQuery slideToggle event - * - * @access public - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _slideToggle($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).slideToggle({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Toggle - * - * Outputs a jQuery toggle event - * - * @access private - * @param string - element - * @return string - */ - function _toggle($element = 'this') - { - $element = $this->_prep_element($element); - $str = "$({$element}).toggle();"; - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Toggle Class - * - * Outputs a jQuery toggle class event - * - * @access private - * @param string - element - * @return string - */ - function _toggleClass($element = 'this', $class='') - { - $element = $this->_prep_element($element); - $str = "$({$element}).toggleClass(\"$class\");"; - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Show - * - * Outputs a jQuery show event - * - * @access private - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - function _show($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback != '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - $str = "$({$element}).show({$speed}{$callback});"; - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Updater - * - * An Ajax call that populates the designated DOM node with - * returned content - * - * @access private - * @param string The element to attach the event to - * @param string the controller to run the call against - * @param string optional parameters - * @return string - */ - - 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 = 'CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />'; - } - - $updater = "$($container).empty();\n"; // anything that was in... get it out - $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image - - $request_options = ''; - if ($options != '') - { - $request_options .= ", {"; - $request_options .= (is_array($options)) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'"; - $request_options .= "}"; - } - - $updater .= "\t\t$($container).load('$controller'$request_options);"; - return $updater; - } - - - // -------------------------------------------------------------------- - // Pre-written handy stuff - // -------------------------------------------------------------------- - - /** - * Zebra tables - * - * @access private - * @param string table name - * @param string plugin location - * @return string - */ - 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 - * - * http://www.malsup.com/jquery/corner/ - * - * @access public - * @param string target - * @return string - */ - 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 - * - * @access public - * @return void - */ - function modal($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * Effect - * - * Load an Effect library - * - * @access public - * @return void - */ - function effect($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * Plugin - * - * Load a plugin library - * - * @access public - * @return void - */ - function plugin($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * UI - * - * Load a user interface library - * - * @access public - * @return void - */ - function ui($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - // -------------------------------------------------------------------- - - /** - * Sortable - * - * Creates a jQuery sortable - * - * @access public - * @return void - */ - 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 - * - * @access public - * @param string table name - * @param string plugin location - * @return string - */ - 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 - * - * @access private - * @param string The element to attach the event to - * @param string The code to execute - * @param string The event to pass - * @return string - */ - 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 funciton compiles them all for output on a page - * - * @access private - * @return string - */ - 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"; - $script .= implode('', $this->jquery_code_for_compile); - $script .= '});'; - - $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 - * - * @access public - * @return void - */ - function _clear_compile() - { - $this->jquery_code_for_compile = array(); - } - - // -------------------------------------------------------------------- - - /** - * Document Ready - * - * A wrapper for writing document.ready() - * - * @access private - * @return string - */ - function _document_ready($js) - { - if ( ! is_array($js)) - { - $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 - * - * @access public - * @param string - * @return string - */ - 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 - * - * @access public - * @param string - * @return string - */ - function _prep_element($element) - { - if ($element != 'this') - { - $element = '"'.$element.'"'; - } - - return $element; - } - - // -------------------------------------------------------------------- - - /** - * Validate Speed - * - * Ensures the speed parameter is valid for jQuery - * - * @access private - * @param string - * @return string - */ - function _validate_speed($speed) - { - if (in_array($speed, array('slow', 'normal', 'fast'))) - { - $speed = '"'.$speed.'"'; - } - elseif (preg_match("/[^0-9]/", $speed)) - { - $speed = ''; - } - - return $speed; - } + /** + * JavaScript directory location + * + * @var string + */ + protected $_javascript_folder = 'js'; + + /** + * JQuery code for load + * + * @var array + */ + public $jquery_code_for_load = array(); + + /** + * JQuery code for compile + * + * @var array + */ + public $jquery_code_for_compile = array(); + + /** + * JQuery corner active flag + * + * @var bool + */ + public $jquery_corner_active = FALSE; + + /** + * JQuery table sorter active flag + * + * @var bool + */ + public $jquery_table_sorter_active = FALSE; + + /** + * JQuery table sorter pager active + * + * @var bool + */ + public $jquery_table_sorter_pager_active = FALSE; + + /** + * JQuery AJAX image + * + * @var string + */ + public $jquery_ajax_img = ''; + + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param array $params + * @return void + */ + public function __construct($params) + { + $this->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; + } } - -/* End of file Jquery.php */ -/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file diff --git a/system/libraries/javascript/index.html b/system/libraries/javascript/index.html old mode 100755 new mode 100644 index 04e928c..b702fbc --- a/system/libraries/javascript/index.html +++ b/system/libraries/javascript/index.html @@ -1,10 +1,11 @@ + - 403 Forbidden + 403 Forbidden

    Directory access is forbidden.

    - \ No newline at end of file + From f10d2fb50a45589c63895d229fcbbfeef08b8569 Mon Sep 17 00:00:00 2001 From: Pierre-Henry Soria Date: Wed, 1 Apr 2020 13:34:44 +1000 Subject: [PATCH 2/5] Update libraries and other files + Requirements for Codeigniter 3+ :fire: --- INSTALLATION - INSTRUCTION.txt | 6 +- README.md | 4 +- application/config/config.php | 19 +- application/config/database.php | 6 +- application/config/grocery_crud.php | 54 +- application/controllers/user.php | 1 - application/core/MY_Loader.php | 24 +- application/libraries/Grocery_CRUD.php | 10015 +++---- application/libraries/image_moo.php | 2089 +- application/models/grocery_crud_model.php | 747 +- application/models/ion_auth_model.php | 0 application/views/example.php | 42 - assets/grocery_crud/config/index.html | 2 +- assets/grocery_crud/config/language_alias.php | 58 +- assets/grocery_crud/config/translit_chars.php | 230 +- assets/grocery_crud/css/index.html | 2 +- .../jquery_plugins/chosen/chosen-sprite.png | Bin 559 -> 538 bytes .../chosen/chosen-sprite@2x.png | Bin 0 -> 738 bytes .../css/jquery_plugins/chosen/chosen.css | 847 +- .../css/jquery_plugins/chosen/chosen.min.css | 3 + .../css/jquery_plugins/chosen/index.html | 2 +- .../css/jquery_plugins/fancybox/blank.gif | Bin .../jquery_plugins/fancybox/fancy_close.png | Bin .../jquery_plugins/fancybox/fancy_loading.png | Bin .../fancybox/fancy_nav_left.png | Bin .../fancybox/fancy_nav_right.png | Bin .../fancybox/fancy_shadow_e.png | Bin .../fancybox/fancy_shadow_n.png | Bin .../fancybox/fancy_shadow_ne.png | Bin .../fancybox/fancy_shadow_nw.png | Bin .../fancybox/fancy_shadow_s.png | Bin .../fancybox/fancy_shadow_se.png | Bin .../fancybox/fancy_shadow_sw.png | Bin .../fancybox/fancy_shadow_w.png | Bin .../fancybox/fancy_title_left.png | Bin .../fancybox/fancy_title_main.png | Bin .../fancybox/fancy_title_over.png | Bin .../fancybox/fancy_title_right.png | Bin .../jquery_plugins/fancybox/fancybox-x.png | Bin .../jquery_plugins/fancybox/fancybox-y.png | Bin .../css/jquery_plugins/fancybox/fancybox.png | Bin .../fancybox/jquery.fancybox.css | 467 +- .../file_upload/bootstrap.min.css | 0 .../file_upload/file-uploader.css | 54 +- .../file_upload/fileuploader.css | 153 +- .../file_upload/jquery.fileupload-ui.css | 58 +- .../jquery_plugins/file_upload/loading.gif | Bin .../file_upload/progressbar.gif | Bin .../css/jquery_plugins/index.html | 2 +- .../jquery-ui-timepicker-addon.css | 49 +- .../css/jquery_plugins/jquery.ui.datetime.css | 238 +- .../css/jquery_plugins/ui.multiselect.css | 171 +- .../uniform/images/bg-input-focus.png | Bin 143 -> 0 bytes .../uniform/images/bg-input.png | Bin 143 -> 0 bytes .../jquery_plugins/uniform/images/sprite.png | Bin 34229 -> 0 bytes .../uniform/uniform.default.css | 645 - assets/grocery_crud/css/ui/index.html | 2 +- .../css/ui/simple/images/animated-overlay.gif | Bin .../images/ui-bg_flat_0_aaaaaa_40x100.png | Bin .../images/ui-bg_flat_75_ffffff_40x100.png | Bin .../images/ui-bg_glass_55_fbf9ee_1x400.png | Bin .../images/ui-bg_glass_65_ffffff_1x400.png | Bin .../images/ui-bg_glass_75_dadada_1x400.png | Bin .../images/ui-bg_glass_75_e6e6e6_1x400.png | Bin .../images/ui-bg_glass_95_fef1ec_1x400.png | Bin .../ui-bg_highlight-soft_75_cccccc_1x100.png | Bin .../simple/images/ui-icons_222222_256x240.png | Bin .../simple/images/ui-icons_2e83ff_256x240.png | Bin .../simple/images/ui-icons_333333_256x240.png | Bin .../simple/images/ui-icons_454545_256x240.png | Bin .../simple/images/ui-icons_cd0a0a_256x240.png | Bin assets/grocery_crud/css/ui/simple/index.html | 2 +- .../ui/simple/jquery-ui-1.10.1.custom.min.css | 5 +- assets/grocery_crud/index.html | 2 +- assets/grocery_crud/js/common/lazyload-min.js | 0 assets/grocery_crud/js/common/list.js | 136 +- assets/grocery_crud/js/index.html | 2 +- assets/grocery_crud/js/jquery-1.10.2.min.js | 9 - assets/grocery_crud/js/jquery-1.11.1.js | 10308 +++++++ assets/grocery_crud/js/jquery-1.11.1.min.js | 4 + assets/grocery_crud/js/jquery-1.11.1.min.map | 1 + .../js/jquery_plugins/ajax-chosen.js | 162 +- .../js/jquery_plugins/config/index.html | 2 +- .../jquery-ui-timepicker-addon.config.js | 28 +- .../config/jquery.chosen.config.js | 6 +- .../config/jquery.ckeditor.config.js | 8 +- .../config/jquery.datepicker.config.js | 32 +- .../config/jquery.datetime.config.js | 24 +- .../config/jquery.fancybox.config.js | 20 +- .../config/jquery.fileupload.config.js | 296 +- .../config/jquery.markitup.config.js | 66 +- .../config/jquery.multiselect.js | 6 +- .../config/jquery.noty.config.js | 82 +- .../config/jquery.numeric.config.js | 62 +- .../config/jquery.tine_mce.config.js | 94 +- .../config/jquery.uniform.config.js | 6 +- .../grocery_crud/js/jquery_plugins/index.html | 2 +- .../jquery-migrate-1.1.0.min.js | 3 - .../jquery-ui-timepicker-addon.js | 4246 ++- .../jquery-ui-timepicker-addon.min.js | 0 .../js/jquery_plugins/jquery.chosen.js | 1257 + .../js/jquery_plugins/jquery.chosen.min.js | 12 +- .../jquery_plugins/jquery.easing-1.3.pack.js | 64 +- .../jquery_plugins/jquery.fancybox-1.3.4.js | 1934 +- .../js/jquery_plugins/jquery.fancybox.js | 1934 +- .../js/jquery_plugins/jquery.fancybox.pack.js | 4 +- .../js/jquery_plugins/jquery.fileupload.js | 0 .../js/jquery_plugins/jquery.form.js | 1278 + .../js/jquery_plugins/jquery.form.min.js | 7 + .../jquery_plugins/jquery.iframe-transport.js | 0 .../js/jquery_plugins/jquery.noty.js | 1150 +- .../js/jquery_plugins/jquery.numeric.min.js | 0 .../js/jquery_plugins/jquery.ui.datetime.js | 604 +- .../js/jquery_plugins/jquery.uniform.js | 967 - .../js/jquery_plugins/jquery.uniform.min.js | 1 - .../js/jquery_plugins/load-image.min.js | 0 .../js/jquery_plugins/tmpl.min.js | 0 .../js/jquery_plugins/ui.multiselect.min.js | 0 .../ui/i18n/datepicker/index.html | 2 +- .../datepicker/jquery.ui.datepicker-af.js | 38 +- .../datepicker/jquery.ui.datepicker-ar.js | 36 +- .../datepicker/jquery.ui.datepicker-bg.js | 40 +- .../datepicker/jquery.ui.datepicker-bn.js | 34 +- .../datepicker/jquery.ui.datepicker-cs.js | 38 +- .../datepicker/jquery.ui.datepicker-da.js | 38 +- .../datepicker/jquery.ui.datepicker-de.js | 38 +- .../datepicker/jquery.ui.datepicker-el.js | 38 +- .../datepicker/jquery.ui.datepicker-es.js | 38 +- .../datepicker/jquery.ui.datepicker-fa.js | 108 +- .../datepicker/jquery.ui.datepicker-fr.js | 42 +- .../datepicker/jquery.ui.datepicker-hu.js | 38 +- .../datepicker/jquery.ui.datepicker-id.js | 38 +- .../datepicker/jquery.ui.datepicker-it.js | 38 +- .../datepicker/jquery.ui.datepicker-ja.js | 38 +- .../datepicker/jquery.ui.datepicker-ko.js | 38 +- .../datepicker/jquery.ui.datepicker-nl.js | 38 +- .../datepicker/jquery.ui.datepicker-no.js | 0 .../datepicker/jquery.ui.datepicker-pl.js | 38 +- .../datepicker/jquery.ui.datepicker-pt-br.js | 38 +- .../datepicker/jquery.ui.datepicker-pt.js | 38 +- .../datepicker/jquery.ui.datepicker-ro.js | 38 +- .../datepicker/jquery.ui.datepicker-ru.js | 38 +- .../datepicker/jquery.ui.datepicker-sk.js | 38 +- .../datepicker/jquery.ui.datepicker-th.js | 38 +- .../datepicker/jquery.ui.datepicker-tr.js | 38 +- .../datepicker/jquery.ui.datepicker-uk.js | 38 +- .../datepicker/jquery.ui.datepicker-vi.js | 38 +- .../datepicker/jquery.ui.datepicker-zh-cn.js | 38 +- .../js/jquery_plugins/ui/i18n/index.html | 2 +- .../ui/i18n/multiselect/index.html | 2 +- .../ui/i18n/multiselect/ui-multiselect-ar.js | 4 +- .../ui/i18n/multiselect/ui-multiselect-de.js | 6 +- .../ui/i18n/multiselect/ui-multiselect-el.js | 20 +- .../ui/i18n/multiselect/ui-multiselect-en.js | 6 +- .../ui/i18n/multiselect/ui-multiselect-es.js | 6 +- .../ui/i18n/multiselect/ui-multiselect-fr.js | 6 +- .../ui/i18n/multiselect/ui-multiselect-it.js | 10 +- .../ui/i18n/multiselect/ui-multiselect-ja.js | 6 +- .../i18n/multiselect/ui-multiselect-pt-br.js | 0 .../ui/i18n/multiselect/ui-multiselect-ru.js | 6 +- .../ui/i18n/multiselect/ui-multiselect-uk.js | 6 +- .../ui/i18n/timepicker/index.html | 2 +- .../timepicker/jquery-ui-timepicker-af.js | 40 +- .../timepicker/jquery-ui-timepicker-ar.js | 32 +- .../timepicker/jquery-ui-timepicker-bg.js | 34 +- .../timepicker/jquery-ui-timepicker-cs.js | 34 +- .../timepicker/jquery-ui-timepicker-de.js | 34 +- .../timepicker/jquery-ui-timepicker-el.js | 34 +- .../timepicker/jquery-ui-timepicker-es.js | 34 +- .../timepicker/jquery-ui-timepicker-fr.js | 34 +- .../timepicker/jquery-ui-timepicker-hu.js | 34 +- .../timepicker/jquery-ui-timepicker-id.js | 34 +- .../timepicker/jquery-ui-timepicker-it.js | 34 +- .../timepicker/jquery-ui-timepicker-ja.js | 34 +- .../timepicker/jquery-ui-timepicker-ko.js | 34 +- .../timepicker/jquery-ui-timepicker-nl.js | 34 +- .../timepicker/jquery-ui-timepicker-no.js | 0 .../timepicker/jquery-ui-timepicker-pl.js | 34 +- .../timepicker/jquery-ui-timepicker-pt-br.js | 34 +- .../timepicker/jquery-ui-timepicker-pt.js | 34 +- .../timepicker/jquery-ui-timepicker-ro.js | 34 +- .../timepicker/jquery-ui-timepicker-ru.js | 34 +- .../timepicker/jquery-ui-timepicker-sk.js | 34 +- .../timepicker/jquery-ui-timepicker-tr.js | 34 +- .../timepicker/jquery-ui-timepicker-uk.js | 34 +- .../timepicker/jquery-ui-timepicker-vi.js | 34 +- .../timepicker/jquery-ui-timepicker-zh-cn.js | 34 +- .../js/jquery_plugins/ui/index.html | 2 +- .../ui/jquery-ui-1.10.3.custom.min.js | 0 assets/grocery_crud/languages/.htaccess | 0 .../languages/add-new-lang-string.sh | 6 +- assets/grocery_crud/languages/afrikaans.php | 175 +- assets/grocery_crud/languages/arabic.php | 179 +- assets/grocery_crud/languages/bengali.php | 180 +- assets/grocery_crud/languages/bulgarian.php | 174 +- assets/grocery_crud/languages/catalan.php | 182 +- assets/grocery_crud/languages/chinese.php | 175 +- assets/grocery_crud/languages/croatian.php | 104 + assets/grocery_crud/languages/czech.php | 178 +- assets/grocery_crud/languages/danish.php | 178 +- assets/grocery_crud/languages/dutch.php | 176 +- assets/grocery_crud/languages/english.php | 177 +- assets/grocery_crud/languages/french.php | 176 +- assets/grocery_crud/languages/german.php | 147 +- assets/grocery_crud/languages/greek.php | 175 +- assets/grocery_crud/languages/hindi.php | 180 +- assets/grocery_crud/languages/hungarian.php | 64 +- assets/grocery_crud/languages/index.html | 2 +- assets/grocery_crud/languages/indonesian.php | 186 +- assets/grocery_crud/languages/italian.php | 149 +- assets/grocery_crud/languages/japanese.php | 174 +- assets/grocery_crud/languages/korean.php | 172 +- assets/grocery_crud/languages/lithuanian.php | 97 + assets/grocery_crud/languages/mongolian.php | 179 +- assets/grocery_crud/languages/norwegian.php | 24 +- assets/grocery_crud/languages/persian.php | 174 +- assets/grocery_crud/languages/polish.php | 177 +- .../languages/pt-br.portuguese.php | 180 +- .../languages/pt-pt.portuguese.php | 152 +- assets/grocery_crud/languages/romanian.php | 152 +- assets/grocery_crud/languages/russian.php | 174 +- assets/grocery_crud/languages/slovak.php | 152 +- assets/grocery_crud/languages/spanish-uy.php | 99 + assets/grocery_crud/languages/spanish.php | 178 +- assets/grocery_crud/languages/thai.php | 174 +- assets/grocery_crud/languages/turkish.php | 162 +- assets/grocery_crud/languages/ukrainian.php | 174 +- assets/grocery_crud/languages/vietnamese.php | 174 +- assets/grocery_crud/license-gpl3.txt | 1348 +- assets/grocery_crud/license-grocery-crud.txt | 12 +- assets/grocery_crud/license-mit.txt | 42 +- .../texteditor/ckeditor/.htaccess | 48 +- .../texteditor/ckeditor/LICENSE.html | 2654 +- .../texteditor/ckeditor/adapters/jquery.js | 12 +- .../texteditor/ckeditor/ckeditor.js | 306 +- .../texteditor/ckeditor/ckeditor.php | 58 +- .../texteditor/ckeditor/ckeditor_php4.php | 1132 +- .../texteditor/ckeditor/ckeditor_php5.php | 1112 +- .../texteditor/ckeditor/config.js | 22 +- .../texteditor/ckeditor/contents.css | 50 +- .../texteditor/ckeditor/images/spacer.gif | Bin .../texteditor/ckeditor/lang/_languages.js | 12 +- .../ckeditor/lang/_translationstatus.txt | 0 .../texteditor/ckeditor/lang/af.js | 12 +- .../texteditor/ckeditor/lang/ar.js | 12 +- .../texteditor/ckeditor/lang/bg.js | 12 +- .../texteditor/ckeditor/lang/bn.js | 12 +- .../texteditor/ckeditor/lang/bs.js | 12 +- .../texteditor/ckeditor/lang/ca.js | 12 +- .../texteditor/ckeditor/lang/cs.js | 12 +- .../texteditor/ckeditor/lang/cy.js | 12 +- .../texteditor/ckeditor/lang/da.js | 12 +- .../texteditor/ckeditor/lang/de.js | 12 +- .../texteditor/ckeditor/lang/el.js | 12 +- .../texteditor/ckeditor/lang/en-au.js | 12 +- .../texteditor/ckeditor/lang/en-ca.js | 12 +- .../texteditor/ckeditor/lang/en-gb.js | 12 +- .../texteditor/ckeditor/lang/en.js | 12 +- .../texteditor/ckeditor/lang/eo.js | 12 +- .../texteditor/ckeditor/lang/es.js | 12 +- .../texteditor/ckeditor/lang/et.js | 12 +- .../texteditor/ckeditor/lang/eu.js | 12 +- .../texteditor/ckeditor/lang/fa.js | 1644 +- .../texteditor/ckeditor/lang/fi.js | 12 +- .../texteditor/ckeditor/lang/fo.js | 12 +- .../texteditor/ckeditor/lang/fr-ca.js | 12 +- .../texteditor/ckeditor/lang/fr.js | 12 +- .../texteditor/ckeditor/lang/gl.js | 12 +- .../texteditor/ckeditor/lang/gu.js | 12 +- .../texteditor/ckeditor/lang/he.js | 12 +- .../texteditor/ckeditor/lang/hi.js | 12 +- .../texteditor/ckeditor/lang/hr.js | 12 +- .../texteditor/ckeditor/lang/hu.js | 12 +- .../texteditor/ckeditor/lang/id.js | 12 +- .../texteditor/ckeditor/lang/is.js | 12 +- .../texteditor/ckeditor/lang/it.js | 12 +- .../texteditor/ckeditor/lang/ja.js | 12 +- .../texteditor/ckeditor/lang/ka.js | 12 +- .../texteditor/ckeditor/lang/km.js | 12 +- .../texteditor/ckeditor/lang/ko.js | 12 +- .../texteditor/ckeditor/lang/ku.js | 1642 +- .../texteditor/ckeditor/lang/lt.js | 12 +- .../texteditor/ckeditor/lang/lv.js | 12 +- .../texteditor/ckeditor/lang/mk.js | 12 +- .../texteditor/ckeditor/lang/mn.js | 12 +- .../texteditor/ckeditor/lang/ms.js | 12 +- .../texteditor/ckeditor/lang/nb.js | 12 +- .../texteditor/ckeditor/lang/nl.js | 12 +- .../texteditor/ckeditor/lang/no.js | 12 +- .../texteditor/ckeditor/lang/pl.js | 12 +- .../texteditor/ckeditor/lang/pt-br.js | 12 +- .../texteditor/ckeditor/lang/pt.js | 12 +- .../texteditor/ckeditor/lang/ro.js | 12 +- .../texteditor/ckeditor/lang/ru.js | 12 +- .../texteditor/ckeditor/lang/sk.js | 12 +- .../texteditor/ckeditor/lang/sl.js | 12 +- .../texteditor/ckeditor/lang/sr-latn.js | 12 +- .../texteditor/ckeditor/lang/sr.js | 12 +- .../texteditor/ckeditor/lang/sv.js | 12 +- .../texteditor/ckeditor/lang/th.js | 12 +- .../texteditor/ckeditor/lang/tr.js | 12 +- .../texteditor/ckeditor/lang/ug.js | 12 +- .../texteditor/ckeditor/lang/uk.js | 12 +- .../texteditor/ckeditor/lang/vi.js | 12 +- .../texteditor/ckeditor/lang/zh-cn.js | 12 +- .../texteditor/ckeditor/lang/zh.js | 12 +- .../plugins/a11yhelp/dialogs/a11yhelp.js | 14 +- .../a11yhelp/lang/_translationstatus.txt | 0 .../ckeditor/plugins/a11yhelp/lang/cs.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/cy.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/da.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/de.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/el.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/en.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/eo.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/fa.js | 188 +- .../ckeditor/plugins/a11yhelp/lang/fi.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/fr.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/gu.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/he.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/it.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/ku.js | 188 +- .../ckeditor/plugins/a11yhelp/lang/mk.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/nb.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/nl.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/no.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/pt-br.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/ro.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/sk.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/tr.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/ug.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/vi.js | 12 +- .../ckeditor/plugins/a11yhelp/lang/zh-cn.js | 12 +- .../ckeditor/plugins/about/dialogs/about.js | 12 +- .../plugins/about/dialogs/logo_ckeditor.png | Bin .../ckeditor/plugins/adobeair/plugin.js | 12 +- .../ckeditor/plugins/ajax/plugin.js | 12 +- .../ckeditor/plugins/autogrow/plugin.js | 12 +- .../ckeditor/plugins/bbcode/plugin.js | 18 +- .../plugins/clipboard/dialogs/paste.js | 14 +- .../colordialog/dialogs/colordialog.js | 14 +- .../devtools/lang/_translationstatus.txt | 0 .../ckeditor/plugins/devtools/lang/bg.js | 12 +- .../ckeditor/plugins/devtools/lang/cs.js | 12 +- .../ckeditor/plugins/devtools/lang/cy.js | 12 +- .../ckeditor/plugins/devtools/lang/da.js | 12 +- .../ckeditor/plugins/devtools/lang/de.js | 12 +- .../ckeditor/plugins/devtools/lang/el.js | 12 +- .../ckeditor/plugins/devtools/lang/en.js | 12 +- .../ckeditor/plugins/devtools/lang/eo.js | 12 +- .../ckeditor/plugins/devtools/lang/et.js | 12 +- .../ckeditor/plugins/devtools/lang/fa.js | 42 +- .../ckeditor/plugins/devtools/lang/fi.js | 12 +- .../ckeditor/plugins/devtools/lang/fr.js | 12 +- .../ckeditor/plugins/devtools/lang/gu.js | 12 +- .../ckeditor/plugins/devtools/lang/he.js | 12 +- .../ckeditor/plugins/devtools/lang/hr.js | 12 +- .../ckeditor/plugins/devtools/lang/it.js | 12 +- .../ckeditor/plugins/devtools/lang/ku.js | 42 +- .../ckeditor/plugins/devtools/lang/nb.js | 12 +- .../ckeditor/plugins/devtools/lang/nl.js | 12 +- .../ckeditor/plugins/devtools/lang/no.js | 12 +- .../ckeditor/plugins/devtools/lang/pl.js | 12 +- .../ckeditor/plugins/devtools/lang/pt-br.js | 12 +- .../ckeditor/plugins/devtools/lang/sk.js | 12 +- .../ckeditor/plugins/devtools/lang/tr.js | 12 +- .../ckeditor/plugins/devtools/lang/ug.js | 12 +- .../ckeditor/plugins/devtools/lang/uk.js | 12 +- .../ckeditor/plugins/devtools/lang/vi.js | 12 +- .../ckeditor/plugins/devtools/lang/zh-cn.js | 12 +- .../ckeditor/plugins/devtools/plugin.js | 12 +- .../plugins/dialog/dialogDefinition.js | 8 +- .../ckeditor/plugins/div/dialogs/div.js | 16 +- .../plugins/docprops/dialogs/docprops.js | 20 +- .../ckeditor/plugins/docprops/plugin.js | 12 +- .../ckeditor/plugins/find/dialogs/find.js | 20 +- .../ckeditor/plugins/flash/dialogs/flash.js | 18 +- .../plugins/flash/images/placeholder.png | Bin .../ckeditor/plugins/forms/dialogs/button.js | 12 +- .../plugins/forms/dialogs/checkbox.js | 12 +- .../ckeditor/plugins/forms/dialogs/form.js | 12 +- .../plugins/forms/dialogs/hiddenfield.js | 12 +- .../ckeditor/plugins/forms/dialogs/radio.js | 12 +- .../ckeditor/plugins/forms/dialogs/select.js | 18 +- .../plugins/forms/dialogs/textarea.js | 12 +- .../plugins/forms/dialogs/textfield.js | 12 +- .../plugins/forms/images/hiddenfield.gif | Bin .../ckeditor/plugins/iframe/dialogs/iframe.js | 14 +- .../plugins/iframe/images/placeholder.png | Bin .../ckeditor/plugins/iframedialog/plugin.js | 12 +- .../ckeditor/plugins/image/dialogs/image.js | 26 +- .../ckeditor/plugins/link/dialogs/anchor.js | 12 +- .../ckeditor/plugins/link/dialogs/link.js | 24 +- .../ckeditor/plugins/link/images/anchor.gif | Bin .../plugins/liststyle/dialogs/liststyle.js | 14 +- .../plugins/pagebreak/images/pagebreak.gif | Bin .../plugins/pastefromword/filter/default.js | 22 +- .../plugins/pastetext/dialogs/pastetext.js | 12 +- .../placeholder/dialogs/placeholder.js | 12 +- .../placeholder/lang/_translationstatus.txt | 0 .../ckeditor/plugins/placeholder/lang/bg.js | 12 +- .../ckeditor/plugins/placeholder/lang/cs.js | 12 +- .../ckeditor/plugins/placeholder/lang/cy.js | 12 +- .../ckeditor/plugins/placeholder/lang/da.js | 12 +- .../ckeditor/plugins/placeholder/lang/de.js | 12 +- .../ckeditor/plugins/placeholder/lang/el.js | 12 +- .../ckeditor/plugins/placeholder/lang/en.js | 12 +- .../ckeditor/plugins/placeholder/lang/eo.js | 12 +- .../ckeditor/plugins/placeholder/lang/et.js | 12 +- .../ckeditor/plugins/placeholder/lang/fa.js | 42 +- .../ckeditor/plugins/placeholder/lang/fi.js | 12 +- .../ckeditor/plugins/placeholder/lang/fr.js | 12 +- .../ckeditor/plugins/placeholder/lang/he.js | 12 +- .../ckeditor/plugins/placeholder/lang/hr.js | 12 +- .../ckeditor/plugins/placeholder/lang/it.js | 12 +- .../ckeditor/plugins/placeholder/lang/ku.js | 42 +- .../ckeditor/plugins/placeholder/lang/nb.js | 12 +- .../ckeditor/plugins/placeholder/lang/nl.js | 12 +- .../ckeditor/plugins/placeholder/lang/no.js | 12 +- .../ckeditor/plugins/placeholder/lang/pl.js | 12 +- .../plugins/placeholder/lang/pt-br.js | 12 +- .../ckeditor/plugins/placeholder/lang/sk.js | 12 +- .../ckeditor/plugins/placeholder/lang/tr.js | 12 +- .../ckeditor/plugins/placeholder/lang/ug.js | 12 +- .../ckeditor/plugins/placeholder/lang/uk.js | 12 +- .../ckeditor/plugins/placeholder/lang/vi.js | 12 +- .../plugins/placeholder/lang/zh-cn.js | 12 +- .../plugins/placeholder/placeholder.gif | Bin .../ckeditor/plugins/placeholder/plugin.js | 12 +- .../ckeditor/plugins/preview/preview.html | 20 +- .../ckeditor/plugins/scayt/dialogs/options.js | 16 +- .../plugins/scayt/dialogs/toolbar.css | 12 +- .../showblocks/images/block_address.png | Bin .../showblocks/images/block_blockquote.png | Bin .../plugins/showblocks/images/block_div.png | Bin .../plugins/showblocks/images/block_h1.png | Bin .../plugins/showblocks/images/block_h2.png | Bin .../plugins/showblocks/images/block_h3.png | Bin .../plugins/showblocks/images/block_h4.png | Bin .../plugins/showblocks/images/block_h5.png | Bin .../plugins/showblocks/images/block_h6.png | Bin .../plugins/showblocks/images/block_p.png | Bin .../plugins/showblocks/images/block_pre.png | Bin .../ckeditor/plugins/smiley/dialogs/smiley.js | 14 +- .../plugins/smiley/images/angel_smile.gif | Bin .../plugins/smiley/images/angry_smile.gif | Bin .../plugins/smiley/images/broken_heart.gif | Bin .../plugins/smiley/images/confused_smile.gif | Bin .../plugins/smiley/images/cry_smile.gif | Bin .../plugins/smiley/images/devil_smile.gif | Bin .../smiley/images/embaressed_smile.gif | Bin .../plugins/smiley/images/envelope.gif | Bin .../ckeditor/plugins/smiley/images/heart.gif | Bin .../ckeditor/plugins/smiley/images/kiss.gif | Bin .../plugins/smiley/images/lightbulb.gif | Bin .../plugins/smiley/images/omg_smile.gif | Bin .../plugins/smiley/images/regular_smile.gif | Bin .../plugins/smiley/images/sad_smile.gif | Bin .../plugins/smiley/images/shades_smile.gif | Bin .../plugins/smiley/images/teeth_smile.gif | Bin .../plugins/smiley/images/thumbs_down.gif | Bin .../plugins/smiley/images/thumbs_up.gif | Bin .../plugins/smiley/images/tounge_smile.gif | Bin .../images/whatchutalkingabout_smile.gif | Bin .../plugins/smiley/images/wink_smile.gif | Bin .../specialchar/dialogs/specialchar.js | 14 +- .../specialchar/lang/_translationstatus.txt | 0 .../ckeditor/plugins/specialchar/lang/cs.js | 12 +- .../ckeditor/plugins/specialchar/lang/cy.js | 12 +- .../ckeditor/plugins/specialchar/lang/de.js | 12 +- .../ckeditor/plugins/specialchar/lang/el.js | 12 +- .../ckeditor/plugins/specialchar/lang/en.js | 12 +- .../ckeditor/plugins/specialchar/lang/eo.js | 12 +- .../ckeditor/plugins/specialchar/lang/et.js | 12 +- .../ckeditor/plugins/specialchar/lang/fa.js | 262 +- .../ckeditor/plugins/specialchar/lang/fi.js | 12 +- .../ckeditor/plugins/specialchar/lang/fr.js | 12 +- .../ckeditor/plugins/specialchar/lang/he.js | 12 +- .../ckeditor/plugins/specialchar/lang/hr.js | 12 +- .../ckeditor/plugins/specialchar/lang/it.js | 12 +- .../ckeditor/plugins/specialchar/lang/ku.js | 262 +- .../ckeditor/plugins/specialchar/lang/nb.js | 12 +- .../ckeditor/plugins/specialchar/lang/nl.js | 12 +- .../ckeditor/plugins/specialchar/lang/no.js | 12 +- .../plugins/specialchar/lang/pt-br.js | 12 +- .../ckeditor/plugins/specialchar/lang/tr.js | 12 +- .../ckeditor/plugins/specialchar/lang/ug.js | 12 +- .../plugins/specialchar/lang/zh-cn.js | 12 +- .../ckeditor/plugins/styles/styles/default.js | 12 +- .../plugins/stylesheetparser/plugin.js | 12 +- .../ckeditor/plugins/table/dialogs/table.js | 18 +- .../ckeditor/plugins/tableresize/plugin.js | 14 +- .../plugins/tabletools/dialogs/tableCell.js | 16 +- .../plugins/templates/dialogs/templates.js | 14 +- .../plugins/templates/templates/default.js | 12 +- .../templates/templates/images/template1.gif | Bin .../templates/templates/images/template2.gif | Bin .../templates/templates/images/template3.gif | Bin .../plugins/uicolor/dialogs/uicolor.js | 14 +- .../uicolor/lang/_translationstatus.txt | 0 .../ckeditor/plugins/uicolor/lang/bg.js | 12 +- .../ckeditor/plugins/uicolor/lang/cs.js | 12 +- .../ckeditor/plugins/uicolor/lang/cy.js | 12 +- .../ckeditor/plugins/uicolor/lang/da.js | 12 +- .../ckeditor/plugins/uicolor/lang/de.js | 12 +- .../ckeditor/plugins/uicolor/lang/el.js | 12 +- .../ckeditor/plugins/uicolor/lang/en.js | 12 +- .../ckeditor/plugins/uicolor/lang/eo.js | 12 +- .../ckeditor/plugins/uicolor/lang/et.js | 12 +- .../ckeditor/plugins/uicolor/lang/fa.js | 40 +- .../ckeditor/plugins/uicolor/lang/fi.js | 12 +- .../ckeditor/plugins/uicolor/lang/fr.js | 12 +- .../ckeditor/plugins/uicolor/lang/he.js | 12 +- .../ckeditor/plugins/uicolor/lang/hr.js | 12 +- .../ckeditor/plugins/uicolor/lang/it.js | 12 +- .../ckeditor/plugins/uicolor/lang/ku.js | 40 +- .../ckeditor/plugins/uicolor/lang/mk.js | 12 +- .../ckeditor/plugins/uicolor/lang/nb.js | 12 +- .../ckeditor/plugins/uicolor/lang/nl.js | 12 +- .../ckeditor/plugins/uicolor/lang/no.js | 12 +- .../ckeditor/plugins/uicolor/lang/pl.js | 12 +- .../ckeditor/plugins/uicolor/lang/pt-br.js | 12 +- .../ckeditor/plugins/uicolor/lang/sk.js | 12 +- .../ckeditor/plugins/uicolor/lang/tr.js | 12 +- .../ckeditor/plugins/uicolor/lang/ug.js | 12 +- .../ckeditor/plugins/uicolor/lang/uk.js | 12 +- .../ckeditor/plugins/uicolor/lang/vi.js | 12 +- .../ckeditor/plugins/uicolor/lang/zh-cn.js | 12 +- .../ckeditor/plugins/uicolor/plugin.js | 12 +- .../ckeditor/plugins/uicolor/uicolor.gif | Bin .../plugins/uicolor/yui/assets/hue_bg.png | Bin .../plugins/uicolor/yui/assets/hue_thumb.png | Bin .../uicolor/yui/assets/picker_mask.png | Bin .../uicolor/yui/assets/picker_thumb.png | Bin .../plugins/uicolor/yui/assets/yui.css | 12 +- .../ckeditor/plugins/uicolor/yui/yui.js | 152 +- .../ckeditor/plugins/wsc/dialogs/ciframe.html | 98 +- .../plugins/wsc/dialogs/tmpFrameset.html | 104 +- .../ckeditor/plugins/wsc/dialogs/wsc.css | 12 +- .../ckeditor/plugins/wsc/dialogs/wsc.js | 14 +- .../texteditor/ckeditor/plugins/xml/plugin.js | 12 +- .../texteditor/ckeditor/skins/kama/dialog.css | 20 +- .../texteditor/ckeditor/skins/kama/editor.css | 26 +- .../texteditor/ckeditor/skins/kama/icons.png | Bin .../ckeditor/skins/kama/icons_rtl.png | Bin .../skins/kama/images/dialog_sides.gif | Bin .../skins/kama/images/dialog_sides.png | Bin .../skins/kama/images/dialog_sides_rtl.png | Bin .../ckeditor/skins/kama/images/mini.gif | Bin .../ckeditor/skins/kama/images/noimage.png | Bin .../ckeditor/skins/kama/images/sprites.png | Bin .../skins/kama/images/sprites_ie6.png | Bin .../skins/kama/images/toolbar_start.gif | Bin .../texteditor/ckeditor/skins/kama/skin.js | 14 +- .../ckeditor/skins/kama/templates.css | 12 +- .../ckeditor/themes/default/theme.js | 16 +- .../texteditor/markitup/index.html | 10 - .../texteditor/markitup/jquery.markitup.js | 593 - .../markitup/sets/default/images/bold.png | Bin 304 -> 0 bytes .../markitup/sets/default/images/clean.png | Bin 667 -> 0 bytes .../markitup/sets/default/images/image.png | Bin 516 -> 0 bytes .../markitup/sets/default/images/italic.png | Bin 223 -> 0 bytes .../markitup/sets/default/images/link.png | Bin 343 -> 0 bytes .../sets/default/images/list-bullet.png | Bin 344 -> 0 bytes .../sets/default/images/list-numeric.png | Bin 357 -> 0 bytes .../markitup/sets/default/images/picture.png | Bin 606 -> 0 bytes .../markitup/sets/default/images/preview.png | Bin 537 -> 0 bytes .../markitup/sets/default/images/stroke.png | Bin 269 -> 0 bytes .../markitup/sets/default/style.css | 34 - .../skins/markitup/images/bg-container.png | Bin 322 -> 0 bytes .../markitup/images/bg-editor-bbcode.png | Bin 1642 -> 0 bytes .../markitup/images/bg-editor-dotclear.png | Bin 1682 -> 0 bytes .../skins/markitup/images/bg-editor-html.png | Bin 1534 -> 0 bytes .../skins/markitup/images/bg-editor-json.png | Bin 1529 -> 0 bytes .../markitup/images/bg-editor-markdown.png | Bin 1783 -> 0 bytes .../markitup/images/bg-editor-textile.png | Bin 1659 -> 0 bytes .../skins/markitup/images/bg-editor-wiki.png | Bin 1488 -> 0 bytes .../skins/markitup/images/bg-editor-xml.png | Bin 1495 -> 0 bytes .../skins/markitup/images/bg-editor.png | Bin 1884 -> 0 bytes .../markitup/skins/markitup/images/handle.png | Bin 258 -> 0 bytes .../markitup/skins/markitup/images/menu.png | Bin 254 -> 0 bytes .../skins/markitup/images/submenu.png | Bin 240 -> 0 bytes .../markitup/skins/markitup/style.css | 147 - .../markitup/skins/simple/images/handle.png | Bin 258 -> 0 bytes .../markitup/skins/simple/images/menu.png | Bin 27151 -> 0 bytes .../markitup/skins/simple/images/submenu.png | Bin 240 -> 0 bytes .../markitup/skins/simple/style.css | 118 - .../texteditor/tiny_mce/jquery.tinymce.js | 1 - .../texteditor/tiny_mce/langs/en.js | 1 - .../tiny_mce/plugins/advhr/css/advhr.css | 5 - .../tiny_mce/plugins/advhr/editor_plugin.js | 1 - .../plugins/advhr/editor_plugin_src.js | 57 - .../tiny_mce/plugins/advhr/js/rule.js | 43 - .../tiny_mce/plugins/advhr/langs/en_dlg.js | 1 - .../tiny_mce/plugins/advhr/rule.htm | 58 - .../plugins/advimage/css/advimage.css | 13 - .../plugins/advimage/editor_plugin.js | 1 - .../plugins/advimage/editor_plugin_src.js | 50 - .../tiny_mce/plugins/advimage/image.htm | 235 - .../tiny_mce/plugins/advimage/img/sample.gif | Bin 1624 -> 0 bytes .../tiny_mce/plugins/advimage/js/image.js | 464 - .../tiny_mce/plugins/advimage/langs/en_dlg.js | 1 - .../tiny_mce/plugins/advlink/css/advlink.css | 8 - .../tiny_mce/plugins/advlink/editor_plugin.js | 1 - .../plugins/advlink/editor_plugin_src.js | 61 - .../tiny_mce/plugins/advlink/js/advlink.js | 543 - .../tiny_mce/plugins/advlink/langs/en_dlg.js | 1 - .../tiny_mce/plugins/advlink/link.htm | 338 - .../tiny_mce/plugins/advlist/editor_plugin.js | 1 - .../plugins/advlist/editor_plugin_src.js | 176 - .../plugins/autolink/editor_plugin.js | 1 - .../plugins/autolink/editor_plugin_src.js | 184 - .../plugins/autoresize/editor_plugin.js | 1 - .../plugins/autoresize/editor_plugin_src.js | 119 - .../plugins/autosave/editor_plugin.js | 1 - .../plugins/autosave/editor_plugin_src.js | 433 - .../tiny_mce/plugins/autosave/langs/en.js | 4 - .../tiny_mce/plugins/bbcode/editor_plugin.js | 1 - .../plugins/bbcode/editor_plugin_src.js | 120 - .../plugins/contextmenu/editor_plugin.js | 1 - .../plugins/contextmenu/editor_plugin_src.js | 163 - .../plugins/directionality/editor_plugin.js | 1 - .../directionality/editor_plugin_src.js | 85 - .../plugins/emotions/editor_plugin.js | 1 - .../plugins/emotions/editor_plugin_src.js | 43 - .../tiny_mce/plugins/emotions/emotions.htm | 42 - .../plugins/emotions/img/smiley-cool.gif | Bin 354 -> 0 bytes .../plugins/emotions/img/smiley-cry.gif | Bin 329 -> 0 bytes .../emotions/img/smiley-embarassed.gif | Bin 331 -> 0 bytes .../emotions/img/smiley-foot-in-mouth.gif | Bin 342 -> 0 bytes .../plugins/emotions/img/smiley-frown.gif | Bin 340 -> 0 bytes .../plugins/emotions/img/smiley-innocent.gif | Bin 336 -> 0 bytes .../plugins/emotions/img/smiley-kiss.gif | Bin 338 -> 0 bytes .../plugins/emotions/img/smiley-laughing.gif | Bin 343 -> 0 bytes .../emotions/img/smiley-money-mouth.gif | Bin 321 -> 0 bytes .../plugins/emotions/img/smiley-sealed.gif | Bin 323 -> 0 bytes .../plugins/emotions/img/smiley-smile.gif | Bin 344 -> 0 bytes .../plugins/emotions/img/smiley-surprised.gif | Bin 338 -> 0 bytes .../emotions/img/smiley-tongue-out.gif | Bin 328 -> 0 bytes .../plugins/emotions/img/smiley-undecided.gif | Bin 337 -> 0 bytes .../plugins/emotions/img/smiley-wink.gif | Bin 350 -> 0 bytes .../plugins/emotions/img/smiley-yell.gif | Bin 336 -> 0 bytes .../tiny_mce/plugins/emotions/js/emotions.js | 43 - .../tiny_mce/plugins/emotions/langs/en_dlg.js | 1 - .../tiny_mce/plugins/example/dialog.htm | 22 - .../tiny_mce/plugins/example/editor_plugin.js | 1 - .../plugins/example/editor_plugin_src.js | 84 - .../tiny_mce/plugins/example/img/example.gif | Bin 87 -> 0 bytes .../tiny_mce/plugins/example/js/dialog.js | 19 - .../tiny_mce/plugins/example/langs/en.js | 3 - .../tiny_mce/plugins/example/langs/en_dlg.js | 3 - .../example_dependency/editor_plugin.js | 1 - .../example_dependency/editor_plugin_src.js | 50 - .../plugins/fullpage/css/fullpage.css | 143 - .../plugins/fullpage/editor_plugin.js | 1 - .../plugins/fullpage/editor_plugin_src.js | 405 - .../tiny_mce/plugins/fullpage/fullpage.htm | 259 - .../tiny_mce/plugins/fullpage/js/fullpage.js | 232 - .../tiny_mce/plugins/fullpage/langs/en_dlg.js | 1 - .../plugins/fullscreen/editor_plugin.js | 1 - .../plugins/fullscreen/editor_plugin_src.js | 159 - .../plugins/fullscreen/fullscreen.htm | 110 - .../tiny_mce/plugins/iespell/editor_plugin.js | 1 - .../plugins/iespell/editor_plugin_src.js | 54 - .../plugins/inlinepopups/editor_plugin.js | 1 - .../plugins/inlinepopups/editor_plugin_src.js | 699 - .../skins/clearlooks2/img/alert.gif | Bin 810 -> 0 bytes .../skins/clearlooks2/img/button.gif | Bin 272 -> 0 bytes .../skins/clearlooks2/img/buttons.gif | Bin 1195 -> 0 bytes .../skins/clearlooks2/img/confirm.gif | Bin 907 -> 0 bytes .../skins/clearlooks2/img/corners.gif | Bin 909 -> 0 bytes .../skins/clearlooks2/img/horizontal.gif | Bin 769 -> 0 bytes .../skins/clearlooks2/img/vertical.gif | Bin 84 -> 0 bytes .../inlinepopups/skins/clearlooks2/window.css | 90 - .../plugins/inlinepopups/template.htm | 387 - .../plugins/insertdatetime/editor_plugin.js | 1 - .../insertdatetime/editor_plugin_src.js | 83 - .../tiny_mce/plugins/layer/editor_plugin.js | 1 - .../plugins/layer/editor_plugin_src.js | 262 - .../plugins/legacyoutput/editor_plugin.js | 1 - .../plugins/legacyoutput/editor_plugin_src.js | 139 - .../tiny_mce/plugins/lists/editor_plugin.js | 1 - .../plugins/lists/editor_plugin_src.js | 955 - .../tiny_mce/plugins/media/css/media.css | 17 - .../tiny_mce/plugins/media/editor_plugin.js | 1 - .../plugins/media/editor_plugin_src.js | 898 - .../tiny_mce/plugins/media/js/embed.js | 73 - .../tiny_mce/plugins/media/js/media.js | 503 - .../tiny_mce/plugins/media/langs/en_dlg.js | 1 - .../tiny_mce/plugins/media/media.htm | 922 - .../tiny_mce/plugins/media/moxieplayer.swf | Bin 19980 -> 0 bytes .../plugins/nonbreaking/editor_plugin.js | 1 - .../plugins/nonbreaking/editor_plugin_src.js | 54 - .../plugins/noneditable/editor_plugin.js | 1 - .../plugins/noneditable/editor_plugin_src.js | 537 - .../plugins/pagebreak/editor_plugin.js | 1 - .../plugins/pagebreak/editor_plugin_src.js | 74 - .../tiny_mce/plugins/paste/editor_plugin.js | 1 - .../plugins/paste/editor_plugin_src.js | 885 - .../tiny_mce/plugins/paste/js/pastetext.js | 36 - .../tiny_mce/plugins/paste/js/pasteword.js | 51 - .../tiny_mce/plugins/paste/langs/en_dlg.js | 1 - .../tiny_mce/plugins/paste/pastetext.htm | 27 - .../tiny_mce/plugins/paste/pasteword.htm | 21 - .../tiny_mce/plugins/preview/editor_plugin.js | 1 - .../plugins/preview/editor_plugin_src.js | 53 - .../tiny_mce/plugins/preview/example.html | 28 - .../plugins/preview/jscripts/embed.js | 73 - .../tiny_mce/plugins/preview/preview.html | 17 - .../tiny_mce/plugins/print/editor_plugin.js | 1 - .../plugins/print/editor_plugin_src.js | 34 - .../tiny_mce/plugins/save/editor_plugin.js | 1 - .../plugins/save/editor_plugin_src.js | 101 - .../searchreplace/css/searchreplace.css | 6 - .../plugins/searchreplace/editor_plugin.js | 1 - .../searchreplace/editor_plugin_src.js | 61 - .../plugins/searchreplace/js/searchreplace.js | 142 - .../plugins/searchreplace/langs/en_dlg.js | 1 - .../plugins/searchreplace/searchreplace.htm | 100 - .../plugins/spellchecker/css/content.css | 1 - .../plugins/spellchecker/editor_plugin.js | 1 - .../plugins/spellchecker/editor_plugin_src.js | 436 - .../plugins/spellchecker/img/wline.gif | Bin 46 -> 0 bytes .../tiny_mce/plugins/style/css/props.css | 14 - .../tiny_mce/plugins/style/editor_plugin.js | 1 - .../plugins/style/editor_plugin_src.js | 71 - .../tiny_mce/plugins/style/js/props.js | 709 - .../tiny_mce/plugins/style/langs/en_dlg.js | 1 - .../tiny_mce/plugins/style/props.htm | 845 - .../tiny_mce/plugins/style/readme.txt | 19 - .../plugins/tabfocus/editor_plugin.js | 1 - .../plugins/tabfocus/editor_plugin_src.js | 122 - .../tiny_mce/plugins/table/cell.htm | 180 - .../tiny_mce/plugins/table/css/cell.css | 17 - .../tiny_mce/plugins/table/css/row.css | 25 - .../tiny_mce/plugins/table/css/table.css | 13 - .../tiny_mce/plugins/table/editor_plugin.js | 1 - .../plugins/table/editor_plugin_src.js | 1452 - .../tiny_mce/plugins/table/js/cell.js | 319 - .../tiny_mce/plugins/table/js/merge_cells.js | 27 - .../tiny_mce/plugins/table/js/row.js | 237 - .../tiny_mce/plugins/table/js/table.js | 501 - .../tiny_mce/plugins/table/langs/en_dlg.js | 1 - .../tiny_mce/plugins/table/merge_cells.htm | 32 - .../texteditor/tiny_mce/plugins/table/row.htm | 158 - .../tiny_mce/plugins/table/table.htm | 188 - .../tiny_mce/plugins/template/blank.htm | 12 - .../plugins/template/css/template.css | 23 - .../plugins/template/editor_plugin.js | 1 - .../plugins/template/editor_plugin_src.js | 159 - .../tiny_mce/plugins/template/js/template.js | 106 - .../tiny_mce/plugins/template/langs/en_dlg.js | 1 - .../tiny_mce/plugins/template/template.htm | 31 - .../plugins/visualblocks/css/visualblocks.css | 21 - .../plugins/visualblocks/editor_plugin.js | 1 - .../plugins/visualblocks/editor_plugin_src.js | 63 - .../plugins/visualchars/editor_plugin.js | 1 - .../plugins/visualchars/editor_plugin_src.js | 83 - .../plugins/wordcount/editor_plugin.js | 1 - .../plugins/wordcount/editor_plugin_src.js | 122 - .../tiny_mce/plugins/xhtmlxtras/abbr.htm | 142 - .../tiny_mce/plugins/xhtmlxtras/acronym.htm | 142 - .../plugins/xhtmlxtras/attributes.htm | 149 - .../tiny_mce/plugins/xhtmlxtras/cite.htm | 142 - .../plugins/xhtmlxtras/css/attributes.css | 11 - .../tiny_mce/plugins/xhtmlxtras/css/popup.css | 9 - .../tiny_mce/plugins/xhtmlxtras/del.htm | 162 - .../plugins/xhtmlxtras/editor_plugin.js | 1 - .../plugins/xhtmlxtras/editor_plugin_src.js | 132 - .../tiny_mce/plugins/xhtmlxtras/ins.htm | 162 - .../tiny_mce/plugins/xhtmlxtras/js/abbr.js | 28 - .../tiny_mce/plugins/xhtmlxtras/js/acronym.js | 28 - .../plugins/xhtmlxtras/js/attributes.js | 111 - .../tiny_mce/plugins/xhtmlxtras/js/cite.js | 28 - .../tiny_mce/plugins/xhtmlxtras/js/del.js | 53 - .../plugins/xhtmlxtras/js/element_common.js | 229 - .../tiny_mce/plugins/xhtmlxtras/js/ins.js | 53 - .../plugins/xhtmlxtras/langs/en_dlg.js | 1 - .../tiny_mce/themes/advanced/about.htm | 52 - .../tiny_mce/themes/advanced/anchor.htm | 26 - .../tiny_mce/themes/advanced/charmap.htm | 55 - .../tiny_mce/themes/advanced/color_picker.htm | 70 - .../themes/advanced/editor_template.js | 1 - .../themes/advanced/editor_template_src.js | 1490 - .../tiny_mce/themes/advanced/image.htm | 80 - .../themes/advanced/img/colorpicker.jpg | Bin 2584 -> 0 bytes .../tiny_mce/themes/advanced/img/flash.gif | Bin 239 -> 0 bytes .../tiny_mce/themes/advanced/img/icons.gif | Bin 11982 -> 0 bytes .../tiny_mce/themes/advanced/img/iframe.gif | Bin 600 -> 0 bytes .../themes/advanced/img/pagebreak.gif | Bin 325 -> 0 bytes .../themes/advanced/img/quicktime.gif | Bin 301 -> 0 bytes .../themes/advanced/img/realmedia.gif | Bin 439 -> 0 bytes .../themes/advanced/img/shockwave.gif | Bin 384 -> 0 bytes .../tiny_mce/themes/advanced/img/trans.gif | Bin 43 -> 0 bytes .../tiny_mce/themes/advanced/img/video.gif | Bin 597 -> 0 bytes .../themes/advanced/img/windowsmedia.gif | Bin 415 -> 0 bytes .../tiny_mce/themes/advanced/js/about.js | 73 - .../tiny_mce/themes/advanced/js/anchor.js | 56 - .../tiny_mce/themes/advanced/js/charmap.js | 363 - .../themes/advanced/js/color_picker.js | 345 - .../tiny_mce/themes/advanced/js/image.js | 253 - .../tiny_mce/themes/advanced/js/link.js | 159 - .../themes/advanced/js/source_editor.js | 78 - .../tiny_mce/themes/advanced/langs/en.js | 1 - .../tiny_mce/themes/advanced/langs/en_dlg.js | 1 - .../tiny_mce/themes/advanced/link.htm | 57 - .../tiny_mce/themes/advanced/shortcuts.htm | 47 - .../themes/advanced/skins/default/content.css | 50 - .../themes/advanced/skins/default/dialog.css | 118 - .../advanced/skins/default/img/buttons.png | Bin 3133 -> 0 bytes .../advanced/skins/default/img/items.gif | Bin 64 -> 0 bytes .../advanced/skins/default/img/menu_arrow.gif | Bin 68 -> 0 bytes .../advanced/skins/default/img/menu_check.gif | Bin 70 -> 0 bytes .../advanced/skins/default/img/progress.gif | Bin 1787 -> 0 bytes .../advanced/skins/default/img/tabs.gif | Bin 1322 -> 0 bytes .../themes/advanced/skins/default/ui.css | 219 - .../advanced/skins/highcontrast/content.css | 24 - .../advanced/skins/highcontrast/dialog.css | 106 - .../themes/advanced/skins/highcontrast/ui.css | 106 - .../themes/advanced/skins/o2k7/content.css | 48 - .../themes/advanced/skins/o2k7/dialog.css | 118 - .../advanced/skins/o2k7/img/button_bg.png | Bin 2766 -> 0 bytes .../skins/o2k7/img/button_bg_black.png | Bin 651 -> 0 bytes .../skins/o2k7/img/button_bg_silver.png | Bin 2084 -> 0 bytes .../themes/advanced/skins/o2k7/ui.css | 222 - .../themes/advanced/skins/o2k7/ui_black.css | 8 - .../themes/advanced/skins/o2k7/ui_silver.css | 5 - .../themes/advanced/source_editor.htm | 25 - .../tiny_mce/themes/simple/editor_template.js | 1 - .../themes/simple/editor_template_src.js | 84 - .../tiny_mce/themes/simple/img/icons.gif | Bin 806 -> 0 bytes .../tiny_mce/themes/simple/langs/en.js | 1 - .../themes/simple/skins/default/content.css | 25 - .../themes/simple/skins/default/ui.css | 32 - .../themes/simple/skins/o2k7/content.css | 17 - .../simple/skins/o2k7/img/button_bg.png | Bin 5102 -> 0 bytes .../tiny_mce/themes/simple/skins/o2k7/ui.css | 35 - .../texteditor/tiny_mce/tiny_mce.js | 1 - .../texteditor/tiny_mce/tiny_mce_popup.js | 5 - .../texteditor/tiny_mce/tiny_mce_src.js | 17769 ------------ .../tiny_mce/utils/editable_selects.js | 70 - .../texteditor/tiny_mce/utils/form_utils.js | 210 - .../texteditor/tiny_mce/utils/mctabs.js | 162 - .../texteditor/tiny_mce/utils/validate.js | 252 - .../grocery_crud/themes/datatables/config.php | 2 +- .../themes/datatables/css/datatables.css | 223 +- .../themes/datatables/css/demo_table_jui.css | 302 +- .../themes/datatables/css/images/error.png | Bin .../themes/datatables/css/images/index.html | 2 +- .../datatables/css/images/small-loading.gif | Bin .../themes/datatables/css/images/success.png | Bin .../themes/datatables/css/index.html | 2 +- .../datatables/css/jquery.dataTables.css | 138 +- .../TableTools/media/as3/ZeroClipboard.as | 0 .../TableTools/media/as3/ZeroClipboardPdf.as | 0 .../TableTools/media/as3/lib/AlivePDF.swc | Bin .../TableTools/media/css/TableTools.css | 310 +- .../TableTools/media/css/TableTools_JUI.css | 132 +- .../TableTools/media/images/background.png | Bin .../TableTools/media/images/collection.png | Bin .../media/images/collection_hover.png | Bin .../extras/TableTools/media/images/copy.png | Bin .../TableTools/media/images/copy_hover.png | Bin .../extras/TableTools/media/images/csv.png | Bin .../TableTools/media/images/csv_hover.png | Bin .../extras/TableTools/media/images/pdf.png | Bin .../TableTools/media/images/pdf_hover.png | Bin .../extras/TableTools/media/images/print.png | Bin .../TableTools/media/images/print_hover.png | Bin .../media/images/psd/collection.psd | Bin .../media/images/psd/copy document.psd | Bin .../media/images/psd/file_types.psd | Bin .../TableTools/media/images/psd/printer.psd | Bin .../extras/TableTools/media/images/xls.png | Bin .../TableTools/media/images/xls_hover.png | Bin .../extras/TableTools/media/js/TableTools.js | 4404 +-- .../TableTools/media/js/TableTools.min.js | 8 +- .../TableTools/media/js/TableTools.min.js.gz | Bin .../TableTools/media/js/ZeroClipboard.js | 718 +- .../TableTools/media/swf/copy_csv_xls.swf | Bin .../TableTools/media/swf/copy_csv_xls_pdf.swf | Bin .../grocery_crud/themes/datatables/index.html | 2 +- .../themes/datatables/js/datatables-add.js | 277 +- .../themes/datatables/js/datatables-edit.js | 159 +- .../themes/datatables/js/datatables-extras.js | 6 +- .../themes/datatables/js/datatables.js | 351 +- .../themes/datatables/js/index.html | 2 +- .../themes/datatables/js/jquery.dataTables.js | 23680 ++++++++-------- .../datatables/js/jquery.dataTables.min.js | 8 +- .../themes/datatables/views/.htaccess | 0 .../themes/datatables/views/add.php | 130 +- .../themes/datatables/views/edit.php | 133 +- .../themes/datatables/views/list.php | 146 +- .../themes/datatables/views/list_template.php | 211 +- .../themes/datatables/views/read.php | 110 +- .../grocery_crud/themes/flexigrid/config.php | 2 +- .../themes/flexigrid/css/flexigrid.css | 1544 +- .../themes/flexigrid/css/images/add.png | Bin .../themes/flexigrid/css/images/bg.gif | Bin .../flexigrid/css/images/btn-sprite.gif | Bin .../themes/flexigrid/css/images/clone.png | Bin 0 -> 498 bytes .../themes/flexigrid/css/images/close.png | Bin .../themes/flexigrid/css/images/ddn.png | Bin .../themes/flexigrid/css/images/dn.png | Bin .../themes/flexigrid/css/images/edit.png | Bin .../themes/flexigrid/css/images/error.png | Bin .../themes/flexigrid/css/images/export.png | Bin .../themes/flexigrid/css/images/fhbg.gif | Bin .../themes/flexigrid/css/images/first.gif | Bin .../themes/flexigrid/css/images/hl.png | Bin .../themes/flexigrid/css/images/index.html | 2 +- .../themes/flexigrid/css/images/last.gif | Bin .../themes/flexigrid/css/images/line.gif | Bin .../themes/flexigrid/css/images/load.gif | Bin .../themes/flexigrid/css/images/load.png | Bin .../themes/flexigrid/css/images/magnifier.png | Bin .../themes/flexigrid/css/images/next.gif | Bin .../themes/flexigrid/css/images/prev.gif | Bin .../themes/flexigrid/css/images/print.png | Bin .../themes/flexigrid/css/images/success.png | Bin .../themes/flexigrid/css/images/up.png | Bin .../themes/flexigrid/css/images/uup.png | Bin .../themes/flexigrid/css/images/wbg.gif | Bin .../themes/flexigrid/css/index.html | 2 +- .../grocery_crud/themes/flexigrid/index.html | 2 +- .../themes/flexigrid/js/cookies.js | 34 +- .../themes/flexigrid/js/flexigrid-add.js | 290 +- .../themes/flexigrid/js/flexigrid-edit.js | 224 +- .../themes/flexigrid/js/flexigrid.js | 519 +- .../themes/flexigrid/js/index.html | 2 +- .../themes/flexigrid/js/jquery.form.js | 1330 +- .../flexigrid/js/jquery.printElement.js | 19 +- .../flexigrid/js/jquery.printElement.min.js | 12 +- .../themes/flexigrid/views/.htaccess | 0 .../themes/flexigrid/views/add.php | 137 +- .../themes/flexigrid/views/edit.php | 141 +- .../themes/flexigrid/views/list.php | 143 +- .../themes/flexigrid/views/list_template.php | 314 +- .../themes/flexigrid/views/read.php | 124 +- assets/grocery_crud/themes/index.html | 2 +- .../themes/twitter-bootstrap/config.php | 2 - .../css/bootstrap-responsive.min.css | 9 - .../twitter-bootstrap/css/bootstrap.min.css | 9 - .../twitter-bootstrap/css/images/loading.gif | Bin 4899 -> 0 bytes .../twitter-bootstrap/css/images/sort_asc.png | Bin 1118 -> 0 bytes .../css/images/sort_both.png | Bin 1136 -> 0 bytes .../css/images/sort_desc.png | Bin 1127 -> 0 bytes .../images/ui-bg_flat_0_aaaaaa_40x100.png | Bin 180 -> 0 bytes .../images/ui-bg_flat_0_eeeeee_40x100.png | Bin 180 -> 0 bytes .../images/ui-bg_flat_55_ffffff_40x100.png | Bin 178 -> 0 bytes .../images/ui-bg_flat_75_ffffff_40x100.png | Bin 178 -> 0 bytes .../images/ui-bg_glass_65_ffffff_1x400.png | Bin 105 -> 0 bytes .../ui-bg_highlight-soft_100_f6f6f6_1x100.png | Bin 90 -> 0 bytes .../ui-bg_highlight-soft_25_0073ea_1x100.png | Bin 118 -> 0 bytes .../ui-bg_highlight-soft_50_dddddd_1x100.png | Bin 92 -> 0 bytes .../flick/images/ui-icons_0073ea_256x240.png | Bin 4369 -> 0 bytes .../flick/images/ui-icons_454545_256x240.png | Bin 4369 -> 0 bytes .../flick/images/ui-icons_666666_256x240.png | Bin 4369 -> 0 bytes .../flick/images/ui-icons_ff0084_256x240.png | Bin 4369 -> 0 bytes .../flick/images/ui-icons_ffffff_256x240.png | Bin 4369 -> 0 bytes .../flick/jquery-ui-1.9.2.custom.css | 462 - .../flick/jquery-ui-1.9.2.custom.min.css | 5 - .../themes/twitter-bootstrap/css/style.css | 13 - .../twitter-bootstrap/css/tablesorter.css | 41 - .../themes/twitter-bootstrap/img/.gitignore | 0 .../img/glyphicons-halflings-white.png | Bin 8777 -> 0 bytes .../img/glyphicons-halflings.png | Bin 12799 -> 0 bytes .../themes/twitter-bootstrap/js/README.md | 106 - .../js/app/twitter-bootstrap-add.js | 165 - .../js/app/twitter-bootstrap-edit.js | 164 - .../js/app/twitter-bootstrap.js | 340 - .../themes/twitter-bootstrap/js/cookies.js | 25 - .../js/jquery-ui/jquery-ui-1.9.2.custom.js | 14879 ---------- .../jquery-ui/jquery-ui-1.9.2.custom.min.js | 6 - .../twitter-bootstrap/js/jquery.form.js | 825 - .../twitter-bootstrap/js/jquery.functions.js | 47 - .../js/libs/bootstrap/application.js | 154 - .../js/libs/bootstrap/bootstrap.js | 2027 -- .../js/libs/bootstrap/bootstrap.min.js | 6 - .../js/libs/google-code-prettify/prettify.css | 30 - .../js/libs/google-code-prettify/prettify.js | 28 - .../libs/modernizr/modernizr-2.6.1.custom.js | 4 - .../libs/print-element/jquery.printElement.js | 181 - .../print-element/jquery.printElement.min.js | 28 - .../js/libs/requirejs/requirejs.min.js | 35 - .../js/libs/tablesorter/jquery.tablesorter.js | 1032 - .../tablesorter/jquery.tablesorter.min.js | 15 - .../themes/twitter-bootstrap/views/add.php | 86 - .../themes/twitter-bootstrap/views/edit.php | 91 - .../themes/twitter-bootstrap/views/list.php | 89 - .../twitter-bootstrap/views/list_template.php | 173 - ...22-Screenshot-from-2015-01-09-12-25-19.png | Bin 301981 -> 0 bytes .../83820-Busuu-Prenium-Membership-1.png | Bin 353919 -> 0 bytes assets/uploads/files/pdftest.pdf | Bin 2995 -> 0 bytes assets/uploads/files/test-2.pdf | Bin 2995 -> 0 bytes ...1533509423529598_1553413580880622241_n.jpg | Bin 73357 -> 0 bytes ...23-screenshot-from-2015-01-09-12_25_19.png | Bin 305182 -> 0 bytes ...e3-screenshot-from-2015-01-09-12_25_19.png | Bin 305182 -> 0 bytes .../e3fa72ba628c04ba6623f2f4da17a6911.jpg | Bin 27245 -> 0 bytes assets/uploads/member/e8420-user2.jpg | Bin 7467 -> 0 bytes ...22-Screenshot-from-2015-01-09-12-25-19.png | Bin 5355 -> 0 bytes ...humb__83820-Busuu-Prenium-Membership-1.png | Bin 4542 -> 0 bytes ..._652922014788213_8276941645263536198_n.jpg | Bin 51646 -> 0 bytes ...0_791995804156438_558723157162025499_n.jpg | Bin 29507 -> 0 bytes ...0152954611928294_6014292537106002370_n.png | Bin 342404 -> 0 bytes ...152954611928294_6014292537106002370_n1.png | Bin 342404 -> 0 bytes ...152954611928294_6014292537106002370_n2.png | Bin 342404 -> 0 bytes .../Screenshot_from_2015-01-09_12_25_19.png | Bin 305182 -> 0 bytes .../Screenshot_from_2015-01-09_12_25_191.png | Bin 305182 -> 0 bytes assets/uploads/video/photo1380581983_858.jpg | Bin 11440 -> 0 bytes assets/uploads/video/shof_6833924c9eb8e64.jpg | Bin 86799 -> 0 bytes assets/uploads/video/shof_87bf7393fe81ea3.jpg | Bin 64306 -> 0 bytes .../uploads/video/shof_87bf7393fe81ea31.jpg | Bin 64306 -> 0 bytes .../uploads/video/shof_87bf7393fe81ea32.jpg | Bin 64306 -> 0 bytes assets/uploads/video/small.mp4 | Bin 383631 -> 0 bytes assets/uploads/video/smile.jpg | Bin 31560 -> 0 bytes assets/uploads/video/smile1.jpg | Bin 31560 -> 0 bytes install.sql | 243 +- 1018 files changed, 55792 insertions(+), 108584 deletions(-) mode change 100755 => 100644 application/config/grocery_crud.php mode change 100755 => 100644 application/libraries/image_moo.php mode change 100755 => 100644 application/models/ion_auth_model.php delete mode 100755 application/views/example.php mode change 100755 => 100644 assets/grocery_crud/config/index.html mode change 100755 => 100644 assets/grocery_crud/config/language_alias.php mode change 100755 => 100644 assets/grocery_crud/config/translit_chars.php mode change 100755 => 100644 assets/grocery_crud/css/index.html mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/chosen/chosen-sprite.png create mode 100644 assets/grocery_crud/css/jquery_plugins/chosen/chosen-sprite@2x.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/chosen/chosen.css create mode 100644 assets/grocery_crud/css/jquery_plugins/chosen/chosen.min.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/chosen/index.html mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/blank.gif mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_close.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_loading.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_left.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_right.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_e.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_n.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_ne.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_nw.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_s.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_se.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_sw.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_w.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_left.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_main.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_over.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_right.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-x.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-y.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/fancybox.png mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/fancybox/jquery.fancybox.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/bootstrap.min.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/file-uploader.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/fileuploader.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/jquery.fileupload-ui.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/loading.gif mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/file_upload/progressbar.gif mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/index.html mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/jquery-ui-timepicker-addon.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/jquery.ui.datetime.css mode change 100755 => 100644 assets/grocery_crud/css/jquery_plugins/ui.multiselect.css delete mode 100755 assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input-focus.png delete mode 100755 assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input.png delete mode 100755 assets/grocery_crud/css/jquery_plugins/uniform/images/sprite.png delete mode 100755 assets/grocery_crud/css/jquery_plugins/uniform/uniform.default.css mode change 100755 => 100644 assets/grocery_crud/css/ui/index.html mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/animated-overlay.gif mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_flat_0_aaaaaa_40x100.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_flat_75_ffffff_40x100.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_glass_55_fbf9ee_1x400.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_glass_65_ffffff_1x400.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_dadada_1x400.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_e6e6e6_1x400.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_glass_95_fef1ec_1x400.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-bg_highlight-soft_75_cccccc_1x100.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-icons_222222_256x240.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-icons_2e83ff_256x240.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-icons_333333_256x240.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-icons_454545_256x240.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/images/ui-icons_cd0a0a_256x240.png mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/index.html mode change 100755 => 100644 assets/grocery_crud/css/ui/simple/jquery-ui-1.10.1.custom.min.css mode change 100755 => 100644 assets/grocery_crud/index.html mode change 100755 => 100644 assets/grocery_crud/js/common/lazyload-min.js mode change 100755 => 100644 assets/grocery_crud/js/common/list.js mode change 100755 => 100644 assets/grocery_crud/js/index.html delete mode 100755 assets/grocery_crud/js/jquery-1.10.2.min.js create mode 100644 assets/grocery_crud/js/jquery-1.11.1.js create mode 100644 assets/grocery_crud/js/jquery-1.11.1.min.js create mode 100644 assets/grocery_crud/js/jquery-1.11.1.min.map mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ajax-chosen.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery-ui-timepicker-addon.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.chosen.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.ckeditor.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.datepicker.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.datetime.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.fancybox.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.fileupload.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.markitup.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.multiselect.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.noty.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.numeric.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.tine_mce.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/config/jquery.uniform.config.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/index.html delete mode 100755 assets/grocery_crud/js/jquery_plugins/jquery-migrate-1.1.0.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery-ui-timepicker-addon.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery-ui-timepicker-addon.min.js create mode 100644 assets/grocery_crud/js/jquery_plugins/jquery.chosen.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.chosen.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.easing-1.3.pack.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.fancybox-1.3.4.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.fancybox.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.fancybox.pack.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.fileupload.js create mode 100644 assets/grocery_crud/js/jquery_plugins/jquery.form.js create mode 100644 assets/grocery_crud/js/jquery_plugins/jquery.form.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.iframe-transport.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.noty.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.numeric.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/jquery.ui.datetime.js delete mode 100755 assets/grocery_crud/js/jquery_plugins/jquery.uniform.js delete mode 100755 assets/grocery_crud/js/jquery_plugins/jquery.uniform.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/load-image.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/tmpl.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui.multiselect.min.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-af.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-ar.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-bg.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-bn.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-cs.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-da.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-de.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-el.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-es.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-fa.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-fr.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-hu.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-id.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-it.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-ja.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-ko.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-nl.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-no.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-pl.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-pt-br.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-pt.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-ro.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-ru.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-sk.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-th.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-tr.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-uk.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-vi.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-zh-cn.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-ar.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-de.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-el.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-en.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-es.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-fr.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-it.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-ja.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-pt-br.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-ru.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/multiselect/ui-multiselect-uk.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-af.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-ar.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-bg.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-cs.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-de.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-el.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-es.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-fr.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-hu.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-id.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-it.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-ja.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-ko.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-nl.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-no.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-pl.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-pt-br.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-pt.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-ro.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-ru.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-sk.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-tr.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-uk.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-vi.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-zh-cn.js mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/index.html mode change 100755 => 100644 assets/grocery_crud/js/jquery_plugins/ui/jquery-ui-1.10.3.custom.min.js mode change 100755 => 100644 assets/grocery_crud/languages/.htaccess mode change 100755 => 100644 assets/grocery_crud/languages/add-new-lang-string.sh mode change 100755 => 100644 assets/grocery_crud/languages/afrikaans.php mode change 100755 => 100644 assets/grocery_crud/languages/arabic.php mode change 100755 => 100644 assets/grocery_crud/languages/bengali.php mode change 100755 => 100644 assets/grocery_crud/languages/bulgarian.php mode change 100755 => 100644 assets/grocery_crud/languages/catalan.php mode change 100755 => 100644 assets/grocery_crud/languages/chinese.php create mode 100644 assets/grocery_crud/languages/croatian.php mode change 100755 => 100644 assets/grocery_crud/languages/czech.php mode change 100755 => 100644 assets/grocery_crud/languages/danish.php mode change 100755 => 100644 assets/grocery_crud/languages/dutch.php mode change 100755 => 100644 assets/grocery_crud/languages/english.php mode change 100755 => 100644 assets/grocery_crud/languages/french.php mode change 100755 => 100644 assets/grocery_crud/languages/german.php mode change 100755 => 100644 assets/grocery_crud/languages/greek.php mode change 100755 => 100644 assets/grocery_crud/languages/hindi.php mode change 100755 => 100644 assets/grocery_crud/languages/hungarian.php mode change 100755 => 100644 assets/grocery_crud/languages/index.html mode change 100755 => 100644 assets/grocery_crud/languages/indonesian.php mode change 100755 => 100644 assets/grocery_crud/languages/italian.php mode change 100755 => 100644 assets/grocery_crud/languages/japanese.php mode change 100755 => 100644 assets/grocery_crud/languages/korean.php create mode 100644 assets/grocery_crud/languages/lithuanian.php mode change 100755 => 100644 assets/grocery_crud/languages/mongolian.php mode change 100755 => 100644 assets/grocery_crud/languages/norwegian.php mode change 100755 => 100644 assets/grocery_crud/languages/persian.php mode change 100755 => 100644 assets/grocery_crud/languages/polish.php mode change 100755 => 100644 assets/grocery_crud/languages/pt-br.portuguese.php mode change 100755 => 100644 assets/grocery_crud/languages/pt-pt.portuguese.php mode change 100755 => 100644 assets/grocery_crud/languages/romanian.php mode change 100755 => 100644 assets/grocery_crud/languages/russian.php mode change 100755 => 100644 assets/grocery_crud/languages/slovak.php create mode 100644 assets/grocery_crud/languages/spanish-uy.php mode change 100755 => 100644 assets/grocery_crud/languages/spanish.php mode change 100755 => 100644 assets/grocery_crud/languages/thai.php mode change 100755 => 100644 assets/grocery_crud/languages/turkish.php mode change 100755 => 100644 assets/grocery_crud/languages/ukrainian.php mode change 100755 => 100644 assets/grocery_crud/languages/vietnamese.php mode change 100755 => 100644 assets/grocery_crud/license-gpl3.txt mode change 100755 => 100644 assets/grocery_crud/license-grocery-crud.txt mode change 100755 => 100644 assets/grocery_crud/license-mit.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/.htaccess mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/LICENSE.html mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/adapters/jquery.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/ckeditor.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/ckeditor.php mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/ckeditor_php4.php mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/ckeditor_php5.php mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/config.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/contents.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/images/spacer.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/_languages.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/af.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ar.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/bg.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/bn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/bs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ca.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/da.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/en-au.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/en-ca.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/en-gb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/es.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/et.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/eu.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/fo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/fr-ca.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/gl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/gu.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/hi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/hr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/hu.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/id.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/is.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ja.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ka.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/km.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ko.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/lt.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/lv.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/mk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/mn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ms.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/pl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/pt.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ro.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ru.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/sk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/sl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/sr-latn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/sr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/sv.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/th.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/uk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/vi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/lang/zh.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/dialogs/a11yhelp.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/da.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/gu.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/mk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/ro.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/sk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/vi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/a11yhelp/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/about/dialogs/about.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/about/dialogs/logo_ckeditor.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/adobeair/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/ajax/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/autogrow/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/bbcode/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/clipboard/dialogs/paste.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/colordialog/dialogs/colordialog.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/bg.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/da.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/et.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/gu.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/hr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/pl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/sk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/uk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/vi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/devtools/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/dialog/dialogDefinition.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/div/dialogs/div.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/docprops/dialogs/docprops.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/docprops/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/find/dialogs/find.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/flash/dialogs/flash.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/flash/images/placeholder.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/button.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/checkbox.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/form.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/hiddenfield.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/radio.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/select.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/textarea.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/dialogs/textfield.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/forms/images/hiddenfield.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/iframe/dialogs/iframe.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/iframe/images/placeholder.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/iframedialog/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/image/dialogs/image.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/link/dialogs/anchor.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/link/dialogs/link.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/link/images/anchor.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/liststyle/dialogs/liststyle.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/pagebreak/images/pagebreak.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/pastefromword/filter/default.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/pastetext/dialogs/pastetext.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/dialogs/placeholder.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/bg.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/da.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/et.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/hr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/pl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/sk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/uk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/vi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/placeholder.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/placeholder/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/preview/preview.html mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/scayt/dialogs/options.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/scayt/dialogs/toolbar.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_address.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_blockquote.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_div.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h1.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h2.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h3.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h4.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h5.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_h6.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_p.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/showblocks/images/block_pre.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/dialogs/smiley.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/angel_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/angry_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/broken_heart.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/confused_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/cry_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/devil_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/embaressed_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/envelope.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/heart.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/kiss.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/lightbulb.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/omg_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/regular_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/sad_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/shades_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/teeth_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/thumbs_down.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/thumbs_up.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/tounge_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/whatchutalkingabout_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/smiley/images/wink_smile.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/dialogs/specialchar.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/et.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/hr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/specialchar/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/styles/styles/default.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/stylesheetparser/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/table/dialogs/table.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/tableresize/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/tabletools/dialogs/tableCell.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/templates/dialogs/templates.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/templates/templates/default.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/templates/templates/images/template1.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/templates/templates/images/template2.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/templates/templates/images/template3.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/dialogs/uicolor.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/_translationstatus.txt mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/bg.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/cs.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/cy.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/da.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/de.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/el.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/en.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/eo.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/et.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/fa.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/fi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/fr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/he.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/hr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/it.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/ku.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/mk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/nb.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/nl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/no.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/pl.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/pt-br.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/sk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/tr.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/ug.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/uk.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/vi.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/lang/zh-cn.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/uicolor.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/assets/hue_bg.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/assets/hue_thumb.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/assets/picker_mask.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/assets/picker_thumb.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/assets/yui.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/uicolor/yui/yui.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/wsc/dialogs/ciframe.html mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/wsc/dialogs/tmpFrameset.html mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/wsc/dialogs/wsc.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/wsc/dialogs/wsc.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/plugins/xml/plugin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/dialog.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/editor.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/icons.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/icons_rtl.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/dialog_sides.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/dialog_sides.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/dialog_sides_rtl.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/mini.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/noimage.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/sprites.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/sprites_ie6.png mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/images/toolbar_start.gif mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/skin.js mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/skins/kama/templates.css mode change 100755 => 100644 assets/grocery_crud/texteditor/ckeditor/themes/default/theme.js delete mode 100755 assets/grocery_crud/texteditor/markitup/index.html delete mode 100755 assets/grocery_crud/texteditor/markitup/jquery.markitup.js delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/bold.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/clean.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/image.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/italic.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/link.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/list-bullet.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/list-numeric.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/picture.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/preview.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/images/stroke.png delete mode 100755 assets/grocery_crud/texteditor/markitup/sets/default/style.css delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-container.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-bbcode.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-dotclear.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-html.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-json.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-markdown.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-textile.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-wiki.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor-xml.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/bg-editor.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/handle.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/menu.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/images/submenu.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/markitup/style.css delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/simple/images/handle.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/simple/images/menu.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/simple/images/submenu.png delete mode 100755 assets/grocery_crud/texteditor/markitup/skins/simple/style.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/jquery.tinymce.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/langs/en.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/css/advhr.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/js/rule.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advhr/rule.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/css/advimage.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/image.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/img/sample.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/js/image.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advimage/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/css/advlink.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/js/advlink.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlink/link.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlist/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/advlist/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autolink/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autolink/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autoresize/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autoresize/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autosave/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autosave/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/autosave/langs/en.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/bbcode/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/bbcode/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/contextmenu/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/contextmenu/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/directionality/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/directionality/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/emotions.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-cool.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-cry.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-embarassed.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-foot-in-mouth.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-frown.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-innocent.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-kiss.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-laughing.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-money-mouth.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-sealed.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-smile.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-surprised.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-tongue-out.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-undecided.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-wink.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/img/smiley-yell.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/js/emotions.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/emotions/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/dialog.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/img/example.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/js/dialog.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/langs/en.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example_dependency/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/example_dependency/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/css/fullpage.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/fullpage.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/js/fullpage.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullpage/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullscreen/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullscreen/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/fullscreen/fullscreen.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/iespell/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/iespell/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/alert.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/button.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/buttons.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/confirm.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/corners.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/horizontal.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/vertical.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/skins/clearlooks2/window.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/inlinepopups/template.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/insertdatetime/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/insertdatetime/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/layer/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/layer/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/legacyoutput/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/legacyoutput/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/lists/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/lists/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/css/media.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/js/embed.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/js/media.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/media.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/media/moxieplayer.swf delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/nonbreaking/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/nonbreaking/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/noneditable/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/noneditable/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/pagebreak/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/pagebreak/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/js/pastetext.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/js/pasteword.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/pastetext.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/paste/pasteword.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/preview/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/preview/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/preview/example.html delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/preview/jscripts/embed.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/preview/preview.html delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/print/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/print/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/save/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/save/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/css/searchreplace.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/js/searchreplace.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/searchreplace/searchreplace.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/spellchecker/css/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/spellchecker/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/spellchecker/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/spellchecker/img/wline.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/css/props.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/js/props.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/props.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/style/readme.txt delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/tabfocus/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/tabfocus/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/cell.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/css/cell.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/css/row.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/css/table.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/js/cell.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/js/merge_cells.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/js/row.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/js/table.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/merge_cells.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/row.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/table/table.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/blank.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/css/template.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/js/template.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/template/template.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/visualblocks/css/visualblocks.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/visualblocks/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/visualblocks/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/visualchars/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/visualchars/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/wordcount/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/wordcount/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/abbr.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/acronym.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/attributes.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/cite.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/css/attributes.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/css/popup.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/del.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/editor_plugin.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/editor_plugin_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/ins.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/abbr.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/acronym.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/attributes.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/cite.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/del.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/element_common.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/js/ins.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/plugins/xhtmlxtras/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/about.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/anchor.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/charmap.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/color_picker.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/editor_template.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/editor_template_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/image.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/colorpicker.jpg delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/flash.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/icons.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/iframe.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/pagebreak.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/quicktime.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/realmedia.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/shockwave.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/trans.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/video.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/img/windowsmedia.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/about.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/anchor.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/charmap.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/color_picker.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/image.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/link.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/js/source_editor.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/langs/en.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/langs/en_dlg.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/link.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/shortcuts.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/dialog.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/buttons.png delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/items.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/menu_arrow.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/menu_check.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/progress.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/img/tabs.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/default/ui.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/highcontrast/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/highcontrast/dialog.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/highcontrast/ui.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/dialog.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/img/button_bg.png delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/img/button_bg_black.png delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/img/button_bg_silver.png delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/ui.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/ui_black.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/skins/o2k7/ui_silver.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/advanced/source_editor.htm delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/editor_template.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/editor_template_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/img/icons.gif delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/langs/en.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/skins/default/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/skins/default/ui.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/skins/o2k7/content.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/skins/o2k7/img/button_bg.png delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/themes/simple/skins/o2k7/ui.css delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/tiny_mce.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/tiny_mce_popup.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/tiny_mce_src.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/utils/editable_selects.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/utils/form_utils.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/utils/mctabs.js delete mode 100755 assets/grocery_crud/texteditor/tiny_mce/utils/validate.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/config.php mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/datatables.css mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/demo_table_jui.css mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/images/error.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/images/index.html mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/images/small-loading.gif mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/images/success.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/index.html mode change 100755 => 100644 assets/grocery_crud/themes/datatables/css/jquery.dataTables.css mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/as3/ZeroClipboard.as mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/as3/ZeroClipboardPdf.as mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/as3/lib/AlivePDF.swc mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/css/TableTools.css mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/css/TableTools_JUI.css mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/background.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/collection.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/collection_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/copy.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/copy_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/csv.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/csv_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/pdf.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/pdf_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/print.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/print_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/psd/collection.psd mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/psd/copy document.psd mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/psd/file_types.psd mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/psd/printer.psd mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/xls.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/images/xls_hover.png mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/js/TableTools.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/js/TableTools.min.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/js/TableTools.min.js.gz mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/js/ZeroClipboard.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/swf/copy_csv_xls.swf mode change 100755 => 100644 assets/grocery_crud/themes/datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf mode change 100755 => 100644 assets/grocery_crud/themes/datatables/index.html mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/datatables-add.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/datatables-edit.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/datatables-extras.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/datatables.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/index.html mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/jquery.dataTables.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/js/jquery.dataTables.min.js mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/.htaccess mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/add.php mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/edit.php mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/list.php mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/list_template.php mode change 100755 => 100644 assets/grocery_crud/themes/datatables/views/read.php mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/config.php mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/add.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/bg.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/btn-sprite.gif create mode 100644 assets/grocery_crud/themes/flexigrid/css/images/clone.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/close.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/ddn.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/dn.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/edit.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/error.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/export.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/fhbg.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/first.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/hl.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/index.html mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/last.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/line.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/load.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/load.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/magnifier.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/next.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/prev.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/print.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/success.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/up.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/uup.png mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/images/wbg.gif mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/css/index.html mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/index.html mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/cookies.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/flexigrid-add.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/flexigrid-edit.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/flexigrid.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/index.html mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/jquery.form.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/jquery.printElement.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/js/jquery.printElement.min.js mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/views/.htaccess mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/views/add.php mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/views/edit.php mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/views/list.php mode change 100755 => 100644 assets/grocery_crud/themes/flexigrid/views/read.php mode change 100755 => 100644 assets/grocery_crud/themes/index.html delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/config.php delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/bootstrap-responsive.min.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/bootstrap.min.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/images/loading.gif delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/images/sort_asc.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/images/sort_both.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/images/sort_desc.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_flat_0_aaaaaa_40x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_flat_0_eeeeee_40x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_flat_55_ffffff_40x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_flat_75_ffffff_40x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_glass_65_ffffff_1x400.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_highlight-soft_100_f6f6f6_1x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_highlight-soft_25_0073ea_1x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-bg_highlight-soft_50_dddddd_1x100.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-icons_0073ea_256x240.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-icons_454545_256x240.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-icons_666666_256x240.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-icons_ff0084_256x240.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/images/ui-icons_ffffff_256x240.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/jquery-ui-1.9.2.custom.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/jquery-ui/flick/jquery-ui-1.9.2.custom.min.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/style.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/css/tablesorter.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/img/.gitignore delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/img/glyphicons-halflings-white.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/img/glyphicons-halflings.png delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/README.md delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/app/twitter-bootstrap-add.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/app/twitter-bootstrap-edit.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/app/twitter-bootstrap.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/cookies.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/jquery-ui/jquery-ui-1.9.2.custom.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/jquery-ui/jquery-ui-1.9.2.custom.min.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/jquery.form.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/jquery.functions.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/bootstrap/application.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/bootstrap/bootstrap.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/bootstrap/bootstrap.min.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/google-code-prettify/prettify.css delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/google-code-prettify/prettify.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/modernizr/modernizr-2.6.1.custom.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/print-element/jquery.printElement.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/print-element/jquery.printElement.min.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/requirejs/requirejs.min.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/tablesorter/jquery.tablesorter.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/js/libs/tablesorter/jquery.tablesorter.min.js delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/views/add.php delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/views/edit.php delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/views/list.php delete mode 100755 assets/grocery_crud/themes/twitter-bootstrap/views/list_template.php delete mode 100755 assets/uploads/53c22-Screenshot-from-2015-01-09-12-25-19.png delete mode 100755 assets/uploads/83820-Busuu-Prenium-Membership-1.png delete mode 100755 assets/uploads/files/pdftest.pdf delete mode 100755 assets/uploads/files/test-2.pdf delete mode 100755 assets/uploads/member/10599313_1533509423529598_1553413580880622241_n.jpg delete mode 100755 assets/uploads/member/2d723-screenshot-from-2015-01-09-12_25_19.png delete mode 100755 assets/uploads/member/bdee3-screenshot-from-2015-01-09-12_25_19.png delete mode 100755 assets/uploads/member/e3fa72ba628c04ba6623f2f4da17a6911.jpg delete mode 100755 assets/uploads/member/e8420-user2.jpg delete mode 100755 assets/uploads/thumb__53c22-Screenshot-from-2015-01-09-12-25-19.png delete mode 100755 assets/uploads/thumb__83820-Busuu-Prenium-Membership-1.png delete mode 100755 assets/uploads/video/10406460_652922014788213_8276941645263536198_n.jpg delete mode 100755 assets/uploads/video/10494630_791995804156438_558723157162025499_n.jpg delete mode 100755 assets/uploads/video/10513362_10152954611928294_6014292537106002370_n.png delete mode 100755 assets/uploads/video/10513362_10152954611928294_6014292537106002370_n1.png delete mode 100755 assets/uploads/video/10513362_10152954611928294_6014292537106002370_n2.png delete mode 100755 assets/uploads/video/Screenshot_from_2015-01-09_12_25_19.png delete mode 100755 assets/uploads/video/Screenshot_from_2015-01-09_12_25_191.png delete mode 100755 assets/uploads/video/photo1380581983_858.jpg delete mode 100755 assets/uploads/video/shof_6833924c9eb8e64.jpg delete mode 100755 assets/uploads/video/shof_87bf7393fe81ea3.jpg delete mode 100755 assets/uploads/video/shof_87bf7393fe81ea31.jpg delete mode 100755 assets/uploads/video/shof_87bf7393fe81ea32.jpg delete mode 100755 assets/uploads/video/small.mp4 delete mode 100755 assets/uploads/video/smile.jpg delete mode 100755 assets/uploads/video/smile1.jpg diff --git a/INSTALLATION - INSTRUCTION.txt b/INSTALLATION - INSTRUCTION.txt index 9c09331..1f649ac 100755 --- a/INSTALLATION - INSTRUCTION.txt +++ b/INSTALLATION - INSTRUCTION.txt @@ -1,4 +1,4 @@ -First off, thank you so much for buying pH2Date. +First off, thank you so much for buying pH2Date. Hope you will enjoy your new dating site and we wish you all the best to succeed! Also, we you want to learn and have a professional marketing service specializing in online dating businesses, just have a look to -> http://edatingmarketing.com @@ -6,7 +6,7 @@ Also, we you want to learn and have a professional marketing service specializin 1 - Upload all files to your server (with a FTP client for example, (e.g., FileZilla or WinSCP). -2- Open /application/config/config.php and in the beginning of the file ($config['base_url'] = ''), add the full URL where your site will be installed by ending by a slash "/", then save it. +2- Open /application/config/config.php - In the beginning of the file, replace 'http://YOUR-URL.COM/' to your website URL where your site will be installed by ending with a slash "/", then save it. 3- Open /application/config/database.php and add the details of your database, then save it. @@ -18,7 +18,7 @@ Also, we you want to learn and have a professional marketing service specializin -- Admin Login -- URL: http://your-site.com/admin/ -Email: demo@demo.com +Email: admin@ph2date.com Password: password diff --git a/README.md b/README.md index 3920a6f..e1c7532 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ Available environment modes are: ## Server Requirements -* PHP >= 5.1.6 +* PHP >= 5.6 * Apache 2.2 or 2.4+ with `mod_rewrite` installed and enabled. -* MySQL database (4.1+); MySQLi, MS SQL, Postgres, Oracle, SQLite, and ODBC. +* MySQL database (5.1+); MySQLi, MS SQL, Postgres, Oracle, SQLite, and ODBC. ## Installation diff --git a/application/config/config.php b/application/config/config.php index 033eef9..eb4b52d 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -1,9 +1,11 @@ - '', 'hostname' => 'localhost', - 'username' => '', - 'password' => '', - 'database' => '', + 'username' => 'ph7cms', + 'password' => 'ph7cms', + 'database' => 'ph2date', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, diff --git a/application/config/grocery_crud.php b/application/config/grocery_crud.php old mode 100755 new mode 100644 index 7528fb5..9a09a4f --- a/application/config/grocery_crud.php +++ b/application/config/grocery_crud.php @@ -1,29 +1,39 @@ -_ci_view_paths = array(FCPATH . 'templates/' => true); } - function site_theme($template = '') + public function site_theme($template = '') { if ($template == '') { return false; @@ -25,7 +20,7 @@ function site_theme($template = '') } } - function admin_theme($template = '') + public function admin_theme($template = '') { if ($template == '') { return false; @@ -37,10 +32,15 @@ function admin_theme($template = '') public function view($view, $vars = array(), $return = false) { - if ($this->template != '') { + if ($this->template !== '') { return $this->_ci_load(array('_ci_view' => $this->template . '/' . $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); - } else { - return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); } + + return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); + } + + protected function _ci_object_to_array($object) + { + return is_object($object) ? get_object_vars($object) : $object; } } diff --git a/application/libraries/Grocery_CRUD.php b/application/libraries/Grocery_CRUD.php index 76a585e..9d1686e 100755 --- a/application/libraries/Grocery_CRUD.php +++ b/application/libraries/Grocery_CRUD.php @@ -34,429 +34,429 @@ */ class grocery_CRUD_Field_Types { - /** - * Gets the field types of the main table. - * @return array - */ - public function get_field_types() - { - if ($this->field_types !== null) { - return $this->field_types; - } - - $types = array(); - foreach($this->basic_model->get_field_types_basic_table() as $field_info) - { - $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; - - $field_info->display_as = - isset($this->display_as[$field_info->name]) ? - $this->display_as[$field_info->name] : - ucfirst(str_replace("_"," ",$field_info->name)); - - if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) - { - $field_type = $this->change_field_type[$field_info->name]; - - if (isset($this->relation[$field_info->name])) { - $field_info->crud_type = "relation_".$field_type->type; - } - elseif (isset($this->upload_fields[$field_info->name])) { - $field_info->crud_type = "upload_file_".$field_type->type; - } else { - $field_info->crud_type = $field_type->type; - $field_info->extras = $field_type->extras; - } - - $real_type = $field_info->crud_type; - } - elseif(isset($this->relation[$field_info->name])) - { - $real_type = 'relation'; - $field_info->crud_type = 'relation'; - } - elseif(isset($this->upload_fields[$field_info->name])) - { - $real_type = 'upload_file'; - $field_info->crud_type = 'upload_file'; - } - else - { - $real_type = $this->get_type($field_info); - $field_info->crud_type = $real_type; - } - - switch ($real_type) { - case 'text': - if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) - $field_info->extras = false; - else - $field_info->extras = 'text_editor'; - break; - - case 'relation': - case 'relation_readonly': - $field_info->extras = $this->relation[$field_info->name]; - break; - - case 'upload_file': - case 'upload_file_readonly': - $field_info->extras = $this->upload_fields[$field_info->name]; - break; - - default: - if(empty($field_info->extras)) - $field_info->extras = false; - break; - } - - $types[$field_info->name] = $field_info; - } - - if(!empty($this->relation_n_n)) - { - foreach($this->relation_n_n as $field_name => $field_extras) - { - $is_read_only = $this->change_field_type !== null - && isset($this->change_field_type[$field_name]) - && $this->change_field_type[$field_name]->type == 'readonly' - ? true : false; - $field_info = (object)array(); - $field_info->name = $field_name; - $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; - $field_info->extras = $field_extras; - $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; - $field_info->display_as = - isset($this->display_as[$field_name]) ? - $this->display_as[$field_name] : - ucfirst(str_replace("_"," ",$field_name)); - - $types[$field_name] = $field_info; - } - } - - if(!empty($this->add_fields)) - foreach($this->add_fields as $field_object) - { - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; - - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD - { - $extras = false; - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) - { - $field_type = $this->change_field_type[$field_name]; - $extras = $field_type->extras; - } - - $field_info = (object)array( - 'name' => $field_name, - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? - $this->change_field_type[$field_name]->type : - 'string', - 'display_as' => isset($this->display_as[$field_name]) ? - $this->display_as[$field_name] : - ucfirst(str_replace("_"," ",$field_name)), - 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, - 'extras' => $extras - ); - - $types[$field_name] = $field_info; - } - } - - if(!empty($this->edit_fields)) - foreach($this->edit_fields as $field_object) - { - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; - - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD - { - $extras = false; - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) - { - $field_type = $this->change_field_type[$field_name]; - $extras = $field_type->extras; - } - - $field_info = (object)array( - 'name' => $field_name, - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? - $this->change_field_type[$field_name]->type : - 'string', - 'display_as' => isset($this->display_as[$field_name]) ? - $this->display_as[$field_name] : - ucfirst(str_replace("_"," ",$field_name)), - 'required' => in_array($field_name,$this->required_fields) ? true : false, - 'extras' => $extras - ); - - $types[$field_name] = $field_info; - } - } - - $this->field_types = $types; - - return $this->field_types; - } - - public function get_primary_key() - { - return $this->basic_model->get_primary_key(); - } - - /** - * Get the html input for the specific field with the - * current value - * - * @param object $field_info - * @param string $value - * @return object - */ - protected function get_field_input($field_info, $value = null) - { - $real_type = $field_info->crud_type; - - $types_array = array( - 'integer', - 'text', - 'true_false', - 'string', - 'date', - 'datetime', - 'enum', - 'set', - 'relation', - 'relation_readonly', - 'relation_n_n', - 'upload_file', - 'upload_file_readonly', - 'hidden', - 'password', - 'readonly', - 'dropdown', - 'multiselect' - ); - - if (in_array($real_type,$types_array)) { - /* A quick way to go to an internal method of type $this->get_{type}_input . + /** + * Gets the field types of the main table. + * @return array + */ + public function get_field_types() + { + if ($this->field_types !== null) { + return $this->field_types; + } + + $types = array(); + foreach($this->basic_model->get_field_types_basic_table() as $field_info) + { + $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; + + $field_info->display_as = + isset($this->display_as[$field_info->name]) ? + $this->display_as[$field_info->name] : + ucfirst(str_replace("_"," ",$field_info->name)); + + if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) + { + $field_type = $this->change_field_type[$field_info->name]; + + if (isset($this->relation[$field_info->name])) { + $field_info->crud_type = "relation_".$field_type->type; + } + elseif (isset($this->upload_fields[$field_info->name])) { + $field_info->crud_type = "upload_file_".$field_type->type; + } else { + $field_info->crud_type = $field_type->type; + $field_info->extras = $field_type->extras; + } + + $real_type = $field_info->crud_type; + } + elseif(isset($this->relation[$field_info->name])) + { + $real_type = 'relation'; + $field_info->crud_type = 'relation'; + } + elseif(isset($this->upload_fields[$field_info->name])) + { + $real_type = 'upload_file'; + $field_info->crud_type = 'upload_file'; + } + else + { + $real_type = $this->get_type($field_info); + $field_info->crud_type = $real_type; + } + + switch ($real_type) { + case 'text': + if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) + $field_info->extras = false; + else + $field_info->extras = 'text_editor'; + break; + + case 'relation': + case 'relation_readonly': + $field_info->extras = $this->relation[$field_info->name]; + break; + + case 'upload_file': + case 'upload_file_readonly': + $field_info->extras = $this->upload_fields[$field_info->name]; + break; + + default: + if(empty($field_info->extras)) + $field_info->extras = false; + break; + } + + $types[$field_info->name] = $field_info; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_extras) + { + $is_read_only = $this->change_field_type !== null + && isset($this->change_field_type[$field_name]) + && $this->change_field_type[$field_name]->type == 'readonly' + ? true : false; + $field_info = (object)array(); + $field_info->name = $field_name; + $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; + $field_info->extras = $field_extras; + $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; + $field_info->display_as = + isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)); + + $types[$field_name] = $field_info; + } + } + + if(!empty($this->add_fields)) + foreach($this->add_fields as $field_object) + { + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; + + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD + { + $extras = false; + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) + { + $field_type = $this->change_field_type[$field_name]; + $extras = $field_type->extras; + } + + $field_info = (object)array( + 'name' => $field_name, + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? + $this->change_field_type[$field_name]->type : + 'string', + 'display_as' => isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)), + 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, + 'extras' => $extras + ); + + $types[$field_name] = $field_info; + } + } + + if(!empty($this->edit_fields)) + foreach($this->edit_fields as $field_object) + { + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; + + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD + { + $extras = false; + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) + { + $field_type = $this->change_field_type[$field_name]; + $extras = $field_type->extras; + } + + $field_info = (object)array( + 'name' => $field_name, + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? + $this->change_field_type[$field_name]->type : + 'string', + 'display_as' => isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)), + 'required' => in_array($field_name,$this->required_fields) ? true : false, + 'extras' => $extras + ); + + $types[$field_name] = $field_info; + } + } + + $this->field_types = $types; + + return $this->field_types; + } + + public function get_primary_key() + { + return $this->basic_model->get_primary_key(); + } + + /** + * Get the html input for the specific field with the + * current value + * + * @param object $field_info + * @param string $value + * @return object + */ + protected function get_field_input($field_info, $value = null) + { + $real_type = $field_info->crud_type; + + $types_array = array( + 'integer', + 'text', + 'true_false', + 'string', + 'date', + 'datetime', + 'enum', + 'set', + 'relation', + 'relation_readonly', + 'relation_n_n', + 'upload_file', + 'upload_file_readonly', + 'hidden', + 'password', + 'readonly', + 'dropdown', + 'multiselect' + ); + + if (in_array($real_type,$types_array)) { + /* A quick way to go to an internal method of type $this->get_{type}_input . * For example if the real type is integer then we will use the method * $this->get_integer_input * */ - $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); - } - else - { - $field_info->input = $this->get_string_input($field_info,$value); - } - - return $field_info; - } - - protected function change_list_value($field_info, $value = null) - { - $real_type = $field_info->crud_type; - - switch ($real_type) { - case 'hidden': - case 'invisible': - case 'integer': - - break; - case 'true_false': - if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { - $value = $field_info->extras[$value]; - } else if(isset($this->default_true_false_text[$value])) { - $value = $this->default_true_false_text[$value]; - } - break; - case 'string': - $value = $this->character_limiter($value,$this->character_limiter,"..."); - break; - case 'text': - $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); - break; - case 'date': - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') - { - list($year,$month,$day) = explode("-",$value); - - $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); - } - else - { - $value = ''; - } - break; - case 'datetime': - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') - { - list($year,$month,$day) = explode("-",$value); - list($hours,$minutes) = explode(":",substr($value,11)); - - $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); - } - else - { - $value = ''; - } - break; - case 'enum': - $value = $this->character_limiter($value,$this->character_limiter,"..."); - break; - - case 'multiselect': - $value_as_array = array(); - foreach(explode(",",$value) as $row_value) - { - $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; - } - $value = implode(",",$value_as_array); - break; - - case 'relation_n_n': - $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); - break; - - case 'password': - $value = '******'; - break; - - case 'dropdown': - $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; - break; + $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); + } + else + { + $field_info->input = $this->get_string_input($field_info,$value); + } - case 'upload_file': - if(empty($value)) - { - $value = ""; - } - else - { - $is_image = !empty($value) && - ( substr($value,-4) == '.jpg' - || substr($value,-4) == '.png' - || substr($value,-5) == '.jpeg' - || substr($value,-4) == '.gif' - || substr($value,-5) == '.tiff') - ? true : false; - - $file_url = base_url().$field_info->extras->upload_path."/$value"; - - $file_url_anchor = ''; - } - else - { - $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); - } - $file_url_anchor .= ''; + return $field_info; + } - $value = $file_url_anchor; - } - break; + protected function change_list_value($field_info, $value = null) + { + $real_type = $field_info->crud_type; - default: - $value = $this->character_limiter($value,$this->character_limiter,"..."); - break; - } + switch ($real_type) { + case 'hidden': + case 'invisible': + case 'integer': - return $value; - } + break; + case 'true_false': + if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { + $value = $field_info->extras[$value]; + } else if(isset($this->default_true_false_text[$value])) { + $value = $this->default_true_false_text[$value]; + } + break; + case 'string': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + case 'text': + $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); + break; + case 'date': + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') + { + list($year,$month,$day) = explode("-",$value); + + $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); + } + else + { + $value = ''; + } + break; + case 'datetime': + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') + { + list($year,$month,$day) = explode("-",$value); + list($hours,$minutes) = explode(":",substr($value,11)); + + $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); + } + else + { + $value = ''; + } + break; + case 'enum': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; - /** - * Character Limiter of codeigniter (I just don't want to load the helper ) - * - * Limits the string based on the character count. Preserves complete words - * so the character count may not be exactly as specified. - * - * @access public - * @param string - * @param integer - * @param string the end character. Usually an ellipsis - * @return string - */ - function character_limiter($str, $n = 500, $end_char = '…') - { - if (strlen($str) < $n) - { - return $str; - } + case 'multiselect': + $value_as_array = array(); + foreach(explode(",",$value) as $row_value) + { + $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; + } + $value = implode(",",$value_as_array); + break; - // a bit complicated, but faster than preg_replace with \s+ - $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); + case 'relation_n_n': + $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); + break; - if (strlen($str) <= $n) - { - return $str; - } + case 'password': + $value = '******'; + break; - $out = ''; - foreach (explode(' ', trim($str)) as $val) - { - $out .= $val.' '; + case 'dropdown': + $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; + break; - if (strlen($out) >= $n) - { - $out = trim($out); - return (strlen($out) === strlen($str)) ? $out : $out.$end_char; - } - } - } + case 'upload_file': + if(empty($value)) + { + $value = ""; + } + else + { + $is_image = !empty($value) && + ( substr($value,-4) == '.jpg' + || substr($value,-4) == '.png' + || substr($value,-5) == '.jpeg' + || substr($value,-4) == '.gif' + || substr($value,-5) == '.tiff') + ? true : false; + + $file_url = base_url().$field_info->extras->upload_path."/$value"; + + $file_url_anchor = ''; + } + else + { + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); + } + $file_url_anchor .= ''; + + $value = $file_url_anchor; + } + break; - protected function get_type($db_type) - { - $type = false; - if(!empty($db_type->type)) - { - switch ($db_type->type) { - case '1': - case '3': - case 'int': - case 'tinyint': - case 'mediumint': - case 'longint': - if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) - $type = 'true_false'; - else - $type = 'integer'; - break; - case '254': - case 'string': - case 'enum': - if($db_type->db_type != 'enum') - $type = 'string'; - else - $type = 'enum'; - break; - case 'set': - if($db_type->db_type != 'set') - $type = 'string'; - else - $type = 'set'; - break; - case '252': - case 'blob': - case 'text': - case 'mediumtext': - case 'longtext': - $type = 'text'; - break; - case '10': - case 'date': - $type = 'date'; - break; - case '12': - case 'datetime': - case 'timestamp': - $type = 'datetime'; - break; - } - } - return $type; - } + default: + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + } + + return $value; + } + + /** + * Character Limiter of codeigniter (I just don't want to load the helper ) + * + * Limits the string based on the character count. Preserves complete words + * so the character count may not be exactly as specified. + * + * @access public + * @param string + * @param integer + * @param string the end character. Usually an ellipsis + * @return string + */ + function character_limiter($str, $n = 500, $end_char = '…') + { + if (strlen($str) < $n) + { + return $str; + } + + // a bit complicated, but faster than preg_replace with \s+ + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); + + if (strlen($str) <= $n) + { + return $str; + } + + $out = ''; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + + if (strlen($out) >= $n) + { + $out = trim($out); + return (strlen($out) === strlen($str)) ? $out : $out.$end_char; + } + } + } + + protected function get_type($db_type) + { + $type = false; + if(!empty($db_type->type)) + { + switch ($db_type->type) { + case '1': + case '3': + case 'int': + case 'tinyint': + case 'mediumint': + case 'longint': + if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) + $type = 'true_false'; + else + $type = 'integer'; + break; + case '254': + case 'string': + case 'enum': + if($db_type->db_type != 'enum') + $type = 'string'; + else + $type = 'enum'; + break; + case 'set': + if($db_type->db_type != 'set') + $type = 'string'; + else + $type = 'set'; + break; + case '252': + case 'blob': + case 'text': + case 'mediumtext': + case 'longtext': + $type = 'text'; + break; + case '10': + case 'date': + $type = 'date'; + break; + case '12': + case 'datetime': + case 'timestamp': + $type = 'datetime'; + break; + } + } + return $type; + } } // ------------------------------------------------------------------------ @@ -473,65 +473,65 @@ protected function get_type($db_type) */ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types { - /** - * @var Grocery_crud_model - */ - public $basic_model = null; - - protected function set_default_Model() - { - $ci = &get_instance(); - $ci->load->model('Grocery_crud_model'); - - $this->basic_model = new Grocery_crud_model(); - } - - protected function get_total_results() - { - if(!empty($this->where)) - foreach($this->where as $where) - $this->basic_model->where($where[0],$where[1],$where[2]); - - if(!empty($this->or_where)) - foreach($this->or_where as $or_where) - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); - - if(!empty($this->like)) - foreach($this->like as $like) - $this->basic_model->like($like[0],$like[1],$like[2]); - - if(!empty($this->or_like)) - foreach($this->or_like as $or_like) - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); - - if(!empty($this->having)) - foreach($this->having as $having) - $this->basic_model->having($having[0],$having[1],$having[2]); - - if(!empty($this->or_having)) - foreach($this->or_having as $or_having) - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); - - if(!empty($this->relation)) - foreach($this->relation as $relation) - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); - - if(!empty($this->relation_n_n)) - { - $columns = $this->get_columns(); - foreach($columns as $column) - { - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. - if(isset($this->relation_n_n[$column->field_name])) - { - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); - } - } - - } - - return $this->basic_model->get_total_results(); - } + /** + * @var Grocery_crud_model + */ + public $basic_model = null; + + protected function set_default_Model() + { + $ci = &get_instance(); + $ci->load->model('Grocery_crud_model'); + + $this->basic_model = new Grocery_crud_model(); + } + + protected function get_total_results() + { + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->where($where[0],$where[1],$where[2]); + + if(!empty($this->or_where)) + foreach($this->or_where as $or_where) + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); + + if(!empty($this->like)) + foreach($this->like as $like) + $this->basic_model->like($like[0],$like[1],$like[2]); + + if(!empty($this->or_like)) + foreach($this->or_like as $or_like) + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + + if(!empty($this->having)) + foreach($this->having as $having) + $this->basic_model->having($having[0],$having[1],$having[2]); + + if(!empty($this->or_having)) + foreach($this->or_having as $or_having) + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + + if(!empty($this->relation)) + foreach($this->relation as $relation) + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); + + if(!empty($this->relation_n_n)) + { + $columns = $this->get_columns(); + foreach($columns as $column) + { + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. + if(isset($this->relation_n_n[$column->field_name])) + { + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); + } + } + + } + + return $this->basic_model->get_total_results(); + } protected function filter_data_from_xss($post_data) { foreach ($post_data as $field_name => $rawData) { @@ -542,49 +542,49 @@ protected function filter_data_from_xss($post_data) { return $post_data; } - public function set_model($model_name) - { - $ci = &get_instance(); - $ci->load->model('Grocery_crud_model'); + public function set_model($model_name) + { + $ci = &get_instance(); + $ci->load->model('Grocery_crud_model'); - $ci->load->model($model_name); + $ci->load->model($model_name); - $temp = explode('/',$model_name); - krsort($temp); - foreach($temp as $t) - { - $real_model_name = $t; - break; - } + $temp = explode('/',$model_name); + krsort($temp); + foreach($temp as $t) + { + $real_model_name = $t; + break; + } - $this->basic_model = $ci->$real_model_name; - } + $this->basic_model = $ci->$real_model_name; + } - protected function set_ajax_list_queries($state_info = null) - { + protected function set_ajax_list_queries($state_info = null) + { $field_types = $this->get_field_types(); - if(!empty($state_info->per_page)) - { - if(empty($state_info->page) || !is_numeric($state_info->page) ) - $this->limit($state_info->per_page); - else - { - $limit_page = ( ($state_info->page-1) * $state_info->per_page ); - $this->limit($state_info->per_page, $limit_page); - } - } - - if(!empty($state_info->order_by)) - { - $this->order_by($state_info->order_by[0],$state_info->order_by[1]); - } - - if(isset($state_info->search) && $state_info->search !== '') - { - if (!empty($this->relation)) { - foreach ($this->relation as $relation_name => $relation_values) { - $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); + if(!empty($state_info->per_page)) + { + if(empty($state_info->page) || !is_numeric($state_info->page) ) + $this->limit($state_info->per_page); + else + { + $limit_page = ( ($state_info->page-1) * $state_info->per_page ); + $this->limit($state_info->per_page, $limit_page); + } + } + + if(!empty($state_info->order_by)) + { + $this->order_by($state_info->order_by[0],$state_info->order_by[1]); + } + + if(isset($state_info->search) && $state_info->search !== '') + { + if (!empty($this->relation)) { + foreach ($this->relation as $relation_name => $relation_values) { + $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); } } @@ -618,120 +618,120 @@ protected function set_ajax_list_queries($state_info = null) } } elseif ($state_info->search->field !== null) { - if (isset($temp_relation[$state_info->search->field])) { - if (is_array($temp_relation[$state_info->search->field])) { - foreach ($temp_relation[$state_info->search->field] as $search_field) { - $this->or_like($search_field , $state_info->search->text); + if (isset($temp_relation[$state_info->search->field])) { + if (is_array($temp_relation[$state_info->search->field])) { + foreach ($temp_relation[$state_info->search->field] as $search_field) { + $this->or_like($search_field , $state_info->search->text); } } else { - $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); + $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); } - } elseif(isset($this->relation_n_n[$state_info->search->field])) { - $escaped_text = $this->basic_model->escape_str($state_info->search->text); - $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); - } else { - $this->like($state_info->search->field , $state_info->search->text); - } - } + } elseif(isset($this->relation_n_n[$state_info->search->field])) { + $escaped_text = $this->basic_model->escape_str($state_info->search->text); + $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); + } else { + $this->like($state_info->search->field , $state_info->search->text); + } + } // Search all field - else - { - $columns = $this->get_columns(); + else + { + $columns = $this->get_columns(); - $search_text = $state_info->search->text; + $search_text = $state_info->search->text; - if(!empty($this->where)) - foreach($this->where as $where) - $this->basic_model->having($where[0],$where[1],$where[2]); + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->having($where[0],$where[1],$where[2]); $temp_where_query_array = []; $basic_table = $this->get_table(); - foreach($columns as $column) - { - if(isset($temp_relation[$column->field_name])) - { - if(is_array($temp_relation[$column->field_name])) - { - foreach($temp_relation[$column->field_name] as $search_field) - { + foreach($columns as $column) + { + if(isset($temp_relation[$column->field_name])) + { + if(is_array($temp_relation[$column->field_name])) + { + foreach($temp_relation[$column->field_name] as $search_field) + { $escaped_text = $this->basic_model->escape_str($search_text); $temp_where_query_array[] = $search_field . ' LIKE \'%' . $escaped_text . '%\''; - } - } - else - { + } + } + else + { $escaped_text = $this->basic_model->escape_str($search_text); $temp_where_query_array[] = $temp_relation[$column->field_name] . ' LIKE \'%' . $escaped_text . '%\''; - } - } - elseif(isset($this->relation_n_n[$column->field_name])) - { - //@todo have a where for the relation_n_n statement - } - elseif ( - isset($field_types[$column->field_name]) && + } + } + elseif(isset($this->relation_n_n[$column->field_name])) + { + //@todo have a where for the relation_n_n statement + } + elseif ( + isset($field_types[$column->field_name]) && !in_array($field_types[$column->field_name]->type, array('date', 'datetime', 'timestamp')) ) { $escaped_text = $this->basic_model->escape_str($search_text); $temp_where_query_array[] = '`' . $basic_table . '`.' . $column->field_name . ' LIKE \'%' . $escaped_text . '%\''; - } - } + } + } if (!empty($temp_where_query_array)) { $this->where('(' . implode(' OR ', $temp_where_query_array) . ')', null); } - } - } - } + } + } + } - protected function table_exists($table_name = null) - { - if($this->basic_model->db_table_exists($table_name)) - return true; - return false; - } + protected function table_exists($table_name = null) + { + if($this->basic_model->db_table_exists($table_name)) + return true; + return false; + } - protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) - { - list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; + protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) + { + list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; - if($primary_key_value !== null) - { - $primary_key = $this->basic_model->get_primary_key($related_table); + if($primary_key_value !== null) + { + $primary_key = $this->basic_model->get_primary_key($related_table); - //A where clause with the primary key is enough to take the selected key row - $where_clause = array($primary_key => $primary_key_value); - } + //A where clause with the primary key is enough to take the selected key row + $where_clause = array($primary_key => $primary_key_value); + } - $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); + $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); - return $relation_array; - } + return $relation_array; + } - protected function get_relation_total_rows($relation_info) - { - list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; + protected function get_relation_total_rows($relation_info) + { + list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; - $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); + $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); - return $relation_array; - } + return $relation_array; + } - protected function db_insert_validation() - { - $validation_result = (object)array('success'=>false); + protected function db_insert_validation() + { + $validation_result = (object)array('success'=>false); - $field_types = $this->get_field_types(); - $required_fields = $this->required_fields; - $unique_fields = $this->_unique_fields; - $add_fields = $this->get_add_fields(); + $field_types = $this->get_field_types(); + $required_fields = $this->required_fields; + $unique_fields = $this->_unique_fields; + $add_fields = $this->get_add_fields(); - if(!empty($required_fields)) - { - foreach($add_fields as $add_field) - { - $field_name = $add_field->field_name; + if(!empty($required_fields)) + { + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; // Workaround as Codeigniter set_rules has a bug with array and doesn't work with required fields. // We are basically doing the check here! @@ -741,832 +741,2339 @@ protected function db_insert_validation() $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); } } else if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) { - $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); - } - } - } + $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); + } + } + } + + /** Checking for unique fields. If the field value is not unique then + * return a validation error straight away, if not continue... */ + if(!empty($unique_fields)) + { + $form_validation = $this->form_validation(); + + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; + if(in_array( $field_name, $unique_fields) ) + { + $form_validation->set_rules( $field_name, + $field_types[$field_name]->display_as, + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); + } + } + + if(!$form_validation->run()) + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + + return $validation_result; + } + } + + if(!empty($this->validation_rules)) + { + $form_validation = $this->form_validation(); + + $add_fields = $this->get_add_fields(); + + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; + if(isset($this->validation_rules[$field_name])) + { + $rule = $this->validation_rules[$field_name]; + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules'],$rule['errors']); + } + } + + if($form_validation->run()) + { + $validation_result->success = true; + } + else + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + } + } + else + { + $validation_result->success = true; + } + + return $validation_result; + } + + protected function form_validation() + { + if($this->form_validation === null) + { + $this->form_validation = new grocery_CRUD_Form_validation(); + $ci = &get_instance(); + $ci->load->library('form_validation'); + $ci->form_validation = $this->form_validation; + } + return $this->form_validation; + } + + protected function db_update_validation() + { + $validation_result = (object)array('success'=>false); + + $field_types = $this->get_field_types(); + $required_fields = $this->required_fields; + $unique_fields = $this->_unique_fields; + $edit_fields = $this->get_edit_fields(); + + if(!empty($required_fields)) + { + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; - /** Checking for unique fields. If the field value is not unique then - * return a validation error straight away, if not continue... */ - if(!empty($unique_fields)) - { - $form_validation = $this->form_validation(); + // Workaround as Codeigniter set_rules has a bug with array and doesn't work with required fields. + // We are basically doing the check here! + if (array_key_exists($field_name, $this->relation_n_n) && in_array($field_name, $required_fields)) { + if (!array_key_exists($field_name, $_POST)) { + // This will always throw an error! + $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); + } + } else if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) { + $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); + } + + + } + } + + + /** Checking for unique fields. If the field value is not unique then + * return a validation error straight away, if not continue... */ + if(!empty($unique_fields)) + { + $form_validation = $this->form_validation(); + + $form_validation_check = false; + + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; + if(in_array( $field_name, $unique_fields) ) + { + $state_info = $this->getStateInfo(); + $primary_key = $this->get_primary_key(); + $field_name_value = $_POST[$field_name]; + + $this->basic_model->where($primary_key,$state_info->primary_key); + $row = $this->basic_model->get_row(); + + if(!property_exists($row, $field_name)) { + throw new Exception("The field name doesn't exist in the database. ". + "Please use the unique fields only for fields ". + "that exist in the database"); + } + + $previous_field_name_value = $row->$field_name; + + if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { + $form_validation->set_rules( $field_name, + $field_types[$field_name]->display_as, + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); + + $form_validation_check = true; + } + } + } + + if($form_validation_check && !$form_validation->run()) + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + + return $validation_result; + } + } + + if(!empty($this->validation_rules)) + { + $form_validation = $this->form_validation(); + + $edit_fields = $this->get_edit_fields(); + + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; + if(isset($this->validation_rules[$field_name])) + { + $rule = $this->validation_rules[$field_name]; + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules'],$rule['errors']); + } + } + + if($form_validation->run()) + { + $validation_result->success = true; + } + else + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + } + } + else + { + $validation_result->success = true; + } + + return $validation_result; + } + + protected function db_insert($state_info) + { + $validation_result = $this->db_insert_validation(); + + if($validation_result->success) + { + $post_data = $state_info->unwrapped_data; - foreach($add_fields as $add_field) - { - $field_name = $add_field->field_name; - if(in_array( $field_name, $unique_fields) ) - { - $form_validation->set_rules( $field_name, - $field_types[$field_name]->display_as, - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); - } + if ($this->config->xss_clean) { + $post_data = $this->filter_data_from_xss($post_data); } - if(!$form_validation->run()) - { - $validation_result->error_message = $form_validation->error_string(); - $validation_result->error_fields = $form_validation->_error_array; + $add_fields = $this->get_add_fields(); + + if($this->callback_insert === null) + { + if($this->callback_before_insert !== null) + { + $callback_return = call_user_func($this->callback_before_insert, $post_data); + + if(!empty($callback_return) && is_array($callback_return)) + $post_data = $callback_return; + elseif($callback_return === false) + return false; + } + + $insert_data = array(); + $types = $this->get_field_types(); + foreach($add_fields as $num_row => $field) + { + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) + { + $post_data[$field->field_name] = array(); + } + + if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) + { + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) + { + $insert_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') + { + $insert_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') + { + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') + { + //This empty if statement is to make sure that a readonly field will never inserted/updated + } + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) + { + $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). + substr($post_data[$field->field_name],10); + } + else + { + $insert_data[$field->field_name] = $post_data[$field->field_name]; + } + } + } + + $insert_result = $this->basic_model->db_insert($insert_data); + + if($insert_result !== false) + { + $insert_primary_key = $insert_result; + } + else + { + return false; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; + $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); + } + } + + if($this->callback_after_insert !== null) + { + $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); + + if($callback_return === false) + { + return false; + } + + } + }else + { + $callback_return = call_user_func($this->callback_insert, $post_data); + + if($callback_return === false) + { + return false; + } + } + + if(isset($insert_primary_key)) + return $insert_primary_key; + else + return true; + } + + return false; + + } + + protected function db_update($state_info) + { + $validation_result = $this->db_update_validation(); + + $edit_fields = $this->get_edit_fields(); + + if($validation_result->success) + { + $post_data = $state_info->unwrapped_data; + $primary_key = $state_info->primary_key; - return $validation_result; + if ($this->config->xss_clean) { + $post_data = $this->filter_data_from_xss($post_data); } - } - if(!empty($this->validation_rules)) - { - $form_validation = $this->form_validation(); + if($this->callback_update === null) + { + if($this->callback_before_update !== null) + { + $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); + + if(!empty($callback_return) && is_array($callback_return)) + { + $post_data = $callback_return; + } + elseif($callback_return === false) + { + return false; + } + + } + + $update_data = array(); + $types = $this->get_field_types(); + foreach($edit_fields as $num_row => $field) + { + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) + { + $post_data[$field->field_name] = array(); + } + + if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) + { + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) + { + $update_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') + { + $update_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') + { + $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') + { + //This empty if statement is to make sure that a readonly field will never inserted/updated + } + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) + { + $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ + $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). + substr($post_data[$field->field_name],10); + } + else + { + $update_data[$field->field_name] = $post_data[$field->field_name]; + } + } + } + + if($this->basic_model->db_update($update_data, $primary_key) === false) + { + return false; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + if ( $this->unset_edit_fields !== null + && is_array($this->unset_edit_fields) + && in_array($field_name,$this->unset_edit_fields) + ) { + continue; + } + + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; + $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); + } + } + + if($this->callback_after_update !== null) + { + $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); + + if($callback_return === false) + { + return false; + } + + } + } + else + { + $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); + + if($callback_return === false) + { + return false; + } + } + + return true; + } + else + { + return false; + } + } + + protected function _convert_date_to_sql_date($date) + { + $date = substr($date,0,10); + if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) + { + //If it's already a sql-date don't convert it! + return $date; + }elseif(empty($date)) + { + return ''; + } + + $date_array = preg_split( '/[-\.\/ ]/', $date); + if($this->php_date_format == 'd/m/Y') + { + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); + } + elseif($this->php_date_format == 'm/d/Y') + { + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); + } + else + { + $sql_date = $date; + } + + return $sql_date; + } + + protected function _get_field_names_to_search(array $relation_values) + { + if(!strstr($relation_values[2],'{')) { + return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; + } else { + $relation_values[2] = ' '.$relation_values[2].' '; + $temp1 = explode('{',$relation_values[2]); + unset($temp1[0]); + + $field_names_array = array(); + foreach($temp1 as $field) { + list($field_name) = explode('}',$field); + $field_name = $this->_unique_join_name($relation_values[0]).'.'. $field_name; + $field_names_array[] = $field_name; + } + + return $field_names_array; + } + } - $add_fields = $this->get_add_fields(); + protected function _unique_join_name($field_name) + { + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number + } - foreach($add_fields as $add_field) - { - $field_name = $add_field->field_name; - if(isset($this->validation_rules[$field_name])) - { - $rule = $this->validation_rules[$field_name]; - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules'],$rule['errors']); - } - } + protected function _unique_field_name($field_name) + { + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number + } - if($form_validation->run()) - { - $validation_result->success = true; - } - else - { - $validation_result->error_message = $form_validation->error_string(); - $validation_result->error_fields = $form_validation->_error_array; + protected function db_multiple_delete($state_info) + { + foreach ($state_info->ids as $delete_id) { + $result = $this->db_delete((object)array('primary_key' => $delete_id)); + if (!$result) { + return false; } } - else - { - $validation_result->success = true; - } - return $validation_result; + return true; } - protected function form_validation() + protected function db_delete($state_info) + { + $primary_key_value = $state_info->primary_key; + + if($this->callback_delete === null) + { + if($this->callback_before_delete !== null) + { + $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $this->db_relation_n_n_delete( $field_info, $primary_key_value ); + } + } + + $delete_result = $this->basic_model->db_delete($primary_key_value); + + if($delete_result === false) + { + return false; + } + + if($this->callback_after_delete !== null) + { + $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + + } + } + else + { + $callback_return = call_user_func($this->callback_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + } + + return true; + } + + protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) + { + $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); + } + + protected function db_relation_n_n_delete($field_info, $primary_key_value) + { + $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); + } + + protected function get_list() + { + if(!empty($this->order_by)) + $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); + + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->where($where[0],$where[1],$where[2]); + + if(!empty($this->or_where)) + foreach($this->or_where as $or_where) + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); + + if(!empty($this->like)) + foreach($this->like as $like) + $this->basic_model->like($like[0],$like[1],$like[2]); + + if(!empty($this->or_like)) + foreach($this->or_like as $or_like) + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + + if(!empty($this->having)) + foreach($this->having as $having) + $this->basic_model->having($having[0],$having[1],$having[2]); + + if(!empty($this->or_having)) + foreach($this->or_having as $or_having) + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + + if(!empty($this->relation)) + foreach($this->relation as $relation) + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); + + if(!empty($this->relation_n_n)) + { + $columns = $this->get_columns(); + foreach($columns as $column) + { + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. + if(isset($this->relation_n_n[$column->field_name])) + { + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); + } + } + + } + + if($this->theme_config['crud_paging'] === true) + { + if($this->limit === null) + { + $default_per_page = $this->config->default_per_page; + if(is_numeric($default_per_page) && $default_per_page >1) + { + $this->basic_model->limit($default_per_page); + } + else + { + $this->basic_model->limit(10); + } + } + else + { + $this->basic_model->limit($this->limit[0],$this->limit[1]); + } + } + + $results = $this->basic_model->get_list(); + + return $results; + } + + protected function get_edit_values($primary_key_value) + { + $values = $this->basic_model->get_edit_values($primary_key_value); + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + } + + return $values; + } + + protected function get_clone_values($primary_key_value) { - if($this->form_validation === null) - { - $this->form_validation = new grocery_CRUD_Form_validation(); - $ci = &get_instance(); - $ci->load->library('form_validation'); - $ci->form_validation = $this->form_validation; + $values = $this->basic_model->get_edit_values($primary_key_value); + + $types = $this->get_field_types(); + foreach ($values as $fieldName => $fieldType) { + if ($types[$fieldName . '']->crud_type == 'upload_file') { + $values->$fieldName = ''; + } } - return $this->form_validation; - } - protected function db_update_validation() - { - $validation_result = (object)array('success'=>false); + if(!empty($this->relation_n_n)) { + foreach($this->relation_n_n as $field_name => $field_info) { + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + } - $field_types = $this->get_field_types(); - $required_fields = $this->required_fields; - $unique_fields = $this->_unique_fields; - $edit_fields = $this->get_edit_fields(); + return $values; + } - if(!empty($required_fields)) - { - foreach($edit_fields as $edit_field) - { - $field_name = $edit_field->field_name; - // Workaround as Codeigniter set_rules has a bug with array and doesn't work with required fields. - // We are basically doing the check here! - if (array_key_exists($field_name, $this->relation_n_n) && in_array($field_name, $required_fields)) { - if (!array_key_exists($field_name, $_POST)) { - // This will always throw an error! - $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); - } - } else if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) { - $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); - } + protected function get_relation_n_n_selection_array($primary_key_value, $field_info) + { + return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + + protected function get_relation_n_n_unselected_array($field_info, $selected_values) + { + return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); + } + + protected function set_basic_db_table($table_name = null) + { + $this->basic_model->set_basic_table($table_name); + } + + protected function upload_file($state_info) + { + if(isset($this->upload_fields[$state_info->field_name]) ) + { + if($this->callback_upload === null) + { + if($this->callback_before_upload !== null) + { + $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); + + if($callback_before_upload_response === false) + return false; + elseif(is_string($callback_before_upload_response)) + return $callback_before_upload_response; + } + + $upload_info = $this->upload_fields[$state_info->field_name]; + + header('Pragma: no-cache'); + header('Cache-Control: private, no-cache'); + header('Content-Disposition: inline; filename="files.json"'); + header('X-Content-Type-Options: nosniff'); + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); + header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); + + $allowed_files = $this->config->file_upload_allow_file_types; + + $reg_exp = ''; + if(!empty($upload_info->allowed_file_types)){ + $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; + }else{ + $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; + } + + $max_file_size_ui = $this->config->file_upload_max_file_size; + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); + + $options = array( + 'upload_dir' => $upload_info->upload_path.'/', + 'param_name' => $this->_unique_field_name($state_info->field_name), + 'upload_url' => base_url().$upload_info->upload_path.'/', + 'accept_file_types' => $reg_exp, + 'max_file_size' => $max_file_size_bytes + ); + $upload_handler = new UploadHandler($options); + $upload_handler->default_config_path = $this->default_config_path; + $uploader_response = $upload_handler->post(); + + if(is_array($uploader_response)) + { + foreach($uploader_response as &$response) + { + unset($response->delete_url); + unset($response->delete_type); + } + } + + if($this->callback_after_upload !== null) + { + $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); + + if($callback_after_upload_response === false) + return false; + elseif(is_string($callback_after_upload_response)) + return $callback_after_upload_response; + elseif(is_array($callback_after_upload_response)) + $uploader_response = $callback_after_upload_response; + } + + return $uploader_response; + } + else + { + $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); + + if($upload_response === false) + { + return false; + } + else + { + return $upload_response; + } + } + } + else + { + return false; + } + } + + protected function delete_file($state_info) + { + + if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) + { + $upload_info = $this->upload_fields[$state_info->field_name]; + + if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) + { + if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) + { + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); + + return true; + } + else + { + return false; + } + } + else + { + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); + return true; + } + } + else + { + return false; + } + } + + protected function ajax_relation($state_info) + { + if(!isset($this->relation[$state_info->field_name])) + return false; + + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; + + return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); + } +} - } - } +/** + * PHP grocery CRUD + * + * LICENSE + * + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. + * Please see the corresponding license file for details of these licenses. + * You are free to use, modify and distribute this software, but all copyright information must remain. + * + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @author John Skoumbourdis + */ +// ------------------------------------------------------------------------ - /** Checking for unique fields. If the field value is not unique then - * return a validation error straight away, if not continue... */ - if(!empty($unique_fields)) - { - $form_validation = $this->form_validation(); +/** + * PHP grocery Layout + * + * Here you manage all the HTML Layout + * + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.6.1 + */ +class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver +{ + private $theme_path = null; + private $views_as_string = ''; + private $echo_and_die = false; + protected $theme = null; + protected $default_true_false_text = array('inactive' , 'active'); - $form_validation_check = false; + protected $css_files = array(); + protected $js_files = array(); + protected $js_lib_files = array(); + protected $js_config_files = array(); - foreach($edit_fields as $edit_field) - { - $field_name = $edit_field->field_name; - if(in_array( $field_name, $unique_fields) ) - { - $state_info = $this->getStateInfo(); - $primary_key = $this->get_primary_key(); - $field_name_value = $_POST[$field_name]; + protected function set_basic_Layout() + { + if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) + { + throw new Exception('The template does not exist. Please check your files and try again.', 12); + die(); + } + } - $this->basic_model->where($primary_key,$state_info->primary_key); - $row = $this->basic_model->get_row(); + protected function showList($ajax = false, $state_info = null) + { + $data = $this->get_common_data(); - if(!property_exists($row, $field_name)) { - throw new Exception("The field name doesn't exist in the database. ". - "Please use the unique fields only for fields ". - "that exist in the database"); - } + $data->order_by = $this->order_by; - $previous_field_name_value = $row->$field_name; + $data->types = $this->get_field_types(); - if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { - $form_validation->set_rules( $field_name, - $field_types[$field_name]->display_as, - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); - $form_validation_check = true; - } - } - } + $data->total_results = $this->get_total_results(); - if($form_validation_check && !$form_validation->run()) - { - $validation_result->error_message = $form_validation->error_string(); - $validation_result->error_fields = $form_validation->_error_array; + $data->dialog_forms = $this->config->dialog_forms; + $data->columns = $this->get_columns(); - return $validation_result; - } - } + $data->success_message = $this->get_success_message_at_list($state_info); - if(!empty($this->validation_rules)) - { - $form_validation = $this->form_validation(); + $data->primary_key = $this->get_primary_key(); + $data->add_url = $this->getAddUrl(); + $data->edit_url = $this->getEditUrl(); + $data->clone_url = $this->getCloneUrl(); + $data->delete_url = $this->getDeleteUrl(); + $data->delete_multiple_url = $this->getDeleteMultipleUrl(); + $data->read_url = $this->getReadUrl(); + $data->ajax_list_url = $this->getAjaxListUrl(); + $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); + $data->export_url = $this->getExportToExcelUrl(); + $data->print_url = $this->getPrintUrl(); + $data->actions = $this->actions; + $data->unique_hash = $this->get_method_hash(); + $data->order_by = $this->order_by; + + $data->unset_add = $this->unset_add; + $data->unset_edit = $this->unset_edit; + $data->unset_clone = $this->unset_clone; + $data->unset_read = $this->unset_read; + $data->unset_delete = $this->unset_delete; + $data->unset_export = $this->unset_export; + $data->unset_print = $this->unset_print; + + $default_per_page = $this->config->default_per_page; + $data->paging_options = $this->config->paging_options; + $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; + + if($data->list === false) + { + throw new Exception('It is impossible to get data. Please check your model and try again.', 13); + $data->list = array(); + } + + foreach($data->list as $num_row => $row) + { + $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; + $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->clone_url = $data->clone_url.'/'.$row->{$data->primary_key}; + } - $edit_fields = $this->get_edit_fields(); + if(!$ajax) + { + $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); - foreach($edit_fields as $edit_field) - { - $field_name = $edit_field->field_name; - if(isset($this->validation_rules[$field_name])) - { - $rule = $this->validation_rules[$field_name]; - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules'],$rule['errors']); - } - } + $data->list_view = $this->_theme_view('list.php',$data,true); + $this->_theme_view('list_template.php',$data); + } + else + { + $this->set_echo_and_die(); + $this->_theme_view('list.php',$data); + } - if($form_validation->run()) - { - $validation_result->success = true; - } - else - { - $validation_result->error_message = $form_validation->error_string(); - $validation_result->error_fields = $form_validation->_error_array; - } - } - else - { - $validation_result->success = true; + if (!empty($this->upload_fields)) { + $this->load_js_fancybox(); } + } - return $validation_result; - } + protected function exportToExcel($state_info = null) + { + $data = $this->get_common_data(); - protected function db_insert($state_info) - { - $validation_result = $this->db_insert_validation(); + $data->order_by = $this->order_by; + $data->types = $this->get_field_types(); - if($validation_result->success) - { - $post_data = $state_info->unwrapped_data; + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); - if ($this->config->xss_clean) { - $post_data = $this->filter_data_from_xss($post_data); - } + $data->total_results = $this->get_total_results(); - $add_fields = $this->get_add_fields(); + $data->columns = $this->get_columns(); + $data->primary_key = $this->get_primary_key(); - if($this->callback_insert === null) - { - if($this->callback_before_insert !== null) - { - $callback_return = call_user_func($this->callback_before_insert, $post_data); + @ob_end_clean(); + $this->_export_to_excel($data); + } - if(!empty($callback_return) && is_array($callback_return)) - $post_data = $callback_return; - elseif($callback_return === false) - return false; - } + protected function _export_to_excel($data) + { + /** + * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining + * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. + * */ - $insert_data = array(); - $types = $this->get_field_types(); - foreach($add_fields as $num_row => $field) - { - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) - { - $post_data[$field->field_name] = array(); - } + $string_to_export = ""; + foreach($data->columns as $column){ + $string_to_export .= $column->display_as."\t"; + } + $string_to_export .= "\n"; - if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) - { - if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) - { - $insert_data[$field->field_name] = null; - } - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') - { - $insert_data[$field->field_name] = null; - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') - { - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') - { - //This empty if statement is to make sure that a readonly field will never inserted/updated - } - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) - { - $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). - substr($post_data[$field->field_name],10); - } - else - { - $insert_data[$field->field_name] = $post_data[$field->field_name]; - } - } - } + foreach($data->list as $num_row => $row){ + foreach($data->columns as $column){ + $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; + } + $string_to_export .= "\n"; + } - $insert_result = $this->basic_model->db_insert($insert_data); + // Convert to UTF-16LE and Prepend BOM + $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); - if($insert_result !== false) - { - $insert_primary_key = $insert_result; - } - else - { - return false; - } + $filename = "export-".date("Y-m-d_H:i:s").".xls"; - if(!empty($this->relation_n_n)) - { - foreach($this->relation_n_n as $field_name => $field_info) - { - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; - $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); - } - } + header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); + header('Content-Disposition: attachment; filename='.$filename); + header("Cache-Control: no-cache"); + echo $string_to_export; + die(); + } - if($this->callback_after_insert !== null) - { - $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); + protected function print_webpage($state_info = null) + { + $data = $this->get_common_data(); - if($callback_return === false) - { - return false; - } + $data->order_by = $this->order_by; + $data->types = $this->get_field_types(); - } - }else - { - $callback_return = call_user_func($this->callback_insert, $post_data); + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); - if($callback_return === false) - { - return false; - } - } + $data->total_results = $this->get_total_results(); - if(isset($insert_primary_key)) - return $insert_primary_key; - else - return true; - } + $data->columns = $this->get_columns(); + $data->primary_key = $this->get_primary_key(); - return false; + @ob_end_clean(); + $this->_print_webpage($data); + } - } + protected function _print_webpage($data) + { + $string_to_print = ""; + $string_to_print .= ""; + + echo $string_to_print; + die(); + } + + protected function _trim_export_string($value) + { + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); + return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); + } + + protected function _trim_print_string($value) + { + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); + + //If the value has only spaces and nothing more then add the whitespace html character + if(str_replace(" ","",$value) == "") + $value = " "; + + return strip_tags($value); + } + + protected function set_echo_and_die() + { + $this->echo_and_die = true; + } + + protected function unset_echo_and_die() + { + $this->echo_and_die = false; + } + + protected function showListInfo() + { + $this->set_echo_and_die(); + + $total_results = (int)$this->get_total_results(); + @ob_end_clean(); + echo json_encode(array('total_results' => $total_results)); + die(); + } + + protected function change_list_add_actions($list) + { + if(empty($this->actions)) + return $list; + + $primary_key = $this->get_primary_key(); + + foreach($list as $num_row => $row) + { + $actions_urls = array(); + foreach($this->actions as $unique_id => $action) + { + if(!empty($action->url_callback)) + { + $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); + } + else + { + $actions_urls[$unique_id] = + $action->url_has_http ? + $action->link_url.$row->$primary_key : + site_url($action->link_url.'/'.$row->$primary_key); + } + } + $row->action_urls = $actions_urls; + } + + return $list; + } + + protected function change_list($list,$types) + { + $primary_key = $this->get_primary_key(); + $has_callbacks = !empty($this->callback_column) ? true : false; + $output_columns = $this->get_columns(); + foreach($list as $num_row => $row) + { + foreach($output_columns as $column) + { + $field_name = $column->field_name; + $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; + if( $has_callbacks && isset($this->callback_column[$field_name]) ) + $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); + elseif(isset($types[$field_name])) + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); + else + $list[$num_row]->$field_name = $field_value; + } + } + + return $list; + } + + protected function showAddForm() + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->list_url = $this->getListUrl(); + $data->insert_url = $this->getInsertUrl(); + $data->validation_url = $this->getValidationInsertUrl(); + $data->input_fields = $this->get_add_input_fields(); + + $data->fields = $this->get_add_fields(); + $data->hidden_fields = $this->get_add_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + $data->unique_hash = $this->get_method_hash(); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('add.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } - protected function db_update($state_info) + protected function showCloneForm($state_info) { - $validation_result = $this->db_update_validation(); + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); - $edit_fields = $this->get_edit_fields(); + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); - if($validation_result->success) - { - $post_data = $state_info->unwrapped_data; - $primary_key = $state_info->primary_key; + $data->field_values = $this->get_edit_values($state_info->primary_key); - if ($this->config->xss_clean) { - $post_data = $this->filter_data_from_xss($post_data); - } + $data->add_url = $this->getAddUrl(); + $data->list_url = $this->getListUrl(); + $data->update_url = $this->getInsertUrl(); + $data->delete_url = $this->getDeleteUrl($state_info); + $data->read_url = $this->getReadUrl($state_info->primary_key); + $data->input_fields = $this->get_edit_input_fields($data->field_values); + $data->unique_hash = $this->get_method_hash(); - if($this->callback_update === null) - { - if($this->callback_before_update !== null) - { - $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); + $data->fields = $this->get_edit_fields(); + $data->hidden_fields = $this->get_edit_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; - if(!empty($callback_return) && is_array($callback_return)) - { - $post_data = $callback_return; - } - elseif($callback_return === false) - { - return false; - } + $data->validation_url = $this->getValidationInsertUrl(); + $data->is_ajax = $this->_is_ajax(); - } + $this->_theme_view('edit.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); - $update_data = array(); - $types = $this->get_field_types(); - foreach($edit_fields as $num_row => $field) - { - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) - { - $post_data[$field->field_name] = array(); - } + $this->_get_ajax_results(); + } - if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) - { - if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) - { - $update_data[$field->field_name] = null; - } - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') - { - $update_data[$field->field_name] = null; - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') - { - $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') - { - //This empty if statement is to make sure that a readonly field will never inserted/updated - } - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) - { - $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; - } - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ - $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). - substr($post_data[$field->field_name],10); - } - else - { - $update_data[$field->field_name] = $post_data[$field->field_name]; - } - } - } - if($this->basic_model->db_update($update_data, $primary_key) === false) - { - return false; - } + protected function showEditForm($state_info) + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->field_values = $this->get_edit_values($state_info->primary_key); + + $data->add_url = $this->getAddUrl(); + $data->list_url = $this->getListUrl(); + $data->update_url = $this->getUpdateUrl($state_info); + $data->delete_url = $this->getDeleteUrl($state_info); + $data->read_url = $this->getReadUrl($state_info->primary_key); + $data->input_fields = $this->get_edit_input_fields($data->field_values); + $data->unique_hash = $this->get_method_hash(); + + $data->fields = $this->get_edit_fields(); + $data->hidden_fields = $this->get_edit_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('edit.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } + + protected function showReadForm($state_info) + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->field_values = $this->get_edit_values($state_info->primary_key); + + $data->add_url = $this->getAddUrl(); + + $data->list_url = $this->getListUrl(); + $data->update_url = $this->getUpdateUrl($state_info); + $data->delete_url = $this->getDeleteUrl($state_info); + $data->read_url = $this->getReadUrl($state_info->primary_key); + $data->input_fields = $this->get_read_input_fields($data->field_values); + $data->unique_hash = $this->get_method_hash(); + + $data->fields = $this->get_read_fields(); + $data->hidden_fields = $this->get_edit_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('read.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } + + protected function delete_layout($delete_result = true) + { + @ob_end_clean(); + if($delete_result === false) + { + $error_message = '

    '.$this->l('delete_error_message').'

    '; + + echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); + } + else + { + $success_message = '

    '.$this->l('delete_success_message').'

    '; + + echo json_encode(array('success' => true , 'success_message' => $success_message)); + } + $this->set_echo_and_die(); + } + + protected function get_success_message_at_list($field_info = null) + { + if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) + { + if(!empty($field_info->primary_key) && !$this->unset_edit) + { + return $this->l('insert_success_message')." ".$this->l('form_edit')." {$this->subject} "; + } + else + { + return $this->l('insert_success_message'); + } + } + else + { + return null; + } + } + + protected function insert_layout($insert_result = false) + { + @ob_end_clean(); + if($insert_result === false) + { + echo json_encode(array('success' => false)); + } + else + { + $success_message = '

    '.$this->l('insert_success_message'); + + if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) + { + $success_message .= " ".$this->l('form_edit')." {$this->subject} "; + + if (!$this->_is_ajax()) { + $success_message .= $this->l('form_or'); + } + } + + if(!$this->unset_back_to_list && !$this->_is_ajax()) + { + $success_message .= " ".$this->l('form_go_back_to_list').""; + } + + $success_message .= '

    '; + + echo json_encode(array( + 'success' => true , + 'insert_primary_key' => $insert_result, + 'success_message' => $success_message, + 'success_list_url' => $this->getListSuccessUrl($insert_result) + )); + } + $this->set_echo_and_die(); + } + + protected function validation_layout($validation_result) + { + @ob_end_clean(); + echo json_encode($validation_result); + $this->set_echo_and_die(); + } + + protected function upload_layout($upload_result, $field_name) + { + @ob_end_clean(); + if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) + { + echo json_encode( + (object)array( + 'success' => true, + 'files' => $upload_result + )); + } + else + { + $result = (object)array('success' => false); + if(is_string($upload_result)) + $result->message = $upload_result; + if(!empty($upload_result[0]->error)) + $result->message = $upload_result[0]->error; + + echo json_encode($result); + } + + $this->set_echo_and_die(); + } + + protected function delete_file_layout($upload_result) + { + @ob_end_clean(); + if($upload_result !== false) + { + echo json_encode( (object)array( 'success' => true ) ); + } + else + { + echo json_encode((object)array('success' => false)); + } + + $this->set_echo_and_die(); + } + + public function set_css($css_file) + { + $this->css_files[sha1($css_file)] = base_url().$css_file; + } + + public function set_js($js_file) + { + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function set_js_lib($js_file) + { + $this->js_lib_files[sha1($js_file)] = base_url().$js_file; + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function set_js_config($js_file) + { + $this->js_config_files[sha1($js_file)] = base_url().$js_file; + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function is_IE7() + { + return isset($_SERVER['HTTP_USER_AGENT']) + && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) + ? true : false; + } + + public function get_css_files() + { + return $this->css_files; + } + + public function get_js_files() + { + return $this->js_files; + } + + public function get_js_lib_files() + { + return $this->js_lib_files; + } + + public function get_js_config_files() + { + return $this->js_config_files; + } + + /** + * Load Javascripts + **/ + protected function load_js_fancybox() + { + $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); + } + + protected function load_js_chosen() + { + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); + } + + protected function load_js_jqueryui() + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + } + + protected function load_js_uploader() + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); + } + + protected function get_layout() + { + $js_files = $this->get_js_files(); + $css_files = $this->get_css_files(); + + $js_lib_files = $this->get_js_lib_files(); + $js_config_files = $this->get_js_config_files(); + + if ($this->unset_jquery) { + unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); + } + + if ($this->unset_jquery_ui) { + unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); + unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); + } + + if ($this->unset_bootstrap) { + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); + } + + if($this->echo_and_die === false) + { + /** Initialize JavaScript variables */ + $js_vars = array( + 'default_javascript_path' => base_url().$this->default_javascript_path, + 'default_css_path' => base_url().$this->default_css_path, + 'default_texteditor_path' => base_url().$this->default_texteditor_path, + 'default_theme_path' => base_url().$this->default_theme_path, + 'base_url' => base_url() + ); + $this->_add_js_vars($js_vars); + + return (object)array( + 'js_files' => $js_files, + 'js_lib_files' => $js_lib_files, + 'js_config_files' => $js_config_files, + 'css_files' => $css_files, + 'output' => $this->views_as_string, + ); + } + elseif($this->echo_and_die === true) + { + echo $this->views_as_string; + die(); + } + } + + protected function update_layout($update_result = false, $state_info = null) + { + @ob_end_clean(); + if($update_result === false) + { + echo json_encode(array('success' => $update_result)); + } + else + { + $success_message = '

    '.$this->l('update_success_message'); + if(!$this->unset_back_to_list && !$this->_is_ajax()) + { + $success_message .= " ".$this->l('form_go_back_to_list').""; + } + $success_message .= '

    '; + + echo json_encode(array( + 'success' => true , + 'insert_primary_key' => $update_result, + 'success_message' => $success_message, + 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) + )); + } + $this->set_echo_and_die(); + } + + protected function get_integer_input($field_info,$value) + { + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); + $extra_attributes = ''; + if(!empty($field_info->db_max_length)) + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + $input = ""; + return $input; + } + + protected function get_true_false_input($field_info,$value) + { + $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; + + $input = "
    "; + + $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; + $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; + $input .= + "
    "; - if(!empty($this->relation_n_n)) - { - foreach($this->relation_n_n as $field_name => $field_info) - { - if ( $this->unset_edit_fields !== null - && is_array($this->unset_edit_fields) - && in_array($field_name,$this->unset_edit_fields) - ) { - continue; - } + $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; + $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; + $input .= + "
    "; - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; - $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); - } - } + $input .= "
    "; - if($this->callback_after_update !== null) - { - $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); + return $input; + } - if($callback_return === false) - { - return false; - } + protected function get_string_input($field_info,$value) + { + $value = !is_string($value) ? '' : str_replace('"',""",$value); - } - } - else - { - $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); + $extra_attributes = ''; + if (!empty($field_info->db_max_length)) { - if($callback_return === false) - { - return false; - } - } + if (in_array($field_info->type, array("decimal", "float"))) { + $decimal_lentgh = explode(",", $field_info->db_max_length); + $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; - return true; - } - else - { - return false; - } - } + $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; + } else { + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + } - protected function _convert_date_to_sql_date($date) - { - $date = substr($date,0,10); - if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) - { - //If it's already a sql-date don't convert it! - return $date; - }elseif(empty($date)) - { - return ''; } + $input = ""; + return $input; + } + + protected function get_text_input($field_info,$value) + { + if($field_info->extras == 'text_editor') + { + $editor = $this->config->default_text_editor; + switch ($editor) { + case 'ckeditor': + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); + break; + + case 'tinymce': + $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); + break; + + case 'markitup': + $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); + $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); + + $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); + break; + } + + $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; + + $input = ""; + } + else + { + $input = ""; + } + return $input; + } + + protected function get_datetime_input($field_info,$value) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); + $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + + $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_datetime_js_file)) + { + $this->set_js_lib($i18n_datetime_js_file); + } + } + } + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); + + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ + list($year,$month,$day) = explode('-',substr($value,0,10)); + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); + $datetime = $date.substr($value,10); + } + else + { + $datetime = ''; + } + $input = " + ".$this->l('form_button_clear')." + ({$this->ui_date_format}) hh:mm:ss"; + return $input; + } + + protected function get_hidden_input($field_info,$value) + { + if($field_info->extras !== null && $field_info->extras != false) + $value = $field_info->extras; + $input = ""; + return $input; + } + + protected function get_password_input($field_info,$value) + { + $value = !is_string($value) ? '' : $value; + + $extra_attributes = ''; + if(!empty($field_info->db_max_length)) + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + $input = ""; + return $input; + } + + protected function get_date_input($field_info,$value) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + } + } + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); + + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') + { + list($year,$month,$day) = explode('-',substr($value,0,10)); + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); + } + else + { + $date = ''; + } + + $input = " + ".$this->l('form_button_clear')." (".$this->ui_date_format.")"; + return $input; + } + + protected function get_dropdown_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + + $input = ""; + return $input; + } + + protected function get_enum_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + + $input = ""; + return $input; + } + + protected function get_readonly_input($field_info, $value) + { + $read_only_value = " "; + + if (!empty($value) && !is_array($value)) { + $read_only_value = $value; + } elseif (is_array($value)) { + $all_values = array_values($value); + $read_only_value = implode(", ",$all_values); + } - $date_array = preg_split( '/[-\.\/ ]/', $date); - if($this->php_date_format == 'd/m/Y') - { - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); - } - elseif($this->php_date_format == 'm/d/Y') - { - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); - } - else - { - $sql_date = $date; - } + return '
    '.$read_only_value.'
    '; + } - return $sql_date; - } + protected function get_set_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - protected function _get_field_names_to_search(array $relation_values) - { - if(!strstr($relation_values[2],'{')) { - return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; - } else { - $relation_values[2] = ' '.$relation_values[2].' '; - $temp1 = explode('{',$relation_values[2]); - unset($temp1[0]); - - $field_names_array = array(); - foreach($temp1 as $field) { - list($field_name) = explode('}',$field); - $field_name = $this->_unique_join_name($relation_values[0]).'.'. $field_name; - $field_names_array[] = $field_name; - } + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); + $selected_values = !empty($value) ? explode(",",$value) : array(); - return $field_names_array; - } - } + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; - protected function db_multiple_delete($state_info) - { - foreach ($state_info->ids as $delete_id) { - $result = $this->db_delete((object)array('primary_key' => $delete_id)); - if (!$result) { - return false; - } - } + return $input; + } - return true; - } + protected function get_multiselect_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $options_array = $field_info->extras; + $selected_values = !empty($value) ? explode(",",$value) : array(); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; + + return $input; + } + + protected function get_relation_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $ajax_limitation = 10000; + $total_rows = $this->get_relation_total_rows($field_info->extras); + + + //Check if we will use ajax for our queries or just clien-side javascript + $using_ajax = $total_rows > $ajax_limitation ? true : false; + + //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 + $using_ajax = false; + + //If total rows are more than the limitation, use the ajax plugin + $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; + + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; + return $input; + } + + protected function get_relation_readonly_input($field_info,$value) + { + $options_array = $this->get_relation_array($field_info->extras); + + $value = isset($options_array[$value]) ? $options_array[$value] : ''; + + return $this->get_readonly_input($field_info, $value); + } + + protected function get_upload_file_readonly_input($field_info,$value) + { + $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; + + $value = !empty($value) ? ''.$value.'' : ''; + + return $this->get_readonly_input($field_info, $value); + } + + protected function get_relation_n_n_input($field_info_type, $selected_values) + { + $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; + $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; + + if($has_priority_field || $is_ie_7) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + } + } + } + else + { + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + } + + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); + + $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check + $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); + + if(empty($unselected_values) && empty($selected_values)) + { + $input = "Please add {$field_info_type->display_as} first"; + } + else + { + $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; + $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; + + $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); + $input = ""; + } + + return $input; + } + + protected function _convert_bytes_ui_to_bytes($bytes_ui) + { + $bytes_ui = str_replace(' ','',$bytes_ui); + if(strstr($bytes_ui,'MB')) + $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; + elseif(strstr($bytes_ui,'KB')) + $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; + elseif(strstr($bytes_ui,'B')) + $bytes = (int)(str_replace('B','',$bytes_ui)); + else + $bytes = (int)($bytes_ui); + + return $bytes; + } + + protected function get_upload_file_input($field_info, $value) + { + $this->load_js_uploader(); + + //Fancybox + $this->load_js_fancybox(); + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); + + $unique = mt_rand(); + + $allowed_files = $this->config->file_upload_allow_file_types; + $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); + $max_file_size_ui = $this->config->file_upload_max_file_size; + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); + + $this->_inline_js(' + var upload_info_'.$unique.' = { + accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, + accepted_file_types_ui : "'.$allowed_files_ui.'", + max_file_size: '.$max_file_size_bytes.', + max_file_size_ui: "'.$max_file_size_ui.'" + }; - protected function db_delete($state_info) - { - $primary_key_value = $state_info->primary_key; + var string_upload_file = "'.$this->l('form_upload_a_file').'"; + var string_delete_file = "'.$this->l('string_delete_file').'"; + var string_progress = "'.$this->l('string_progress').'"; + var error_on_uploading = "'.$this->l('error_on_uploading').'"; + var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; - if($this->callback_delete === null) - { - if($this->callback_before_delete !== null) - { - $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); + var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; + var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; + var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; + var error_min_file_size = "'.$this->l('error_min_file_size').'"; - if($callback_return === false) - { - return false; - } - - } - - if(!empty($this->relation_n_n)) - { - foreach($this->relation_n_n as $field_name => $field_info) - { - $this->db_relation_n_n_delete( $field_info, $primary_key_value ); - } - } - - $delete_result = $this->basic_model->db_delete($primary_key_value); - - if($delete_result === false) - { - return false; - } - - if($this->callback_after_delete !== null) - { - $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); - - if($callback_return === false) - { - return false; - } - - } - } - else - { - $callback_return = call_user_func($this->callback_delete, $primary_key_value); - - if($callback_return === false) - { - return false; - } - } - - return true; - } - - protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) - { - $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); - } - - protected function db_relation_n_n_delete($field_info, $primary_key_value) - { - $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); - } - - protected function get_list() - { - if(!empty($this->order_by)) - $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); - - if(!empty($this->where)) - foreach($this->where as $where) - $this->basic_model->where($where[0],$where[1],$where[2]); - - if(!empty($this->or_where)) - foreach($this->or_where as $or_where) - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); - - if(!empty($this->like)) - foreach($this->like as $like) - $this->basic_model->like($like[0],$like[1],$like[2]); - - if(!empty($this->or_like)) - foreach($this->or_like as $or_like) - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); - - if(!empty($this->having)) - foreach($this->having as $having) - $this->basic_model->having($having[0],$having[1],$having[2]); - - if(!empty($this->or_having)) - foreach($this->or_having as $or_having) - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); - - if(!empty($this->relation)) - foreach($this->relation as $relation) - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); - - if(!empty($this->relation_n_n)) - { - $columns = $this->get_columns(); - foreach($columns as $column) - { - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. - if(isset($this->relation_n_n[$column->field_name])) - { - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); - } - } - - } - - if($this->theme_config['crud_paging'] === true) - { - if($this->limit === null) - { - $default_per_page = $this->config->default_per_page; - if(is_numeric($default_per_page) && $default_per_page >1) - { - $this->basic_model->limit($default_per_page); - } - else - { - $this->basic_model->limit(10); - } - } - else - { - $this->basic_model->limit($this->limit[0],$this->limit[1]); - } - } - - $results = $this->basic_model->get_list(); - - return $results; - } - - protected function get_edit_values($primary_key_value) - { - $values = $this->basic_model->get_edit_values($primary_key_value); - - if(!empty($this->relation_n_n)) - { - foreach($this->relation_n_n as $field_name => $field_info) - { - $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); - } - } - - return $values; - } - - protected function get_clone_values($primary_key_value) - { - $values = $this->basic_model->get_edit_values($primary_key_value); - - $types = $this->get_field_types(); - foreach ($values as $fieldName => $fieldType) { - if ($types[$fieldName . '']->crud_type == 'upload_file') { - $values->$fieldName = ''; - } - } - - if(!empty($this->relation_n_n)) { - foreach($this->relation_n_n as $field_name => $field_info) { - $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); - } - } - - return $values; - } - - - protected function get_relation_n_n_selection_array($primary_key_value, $field_info) - { - return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); - } - - protected function get_relation_n_n_unselected_array($field_info, $selected_values) - { - return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); - } - - protected function set_basic_db_table($table_name = null) - { - $this->basic_model->set_basic_table($table_name); - } - - protected function upload_file($state_info) - { - if(isset($this->upload_fields[$state_info->field_name]) ) - { - if($this->callback_upload === null) - { - if($this->callback_before_upload !== null) - { - $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); - - if($callback_before_upload_response === false) - return false; - elseif(is_string($callback_before_upload_response)) - return $callback_before_upload_response; - } - - $upload_info = $this->upload_fields[$state_info->field_name]; - - header('Pragma: no-cache'); - header('Cache-Control: private, no-cache'); - header('Content-Disposition: inline; filename="files.json"'); - header('X-Content-Type-Options: nosniff'); - header('Access-Control-Allow-Origin: *'); - header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); - header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); - - $allowed_files = $this->config->file_upload_allow_file_types; - - $reg_exp = ''; - if(!empty($upload_info->allowed_file_types)){ - $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; - }else{ - $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; - } - - $max_file_size_ui = $this->config->file_upload_max_file_size; - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); - - $options = array( - 'upload_dir' => $upload_info->upload_path.'/', - 'param_name' => $this->_unique_field_name($state_info->field_name), - 'upload_url' => base_url().$upload_info->upload_path.'/', - 'accept_file_types' => $reg_exp, - 'max_file_size' => $max_file_size_bytes - ); - $upload_handler = new UploadHandler($options); - $upload_handler->default_config_path = $this->default_config_path; - $uploader_response = $upload_handler->post(); - - if(is_array($uploader_response)) - { - foreach($uploader_response as &$response) - { - unset($response->delete_url); - unset($response->delete_type); - } - } - - if($this->callback_after_upload !== null) - { - $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); - - if($callback_after_upload_response === false) - return false; - elseif(is_string($callback_after_upload_response)) - return $callback_after_upload_response; - elseif(is_array($callback_after_upload_response)) - $uploader_response = $callback_after_upload_response; - } - - return $uploader_response; - } - else - { - $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); - - if($upload_response === false) - { - return false; - } - else - { - return $upload_response; - } - } - } - else - { - return false; - } - } + var base_url = "'.base_url().'"; + var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; + '); - protected function delete_file($state_info) - { + $uploader_display_none = empty($value) ? "" : "display:none;"; + $file_display_none = empty($value) ? "display:none;" : ""; - if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) - { - $upload_info = $this->upload_fields[$state_info->field_name]; + $is_image = !empty($value) && + ( substr($value,-4) == '.jpg' + || substr($value,-4) == '.png' + || substr($value,-5) == '.jpeg' + || substr($value,-4) == '.gif' + || substr($value,-5) == '.tiff') + ? true : false; - if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) - { - if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) - { - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); + $image_class = $is_image ? 'image-thumbnail' : ''; - return true; - } - else - { - return false; - } - } - else - { - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); - return true; - } - } - else - { - return false; - } - } + $input = ' + '.$this->l('form_upload_a_file').' + + + '; - protected function ajax_relation($state_info) - { - if(!isset($this->relation[$state_info->field_name])) - return false; + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); + + $file_url = base_url().$field_info->extras->upload_path.'/'.$value; + + $input .= "
    "; + $input .= "
    "; + $input .= ""; + $input .= "
    "; + $input .= "
    "; + + return $input; + } + + protected function get_add_hidden_fields() + { + return $this->add_hidden_fields; + } + + protected function get_edit_hidden_fields() + { + return $this->edit_hidden_fields; + } + + protected function get_add_input_fields($field_values = null) + { + $fields = $this->get_add_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + + if(!isset($this->callback_add_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->add_fields[$field_num]); + unset($fields[$field_num]); + break; + case 'hidden': + $this->add_hidden_fields[] = $field_input; + unset($this->add_fields[$field_num]); + unset($fields[$field_num]); + break; + default: + $input_fields[$field->field_name] = $field_input; + break; + } + + + } + + return $input_fields; + } + + protected function get_edit_input_fields($field_values = null) + { + $fields = $this->get_edit_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + if(!isset($this->callback_edit_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->edit_fields[$field_num]); + unset($fields[$field_num]); + break; + case 'hidden': + $this->edit_hidden_fields[] = $field_input; + unset($this->edit_fields[$field_num]); + unset($fields[$field_num]); + break; + default: + $input_fields[$field->field_name] = $field_input; + break; + } + + + } + + return $input_fields; + } + + protected function get_read_input_fields($field_values = null) + { + $read_fields = $this->get_read_fields(); + + $this->field_types = null; + $this->required_fields = null; + + $read_inputs = array(); + foreach ($read_fields as $field) { + if (!empty($this->change_field_type) + && isset($this->change_field_type[$field->field_name]) + && $this->change_field_type[$field->field_name]->type == 'hidden') { + continue; + } + $this->field_type($field->field_name, 'readonly'); + } + + $fields = $this->get_read_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + if(!isset($this->callback_read_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + break; + case 'hidden': + $this->read_hidden_fields[] = $field_input; + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + break; + default: + $input_fields[$field->field_name] = $field_input; + break; - list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; + } - return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); - } + } + + return $input_fields; + } + + protected function setThemeBasics() + { + $this->theme_path = $this->default_theme_path; + if(substr($this->theme_path,-1) != '/') + $this->theme_path = $this->theme_path.'/'; + + include($this->theme_path.$this->theme.'/config.php'); + + $this->theme_config = $config; + } + + public function set_theme($theme = null) + { + $this->theme = $theme; + + return $this; + } + + protected function _get_ajax_results() + { + //This is a $_POST request rather that $_GET request , because + //Codeigniter doesn't like the $_GET requests so much! + if ($this->_is_ajax()) { + @ob_end_clean(); + $results= (object)array( + 'output' => $this->views_as_string, + 'js_files' => array_values($this->get_js_files()), + 'js_lib_files' => array_values($this->get_js_lib_files()), + 'js_config_files' => array_values($this->get_js_config_files()), + 'css_files' => array_values($this->get_css_files()) + ); + + echo json_encode($results); + die; + } + //else just continue + } + + protected function _is_ajax() + { + return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; + } + + protected function _theme_view($view, $vars = array(), $return = FALSE) + { + $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; + + $file_exists = FALSE; + + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.'.php' : $view; + + $view_file = $this->theme_path.$this->theme.'/views/'; + + if (file_exists($view_file.$file)) + { + $path = $view_file.$file; + $file_exists = TRUE; + } + + if ( ! $file_exists) + { + throw new Exception('Unable to load the requested file: '.$file, 16); + } + + extract($vars); + + #region buffering... + ob_start(); + + include($path); + + $buffer = ob_get_contents(); + @ob_end_clean(); + #endregion + + if ($return === TRUE) + { + return $buffer; + } + + $this->views_as_string .= $buffer; + } + + protected function _inline_js($inline_js = '') + { + $this->views_as_string .= "\n"; + } + + protected function _add_js_vars($js_vars = array()) + { + $javascript_as_string = "\n"; + $this->views_as_string .= $javascript_as_string; + } + + protected function get_views_as_string() + { + if(!empty($this->views_as_string)) + return $this->views_as_string; + else + return null; + } } @@ -1589,3234 +3096,1727 @@ protected function ajax_relation($state_info) // ------------------------------------------------------------------------ /** - * PHP grocery Layout + * PHP grocery States * - * Here you manage all the HTML Layout + * States of grocery CRUD * * @package grocery CRUD * @author John Skoumbourdis * @version 1.6.1 */ -class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver +class grocery_CRUD_States extends grocery_CRUD_Layout { - private $theme_path = null; - private $views_as_string = ''; - private $echo_and_die = false; - protected $theme = null; - protected $default_true_false_text = array('inactive' , 'active'); - - protected $css_files = array(); - protected $js_files = array(); - protected $js_lib_files = array(); - protected $js_config_files = array(); - - protected function set_basic_Layout() - { - if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) - { - throw new Exception('The template does not exist. Please check your files and try again.', 12); - die(); - } - } - - protected function showList($ajax = false, $state_info = null) - { - $data = $this->get_common_data(); - - $data->order_by = $this->order_by; + const STATE_UNKNOWN = 0; + const STATE_LIST = 1; + const STATE_ADD = 2; + const STATE_EDIT = 3; + const STATE_DELETE = 4; + const STATE_INSERT = 5; + const STATE_READ = 18; + const STATE_DELETE_MULTIPLE = 19; + const STATE_CLONE = 20; - $data->types = $this->get_field_types(); + protected $states = array( + 0 => 'unknown', + 1 => 'list', + 2 => 'add', + 3 => 'edit', + 4 => 'delete', + 5 => 'insert', + 6 => 'update', + 7 => 'ajax_list', + 8 => 'ajax_list_info', + 9 => 'insert_validation', + 10 => 'update_validation', + 11 => 'upload_file', + 12 => 'delete_file', + 13 => 'ajax_relation', + 14 => 'ajax_relation_n_n', + 15 => 'success', + 16 => 'export', + 17 => 'print', + 18 => 'read', + 19 => 'delete_multiple', + 20 => 'clone' + ); - $data->list = $this->get_list(); - $data->list = $this->change_list($data->list , $data->types); - $data->list = $this->change_list_add_actions($data->list); + public function getStateInfo() + { + $state_code = $this->getStateCode(); + $segment_object = $this->get_state_info_from_url(); - $data->total_results = $this->get_total_results(); + $first_parameter = $segment_object->first_parameter; + $second_parameter = $segment_object->second_parameter; - $data->dialog_forms = $this->config->dialog_forms; - $data->columns = $this->get_columns(); + $state_info = (object)array(); - $data->success_message = $this->get_success_message_at_list($state_info); + switch ($state_code) { + case self::STATE_LIST: + case self::STATE_ADD: + //for now... do nothing! Keeping this switch here in case we need any information at the future. + break; - $data->primary_key = $this->get_primary_key(); - $data->add_url = $this->getAddUrl(); - $data->edit_url = $this->getEditUrl(); - $data->clone_url = $this->getCloneUrl(); - $data->delete_url = $this->getDeleteUrl(); - $data->delete_multiple_url = $this->getDeleteMultipleUrl(); - $data->read_url = $this->getReadUrl(); - $data->ajax_list_url = $this->getAjaxListUrl(); - $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); - $data->export_url = $this->getExportToExcelUrl(); - $data->print_url = $this->getPrintUrl(); - $data->actions = $this->actions; - $data->unique_hash = $this->get_method_hash(); - $data->order_by = $this->order_by; - - $data->unset_add = $this->unset_add; - $data->unset_edit = $this->unset_edit; - $data->unset_clone = $this->unset_clone; - $data->unset_read = $this->unset_read; - $data->unset_delete = $this->unset_delete; - $data->unset_export = $this->unset_export; - $data->unset_print = $this->unset_print; - - $default_per_page = $this->config->default_per_page; - $data->paging_options = $this->config->paging_options; - $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; - - if($data->list === false) - { - throw new Exception('It is impossible to get data. Please check your model and try again.', 13); - $data->list = array(); - } + case self::STATE_EDIT: + case self::STATE_READ: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "edit" the Primary key cannot be null', 6); + die(); + } + break; - foreach($data->list as $num_row => $row) - { - $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; - $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; - $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; - $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; - $data->list[$num_row]->clone_url = $data->clone_url.'/'.$row->{$data->primary_key}; - } + case self::STATE_DELETE: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "delete" the Primary key cannot be null',7); + die(); + } + break; - if(!$ajax) - { - $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); + case self::STATE_DELETE_MULTIPLE: + if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { + $state_info = (object) array('ids' => $_POST['ids']); + } else { + throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); + die(); + } + break; - $data->list_view = $this->_theme_view('list.php',$data,true); - $this->_theme_view('list_template.php',$data); - } - else - { - $this->set_echo_and_die(); - $this->_theme_view('list.php',$data); - } + case self::STATE_CLONE: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "clone" the Primary key cannot be null', 20); + die(); + } + break; - if (!empty($this->upload_fields)) { - $this->load_js_fancybox(); - } - } - - protected function exportToExcel($state_info = null) - { - $data = $this->get_common_data(); - - $data->order_by = $this->order_by; - $data->types = $this->get_field_types(); - - $data->list = $this->get_list(); - $data->list = $this->change_list($data->list , $data->types); - $data->list = $this->change_list_add_actions($data->list); - - $data->total_results = $this->get_total_results(); - - $data->columns = $this->get_columns(); - $data->primary_key = $this->get_primary_key(); - - @ob_end_clean(); - $this->_export_to_excel($data); - } - - protected function _export_to_excel($data) - { - /** - * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining - * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. - * */ - - $string_to_export = ""; - foreach($data->columns as $column){ - $string_to_export .= $column->display_as."\t"; - } - $string_to_export .= "\n"; - - foreach($data->list as $num_row => $row){ - foreach($data->columns as $column){ - $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; - } - $string_to_export .= "\n"; - } - - // Convert to UTF-16LE and Prepend BOM - $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); - - $filename = "export-".date("Y-m-d_H:i:s").".xls"; - - header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); - header('Content-Disposition: attachment; filename='.$filename); - header("Cache-Control: no-cache"); - echo $string_to_export; - die(); - } - - protected function print_webpage($state_info = null) - { - $data = $this->get_common_data(); - - $data->order_by = $this->order_by; - $data->types = $this->get_field_types(); - - $data->list = $this->get_list(); - $data->list = $this->change_list($data->list , $data->types); - $data->list = $this->change_list_add_actions($data->list); - - $data->total_results = $this->get_total_results(); - - $data->columns = $this->get_columns(); - $data->primary_key = $this->get_primary_key(); - - @ob_end_clean(); - $this->_print_webpage($data); - } - - protected function _print_webpage($data) - { - $string_to_print = ""; - $string_to_print .= ""; - - echo $string_to_print; - die(); - } - - protected function _trim_export_string($value) - { - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); - return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); - } - - protected function _trim_print_string($value) - { - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); - - //If the value has only spaces and nothing more then add the whitespace html character - if(str_replace(" ","",$value) == "") - $value = " "; - - return strip_tags($value); - } - - protected function set_echo_and_die() - { - $this->echo_and_die = true; - } - - protected function unset_echo_and_die() - { - $this->echo_and_die = false; - } - - protected function showListInfo() - { - $this->set_echo_and_die(); - - $total_results = (int)$this->get_total_results(); - @ob_end_clean(); - echo json_encode(array('total_results' => $total_results)); - die(); - } - - protected function change_list_add_actions($list) - { - if(empty($this->actions)) - return $list; - - $primary_key = $this->get_primary_key(); - - foreach($list as $num_row => $row) - { - $actions_urls = array(); - foreach($this->actions as $unique_id => $action) - { - if(!empty($action->url_callback)) - { - $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); - } - else - { - $actions_urls[$unique_id] = - $action->url_has_http ? - $action->link_url.$row->$primary_key : - site_url($action->link_url.'/'.$row->$primary_key); - } - } - $row->action_urls = $actions_urls; - } - - return $list; - } - - protected function change_list($list,$types) - { - $primary_key = $this->get_primary_key(); - $has_callbacks = !empty($this->callback_column) ? true : false; - $output_columns = $this->get_columns(); - foreach($list as $num_row => $row) - { - foreach($output_columns as $column) - { - $field_name = $column->field_name; - $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; - if( $has_callbacks && isset($this->callback_column[$field_name]) ) - $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); - elseif(isset($types[$field_name])) - $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); - else - $list[$num_row]->$field_name = $field_value; - } - } - - return $list; - } - - protected function showAddForm() - { - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); - - $data = $this->get_common_data(); - $data->types = $this->get_field_types(); - - $data->list_url = $this->getListUrl(); - $data->insert_url = $this->getInsertUrl(); - $data->validation_url = $this->getValidationInsertUrl(); - $data->input_fields = $this->get_add_input_fields(); - - $data->fields = $this->get_add_fields(); - $data->hidden_fields = $this->get_add_hidden_fields(); - $data->unset_back_to_list = $this->unset_back_to_list; - $data->unique_hash = $this->get_method_hash(); - $data->is_ajax = $this->_is_ajax(); - - $this->_theme_view('add.php',$data); - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); - - $this->_get_ajax_results(); - } - - protected function showCloneForm($state_info) - { - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); - - $data = $this->get_common_data(); - $data->types = $this->get_field_types(); - - $data->field_values = $this->get_edit_values($state_info->primary_key); - - $data->add_url = $this->getAddUrl(); - $data->list_url = $this->getListUrl(); - $data->update_url = $this->getInsertUrl(); - $data->delete_url = $this->getDeleteUrl($state_info); - $data->read_url = $this->getReadUrl($state_info->primary_key); - $data->input_fields = $this->get_edit_input_fields($data->field_values); - $data->unique_hash = $this->get_method_hash(); - - $data->fields = $this->get_edit_fields(); - $data->hidden_fields = $this->get_edit_hidden_fields(); - $data->unset_back_to_list = $this->unset_back_to_list; - - $data->validation_url = $this->getValidationInsertUrl(); - $data->is_ajax = $this->_is_ajax(); - - $this->_theme_view('edit.php',$data); - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); - - $this->_get_ajax_results(); - } - - - protected function showEditForm($state_info) - { - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); - - $data = $this->get_common_data(); - $data->types = $this->get_field_types(); - - $data->field_values = $this->get_edit_values($state_info->primary_key); - - $data->add_url = $this->getAddUrl(); - $data->list_url = $this->getListUrl(); - $data->update_url = $this->getUpdateUrl($state_info); - $data->delete_url = $this->getDeleteUrl($state_info); - $data->read_url = $this->getReadUrl($state_info->primary_key); - $data->input_fields = $this->get_edit_input_fields($data->field_values); - $data->unique_hash = $this->get_method_hash(); - - $data->fields = $this->get_edit_fields(); - $data->hidden_fields = $this->get_edit_hidden_fields(); - $data->unset_back_to_list = $this->unset_back_to_list; - - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); - $data->is_ajax = $this->_is_ajax(); - - $this->_theme_view('edit.php',$data); - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); - - $this->_get_ajax_results(); - } - - protected function showReadForm($state_info) - { - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); - - $data = $this->get_common_data(); - $data->types = $this->get_field_types(); - - $data->field_values = $this->get_edit_values($state_info->primary_key); - - $data->add_url = $this->getAddUrl(); - - $data->list_url = $this->getListUrl(); - $data->update_url = $this->getUpdateUrl($state_info); - $data->delete_url = $this->getDeleteUrl($state_info); - $data->read_url = $this->getReadUrl($state_info->primary_key); - $data->input_fields = $this->get_read_input_fields($data->field_values); - $data->unique_hash = $this->get_method_hash(); - - $data->fields = $this->get_read_fields(); - $data->hidden_fields = $this->get_edit_hidden_fields(); - $data->unset_back_to_list = $this->unset_back_to_list; - - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); - $data->is_ajax = $this->_is_ajax(); - - $this->_theme_view('read.php',$data); - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); - - $this->_get_ajax_results(); - } - - protected function delete_layout($delete_result = true) - { - @ob_end_clean(); - if($delete_result === false) - { - $error_message = '

    '.$this->l('delete_error_message').'

    '; - - echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); - } - else - { - $success_message = '

    '.$this->l('delete_success_message').'

    '; - - echo json_encode(array('success' => true , 'success_message' => $success_message)); - } - $this->set_echo_and_die(); - } - - protected function get_success_message_at_list($field_info = null) - { - if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) - { - if(!empty($field_info->primary_key) && !$this->unset_edit) - { - return $this->l('insert_success_message')." ".$this->l('form_edit')." {$this->subject} "; - } - else - { - return $this->l('insert_success_message'); - } - } - else - { - return null; - } - } - - protected function insert_layout($insert_result = false) - { - @ob_end_clean(); - if($insert_result === false) - { - echo json_encode(array('success' => false)); - } - else - { - $success_message = '

    '.$this->l('insert_success_message'); - - if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) - { - $success_message .= " ".$this->l('form_edit')." {$this->subject} "; - - if (!$this->_is_ajax()) { - $success_message .= $this->l('form_or'); - } - } - - if(!$this->unset_back_to_list && !$this->_is_ajax()) - { - $success_message .= " ".$this->l('form_go_back_to_list').""; - } - - $success_message .= '

    '; - - echo json_encode(array( - 'success' => true , - 'insert_primary_key' => $insert_result, - 'success_message' => $success_message, - 'success_list_url' => $this->getListSuccessUrl($insert_result) - )); - } - $this->set_echo_and_die(); - } - - protected function validation_layout($validation_result) - { - @ob_end_clean(); - echo json_encode($validation_result); - $this->set_echo_and_die(); - } - - protected function upload_layout($upload_result, $field_name) - { - @ob_end_clean(); - if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) - { - echo json_encode( - (object)array( - 'success' => true, - 'files' => $upload_result - )); - } - else - { - $result = (object)array('success' => false); - if(is_string($upload_result)) - $result->message = $upload_result; - if(!empty($upload_result[0]->error)) - $result->message = $upload_result[0]->error; - - echo json_encode($result); - } - - $this->set_echo_and_die(); - } - - protected function delete_file_layout($upload_result) - { - @ob_end_clean(); - if($upload_result !== false) - { - echo json_encode( (object)array( 'success' => true ) ); - } - else - { - echo json_encode((object)array('success' => false)); - } - - $this->set_echo_and_die(); - } - - public function set_css($css_file) - { - $this->css_files[sha1($css_file)] = base_url().$css_file; - } - - public function set_js($js_file) - { - $this->js_files[sha1($js_file)] = base_url().$js_file; - } - - public function set_js_lib($js_file) - { - $this->js_lib_files[sha1($js_file)] = base_url().$js_file; - $this->js_files[sha1($js_file)] = base_url().$js_file; - } - - public function set_js_config($js_file) - { - $this->js_config_files[sha1($js_file)] = base_url().$js_file; - $this->js_files[sha1($js_file)] = base_url().$js_file; - } - - public function is_IE7() - { - return isset($_SERVER['HTTP_USER_AGENT']) - && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) - ? true : false; - } - - public function get_css_files() - { - return $this->css_files; - } - - public function get_js_files() - { - return $this->js_files; - } - - public function get_js_lib_files() - { - return $this->js_lib_files; - } - - public function get_js_config_files() - { - return $this->js_config_files; - } - - /** - * Load Javascripts - **/ - protected function load_js_fancybox() - { - $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); - - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); - } - - protected function load_js_chosen() - { - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); - } - - protected function load_js_jqueryui() - { - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); - } - - protected function load_js_uploader() - { - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); - - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); - - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); - } - - protected function get_layout() - { - $js_files = $this->get_js_files(); - $css_files = $this->get_css_files(); - - $js_lib_files = $this->get_js_lib_files(); - $js_config_files = $this->get_js_config_files(); - - if ($this->unset_jquery) { - unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); - } - - if ($this->unset_jquery_ui) { - unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); - unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); - } - - if ($this->unset_bootstrap) { - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); - } - - if($this->echo_and_die === false) - { - /** Initialize JavaScript variables */ - $js_vars = array( - 'default_javascript_path' => base_url().$this->default_javascript_path, - 'default_css_path' => base_url().$this->default_css_path, - 'default_texteditor_path' => base_url().$this->default_texteditor_path, - 'default_theme_path' => base_url().$this->default_theme_path, - 'base_url' => base_url() - ); - $this->_add_js_vars($js_vars); - - return (object)array( - 'js_files' => $js_files, - 'js_lib_files' => $js_lib_files, - 'js_config_files' => $js_config_files, - 'css_files' => $css_files, - 'output' => $this->views_as_string, - ); - } - elseif($this->echo_and_die === true) - { - echo $this->views_as_string; - die(); - } - } - - protected function update_layout($update_result = false, $state_info = null) - { - @ob_end_clean(); - if($update_result === false) - { - echo json_encode(array('success' => $update_result)); - } - else - { - $success_message = '

    '.$this->l('update_success_message'); - if(!$this->unset_back_to_list && !$this->_is_ajax()) - { - $success_message .= " ".$this->l('form_go_back_to_list').""; - } - $success_message .= '

    '; - - echo json_encode(array( - 'success' => true , - 'insert_primary_key' => $update_result, - 'success_message' => $success_message, - 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) - )); - } - $this->set_echo_and_die(); - } - - protected function get_integer_input($field_info,$value) - { - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); - $extra_attributes = ''; - if(!empty($field_info->db_max_length)) - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; - $input = ""; - return $input; - } - - protected function get_true_false_input($field_info,$value) - { - $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; - - $input = "
    "; - - $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; - $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; - $input .= - "
    "; - - $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; - $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; - $input .= - "
    "; - - $input .= "
    "; - - return $input; - } - - protected function get_string_input($field_info,$value) - { - $value = !is_string($value) ? '' : str_replace('"',""",$value); - - $extra_attributes = ''; - if (!empty($field_info->db_max_length)) { - - if (in_array($field_info->type, array("decimal", "float"))) { - $decimal_lentgh = explode(",", $field_info->db_max_length); - $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; - - $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; - } else { - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; - } - - } - $input = ""; - return $input; - } - - protected function get_text_input($field_info,$value) - { - if($field_info->extras == 'text_editor') - { - $editor = $this->config->default_text_editor; - switch ($editor) { - case 'ckeditor': - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); - break; - - case 'tinymce': - $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); - break; - - case 'markitup': - $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); - $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); - - $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); - break; - } - - $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; - - $input = ""; - } - else - { - $input = ""; - } - return $input; - } - - protected function get_datetime_input($field_info,$value) - { - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); - $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); - $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); - - if($this->language !== 'english') - { - include($this->default_config_path.'/language_alias.php'); - if(array_key_exists($this->language, $language_alias)) - { - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; - if(file_exists($i18n_date_js_file)) - { - $this->set_js_lib($i18n_date_js_file); - } - - $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; - if(file_exists($i18n_datetime_js_file)) - { - $this->set_js_lib($i18n_datetime_js_file); - } - } - } - - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); - - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ - list($year,$month,$day) = explode('-',substr($value,0,10)); - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); - $datetime = $date.substr($value,10); - } - else - { - $datetime = ''; - } - $input = " - ".$this->l('form_button_clear')." - ({$this->ui_date_format}) hh:mm:ss"; - return $input; - } - - protected function get_hidden_input($field_info,$value) - { - if($field_info->extras !== null && $field_info->extras != false) - $value = $field_info->extras; - $input = ""; - return $input; - } - - protected function get_password_input($field_info,$value) - { - $value = !is_string($value) ? '' : $value; - - $extra_attributes = ''; - if(!empty($field_info->db_max_length)) - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; - $input = ""; - return $input; - } - - protected function get_date_input($field_info,$value) - { - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); - - if($this->language !== 'english') - { - include($this->default_config_path.'/language_alias.php'); - if(array_key_exists($this->language, $language_alias)) - { - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; - if(file_exists($i18n_date_js_file)) - { - $this->set_js_lib($i18n_date_js_file); - } - } - } - - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); - - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') - { - list($year,$month,$day) = explode('-',substr($value,0,10)); - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); - } - else - { - $date = ''; - } - - $input = " - ".$this->l('form_button_clear')." (".$this->ui_date_format.")"; - return $input; - } - - protected function get_dropdown_input($field_info,$value) - { - $this->load_js_chosen(); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); - - $input = ""; - return $input; - } - - protected function get_enum_input($field_info,$value) - { - $this->load_js_chosen(); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); - - $input = ""; - return $input; - } - - protected function get_readonly_input($field_info, $value) - { - $read_only_value = " "; - - if (!empty($value) && !is_array($value)) { - $read_only_value = $value; - } elseif (is_array($value)) { - $all_values = array_values($value); - $read_only_value = implode(", ",$all_values); - } - - return '
    '.$read_only_value.'
    '; - } - - protected function get_set_input($field_info,$value) - { - $this->load_js_chosen(); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); - $selected_values = !empty($value) ? explode(",",$value) : array(); - - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); - $input = ""; - - return $input; - } - - protected function get_multiselect_input($field_info,$value) - { - $this->load_js_chosen(); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - - $options_array = $field_info->extras; - $selected_values = !empty($value) ? explode(",",$value) : array(); - - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); - $input = ""; - - return $input; - } - - protected function get_relation_input($field_info,$value) - { - $this->load_js_chosen(); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - - $ajax_limitation = 10000; - $total_rows = $this->get_relation_total_rows($field_info->extras); - - - //Check if we will use ajax for our queries or just clien-side javascript - $using_ajax = $total_rows > $ajax_limitation ? true : false; - - //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 - $using_ajax = false; - - //If total rows are more than the limitation, use the ajax plugin - $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; - - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); - - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); - $input = ""; - return $input; - } - - protected function get_relation_readonly_input($field_info,$value) - { - $options_array = $this->get_relation_array($field_info->extras); - - $value = isset($options_array[$value]) ? $options_array[$value] : ''; - - return $this->get_readonly_input($field_info, $value); - } - - protected function get_upload_file_readonly_input($field_info,$value) - { - $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; - - $value = !empty($value) ? ''.$value.'' : ''; - - return $this->get_readonly_input($field_info, $value); - } - - protected function get_relation_n_n_input($field_info_type, $selected_values) - { - $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; - $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; - - if($has_priority_field || $is_ie_7) - { - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); - $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); - - if($this->language !== 'english') - { - include($this->default_config_path.'/language_alias.php'); - if(array_key_exists($this->language, $language_alias)) - { - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; - if(file_exists($i18n_date_js_file)) - { - $this->set_js_lib($i18n_date_js_file); - } - } - } - } - else - { - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); - } - - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); - - $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check - $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); - - if(empty($unselected_values) && empty($selected_values)) - { - $input = "Please add {$field_info_type->display_as} first"; - } - else - { - $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; - $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; - - $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); - $input = ""; - } - - return $input; - } - - protected function _convert_bytes_ui_to_bytes($bytes_ui) - { - $bytes_ui = str_replace(' ','',$bytes_ui); - if(strstr($bytes_ui,'MB')) - $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; - elseif(strstr($bytes_ui,'KB')) - $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; - elseif(strstr($bytes_ui,'B')) - $bytes = (int)(str_replace('B','',$bytes_ui)); - else - $bytes = (int)($bytes_ui); - - return $bytes; - } - - protected function get_upload_file_input($field_info, $value) - { - $this->load_js_uploader(); - - //Fancybox - $this->load_js_fancybox(); - - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); - - $unique = mt_rand(); - - $allowed_files = $this->config->file_upload_allow_file_types; - $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); - $max_file_size_ui = $this->config->file_upload_max_file_size; - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); - - $this->_inline_js(' - var upload_info_'.$unique.' = { - accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, - accepted_file_types_ui : "'.$allowed_files_ui.'", - max_file_size: '.$max_file_size_bytes.', - max_file_size_ui: "'.$max_file_size_ui.'" - }; - - var string_upload_file = "'.$this->l('form_upload_a_file').'"; - var string_delete_file = "'.$this->l('string_delete_file').'"; - var string_progress = "'.$this->l('string_progress').'"; - var error_on_uploading = "'.$this->l('error_on_uploading').'"; - var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; - - var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; - var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; - var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; - var error_min_file_size = "'.$this->l('error_min_file_size').'"; - - var base_url = "'.base_url().'"; - var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; - '); - - $uploader_display_none = empty($value) ? "" : "display:none;"; - $file_display_none = empty($value) ? "display:none;" : ""; - - $is_image = !empty($value) && - ( substr($value,-4) == '.jpg' - || substr($value,-4) == '.png' - || substr($value,-5) == '.jpeg' - || substr($value,-4) == '.gif' - || substr($value,-5) == '.tiff') - ? true : false; - - $image_class = $is_image ? 'image-thumbnail' : ''; - - $input = ' - '.$this->l('form_upload_a_file').' - - - '; - - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); - - $file_url = base_url().$field_info->extras->upload_path.'/'.$value; - - $input .= "
    "; - $input .= "
    "; - $input .= ""; - $input .= "
    "; - $input .= "
    "; - - return $input; - } - - protected function get_add_hidden_fields() - { - return $this->add_hidden_fields; - } - - protected function get_edit_hidden_fields() - { - return $this->edit_hidden_fields; - } - - protected function get_add_input_fields($field_values = null) - { - $fields = $this->get_add_fields(); - $types = $this->get_field_types(); - - $input_fields = array(); - - foreach($fields as $field_num => $field) - { - $field_info = $types[$field->field_name]; - - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; - - if(!isset($this->callback_add_field[$field->field_name])) - { - $field_input = $this->get_field_input($field_info, $field_value); - } - else - { - $field_input = $field_info; - $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); - } - - switch ($field_info->crud_type) { - case 'invisible': - unset($this->add_fields[$field_num]); - unset($fields[$field_num]); - break; - case 'hidden': - $this->add_hidden_fields[] = $field_input; - unset($this->add_fields[$field_num]); - unset($fields[$field_num]); - break; - default: - $input_fields[$field->field_name] = $field_input; - break; - } - - - } - - return $input_fields; - } - - protected function get_edit_input_fields($field_values = null) - { - $fields = $this->get_edit_fields(); - $types = $this->get_field_types(); - - $input_fields = array(); - - foreach($fields as $field_num => $field) - { - $field_info = $types[$field->field_name]; - - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; - if(!isset($this->callback_edit_field[$field->field_name])) - { - $field_input = $this->get_field_input($field_info, $field_value); - } - else - { - $primary_key = $this->getStateInfo()->primary_key; - $field_input = $field_info; - $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); - } - - switch ($field_info->crud_type) { - case 'invisible': - unset($this->edit_fields[$field_num]); - unset($fields[$field_num]); - break; - case 'hidden': - $this->edit_hidden_fields[] = $field_input; - unset($this->edit_fields[$field_num]); - unset($fields[$field_num]); - break; - default: - $input_fields[$field->field_name] = $field_input; - break; - } - - - } - - return $input_fields; - } - - protected function get_read_input_fields($field_values = null) - { - $read_fields = $this->get_read_fields(); - - $this->field_types = null; - $this->required_fields = null; - - $read_inputs = array(); - foreach ($read_fields as $field) { - if (!empty($this->change_field_type) - && isset($this->change_field_type[$field->field_name]) - && $this->change_field_type[$field->field_name]->type == 'hidden') { - continue; - } - $this->field_type($field->field_name, 'readonly'); - } - - $fields = $this->get_read_fields(); - $types = $this->get_field_types(); - - $input_fields = array(); - - foreach($fields as $field_num => $field) - { - $field_info = $types[$field->field_name]; - - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; - if(!isset($this->callback_read_field[$field->field_name])) - { - $field_input = $this->get_field_input($field_info, $field_value); - } - else - { - $primary_key = $this->getStateInfo()->primary_key; - $field_input = $field_info; - $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); - } - - switch ($field_info->crud_type) { - case 'invisible': - unset($this->read_fields[$field_num]); - unset($fields[$field_num]); - break; - case 'hidden': - $this->read_hidden_fields[] = $field_input; - unset($this->read_fields[$field_num]); - unset($fields[$field_num]); - break; - default: - $input_fields[$field->field_name] = $field_input; - break; - - } - - } - - return $input_fields; - } - - protected function setThemeBasics() - { - $this->theme_path = $this->default_theme_path; - if(substr($this->theme_path,-1) != '/') - $this->theme_path = $this->theme_path.'/'; - - include($this->theme_path.$this->theme.'/config.php'); - - $this->theme_config = $config; - } - - public function set_theme($theme = null) - { - $this->theme = $theme; - - return $this; - } - - protected function _get_ajax_results() - { - //This is a $_POST request rather that $_GET request , because - //Codeigniter doesn't like the $_GET requests so much! - if ($this->_is_ajax()) { - @ob_end_clean(); - $results= (object)array( - 'output' => $this->views_as_string, - 'js_files' => array_values($this->get_js_files()), - 'js_lib_files' => array_values($this->get_js_lib_files()), - 'js_config_files' => array_values($this->get_js_config_files()), - 'css_files' => array_values($this->get_css_files()) - ); - - echo json_encode($results); - die; - } - //else just continue - } - - protected function _is_ajax() - { - return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; - } - - protected function _theme_view($view, $vars = array(), $return = FALSE) - { - $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; - - $file_exists = FALSE; - - $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.'.php' : $view; - - $view_file = $this->theme_path.$this->theme.'/views/'; - - if (file_exists($view_file.$file)) - { - $path = $view_file.$file; - $file_exists = TRUE; - } - - if ( ! $file_exists) - { - throw new Exception('Unable to load the requested file: '.$file, 16); - } - - extract($vars); - - #region buffering... - ob_start(); - - include($path); - - $buffer = ob_get_contents(); - @ob_end_clean(); - #endregion - - if ($return === TRUE) - { - return $buffer; - } - - $this->views_as_string .= $buffer; - } - - protected function _inline_js($inline_js = '') - { - $this->views_as_string .= "\n"; - } - - protected function _add_js_vars($js_vars = array()) - { - $javascript_as_string = "\n"; - $this->views_as_string .= $javascript_as_string; - } - - protected function get_views_as_string() - { - if(!empty($this->views_as_string)) - return $this->views_as_string; - else - return null; - } -} - - -/** - * PHP grocery CRUD - * - * LICENSE - * - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. - * Please see the corresponding license file for details of these licenses. - * You are free to use, modify and distribute this software, but all copyright information must remain. - * - * @package grocery CRUD - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @author John Skoumbourdis - */ - -// ------------------------------------------------------------------------ - -/** - * PHP grocery States - * - * States of grocery CRUD - * - * @package grocery CRUD - * @author John Skoumbourdis - * @version 1.6.1 - */ -class grocery_CRUD_States extends grocery_CRUD_Layout -{ - const STATE_UNKNOWN = 0; - const STATE_LIST = 1; - const STATE_ADD = 2; - const STATE_EDIT = 3; - const STATE_DELETE = 4; - const STATE_INSERT = 5; - const STATE_READ = 18; - const STATE_DELETE_MULTIPLE = 19; - const STATE_CLONE = 20; - - protected $states = array( - 0 => 'unknown', - 1 => 'list', - 2 => 'add', - 3 => 'edit', - 4 => 'delete', - 5 => 'insert', - 6 => 'update', - 7 => 'ajax_list', - 8 => 'ajax_list_info', - 9 => 'insert_validation', - 10 => 'update_validation', - 11 => 'upload_file', - 12 => 'delete_file', - 13 => 'ajax_relation', - 14 => 'ajax_relation_n_n', - 15 => 'success', - 16 => 'export', - 17 => 'print', - 18 => 'read', - 19 => 'delete_multiple', - 20 => 'clone' - ); - - public function getStateInfo() - { - $state_code = $this->getStateCode(); - $segment_object = $this->get_state_info_from_url(); - - $first_parameter = $segment_object->first_parameter; - $second_parameter = $segment_object->second_parameter; - - $state_info = (object)array(); - - switch ($state_code) { - case self::STATE_LIST: - case self::STATE_ADD: - //for now... do nothing! Keeping this switch here in case we need any information at the future. - break; - - case self::STATE_EDIT: - case self::STATE_READ: - if ($first_parameter !== null) { - $state_info = (object) array('primary_key' => $first_parameter); - } else { - throw new Exception('On the state "edit" the Primary key cannot be null', 6); - die(); - } - break; - - case self::STATE_DELETE: - if ($first_parameter !== null) { - $state_info = (object) array('primary_key' => $first_parameter); - } else { - throw new Exception('On the state "delete" the Primary key cannot be null',7); - die(); - } - break; - - case self::STATE_DELETE_MULTIPLE: - if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { - $state_info = (object) array('ids' => $_POST['ids']); - } else { - throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); - die(); - } - break; - - case self::STATE_CLONE: - if ($first_parameter !== null) { - $state_info = (object) array('primary_key' => $first_parameter); - } else { - throw new Exception('On the state "clone" the Primary key cannot be null', 20); - die(); - } - break; - - case self::STATE_INSERT: - if(!empty($_POST)) - { - $state_info = (object)array('unwrapped_data' => $_POST); - } - else - { - throw new Exception('On the state "insert" you must have post data',8); - die(); - } - break; - - case 6: - if(!empty($_POST) && $first_parameter !== null) - { - $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); - } - elseif(empty($_POST)) - { - throw new Exception('On the state "update" you must have post data',9); - die(); - } - else - { - throw new Exception('On the state "update" the Primary key cannot be null',10); - die(); - } - break; - - case 7: - case 8: - case 16: //export to excel - case 17: //print - $state_info = (object)array(); - $data = !empty($_POST) ? $_POST : $_GET; - - if(!empty($data['per_page'])) - { - $state_info->per_page = is_numeric($data['per_page']) ? $data['per_page'] : null; - } - if(!empty($data['page'])) - { - $state_info->page = is_numeric($data['page']) ? $data['page'] : null; - } - //If we request an export or a print we don't care about what page we are - if($state_code === 16 || $state_code === 17) - { - $state_info->page = 1; - $state_info->per_page = 1000000; //a very big number! - } - if(!empty($data['order_by'][0])) - { - $state_info->order_by = $data['order_by']; - } - if(isset($data['search_text']) && $data['search_text'] !== '') - { - if(empty($data['search_field'])) - { - $search_text = strip_tags($data['search_field']); - $state_info->search = (object)array('field' => null , 'text' => $data['search_text']); - } - else - { - if (is_array($data['search_field'])) { - $search_array = array(); - foreach ($data['search_field'] as $search_key => $search_field_name) { - $search_field_name = preg_replace("/[=\"'?\\\\]/", '' , $search_field_name); - $search_array[$search_field_name] = isset($data['search_text'][$search_key]) ? $data['search_text'][$search_key] : ''; - } - $state_info->search = $search_array; - } else { - $field_name = preg_replace("/[=\"'?\\\\]/", '' , $data['search_field']); - $state_info->search = (object)array( - 'field' => $field_name, - 'text' => $data['search_text'] ); - } - } - } - break; - - case 9: - - break; - - case 10: - if($first_parameter !== null) - { - $state_info = (object)array('primary_key' => $first_parameter); - } - break; - - case 11: - $state_info->field_name = $first_parameter; - break; - - case 12: - $state_info->field_name = $first_parameter; - $state_info->file_name = $second_parameter; - break; - - case 13: - $state_info->field_name = $_POST['field_name']; - $state_info->search = $_POST['term']; - break; - - case 14: - $state_info->field_name = $_POST['field_name']; - $state_info->search = $_POST['term']; - break; - - case 15: - $state_info = (object)array( - 'primary_key' => $first_parameter, - 'success_message' => true - ); - break; - } - - return $state_info; - } - - protected function getStateCode() - { - $state_string = $this->get_state_info_from_url()->operation; - - if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) - $state_code = array_search($state_string, $this->states); - else - $state_code = 0; - - return $state_code; - } - - protected function state_url($url = '', $is_list_page = false) - { - //Easy scenario, we had set the crud_url_path - if (!empty($this->crud_url_path)) { - $state_url = !empty($this->list_url_path) && $is_list_page? - $this->list_url_path : - $this->crud_url_path.'/'.$url ; - } else { - //Complicated scenario. The crud_url_path is not specified so we are - //trying to understand what is going on from the URL. - $ci = &get_instance(); - - $segment_object = $this->get_state_info_from_url(); - $method_name = $this->get_method_name(); - $segment_position = $segment_object->segment_position; - - $state_url_array = array(); - - if( sizeof($ci->uri->segments) > 0 ) { - foreach($ci->uri->segments as $num => $value) - { - $state_url_array[$num] = $value; - if($num == ($segment_position - 1)) - break; - } - - if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url - $state_url_array[$num+1] = 'index'; - } - - $state_url = site_url(implode('/',$state_url_array).'/'.$url); - } - - return $state_url; - } - - protected function get_state_info_from_url() - { - $ci = &get_instance(); - - $segment_position = count($ci->uri->segments) + 1; - $operation = 'list'; - - $segements = $ci->uri->segments; - foreach($segements as $num => $value) - { - if($value != 'unknown' && in_array($value, $this->states)) - { - $segment_position = (int)$num; - $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. - } - } - - $function_name = $this->get_method_name(); - - if($function_name == 'index' && !in_array('index',$ci->uri->segments)) - $segment_position++; - - $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; - $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; - - return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); - } - - protected function get_method_hash() - { - $ci = &get_instance(); - - $state_info = $this->get_state_info_from_url(); - $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; - - return $this->crud_url_path !== null - ? md5($this->crud_url_path) - : md5($this->get_controller_name().$this->get_method_name().$extra_values); - } - - protected function get_method_name() - { - $ci = &get_instance(); - return $ci->router->method; - } - - protected function get_controller_name() - { - $ci = &get_instance(); - return $ci->router->class; - } - - public function getState() - { - return $this->states[$this->getStateCode()]; - } - - protected function getListUrl() - { - return $this->state_url('',true); - } - - protected function getAjaxListUrl() - { - return $this->state_url('ajax_list'); - } - - protected function getExportToExcelUrl() - { - return $this->state_url('export'); - } - - protected function getPrintUrl() - { - return $this->state_url('print'); - } - - protected function getAjaxListInfoUrl() - { - return $this->state_url('ajax_list_info'); - } - - protected function getAddUrl() - { - return $this->state_url('add'); - } - - protected function getInsertUrl() - { - return $this->state_url('insert'); - } - - protected function getValidationInsertUrl() - { - return $this->state_url('insert_validation'); - } - - protected function getValidationUpdateUrl($primary_key = null) - { - if($primary_key === null) - return $this->state_url('update_validation'); - else - return $this->state_url('update_validation/'.$primary_key); - } - - protected function getCloneUrl($primary_key = null) - { - if ($primary_key === null) { - return $this->state_url('clone'); - } else { - return $this->state_url('clone/' . $primary_key); - } - } - - protected function getEditUrl($primary_key = null) - { - if($primary_key === null) - return $this->state_url('edit'); - else - return $this->state_url('edit/'.$primary_key); - } - - protected function getReadUrl($primary_key = null) - { - if($primary_key === null) - return $this->state_url('read'); - else - return $this->state_url('read/'.$primary_key); - } - - protected function getUpdateUrl($state_info) - { - return $this->state_url('update/'.$state_info->primary_key); - } - - protected function getDeleteUrl($state_info = null) - { - if (empty($state_info)) { - return $this->state_url('delete'); - } else { - return $this->state_url('delete/'.$state_info->primary_key); - } - } - - protected function getDeleteMultipleUrl() - { - return $this->state_url('delete_multiple'); - } - - protected function getListSuccessUrl($primary_key = null) - { - if(empty($primary_key)) - return $this->state_url('success',true); - else - return $this->state_url('success/'.$primary_key,true); - } - - protected function getUploadUrl($field_name) - { - return $this->state_url('upload_file/'.$field_name); - } - - protected function getFileDeleteUrl($field_name) - { - return $this->state_url('delete_file/'.$field_name); - } - - protected function getAjaxRelationUrl() - { - return $this->state_url('ajax_relation'); - } - - protected function getAjaxRelationManytoManyUrl() - { - return $this->state_url('ajax_relation_n_n'); - } -} - - -/** - * PHP grocery CRUD - * - * LICENSE - * - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. - * Please see the corresponding license file for details of these licenses. - * You are free to use, modify and distribute this software, but all copyright information must remain. - * - * @package grocery CRUD - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @version 1.6.1 - * @author John Skoumbourdis - */ - -// ------------------------------------------------------------------------ - -/** - * PHP grocery CRUD - * - * Creates a full functional CRUD with few lines of code. - * - * @package grocery CRUD - * @author John Skoumbourdis - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @link http://www.grocerycrud.com/documentation - */ -class Grocery_CRUD extends grocery_CRUD_States -{ - /** - * Grocery CRUD version - * - * @var string - */ - const VERSION = "1.6.1"; - - const JQUERY = "jquery-1.11.1.min.js"; - const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; - const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; - - protected $state_code = null; - protected $state_info = null; - protected $columns = null; - - private $basic_db_table_checked = false; - private $columns_checked = false; - private $add_fields_checked = false; - private $edit_fields_checked = false; - private $read_fields_checked = false; - - protected $default_theme = 'flexigrid'; - protected $language = null; - protected $lang_strings = array(); - protected $php_date_format = null; - protected $js_date_format = null; - protected $ui_date_format = null; - protected $character_limiter = null; - protected $config = null; - - protected $add_fields = null; - protected $edit_fields = null; - protected $read_fields = null; - protected $add_hidden_fields = array(); - protected $edit_hidden_fields = array(); - protected $field_types = null; - protected $basic_db_table = null; - protected $theme_config = array(); - protected $subject = null; - protected $subject_plural = null; - protected $display_as = array(); - protected $order_by = null; - protected $where = array(); - protected $like = array(); - protected $having = array(); - protected $or_having = array(); - protected $limit = null; - protected $required_fields = array(); - protected $_unique_fields = array(); - protected $validation_rules = array(); - protected $relation = array(); - protected $relation_n_n = array(); - protected $upload_fields = array(); - protected $actions = array(); - - protected $form_validation = null; - protected $change_field_type = null; - protected $primary_keys = array(); - protected $crud_url_path = null; - protected $list_url_path = null; - - /* The unsetters */ - protected $unset_texteditor = array(); - protected $unset_add = false; - protected $unset_edit = false; - protected $unset_delete = false; - protected $unset_read = false; - protected $unset_jquery = false; - protected $unset_jquery_ui = false; - protected $unset_bootstrap = false; - protected $unset_list = false; - protected $unset_export = false; - protected $unset_print = false; - protected $unset_back_to_list = false; - protected $unset_clone = false; - protected $unset_columns = null; - protected $unset_add_fields = null; - protected $unset_edit_fields = null; - protected $unset_clone_fields = null; - protected $unset_read_fields = null; - - /* Callbacks */ - protected $callback_before_insert = null; - protected $callback_after_insert = null; - protected $callback_insert = null; - protected $callback_before_update = null; - protected $callback_after_update = null; - protected $callback_update = null; - protected $callback_before_delete = null; - protected $callback_after_delete = null; - protected $callback_delete = null; - protected $callback_before_clone = null; - protected $callback_after_clone = null; - protected $callback_clone = null; - protected $callback_column = array(); - protected $callback_add_field = array(); - protected $callback_edit_field = array(); - protected $callback_read_field = array(); - protected $callback_clone_field = array(); - protected $callback_upload = null; - protected $callback_before_upload = null; - protected $callback_after_upload = null; - - protected $default_javascript_path = null; //autogenerate, please do not modify - protected $default_css_path = null; //autogenerate, please do not modify - protected $default_texteditor_path = null; //autogenerate, please do not modify - protected $default_theme_path = null; //autogenerate, please do not modify - protected $default_language_path = 'assets/grocery_crud/languages'; - protected $default_config_path = 'assets/grocery_crud/config'; - protected $default_assets_path = 'assets/grocery_crud'; - - /** - * - * Constructor - * - * @access public - */ - public function __construct() - { - - } - - /** - * The displayed columns that user see - * - * @access public - * @param string - * @param array - * @return void - */ - public function columns() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->columns = $args; - - return $this; - } - - - /** - * Set Validation Rules - * - * Important note: If the $field is an array then no automated crud fields will take apart - * - * @access public - * @param mixed - * @param string - * @oaram array - * @return void - */ - function set_rules($field, $label = '', $rules = '', $errors = array()) - { - if(is_string($field)) - { - $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules, 'errors' => $errors); - }elseif(is_array($field)) - { - foreach($field as $num_field => $field_array) - { - $this->validation_rules[$field_array['field']] = $field_array; - } - } - return $this; - } - - /** - * - * Changes the default field type - * @param string $field - * @param string $type - * @param array|string $extras - */ - public function change_field_type($field , $type, $extras = null) - { - $field_type = (object)array('type' => $type); - - $field_type->extras = $extras; - - $this->change_field_type[$field] = $field_type; - - return $this; - } - - /** - * - * Just an alias to the change_field_type method - * @param string $field - * @param string $type - * @param array|string $extras - */ - public function field_type($field , $type, $extras = null) - { - return $this->change_field_type($field , $type, $extras); - } - - /** - * Change the default primary key for a specific table. - * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method - * - * @param string $primary_key_field - * @param string $table_name - */ - public function set_primary_key($primary_key_field, $table_name = null) - { - $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); - - return $this; - } - - /** - * Unsets the texteditor of the selected fields - * - * @access public - * @param string - * @param array - * @return void - */ - public function unset_texteditor() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - foreach($args as $arg) - { - $this->unset_texteditor[] = $arg; - } - - return $this; - } - - /** - * Unsets just the jquery library from the js. This function can be used if there is already a jquery included - * in the main template. This will avoid all jquery conflicts. - * - * @return void - */ - public function unset_jquery() - { - $this->unset_jquery = true; - - return $this; - } - - /** - * Unsets the jquery UI Javascript and CSS. This function is really useful - * when the jquery UI JavaScript and CSS are already included in the main template. - * This will avoid all jquery UI conflicts. - * - * @return void - */ - public function unset_jquery_ui() - { - $this->unset_jquery_ui = true; - - return $this; - } - - /** - * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included - * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. - * - * @return void - */ - public function unset_bootstrap() - { - $this->unset_bootstrap = true; - - return $this; - } - - /** - * Unsets the add operation from the list - * - * @return void - */ - public function unset_add() - { - $this->unset_add = true; - $this->unset_clone = true; - - return $this; - } - - /** - * Unsets the edit operation from the list - * - * @return void - */ - public function unset_edit() - { - $this->unset_edit = true; - - return $this; - } - - /** - * Unsets the delete operation from the list - * - * @return void - */ - public function unset_delete() - { - $this->unset_delete = true; - - return $this; - } - - /** - * Unsets the read operation from the list - * - * @return void - */ - public function unset_read() - { - $this->unset_read = true; - - return $this; - } - - /** - * Just an alias to unset_read - * - * @return void - * */ - public function unset_view() - { - return unset_read(); - } - - /** - * Unsets the export button and functionality from the list - * - * @return void - */ - public function unset_export() - { - $this->unset_export = true; - - return $this; - } - - - /** - * Unsets the print button and functionality from the list - * - * @return void - */ - public function unset_print() - { - $this->unset_print = true; - - return $this; - } - - /** - * Unsets all the operations from the list - * - * @return void - */ - public function unset_operations() - { - $this->unset_add = true; - $this->unset_edit = true; - $this->unset_clone = true; - $this->unset_delete = true; - $this->unset_read = true; - $this->unset_export = true; - $this->unset_print = true; - - return $this; - } - - /** - * Unsets a column from the list - * - * @return void. - */ - public function unset_columns() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->unset_columns = $args; - - return $this; - } - - public function unset_list() - { - $this->unset_list = true; - - return $this; - } - - public function unset_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->unset_add_fields = $args; - $this->unset_edit_fields = $args; - $this->unset_clone_fields = $args; - $this->unset_read_fields = $args; - - return $this; - } - - public function unset_add_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->unset_add_fields = $args; - - return $this; - } - - public function unset_edit_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->unset_edit_fields = $args; - - return $this; - } - - public function unset_clone_fields() - { - $args = func_get_args(); - - if (isset($args[0]) && is_array($args[0])) { - $args = $args[0]; - } - - $this->unset_clone_fields = $args; - - return $this; - } - - public function unset_read_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->unset_read_fields = $args; - - return $this; - } - - - /** - * Unsets everything that has to do with buttons or links with go back to list message - * @access public - * @return void - */ - public function unset_back_to_list() - { - $this->unset_back_to_list = true; - - return $this; - } - - /** - * Unsets everything that has to do with buttons or links with clone - * @access public - * @return void - */ - public function unset_clone() - { - $this->unset_clone = true; - - return $this; - } - - public function set_clone() - { - $this->unset_clone = false; - $this->unset_add = false; - - return $this; - } - - /** - * - * The fields that user will see on add/edit - * - * @access public - * @param string - * @param array - * @return void - */ - public function fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->add_fields = $args; - $this->edit_fields = $args; - - return $this; - } - - /** - * - * The fields that user can see . It is only for the add form - */ - public function add_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->add_fields = $args; - - return $this; - } - - /** - * - * The fields that user can see . It is only for the edit form - */ - public function edit_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->edit_fields = $args; - - return $this; - } - - public function set_read_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) { - $args = $args[0]; - } - - $this->read_fields = $args; - - return $this; - } - - /** - * - * Changes the displaying label of the field - * @param $field_name - * @param $display_as - * @return void - */ - public function display_as($field_name, $display_as = null) - { - if(is_array($field_name)) - { - foreach($field_name as $field => $display_as) - { - $this->display_as[$field] = $display_as; - } - } - elseif($display_as !== null) - { - $this->display_as[$field_name] = $display_as; - } - return $this; - } - - /** - * - * Load the language strings array from the language file - */ - protected function _load_language() - { - if($this->language === null) - { - $this->language = strtolower($this->config->default_language); - } - include($this->default_language_path.'/'.$this->language.'.php'); - - foreach($lang as $handle => $lang_string) - if(!isset($this->lang_strings[$handle])) - $this->lang_strings[$handle] = $lang_string; - - $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); - $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; - - } - - protected function _load_date_format() - { - list($php_day, $php_month, $php_year) = array('d','m','Y'); - list($js_day, $js_month, $js_year) = array('dd','mm','yy'); - list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); - - $date_format = $this->config->date_format; - switch ($date_format) { - case 'uk-date': - $this->php_date_format = "$php_day/$php_month/$php_year"; - $this->js_date_format = "$js_day/$js_month/$js_year"; - $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; - break; - - case 'us-date': - $this->php_date_format = "$php_month/$php_day/$php_year"; - $this->js_date_format = "$js_month/$js_day/$js_year"; - $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; + case self::STATE_INSERT: + if(!empty($_POST)) + { + $state_info = (object)array('unwrapped_data' => $_POST); + } + else + { + throw new Exception('On the state "insert" you must have post data',8); + die(); + } break; - case 'sql-date': - default: - $this->php_date_format = "$php_year-$php_month-$php_day"; - $this->js_date_format = "$js_year-$js_month-$js_day"; - $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; + case 6: + if(!empty($_POST) && $first_parameter !== null) + { + $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); + } + elseif(empty($_POST)) + { + throw new Exception('On the state "update" you must have post data',9); + die(); + } + else + { + throw new Exception('On the state "update" the Primary key cannot be null',10); + die(); + } break; - } - } - - /** - * - * Set a language string directly - * @param string $handle - * @param string $string - */ - public function set_lang_string($handle, $lang_string){ - $this->lang_strings[$handle] = $lang_string; - - return $this; - } - - /** - * - * Just an alias to get_lang_string method - * @param string $handle - */ - public function l($handle) - { - return $this->get_lang_string($handle); - } - - /** - * - * Get the language string of the inserted string handle - * @param string $handle - */ - public function get_lang_string($handle) - { - return $this->lang_strings[$handle]; - } - - /** - * - * Simply set the language - * @example english - * @param string $language - */ - public function set_language($language) - { - $this->language = $language; - return $this; - } + case 7: + case 8: + case 16: //export to excel + case 17: //print + $state_info = (object)array(); + $data = !empty($_POST) ? $_POST : $_GET; - /** - * - * Enter description here ... - */ - protected function get_columns() - { - if($this->columns_checked === false) - { - $field_types = $this->get_field_types(); - if(empty($this->columns)) - { - $this->columns = array(); - foreach($field_types as $field) + if(!empty($data['per_page'])) { - if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) - $this->columns[] = $field->name; + $state_info->per_page = is_numeric($data['per_page']) ? $data['per_page'] : null; } - } - - foreach($this->columns as $col_num => $column) - { - - if(isset($this->relation[$column])) + if(!empty($data['page'])) { - - $new_column = $this->_unique_field_name($this->relation[$column][0]); - $this->columns[$col_num] = $new_column; - - if(isset($this->display_as[$column])) + $state_info->page = is_numeric($data['page']) ? $data['page'] : null; + } + //If we request an export or a print we don't care about what page we are + if($state_code === 16 || $state_code === 17) + { + $state_info->page = 1; + $state_info->per_page = 1000000; //a very big number! + } + if(!empty($data['order_by'][0])) + { + $state_info->order_by = $data['order_by']; + } + if(isset($data['search_text']) && $data['search_text'] !== '') + { + if(empty($data['search_field'])) { - $display_as = $this->display_as[$column]; - unset($this->display_as[$column]); - $this->display_as[$new_column] = $display_as; + $search_text = strip_tags($data['search_field']); + $state_info->search = (object)array('field' => null , 'text' => $data['search_text']); } else { - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); - } - - $column = $new_column; - $this->columns[$col_num] = $new_column; - } - else - { - if(!empty($this->relation)) - { - $table_name = $this->get_table(); - foreach($this->relation as $relation) - { - if( $relation[2] == $column ) - { - $new_column = $table_name.'.'.$column; - if(isset($this->display_as[$column])) - { - $display_as = $this->display_as[$column]; - unset($this->display_as[$column]); - $this->display_as[$new_column] = $display_as; - } - else - { - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); - } - - $column = $new_column; - $this->columns[$col_num] = $new_column; + if (is_array($data['search_field'])) { + $search_array = array(); + foreach ($data['search_field'] as $search_key => $search_field_name) { + $search_field_name = preg_replace("/[=\"'?\\\\]/", '' , $search_field_name); + $search_array[$search_field_name] = isset($data['search_text'][$search_key]) ? $data['search_text'][$search_key] : ''; } + $state_info->search = $search_array; + } else { + $field_name = preg_replace("/[=\"'?\\\\]/", '' , $data['search_field']); + $state_info->search = (object)array( + 'field' => $field_name, + 'text' => $data['search_text'] ); } } - } + break; - if(isset($this->display_as[$column])) - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); - elseif(isset($field_types[$column])) - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); - else - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => - ucfirst(str_replace('_',' ',$column))); + case 9: + + break; - if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) + case 10: + if($first_parameter !== null) { - unset($this->columns[$col_num]); + $state_info = (object)array('primary_key' => $first_parameter); } - } + break; + + case 11: + $state_info->field_name = $first_parameter; + break; + + case 12: + $state_info->field_name = $first_parameter; + $state_info->file_name = $second_parameter; + break; + + case 13: + $state_info->field_name = $_POST['field_name']; + $state_info->search = $_POST['term']; + break; - $this->columns_checked = true; + case 14: + $state_info->field_name = $_POST['field_name']; + $state_info->search = $_POST['term']; + break; + case 15: + $state_info = (object)array( + 'primary_key' => $first_parameter, + 'success_message' => true + ); + break; } - return $this->columns; + return $state_info; } - /** - * - * Enter description here ... - */ - protected function get_add_fields() - { - if($this->add_fields_checked === false) - { - $field_types = $this->get_field_types(); - if(!empty($this->add_fields)) - { - foreach($this->add_fields as $field_num => $field) - { - if(isset($this->display_as[$field])) - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); - elseif(isset($field_types[$field]->display_as)) - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); - else - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); - } - } - else - { - $this->add_fields = array(); - foreach($field_types as $field) - { - //Check if an unset_add_field is initialize for this field name - if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) - continue; - - if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) - { - if(isset($this->display_as[$field->name])) - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); - else - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); - } - } - } + protected function getStateCode() + { + $state_string = $this->get_state_info_from_url()->operation; + + if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) + $state_code = array_search($state_string, $this->states); + else + $state_code = 0; + + return $state_code; + } + + protected function state_url($url = '', $is_list_page = false) + { + //Easy scenario, we had set the crud_url_path + if (!empty($this->crud_url_path)) { + $state_url = !empty($this->list_url_path) && $is_list_page? + $this->list_url_path : + $this->crud_url_path.'/'.$url ; + } else { + //Complicated scenario. The crud_url_path is not specified so we are + //trying to understand what is going on from the URL. + $ci = &get_instance(); + + $segment_object = $this->get_state_info_from_url(); + $method_name = $this->get_method_name(); + $segment_position = $segment_object->segment_position; + + $state_url_array = array(); + + if( sizeof($ci->uri->segments) > 0 ) { + foreach($ci->uri->segments as $num => $value) + { + $state_url_array[$num] = $value; + if($num == ($segment_position - 1)) + break; + } + + if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url + $state_url_array[$num+1] = 'index'; + } + + $state_url = site_url(implode('/',$state_url_array).'/'.$url); + } + + return $state_url; + } + + protected function get_state_info_from_url() + { + $ci = &get_instance(); + + $segment_position = count($ci->uri->segments) + 1; + $operation = 'list'; + + $segements = $ci->uri->segments; + foreach($segements as $num => $value) + { + if($value != 'unknown' && in_array($value, $this->states)) + { + $segment_position = (int)$num; + $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. + } + } + + $function_name = $this->get_method_name(); + + if($function_name == 'index' && !in_array('index',$ci->uri->segments)) + $segment_position++; + + $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; + $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; + + return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); + } + + protected function get_method_hash() + { + $ci = &get_instance(); + + $state_info = $this->get_state_info_from_url(); + $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; + + return $this->crud_url_path !== null + ? md5($this->crud_url_path) + : md5($this->get_controller_name().$this->get_method_name().$extra_values); + } + + protected function get_method_name() + { + $ci = &get_instance(); + return $ci->router->method; + } + + protected function get_controller_name() + { + $ci = &get_instance(); + return $ci->router->class; + } + + public function getState() + { + return $this->states[$this->getStateCode()]; + } + + protected function getListUrl() + { + return $this->state_url('',true); + } + + protected function getAjaxListUrl() + { + return $this->state_url('ajax_list'); + } + + protected function getExportToExcelUrl() + { + return $this->state_url('export'); + } + + protected function getPrintUrl() + { + return $this->state_url('print'); + } + + protected function getAjaxListInfoUrl() + { + return $this->state_url('ajax_list_info'); + } + + protected function getAddUrl() + { + return $this->state_url('add'); + } + + protected function getInsertUrl() + { + return $this->state_url('insert'); + } + + protected function getValidationInsertUrl() + { + return $this->state_url('insert_validation'); + } + + protected function getValidationUpdateUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('update_validation'); + else + return $this->state_url('update_validation/'.$primary_key); + } - $this->add_fields_checked = true; + protected function getCloneUrl($primary_key = null) + { + if ($primary_key === null) { + return $this->state_url('clone'); + } else { + return $this->state_url('clone/' . $primary_key); } - return $this->add_fields; } - /** - * - * Enter description here ... - */ - protected function get_edit_fields() - { - if($this->edit_fields_checked === false) - { - $field_types = $this->get_field_types(); - if(!empty($this->edit_fields)) - { - foreach($this->edit_fields as $field_num => $field) - { - if(isset($this->display_as[$field])) - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); - else - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); - } - } - else - { - $this->edit_fields = array(); - foreach($field_types as $field) - { - //Check if an unset_edit_field is initialize for this field name - if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) - continue; + protected function getEditUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('edit'); + else + return $this->state_url('edit/'.$primary_key); + } - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') - { - if(isset($this->display_as[$field->name])) - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); - else - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); - } - } - } + protected function getReadUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('read'); + else + return $this->state_url('read/'.$primary_key); + } - $this->edit_fields_checked = true; + protected function getUpdateUrl($state_info) + { + return $this->state_url('update/'.$state_info->primary_key); + } + + protected function getDeleteUrl($state_info = null) + { + if (empty($state_info)) { + return $this->state_url('delete'); + } else { + return $this->state_url('delete/'.$state_info->primary_key); } - return $this->edit_fields; - } + } - /** - * - * Enter description here ... - */ - protected function get_read_fields() + protected function getDeleteMultipleUrl() { - if($this->read_fields_checked === false) - { - $field_types = $this->get_field_types(); - if(!empty($this->read_fields)) - { - foreach($this->read_fields as $field_num => $field) - { - if(isset($this->display_as[$field])) - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); - else - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); - } - } - else - { - $this->read_fields = array(); - foreach($field_types as $field) - { - //Check if an unset_read_field is initialize for this field name - if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) - continue; + return $this->state_url('delete_multiple'); + } - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') - { - if(isset($this->display_as[$field->name])) - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); - else - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); - } - } - } + protected function getListSuccessUrl($primary_key = null) + { + if(empty($primary_key)) + return $this->state_url('success',true); + else + return $this->state_url('success/'.$primary_key,true); + } + + protected function getUploadUrl($field_name) + { + return $this->state_url('upload_file/'.$field_name); + } + + protected function getFileDeleteUrl($field_name) + { + return $this->state_url('delete_file/'.$field_name); + } + + protected function getAjaxRelationUrl() + { + return $this->state_url('ajax_relation'); + } + + protected function getAjaxRelationManytoManyUrl() + { + return $this->state_url('ajax_relation_n_n'); + } +} - $this->read_fields_checked = true; - } - return $this->read_fields; - } - public function order_by($order_by, $direction = 'asc') - { - $this->order_by = array($order_by,$direction); +/** + * PHP grocery CRUD + * + * LICENSE + * + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. + * Please see the corresponding license file for details of these licenses. + * You are free to use, modify and distribute this software, but all copyright information must remain. + * + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @version 1.6.1 + * @author John Skoumbourdis + */ - return $this; - } +// ------------------------------------------------------------------------ - public function where($key, $value = NULL, $escape = TRUE) - { - $this->where[] = array($key,$value,$escape); +/** + * PHP grocery CRUD + * + * Creates a full functional CRUD with few lines of code. + * + * @package grocery CRUD + * @author John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @link http://www.grocerycrud.com/documentation + */ +class Grocery_CRUD extends grocery_CRUD_States +{ + /** + * Grocery CRUD version + * + * @var string + */ + const VERSION = "1.6.1"; + + const JQUERY = "jquery-1.11.1.min.js"; + const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; + const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; + + protected $state_code = null; + protected $state_info = null; + protected $columns = null; + + private $basic_db_table_checked = false; + private $columns_checked = false; + private $add_fields_checked = false; + private $edit_fields_checked = false; + private $read_fields_checked = false; + + protected $default_theme = 'flexigrid'; + protected $language = null; + protected $lang_strings = array(); + protected $php_date_format = null; + protected $js_date_format = null; + protected $ui_date_format = null; + protected $character_limiter = null; + protected $config = null; + + protected $add_fields = null; + protected $edit_fields = null; + protected $read_fields = null; + protected $add_hidden_fields = array(); + protected $edit_hidden_fields = array(); + protected $field_types = null; + protected $basic_db_table = null; + protected $theme_config = array(); + protected $subject = null; + protected $subject_plural = null; + protected $display_as = array(); + protected $order_by = null; + protected $where = array(); + protected $like = array(); + protected $having = array(); + protected $or_having = array(); + protected $limit = null; + protected $required_fields = array(); + protected $_unique_fields = array(); + protected $validation_rules = array(); + protected $relation = array(); + protected $relation_n_n = array(); + protected $upload_fields = array(); + protected $actions = array(); + + protected $form_validation = null; + protected $change_field_type = null; + protected $primary_keys = array(); + protected $crud_url_path = null; + protected $list_url_path = null; + + /* The unsetters */ + protected $unset_texteditor = array(); + protected $unset_add = false; + protected $unset_edit = false; + protected $unset_delete = false; + protected $unset_read = false; + protected $unset_jquery = false; + protected $unset_jquery_ui = false; + protected $unset_bootstrap = false; + protected $unset_list = false; + protected $unset_export = false; + protected $unset_print = false; + protected $unset_back_to_list = false; + protected $unset_clone = false; + protected $unset_columns = null; + protected $unset_add_fields = null; + protected $unset_edit_fields = null; + protected $unset_clone_fields = null; + protected $unset_read_fields = null; + + /* Callbacks */ + protected $callback_before_insert = null; + protected $callback_after_insert = null; + protected $callback_insert = null; + protected $callback_before_update = null; + protected $callback_after_update = null; + protected $callback_update = null; + protected $callback_before_delete = null; + protected $callback_after_delete = null; + protected $callback_delete = null; + protected $callback_before_clone = null; + protected $callback_after_clone = null; + protected $callback_clone = null; + protected $callback_column = array(); + protected $callback_add_field = array(); + protected $callback_edit_field = array(); + protected $callback_read_field = array(); + protected $callback_clone_field = array(); + protected $callback_upload = null; + protected $callback_before_upload = null; + protected $callback_after_upload = null; + + protected $default_javascript_path = null; //autogenerate, please do not modify + protected $default_css_path = null; //autogenerate, please do not modify + protected $default_texteditor_path = null; //autogenerate, please do not modify + protected $default_theme_path = null; //autogenerate, please do not modify + protected $default_language_path = 'assets/grocery_crud/languages'; + protected $default_config_path = 'assets/grocery_crud/config'; + protected $default_assets_path = 'assets/grocery_crud'; + + /** + * + * Constructor + * + * @access public + */ + public function __construct() + { + + } + + /** + * The displayed columns that user see + * + * @access public + * @param string + * @param array + * @return void + */ + public function columns() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->columns = $args; + + return $this; + } + + + /** + * Set Validation Rules + * + * Important note: If the $field is an array then no automated crud fields will take apart + * + * @access public + * @param mixed + * @param string + * @oaram array + * @return void + */ + function set_rules($field, $label = '', $rules = '', $errors = array()) + { + if(is_string($field)) + { + $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules, 'errors' => $errors); + }elseif(is_array($field)) + { + foreach($field as $num_field => $field_array) + { + $this->validation_rules[$field_array['field']] = $field_array; + } + } + return $this; + } + + /** + * + * Changes the default field type + * @param string $field + * @param string $type + * @param array|string $extras + */ + public function change_field_type($field , $type, $extras = null) + { + $field_type = (object)array('type' => $type); + + $field_type->extras = $extras; + + $this->change_field_type[$field] = $field_type; + + return $this; + } + + /** + * + * Just an alias to the change_field_type method + * @param string $field + * @param string $type + * @param array|string $extras + */ + public function field_type($field , $type, $extras = null) + { + return $this->change_field_type($field , $type, $extras); + } + + /** + * Change the default primary key for a specific table. + * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method + * + * @param string $primary_key_field + * @param string $table_name + */ + public function set_primary_key($primary_key_field, $table_name = null) + { + $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); + + return $this; + } + + /** + * Unsets the texteditor of the selected fields + * + * @access public + * @param string + * @param array + * @return void + */ + public function unset_texteditor() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + foreach($args as $arg) + { + $this->unset_texteditor[] = $arg; + } + + return $this; + } + + /** + * Unsets just the jquery library from the js. This function can be used if there is already a jquery included + * in the main template. This will avoid all jquery conflicts. + * + * @return void + */ + public function unset_jquery() + { + $this->unset_jquery = true; + + return $this; + } + + /** + * Unsets the jquery UI Javascript and CSS. This function is really useful + * when the jquery UI JavaScript and CSS are already included in the main template. + * This will avoid all jquery UI conflicts. + * + * @return void + */ + public function unset_jquery_ui() + { + $this->unset_jquery_ui = true; + + return $this; + } + + /** + * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included + * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. + * + * @return void + */ + public function unset_bootstrap() + { + $this->unset_bootstrap = true; + + return $this; + } + + /** + * Unsets the add operation from the list + * + * @return void + */ + public function unset_add() + { + $this->unset_add = true; + $this->unset_clone = true; - return $this; - } + return $this; + } + + /** + * Unsets the edit operation from the list + * + * @return void + */ + public function unset_edit() + { + $this->unset_edit = true; + + return $this; + } + + /** + * Unsets the delete operation from the list + * + * @return void + */ + public function unset_delete() + { + $this->unset_delete = true; + + return $this; + } + + /** + * Unsets the read operation from the list + * + * @return void + */ + public function unset_read() + { + $this->unset_read = true; + + return $this; + } + + /** + * Just an alias to unset_read + * + * @return void + * */ + public function unset_view() + { + return unset_read(); + } + + /** + * Unsets the export button and functionality from the list + * + * @return void + */ + public function unset_export() + { + $this->unset_export = true; + + return $this; + } + + + /** + * Unsets the print button and functionality from the list + * + * @return void + */ + public function unset_print() + { + $this->unset_print = true; + + return $this; + } + + /** + * Unsets all the operations from the list + * + * @return void + */ + public function unset_operations() + { + $this->unset_add = true; + $this->unset_edit = true; + $this->unset_clone = true; + $this->unset_delete = true; + $this->unset_read = true; + $this->unset_export = true; + $this->unset_print = true; + + return $this; + } + + /** + * Unsets a column from the list + * + * @return void. + */ + public function unset_columns() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_columns = $args; + + return $this; + } + + public function unset_list() + { + $this->unset_list = true; + + return $this; + } + + public function unset_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_add_fields = $args; + $this->unset_edit_fields = $args; + $this->unset_clone_fields = $args; + $this->unset_read_fields = $args; - public function or_where($key, $value = NULL, $escape = TRUE) - { - $this->or_where[] = array($key,$value,$escape); + return $this; + } - return $this; - } + public function unset_add_fields() + { + $args = func_get_args(); - public function like($field, $match = '', $side = 'both') - { - $this->like[] = array($field, $match, $side); + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } - return $this; - } + $this->unset_add_fields = $args; - protected function having($key, $value = '', $escape = TRUE) - { - $this->having[] = array($key, $value, $escape); + return $this; + } - return $this; - } + public function unset_edit_fields() + { + $args = func_get_args(); - protected function or_having($key, $value = '', $escape = TRUE) - { - $this->or_having[] = array($key, $value, $escape); + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } - return $this; - } + $this->unset_edit_fields = $args; - public function or_like($field, $match = '', $side = 'both') - { - $this->or_like[] = array($field, $match, $side); + return $this; + } - return $this; - } + public function unset_clone_fields() + { + $args = func_get_args(); - public function limit($limit, $offset = '') - { - $this->limit = array($limit,$offset); + if (isset($args[0]) && is_array($args[0])) { + $args = $args[0]; + } - return $this; - } + $this->unset_clone_fields = $args; - protected function _initialize_helpers() - { - $ci = &get_instance(); + return $this; + } - $ci->load->helper('url'); - $ci->load->helper('form'); - } + public function unset_read_fields() + { + $args = func_get_args(); - protected function _initialize_variables() - { - $ci = &get_instance(); - $ci->load->config('grocery_crud'); - - $this->config = (object)array(); - - /** Initialize all the config variables into this object */ - $this->config->default_language = $ci->config->item('grocery_crud_default_language'); - $this->config->date_format = $ci->config->item('grocery_crud_date_format'); - $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); - $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); - $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); - $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); - $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); - $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); - $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); - $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); - $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); - $this->config->environment = $ci->config->item('grocery_crud_environment'); - $this->config->xss_clean = $ci->config->item('grocery_crud_xss_clean'); + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } - /** Initialize default paths */ - $this->default_javascript_path = $this->default_assets_path.'/js'; - $this->default_css_path = $this->default_assets_path.'/css'; - $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; - $this->default_theme_path = $this->default_assets_path.'/themes'; + $this->unset_read_fields = $args; - $this->character_limiter = $this->config->character_limiter; + return $this; + } - if ($this->character_limiter === 0 || $this->character_limiter === '0') { - $this->character_limiter = 1000000; //a very big number - } elseif($this->character_limiter === null || $this->character_limiter === false) { - $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value - } - if ($this->theme === null && !empty($this->config->default_theme)) { - $this->set_theme($this->config->default_theme); - } - } + /** + * Unsets everything that has to do with buttons or links with go back to list message + * @access public + * @return void + */ + public function unset_back_to_list() + { + $this->unset_back_to_list = true; - protected function _set_primary_keys_to_model() - { - if(!empty($this->primary_keys)) - { - foreach($this->primary_keys as $primary_key) - { - $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); - } - } - } + return $this; + } /** - * Initialize all the required libraries and variables before rendering + * Unsets everything that has to do with buttons or links with clone + * @access public + * @return void */ - protected function pre_render() + public function unset_clone() { - $this->_initialize_variables(); - $this->_initialize_helpers(); - $this->_load_language(); - $this->state_code = $this->getStateCode(); - - if($this->basic_model === null) - $this->set_default_Model(); + $this->unset_clone = true; - $this->set_basic_db_table($this->get_table()); + return $this; + } - $this->_load_date_format(); + public function set_clone() + { + $this->unset_clone = false; + $this->unset_add = false; - $this->_set_primary_keys_to_model(); + return $this; } - /** - * - * Or else ... make it work! The web application takes decision of what to do and show it to the final user. - * Without this function nothing works. Here is the core of grocery CRUD project. - * - * @access public - */ - public function render() - { - $this->pre_render(); + /** + * + * The fields that user will see on add/edit + * + * @access public + * @param string + * @param array + * @return void + */ + public function fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->add_fields = $args; + $this->edit_fields = $args; + + return $this; + } + + /** + * + * The fields that user can see . It is only for the add form + */ + public function add_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->add_fields = $args; + + return $this; + } + + /** + * + * The fields that user can see . It is only for the edit form + */ + public function edit_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->edit_fields = $args; + + return $this; + } + + public function set_read_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) { + $args = $args[0]; + } + + $this->read_fields = $args; + + return $this; + } + + /** + * + * Changes the displaying label of the field + * @param $field_name + * @param $display_as + * @return void + */ + public function display_as($field_name, $display_as = null) + { + if(is_array($field_name)) + { + foreach($field_name as $field => $display_as) + { + $this->display_as[$field] = $display_as; + } + } + elseif($display_as !== null) + { + $this->display_as[$field_name] = $display_as; + } + return $this; + } + + /** + * + * Load the language strings array from the language file + */ + protected function _load_language() + { + if($this->language === null) + { + $this->language = strtolower($this->config->default_language); + } + include($this->default_language_path.'/'.$this->language.'.php'); + + foreach($lang as $handle => $lang_string) + if(!isset($this->lang_strings[$handle])) + $this->lang_strings[$handle] = $lang_string; + + $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); + $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; + + } + + protected function _load_date_format() + { + list($php_day, $php_month, $php_year) = array('d','m','Y'); + list($js_day, $js_month, $js_year) = array('dd','mm','yy'); + list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); + + $date_format = $this->config->date_format; + switch ($date_format) { + case 'uk-date': + $this->php_date_format = "$php_day/$php_month/$php_year"; + $this->js_date_format = "$js_day/$js_month/$js_year"; + $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; + break; - if( $this->state_code != 0 ) - { - $this->state_info = $this->getStateInfo(); - } - else - { - throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); - die(); - } + case 'us-date': + $this->php_date_format = "$php_month/$php_day/$php_year"; + $this->js_date_format = "$js_month/$js_day/$js_year"; + $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; + break; - switch ($this->state_code) { - case 15://success - case 1://list - if($this->unset_list) - { - throw new Exception('You don\'t have permissions for this operation', 14); - die(); - } + case 'sql-date': + default: + $this->php_date_format = "$php_year-$php_month-$php_day"; + $this->js_date_format = "$js_year-$js_month-$js_day"; + $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; + break; + } + } + + /** + * + * Set a language string directly + * @param string $handle + * @param string $string + */ + public function set_lang_string($handle, $lang_string){ + $this->lang_strings[$handle] = $lang_string; + + return $this; + } + + /** + * + * Just an alias to get_lang_string method + * @param string $handle + */ + public function l($handle) + { + return $this->get_lang_string($handle); + } + + /** + * + * Get the language string of the inserted string handle + * @param string $handle + */ + public function get_lang_string($handle) + { + return $this->lang_strings[$handle]; + } + + /** + * + * Simply set the language + * @example english + * @param string $language + */ + public function set_language($language) + { + $this->language = $language; + + return $this; + } + + /** + * + * Enter description here ... + */ + protected function get_columns() + { + if($this->columns_checked === false) + { + $field_types = $this->get_field_types(); + if(empty($this->columns)) + { + $this->columns = array(); + foreach($field_types as $field) + { + if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) + $this->columns[] = $field->name; + } + } + + foreach($this->columns as $col_num => $column) + { + + if(isset($this->relation[$column])) + { + + $new_column = $this->_unique_field_name($this->relation[$column][0]); + $this->columns[$col_num] = $new_column; + + if(isset($this->display_as[$column])) + { + $display_as = $this->display_as[$column]; + unset($this->display_as[$column]); + $this->display_as[$new_column] = $display_as; + } + else + { + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); + } + + $column = $new_column; + $this->columns[$col_num] = $new_column; + } + else + { + if(!empty($this->relation)) + { + $table_name = $this->get_table(); + foreach($this->relation as $relation) + { + if( $relation[2] == $column ) + { + $new_column = $table_name.'.'.$column; + if(isset($this->display_as[$column])) + { + $display_as = $this->display_as[$column]; + unset($this->display_as[$column]); + $this->display_as[$new_column] = $display_as; + } + else + { + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); + } + + $column = $new_column; + $this->columns[$col_num] = $new_column; + } + } + } + + } + + if(isset($this->display_as[$column])) + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); + elseif(isset($field_types[$column])) + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); + else + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => + ucfirst(str_replace('_',' ',$column))); + + if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) + { + unset($this->columns[$col_num]); + } + } + + $this->columns_checked = true; + + } + + return $this->columns; + } + + /** + * + * Enter description here ... + */ + protected function get_add_fields() + { + if($this->add_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->add_fields)) + { + foreach($this->add_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + elseif(isset($field_types[$field]->display_as)) + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + else + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); + } + } + else + { + $this->add_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_add_field is initialize for this field name + if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) + continue; + + if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) + { + if(isset($this->display_as[$field->name])) + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->add_fields_checked = true; + } + return $this->add_fields; + } + + /** + * + * Enter description here ... + */ + protected function get_edit_fields() + { + if($this->edit_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->edit_fields)) + { + foreach($this->edit_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + else + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + } + } + else + { + $this->edit_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_edit_field is initialize for this field name + if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) + continue; + + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') + { + if(isset($this->display_as[$field->name])) + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->edit_fields_checked = true; + } + return $this->edit_fields; + } + + /** + * + * Enter description here ... + */ + protected function get_read_fields() + { + if($this->read_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->read_fields)) + { + foreach($this->read_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + else + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + } + } + else + { + $this->read_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_read_field is initialize for this field name + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) + continue; + + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') + { + if(isset($this->display_as[$field->name])) + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->read_fields_checked = true; + } + return $this->read_fields; + } + + public function order_by($order_by, $direction = 'asc') + { + $this->order_by = array($order_by,$direction); + + return $this; + } + + public function where($key, $value = NULL, $escape = TRUE) + { + $this->where[] = array($key,$value,$escape); + + return $this; + } + + public function or_where($key, $value = NULL, $escape = TRUE) + { + $this->or_where[] = array($key,$value,$escape); + + return $this; + } + + public function like($field, $match = '', $side = 'both') + { + $this->like[] = array($field, $match, $side); + + return $this; + } + + protected function having($key, $value = '', $escape = TRUE) + { + $this->having[] = array($key, $value, $escape); + + return $this; + } + + protected function or_having($key, $value = '', $escape = TRUE) + { + $this->or_having[] = array($key, $value, $escape); + + return $this; + } + + public function or_like($field, $match = '', $side = 'both') + { + $this->or_like[] = array($field, $match, $side); + + return $this; + } + + public function limit($limit, $offset = '') + { + $this->limit = array($limit,$offset); + + return $this; + } + + protected function _initialize_helpers() + { + $ci = &get_instance(); + + $ci->load->helper('url'); + $ci->load->helper('form'); + } + + protected function _initialize_variables() + { + $ci = &get_instance(); + $ci->load->config('grocery_crud'); + + $this->config = (object)array(); + + /** Initialize all the config variables into this object */ + $this->config->default_language = $ci->config->item('grocery_crud_default_language'); + $this->config->date_format = $ci->config->item('grocery_crud_date_format'); + $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); + $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); + $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); + $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); + $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); + $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); + $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); + $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); + $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); + $this->config->environment = $ci->config->item('grocery_crud_environment'); + $this->config->xss_clean = $ci->config->item('grocery_crud_xss_clean'); - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + /** Initialize default paths */ + $this->default_javascript_path = $this->default_assets_path.'/js'; + $this->default_css_path = $this->default_assets_path.'/css'; + $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; + $this->default_theme_path = $this->default_assets_path.'/themes'; - $this->set_basic_Layout(); + $this->character_limiter = $this->config->character_limiter; - $state_info = $this->getStateInfo(); + if ($this->character_limiter === 0 || $this->character_limiter === '0') { + $this->character_limiter = 1000000; //a very big number + } elseif($this->character_limiter === null || $this->character_limiter === false) { + $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value + } - $this->showList(false,$state_info); + if ($this->theme === null && !empty($this->config->default_theme)) { + $this->set_theme($this->config->default_theme); + } + } + + protected function _set_primary_keys_to_model() + { + if(!empty($this->primary_keys)) + { + foreach($this->primary_keys as $primary_key) + { + $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); + } + } + } + + /** + * Initialize all the required libraries and variables before rendering + */ + protected function pre_render() + { + $this->_initialize_variables(); + $this->_initialize_helpers(); + $this->_load_language(); + $this->state_code = $this->getStateCode(); + + if($this->basic_model === null) + $this->set_default_Model(); + + $this->set_basic_db_table($this->get_table()); + + $this->_load_date_format(); + + $this->_set_primary_keys_to_model(); + } + + /** + * + * Or else ... make it work! The web application takes decision of what to do and show it to the final user. + * Without this function nothing works. Here is the core of grocery CRUD project. + * + * @access public + */ + public function render() + { + $this->pre_render(); + + if( $this->state_code != 0 ) + { + $this->state_info = $this->getStateInfo(); + } + else + { + throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); + die(); + } + + switch ($this->state_code) { + case 15://success + case 1://list + if($this->unset_list) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); - break; + $state_info = $this->getStateInfo(); - case 2://add - if($this->unset_add) - { - throw new Exception('You don\'t have permissions for this operation', 14); - die(); - } + $this->showList(false,$state_info); - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + break; - $this->set_basic_Layout(); + case 2://add + if($this->unset_add) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } - $this->showAddForm(); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - break; + $this->set_basic_Layout(); - case 3://edit - if($this->unset_edit) - { - throw new Exception('You don\'t have permissions for this operation', 14); - die(); - } + $this->showAddForm(); - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + break; - $this->set_basic_Layout(); + case 3://edit + if($this->unset_edit) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } - $state_info = $this->getStateInfo(); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->showEditForm($state_info); + $this->set_basic_Layout(); - break; + $state_info = $this->getStateInfo(); - case 4://delete - if($this->unset_delete) - { - throw new Exception('This user is not allowed to do this operation', 14); - die(); - } + $this->showEditForm($state_info); - $state_info = $this->getStateInfo(); - $delete_result = $this->db_delete($state_info); + break; - $this->delete_layout( $delete_result ); - break; + case 4://delete + if($this->unset_delete) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } - case 5://insert - if($this->unset_add) - { - throw new Exception('This user is not allowed to do this operation', 14); - die(); - } + $state_info = $this->getStateInfo(); + $delete_result = $this->db_delete($state_info); - $state_info = $this->getStateInfo(); - $insert_result = $this->db_insert($state_info); + $this->delete_layout( $delete_result ); + break; - $this->insert_layout($insert_result); - break; + case 5://insert + if($this->unset_add) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } - case 6://update - if($this->unset_edit) - { - throw new Exception('This user is not allowed to do this operation', 14); - die(); - } + $state_info = $this->getStateInfo(); + $insert_result = $this->db_insert($state_info); - $state_info = $this->getStateInfo(); - $update_result = $this->db_update($state_info); + $this->insert_layout($insert_result); + break; - $this->update_layout( $update_result,$state_info); - break; + case 6://update + if($this->unset_edit) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } - case 7://ajax_list + $state_info = $this->getStateInfo(); + $update_result = $this->db_update($state_info); - if($this->unset_list) - { - throw new Exception('You don\'t have permissions for this operation', 14); - die(); - } + $this->update_layout( $update_result,$state_info); + break; - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + case 7://ajax_list - $this->set_basic_Layout(); + if($this->unset_list) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } - $state_info = $this->getStateInfo(); - $this->set_ajax_list_queries($state_info); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->showList(true); + $this->set_basic_Layout(); - break; + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); - case 8://ajax_list_info + $this->showList(true); - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + break; - $this->set_basic_Layout(); + case 8://ajax_list_info - $state_info = $this->getStateInfo(); - $this->set_ajax_list_queries($state_info); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->showListInfo(); - break; + $this->set_basic_Layout(); - case 9://insert_validation + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); - $validation_result = $this->db_insert_validation(); + $this->showListInfo(); + break; - $this->validation_layout($validation_result); - break; + case 9://insert_validation - case 10://update_validation + $validation_result = $this->db_insert_validation(); - $validation_result = $this->db_update_validation(); + $this->validation_layout($validation_result); + break; - $this->validation_layout($validation_result); - break; + case 10://update_validation - case 11://upload_file + $validation_result = $this->db_update_validation(); - $state_info = $this->getStateInfo(); + $this->validation_layout($validation_result); + break; - $upload_result = $this->upload_file($state_info); + case 11://upload_file - $this->upload_layout($upload_result, $state_info->field_name); - break; + $state_info = $this->getStateInfo(); - case 12://delete_file - $state_info = $this->getStateInfo(); + $upload_result = $this->upload_file($state_info); - $delete_file_result = $this->delete_file($state_info); + $this->upload_layout($upload_result, $state_info->field_name); + break; - $this->delete_file_layout($delete_file_result); - break; - /* + case 12://delete_file + $state_info = $this->getStateInfo(); + + $delete_file_result = $this->delete_file($state_info); + + $this->delete_file_layout($delete_file_result); + break; + /* case 13: //ajax_relation $state_info = $this->getStateInfo(); @@ -4833,79 +4833,79 @@ public function render() die(); break; */ - case 16: //export to excel - //a big number just to ensure that the table characters will not be cutted. - $this->character_limiter = 1000000; + case 16: //export to excel + //a big number just to ensure that the table characters will not be cutted. + $this->character_limiter = 1000000; - if($this->unset_export) - { - throw new Exception('You don\'t have permissions for this operation', 15); - die(); - } + if($this->unset_export) + { + throw new Exception('You don\'t have permissions for this operation', 15); + die(); + } - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->set_basic_Layout(); + $this->set_basic_Layout(); - $state_info = $this->getStateInfo(); - $this->set_ajax_list_queries($state_info); - $this->exportToExcel($state_info); - break; + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + $this->exportToExcel($state_info); + break; - case 17: //print - //a big number just to ensure that the table characters will not be cutted. - $this->character_limiter = 1000000; + case 17: //print + //a big number just to ensure that the table characters will not be cutted. + $this->character_limiter = 1000000; - if($this->unset_print) - { - throw new Exception('You don\'t have permissions for this operation', 15); - die(); - } + if($this->unset_print) + { + throw new Exception('You don\'t have permissions for this operation', 15); + die(); + } - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->set_basic_Layout(); + $this->set_basic_Layout(); - $state_info = $this->getStateInfo(); - $this->set_ajax_list_queries($state_info); - $this->print_webpage($state_info); - break; + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + $this->print_webpage($state_info); + break; - case grocery_CRUD_States::STATE_READ: - if($this->unset_read) - { - throw new Exception('You don\'t have permissions for this operation', 14); - die(); - } + case grocery_CRUD_States::STATE_READ: + if($this->unset_read) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } - if($this->theme === null) - $this->set_theme($this->default_theme); - $this->setThemeBasics(); + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); - $this->set_basic_Layout(); + $this->set_basic_Layout(); - $state_info = $this->getStateInfo(); + $state_info = $this->getStateInfo(); - $this->showReadForm($state_info); + $this->showReadForm($state_info); - break; + break; case grocery_CRUD_States::STATE_DELETE_MULTIPLE: - if($this->unset_delete) + if($this->unset_delete) { throw new Exception('This user is not allowed to do this operation'); die(); } - $state_info = $this->getStateInfo(); - $delete_result = $this->db_multiple_delete($state_info); + $state_info = $this->getStateInfo(); + $delete_result = $this->db_multiple_delete($state_info); - $this->delete_layout($delete_result); + $this->delete_layout($delete_result); break; @@ -4930,211 +4930,211 @@ public function render() break; - } - - return $this->get_layout(); - } - - protected function get_common_data() - { - $data = (object)array(); - - $data->subject = $this->subject; - $data->subject_plural = $this->subject_plural; - - return $data; - } - - /** - * - * Enter description here ... - */ - public function callback_before_insert($callback = null) - { - $this->callback_before_insert = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_after_insert($callback = null) - { - $this->callback_after_insert = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_insert($callback = null) - { - $this->callback_insert = $callback; - - return $this; - } - - - /** - * - * Enter description here ... - */ - public function callback_before_update($callback = null) - { - $this->callback_before_update = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_after_update($callback = null) - { - $this->callback_after_update = $callback; - - return $this; - } - - - /** - * - * Enter description here ... - * @param mixed $callback - */ - public function callback_update($callback = null) - { - $this->callback_update = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_before_delete($callback = null) - { - $this->callback_before_delete = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_after_delete($callback = null) - { - $this->callback_after_delete = $callback; - - return $this; - } - - /** - * - * Enter description here ... - */ - public function callback_delete($callback = null) - { - $this->callback_delete = $callback; - - return $this; - } + } + + return $this->get_layout(); + } + + protected function get_common_data() + { + $data = (object)array(); + + $data->subject = $this->subject; + $data->subject_plural = $this->subject_plural; + + return $data; + } + + /** + * + * Enter description here ... + */ + public function callback_before_insert($callback = null) + { + $this->callback_before_insert = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_insert($callback = null) + { + $this->callback_after_insert = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_insert($callback = null) + { + $this->callback_insert = $callback; + + return $this; + } + + + /** + * + * Enter description here ... + */ + public function callback_before_update($callback = null) + { + $this->callback_before_update = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_update($callback = null) + { + $this->callback_after_update = $callback; + + return $this; + } + + + /** + * + * Enter description here ... + * @param mixed $callback + */ + public function callback_update($callback = null) + { + $this->callback_update = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_before_delete($callback = null) + { + $this->callback_before_delete = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_delete($callback = null) + { + $this->callback_after_delete = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_delete($callback = null) + { + $this->callback_delete = $callback; + + return $this; + } /** * @param null $callback * @return $this */ - public function callback_before_clone($callback = null) - { - $this->callback_before_clone = $callback; + public function callback_before_clone($callback = null) + { + $this->callback_before_clone = $callback; - return $this; - } + return $this; + } /** * @param null $callback * @return $this */ - public function callback_after_clone($callback = null) - { - $this->callback_after_clone = $callback; + public function callback_after_clone($callback = null) + { + $this->callback_after_clone = $callback; - return $this; - } + return $this; + } /** * @param null $callback * @return $this */ - public function callback_clone($callback = null) - { - $this->callback_clone = $callback; - - return $this; - } - - - - /** - * - * Enter description here ... - * @param string $column - * @param mixed $callback - */ - public function callback_column($column ,$callback = null) - { - $this->callback_column[$column] = $callback; - - return $this; - } - - /** - * - * Enter description here ... - * @param string $field - * @param mixed $callback - */ - public function callback_field($field, $callback = null) - { - $this->callback_add_field[$field] = $callback; - $this->callback_edit_field[$field] = $callback; + public function callback_clone($callback = null) + { + $this->callback_clone = $callback; + + return $this; + } + + + + /** + * + * Enter description here ... + * @param string $column + * @param mixed $callback + */ + public function callback_column($column ,$callback = null) + { + $this->callback_column[$column] = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_field($field, $callback = null) + { + $this->callback_add_field[$field] = $callback; + $this->callback_edit_field[$field] = $callback; $this->callback_read_field[$field] = $callback; - return $this; - } - - /** - * - * Enter description here ... - * @param string $field - * @param mixed $callback - */ - public function callback_add_field($field, $callback = null) - { - $this->callback_add_field[$field] = $callback; - - return $this; - } - - /** - * - * Enter description here ... - * @param string $field - * @param mixed $callback - */ - public function callback_edit_field($field, $callback = null) - { - $this->callback_edit_field[$field] = $callback; - - return $this; - } + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_add_field($field, $callback = null) + { + $this->callback_add_field[$field] = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_edit_field($field, $callback = null) + { + $this->callback_edit_field[$field] = $callback; + + return $this; + } /** * @param $field @@ -5148,313 +5148,313 @@ public function callback_read_field($field, $callback = null) return $this; } - /** - * - * Callback that replace the default auto uploader - * - * @param mixed $callback - * @return grocery_CRUD - */ - public function callback_upload($callback = null) - { - $this->callback_upload = $callback; - - return $this; - } - - /** - * - * A callback that triggered before the upload functionality. This callback is suggested for validation checks - * @param mixed $callback - * @return grocery_CRUD - */ - public function callback_before_upload($callback = null) - { - $this->callback_before_upload = $callback; - - return $this; - } - - /** - * - * A callback that triggered after the upload functionality - * @param mixed $callback - * @return grocery_CRUD - */ - public function callback_after_upload($callback = null) - { - $this->callback_after_upload = $callback; - - return $this; - - } - - /** - * - * Gets the basic database table of our crud. - * @return string - */ - public function get_table() - { - if($this->basic_db_table_checked) - { - return $this->basic_db_table; - } - elseif( $this->basic_db_table !== null ) - { - if(!$this->table_exists($this->basic_db_table)) - { - throw new Exception('The table name does not exist. Please check you database and try again.',11); - die(); - } - $this->basic_db_table_checked = true; - return $this->basic_db_table; - } - else - { - //Last try , try to find the table from your view / function name!!! Not suggested but it works . - $last_chance_table_name = $this->get_method_name(); - if($this->table_exists($last_chance_table_name)) - { - $this->set_table($last_chance_table_name); - } - $this->basic_db_table_checked = true; - return $this->basic_db_table; - - } - - return false; - } - - /** - * - * The field names of the required fields - */ - public function required_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->required_fields = $args; - - return $this; - } - - /** - * Add the fields that they are as UNIQUE in the database structure - * - * @return grocery_CRUD - */ - public function unique_fields() - { - $args = func_get_args(); - - if(isset($args[0]) && is_array($args[0])) - { - $args = $args[0]; - } - - $this->_unique_fields = $args; - - return $this; - } - - /** - * - * Sets the basic database table that we will get our data. - * @param string $table_name - * @return grocery_CRUD - */ - public function set_table($table_name) - { - if(!empty($table_name) && $this->basic_db_table === null) - { - $this->basic_db_table = $table_name; - } - elseif(!empty($table_name)) - { - throw new Exception('You have already insert a table name once...', 1); - } - else - { - throw new Exception('The table name cannot be empty.', 2); - die(); - } - - return $this; - } - - /** - * Set a full URL path to this method. - * - * This method is useful when the path is not specified correctly. - * Especially when we are using routes. - * For example: - * Let's say we have the path http://www.example.com/ however the original url path is - * http://www.example.com/example/index . We have to specify the url so we can have - * all the CRUD operations correctly. - * The url path has to be set from this method like this: - * - * $crud->set_crud_url_path(site_url('example/index')); - * - * - * @param string $crud_url_path - * @param string $list_url_path - * @return grocery_CRUD - */ - public function set_crud_url_path($crud_url_path, $list_url_path = null) - { - $this->crud_url_path = $crud_url_path; - - //If the list_url_path is empty so we are guessing that the list_url_path - //will be the same with crud_url_path - $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; - - return $this; - } - - /** - * - * Set a subject to understand what type of CRUD you use. + /** + * + * Callback that replace the default auto uploader + * + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_upload($callback = null) + { + $this->callback_upload = $callback; + + return $this; + } + + /** + * + * A callback that triggered before the upload functionality. This callback is suggested for validation checks + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_before_upload($callback = null) + { + $this->callback_before_upload = $callback; + + return $this; + } + + /** + * + * A callback that triggered after the upload functionality + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_after_upload($callback = null) + { + $this->callback_after_upload = $callback; + + return $this; + + } + + /** + * + * Gets the basic database table of our crud. + * @return string + */ + public function get_table() + { + if($this->basic_db_table_checked) + { + return $this->basic_db_table; + } + elseif( $this->basic_db_table !== null ) + { + if(!$this->table_exists($this->basic_db_table)) + { + throw new Exception('The table name does not exist. Please check you database and try again.',11); + die(); + } + $this->basic_db_table_checked = true; + return $this->basic_db_table; + } + else + { + //Last try , try to find the table from your view / function name!!! Not suggested but it works . + $last_chance_table_name = $this->get_method_name(); + if($this->table_exists($last_chance_table_name)) + { + $this->set_table($last_chance_table_name); + } + $this->basic_db_table_checked = true; + return $this->basic_db_table; + + } + + return false; + } + + /** + * + * The field names of the required fields + */ + public function required_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->required_fields = $args; + + return $this; + } + + /** + * Add the fields that they are as UNIQUE in the database structure + * + * @return grocery_CRUD + */ + public function unique_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->_unique_fields = $args; + + return $this; + } + + /** + * + * Sets the basic database table that we will get our data. + * @param string $table_name + * @return grocery_CRUD + */ + public function set_table($table_name) + { + if(!empty($table_name) && $this->basic_db_table === null) + { + $this->basic_db_table = $table_name; + } + elseif(!empty($table_name)) + { + throw new Exception('You have already insert a table name once...', 1); + } + else + { + throw new Exception('The table name cannot be empty.', 2); + die(); + } + + return $this; + } + + /** + * Set a full URL path to this method. + * + * This method is useful when the path is not specified correctly. + * Especially when we are using routes. + * For example: + * Let's say we have the path http://www.example.com/ however the original url path is + * http://www.example.com/example/index . We have to specify the url so we can have + * all the CRUD operations correctly. + * The url path has to be set from this method like this: + * + * $crud->set_crud_url_path(site_url('example/index')); + * + * + * @param string $crud_url_path + * @param string $list_url_path + * @return grocery_CRUD + */ + public function set_crud_url_path($crud_url_path, $list_url_path = null) + { + $this->crud_url_path = $crud_url_path; + + //If the list_url_path is empty so we are guessing that the list_url_path + //will be the same with crud_url_path + $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; + + return $this; + } + + /** + * + * Set a subject to understand what type of CRUD you use. * ---------------------------------------------------------------------------------------------- * Subject_plural: Sets the subject to its plural form. For example the plural * of "Customer" is "Customers", "Product" is "Products"... e.t.c. - * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' + * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' * and the $subject_plural will be 'Categories' - * @param string $subject - * @param string $subject_plural - * @return grocery_CRUD - */ - public function set_subject($subject, $subject_plural = null) - { - $this->subject = $subject; + * @param string $subject + * @param string $subject_plural + * @return grocery_CRUD + */ + public function set_subject($subject, $subject_plural = null) + { + $this->subject = $subject; $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; - return $this; - } - - /** - * - * Enter description here ... - * @param $title - * @param $image_url - * @param $url - * @param $css_class - * @param $url_callback - */ - public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) - { - $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string - - $this->actions[$unique_id] = (object)array( - 'label' => $label, - 'image_url' => $image_url, - 'link_url' => $link_url, - 'css_class' => $css_class, - 'url_callback' => $url_callback, - 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false - ); - - return $this; - } - - /** - * - * Set a simple 1-n foreign key relation - * @param string $field_name - * @param string $related_table - * @param string $related_title_field - * @param mixed $where_clause - * @param string $order_by + return $this; + } + + /** + * + * Enter description here ... + * @param $title + * @param $image_url + * @param $url + * @param $css_class + * @param $url_callback + */ + public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) + { + $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string + + $this->actions[$unique_id] = (object)array( + 'label' => $label, + 'image_url' => $image_url, + 'link_url' => $link_url, + 'css_class' => $css_class, + 'url_callback' => $url_callback, + 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false + ); + + return $this; + } + + /** + * + * Set a simple 1-n foreign key relation + * @param string $field_name + * @param string $related_table + * @param string $related_title_field + * @param mixed $where_clause + * @param string $order_by * @return Grocery_CRUD - */ - public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) - { - $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); - return $this; - } - - /** - * - * Sets a relation with n-n relationship. - * @param string $field_name - * @param string $relation_table - * @param string $selection_table - * @param string $primary_key_alias_to_this_table - * @param string $primary_key_alias_to_selection_table - * @param string $title_field_selection_table - * @param string $priority_field_relation_table - * @param mixed $where_clause + */ + public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) + { + $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); + return $this; + } + + /** + * + * Sets a relation with n-n relationship. + * @param string $field_name + * @param string $relation_table + * @param string $selection_table + * @param string $primary_key_alias_to_this_table + * @param string $primary_key_alias_to_selection_table + * @param string $title_field_selection_table + * @param string $priority_field_relation_table + * @param mixed $where_clause * @return Grocery_CRUD - */ - public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) - { - $this->relation_n_n[$field_name] = - (object)array( - 'field_name' => $field_name, - 'relation_table' => $relation_table, - 'selection_table' => $selection_table, - 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, - 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , - 'title_field_selection_table' => $title_field_selection_table , - 'priority_field_relation_table' => $priority_field_relation_table, - 'where_clause' => $where_clause - ); - - return $this; - } - - /** - * - * Transform a field to an upload field - * - * @param string $field_name - * @param string $upload_path + */ + public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) + { + $this->relation_n_n[$field_name] = + (object)array( + 'field_name' => $field_name, + 'relation_table' => $relation_table, + 'selection_table' => $selection_table, + 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, + 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , + 'title_field_selection_table' => $title_field_selection_table , + 'priority_field_relation_table' => $priority_field_relation_table, + 'where_clause' => $where_clause + ); + + return $this; + } + + /** + * + * Transform a field to an upload field + * + * @param string $field_name + * @param string $upload_path * @return Grocery_CRUD - */ - public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') - { - $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' - ? substr($upload_dir,0,-1) - : $upload_dir; - $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; - - /** Check if the upload Url folder exists. If not then throw an exception **/ - if (!is_dir(FCPATH.$upload_dir)) { - throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name + */ + public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') + { + $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' + ? substr($upload_dir,0,-1) + : $upload_dir; + $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; + + /** Check if the upload Url folder exists. If not then throw an exception **/ + if (!is_dir(FCPATH.$upload_dir)) { + throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name \"".$field_name."\" doesn't exists. Please create the folder and try again."); - } - - $this->upload_fields[$field_name] = (object) array( - 'field_name' => $field_name, - 'upload_path' => $upload_dir, - 'allowed_file_types' => $allowed_file_types, - 'encrypted_field_name' => $this->_unique_field_name($field_name)); - return $this; - } + } + + $this->upload_fields[$field_name] = (object) array( + 'field_name' => $field_name, + 'upload_path' => $upload_dir, + 'allowed_file_types' => $allowed_file_types, + 'encrypted_field_name' => $this->_unique_field_name($field_name)); + return $this; + } } if(defined('CI_VERSION')) { - $ci = &get_instance(); - $ci->load->library('Form_validation'); - - class grocery_CRUD_Form_validation extends CI_Form_validation{ - - public $CI; - public $_field_data = array(); - public $_config_rules = array(); - public $_error_array = array(); - public $_error_messages = array(); - public $_error_prefix = '

    '; - public $_error_suffix = '

    '; - public $error_string = ''; - public $_safe_form_data = FALSE; - } + $ci = &get_instance(); + $ci->load->library('Form_validation'); + + class grocery_CRUD_Form_validation extends CI_Form_validation{ + + public $CI; + public $_field_data = array(); + public $_config_rules = array(); + public $_error_array = array(); + public $_error_messages = array(); + public $_error_prefix = '

    '; + public $_error_suffix = '

    '; + public $error_string = ''; + public $_safe_form_data = FALSE; + } } /* @@ -5514,19 +5514,19 @@ function __construct($options=null) { // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); foreach($options as $option_name => $option) { - $this->options[$option_name] = $option; + $this->options[$option_name] = $option; } } } function getFullUrl() { - return - (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). - (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). - (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. - (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || - $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). - substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); + return + (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). + (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). + (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. + (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || + $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). + substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); } private function get_file_object($file_name) { @@ -5596,14 +5596,14 @@ private function create_scaled_image($file_name, $options) { $src_img = $image_method = null; } $success = $src_img && @imagecopyresampled( - $new_img, - $src_img, - 0, 0, 0, 0, - $new_width, - $new_height, - $img_width, - $img_height - ) && $write_image($new_img, $new_file_path); + $new_img, + $src_img, + 0, 0, 0, 0, + $new_width, + $new_height, + $img_width, + $img_height + ) && $write_image($new_img, $new_file_path); // Free up memory (imagedestroy does not delete files): @imagedestroy($src_img); @imagedestroy($new_img); @@ -5612,26 +5612,26 @@ private function create_scaled_image($file_name, $options) { private function has_error($uploaded_file, $file, $error) { if ($error) { - switch($error) { - case UPLOAD_ERR_INI_SIZE: - return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; - break; - case UPLOAD_ERR_PARTIAL: - return 'The uploaded file was only partially uploaded.'; - break; - case UPLOAD_ERR_NO_FILE: - return 'No file was uploaded.'; - break; - case UPLOAD_ERR_CANT_WRITE: - return 'Failed to write file to disk.'; - break; - case UPLOAD_ERR_EXTENSION: - return 'File upload stopped by extension.'; - break; - default: - return $error; - break; - } + switch($error) { + case UPLOAD_ERR_INI_SIZE: + return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; + break; + case UPLOAD_ERR_PARTIAL: + return 'The uploaded file was only partially uploaded.'; + break; + case UPLOAD_ERR_NO_FILE: + return 'No file was uploaded.'; + break; + case UPLOAD_ERR_CANT_WRITE: + return 'Failed to write file to disk.'; + break; + case UPLOAD_ERR_EXTENSION: + return 'File upload stopped by extension.'; + break; + default: + return $error; + break; + } } if (!preg_match($this->options['accept_file_types'], $file->name)) { return 'acceptFileTypes'; @@ -5645,7 +5645,7 @@ private function has_error($uploaded_file, $file, $error) { if ($this->options['max_file_size'] && ( $file_size > $this->options['max_file_size'] || $file->size > $this->options['max_file_size']) - ) { + ) { return 'maxFileSize'; } if ($this->options['min_file_size'] && @@ -5654,7 +5654,7 @@ private function has_error($uploaded_file, $file, $error) { } if (is_int($this->options['max_number_of_files']) && ( count($this->get_file_objects()) >= $this->options['max_number_of_files']) - ) { + ) { return 'maxNumberOfFiles'; } return $error; @@ -5681,43 +5681,43 @@ private function trim_file_name($name, $type) { } private function _transliterate_characters($file_name) - { - include($this->default_config_path.'/translit_chars.php'); - if ( isset($translit_characters)) - { - $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); - } + { + include($this->default_config_path.'/translit_chars.php'); + if ( isset($translit_characters)) + { + $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); + } - $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); - $file_name = str_replace(" ", "-", $file_name); + $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); + $file_name = str_replace(" ", "-", $file_name); - return preg_replace('/\-+/', '-', trim($file_name, '-')); - } + return preg_replace('/\-+/', '-', trim($file_name, '-')); + } private function orient_image($file_path) { - $exif = exif_read_data($file_path); - $orientation = intval(@$exif['Orientation']); - if (!in_array($orientation, array(3, 6, 8))) { - return false; - } - $image = @imagecreatefromjpeg($file_path); - switch ($orientation) { - case 3: - $image = @imagerotate($image, 180, 0); - break; - case 6: - $image = @imagerotate($image, 270, 0); - break; - case 8: - $image = @imagerotate($image, 90, 0); - break; - default: - return false; - } - $success = imagejpeg($image, $file_path); - // Free up memory (imagedestroy does not delete files): - @imagedestroy($image); - return $success; + $exif = exif_read_data($file_path); + $orientation = intval(@$exif['Orientation']); + if (!in_array($orientation, array(3, 6, 8))) { + return false; + } + $image = @imagecreatefromjpeg($file_path); + switch ($orientation) { + case 3: + $image = @imagerotate($image, 180, 0); + break; + case 6: + $image = @imagerotate($image, 270, 0); + break; + case 8: + $image = @imagerotate($image, 90, 0); + break; + default: + return false; + } + $success = imagejpeg($image, $file_path); + // Free up memory (imagedestroy does not delete files): + @imagedestroy($image); + return $success; } private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { @@ -5752,9 +5752,9 @@ private function handle_file_upload($uploaded_file, $name, $size, $type, $error) } $file_size = filesize($file_path); if ($file_size === $file->size) { - if ($this->options['orient_image']) { - $this->orient_image($file_path); - } + if ($this->options['orient_image']) { + $this->orient_image($file_path); + } $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->name, $options)) { @@ -5853,4 +5853,5 @@ public function delete() { header('Content-type: application/json'); echo json_encode($success); } + } diff --git a/application/libraries/image_moo.php b/application/libraries/image_moo.php old mode 100755 new mode 100644 index 9aad577..c421130 --- a/application/libraries/image_moo.php +++ b/application/libraries/image_moo.php @@ -1,19 +1,18 @@ ', $close = '

    ') - //---------------------------------------------------------------------------------------------------------- - // returns the errors formatted as needed, same as CI doed - //---------------------------------------------------------------------------------------------------------- - { - $str = ''; - foreach ($this->error_msg as $val) { - $str .= $open . $val . $close; - } - return $str; - } - - public function check_gd() - //---------------------------------------------------------------------------------------------------------- - // verification util to see if you can use image_moo - //---------------------------------------------------------------------------------------------------------- - { - if (!extension_loaded('gd')) { - if (!dl('gd.so')) { - $this->set_error('GD library does not appear to be loaded'); - return false; - } - } - if (function_exists('gd_info')) { - $gdarray = @gd_info(); - $versiontxt = ereg_replace('[[:alpha:][:space:]()]+', '', $gdarray['GD Version']); - $versionparts = explode('.', $versiontxt); - if ($versionparts[0] == "2") { - return true; - } else { - $this->set_error('Requires GD2, this reported as ' . $versiontxt); - return false; - } - } else { - $this->set_error('Could not verify GD version'); - return false; - } - } - - private function set_error($msg) - //---------------------------------------------------------------------------------------------------------- - // Set an error message - //---------------------------------------------------------------------------------------------------------- - { - $this->errors = true; - $this->error_msg[] = $msg; - } - - function save_dynamic($filename = "") - //---------------------------------------------------------------------------------------------------------- - // Saves the temp image as a dynamic image - // e.g. direct output to the browser - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // ok, lets go! - if ($filename == "") $filename = rand(1000, 999999) . ".jpg"; // send as jpeg - $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); - header("Content-disposition: filename=$filename;"); - header('Content-transfer-Encoding: binary'); - header('Last-modified: ' . gmdate('D, d M Y H:i:s')); - switch ($ext) { - case "GIF" : - header("Content-type: image/gif"); - imagegif($this->temp_image); - return $this; - break; - case "JPG" : - case "JPEG" : - header("Content-type: image/jpeg"); - imagejpeg($this->temp_image, null, $this->jpeg_quality); - return $this; - break; - case "PNG" : - header("Content-type: image/png"); - imagepng($this->temp_image); - return $this; - break; - } - $this->set_error('Unable to save, extension not GIF/JPEG/JPG/PNG'); - return $this; - } - - private function _check_image() - //---------------------------------------------------------------------------------------------------------- - // checks that we have an image loaded - //---------------------------------------------------------------------------------------------------------- + // image vars + private $main_image=""; + private $watermark_image; + private $temp_image; + private $jpeg_quality=75; + private $background_colour="#ffffff"; + private $watermark_method; + + // other + private $filename=""; + + // watermark stuff, opacity + private $watermark_transparency=50; + + // reported errors + public $errors=FALSE; + private $error_msg = array(); + + // image info + public $width=0; + public $height=0; + + function Image_moo() + //---------------------------------------------------------------------------------------------------------- + // create stuff here as needed + //---------------------------------------------------------------------------------------------------------- + { + log_message('debug', "Image Moo Class Initialized"); + } + + private function _clear_errors() + //---------------------------------------------------------------------------------------------------------- + // load a resource + //---------------------------------------------------------------------------------------------------------- + { + $this->error_msg = array(); + } + + private function set_error($msg) + //---------------------------------------------------------------------------------------------------------- + // Set an error message + //---------------------------------------------------------------------------------------------------------- + { + $this->errors = TRUE; + $this->error_msg[] = $msg; + } + + public function display_errors($open = '

    ', $close = '

    ') + //---------------------------------------------------------------------------------------------------------- + // returns the errors formatted as needed, same as CI doed + //---------------------------------------------------------------------------------------------------------- + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + return $str; + } + + public function check_gd() + //---------------------------------------------------------------------------------------------------------- + // verification util to see if you can use image_moo + //---------------------------------------------------------------------------------------------------------- + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + $this->set_error('GD library does not appear to be loaded'); + return FALSE; + } + } + if (function_exists('gd_info')) + { + $gdarray = @gd_info(); + $versiontxt = ereg_replace('[[:alpha:][:space:]()]+', '', $gdarray['GD Version']); + $versionparts=explode('.',$versiontxt); + if ($versionparts[0]=="2") + { + return TRUE; + } + else + { + $this->set_error('Requires GD2, this reported as '.$versiontxt); + return FALSE; + } + } + else + { + $this->set_error('Could not verify GD version'); + return FALSE; + } + } + + private function _check_image() + //---------------------------------------------------------------------------------------------------------- + // checks that we have an image loaded + //---------------------------------------------------------------------------------------------------------- + { + if (!is_resource($this->main_image)) + { + $this->set_error("No main image loaded!"); + return FALSE; + } + else + { + return TRUE; + } + } + + function save_dynamic($filename="") + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as a dynamic image + // e.g. direct output to the browser + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // ok, lets go! + if ($filename=="") $filename=rand(1000,999999).".jpg"; // send as jpeg + $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); + header("Content-disposition: filename=$filename;"); + header('Content-transfer-Encoding: binary'); + header('Last-modified: '.gmdate('D, d M Y H:i:s')); + switch ($ext) + { + case "GIF" : + header("Content-type: image/gif"); + imagegif($this->temp_image); + return $this; + break; + case "JPG" : + case "JPEG" : + header("Content-type: image/jpeg"); + imagejpeg($this->temp_image, NULL, $this->jpeg_quality); + return $this; + break; + case "PNG" : + header("Content-type: image/png"); + imagepng($this->temp_image); + return $this; + break; + } + $this->set_error('Unable to save, extension not GIF/JPEG/JPG/PNG'); + return $this; + } + + function save_pa($prepend="", $append="", $overwrite=FALSE) + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as the filename specified, + // overwrite = true of false + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // get current file parts + $parts=pathinfo($this->filename); + + // save + $this->save($parts["dirname"].'/'.$prepend.$parts['filename'].$append.'.'.$parts["extension"], $overwrite); + + return $this; + } + + function save($filename,$overwrite=FALSE) + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as the filename specified, + // overwrite = true of false + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // check if it already exists + if (!$overwrite) + { + // don't overwrite, so check for file + if (file_exists($filename)) + { + $this->set_error('File exists, overwrite is FALSE, could not save over file '.$filename); + return $this; + } + } + + // find out the type of file to save + $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); + switch ($ext) + { + case "GIF" : + imagegif($this->temp_image, $filename); + return $this; + break; + case "JPG" : + case "JPEG" : + imagejpeg($this->temp_image, $filename, $this->jpeg_quality); + return $this; + break; + case "PNG" : + imagepng($this->temp_image, $filename); + return $this; + break; + } + + // invalid filetype?! + $this->set_error('Do no know what '.$ext.' filetype is in filename '.$filename); + return $this; + } + + private function _load_image($filename) + //---------------------------------------------------------------------------------------------------------- + // private function to load a resource + //---------------------------------------------------------------------------------------------------------- + { + // check the request file can be located + if (!file_exists($filename)) + { + $this->set_error('Could not locate file '.$filename); + return FALSE; + } + + // get image info about this file + $image_info=getimagesize($filename); + + // load file depending on mimetype + switch ($image_info["mime"]) + { + case "image/gif" : + return imagecreatefromgif($filename); + break; + case "image/jpeg" : + return imagecreatefromjpeg($filename); + break; + case "image/png" : + return imagecreatefrompng($filename); + break; + } + + // invalid filetype?! + $this->set_error('Unable to load '.$filename.' filetype '.$image_info["mime"].'not recognised'); + return FALSE; + } + + public function load($filename) + //---------------------------------------------------------------------------------------------------------- + // Load an image, public function + //---------------------------------------------------------------------------------------------------------- + { + // new image, reset error messages + $this->_clear_errors(); + + // remove temporary image stored + $this->clear_temp(); + + // save filename + $this->filename=$filename; + + // reset width and height + $this->width = 0; + $this->height = 0; + + // load it + $this->main_image = $this->_load_image($filename); + + // no error, then get the dminesions set + if ($this->main_image <> FALSE) + { + $this->width = imageSX($this->main_image); + $this->height = imageSY($this->main_image); + } + + // return the object + return $this; + } + + public function load_watermark($filename, $transparent_x=NULL, $transparent_y=NULL) + //---------------------------------------------------------------------------------------------------------- + // Load an image, public function + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + $this->watermark_image = $this->_load_image($filename); + + if(is_resource($this->watermark_image)) + { + $this->watermark_method = 1; + if(($transparent_x <> NULL) AND ($transparent_y <> NULL)) + { + // get the top left corner colour allocation + $tpcolour = imagecolorat($this->watermark_image, $transparent_x, $transparent_y); + + // set this as the transparent colour + imagecolortransparent($this->watermark_image, $tpcolour); + + // $set diff method + $this->watermark_method = 2; + } + } + + // return this object + return $this; + } + + public function set_watermark_transparency($transparency=50) + //---------------------------------------------------------------------------------------------------------- + // Sets the quality that jpeg will be saved at + //---------------------------------------------------------------------------------------------------------- + { + $this->watermark_transparency = $transparency; + return $this; + } + + public function set_background_colour($colour="#ffffff") + //---------------------------------------------------------------------------------------------------------- + // Sets teh background colour to use on rotation and padding for resize + //---------------------------------------------------------------------------------------------------------- + { + $this->background_colour = $this->_html2rgb($colour); + return $this; + } + + public function set_jpeg_quality($quality=75) + //---------------------------------------------------------------------------------------------------------- + // Sets the quality that jpeg will be saved at + //---------------------------------------------------------------------------------------------------------- + { + $this->jpeg_quality = $quality; + return $this; + } + + private function _copy_to_temp_if_needed() + //---------------------------------------------------------------------------------------------------------- + // If temp image is empty, e.g. not resized or done anything then just copy main image + //---------------------------------------------------------------------------------------------------------- + { + if (!is_resource($this->temp_image)) + { + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($this->width, $this->height); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$this->width.' x '.$this->height); + return FALSE; + } + + // copy image to temp workspace + imagecopy($this->temp_image, $this->main_image, 0, 0, 0, 0, $this->width, $this->height); + } + } + + public function clear() + //---------------------------------------------------------------------------------------------------------- + // clear everything! + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->main_image)) imagedestroy($this->main_image); + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + if(is_resource($this->temp_image)) imagedestroy($this->temp_image); + return $this; + } + + public function clear_temp() + //---------------------------------------------------------------------------------------------------------- + // you may want to revert back to teh original image to work on, e.g. watermark, this clears temp + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->temp_image)) imagedestroy($this->temp_image); + return $this; + } + + public function resize_crop($mw,$mh) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using EXACT boundaries mw,mh (max width and max height) + // this is proportional and crops the image centrally to fit + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($mw,$mh); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$mw.' x '.$mh); + return $this; + } + + // work out best positions for copy + $wx=$this->width / $mw; + $wy=$this->height / $mh; + if ($wx >= $wy) + { + // use full height + $sy = 0; + $sy2 = $this->height; + + // calcs + $calc_width = $mw * $wy; + $sx = ($this->width - $calc_width) / 2; + $sx2 = $calc_width; + } + else + { + // use full width + $sx = 0; + $sx2 = $this->width; + + // calcs + $calc_height = $mh * $wx; + $sy = ($this->height - $calc_height) / 2; + $sy2 = $calc_height; + } + + // copy section + imagecopyresampled($this->temp_image, $this->main_image, 0, 0, $sx, $sy, $mw, $mh, $sx2, $sy2); + return $this; + } + + public function resize($mw, $mh, $pad=FALSE) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using boundaries mw,mh (max width or max height) + // this is proportional, pad to true will set it in the middle of area size + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // calc new dimensions + if( $this->width > $mw || $this->height > $mh ) { +// if( $this->width > $this->height ) { could calc wronf - Cole Thorsen swapped to his suggestion + if( ($this->width / $this->height) > ($mw / $mh) ) { + $tnw = $mw; + $tnh = $tnw * $this->height / $this->width; + } else { + $tnh = $mh; + $tnw = $tnh * $this->width / $this->height; + } + } else { + $tnw = $this->width; + $tnh = $this->height; + } + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + if ($pad) + { + $tx = $mw; + $ty = $mh; + $px = ($mw - $tnw) / 2; + $py = ($mh - $tnh) / 2; + } + else + { + $tx = $tnw; + $ty = $tnh; + $px = 0; + $py = 0; + } + $this->temp_image = imagecreatetruecolor($tx,$ty); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$tx.' x '.$ty); + return $this; + } + + // if padding, fill background + if ($pad) + { + $col = $this->_html2rgb($this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + imagefilledrectangle($this->temp_image, 0, 0, $tx, $ty, $bg); + } + + // copy resized + imagecopyresampled($this->temp_image, $this->main_image, $px, $py, 0, 0, $tnw, $tnh, $this->width, $this->height); + return $this; + } + + public function stretch($mw,$mh) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using boundaries mw,mh (max width or max height) + // does not retain proportions + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($mw, $mh); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$mh.' x '.$mw); + return $this; + } + + // copy resized (stethced, proportions not kept); + imagecopyresampled($this->temp_image, $this->main_image, 0, 0, 0, 0, $mw, $mh, $this->width, $this->height); + return $this; + } + + public function crop($x1, $y1, $x2, $y2) + //---------------------------------------------------------------------------------------------------------- + // crop the main image to temp image using coords + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // check dimensions + if ($x1 < 0 || $y1 < 0 || $x2 - $x1 > $this->width || $y2 - $y1 > $this->height) + { + $this->set_error('Invalid crop dimensions, either - passed or width/heigh too large '.$x1.'/'.$y1.' x '.$x2.'/'.$y2); + return $this; + } + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($x2-$x1, $y2-$y1); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$x2-$x1.' x '.$y2-$y1); + return $this; + } + + // copy cropped portion + imagecopy($this->temp_image, $this->main_image, 0, 0, $x1, $y1, $x2 - $x1, $y2 - $y1); + return $this; + } + + private function _html2rgb($colour) + //---------------------------------------------------------------------------------------------------------- + // convert #aa0011 to a php colour array + //---------------------------------------------------------------------------------------------------------- { - if (!is_resource($this->main_image)) { - $this->set_error("No main image loaded!"); - return false; - } else { - return true; - } - } - - private function _copy_to_temp_if_needed() - //---------------------------------------------------------------------------------------------------------- - // If temp image is empty, e.g. not resized or done anything then just copy main image - //---------------------------------------------------------------------------------------------------------- - { - if (!is_resource($this->temp_image)) { - // create a temp based on new dimensions - $this->temp_image = imagecreatetruecolor($this->width, $this->height); - - // check it - if (!is_resource($this->temp_image)) { - $this->set_error('Unable to create temp image sized ' . $this->width . ' x ' . $this->height); - return false; - } - - // copy image to temp workspace - imagecopy($this->temp_image, $this->main_image, 0, 0, 0, 0, $this->width, $this->height); - } - } - - function save_pa($prepend = "", $append = "", $overwrite = false) - //---------------------------------------------------------------------------------------------------------- - // Saves the temp image as the filename specified, - // overwrite = true of false - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // get current file parts - $parts = pathinfo($this->filename); - - // save - $this->save($parts["dirname"] . '/' . $prepend . $parts['filename'] . $append . '.' . $parts["extension"], $overwrite); - - return $this; - } - - function save($filename, $overwrite = false) - //---------------------------------------------------------------------------------------------------------- - // Saves the temp image as the filename specified, - // overwrite = true of false - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // check if it already exists - if (!$overwrite) { - // don't overwrite, so check for file - if (file_exists($filename)) { - $this->set_error('File exists, overwrite is FALSE, could not save over file ' . $filename); - return $this; - } - } - - // find out the type of file to save - $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); - switch ($ext) { - case "GIF" : - imagegif($this->temp_image, $filename); - return $this; - break; - case "JPG" : - case "JPEG" : - imagejpeg($this->temp_image, $filename, $this->jpeg_quality); - return $this; - break; - case "PNG" : - imagepng($this->temp_image, $filename); - return $this; - break; - } - - // invalid filetype?! - $this->set_error('Do no know what ' . $ext . ' filetype is in filename ' . $filename); - return $this; - } - - public function load($filename) - //---------------------------------------------------------------------------------------------------------- - // Load an image, public function - //---------------------------------------------------------------------------------------------------------- - { - // new image, reset error messages - $this->_clear_errors(); - - // remove temporary image stored - $this->clear_temp(); - - // save filename - $this->filename = $filename; - - // reset width and height - $this->width = 0; - $this->height = 0; - - // load it - $this->main_image = $this->_load_image($filename); - - // no error, then get the dminesions set - if ($this->main_image <> false) { - $this->width = imageSX($this->main_image); - $this->height = imageSY($this->main_image); - } - - // return the object - return $this; - } - - private function _clear_errors() - //---------------------------------------------------------------------------------------------------------- - // load a resource - //---------------------------------------------------------------------------------------------------------- - { - $this->error_msg = array(); - } - - public function clear_temp() - //---------------------------------------------------------------------------------------------------------- - // you may want to revert back to teh original image to work on, e.g. watermark, this clears temp - //---------------------------------------------------------------------------------------------------------- - { - if (is_resource($this->temp_image)) imagedestroy($this->temp_image); - return $this; - } - - private function _load_image($filename) - //---------------------------------------------------------------------------------------------------------- - // private function to load a resource - //---------------------------------------------------------------------------------------------------------- - { - // check the request file can be located - if (!file_exists($filename)) { - $this->set_error('Could not locate file ' . $filename); - return false; - } - - // get image info about this file - $image_info = getimagesize($filename); - - // load file depending on mimetype - switch ($image_info["mime"]) { - case "image/gif" : - return imagecreatefromgif($filename); - break; - case "image/jpeg" : - return imagecreatefromjpeg($filename); - break; - case "image/png" : - return imagecreatefrompng($filename); - break; - } - - // invalid filetype?! - $this->set_error('Unable to load ' . $filename . ' filetype ' . $image_info["mime"] . 'not recognised'); - return false; - } - - public function load_watermark($filename, $transparent_x = null, $transparent_y = null) - //---------------------------------------------------------------------------------------------------------- - // Load an image, public function - //---------------------------------------------------------------------------------------------------------- - { - if (is_resource($this->watermark_image)) imagedestroy($this->watermark_image); - $this->watermark_image = $this->_load_image($filename); - - if (is_resource($this->watermark_image)) { - $this->watermark_method = 1; - if (($transparent_x <> null) AND ($transparent_y <> null)) { - // get the top left corner colour allocation - $tpcolour = imagecolorat($this->watermark_image, $transparent_x, $transparent_y); - - // set this as the transparent colour - imagecolortransparent($this->watermark_image, $tpcolour); - - // $set diff method - $this->watermark_method = 2; - } - } - - // return this object - return $this; - } - - public function set_watermark_transparency($transparency = 50) - //---------------------------------------------------------------------------------------------------------- - // Sets the quality that jpeg will be saved at - //---------------------------------------------------------------------------------------------------------- - { - $this->watermark_transparency = $transparency; - return $this; - } - - public function set_background_colour($colour = "#ffffff") - //---------------------------------------------------------------------------------------------------------- - // Sets teh background colour to use on rotation and padding for resize - //---------------------------------------------------------------------------------------------------------- - { - $this->background_colour = $this->_html2rgb($colour); - return $this; - } - - private function _html2rgb($colour) - //---------------------------------------------------------------------------------------------------------- - // convert #aa0011 to a php colour array - //---------------------------------------------------------------------------------------------------------- - { - if (is_array($colour)) { - if (count($colour) == 3) return $colour; // rgb sent as an array so use it - $this->set_error('Colour error, array sent not 3 elements, expected array(r,g,b)'); - return false; - } + if (is_array($colour)) + { + if (count($colour)==3) return $colour; // rgb sent as an array so use it + $this->set_error('Colour error, array sent not 3 elements, expected array(r,g,b)'); + return false; + } if ($colour[0] == '#') $colour = substr($colour, 1); - if (strlen($colour) == 6) { - list($r, $g, $b) = array($colour[0] . $colour[1], - $colour[2] . $colour[3], - $colour[4] . $colour[5]); - } elseif (strlen($colour) == 3) { - list($r, $g, $b) = array($colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2]); - } else { - $this->set_error('Colour error, value sent not #RRGGBB or RRGGBB, and not array(r,g,b)'); + if (strlen($colour) == 6) + { + list($r, $g, $b) = array($colour[0].$colour[1], + $colour[2].$colour[3], + $colour[4].$colour[5]); + } + elseif (strlen($colour) == 3) + { + list($r, $g, $b) = array($colour[0].$colour[0], $colour[1].$colour[1], $colour[2].$colour[2]); + } + else + { + $this->set_error('Colour error, value sent not #RRGGBB or RRGGBB, and not array(r,g,b)'); return false; - } + } - $r = hexdec($r); - $g = hexdec($g); - $b = hexdec($b); + $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } - public function set_jpeg_quality($quality = 75) - //---------------------------------------------------------------------------------------------------------- - // Sets the quality that jpeg will be saved at - //---------------------------------------------------------------------------------------------------------- - { - $this->jpeg_quality = $quality; - return $this; - } + public function rotate($angle) + //---------------------------------------------------------------------------------------------------------- + // rotate an image bu 0 / 90 / 180 / 270 degrees + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // set the colour + $col = $this->_html2rgb($$this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + + // rotate as needed + $this->temp_image = imagerotate($this->temp_image, $angle, $bg); + return $this; + } + + public function make_watermark_text($text, $fontfile, $size=16, $colour="#ffffff", $angle=0) + //---------------------------------------------------------------------------------------------------------- + // create an image from text that can be applied as a watermark + // text is the text to write, $fontile is a ttf file that will be used $size=font size, $colour is the colour of text + //---------------------------------------------------------------------------------------------------------- + { + // check font file can be found + if (!file_exists($fontfile)) + { + $this->set_error('Could not locate font file "'.$fontfile.'"'); + return $this; + } + + // validate we loaded a main image + if (!$this->_check_image()) + { + $remove = TRUE; + // no image loaded so make temp image to use + $this->main_image = imagecreatetruecolor(1000,1000); + } + else + { + $remove = FALSE; + } + + // work out text dimensions + $bbox = imageftbbox($size, $angle, $fontfile, $text); + $bw = abs($bbox[4] - $bbox[0]) + 1; + $bh = abs($bbox[1] - $bbox[5]) + 1; + $bl = $bbox[1]; + + // use this to create watermark image + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + $this->watermark_image = imagecreatetruecolor($bw, $bh); + + // set colours + $col = $this->_html2rgb($colour); + $font_col = imagecolorallocate($this->watermark_image, $col[0], $col[1], $col[2]); + $bg_col = imagecolorallocate($this->watermark_image, 127, 128, 126); + + // set method to use + $this->watermark_method = 2; + + // create bg + imagecolortransparent($this->watermark_image, $bg_col); + imagefilledrectangle($this->watermark_image, 0,0, $bw, $bh, $bg_col); + + // write text to watermark + imagefttext($this->watermark_image, $size, $angle, 0, $bh-$bl, $font_col, $fontfile, $text); + + if ($remove) imagedestroy($this->main_image); + return $this; + } + + public function watermark($position, $offset=8, $abs=FALSE) + //---------------------------------------------------------------------------------------------------------- + // add a watermark to the image + // position works like a keypad e.g. + // 7 8 9 + // 4 5 6 + // 1 2 3 + // offset moves image inwards by x pixels + // if abs is set then $position, $offset = direct placement coords + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // validate we have a watermark + if(!is_resource($this->watermark_image)) + { + $this->set_error("Can't watermark image, no watermark loaded/created"); + return $this; + } + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get watermark width + $wm_w = imageSX($this->watermark_image); + $wm_h = imageSY($this->watermark_image); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // check watermark will fit! + if ($wm_w > $temp_w || $wm_h > $temp_h) + { + $this->set_error("Watermark is larger than image. WM: $wm_w x $wm_h Temp image: $temp_w x $temp_h"); + return $this; + } + + if ($abs) + { + // direct placement + $dest_x = $position; + $dest_y = $offset; + } + else + { + // do X position + switch ($position) + { + // x left + case "7": + case "4": + case "1": + $dest_x = $offset; + break; + // x middle + case "8": + case "5": + case "2": + $dest_x = ($temp_w - $wm_w) /2 ; + break; + // x right + case "9": + case "6": + case "3": + $dest_x = $temp_w - $offset - $wm_w; + break; + default: + $dest_x = $offset; + $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + // do y position + switch ($position) + { + // y top + case "7": + case "8": + case "9": + $dest_y = $offset; + break; + // y middle + case "4": + case "5": + case "6": + $dest_y = ($temp_h - $wm_h) /2 ; + break; + // y bottom + case "1": + case "2": + case "3": + $dest_y = $temp_h - $offset - $wm_h; + break; + default: + $dest_y = $offset; + $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + + } + + // copy over temp image to desired location + if ($this->watermark_method == 1) + { + // use back methods to do this, taken from php help files + //$this->imagecopymerge_alpha($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); + + $opacity=$this->watermark_transparency; + + // creating a cut resource + $cut = imagecreatetruecolor($wm_w, $wm_h); + + // copying that section of the background to the cut + imagecopy($cut, $this->temp_image, 0, 0, $dest_x, $dest_y, $wm_w, $wm_h); + + // inverting the opacity + $opacity = 100 - $opacity; + + // placing the watermark now + imagecopy($cut, $this->watermark_image, 0, 0, 0, 0, $wm_w, $wm_h); + imagecopymerge($this->temp_image, $cut, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $opacity); + + } + else + { + // use normal with selected transparency colour + imagecopymerge($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); + } - public function clear() - //---------------------------------------------------------------------------------------------------------- - // clear everything! - //---------------------------------------------------------------------------------------------------------- - { - if (is_resource($this->main_image)) imagedestroy($this->main_image); - if (is_resource($this->watermark_image)) imagedestroy($this->watermark_image); - if (is_resource($this->temp_image)) imagedestroy($this->temp_image); - return $this; - } - - public function resize_crop($mw, $mh) - //---------------------------------------------------------------------------------------------------------- - // take main image and resize to tempimage using EXACT boundaries mw,mh (max width and max height) - // this is proportional and crops the image centrally to fit - //---------------------------------------------------------------------------------------------------------- - { - if (!$this->_check_image()) return $this; - - // clear temp image - $this->clear_temp(); - - // create a temp based on new dimensions - $this->temp_image = imagecreatetruecolor($mw, $mh); - - // check it - if (!is_resource($this->temp_image)) { - $this->set_error('Unable to create temp image sized ' . $mw . ' x ' . $mh); - return $this; - } - - // work out best positions for copy - $wx = $this->width / $mw; - $wy = $this->height / $mh; - if ($wx >= $wy) { - // use full height - $sy = 0; - $sy2 = $this->height; - - // calcs - $calc_width = $mw * $wy; - $sx = ($this->width - $calc_width) / 2; - $sx2 = $calc_width; - } else { - // use full width - $sx = 0; - $sx2 = $this->width; - - // calcs - $calc_height = $mh * $wx; - $sy = ($this->height - $calc_height) / 2; - $sy2 = $calc_height; - } - - // copy section - imagecopyresampled($this->temp_image, $this->main_image, 0, 0, $sx, $sy, $mw, $mh, $sx2, $sy2); - return $this; - } - - public function resize($mw, $mh, $pad = false) - //---------------------------------------------------------------------------------------------------------- - // take main image and resize to tempimage using boundaries mw,mh (max width or max height) - // this is proportional, pad to true will set it in the middle of area size - //---------------------------------------------------------------------------------------------------------- - { - if (!$this->_check_image()) return $this; - - // calc new dimensions - if ($this->width > $mw || $this->height > $mh) { -// if( $this->width > $this->height ) { could calc wronf - Cole Thorsen swapped to his suggestion - if (($this->width / $this->height) > ($mw / $mh)) { - $tnw = $mw; - $tnh = $tnw * $this->height / $this->width; - } else { - $tnh = $mh; - $tnw = $tnh * $this->width / $this->height; - } - } else { - $tnw = $this->width; - $tnh = $this->height; - } - // clear temp image - $this->clear_temp(); - - // create a temp based on new dimensions - if ($pad) { - $tx = $mw; - $ty = $mh; - $px = ($mw - $tnw) / 2; - $py = ($mh - $tnh) / 2; - } else { - $tx = $tnw; - $ty = $tnh; - $px = 0; - $py = 0; - } - $this->temp_image = imagecreatetruecolor($tx, $ty); - - // check it - if (!is_resource($this->temp_image)) { - $this->set_error('Unable to create temp image sized ' . $tx . ' x ' . $ty); - return $this; - } - - // if padding, fill background - if ($pad) { - $col = $this->_html2rgb($this->background_colour); - $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); - imagefilledrectangle($this->temp_image, 0, 0, $tx, $ty, $bg); - } - - // copy resized - imagecopyresampled($this->temp_image, $this->main_image, $px, $py, 0, 0, $tnw, $tnh, $this->width, $this->height); - return $this; - } - - public function stretch($mw, $mh) - //---------------------------------------------------------------------------------------------------------- - // take main image and resize to tempimage using boundaries mw,mh (max width or max height) - // does not retain proportions - //---------------------------------------------------------------------------------------------------------- - { - if (!$this->_check_image()) return $this; - - // clear temp image - $this->clear_temp(); - - // create a temp based on new dimensions - $this->temp_image = imagecreatetruecolor($mw, $mh); - - // check it - if (!is_resource($this->temp_image)) { - $this->set_error('Unable to create temp image sized ' . $mh . ' x ' . $mw); - return $this; - } - - // copy resized (stethced, proportions not kept); - imagecopyresampled($this->temp_image, $this->main_image, 0, 0, 0, 0, $mw, $mh, $this->width, $this->height); - return $this; - } - - public function crop($x1, $y1, $x2, $y2) - //---------------------------------------------------------------------------------------------------------- - // crop the main image to temp image using coords - //---------------------------------------------------------------------------------------------------------- - { - if (!$this->_check_image()) return $this; - - // clear temp image - $this->clear_temp(); - - // check dimensions - if ($x1 < 0 || $y1 < 0 || $x2 - $x1 > $this->width || $y2 - $y1 > $this->height) { - $this->set_error('Invalid crop dimensions, either - passed or width/heigh too large ' . $x1 . '/' . $y1 . ' x ' . $x2 . '/' . $y2); - return $this; - } - - // create a temp based on new dimensions - $this->temp_image = imagecreatetruecolor($x2 - $x1, $y2 - $y1); - - // check it - if (!is_resource($this->temp_image)) { - $this->set_error('Unable to create temp image sized ' . $x2 - $x1 . ' x ' . $y2 - $y1); - return $this; - } - - // copy cropped portion - imagecopy($this->temp_image, $this->main_image, 0, 0, $x1, $y1, $x2 - $x1, $y2 - $y1); - return $this; - } - - public function rotate($angle) - //---------------------------------------------------------------------------------------------------------- - // rotate an image bu 0 / 90 / 180 / 270 degrees - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // set the colour - $col = $this->_html2rgb($$this->background_colour); - $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); - - // rotate as needed - $this->temp_image = imagerotate($this->temp_image, $angle, $bg); - return $this; - } - - public function make_watermark_text($text, $fontfile, $size = 16, $colour = "#ffffff", $angle = 0) - //---------------------------------------------------------------------------------------------------------- - // create an image from text that can be applied as a watermark - // text is the text to write, $fontile is a ttf file that will be used $size=font size, $colour is the colour of text - //---------------------------------------------------------------------------------------------------------- - { - // check font file can be found - if (!file_exists($fontfile)) { - $this->set_error('Could not locate font file "' . $fontfile . '"'); - return $this; - } - - // validate we loaded a main image - if (!$this->_check_image()) { - $remove = true; - // no image loaded so make temp image to use - $this->main_image = imagecreatetruecolor(1000, 1000); - } else { - $remove = false; - } - - // work out text dimensions - $bbox = imageftbbox($size, $angle, $fontfile, $text); - $bw = abs($bbox[4] - $bbox[0]) + 1; - $bh = abs($bbox[1] - $bbox[5]) + 1; - $bl = $bbox[1]; - - // use this to create watermark image - if (is_resource($this->watermark_image)) imagedestroy($this->watermark_image); - $this->watermark_image = imagecreatetruecolor($bw, $bh); - - // set colours - $col = $this->_html2rgb($colour); - $font_col = imagecolorallocate($this->watermark_image, $col[0], $col[1], $col[2]); - $bg_col = imagecolorallocate($this->watermark_image, 127, 128, 126); - - // set method to use - $this->watermark_method = 2; - - // create bg - imagecolortransparent($this->watermark_image, $bg_col); - imagefilledrectangle($this->watermark_image, 0, 0, $bw, $bh, $bg_col); - - // write text to watermark - imagefttext($this->watermark_image, $size, $angle, 0, $bh - $bl, $font_col, $fontfile, $text); - - if ($remove) imagedestroy($this->main_image); - return $this; - } - - public function watermark($position, $offset = 8, $abs = false) - //---------------------------------------------------------------------------------------------------------- - // add a watermark to the image - // position works like a keypad e.g. - // 7 8 9 - // 4 5 6 - // 1 2 3 - // offset moves image inwards by x pixels - // if abs is set then $position, $offset = direct placement coords - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // validate we have a watermark - if (!is_resource($this->watermark_image)) { - $this->set_error("Can't watermark image, no watermark loaded/created"); - return $this; - } - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // get watermark width - $wm_w = imageSX($this->watermark_image); - $wm_h = imageSY($this->watermark_image); - - // get temp widths - $temp_w = imageSX($this->temp_image); - $temp_h = imageSY($this->temp_image); - - // check watermark will fit! - if ($wm_w > $temp_w || $wm_h > $temp_h) { - $this->set_error("Watermark is larger than image. WM: $wm_w x $wm_h Temp image: $temp_w x $temp_h"); - return $this; - } - - if ($abs) { - // direct placement - $dest_x = $position; - $dest_y = $offset; - } else { - // do X position - switch ($position) { - // x left - case "7": - case "4": - case "1": - $dest_x = $offset; - break; - // x middle - case "8": - case "5": - case "2": - $dest_x = ($temp_w - $wm_w) / 2; - break; - // x right - case "9": - case "6": - case "3": - $dest_x = $temp_w - $offset - $wm_w; - break; - default: - $dest_x = $offset; - $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); - } - // do y position - switch ($position) { - // y top - case "7": - case "8": - case "9": - $dest_y = $offset; - break; - // y middle - case "4": - case "5": - case "6": - $dest_y = ($temp_h - $wm_h) / 2; - break; - // y bottom - case "1": - case "2": - case "3": - $dest_y = $temp_h - $offset - $wm_h; - break; - default: - $dest_y = $offset; - $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); - } - - } - - // copy over temp image to desired location - if ($this->watermark_method == 1) { - // use back methods to do this, taken from php help files - //$this->imagecopymerge_alpha($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); - - $opacity = $this->watermark_transparency; - - // creating a cut resource - $cut = imagecreatetruecolor($wm_w, $wm_h); - - // copying that section of the background to the cut - imagecopy($cut, $this->temp_image, 0, 0, $dest_x, $dest_y, $wm_w, $wm_h); - - // inverting the opacity - $opacity = 100 - $opacity; - - // placing the watermark now - imagecopy($cut, $this->watermark_image, 0, 0, 0, 0, $wm_w, $wm_h); - imagecopymerge($this->temp_image, $cut, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $opacity); - - } else { - // use normal with selected transparency colour - imagecopymerge($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); - } - - return $this; - } - - public function border($width = 5, $colour = "#000") - //---------------------------------------------------------------------------------------------------------- - // add a solidborder frame, coloured $colour to the image - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // get colour set for temp image - $col = $this->_html2rgb($colour); - $border_col = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); - - // get temp widths - $temp_w = imageSX($this->temp_image); - $temp_h = imageSY($this->temp_image); - - // do border - for ($x = 0; $x < $width; $x++) { - imagerectangle($this->temp_image, $x, $x, $temp_w - $x - 1, $temp_h - $x - 1, $border_col); - } - - // return object - return $this; - } - - public function border_3d($width = 5, $rot = 0, $opacity = 30) - //---------------------------------------------------------------------------------------------------------- - // overlay a black white border to make it look 3d - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // get temp widths - $temp_w = imageSX($this->temp_image); - $temp_h = imageSY($this->temp_image); - - // create temp canvas to merge - $border_image = imagecreatetruecolor($temp_w, $temp_h); - - // create colours - $black = imagecolorallocate($border_image, 0, 0, 0); - $white = imagecolorallocate($border_image, 255, 255, 255); - switch ($rot) { - case 1 : - $cols = array($white, $black, $white, $black); - break; - case 2 : - $cols = array($black, $black, $white, $white); - break; - case 3 : - $cols = array($black, $white, $black, $white); - break; - default : - $cols = array($white, $white, $black, $black); - } - $bg_col = imagecolorallocate($border_image, 127, 128, 126); - - // create bg - imagecolortransparent($border_image, $bg_col); - imagefilledrectangle($border_image, 0, 0, $temp_w, $temp_h, $bg_col); - - // do border - for ($x = 0; $x < $width; $x++) { - // top - imageline($border_image, $x, $x, $temp_w - $x - 1, $x, $cols[0]); - // left - imageline($border_image, $x, $x, $x, $temp_w - $x - 1, $cols[1]); - // bottom - imageline($border_image, $x, $temp_h - $x - 1, $temp_w - 1 - $x, $temp_h - $x - 1, $cols[3]); - // right - imageline($border_image, $temp_w - $x - 1, $x, $temp_w - $x - 1, $temp_h - $x - 1, $cols[2]); - } - - // merg with temp image - imagecopymerge($this->temp_image, $border_image, 0, 0, 0, 0, $temp_w, $temp_h, $opacity); - - // clean up - imagedestroy($border_image); - - // return object - return $this; - } - - public function shadow($size = 4, $direction = 3, $colour = "#444") - //---------------------------------------------------------------------------------------------------------- - // add a shadow to an image, this will INCREASE the size of the image - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // get the current size - $sx = imagesx($this->temp_image); - $sy = imagesy($this->temp_image); - - // new image - $bu_image = imagecreatetruecolor($sx, $sy); - - // check it - if (!is_resource($bu_image)) { - $this->set_error('Unable to create shadow temp image sized ' . $this->width . ' x ' . $this->height); - return false; - } - - // copy the current image to memory - imagecopy($bu_image, $this->temp_image, 0, 0, 0, 0, $sx, $sy); - - imagedestroy($this->temp_image); - $this->temp_image = imagecreatetruecolor($sx + $size, $sy + $size); - - // fill background colour - $col = $this->_html2rgb($this->background_colour); - $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); - imagefilledrectangle($this->temp_image, 0, 0, $sx + $size, $sy + $size, $bg); - - // work out position - // do X position - switch ($direction) { - // x left - case "7": - case "4": - case "1": - $sh_x = 0; - $pic_x = $size; - break; - // x middle - case "8": - case "5": - case "2": - $sh_x = $size / 2; - $pic_x = $size / 2; - break; - // x right - case "9": - case "6": - case "3": - $sh_x = $size; - $pic_x = 0; - break; - default: - $sh_x = $size; - $pic_x = 0; - $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); - } - // do y position - switch ($direction) { - // y top - case "7": - case "8": - case "9": - $sh_y = 0; - $pic_y = $size; - break; - // y middle - case "4": - case "5": - case "6": - $sh_y = $size / 2; - $pic_y = $size / 2; - break; - // y bottom - case "1": - case "2": - case "3": - $sh_y = $size; - $pic_y = 0; - break; - default: - $sh_y = $size; - $pic_y = 0; - $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); - } - - // create the shadow - $shadowcolour = $this->_html2rgb($colour); - $shadow = imagecolorallocate($this->temp_image, $shadowcolour[0], $shadowcolour[1], $shadowcolour[2]); - imagefilledrectangle($this->temp_image, $sh_x, $sh_y, $sh_x + $sx - 1, $sh_y + $sy - 1, $shadow); - - // copy current image to correct location - imagecopy($this->temp_image, $bu_image, $pic_x, $pic_y, 0, 0, $sx, $sy); - - // clean up and desstroy temp image - imagedestroy($bu_image); - - //return object return $this; - } - - public function filter($function, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null) - //---------------------------------------------------------------------------------------------------------- - // allows you to use the inbulit gd2 image filters - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - if (!imagefilter($this->temp_image, $function, $arg1, $arg2, $arg3, $arg4)) { - $this->set_error("Filter $function failed"); - } - - // return object - return $this; - } - - public function round($radius = 5, $invert = false, $corners = "") - //---------------------------------------------------------------------------------------------------------- - // adds rounded corners to the output - // using a quarter and rotating as you can end up with odd roudning if you draw a whole and use parts - //---------------------------------------------------------------------------------------------------------- - { - // validate we loaded a main image - if (!$this->_check_image()) return $this; - - // if no operations, copy it for temp save - $this->_copy_to_temp_if_needed(); - - // check input - if ($corners == "") $corners = array(true, true, true, true); - if (!is_array($corners) || count($corners) <> 4) { - $this->set_error("Round failed, expected an array of 4 items round(radius,tl,tr,br,bl)"); - return $this; - } - - // create corner - $corner = imagecreatetruecolor($radius, $radius); - - // turn on aa make it nicer - imageantialias($corner, true); - $col = $this->_html2rgb($this->background_colour); - - // use bg col for corners - $bg = imagecolorallocate($corner, $col[0], $col[1], $col[2]); - - // create our transparent colour - $xparent = imagecolorallocate($corner, 127, 128, 126); - imagecolortransparent($corner, $xparent); - if ($invert) { - // fill and clear bits - imagefilledrectangle($corner, 0, 0, $radius, $radius, $xparent); - imagefilledellipse($corner, 0, 0, ($radius * 2) - 1, ($radius * 2) - 1, $bg); - } else { - // fill and clear bits - imagefilledrectangle($corner, 0, 0, $radius, $radius, $bg); - imagefilledellipse($corner, $radius, $radius, ($radius * 2), ($radius * 2), $xparent); - } - - // get temp widths - $temp_w = imageSX($this->temp_image); - $temp_h = imageSY($this->temp_image); - - // do corners - if ($corners[0]) imagecopymerge($this->temp_image, $corner, 0, 0, 0, 0, $radius, $radius, 100); - $corner = imagerotate($corner, 270, 0); - if ($corners[1]) imagecopymerge($this->temp_image, $corner, $temp_w - $radius, 0, 0, 0, $radius, $radius, 100); - $corner = imagerotate($corner, 270, 0); - if ($corners[2]) imagecopymerge($this->temp_image, $corner, $temp_w - $radius, $temp_h - $radius, 0, 0, $radius, $radius, 100); - $corner = imagerotate($corner, 270, 0); - if ($corners[3]) imagecopymerge($this->temp_image, $corner, 0, $temp_h - $radius, 0, 0, $radius, $radius, 100); - - // return object - return $this; - } + } + + public function border($width=5,$colour="#000") + //---------------------------------------------------------------------------------------------------------- + // add a solidborder frame, coloured $colour to the image + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get colour set for temp image + $col = $this->_html2rgb($colour); + $border_col = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // do border + for($x=0;$x<$width;$x++) + { + imagerectangle($this->temp_image, $x, $x, $temp_w-$x-1, $temp_h-$x-1, $border_col); + } + + // return object + return $this; + } + + public function border_3d($width=5,$rot=0,$opacity=30) + //---------------------------------------------------------------------------------------------------------- + // overlay a black white border to make it look 3d + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // create temp canvas to merge + $border_image = imagecreatetruecolor($temp_w, $temp_h); + + // create colours + $black = imagecolorallocate($border_image, 0, 0, 0); + $white = imagecolorallocate($border_image, 255, 255, 255); + switch ($rot) + { + case 1 : + $cols=array($white,$black,$white,$black); + break; + case 2 : + $cols=array($black,$black,$white,$white); + break; + case 3 : + $cols=array($black,$white,$black,$white); + break; + default : + $cols=array($white,$white,$black,$black); + } + $bg_col = imagecolorallocate($border_image, 127, 128, 126); + + // create bg + imagecolortransparent($border_image, $bg_col); + imagefilledrectangle($border_image, 0,0, $temp_w, $temp_h, $bg_col); + + // do border + for($x=0;$x<$width;$x++) + { + // top + imageline($border_image, $x, $x, $temp_w-$x-1, $x, $cols[0]); + // left + imageline($border_image, $x, $x, $x, $temp_w-$x-1, $cols[1]); + // bottom + imageline($border_image, $x, $temp_h-$x-1, $temp_w-1-$x, $temp_h-$x-1, $cols[3]); + // right + imageline($border_image, $temp_w-$x-1, $x, $temp_w-$x-1, $temp_h-$x-1, $cols[2]); + } + + // merg with temp image + imagecopymerge($this->temp_image, $border_image, 0, 0, 0, 0, $temp_w, $temp_h, $opacity); + + // clean up + imagedestroy($border_image); + + // return object + return $this; + } + + public function shadow($size=4, $direction=3, $colour="#444") + //---------------------------------------------------------------------------------------------------------- + // add a shadow to an image, this will INCREASE the size of the image + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get the current size + $sx = imagesx($this->temp_image); + $sy = imagesy($this->temp_image); + + // new image + $bu_image = imagecreatetruecolor($sx, $sy); + + // check it + if(!is_resource($bu_image)) + { + $this->set_error('Unable to create shadow temp image sized '.$this->width.' x '.$this->height); + return FALSE; + } + + // copy the current image to memory + imagecopy($bu_image, $this->temp_image, 0, 0, 0, 0, $sx, $sy); + + imagedestroy($this->temp_image); + $this->temp_image = imagecreatetruecolor($sx+$size, $sy+$size); + + // fill background colour + $col = $this->_html2rgb($this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + imagefilledrectangle($this->temp_image, 0, 0, $sx+$size, $sy+$size, $bg); + + // work out position + // do X position + switch ($direction) + { + // x left + case "7": + case "4": + case "1": + $sh_x = 0; + $pic_x = $size; + break; + // x middle + case "8": + case "5": + case "2": + $sh_x = $size / 2; + $pic_x = $size / 2; + break; + // x right + case "9": + case "6": + case "3": + $sh_x = $size; + $pic_x = 0; + break; + default: + $sh_x = $size; + $pic_x = 0; + $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + // do y position + switch ($direction) + { + // y top + case "7": + case "8": + case "9": + $sh_y = 0; + $pic_y = $size; + break; + // y middle + case "4": + case "5": + case "6": + $sh_y = $size / 2; + $pic_y = $size / 2; + break; + // y bottom + case "1": + case "2": + case "3": + $sh_y = $size; + $pic_y = 0; + break; + default: + $sh_y = $size; + $pic_y = 0; + $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + + // create the shadow + $shadowcolour = $this->_html2rgb($colour); + $shadow = imagecolorallocate($this->temp_image, $shadowcolour[0], $shadowcolour[1], $shadowcolour[2]); + imagefilledrectangle($this->temp_image, $sh_x, $sh_y, $sh_x+$sx-1, $sh_y+$sy-1, $shadow); + + // copy current image to correct location + imagecopy($this->temp_image, $bu_image, $pic_x, $pic_y, 0, 0, $sx, $sy); + + // clean up and desstroy temp image + imagedestroy($bu_image); + + //return object + return $this; + } + + public function filter($function, $arg1=NULL, $arg2=NULL, $arg3=NULL, $arg4=NULL) + //---------------------------------------------------------------------------------------------------------- + // allows you to use the inbulit gd2 image filters + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + if (!imagefilter($this->temp_image, $function, $arg1, $arg2, $arg3, $arg4)) + { + $this->set_error("Filter $function failed"); + } + + // return object + return $this; + } + + public function round($radius=5,$invert=False,$corners="") + //---------------------------------------------------------------------------------------------------------- + // adds rounded corners to the output + // using a quarter and rotating as you can end up with odd roudning if you draw a whole and use parts + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // check input + if ($corners=="") $corners=array(True,True,True,True); + if (!is_array($corners) || count($corners)<>4) + { + $this->set_error("Round failed, expected an array of 4 items round(radius,tl,tr,br,bl)"); + return $this; + } + + // create corner + $corner = imagecreatetruecolor($radius, $radius); + + // turn on aa make it nicer + imageantialias($corner, true); + $col = $this->_html2rgb($this->background_colour); + + // use bg col for corners + $bg = imagecolorallocate($corner, $col[0], $col[1], $col[2]); + + // create our transparent colour + $xparent = imagecolorallocate($corner, 127, 128, 126); + imagecolortransparent($corner, $xparent); + if ($invert) + { + // fill and clear bits + imagefilledrectangle($corner, 0, 0, $radius, $radius, $xparent); + imagefilledellipse($corner, 0, 0, ($radius * 2)-1, ($radius * 2)-1, $bg); + } + else + { + // fill and clear bits + imagefilledrectangle($corner, 0, 0, $radius, $radius, $bg); + imagefilledellipse($corner, $radius, $radius, ($radius * 2) , ($radius * 2) , $xparent); + } + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // do corners + if ($corners[0]) imagecopymerge($this->temp_image, $corner, 0, 0, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[1]) imagecopymerge($this->temp_image, $corner, $temp_w-$radius, 0, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[2]) imagecopymerge($this->temp_image, $corner, $temp_w-$radius, $temp_h-$radius, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[3]) imagecopymerge($this->temp_image, $corner, 0, $temp_h-$radius, 0, 0, $radius, $radius, 100); + + // return object + return $this; + } } /* End of file image_moo.php */ -/* Location: .system/application/libraries/image_moo.php */ +/* Location: .system/application/libraries/image_moo.php */ \ No newline at end of file diff --git a/application/models/grocery_crud_model.php b/application/models/grocery_crud_model.php index 01a199e..2493005 100755 --- a/application/models/grocery_crud_model.php +++ b/application/models/grocery_crud_model.php @@ -9,11 +9,11 @@ * Please see the corresponding license file for details of these licenses. * You are free to use, modify and distribute this software, but all copyright information must remain. * - * @package grocery CRUD - * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @version 1.2 - * @author John Skoumbourdis + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @version 1.4.2 + * @author John Skoumbourdis */ // ------------------------------------------------------------------------ @@ -22,509 +22,566 @@ * Grocery CRUD Model * * - * @package grocery CRUD - * @author John Skoumbourdis - * @version 1.2 - * @link http://www.grocerycrud.com/documentation + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.5.6 + * @link http://www.grocerycrud.com/documentation */ -class grocery_CRUD_Model extends CI_Model -{ +class Grocery_crud_model extends CI_Model { - protected $primary_key = null; - protected $table_name = null; - protected $relation = array(); - protected $relation_n_n = array(); - protected $primary_keys = array(); + protected $primary_key = null; + protected $table_name = null; + protected $relation = array(); + protected $relation_n_n = array(); + protected $primary_keys = array(); - function __construct() + function __construct() { parent::__construct(); } function db_table_exists($table_name = null) { - return $this->db->table_exists($table_name); + return $this->db->table_exists($table_name); } function get_list() { - if ($this->table_name === null) - return false; + if($this->table_name === null) + return false; - $select = "`{$this->table_name}`.*"; + $select = "`{$this->table_name}`.*"; - //set_relation special queries - if (!empty($this->relation)) { - foreach ($this->relation as $relation) { - list($field_name, $related_table, $related_field_title) = $relation; - $unique_join_name = $this->_unique_join_name($field_name); - $unique_field_name = $this->_unique_field_name($field_name); + //set_relation special queries + if(!empty($this->relation)) + { + foreach($this->relation as $relation) + { + list($field_name , $related_table , $related_field_title) = $relation; + $unique_join_name = $this->_unique_join_name($field_name); + $unique_field_name = $this->_unique_field_name($field_name); - if (strstr($related_field_title, '{')) { - $related_field_title = str_replace(" ", " ", $related_field_title); - $select .= ", CONCAT('" . str_replace(array('{', '}'), array("',COALESCE({$unique_join_name}.", ", ''),'"), str_replace("'", "\\'", $related_field_title)) . "') as $unique_field_name"; - } else { - $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; - } + if(strstr($related_field_title,'{')) + { + $related_field_title = str_replace(" "," ",$related_field_title); + $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; + } + else + { + $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; + } - if ($this->field_exists($related_field_title)) - $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; - } - } - - //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. - if (!empty($this->relation_n_n)) { - $select = $this->relation_n_n_queries($select); - } + if($this->field_exists($related_field_title)) + $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; + } + } - $this->db->select($select, false); + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. + if(!empty($this->relation_n_n)) + { + $select = $this->relation_n_n_queries($select); + } - $results = $this->db->get($this->table_name)->result(); + $this->db->select($select, false); - return $results; - } + $results = $this->db->get($this->table_name)->result(); - protected function _unique_join_name($field_name) - { - return 'j' . substr(md5($field_name), 0, 8); //This j is because is better for a string to begin with a letter and not with a number + return $results; } - protected function _unique_field_name($field_name) - { - return 's' . substr(md5($field_name), 0, 8); //This s is because is better for a string to begin with a letter and not with a number - } - - function field_exists($field, $table_name = null) - { - if (empty($table_name)) { - $table_name = $this->table_name; - } - return $this->db->field_exists($field, $table_name); - } - - protected function relation_n_n_queries($select) - { - $this_table_primary_key = $this->get_primary_key(); - foreach ($this->relation_n_n as $relation_n_n) { - list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, - $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); - - $primary_key_selection_table = $this->get_primary_key($selection_table); - - $field = ""; - $use_template = strpos($title_field_selection_table, '{') !== false; - $field_name_hash = $this->_unique_field_name($title_field_selection_table); - if ($use_template) { - $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); - $field .= "CONCAT('" . str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $title_field_selection_table)) . "')"; - } else { - $field .= "$selection_table.$title_field_selection_table"; - } - - //Sorry Codeigniter but you cannot help me with the subquery! - $select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table " - . "LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table " - . "WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name"; - } - - return $select; - } - - function get_primary_key($table_name = null) + public function get_row($table_name = null) { - if ($table_name == null) { - if (isset($this->primary_keys[$this->table_name])) { - return $this->primary_keys[$this->table_name]; - } - - if (empty($this->primary_key)) { - $fields = $this->get_field_types_basic_table(); - - foreach ($fields as $field) { - if ($field->primary_key == 1) { - return $field->name; - } - } - - return false; - } else { - return $this->primary_key; - } - } else { - if (isset($this->primary_keys[$table_name])) { - return $this->primary_keys[$table_name]; - } - - $fields = $this->get_field_types($table_name); - - foreach ($fields as $field) { - if ($field->primary_key == 1) { - return $field->name; - } - } - - return false; - } + $table_name = $table_name === null ? $this->table_name : $table_name; + return $this->db->get($table_name)->row(); } public function set_primary_key($field_name, $table_name = null) { - $table_name = $table_name === null ? $this->table_name : $table_name; + $table_name = $table_name === null ? $this->table_name : $table_name; - $this->primary_keys[$table_name] = $field_name; + $this->primary_keys[$table_name] = $field_name; } - function get_field_types_basic_table() + protected function relation_n_n_queries($select) { - $db_field_types = array(); - foreach ($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) { - $type = explode("(", $db_field_type->Type); - $db_type = $type[0]; - - if (isset($type[1])) { - if (substr($type[1], -1) == ')') { - $length = substr($type[1], 0, -1); - } else { - list($length) = explode(" ", $type[1]); - $length = substr($length, 0, -1); - } - } else { - $length = ''; - } - $db_field_types[$db_field_type->Field]['db_max_length'] = $length; - $db_field_types[$db_field_type->Field]['db_type'] = $db_type; - $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false; - $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; - } + $this_table_primary_key = $this->get_primary_key(); + foreach($this->relation_n_n as $relation_n_n) + { + list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, + $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); - $results = $this->db->field_data($this->table_name); - foreach ($results as $num => $row) { - $row = (array)$row; - $results[$num] = (object)(array_merge($row, $db_field_types[$row['name']])); - } + $primary_key_selection_table = $this->get_primary_key($selection_table); - return $results; - } + $field = ""; + $use_template = strpos($title_field_selection_table,'{') !== false; + $field_name_hash = $this->_unique_field_name($title_field_selection_table); + if($use_template) + { + $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); + $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; + } + else + { + $field .= "$selection_table.$title_field_selection_table"; + } - function get_field_types($table_name) - { - $results = $this->db->field_data($table_name); + //Sorry Codeigniter but you cannot help me with the subquery! + $select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table " + ."LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table " + ."WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name"; + } - return $results; + return $select; } - public function get_row($table_name = null) + function order_by($order_by , $direction) { - $table_name = $table_name === null ? $this->table_name : $table_name; - - return $this->db->get($table_name)->row(); + $this->db->order_by( $order_by , $direction ); } - function order_by($order_by, $direction) + function where($key, $value = NULL, $escape = TRUE) { - $this->db->order_by($order_by, $direction); + $this->db->where( $key, $value, $escape); } - function where($key, $value = null, $escape = true) + function or_where($key, $value = NULL, $escape = TRUE) { - $this->db->where($key, $value, $escape); + $this->db->or_where( $key, $value, $escape); } - function or_where($key, $value = null, $escape = true) + function having($key, $value = NULL, $escape = TRUE) { - $this->db->or_where($key, $value, $escape); + $this->db->having( $key, $value, $escape); } - function having($key, $value = null, $escape = true) + function or_having($key, $value = NULL, $escape = TRUE) { - $this->db->having($key, $value, $escape); - } - - function or_having($key, $value = null, $escape = true) - { - $this->db->or_having($key, $value, $escape); + $this->db->or_having( $key, $value, $escape); } function like($field, $match = '', $side = 'both') { - $this->db->like($field, $match, $side); + $this->db->like($field, $match, $side); } function or_like($field, $match = '', $side = 'both') { - $this->db->or_like($field, $match, $side); + $this->db->or_like($field, $match, $side); } function limit($value, $offset = '') { - $this->db->limit($value, $offset); + $this->db->limit( $value , $offset ); } function get_total_results() { - //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. - if (!empty($this->relation_n_n)) { - $select = "{$this->table_name}.*"; - $select = $this->relation_n_n_queries($select); + // A fast way to calculate the total results + $key = $this->get_primary_key(); - $this->db->select($select, false); + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. + if(!empty($this->relation_n_n)) + { + $select = "{$this->table_name}." . $key; + $select = $this->relation_n_n_queries($select); - return $this->db->get($this->table_name)->num_rows(); + $this->db->select($select,false); + } else { + $this->db->select($this->table_name . '.' . $key); } - - return $this->db->count_all_results($this->table_name); - + + return $this->db->get($this->table_name)->num_rows(); } function set_basic_table($table_name = null) { - if (!($this->db->table_exists($table_name))) - return false; + if( !($this->db->table_exists($table_name)) ) + return false; - $this->table_name = $table_name; + $this->table_name = $table_name; - return true; + return true; } function get_edit_values($primary_key_value) { - $primary_key_field = $this->get_primary_key(); - $this->db->where($primary_key_field, $primary_key_value); - $result = $this->db->get($this->table_name)->row(); - return $result; + $primary_key_field = $this->get_primary_key(); + $this->db->where($primary_key_field,$primary_key_value); + $result = $this->db->get($this->table_name)->row(); + return $result; } - function join_relation($field_name, $related_table, $related_field_title) + function join_relation($field_name , $related_table , $related_field_title) { - $related_primary_key = $this->get_primary_key($related_table); + $related_primary_key = $this->get_primary_key($related_table); - if ($related_primary_key !== false) { - $unique_name = $this->_unique_join_name($field_name); - $this->db->join($related_table . ' as ' . $unique_name, "$unique_name.$related_primary_key = {$this->table_name}.$field_name", 'left'); + if($related_primary_key !== false) + { + $unique_name = $this->_unique_join_name($field_name); + $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); - $this->relation[$field_name] = array($field_name, $related_table, $related_field_title); + $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); - return true; - } + return true; + } - return false; + return false; } function set_relation_n_n_field($field_info) { - $this->relation_n_n[$field_info->field_name] = $field_info; + $this->relation_n_n[$field_info->field_name] = $field_info; } - function get_ajax_relation_array($search, $field_name, $related_table, $related_field_title, $where_clause, $order_by) + protected function _unique_join_name($field_name) { - return $this->get_relation_array($field_name, $related_table, $related_field_title, $where_clause, $order_by, 10, $search); + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number } - function get_relation_array($field_name, $related_table, $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) + protected function _unique_field_name($field_name) { - $relation_array = array(); - $field_name_hash = $this->_unique_field_name($field_name); + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number + } - $related_primary_key = $this->get_primary_key($related_table); + function get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) + { + $relation_array = array(); + $field_name_hash = $this->_unique_field_name($field_name); - $select = "$related_table.$related_primary_key, "; + $related_primary_key = $this->get_primary_key($related_table); - if (strstr($related_field_title, '{')) { - $related_field_title = str_replace(" ", " ", $related_field_title); - $select .= "CONCAT('" . str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title)) . "') as $field_name_hash"; - } else { - $select .= "$related_table.$related_field_title as $field_name_hash"; - } + $select = "$related_table.$related_primary_key, "; - $this->db->select($select, false); - if ($where_clause !== null) - $this->db->where($where_clause); + if(strstr($related_field_title,'{')) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_table.$related_field_title as $field_name_hash"; + } - if ($where_clause !== null) - $this->db->where($where_clause); + $this->db->select($select,false); + if($where_clause !== null) + $this->db->where($where_clause); - if ($limit !== null) - $this->db->limit($limit); + if($where_clause !== null) + $this->db->where($where_clause); - if ($search_like !== null) - $this->db->having("$field_name_hash LIKE '%" . $this->db->escape_like_str($search_like) . "%'"); + if($limit !== null) + $this->db->limit($limit); - $order_by !== null - ? $this->db->order_by($order_by) - : $this->db->order_by($field_name_hash); + if($search_like !== null) + $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); - $results = $this->db->get($related_table)->result(); + $order_by !== null + ? $this->db->order_by($order_by) + : $this->db->order_by($field_name_hash); - foreach ($results as $row) { - $relation_array[$row->$related_primary_key] = $row->$field_name_hash; - } + $results = $this->db->get($related_table)->result(); + + foreach($results as $row) + { + $relation_array[$row->$related_primary_key] = $row->$field_name_hash; + } - return $relation_array; + return $relation_array; } - function get_relation_total_rows($field_name, $related_table, $related_field_title, $where_clause) + function get_ajax_relation_array($search, $field_name , $related_table , $related_field_title, $where_clause, $order_by) { - if ($where_clause !== null) - $this->db->where($where_clause); - - return $this->db->count_all_results($related_table); + return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search); } - function get_relation_n_n_selection_array($primary_key_value, $field_info) + function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause) { - $select = ""; - $related_field_title = $field_info->title_field_selection_table; - $use_template = strpos($related_field_title, '{') !== false;; - $field_name_hash = $this->_unique_field_name($related_field_title); - if ($use_template) { - $related_field_title = str_replace(" ", " ", $related_field_title); - $select .= "CONCAT('" . str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title)) . "') as $field_name_hash"; - } else { - $select .= "$related_field_title as $field_name_hash"; - } - $this->db->select('*, ' . $select, false); + if($where_clause !== null) + $this->db->where($where_clause); - $selection_primary_key = $this->get_primary_key($field_info->selection_table); - - if (empty($field_info->priority_field_relation_table)) { - if (!$use_template) { - $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); - } - } else { - $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); - } - $this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value); - $this->db->join( - $field_info->selection_table, - "{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}" - ); - $results = $this->db->get($field_info->relation_table)->result(); - - $results_array = array(); - foreach ($results as $row) { - $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; - } + return $this->db->count_all_results($related_table); + } - return $results_array; + function get_relation_n_n_selection_array($primary_key_value, $field_info) + { + $select = ""; + $related_field_title = $field_info->title_field_selection_table; + $use_template = strpos($related_field_title,'{') !== false;; + $field_name_hash = $this->_unique_field_name($related_field_title); + if($use_template) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_field_title as $field_name_hash"; + } + $this->db->select('*, '.$select,false); + + $selection_primary_key = $this->get_primary_key($field_info->selection_table); + + if(empty($field_info->priority_field_relation_table)) + { + if(!$use_template){ + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); + } + } + else + { + $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); + } + $this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value); + $this->db->join( + $field_info->selection_table, + "{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}" + ); + $results = $this->db->get($field_info->relation_table)->result(); + + $results_array = array(); + foreach($results as $row) + { + $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; + } + + return $results_array; } function get_relation_n_n_unselected_array($field_info, $selected_values) { - $use_where_clause = !empty($field_info->where_clause); - - $select = ""; - $related_field_title = $field_info->title_field_selection_table; - $use_template = strpos($related_field_title, '{') !== false; - $field_name_hash = $this->_unique_field_name($related_field_title); - - if ($use_template) { - $related_field_title = str_replace(" ", " ", $related_field_title); - $select .= "CONCAT('" . str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title)) . "') as $field_name_hash"; - } else { - $select .= "$related_field_title as $field_name_hash"; - } - $this->db->select('*, ' . $select, false); - - if ($use_where_clause) { - $this->db->where($field_info->where_clause); - } - - $selection_primary_key = $this->get_primary_key($field_info->selection_table); - if (!$use_template) - $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); + $use_where_clause = !empty($field_info->where_clause); + + $select = ""; + $related_field_title = $field_info->title_field_selection_table; + $use_template = strpos($related_field_title,'{') !== false; + $field_name_hash = $this->_unique_field_name($related_field_title); + + if($use_template) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_field_title as $field_name_hash"; + } + $this->db->select('*, '.$select,false); + + if($use_where_clause){ + $this->db->where($field_info->where_clause); + } + + $selection_primary_key = $this->get_primary_key($field_info->selection_table); + if(!$use_template) + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); $results = $this->db->get($field_info->selection_table)->result(); $results_array = array(); - foreach ($results as $row) { - if (!isset($selected_values[$row->$selection_primary_key])) + foreach($results as $row) + { + if(!isset($selected_values[$row->$selection_primary_key])) $results_array[$row->$selection_primary_key] = $row->{$field_name_hash}; } return $results_array; } - function db_relation_n_n_update($field_info, $post_data, $main_primary_key) + function db_relation_n_n_update($field_info, $post_data ,$main_primary_key) { - $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); - if (!empty($post_data)) - $this->db->where_not_in($field_info->primary_key_alias_to_selection_table, $post_data); - $this->db->delete($field_info->relation_table); + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); + if(!empty($post_data)) + $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); + $this->db->delete($field_info->relation_table); - $counter = 0; - if (!empty($post_data)) { - foreach ($post_data as $primary_key_value) { - $where_array = array( - $field_info->primary_key_alias_to_this_table => $main_primary_key, - $field_info->primary_key_alias_to_selection_table => $primary_key_value, - ); + $counter = 0; + if(!empty($post_data)) + { + foreach($post_data as $primary_key_value) + { + $where_array = array( + $field_info->primary_key_alias_to_this_table => $main_primary_key, + $field_info->primary_key_alias_to_selection_table => $primary_key_value, + ); - $this->db->where($where_array); - $count = $this->db->from($field_info->relation_table)->count_all_results(); + $this->db->where($where_array); + $count = $this->db->from($field_info->relation_table)->count_all_results(); - if ($count == 0) { - if (!empty($field_info->priority_field_relation_table)) - $where_array[$field_info->priority_field_relation_table] = $counter; + if($count == 0) + { + if(!empty($field_info->priority_field_relation_table)) + $where_array[$field_info->priority_field_relation_table] = $counter; - $this->db->insert($field_info->relation_table, $where_array); + $this->db->insert($field_info->relation_table, $where_array); - } elseif ($count >= 1 && !empty($field_info->priority_field_relation_table)) { - $this->db->update($field_info->relation_table, array($field_info->priority_field_relation_table => $counter), $where_array); - } + }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) + { + $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); + } - $counter++; - } - } + $counter++; + } + } } function db_relation_n_n_delete($field_info, $main_primary_key) { - $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); - $this->db->delete($field_info->relation_table); + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); + $this->db->delete($field_info->relation_table); + } + + function get_field_types_basic_table() + { + $db_field_types = array(); + foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) + { + $type = explode("(",$db_field_type->Type); + $db_type = $type[0]; + + if(isset($type[1])) + { + if(substr($type[1],-1) == ')') + { + $length = substr($type[1],0,-1); + } + else + { + list($length) = explode(" ",$type[1]); + $length = substr($length,0,-1); + } + } + else + { + $length = ''; + } + $db_field_types[$db_field_type->Field]['db_max_length'] = $length; + $db_field_types[$db_field_type->Field]['db_type'] = $db_type; + $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false; + $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; + } + + $results = $this->db->field_data($this->table_name); + foreach($results as $num => $row) + { + $row = (array)$row; + $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) ); + } + + return $results; + } + + function get_field_types($table_name) + { + $results = $this->db->field_data($table_name); + + return $results; } function db_update($post_array, $primary_key_value) { - $primary_key_field = $this->get_primary_key(); - return $this->db->update($this->table_name, $post_array, array($primary_key_field => $primary_key_value)); + $primary_key_field = $this->get_primary_key(); + return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value)); } function db_insert($post_array) { - $insert = $this->db->insert($this->table_name, $post_array); - if ($insert) { - return $this->db->insert_id(); - } - return false; + $insert = $this->db->insert($this->table_name,$post_array); + if($insert) + { + return $this->db->insert_id(); + } + return false; } function db_delete($primary_key_value) { - $primary_key_field = $this->get_primary_key(); + $primary_key_field = $this->get_primary_key(); - if ($primary_key_field === false) - return false; + if($primary_key_field === false) + return false; - $this->db->limit(1); - $this->db->delete($this->table_name, array($primary_key_field => $primary_key_value)); - if ($this->db->affected_rows() != 1) - return false; - else - return true; + $this->db->limit(1); + $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); + if( $this->db->affected_rows() != 1) + return false; + else + return true; } function db_file_delete($field_name, $filename) { - if ($this->db->update($this->table_name, array($field_name => ''), array($field_name => $filename))) { - return true; - } else { - return false; - } + if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) + { + return true; + } + else + { + return false; + } + } + + function field_exists($field,$table_name = null) + { + if(empty($table_name)) + { + $table_name = $this->table_name; + } + return $this->db->field_exists($field,$table_name); + } + + function get_primary_key($table_name = null) + { + if($table_name == null) + { + if(isset($this->primary_keys[$this->table_name])) + { + return $this->primary_keys[$this->table_name]; + } + + if(empty($this->primary_key)) + { + $fields = $this->get_field_types_basic_table(); + + foreach($fields as $field) + { + if($field->primary_key == 1) + { + return $field->name; + } + } + + return false; + } + else + { + return $this->primary_key; + } + } + else + { + if(isset($this->primary_keys[$table_name])) + { + return $this->primary_keys[$table_name]; + } + + $fields = $this->get_field_types($table_name); + + foreach($fields as $field) + { + if($field->primary_key == 1) + { + return $field->name; + } + } + + return false; + } + } function escape_str($value) { - return $this->db->escape_str($value); + return $this->db->escape_str($value); } } diff --git a/application/models/ion_auth_model.php b/application/models/ion_auth_model.php old mode 100755 new mode 100644 diff --git a/application/views/example.php b/application/views/example.php deleted file mode 100755 index 5e872ac..0000000 --- a/application/views/example.php +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - -
    -
    - -
    - - diff --git a/assets/grocery_crud/config/index.html b/assets/grocery_crud/config/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/config/index.html +++ b/assets/grocery_crud/config/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/config/language_alias.php b/assets/grocery_crud/config/language_alias.php old mode 100755 new mode 100644 index 3b67735..4656400 --- a/assets/grocery_crud/config/language_alias.php +++ b/assets/grocery_crud/config/language_alias.php @@ -1,33 +1,33 @@ 'af', - 'arabic' => 'ar', - 'bengali' => 'bn', // Timepicker is not avaliable yet - 'bulgarian' => 'bg', - 'chinese' => 'zh-cn', - 'czech' => 'cs', - 'danish' => 'da', // Timepicker is not avaliable yet - 'dutch' => 'nl', - 'french' => 'fr', - 'german' => 'de', - 'greek' => 'el', - 'hungarian' => 'hu', - 'indonesian' => 'id', - 'italian' => 'it', - 'japanese' => 'ja', - 'korean' => 'ko', - 'norwegian' => 'no', - 'persian' => 'fa', // Timepicker is not avaliable yet - 'polish' => 'pl', - 'pt-br.portuguese' => 'pt-br', - 'pt-pt.portuguese' => 'pt', - 'romanian' => 'ro', - 'russian' => 'ru', - 'slovak' => 'sk', - 'spanish' => 'es', - 'thai' => 'th', // Timepicker is not avaliable yet - 'turkish' => 'tr', - 'ukrainian' => 'uk', - 'vietnamese' => 'vi' + 'afrikaans' => 'af', + 'arabic' => 'ar', + 'bengali' => 'bn', // Timepicker is not avaliable yet + 'bulgarian' => 'bg', + 'chinese' => 'zh-cn', + 'czech' => 'cs', + 'danish' => 'da', // Timepicker is not avaliable yet + 'dutch' => 'nl', + 'french' => 'fr', + 'german' => 'de', + 'greek' => 'el', + 'hungarian' => 'hu', + 'indonesian' => 'id', + 'italian' => 'it', + 'japanese' => 'ja', + 'korean' => 'ko', + 'norwegian' => 'no', + 'persian' => 'fa', // Timepicker is not avaliable yet + 'polish' => 'pl', + 'pt-br.portuguese' => 'pt-br', + 'pt-pt.portuguese' => 'pt', + 'romanian' => 'ro', + 'russian' => 'ru', + 'slovak' => 'sk', + 'spanish' => 'es', + 'thai' => 'th', // Timepicker is not avaliable yet + 'turkish' => 'tr', + 'ukrainian' => 'uk', + 'vietnamese' => 'vi' ); diff --git a/assets/grocery_crud/config/translit_chars.php b/assets/grocery_crud/config/translit_chars.php old mode 100755 new mode 100644 index 0050be4..8cea881 --- a/assets/grocery_crud/config/translit_chars.php +++ b/assets/grocery_crud/config/translit_chars.php @@ -1,169 +1,169 @@ - 'A', - '/α|ά|а|à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', + // Aa + '/Α|Ά|А|À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', + '/α|ά|а|à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', - // Bb - '/Β|Б/' => 'B', - '/β|б/' => 'b', + // Bb + '/Β|Б/' => 'B', + '/β|б/' => 'b', - // Cc - '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', - '/ç|ć|ĉ|ċ|č/' => 'c', + // Cc + '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', + '/ç|ć|ĉ|ċ|č/' => 'c', - // Dd - '/Δ|Д|Ð|Ď|Đ/' => 'D', - '/δ|д|ð|ď|đ/' => 'd', + // Dd + '/Δ|Д|Ð|Ď|Đ/' => 'D', + '/δ|д|ð|ď|đ/' => 'd', - // Ee - '/Ε|Έ|Е|Э|Є|È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E', - '/ε|έ|е|э|є|è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e', + // Ee + '/Ε|Έ|Е|Э|Є|È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E', + '/ε|έ|е|э|є|è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e', - // Ff - '/Φ|Ф/' => 'F', - '/φ|ф|ƒ/' => 'f', + // Ff + '/Φ|Ф/' => 'F', + '/φ|ф|ƒ/' => 'f', - // Gg - '/Γ|Г|Ĝ|Ğ|Ġ|Ģ/' => 'G', - '/γ|г|ĝ|ğ|ġ|ģ/' => 'g', + // Gg + '/Γ|Г|Ĝ|Ğ|Ġ|Ģ/' => 'G', + '/γ|г|ĝ|ğ|ġ|ģ/' => 'g', - // Hh - '/Х|Ĥ|Ħ/' => 'H', - '/х|ĥ|ħ/' => 'h', + // Hh + '/Х|Ĥ|Ħ/' => 'H', + '/х|ĥ|ħ/' => 'h', - // Ii - '/Η|Ή|Ι|Ί|И|Ы|І|Ї|Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I', - '/η|ή|ι|ί|и|ы|і|ї|ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i', + // Ii + '/Η|Ή|Ι|Ί|И|Ы|І|Ї|Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I', + '/η|ή|ι|ί|и|ы|і|ї|ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i', - // Jj - '/Ĵ/' => 'J', - '/ĵ/' => 'j', + // Jj + '/Ĵ/' => 'J', + '/ĵ/' => 'j', - // Kk - '/Κ|К|Ķ/' => 'K', - '/κ|к|ķ/' => 'k', + // Kk + '/Κ|К|Ķ/' => 'K', + '/κ|к|ķ/' => 'k', - // Ll - '/Λ|Л|Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L', - '/λ|л|ĺ|ļ|ľ|ŀ|ł/' => 'l', + // Ll + '/Λ|Л|Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L', + '/λ|л|ĺ|ļ|ľ|ŀ|ł/' => 'l', - // Mm - '/Μ|М/' => 'M', - '/μ|м/' => 'm', + // Mm + '/Μ|М/' => 'M', + '/μ|м/' => 'm', - // Nn - '/Ν|Н|Ñ|Ń|Ņ|Ň/' => 'N', - '/ν|н|ñ|ń|ņ|ň|ʼn/' => 'n', + // Nn + '/Ν|Н|Ñ|Ń|Ņ|Ň/' => 'N', + '/ν|н|ñ|ń|ņ|ň|ʼn/' => 'n', - // Oo - '/Ο|Ό|О|Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O', - '/ο|ό|о|ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o', + // Oo + '/Ο|Ό|О|Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O', + '/ο|ό|о|ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o', - // Pp - '/Π|П/' => 'P', - '/π|п/' => 'p', + // Pp + '/Π|П/' => 'P', + '/π|п/' => 'p', - // Qq - // '//' => 'Q', - // '//' => 'q', + // Qq + // '//' => 'Q', + // '//' => 'q', - // Rr - '/Ρ|Р|Ŕ|Ŗ|Ř/' => 'R', - '/ρ|р|ŕ|ŗ|ř/' => 'r', + // Rr + '/Ρ|Р|Ŕ|Ŗ|Ř/' => 'R', + '/ρ|р|ŕ|ŗ|ř/' => 'r', - // Ss - '/Σ|С|Ś|Ŝ|Ş|Š/' => 'S', - '/σ|ς|с|ś|ŝ|ş|š|ſ/' => 's', + // Ss + '/Σ|С|Ś|Ŝ|Ş|Š/' => 'S', + '/σ|ς|с|ś|ŝ|ş|š|ſ/' => 's', - // Tt - '/Τ|Т|Ţ|Ť|Ŧ/' => 'T', - '/τ|т|ţ|ť|ŧ/' => 't', + // Tt + '/Τ|Т|Ţ|Ť|Ŧ/' => 'T', + '/τ|т|ţ|ť|ŧ/' => 't', - // Uu - '/У|Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', - '/у|ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u', + // Uu + '/У|Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', + '/у|ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u', - // Vv - '/В/' => 'V', - '/в/' => 'v', + // Vv + '/В/' => 'V', + '/в/' => 'v', - // Ww - '/Ω|Ώ|Ŵ/' => 'W', - '/ω|ώ|ŵ/' => 'w', + // Ww + '/Ω|Ώ|Ŵ/' => 'W', + '/ω|ώ|ŵ/' => 'w', - // Xx - '/Χ/' => 'X', - '/χ/' => 'x', + // Xx + '/Χ/' => 'X', + '/χ/' => 'x', - // Yy - '/Υ|Ύ|Ψ|Й|Ý|Ÿ|Ŷ/' => 'Y', - '/υ|ύ|ψ|й|ý|ÿ|ŷ/' => 'y', + // Yy + '/Υ|Ύ|Ψ|Й|Ý|Ÿ|Ŷ/' => 'Y', + '/υ|ύ|ψ|й|ý|ÿ|ŷ/' => 'y', - // Zz - '/Ζ|З|Ź|Ż|Ž/' => 'Z', - '/ζ|з|ź|ż|ž/' => 'z', + // Zz + '/Ζ|З|Ź|Ż|Ž/' => 'Z', + '/ζ|з|ź|ż|ž/' => 'z', - '/Θ/' => 'Th', - '/θ/' => 'th', + '/Θ/' => 'Th', + '/θ/' => 'th', - '/Ξ/' => 'Ks', - '/ξ/' => 'ks', + '/Ξ/' => 'Ks', + '/ξ/' => 'ks', - '/Ё/' => 'Yo', - '/ё/' => 'yo', + '/Ё/' => 'Yo', + '/ё/' => 'yo', - '/Ж/' => 'Zh', - '/ж/' => 'zh', + '/Ж/' => 'Zh', + '/ж/' => 'zh', - '/Ц/' => 'Ts', - '/ц/' => 'ts', + '/Ц/' => 'Ts', + '/ц/' => 'ts', - '/Ч/' => 'Ch', - '/ч/' => 'ch', + '/Ч/' => 'Ch', + '/ч/' => 'ch', - '/Ш/' => 'Sh', - '/ш/' => 'sh', + '/Ш/' => 'Sh', + '/ш/' => 'sh', - '/Щ/' => 'Sch', - '/щ/' => 'sch', + '/Щ/' => 'Sch', + '/щ/' => 'sch', - '/Ь|Ъ/' => '', - '/ь|ъ/' => '', + '/Ь|Ъ/' => '', + '/ь|ъ/' => '', - '/Ю/' => 'Yu', - '/ю/' => 'yu', + '/Ю/' => 'Yu', + '/ю/' => 'yu', - '/Я/' => 'Ya', - '/я/' => 'ya', + '/Я/' => 'Ya', + '/я/' => 'ya', - '/Æ|Ǽ/' => 'AE', - '/Ä/' => 'Ae', - '/ä|æ|ǽ/' => 'ae', + '/Æ|Ǽ/' => 'AE', + '/Ä/' => 'Ae', + '/ä|æ|ǽ/' => 'ae', - '/Œ/' => 'OE', - '/Ö/' => 'Oe', - '/ö|œ/' => 'oe', + '/Œ/' => 'OE', + '/Ö/' => 'Oe', + '/ö|œ/' => 'oe', - '/Ü/' => 'Ue', - '/ü/' => 'ue', + '/Ü/' => 'Ue', + '/ü/' => 'ue', - '/IJ/' => 'IJ', - '/ij/' => 'ij', + '/IJ/' => 'IJ', + '/ij/' => 'ij', - '/ß/' => 'ss', + '/ß/'=> 'ss', ); /* End of file translit_chars.php */ -/* Location: ./assets/grocery_crud/translit_chars.php */ +/* Location: ./assets/grocery_crud/translit_chars.php */ \ No newline at end of file diff --git a/assets/grocery_crud/css/index.html b/assets/grocery_crud/css/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/css/index.html +++ b/assets/grocery_crud/css/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/css/jquery_plugins/chosen/chosen-sprite.png b/assets/grocery_crud/css/jquery_plugins/chosen/chosen-sprite.png old mode 100755 new mode 100644 index 113dc9885a6b864ac154b266f024b4597f5c6ae7..c57da70b4b5b1e08a6977ddde182677af0e5e1b8 GIT binary patch literal 538 zcmV+#0_FXQP)cz2)-WJLkv8J@4bb5L`rsE?Kc|FrXHkKz)ov z76MHYM&Apx%05P7orE!>9=yZ~6O0^V?1%{=1UASqa<2Pgnk7fs!OIs9gh{NCN+@=) z>Gfttd5uq;oeR{%NHjtqV~jEQeY?tDff=(jqx>~SZ_e+iN26HR*`0Q!Re)~HD85p> zbL()Mw}bI^#`7wp0+cv&7*LhrtOmR)?PK>(-BeLm#jL5Jfogv-QS(TBnUb;))Krqm zD}uDDeVLNhm1G*pFB`O?iA=dnWBEpqHk8Yh%Qu45EIG=&F-dDmt|;|nN@|3lOkVZ7>z*~a1?_t?U)c+&|JFJke1`&0-a z#PjhRlg?=$KTo4|rU@NyV_fzDy@>h!lVyKShsO8>V>$xyIXRbHK%H~^Aaz=s$Jz^V zlb?KfaKdZqu3^#m$mintvgJ15@j`sb2Zr%69Sn=xN01Tm5r)NQanT=jhwm7zqj2>O cEB}D~0$b-QdD7|v=>Px#07*qoM6N<$g6AXnUH||9 literal 559 zcmV+~0?_@5P)7_w9?!Y=&fGw`Tn=~{*Ton1uJA6{0|TOO2&BQ5HsK)1f-8_= zX_7tWzO=>&TSAbor(8d*in_8nYza}~$VhQ@!VyE5(mbqHI3iLyW7NYng`2gyw{w@M zv1lD|8e5_--EQGNFyBI9Dm%P2^&4|~A8h_6JOwVrJdj*~F_*$UV4Lqxwour8q(n*7 zkflFi+GT_()i#XZnd?O10H>gQ&_n|%z37lBGo2_bA2`{-9A0pctz^q&lZEfVJs1{! zF;D>4e-);bob|{m{RT>)$kHVH!F`36uG0Us4@ZUIJNV@Kb5+!py=js37mE_FMvAKw zj*G~aIL$}23dcoCzleIVN?OtPaAnbYoJoIWh{eAG@xkM<0ryd(K3(} zP8JV&;uuIJ4nL%g8!wSG9E$P+3QVMGgj><+00}M5I5kMzaT<~M;uJ`UhLfbp9Ahdsrux5(g+(>Q*+9wU{AuYPH0}W_u4`|q(9c->{ zt>Jn|lbhH<_x5jU6prFi#S}&XMZ=~Y5VyC3+ZN%hXciz8 zPcLpJgbIK#a49e31-%wf2zh2F&&(Nq;AL%4zA(=QJRGq`sx3y3#0_cg9Fim739XTOu1NKKjlWs`52Q+3 Uja*K~(*OVf07*qoM6N<$g3mu-GXMYp literal 0 HcmV?d00001 diff --git a/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css b/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css old mode 100755 new mode 100644 index d45d930..e7ea092 --- a/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css +++ b/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css @@ -1,481 +1,450 @@ -/* @group Base */ -.chzn-container { - font-size: 13px; - position: relative; - display: inline-block; - zoom: 1; - *display: inline; -} - -.chzn-container .chzn-drop { - background: #fff; - border: 1px solid #aaa; - border-top: 0; - position: absolute; - top: 29px; - left: 0; - -webkit-box-shadow: 0 4px 5px rgba(0, 0, 0, .15); - -moz-box-shadow: 0 4px 5px rgba(0, 0, 0, .15); - -o-box-shadow: 0 4px 5px rgba(0, 0, 0, .15); - box-shadow: 0 4px 5px rgba(0, 0, 0, .15); - z-index: 999; -} - -/* @end */ - -/* @group Single Chosen */ -.chzn-container-single .chzn-single { - background-color: #ffffff; - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0); - background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4)); - background-image: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); - background-image: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); - background-image: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); - background-image: -ms-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); - background-image: linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - border-radius: 5px; - -moz-background-clip: padding; - -webkit-background-clip: padding-box; - background-clip: padding-box; - border: 1px solid #aaaaaa; - -webkit-box-shadow: 0 0 3px #ffffff inset, 0 1px 1px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 0 0 3px #ffffff inset, 0 1px 1px rgba(0, 0, 0, 0.1); - box-shadow: 0 0 3px #ffffff inset, 0 1px 1px rgba(0, 0, 0, 0.1); - display: block; - overflow: hidden; - white-space: nowrap; - position: relative; - height: 23px; - line-height: 24px; - padding: 0 0 0 8px; - color: #444444; - text-decoration: none; -} +/*! +Chosen, a Select Box Enhancer for jQuery and Prototype +by Patrick Filler for Harvest, http://getharvest.com -.chzn-container-single .chzn-default { - color: #999; -} +Version 1.4.2 +Full source at https://github.com/harvesthq/chosen +Copyright (c) 2011-2015 Harvest http://getharvest.com -.chzn-container-single .chzn-single span { - margin-right: 26px; - display: block; - overflow: hidden; - white-space: nowrap; - -o-text-overflow: ellipsis; - -ms-text-overflow: ellipsis; - text-overflow: ellipsis; -} +MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md +This file is generated by `grunt build`, do not edit it by hand. +*/ -.chzn-container-single .chzn-single abbr { - display: block; - position: absolute; - right: 26px; - top: 6px; - width: 12px; - height: 13px; - font-size: 1px; - background: url(chosen-sprite.png) right top no-repeat; -} - -.chzn-container-single .chzn-single abbr:hover { - background-position: right -11px; -} - -.chzn-container-single .chzn-single div { - position: absolute; - right: 0; - top: 0; - display: block; - height: 100%; - width: 18px; -} - -.chzn-container-single .chzn-single div b { - background: url('chosen-sprite.png') no-repeat 0 0; - display: block; - width: 100%; - height: 100%; -} - -.chzn-container-single .chzn-search { - padding: 3px 4px; - position: relative; - margin: 0; - white-space: nowrap; - z-index: 1010; -} - -.chzn-container-single .chzn-search input { - background: #fff url('chosen-sprite.png') no-repeat 100% -22px; - background: url('chosen-sprite.png') no-repeat 100% -22px, -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); - background: url('chosen-sprite.png') no-repeat 100% -22px, -webkit-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat 100% -22px, -moz-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat 100% -22px, -o-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat 100% -22px, -ms-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat 100% -22px, linear-gradient(top, #eeeeee 1%, #ffffff 15%); - margin: 1px 0; - padding: 4px 20px 4px 5px; - outline: 0; - border: 1px solid #aaa; - font-family: sans-serif; - font-size: 1em; -} - -.chzn-container-single .chzn-drop { - -webkit-border-radius: 0 0 4px 4px; - -moz-border-radius: 0 0 4px 4px; - border-radius: 0 0 4px 4px; - -moz-background-clip: padding; - -webkit-background-clip: padding-box; - background-clip: padding-box; +/* @group Base */ +.chosen-container { + position: relative; + display: inline-block; + vertical-align: middle; + font-size: 13px; + zoom: 1; + *display: inline; + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; +} +.chosen-container * { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.chosen-container .chosen-drop { + position: absolute; + top: 100%; + left: -9999px; + z-index: 1010; + width: 100%; + border: 1px solid #aaa; + border-top: 0; + background: #fff; + box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15); +} +.chosen-container.chosen-with-drop .chosen-drop { + left: 0; +} +.chosen-container a { + cursor: pointer; +} +.chosen-container .search-choice .group-name, .chosen-container .chosen-single .group-name { + margin-right: 4px; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + font-weight: normal; + color: #999999; +} +.chosen-container .search-choice .group-name:after, .chosen-container .chosen-single .group-name:after { + content: ":"; + padding-left: 2px; + vertical-align: top; } /* @end */ - -.chzn-container-single-nosearch .chzn-search input { - position: absolute; - left: -9000px; -} - -/* @group Multi Chosen */ -.chzn-container-multi .chzn-choices { - background-color: #fff; - background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); - background-image: -webkit-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background-image: -moz-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background-image: -o-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background-image: -ms-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background-image: linear-gradient(top, #eeeeee 1%, #ffffff 15%); - border: 1px solid #aaa; - margin: 0; - padding: 0; - cursor: text; - overflow: hidden; - height: auto !important; - height: 1%; - position: relative; -} - -.chzn-container-multi .chzn-choices li { - float: left; - list-style: none; -} - -.chzn-container-multi .chzn-choices .search-field { - white-space: nowrap; - margin: 0; - padding: 0; -} - -.chzn-container-multi .chzn-choices .search-field input { - color: #666; - background: transparent !important; - border: 0 !important; - font-family: sans-serif; - font-size: 100%; - height: 15px; - padding: 5px; - margin: 1px 0; - outline: 0; - -webkit-box-shadow: none; - -moz-box-shadow: none; - -o-box-shadow: none; - box-shadow: none; -} - -.chzn-container-multi .chzn-choices .search-field .default { - color: #999; -} - -.chzn-container-multi .chzn-choices .search-choice { - -webkit-border-radius: 3px; - -moz-border-radius: 3px; - border-radius: 3px; - -moz-background-clip: padding; - -webkit-background-clip: padding-box; - background-clip: padding-box; - background-color: #e4e4e4; - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f4f4f4', endColorstr='#eeeeee', GradientType=0); - background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); - background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); - background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); - background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); - background-image: -ms-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); - background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); - -webkit-box-shadow: 0 0 2px #ffffff inset, 0 1px 0 rgba(0, 0, 0, 0.05); - -moz-box-shadow: 0 0 2px #ffffff inset, 0 1px 0 rgba(0, 0, 0, 0.05); - box-shadow: 0 0 2px #ffffff inset, 0 1px 0 rgba(0, 0, 0, 0.05); - color: #333; - border: 1px solid #aaaaaa; - line-height: 13px; - padding: 3px 20px 3px 5px; - margin: 3px 0 3px 5px; - position: relative; - cursor: default; -} - -.chzn-container-multi .chzn-choices .search-choice-focus { - background: #d4d4d4; -} - -.chzn-container-multi .chzn-choices .search-choice .search-choice-close { - display: block; - position: absolute; - right: 3px; - top: 4px; - width: 12px; - height: 13px; - font-size: 1px; - background: url(chosen-sprite.png) right top no-repeat; -} - -.chzn-container-multi .chzn-choices .search-choice .search-choice-close:hover { - background-position: right -11px; -} - -.chzn-container-multi .chzn-choices .search-choice-focus .search-choice-close { - background-position: right -11px; +/* @group Single Chosen */ +.chosen-container-single .chosen-single { + position: relative; + display: block; + overflow: hidden; + padding: 0 0 0 8px; + height: 25px; + border: 1px solid #aaa; + border-radius: 5px; + background-color: #fff; + background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4)); + background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); + background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); + background: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); + background: linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); + background-clip: padding-box; + box-shadow: 0 0 3px white inset, 0 1px 1px rgba(0, 0, 0, 0.1); + color: #444; + text-decoration: none; + white-space: nowrap; + line-height: 24px; +} +.chosen-container-single .chosen-default { + color: #999; +} +.chosen-container-single .chosen-single span { + display: block; + overflow: hidden; + margin-right: 26px; + text-overflow: ellipsis; + white-space: nowrap; +} +.chosen-container-single .chosen-single-with-deselect span { + margin-right: 38px; +} +.chosen-container-single .chosen-single abbr { + position: absolute; + top: 6px; + right: 26px; + display: block; + width: 12px; + height: 12px; + background: url('chosen-sprite.png') -42px 1px no-repeat; + font-size: 1px; +} +.chosen-container-single .chosen-single abbr:hover { + background-position: -42px -10px; +} +.chosen-container-single.chosen-disabled .chosen-single abbr:hover { + background-position: -42px -10px; +} +.chosen-container-single .chosen-single div { + position: absolute; + top: 0; + right: 0; + display: block; + width: 18px; + height: 100%; +} +.chosen-container-single .chosen-single div b { + display: block; + width: 100%; + height: 100%; + background: url('chosen-sprite.png') no-repeat 0px 2px; +} +.chosen-container-single .chosen-search { + position: relative; + z-index: 1010; + margin: 0; + padding: 3px 4px; + white-space: nowrap; +} +.chosen-container-single .chosen-search input[type="text"] { + margin: 1px 0; + padding: 4px 20px 4px 5px; + width: 100%; + height: auto; + outline: 0; + border: 1px solid #aaa; + background: white url('chosen-sprite.png') no-repeat 100% -20px; + background: url('chosen-sprite.png') no-repeat 100% -20px; + font-size: 1em; + font-family: sans-serif; + line-height: normal; + border-radius: 0; +} +.chosen-container-single .chosen-drop { + margin-top: -1px; + border-radius: 0 0 4px 4px; + background-clip: padding-box; +} +.chosen-container-single.chosen-container-single-nosearch .chosen-search { + position: absolute; + left: -9999px; } /* @end */ - /* @group Results */ -.chzn-container .chzn-results { - margin: 0 4px 4px 0; - max-height: 240px; - padding: 0 0 0 4px; - position: relative; - overflow-x: hidden; - overflow-y: auto; -} - -.chzn-container-multi .chzn-results { - margin: -1px 0 0; - padding: 0; -} - -.chzn-container .chzn-results li { - display: none; - line-height: 15px; - padding: 5px 6px; - margin: 0; - list-style: none; -} - -.chzn-container .chzn-results .active-result { - cursor: pointer; - display: list-item; +.chosen-container .chosen-results { + color: #444; + position: relative; + overflow-x: hidden; + overflow-y: auto; + margin: 0 4px 4px 0; + padding: 0 0 0 4px; + max-height: 240px; + -webkit-overflow-scrolling: touch; +} +.chosen-container .chosen-results li { + display: none; + margin: 0; + padding: 5px 6px; + list-style: none; + line-height: 15px; + word-wrap: break-word; + -webkit-touch-callout: none; +} +.chosen-container .chosen-results li.active-result { + display: list-item; + cursor: pointer; +} +.chosen-container .chosen-results li.disabled-result { + display: list-item; + color: #ccc; + cursor: default; +} +.chosen-container .chosen-results li.highlighted { + background-color: #3875d7; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc)); + background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: linear-gradient(#3875d7 20%, #2a62bc 90%); + color: #fff; +} +.chosen-container .chosen-results li.no-results { + color: #777; + display: list-item; + background: #f4f4f4; +} +.chosen-container .chosen-results li.group-result { + display: list-item; + font-weight: bold; + cursor: default; +} +.chosen-container .chosen-results li.group-option { + padding-left: 15px; +} +.chosen-container .chosen-results li em { + font-style: normal; + text-decoration: underline; } -.chzn-container .chzn-results .highlighted { - background-color: #3875d7; - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#3875d7', endColorstr='#2a62bc', GradientType=0); - background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc)); - background-image: -webkit-linear-gradient(top, #3875d7 20%, #2a62bc 90%); - background-image: -moz-linear-gradient(top, #3875d7 20%, #2a62bc 90%); - background-image: -o-linear-gradient(top, #3875d7 20%, #2a62bc 90%); - background-image: -ms-linear-gradient(top, #3875d7 20%, #2a62bc 90%); - background-image: linear-gradient(top, #3875d7 20%, #2a62bc 90%); - color: #fff; -} - -.chzn-container .chzn-results li em { - background: #feffde; - font-style: normal; -} - -.chzn-container .chzn-results .highlighted em { - background: transparent; -} - -.chzn-container .chzn-results .no-results { - background: #f4f4f4; - display: list-item; -} - -.chzn-container .chzn-results .group-result { - cursor: default; - color: #999; - font-weight: bold; -} - -.chzn-container .chzn-results .group-option { - padding-left: 15px; -} - -.chzn-container-multi .chzn-drop .result-selected { - display: none; -} - -.chzn-container .chzn-results-scroll { - background: white; - margin: 0 4px; - position: absolute; - text-align: center; - width: 321px; /* This should by dynamic with js */ - z-index: 1; -} - -.chzn-container .chzn-results-scroll span { - display: inline-block; - height: 17px; - text-indent: -5000px; - width: 9px; -} - -.chzn-container .chzn-results-scroll-down { - bottom: 0; -} - -.chzn-container .chzn-results-scroll-down span { - background: url('chosen-sprite.png') no-repeat -4px -3px; -} - -.chzn-container .chzn-results-scroll-up span { - background: url('chosen-sprite.png') no-repeat -22px -3px; +/* @end */ +/* @group Multi Chosen */ +.chosen-container-multi .chosen-choices { + position: relative; + overflow: hidden; + margin: 0; + padding: 0 5px; + width: 100%; + height: auto !important; + height: 1%; + border: 1px solid #aaa; + background-color: #fff; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); + background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%); + background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%); + background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%); + background-image: linear-gradient(#eeeeee 1%, #ffffff 15%); + cursor: text; +} +.chosen-container-multi .chosen-choices li { + float: left; + list-style: none; +} +.chosen-container-multi .chosen-choices li.search-field { + margin: 0; + padding: 0; + white-space: nowrap; +} +.chosen-container-multi .chosen-choices li.search-field input[type="text"] { + margin: 1px 0; + padding: 0; + height: 25px; + outline: 0; + border: 0 !important; + background: transparent !important; + box-shadow: none; + color: #999; + font-size: 100%; + font-family: sans-serif; + line-height: normal; + border-radius: 0; +} +.chosen-container-multi .chosen-choices li.search-choice { + position: relative; + margin: 3px 5px 3px 0; + padding: 3px 20px 3px 5px; + border: 1px solid #aaa; + max-width: 100%; + border-radius: 3px; + background-color: #eeeeee; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); + background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-size: 100% 19px; + background-repeat: repeat-x; + background-clip: padding-box; + box-shadow: 0 0 2px white inset, 0 1px 0 rgba(0, 0, 0, 0.05); + color: #333; + line-height: 13px; + cursor: default; +} +.chosen-container-multi .chosen-choices li.search-choice span { + word-wrap: break-word; +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close { + position: absolute; + top: 4px; + right: 3px; + display: block; + width: 12px; + height: 12px; + background: url('chosen-sprite.png') -42px 1px no-repeat; + font-size: 1px; +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover { + background-position: -42px -10px; +} +.chosen-container-multi .chosen-choices li.search-choice-disabled { + padding-right: 5px; + border: 1px solid #ccc; + background-color: #e4e4e4; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); + background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + color: #666; +} +.chosen-container-multi .chosen-choices li.search-choice-focus { + background: #d4d4d4; +} +.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close { + background-position: -42px -10px; +} +.chosen-container-multi .chosen-results { + margin: 0; + padding: 0; +} +.chosen-container-multi .chosen-drop .result-selected { + display: list-item; + color: #ccc; + cursor: default; } /* @end */ - /* @group Active */ -.chzn-container-active .chzn-single { - -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - -moz-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - -o-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - box-shadow: 0 0 5px rgba(0, 0, 0, .3); - border: 1px solid #5897fb; +.chosen-container-active .chosen-single { + border: 1px solid #5897fb; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); +} +.chosen-container-active.chosen-with-drop .chosen-single { + border: 1px solid #aaa; + -moz-border-radius-bottomright: 0; + border-bottom-right-radius: 0; + -moz-border-radius-bottomleft: 0; + border-bottom-left-radius: 0; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff)); + background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%); + background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%); + background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%); + background-image: linear-gradient(#eeeeee 20%, #ffffff 80%); + box-shadow: 0 1px 0 #fff inset; +} +.chosen-container-active.chosen-with-drop .chosen-single div { + border-left: none; + background: transparent; +} +.chosen-container-active.chosen-with-drop .chosen-single div b { + background-position: -18px 2px; +} +.chosen-container-active .chosen-choices { + border: 1px solid #5897fb; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); +} +.chosen-container-active .chosen-choices li.search-field input[type="text"] { + color: #222 !important; } -.chzn-container-active .chzn-single-with-drop { - border: 1px solid #aaa; - -webkit-box-shadow: 0 1px 0 #fff inset; - -moz-box-shadow: 0 1px 0 #fff inset; - -o-box-shadow: 0 1px 0 #fff inset; - box-shadow: 0 1px 0 #fff inset; - background-color: #eee; - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#ffffff', GradientType=0); - background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff)); - background-image: -webkit-linear-gradient(top, #eeeeee 20%, #ffffff 80%); - background-image: -moz-linear-gradient(top, #eeeeee 20%, #ffffff 80%); - background-image: -o-linear-gradient(top, #eeeeee 20%, #ffffff 80%); - background-image: -ms-linear-gradient(top, #eeeeee 20%, #ffffff 80%); - background-image: linear-gradient(top, #eeeeee 20%, #ffffff 80%); - -webkit-border-bottom-left-radius: 0; - -webkit-border-bottom-right-radius: 0; - -moz-border-radius-bottomleft: 0; - -moz-border-radius-bottomright: 0; - border-bottom-left-radius: 0; - border-bottom-right-radius: 0; +/* @end */ +/* @group Disabled Support */ +.chosen-disabled { + opacity: 0.5 !important; + cursor: default; } - -.chzn-container-active .chzn-single-with-drop div { - background: transparent; - border-left: none; +.chosen-disabled .chosen-single { + cursor: default; } - -.chzn-container-active .chzn-single-with-drop div b { - background-position: -18px 1px; +.chosen-disabled .chosen-choices .search-choice .search-choice-close { + cursor: default; } -.chzn-container-active .chzn-choices { - -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - -moz-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - -o-box-shadow: 0 0 5px rgba(0, 0, 0, .3); - box-shadow: 0 0 5px rgba(0, 0, 0, .3); - border: 1px solid #5897fb; +/* @end */ +/* @group Right to Left */ +.chosen-rtl { + text-align: right; } - -.chzn-container-active .chzn-choices .search-field input { - color: #111 !important; +.chosen-rtl .chosen-single { + overflow: visible; + padding: 0 8px 0 0; } - -/* @end */ - -/* @group Disabled Support */ -.chzn-disabled { - cursor: default; - opacity: 0.5 !important; +.chosen-rtl .chosen-single span { + margin-right: 0; + margin-left: 26px; + direction: rtl; } - -.chzn-disabled .chzn-single { - cursor: default; +.chosen-rtl .chosen-single-with-deselect span { + margin-left: 38px; } - -.chzn-disabled .chzn-choices .search-choice .search-choice-close { - cursor: default; +.chosen-rtl .chosen-single div { + right: auto; + left: 3px; } - -/* @group Right to Left */ -.chzn-rtl { - text-align: right; +.chosen-rtl .chosen-single abbr { + right: auto; + left: 26px; } - -.chzn-rtl .chzn-single { - padding: 0 8px 0 0; - overflow: visible; +.chosen-rtl .chosen-choices li { + float: right; } - -.chzn-rtl .chzn-single span { - margin-left: 26px; - margin-right: 0; - direction: rtl; +.chosen-rtl .chosen-choices li.search-field input[type="text"] { + direction: rtl; } - -.chzn-rtl .chzn-single div { - left: 3px; - right: auto; +.chosen-rtl .chosen-choices li.search-choice { + margin: 3px 5px 3px 0; + padding: 3px 5px 3px 19px; } - -.chzn-rtl .chzn-single abbr { - left: 26px; - right: auto; +.chosen-rtl .chosen-choices li.search-choice .search-choice-close { + right: auto; + left: 4px; } - -.chzn-rtl .chzn-choices .search-field input { - direction: rtl; +.chosen-rtl.chosen-container-single-nosearch .chosen-search, +.chosen-rtl .chosen-drop { + left: 9999px; } - -.chzn-rtl .chzn-choices li { - float: right; +.chosen-rtl.chosen-container-single .chosen-results { + margin: 0 0 4px 4px; + padding: 0 4px 0 0; } - -.chzn-rtl .chzn-choices .search-choice { - padding: 3px 5px 3px 19px; - margin: 3px 5px 3px 0; +.chosen-rtl .chosen-results li.group-option { + padding-right: 15px; + padding-left: 0; } - -.chzn-rtl .chzn-choices .search-choice .search-choice-close { - left: 4px; - right: auto; - background-position: right top; +.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div { + border-right: none; } - -.chzn-rtl.chzn-container-single .chzn-results { - margin: 0 0 4px 4px; - padding: 0 4px 0 0; +.chosen-rtl .chosen-search input[type="text"] { + padding: 4px 5px 4px 20px; + background: white url('chosen-sprite.png') no-repeat -30px -20px; + background: url('chosen-sprite.png') no-repeat -30px -20px; + direction: rtl; } - -.chzn-rtl .chzn-results .group-option { - padding-left: 0; - padding-right: 15px; +.chosen-rtl.chosen-container-single .chosen-single div b { + background-position: 6px 2px; } - -.chzn-rtl.chzn-container-active .chzn-single-with-drop div { - border-right: none; +.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b { + background-position: -12px 2px; } -.chzn-rtl .chzn-search input { - background: #fff url('chosen-sprite.png') no-repeat -38px -22px; - background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); - background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat -38px -22px, -moz-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat -38px -22px, -o-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat -38px -22px, -ms-linear-gradient(top, #eeeeee 1%, #ffffff 15%); - background: url('chosen-sprite.png') no-repeat -38px -22px, linear-gradient(top, #eeeeee 1%, #ffffff 15%); - padding: 4px 5px 4px 20px; - direction: rtl; +/* @end */ +/* @group Retina compatibility */ +@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi), only screen and (min-resolution: 1.5dppx) { + .chosen-rtl .chosen-search input[type="text"], + .chosen-container-single .chosen-single abbr, + .chosen-container-single .chosen-single div b, + .chosen-container-single .chosen-search input[type="text"], + .chosen-container-multi .chosen-choices .search-choice .search-choice-close, + .chosen-container .chosen-results-scroll-down span, + .chosen-container .chosen-results-scroll-up span { + background-image: url('chosen-sprite@2x.png') !important; + background-size: 52px 37px !important; + background-repeat: no-repeat !important; + } } - /* @end */ diff --git a/assets/grocery_crud/css/jquery_plugins/chosen/chosen.min.css b/assets/grocery_crud/css/jquery_plugins/chosen/chosen.min.css new file mode 100644 index 0000000..5ca6159 --- /dev/null +++ b/assets/grocery_crud/css/jquery_plugins/chosen/chosen.min.css @@ -0,0 +1,3 @@ +/* Chosen v1.4.2 | (c) 2011-2015 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */ + +.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;zoom:1;*display:inline;-webkit-user-select:none;-moz-user-select:none;user-select:none}.chosen-container *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.chosen-container .chosen-drop{position:absolute;top:100%;left:-9999px;z-index:1010;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15)}.chosen-container.chosen-with-drop .chosen-drop{left:0}.chosen-container a{cursor:pointer}.chosen-container .search-choice .group-name,.chosen-container .chosen-single .group-name{margin-right:4px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-weight:400;color:#999}.chosen-container .search-choice .group-name:after,.chosen-container .chosen-single .group-name:after{content:":";padding-left:2px;vertical-align:top}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:25px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),color-stop(100%,#f4f4f4));background:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:24px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(chosen-sprite.png) no-repeat 0 2px}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:#fff url(chosen-sprite.png) no-repeat 100% -20px;background:url(chosen-sprite.png) no-repeat 100% -20px;font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;left:-9999px}.chosen-container .chosen-results{color:#444;position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px;word-wrap:break-word;-webkit-touch-callout:none}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#3875d7),color-stop(90%,#2a62bc));background-image:-webkit-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-moz-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-o-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{color:#777;display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;margin:0;padding:0 5px;width:100%;height:auto!important;height:1%;border:1px solid #aaa;background-color:#fff;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background-image:-webkit-linear-gradient(#eee 1%,#fff 15%);background-image:-moz-linear-gradient(#eee 1%,#fff 15%);background-image:-o-linear-gradient(#eee 1%,#fff 15%);background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:0;height:25px;outline:0;border:0!important;background:transparent!important;box-shadow:none;color:#999;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 5px 3px 0;padding:3px 20px 3px 5px;border:1px solid #aaa;max-width:100%;border-radius:3px;background-color:#eee;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-size:100% 19px;background-repeat:repeat-x;background-clip:padding-box;box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice span{word-wrap:break-word}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;-moz-border-radius-bottomright:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#eee),color-stop(80%,#fff));background-image:-webkit-linear-gradient(#eee 20%,#fff 80%);background-image:-moz-linear-gradient(#eee 20%,#fff 80%);background-image:-o-linear-gradient(#eee 20%,#fff 80%);background-image:linear-gradient(#eee 20%,#fff 80%);box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:0;background:transparent}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#222!important}.chosen-disabled{opacity:.5!important;cursor:default}.chosen-disabled .chosen-single{cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl.chosen-container-single-nosearch .chosen-search,.chosen-rtl .chosen-drop{left:9999px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:0}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:#fff url(chosen-sprite.png) no-repeat -30px -20px;background:url(chosen-sprite.png) no-repeat -30px -20px;direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-resolution:144dpi),only screen and (min-resolution:1.5dppx){.chosen-rtl .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-container-single .chosen-search input[type=text],.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span{background-image:url(chosen-sprite@2x.png)!important;background-size:52px 37px!important;background-repeat:no-repeat!important}} \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/chosen/index.html b/assets/grocery_crud/css/jquery_plugins/chosen/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/css/jquery_plugins/chosen/index.html +++ b/assets/grocery_crud/css/jquery_plugins/chosen/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/blank.gif b/assets/grocery_crud/css/jquery_plugins/fancybox/blank.gif old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_close.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_close.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_loading.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_loading.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_left.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_left.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_right.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_nav_right.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_e.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_e.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_n.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_n.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_ne.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_ne.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_nw.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_nw.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_s.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_s.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_se.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_se.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_sw.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_sw.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_w.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_shadow_w.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_left.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_left.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_main.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_main.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_over.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_over.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_right.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancy_title_right.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-x.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-x.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-y.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox-y.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox.png b/assets/grocery_crud/css/jquery_plugins/fancybox/fancybox.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/fancybox/jquery.fancybox.css b/assets/grocery_crud/css/jquery_plugins/fancybox/jquery.fancybox.css old mode 100755 new mode 100644 index ddcdf55..8fe0fbd --- a/assets/grocery_crud/css/jquery_plugins/fancybox/jquery.fancybox.css +++ b/assets/grocery_crud/css/jquery_plugins/fancybox/jquery.fancybox.css @@ -3,10 +3,10 @@ * Simple and fancy lightbox alternative * * Examples and documentation at: http://fancybox.net - * + * * Copyright (c) 2008 - 2010 Janis Skarnelis * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. - * + * * Version: 1.3.4 (11/11/2010) * Requires: jQuery v1.3+ * @@ -16,399 +16,344 @@ */ #fancybox-loading { - position: fixed; - top: 50%; - left: 50%; - width: 40px; - height: 40px; - margin-top: -20px; - margin-left: -20px; - cursor: pointer; - overflow: hidden; - z-index: 1104; - display: none; + position: fixed; + top: 50%; + left: 50%; + width: 40px; + height: 40px; + margin-top: -20px; + margin-left: -20px; + cursor: pointer; + overflow: hidden; + z-index: 1104; + display: none; } #fancybox-loading div { - position: absolute; - top: 0; - left: 0; - width: 40px; - height: 480px; - background-image: url('fancybox.png'); + position: absolute; + top: 0; + left: 0; + width: 40px; + height: 480px; + background-image: url('fancybox.png'); } #fancybox-overlay { - position: absolute; - top: 0; - left: 0; - width: 100%; - z-index: 1100; - display: none; + position: absolute; + top: 0; + left: 0; + width: 100%; + z-index: 1100; + display: none; } #fancybox-tmp { - padding: 0; - margin: 0; - border: 0; - overflow: auto; - display: none; + padding: 0; + margin: 0; + border: 0; + overflow: auto; + display: none; } #fancybox-wrap { - position: absolute; - top: 0; - left: 0; - padding: 20px; - z-index: 1101; - outline: none; - display: none; + position: absolute; + top: 0; + left: 0; + padding: 20px; + z-index: 1101; + outline: none; + display: none; } #fancybox-outer { - position: relative; - width: 100%; - height: 100%; - background: #fff; + position: relative; + width: 100%; + height: 100%; + background: #fff; } #fancybox-content { - width: 0; - height: 0; - padding: 0; - outline: none; - position: relative; - overflow: hidden; - z-index: 1102; - border: 0px solid #fff; + width: 0; + height: 0; + padding: 0; + outline: none; + position: relative; + overflow: hidden; + z-index: 1102; + border: 0px solid #fff; } #fancybox-hide-sel-frame { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: transparent; - z-index: 1101; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: transparent; + z-index: 1101; } #fancybox-close { - position: absolute; - top: -15px; - right: -15px; - width: 30px; - height: 30px; - background: transparent url('fancybox.png') -40px 0px; - cursor: pointer; - z-index: 1103; - display: none; + position: absolute; + top: -15px; + right: -15px; + width: 30px; + height: 30px; + background: transparent url('fancybox.png') -40px 0px; + cursor: pointer; + z-index: 1103; + display: none; } #fancybox-error { - color: #444; - font: normal 12px/20px Arial; - padding: 14px; - margin: 0; + color: #444; + font: normal 12px/20px Arial; + padding: 14px; + margin: 0; } #fancybox-img { - width: 100%; - height: 100%; - padding: 0; - margin: 0; - border: none; - outline: none; - line-height: 0; - vertical-align: top; + width: 100%; + height: 100%; + padding: 0; + margin: 0; + border: none; + outline: none; + line-height: 0; + vertical-align: top; } #fancybox-frame { - width: 100%; - height: 100%; - border: none; - display: block; + width: 100%; + height: 100%; + border: none; + display: block; } #fancybox-left, #fancybox-right { - position: absolute; - bottom: 0px; - height: 100%; - width: 35%; - cursor: pointer; - outline: none; - background: transparent url('blank.gif'); - z-index: 1102; - display: none; + position: absolute; + bottom: 0px; + height: 100%; + width: 35%; + cursor: pointer; + outline: none; + background: transparent url('blank.gif'); + z-index: 1102; + display: none; } #fancybox-left { - left: 0px; + left: 0px; } #fancybox-right { - right: 0px; + right: 0px; } #fancybox-left-ico, #fancybox-right-ico { - position: absolute; - top: 50%; - left: -9999px; - width: 30px; - height: 30px; - margin-top: -15px; - cursor: pointer; - z-index: 1102; - display: block; + position: absolute; + top: 50%; + left: -9999px; + width: 30px; + height: 30px; + margin-top: -15px; + cursor: pointer; + z-index: 1102; + display: block; } #fancybox-left-ico { - background-image: url('fancybox.png'); - background-position: -40px -30px; + background-image: url('fancybox.png'); + background-position: -40px -30px; } #fancybox-right-ico { - background-image: url('fancybox.png'); - background-position: -40px -60px; + background-image: url('fancybox.png'); + background-position: -40px -60px; } #fancybox-left:hover, #fancybox-right:hover { - visibility: visible; /* IE6 */ + visibility: visible; /* IE6 */ } #fancybox-left:hover span { - left: 20px; + left: 20px; } #fancybox-right:hover span { - left: auto; - right: 20px; + left: auto; + right: 20px; } .fancybox-bg { - position: absolute; - padding: 0; - margin: 0; - border: 0; - width: 20px; - height: 20px; - z-index: 1001; + position: absolute; + padding: 0; + margin: 0; + border: 0; + width: 20px; + height: 20px; + z-index: 1001; } #fancybox-bg-n { - top: -20px; - left: 0; - width: 100%; - background-image: url('fancybox-x.png'); + top: -20px; + left: 0; + width: 100%; + background-image: url('fancybox-x.png'); } #fancybox-bg-ne { - top: -20px; - right: -20px; - background-image: url('fancybox.png'); - background-position: -40px -162px; + top: -20px; + right: -20px; + background-image: url('fancybox.png'); + background-position: -40px -162px; } #fancybox-bg-e { - top: 0; - right: -20px; - height: 100%; - background-image: url('fancybox-y.png'); - background-position: -20px 0px; + top: 0; + right: -20px; + height: 100%; + background-image: url('fancybox-y.png'); + background-position: -20px 0px; } #fancybox-bg-se { - bottom: -20px; - right: -20px; - background-image: url('fancybox.png'); - background-position: -40px -182px; + bottom: -20px; + right: -20px; + background-image: url('fancybox.png'); + background-position: -40px -182px; } #fancybox-bg-s { - bottom: -20px; - left: 0; - width: 100%; - background-image: url('fancybox-x.png'); - background-position: 0px -20px; + bottom: -20px; + left: 0; + width: 100%; + background-image: url('fancybox-x.png'); + background-position: 0px -20px; } #fancybox-bg-sw { - bottom: -20px; - left: -20px; - background-image: url('fancybox.png'); - background-position: -40px -142px; + bottom: -20px; + left: -20px; + background-image: url('fancybox.png'); + background-position: -40px -142px; } #fancybox-bg-w { - top: 0; - left: -20px; - height: 100%; - background-image: url('fancybox-y.png'); + top: 0; + left: -20px; + height: 100%; + background-image: url('fancybox-y.png'); } #fancybox-bg-nw { - top: -20px; - left: -20px; - background-image: url('fancybox.png'); - background-position: -40px -122px; + top: -20px; + left: -20px; + background-image: url('fancybox.png'); + background-position: -40px -122px; } #fancybox-title { - font-family: Helvetica; - font-size: 12px; - z-index: 1102; + font-family: Helvetica; + font-size: 12px; + z-index: 1102; } .fancybox-title-inside { - padding-bottom: 10px; - text-align: center; - color: #333; - background: #fff; - position: relative; + padding-bottom: 10px; + text-align: center; + color: #333; + background: #fff; + position: relative; } .fancybox-title-outside { - padding-top: 10px; - color: #fff; + padding-top: 10px; + color: #fff; } .fancybox-title-over { - position: absolute; - bottom: 0; - left: 0; - color: #FFF; - text-align: left; + position: absolute; + bottom: 0; + left: 0; + color: #FFF; + text-align: left; } #fancybox-title-over { - padding: 10px; - background-image: url('fancy_title_over.png'); - display: block; + padding: 10px; + background-image: url('fancy_title_over.png'); + display: block; } .fancybox-title-float { - position: absolute; - left: 0; - bottom: -20px; - height: 32px; + position: absolute; + left: 0; + bottom: -20px; + height: 32px; } #fancybox-title-float-wrap { - border: none; - border-collapse: collapse; - width: auto; + border: none; + border-collapse: collapse; + width: auto; } #fancybox-title-float-wrap td { - border: none; - white-space: nowrap; + border: none; + white-space: nowrap; } #fancybox-title-float-left { - padding: 0 0 0 15px; - background: url('fancybox.png') -40px -90px no-repeat; + padding: 0 0 0 15px; + background: url('fancybox.png') -40px -90px no-repeat; } #fancybox-title-float-main { - color: #FFF; - line-height: 29px; - font-weight: bold; - padding: 0 0 3px 0; - background: url('fancybox-x.png') 0px -40px; + color: #FFF; + line-height: 29px; + font-weight: bold; + padding: 0 0 3px 0; + background: url('fancybox-x.png') 0px -40px; } #fancybox-title-float-right { - padding: 0 0 0 15px; - background: url('fancybox.png') -55px -90px no-repeat; + padding: 0 0 0 15px; + background: url('fancybox.png') -55px -90px no-repeat; } /* IE6 */ -.fancybox-ie6 #fancybox-close { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); -} - -.fancybox-ie6 #fancybox-left-ico { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); -} +.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); } -.fancybox-ie6 #fancybox-right-ico { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); -} +.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); } -.fancybox-ie6 #fancybox-title-over { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); - zoom: 1; -} - -.fancybox-ie6 #fancybox-title-float-left { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); -} - -.fancybox-ie6 #fancybox-title-float-main { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); -} - -.fancybox-ie6 #fancybox-title-float-right { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); -} +.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; } +.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame { - height: expression(this.parentNode.clientHeight + "px"); + height: expression(this.parentNode.clientHeight + "px"); } #fancybox-loading.fancybox-ie6 { - position: absolute; - margin-top: 0; - top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'); + position: absolute; margin-top: 0; + top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'); } -#fancybox-loading.fancybox-ie6 div { - background: transparent; - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); -} +#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); } /* IE6, IE7, IE8 */ -.fancybox-ie .fancybox-bg { - background: transparent !important; -} - -.fancybox-ie #fancybox-bg-n { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-ne { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-e { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-se { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); -} +.fancybox-ie .fancybox-bg { background: transparent !important; } -.fancybox-ie #fancybox-bg-s { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-sw { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-w { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); -} - -.fancybox-ie #fancybox-bg-nw { - filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); -} +.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); } \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/bootstrap.min.css b/assets/grocery_crud/css/jquery_plugins/file_upload/bootstrap.min.css old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/file-uploader.css b/assets/grocery_crud/css/jquery_plugins/file_upload/file-uploader.css old mode 100755 new mode 100644 index 17dd579..85e8103 --- a/assets/grocery_crud/css/jquery_plugins/file_upload/file-uploader.css +++ b/assets/grocery_crud/css/jquery_plugins/file_upload/file-uploader.css @@ -1,33 +1,29 @@ .qq-upload-button { - display: block; /* or inline-block */ - padding: 7px 15px; - text-align: center; - border: 1px solid #AAA; - color: #555555; - border-radius: 5px; - float: left; - - background: #ccc; - background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #ccc), color-stop(0.6, #eee)); - background-image: -webkit-linear-gradient(center bottom, #ccc 0%, #eee 60%); - background-image: -moz-linear-gradient(center bottom, #ccc 0%, #eee 60%); - background-image: -o-linear-gradient(bottom, #ccc 0%, #eee 60%); - background-image: -ms-linear-gradient(top, #cccccc 0%, #eeeeee 60%); - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#eeeeee', GradientType=0); - background-image: linear-gradient(top, #cccccc 0%, #eeeeee 60%); + display:block; /* or inline-block */ + padding: 7px 15px; + text-align:center; + border:1px solid #AAA; + color: #555555; + border-radius: 5px; + float:left; + + background: #ccc; + background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #ccc), color-stop(0.6, #eee)); + background-image: -webkit-linear-gradient(center bottom, #ccc 0%, #eee 60%); + background-image: -moz-linear-gradient(center bottom, #ccc 0%, #eee 60%); + background-image: -o-linear-gradient(bottom, #ccc 0%, #eee 60%); + background-image: -ms-linear-gradient(top, #cccccc 0%,#eeeeee 60%); + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cccccc', endColorstr='#eeeeee',GradientType=0 ); + background-image: linear-gradient(top, #cccccc 0%,#eeeeee 60%); } - .qq-upload-button:hover { - background: #bbb; - background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #bbb), color-stop(0.6, #ddd)); - background-image: -webkit-linear-gradient(center bottom, #bbb 0%, #ddd 60%); - background-image: -moz-linear-gradient(center bottom, #bbb 0%, #ddd 60%); - background-image: -o-linear-gradient(bottom, #bbb 0%, #ddd 60%); - background-image: -ms-linear-gradient(top, #bbbbbb 0%, #dddddd 60%); - filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bbbbbb', endColorstr='#dddddd', GradientType=0); - background-image: linear-gradient(top, #bbbbbb 0%, #dddddd 60%); -} - -.qq-upload-button:focus { - outline: 1px dotted black; + background: #bbb; + background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #bbb), color-stop(0.6, #ddd)); + background-image: -webkit-linear-gradient(center bottom, #bbb 0%, #ddd 60%); + background-image: -moz-linear-gradient(center bottom, #bbb 0%, #ddd 60%); + background-image: -o-linear-gradient(bottom, #bbb 0%, #ddd 60%); + background-image: -ms-linear-gradient(top, #bbbbbb 0%,#dddddd 60%); + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bbbbbb', endColorstr='#dddddd',GradientType=0 ); + background-image: linear-gradient(top, #bbbbbb 0%,#dddddd 60%); } +.qq-upload-button:focus {outline:1px dotted black;} \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/fileuploader.css b/assets/grocery_crud/css/jquery_plugins/file_upload/fileuploader.css old mode 100755 new mode 100644 index ec72be6..f795020 --- a/assets/grocery_crud/css/jquery_plugins/file_upload/fileuploader.css +++ b/assets/grocery_crud/css/jquery_plugins/file_upload/fileuploader.css @@ -1,122 +1,71 @@ -.qq-uploader { - position: relative; - width: 100%; -} +.qq-uploader { position:relative; width: 100%;} .qq-upload-button { - display: block; /* or inline-block */ - padding: 7px 15px; - text-align: center; - border: 1px solid #AAA; - color: #555555; - border-radius: 5px; - float: left; + display:block; /* or inline-block */ + padding: 7px 15px; + text-align:center; + border:1px solid #AAA; + color: #555555; + border-radius: 5px; + float:left; } - .qq-upload-button-hover { } - -.qq-upload-button-focus { - outline: 1px dotted black; -} +.qq-upload-button-focus {outline:1px dotted black;} .qq-upload-drop-area { - position: absolute; - top: 0; - left: 0; - width: 510px; - height: 35px; - z-index: 2; - background: #FF9797; - text-align: center; + position:absolute; top:0; left:0; width: 510px; height: 35px; z-index:2; + background:#FF9797; text-align:center; } - .qq-upload-drop-area span { - display: block; - position: absolute; - top: 50%; - width: 100%; - margin-top: -8px; - font-size: 16px; -} - -.qq-upload-drop-area-active { - background: #FF7171; -} - -.qq-upload-list { - margin: 10px 5px 0px 10px; - padding: 0; - list-style: none; - float: left; -} - -.qq-upload-list li { - margin: 0; - padding: 0; - line-height: 15px; - font-size: 12px; - float: left; + display:block; position:absolute; top: 50%; width:100%; margin-top:-8px; font-size:16px; } +.qq-upload-drop-area-active {background:#FF7171;} +.qq-upload-list {margin: 10px 5px 0px 10px; padding:0; list-style: none; float:left;} +.qq-upload-list li { margin:0; padding:0; line-height:15px; font-size:12px; float:left;} .qq-upload-file, .qq-upload-spinner, .qq-upload-size, .qq-upload-cancel, .qq-upload-failed-text { margin-right: 7px; } +.qq-upload-file {} +.qq-upload-spinner {display:inline-block; background: url("loading.gif"); width:15px; height:15px; vertical-align:text-bottom;} +.qq-upload-size,.qq-upload-cancel {font-size:11px;} -.qq-upload-file { -} - -.qq-upload-spinner { - display: inline-block; - background: url("loading.gif"); - width: 15px; - height: 15px; - vertical-align: text-bottom; -} - -.qq-upload-size, .qq-upload-cancel { - font-size: 11px; -} - -.qq-upload-failed-text { - display: none; -} - -.qq-upload-fail .qq-upload-failed-text { - display: inline; -} +.qq-upload-failed-text {display:none;} +.qq-upload-fail .qq-upload-failed-text {display:inline;} -a.qq-upload-cancel { - color: red !important; +a.qq-upload-cancel +{ + color: red !important; } /* Grocery CRUD extras */ -a.open-file { - color: #000; - font-weight: bold; - text-decoration: none; -} - -a.open-file:hover { - text-decoration: underline; -} - -a.delete-anchor { - color: red !important; -} - -.image-thumbnail img { - cursor: -moz-zoom-in; - cursor: -webkit-zoom-in; -} - -.form-field-box.even .image-thumbnail img { - border: 4px solid #fff; -} - -.form-field-box.odd .image-thumbnail img { - border: 4px solid #ddd; -} - -/* ------------------- */ +a.open-file +{ + color: #000; + font-weight: bold; + text-decoration: none; +} +a.open-file:hover +{ + text-decoration: underline; +} +a.delete-anchor +{ + color: red !important; +} +.image-thumbnail img +{ + cursor: -moz-zoom-in; + cursor: -webkit-zoom-in; +} +.form-field-box.even .image-thumbnail img +{ + border: 4px solid #fff; +} +.form-field-box.odd .image-thumbnail img +{ + border: 4px solid #ddd; +} +/* ------------------- */ \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/jquery.fileupload-ui.css b/assets/grocery_crud/css/jquery_plugins/file_upload/jquery.fileupload-ui.css old mode 100755 new mode 100644 index dd86976..edb196f --- a/assets/grocery_crud/css/jquery_plugins/file_upload/jquery.fileupload-ui.css +++ b/assets/grocery_crud/css/jquery_plugins/file_upload/jquery.fileupload-ui.css @@ -11,46 +11,46 @@ */ .fileinput-button input { - position: absolute; - top: 0; - right: 0; - margin: 0; - border: solid transparent; - border-width: 0 0 100px 200px; - opacity: 0; - filter: alpha(opacity=0); - -moz-transform: translate(-300px, 0) scale(4); - direction: ltr; - cursor: pointer; + position: absolute; + top: 0; + right: 0; + margin: 0; + border: solid transparent; + border-width: 0 0 100px 200px; + opacity: 0; + filter: alpha(opacity=0); + -moz-transform: translate(-300px, 0) scale(4); + direction: ltr; + cursor: pointer; } .fileinput-button { - position: relative; - overflow: hidden; - float: left; - margin-right: 4px; + position: relative; + overflow: hidden; + float: left; + margin-right: 4px; } .progressbar, .progressbar div { - width: 200px; - height: 20px; - -webkit-border-radius: 4px; - -moz-border-radius: 4px; - border-radius: 4px; - -webkit-box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); - -moz-box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); - box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); - background: #fff; + width: 200px; + height: 20px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + -webkit-box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); + -moz-box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); + box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.3); + background: #fff; } .progressbar div { - width: auto; - background: url(progressbar.gif); + width: auto; + background: url(progressbar.gif); } .fileupload-progressbar { - float: right; - width: 400px; - margin-top: 4px; + float: right; + width: 400px; + margin-top: 4px; } diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/loading.gif b/assets/grocery_crud/css/jquery_plugins/file_upload/loading.gif old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/file_upload/progressbar.gif b/assets/grocery_crud/css/jquery_plugins/file_upload/progressbar.gif old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/jquery_plugins/index.html b/assets/grocery_crud/css/jquery_plugins/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/css/jquery_plugins/index.html +++ b/assets/grocery_crud/css/jquery_plugins/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/css/jquery_plugins/jquery-ui-timepicker-addon.css b/assets/grocery_crud/css/jquery_plugins/jquery-ui-timepicker-addon.css old mode 100755 new mode 100644 index e1d5091..a9f0308 --- a/assets/grocery_crud/css/jquery_plugins/jquery-ui-timepicker-addon.css +++ b/assets/grocery_crud/css/jquery_plugins/jquery-ui-timepicker-addon.css @@ -1,39 +1,10 @@ -.ui-timepicker-div .ui-widget-header { - margin-bottom: 8px; -} - -.ui-timepicker-div dl { - text-align: left; -} - -.ui-timepicker-div dl dt { - height: 25px; - margin-bottom: -25px; -} - -.ui-timepicker-div dl dd { - margin: 0 10px 10px 65px; -} - -.ui-timepicker-div td { - font-size: 90%; -} - -.ui-tpicker-grid-label { - background: none; - border: none; - margin: 0; - padding: 0; -} - -.ui-timepicker-rtl { - direction: rtl; -} - -.ui-timepicker-rtl dl { - text-align: right; -} - -.ui-timepicker-rtl dl dd { - margin: 0 65px 10px 10px; -} +.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } +.ui-timepicker-div dl { text-align: left; } +.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; } +.ui-timepicker-div dl dd { margin: 0 10px 10px 86px; } +.ui-timepicker-div td { font-size: 90%; } +.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } + +.ui-timepicker-rtl{ direction: rtl; } +.ui-timepicker-rtl dl { text-align: right; } +.ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; } diff --git a/assets/grocery_crud/css/jquery_plugins/jquery.ui.datetime.css b/assets/grocery_crud/css/jquery_plugins/jquery.ui.datetime.css old mode 100755 new mode 100644 index c1fe610..c81be50 --- a/assets/grocery_crud/css/jquery_plugins/jquery.ui.datetime.css +++ b/assets/grocery_crud/css/jquery_plugins/jquery.ui.datetime.css @@ -1,126 +1,116 @@ @CHARSET "UTF-8"; -/*demo page css*/ - -.demoHeaders { - margin-top: 2em; -} - -#dialog_link { - padding: .4em 1em .4em 20px; - text-decoration: none; - position: relative; -} - -#dialog_link span.ui-icon { - margin: 0 5px 0 0; - position: absolute; - left: .2em; - top: 50%; - margin-top: -8px; -} - -ul#icons { - margin: 0; - padding: 0; -} - -ul#icons li { - margin: 2px; - position: relative; - padding: 4px 0; - cursor: pointer; - float: left; - list-style: none; -} - -ul#icons span.ui-icon { - float: left; - margin: 0 4px; -} - -.selHrs, .selMins { - width: 2.5em; -} - -.selHrs { - margin-left: 5px; -} - -.dayPeriod { - display: inline-block; - width: 20px; -} - -.slider { - height: 120px; - float: left; - margin: 10px -} - -#tpSelectedTime { - margin-bottom: 0; - border-bottom: 1px solid #aaa; - padding: 5px; - color: #000; - background: #fff; - text-transform: none; - -} - -#tpSelectedTime span { - fon-weight: bold; -} - -#datepicker { - -} - -#pickerplug { - overflow: hidden; - display: none; - position: absolute; - top: 200px; - left: 300px; - padding: 0; - margin: 0; - z-index: 500; -} - -#pickerplug li { - display: block; - float: left; -} - -#timepicker { - border: 1px solid #aaa; - background: #fff; -} - -#timepicker ul { - overflow: hidden; - padding: 5px; -} - -#timepicker ul li { - position: relative; - display: block; - float: left; - width: 50px; - -} - -#timepicker ul li h4 { - width: 100%; - background: transparent; - color: #000; - text-align: center; -} - -#timepicker ul li .slider { - position: relative; - left: 10px; - - /* background:#FBF9EE url(images/ui-bg_glass_55_fbf9ee_1x400.png) repeat-x scroll 50% 50%; - border:1px solid #FCEFA1;*/ -} + /*demo page css*/ + + + .demoHeaders { + margin-top: 2em; + } + + #dialog_link { + padding: .4em 1em .4em 20px; + text-decoration: none; + position: relative; + } + + #dialog_link span.ui-icon { + margin: 0 5px 0 0; + position: absolute; + left: .2em; + top: 50%; + margin-top: -8px; + } + + ul#icons { + margin: 0; + padding: 0; + } + + ul#icons li { + margin: 2px; + position: relative; + padding: 4px 0; + cursor: pointer; + float: left; + list-style: none; + } + + ul#icons span.ui-icon { + float: left; + margin: 0 4px; + } + + + .selHrs, .selMins { + width:2.5em; + } + .selHrs { + margin-left:5px; + } + .dayPeriod { + display:inline-block; + width:20px; + } + .slider { + height:120px; + float:left; + margin:10px + } + + #tpSelectedTime { + margin-bottom:0; + border-bottom:1px solid #aaa; + padding:5px; + color:#000; + background:#fff; + text-transform:none; + + } + #tpSelectedTime span { + fon-weight:bold; + } + #datepicker { + + } + #pickerplug { + overflow:hidden; + display:none; + position:absolute; + top:200px; + left:300px; + padding:0; + margin:0; + z-index:500; + } + #pickerplug li { + display:block; + float:left; + } + #timepicker { + border:1px solid #aaa; + background:#fff; + } + #timepicker ul { + overflow:hidden; + padding:5px; + } + #timepicker ul li { + position:relative; + display:block; + float:left; + width:50px; + + } + #timepicker ul li h4 { + width:100%; + background:transparent; + color:#000; + text-align:center; + } + #timepicker ul li .slider { + position:relative; + left:10px; + + /* background:#FBF9EE url(images/ui-bg_glass_55_fbf9ee_1x400.png) repeat-x scroll 50% 50%; + border:1px solid #FCEFA1;*/ + } \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/ui.multiselect.css b/assets/grocery_crud/css/jquery_plugins/ui.multiselect.css old mode 100755 new mode 100644 index d3b1334..f1e41ce --- a/assets/grocery_crud/css/jquery_plugins/ui.multiselect.css +++ b/assets/grocery_crud/css/jquery_plugins/ui.multiselect.css @@ -1,145 +1,32 @@ /* Multiselect ----------------------------------*/ -.ui-multiselect { - border: solid 1px; - font-size: 0.8em; -} - -.ui-multiselect ul { - -moz-user-select: none; -} - -.ui-multiselect li { - margin: 0; - padding: 0; - cursor: default; - line-height: 20px; - height: 20px; - font-size: 11px; - list-style: none; -} - -.ui-multiselect li a { - color: #999; - text-decoration: none; - padding: 0; - display: block; - float: left; - cursor: pointer; -} - -.ui-multiselect li.ui-draggable-dragging { - padding-left: 10px; -} - -.ui-multiselect div.selected { - position: relative; - padding: 0; - margin: 0; - border: 0; - float: left; -} - -.ui-multiselect ul.selected { - position: relative; - padding: 0; - overflow: auto; - overflow-x: hidden; - background: #fff; - margin: 0; - list-style: none; - border: 0; - position: relative; - width: 100%; -} - -.ui-multiselect ul.selected li { -} - -.ui-multiselect div.available { - position: relative; - padding: 0; - margin: 0; - border: 0; - float: left; - border-left: 1px solid; -} - -.ui-multiselect ul.available { - position: relative; - padding: 0; - overflow: auto; - overflow-x: hidden; - background: #fff; - margin: 0; - list-style: none; - border: 0; - width: 100%; -} - -.ui-multiselect ul.available li { - padding-left: 10px; -} - -.ui-multiselect .ui-state-default { - border: none; - margin-bottom: 1px; - position: relative; - padding-left: 20px; -} - -.ui-multiselect .ui-state-hover { - border: none; -} - -.ui-multiselect .ui-widget-header { - border: none; - font-size: 11px; - margin-bottom: 1px; -} - -.ui-multiselect .add-all { - float: right; - padding: 10px 7px 10px 0; - font-size: 11px; -} - -.ui-multiselect .remove-all { - float: right; - padding: 10px 7px 11px 0; - font-size: 11px; -} - -.ui-multiselect .search { - float: left; - padding: 0; -} - -.ui-multiselect .count { - float: left; - padding: 10px 7px; -} - -.ui-multiselect li span.ui-icon-arrowthick-2-n-s { - position: absolute; - left: 2px; -} - -.ui-multiselect li a.action { - position: absolute; - right: 2px; - top: 2px; -} - -.ui-multiselect input.search { - height: 20px !important; - padding: 2px !important; - opacity: 0.5 !important; - margin: 4px !important; - width: 150px !important; -} - -select.multiselect { - width: 704px; -} +.ui-multiselect { border: solid 1px; font-size: 0.8em; } +.ui-multiselect ul { -moz-user-select: none; } +.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; } +.ui-multiselect li a { color: #999; text-decoration: none; padding: 0; display: block; float: left; cursor: pointer;} +.ui-multiselect li.ui-draggable-dragging { padding-left: 10px; } + +.ui-multiselect div.selected { position: relative; padding: 0; margin: 0; border: 0; float:left; } +.ui-multiselect ul.selected { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; position: relative; width: 100%; } +.ui-multiselect ul.selected li { } + +.ui-multiselect div.available { position: relative; padding: 0; margin: 0; border: 0; float:left; border-left: 1px solid; } +.ui-multiselect ul.available { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; width: 100%; } +.ui-multiselect ul.available li { padding-left: 10px; } + +.ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; padding-left: 20px;} +.ui-multiselect .ui-state-hover { border: none; } +.ui-multiselect .ui-widget-header {border: none; font-size: 11px; margin-bottom: 1px;} + +.ui-multiselect .add-all { float: right; padding: 10px 7px 10px 0; font-size: 11px; } +.ui-multiselect .remove-all { float: right; padding: 10px 7px 11px 0; font-size: 11px; } +.ui-multiselect .search { float: left; padding:0;} +.ui-multiselect .count { float: left; padding: 10px 7px;} + +.ui-multiselect li span.ui-icon-arrowthick-2-n-s { position: absolute; left: 2px; } +.ui-multiselect li a.action { position: absolute; right: 2px; top: 2px; } + +.ui-multiselect input.search { height: 20px !important; padding: 2px !important; opacity: 0.5 !important; margin: 4px !important; width: 150px !important; } + +select.multiselect{ width:704px; } \ No newline at end of file diff --git a/assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input-focus.png b/assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input-focus.png deleted file mode 100755 index 0b059d48da54ea8912aa090ff066c305ad2bd737..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^j6lrB!3-o#&#{0g$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G`~f~8u0MYKc>n(WvuDrl-o5+(|Np=24<-Yp#5`RbLn>}1 nC8Q-JC8Q)IBqSybP0l+XkKgNrV7 diff --git a/assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input.png b/assets/grocery_crud/css/jquery_plugins/uniform/images/bg-input.png deleted file mode 100755 index 485d222ebb14b743b62680377907cf01944bb761..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^j6lrB!3-o#&#{0g$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G`~f~8u1}vnee>qc=g*&i{rdI)|No0DL0f=QVxBIJAr-fh n5)u+p5|R?q5)u;_ISd#WoEZ4!^X2t`Di}On{an^LB{Ts5W?d~; diff --git a/assets/grocery_crud/css/jquery_plugins/uniform/images/sprite.png b/assets/grocery_crud/css/jquery_plugins/uniform/images/sprite.png deleted file mode 100755 index 66b558fc6e40a749db29374e9bfef084c7c91e0e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 34229 zcmb5WWk8f`*EWpX?M6kwKss!s5$RMBDG7%fhLRG7p}S$LfYM6C04fY4G4#-(AT2e( z&>%5%NDj?=4tU?s_kPcx@B1Tg#d)2v*0JhXzE@Y3r@Y8`k&KLtQc>Y4gpBOWG8x%l z`{(}wSGsyee}Nwi&T>#^4ZBy)ZpM!0WRK14Ow4a6+8A4yL(GlMJRDlgCCSJFbQGUH z)^s0Qs=g3yB$q(+^Bb*Q=@{y|dFO3pWb>B`m5gT3EWFP}@$*qVHgixnQ}n+u`Asy< z2|4xYVTZ(bwy`IK3}6yX_cPp{2&7CZ*Mh;nd=cxddiQwxxFVDe31Ws@CP@Wq#}#GBW?Y zmoXA4u1(%G1Xd9Iq^C zlt(`N-aEe!;`xoAl$f=AELZg)Zf|Y*M%L5Q6BW~Tz%4XCTT&tn8Dih!vbhvN zdgp8>PwB|VFeVXRiN&0v0WTN~HrN07P>IQeboZaw)Z>HMLDLASSRo-H^Cng=YuBF- zn&MO5peVuZOE0Tuj;_&(8$~50XUe3|AOfIh~9?6e%&?`kVAoD%e(zb}O`j2K+%! zUt%*H>vOnh)G015?kXnZve3IUgvjfQ5e{r3jqK2h-G6>J-p@n9O+cQaa zW8NKNvm+YM&EuNFStvM2FS?NNR2ABeR#^9CX%$z^^K?q@FU7UoUo9;j9v;4V7d-Ka zYHo3Hac*J3^VL*in23?*JnDEt^#ePsw#mJPrT)e}@XX6pjZ9WEU81(%?8QoYR=$ZS zKGIctvQ-E0lT3+;^sm=7$EWqDGRcG6LT^fp%T*|LsA4drx@Q+Tm(B+Yi zj?U2_9p>#eUeB)G4P7%GO`LfGj}x&QyY!z~+lT|P^{(vb%hu^MD79tr_}~X*7FJ@- zziM;gV&(4#|z5UXIGcXXZ(Barw(9SVcJ$i0rFktNHEa;n|8F zJFex}SXzbi;5PkB1&$~=1NEhIPn42!U0hvf@UEGf;+bXWk&%&0Ehjtv)4**s#w#Gz zcW?d$N=3deU;3*Nd>_V28h%wWLgvVQd(r4ve7tWl-ZZ@Bo=Re`ol6uhqqY)AuDZOb z!*%f7OETSRPZ!s5A0ojo%B1FSd$=fB!fo4#FGi`HPK;wo9UeFT7iqvT4+TZPTXEV1k4+~d9jLwRy-`BKL@jml<=Br)VMBr%j1F_`p30bF+N)8)=deT(+`MZKG z9z5}3-oL}db}FP_^Jm+W;;7&6KTj4Hs$8j9?45leNd=z0bosV?_|M#mg)HxP$eGd$ zu)@t?uG|5e`&B!CUphI*0eNPZ-WP-AvnffVUaQsRUurgS%0+Le#G5y{qe)W7{|)Ja z*BvZ0Z!3I%jr|oG>8RA370zk%jx;_!R6((aUyMhClVd3*g>?^0c_OL#)HefE>^qxT*Hp>K;Pt$d3dBUNM4aB}1x16G{l!1!<>jSiXD=oI7#j1Q zN5vflN%Sq}EGs!AvDCCnY5nB4RsI_G>bP&-X`V@f&Wt#GXJL$tEq39Y^JbhldBq9L}rN76Lfq z(Ngx3IN4hDAa32lJ6_=AZBu}{jBBg8#CUpnol1cCv`Fo)$~HhN1J`ajy3y66<$6a; zFybSYCtR_rDUu1>Ln#_kTAV$vr%5xRhguG|J0^_ZOxkqP)6>Hb47fk3#g*7rk+9ak zy6Jx*bs;3P7j|G22$lwbkT5HA?6Eyy8ey)YqB2;}#G1t7^z%W+?8{RLJHPzFr&G#q zwPbK~G?@pQf1~nfZ?WjJY|xXF`&)l;%m+}=y^?TSS&}JrT^>3Z>C-WyJi+;1imm_AB@x*x_lFSli$88%K{5&d`()^w{Q7Cua`(F#`B`0Z8uW`{i@&43zPdt z7A{??52S1(3Gz}PlWlX*j|+RW`#_YNx%cQ#wVqaFI7o!M*p%|!@C11Rvysq5f-O} z@;*O0KkwTqbZY1J$ru^^7BQs*ix>=MaBpj|<)UASXVzG5Y@v*y0d;@v~hPw^5h={^tAaT*E8|gzart zg$rQ(uV;Zw^e>N;JFP9|)%p&*^cxUAN%R?L4NPOSIm+2guhw&)tL4!Qoh1{!e4n8c zzIDOny#HZ@QeWZ9makjI?c;l)H9cbmag51QFMg3d@FKq_?k>d1QcJxxJn=!OGh9%G6=<}@ zT4NX!oxb;4Lxg*rC1)kN_*FaOsp+Ny7N%8Z|4U4lu=POxZ#0m89a>)fGL#kEj_+{A zt@h0y?SKsxqfmDdwzeJGd4|at{qpr0-J(~AHlKTxfphccsdtTyjn+HACk6rjKM%># zKUD}-Vhl?p35C?zyH=8lf4JM(**(jSwFOueE}^1Ssd?`qGq_83mV(2)@GC`d^&v~~OUHe^N}Ogpjutx#JF1%%jf0dbpVN^(_`5?^X>Wi0_=s1jA}#H9 z%XoffQBDaK;Wb@Uw? zY-J}J*k7s-fk(bcPkv1cZ|#sGjx3FNt+rp^Ld6*-vN(4=&an7ni)M0)I$HnZ;7Aan zHNI%OXu@TkNpF99qLdie0#AS_8WT4+yG*!-jZY9^|1xCYZ*3! zmR5FiYt2+{<;q^7gi6%dbvNgj|A$wzylhYkHoGCO_Gr(hA6WA@E1GUv#yuv4>#&D5 zp;w<}dMaqf*PbEsO1-)vq9gKx{S3XNW>&0A9x;jb?&{}|&6fV~xBt|w3xGv&+V(1w zZOfi0iA&kjBpZ^e_vz?gI!5r5U*U#)@o|i0F7YvG?%yQpXx(xgnxYV^jQ z{1!dMck-Q7Z=1nFf}-2P3v`tm?H}LoQSu|@B-MESn-a^#J%wviO=?bPRbpNoMj`}^ zNA~hpyny*d-C?x!?{8=GD*cT7PjQr^*kpdXC8`LLDTo=zWt=;4T=?@hH#ehO2?G10 z|MAaF_y6nO&Nj&$t#zw%*c~^^OBW_qqEV;-U&{H?nwuok{_>^A!CDiw&oZ{ZQHD6; zBwxGU%2ki){C=XF|3t=c=}>vBx3G`P`T^HUSaNSJt%(h&i5eA)xTaR~srZm}4-O9g z{#{SaHaY>z<^-L;UQ0|&EF3JdAbzkYqn@A4&E?(N6?jT= z&MwjWsEQqz;Dg!*2o&J&6Q3QwQ_ptvyL!0PZoFZ4sY{mHz-=OcuI3Zxe*%yCcUNu~ zM))k5QW8hqjI?v2o+!tq_-qeS()wIFjV>;$&Tflm?*;UzN-Q59AC4azd~ssiZI-V9 zK}u|5wD9T2nStpZ9^W4$))aegEttwjuo@%?!f{vKa);NsXHFuGGa1?0h%MkP3?(Kd zm6p|tG_7#NDCxSn<+kmQww}5wOJ^Aw8GV8Lsk)wx#N+YShkILs=`|V04DU$hm)_md zH>vX3xKmGo_pT!>k^qO2RPRyp<6zIZuFtz91F_UDGVZ;Hbn5W<9N)?t!6HEmA$d#- z{>#Iq7K?aHn>Gd(gE6SwPOwPz*|u15uHDcrudZhK^Hfbu&9Z@k0YcbzWM>m-@Sc}A zfy-v^SQ%nz16QkHq zkTz;$@JUP_u}7xqp`Heo0B`W zx^MpevrFG?l1@?aG@y8C$7%EP1Z4jA6TJ-aJ){r*Q;usyp17|H{->kARYDb_pp;=V z*!r`lGRcNItjkbIT0bm;zmt^wv#9U7gCaa2>_S*swMJY%HD;=!z%QkBadsZ5a-PS9 zy6!VRFnJ0btN}ZCy%)*Ed}Z6CP_)O%a{X!Wd)Np1$ArKZ%ykDrai8 z`jw~6mkitPL-q8AW7^x>(Sm}4q5qyvPYq5NoRpEzlwGU5Yku-s5O2u~g2DeAZ@Hhu z+%8YNyef}Z6IS9E!-?gllBY=H$2=YG0Z=l@tNCWobatAMh)DhEz>$8eQl6V5_0%$w ziwg^1v~Yzi60WBkx%Je@XdL}4l-_}oV~HeY)z#IzyOSFHf0k|E>aj9VVCrP9(iV%m znlV;7e4_G?SU8ra;8b29EY~g9ACrTN2nzlQ^?p3&;o;F$Q&Y>$|Kr65(g^7e77MX+ zSoyg#hh&r1SCt@r*oj$&r;Ala$%CqX0+ z(f{$6pEpUe`>E#JZ;~4VU^w89u{1%2odn#URKIF+>Vaf}hdI?1l4QH26&npyxFA-f z457o7%$Ki#YwB#yuC8O7dy9Fqeso-EyX2=|W(TS#7Bc3&0U{|LJ=)~{z}qCSSC`r3 zF|68Yi%~*V0S~pUDS|CEj8TX)ZCU*N$4au(uRQYd@)CBMc@DdX`M(cXG{o!De;4+Z z)0UCRF6SuYSost>Z=7*DwZQiVnD4N$<}J)UJKcHdn|Gz|nBrgjk&Uys7TFNLm9nYu zh!QNeog=P|T|)W5{?D`bwRo1Sx0ePnBwUaQXL$I^b*F{yZrgU@ z&p9zNF`-$#e}88vm16(1Wzk9~JP5LfmP15H=@c^c<8P-z7aD(!@#Gn@6J7VO#uPt5 zlaTPz)zg5&<)2a;;Xga`#{-{MVmjT98)yF549=L=SQ8<^#C|I3)3s7<3LVbP&+Ase zdosL_tr>4o|GA+Wy$!r_JKY*@4}5QLG~3P74X!~4`Rap&jSRHhk$_Q-<88Mr&AW2@ zSyzYAVXSb~NeakEEl#4jctx++vb&$RV(!a29;3&{D&y-dY}Nbq;D*u&`3RUdFiT3P ztB1E_J?|eXUp#1JvXgWIK|~xCgTSftEN&xf-6bU@Vg$$CX-KB? zA7_FsI*Zm-*lT+UUj))RZ1O+~_akMgT6E-r_Z)bNsTbO{8j{5Vd=9V3Ge6h|M!B=1 zqCx-`;tc|hQ{7FDT%4+0t=a#}!q`ahqSyZRvaX%o>hLS~zDnkkZ66>`hg*O!$Eh)# zC5a0GD~XQf-;yE!y$0iX6+ULU6X0mVfZ|9Qu=<9>DLA4t?W4ro+Z& zR$JJnT`_owjkPKGBz8^aun~U}pz=pd-g(nkiKnvsbvpS3+&zjU-_v(psC0)Wy4-WS zZjzMnW#oOQci<=4S3dsJyv9|9KOcDmg`1v4a9^*H#ARj0)-d5D6Z);Dzkf3g1S#|2 zK%G|C>W0P${>YOpS07sJ&#NVD^&54n(fk(y@>l0Sv&8{%p$3-LWf3GizHAKrM~P$p$ev46T`CR64FmoBzLLWEw;; z-Mc=gXJBxD`H4em*&A01_;261Q^T_d8Pe5yETVILn^({0@gM6Z`h}!bZ~o>sB_+Ij zFM#~;QLTKXX`)19dD`_;Es+TfAy=Zeil@RQY)dKroPJk- zzuV+@ayIV;5dO}sj^@^%3gk5<6mFkgEroeB_S)&oMoM0xMa2(oy;M(i&zByD!+iwF zvuAuJ?j)l}f9L;)vY-6}85aLr*-t;m4)Q3f^2%Fwr#7F3YdKscNtm#2(R10u{f~8d zT~wF~`;Us}pEzgY1d_*8la@9$k5Z0%RXp5Jaty&{`zoKJ$)iJc-75FBPR%QmqtH_mV_Qk!d@mNhD_1^6;fS-L6Q>-rG;Um~F^2d-%-IcToJYxCpRvFIK}X z)A?bL;XSL0xw#z9$Z8htYEJ8B;3HGrK>1`y%v4O(uZSwR+ZIXqPK58SxbwTdDGHS~ zq(oHQWc7fm&W|ubJ<4&wYDh>A;qk&~eO|w2T_a4LeO+uyN=g&(6i*XY>3iPBYXoDG zcz04u@4URYcpH`uat>_6#qgfG5CDq4d^v`EVNTg_$?uVkv)Sv3o%+Y#LOE%a#yoj} z8+rc*B%{}YWDX{f09$_oNDx(}_?nkz*8;Ndv?+c^yA&qt6~{;Wc?=*Kz)Xj)ykvZ6 zOiF=}f=;`JX@V%8W!0_eMc;wBoEqGD-3Nz4FgSH8_T}HBpT^b&Y(-Nn>S}tBeS4WP zO)249m6}1wcNm%=WPvsiym(C`;jkW(DF&1)}jocv!n#C({5&CTLXKV z9jn{Q$gU|Je)3aVkT!6LcDQZ&-3>_D6$y!h-}U=4lQW;RVE3NKM;`mGl+QMcSBY4j z&r1uj)&z zdwF9@9c(&C4vrKsSIVVFiC*vWNmod9pSuB zzf~F6FAjffd{UrO4-2)TCZo^U6v@h6JJzuHoWS_Kj`3DozwUE3SM9DYgP%kQoKff( zh!8t@IF~=|&-oIGf_yopqr+_kYW&r_nVA`C@oX#0nab9WS?l6s6kHK{rlwOZq-|<;3tIn@Z}mPds=xPLRrvFEd8MF``YXB51<$QBqET!A zlCz3VjvpRW){LRxu#8`37b0HJGZWq#Gaxh6(JCK(n>hS_<*4-EwM#pD} zJY0{f{Yf&}1|Ec%L*j$=EHOiUM#Ouatg7gBxsCCoH zNL~LIaIG_o_j!=jXE-FRoaal0{S;%bjG}c7x9IZ#P|WShh0vPI23~53VbINXP8H;P zzWRAF0Jq`s`#bqYzBIACb8GcL06K*&U4L!a zf4DL?N59OyBoau?Hm0FZ4n7bN2sO2n;?~AAC|9a~`gjXNbT_d7er}i81eD2cV*{Py zY2{cIe1$CWcE$t(68g7pqw|=|KVDVa&!lOI$)L=|7eW8Pgo(pe+^_Bed(Lx8l3{U2 zu?WxMjBP$G@)(+l;U23R#2NW|NSi%R6=nftqQm~++YMROpa{E>ub_yVyk{I_lHZ81 zn=!rOSD4i)Iu%Mc$IM|zmuHg+|C`MJyMJDcr-AHX{Lr`VLr{oXx}-X5tQ#12*r7P`8zs4ebshvsd#q0{fn<<9tG2aa zGINEAak+?oW&L-%sXhvX=bj1GLiDM6f@yi;6Zf-&Of)DOc%3YlE8+ zE@6c1`k41Cj|@GaG;XOHYEmwQ7WUMGXY_m(5wQX;#u%y-6@|kq1Gh7PljG|jTU?wo z`<#*!GrPpNom7WVZ5ahcJHF~vMu)<6!LN@G4_EzCWoAp;)5%A?Y#mlT{H&^gwRg{^ zQ_a;FDc94ls!3+#qkBb9%VXo&103BWat?Y%S6*%+wCp=GKC@ zc?-+Eg=d_TyUz_Xk~+^77ZwRyMgCQBu-<03R>wKn zZx52h$s&%^3QAL{q7CsMccS34++=$*rAN=|Rg@2~X_{D0xij&wqE}-ROCpIA=mF6oWU zxc3AQi@A){)S*X#H}B+u>MU``xIVDDGv@tmY(BC|yUbbI<@-50$yK*IS?f=^fJ^SJ zG>q73*}J##eD7Ws#OAwBo6xriyNb(X;uDIkYz91Fgh#L_~6{&b*3|41N)XZ1bLZxaw=}% z=B=_a@}@aFRK#ZB+~P0$>=`8!;zGLzdANDTiNyyF1olgDmDC`r;g7#h{aRF8lB-1I zi=j6@If^w^e5It6MrlZyXC#OU_02U(w zw*_Ks8K+JuqBS3mko#e4xaIzlLEV+sV0uuh@pq%Obw6Nq`^h3;)~va=88}d4!^HEx z{O6(AILo*|px@1ap5ETgiMloq;0;gHZ$1@54!@mPyE!;4TRrFlGTVgT6ZNx~n1q+4 ze7#53K8EzXR`Z^`wvpZ0H7hAmZVxK`xoXTHCsSllAwAt>0WxxGBm?_BfX=W?;e3-0 zo(=6RBq;bCJ&I|rOq}fL?>Z^=NLTzK z$#>%|W;$Z>lac#X#L6i%HyYc;#gT#mmg(=+J))AfR2HQZ441sll2Kho9onGj^E^7e z#)^h3aK+gq2$~xbW_GP?O%BK1j8%4=`z8X$YaSU}0e~voUJoutw9%_yIR_ zTdzU7xcJ^0NK8h3IfzBLAKF{4Buaa5iplM7-3}Ku$-OJho3pF>;Lu=uTYqJHfk#gC z*b&5=hNkZ$ly&G;8*~O#ANx*3YpAx=>SowQxjmrBo=x#u5ra7AOx_DvUO8;69NWtE z-d7yzO&ciuh#blM!6dQ*Q}#xF;i4hhuHOt;j^3(;P8K;# zH9m2eohU2b8FEPUI?B1GDtc3=aH7>LT8Fo`$RfofQ2cCpoq6=OARVztReb)A)9KRB z96KdM8N5m2vWA5B4g_Uuc8iItO0N9?C1Ks=LW0tPc0F1@{pwYp)!r-!g14@Gt&wSbO8jy^bZRQ6 zogew68&csIpwbz6jCK*Rr)c&CJcdxO;b=#REe~9p;&zZhcHA=PSm?aY)c)pL2rW-5tKY$zBvr8&o>XE#uw#T} zP?5Eu89R8_8KgX&Yv%uPp}jB7SM~detsZ<8Q9uM`$h zq?*?}=KA+iT&J!@vQSX8sgn26wAztb2cV#|GyS#uoGY*Zb?^m|Za+T;D0<0(-~3pc zEf`U4)UyqAM$F})d{uAYtppf;OH8@9OF1qzjcyx#?Eu363|`r|(FxB~hL8lK35;y$JLsU>=V?@} zypfYbJj{hh2Ro8GzupW2#2I31^gHbL`yiCmo+!jsi{?x{X86!4CusM4_13vvfJWiW z(|dV6$AV9#%v+-+4btyOh>P=XMZ4ZiO~_nxSWjTcXyaI<0DCHaCDk#`_WZQdRSxwE zG(9Ztlb3?!V(_x4h8gbo&Jkhm1R z{5zWU;HF0uk_lt(t-*@ zFPG zc+}PaF#iM=^1>y+QYb}Xi@;QF)jo5`4Sd)VpurvgM9-u`IZQsIkv&>1#W*ZX9^Du; zcK9!~_YF42JYROzdGWX6lIaK715R=ImE<6^?^!m+qP&z-6afamXm)pQARk1_pPX7F z@R+A)Ek=uRkzZd8Le3i5__ufsj2C3Z)j7=SQQTFa#ne*X6FS(mE|9us;MVCJAQ8}a zmCb_3O~);+)dSR%_pIJW?2l8UCnuk^!EK!;BJNLWEPWx!YTwsgs`0LKCOpYo=~0RG zvkp-YKFguV$Z|e#ovY8en>KBDv@#I=1FS%+110rN%@0}idt2!{cin~S!V}^*5B0FH zQs_Al0JY*=!+!Yzf*EhAq>%FamCr2smJ*%(kA@0AGRMuaTK%FhpJQvN65zls5Zir4 z%L6lb?rBU-F>Z`|2B(*vXBU!wEE;1~;VZj(qv6@=0q{c;uaAdbGi&b=sc&GeypbAb z=^M|jeR1&(+rcl};8|I=J$2tO?w5>1uC1{pGRqgIH#DuhP1YTZYmtm>#1#}!6}$V= zF?C)e)fQ4d;abkG)8B}nnLb=T8jC!~H4-qv?6cX8c)~ym0<&M+3zrw0q*{}G`_~lS zvmFVju%B3xHACLhd@9g zWwTRmHi2Nj2l$Z!QE{oe(jV*fRP7@t}Q+amY+0M@l+B zoJ)Z{I))wrj9QR84|=ejy1pBV zgShH+DBQ9SSSVeEzP|c8`@O8zPpg35x$g(kMBeDT(kng`g$AX#CF&-QrE~Zl(S~b* zJ#2gyHl1j%`^*qVIp*e@p+~&jGV5iog~+Yc??~*!%BekBOkfPR@t1x zqiK19Csz(}Mn?prnk!Ke%Kc9e-uino^ECQ8_u1&0czE0WEJ){J+8h7lJd6J5JLGGV&6H#?O=qSU9 zhRre2iFkCdkexU7I_na^-1Eeqj0RyUaX>pi(gEf4zUdK7sI{57nB3DQl}?%C0~tfV z!!5hNvyFEr1P^+^2@e3LWrC|isV114aEsZ>8nBO_haJBLS!?PIz$vQeztx(GjIbQ3 zUMucVMO2fBmok9KocpdJD6o4Kl+5xfr^2!XJh_HlEch>?y~jLe!(5uiK}@%@4)sR< zRdomgg$9w?&eY?eER&7;`PJ#4Ng}JiiB+>wM!63R&V|YBbw}hnbdKHU>6x!P*e7}N z#}dOn7DY$S27p61rSI$WxzYLhgy1MCsx5aPxzS*;JcKnm+yu5AV}+i;@E>!Guht$P zQCEc5GYDcHYg}!RlpxTBxoTqOQYEqzq`MbFFz=pClpRR+NqOCC2nbvWv0H{KY9-cv z4cy3&>YQTOZUO4{PN`CTB>fW7QQQibu4q9CikLJIfsR|g8K97I2K~rS2V3|(uKmF^&Z#yKHJ=*YeJ%krgM%)l^0oeY=-M6w1SwC=Rfx|J7YE10O75*vZwf8#9ab@_; zjbMXJ#_Y8%rqwYkX0EgJs1D>>@H#KL7}o% zXUL_Im8-OxS=C^|CEs)5CaI#g8i`AJVA{xfu4`=UsKaueF-YW4sNo8UJ-dGm^<~X( zXCmlu!=l18SHhA@9=7j6N6b{IWBV? z!3?2Oy4lP;otEa0A!e}T=UNvzSTdqr>tG!k61ou297=B`)_xdmj)%ENDlJ{eQGRbg zbokGdk_L`tHLKa%RoYaxJG0$s@|`F<(+hr-RpTwoQvLKI}D1)fvXmmlDQ{npsCAYQFQp?z^PAh&+|;Op(7x_oaoSd4LP~FKxws+XaB?BE_nyO+p!Pq-L{!x< zCp*Wn#-v3|5?)n_&<9(^3c_vP$jMu-VVm0>Rg_Ba`lZ{uy%<{gfrjbnOAW*9-p_wHN- zlRtDSyW#uLaEWjU_P%3CLyk*y@dn3)E~8d9>Z_J#<_p#N9jH7@StB2+paja3_#8uM zw0fb}Rw~2`VZc@yeJqG}!{_s`TvleuK^dY#JuR2tH|!|dyg}Hg@wB!Nohd50%@M4P zh!7I9)UH7}y%d_{eg<7KIQqS_R_uJ&rrQ#$F4T}D@H9ny+Jqr1-!?De)Tzu+xnFrgTAo@(p%)&giT45&a6=NaXCODzHI#W8`f z54gbsPM<}=5L77oKDW)&Z{o?8nTXgI|78DFkp2R4gr!%31&t5gEWIS(FEC=8JXCxs z75yCZ)^UZ%3P{m;OY^fvK#9rRXD$6noJ+Ekl0I40HKqMzSUE`igLWQWxT)@Q@C)Et zkeJM5r#1Kg;o6)-ntpY!8Es`J zj#k0(!vb0}D81w^b_KEi4oeO3=o;(n6T+k@8Y`Hqe#G2W!)(cAl|ImgyS$IejOK$$ z+b>6;R0^gO?v57Z1I>D><n9;^yuHv}gvvv=TznnO&TwizU?eRsyO;Z2--Wi zX(grCE#&csk7G1q=n@8enbO7Yj&=(=XET>S6U0Kkzd*1eT*hzJMu*34QAB>lxr!jA zK@JWs&+PD2aDBoGPDx35I6JrcTl$!p+|AC~yyQ2_(f;8M4N-CJcWQs#+G_vg()hJj zcG^I;@OvVv_z4MAZMk>xvn1{z#U203{ge4jpIgpt123Su&L$?O0AcaBQ!kmu=B+!#dzJ1(Mn39vHw{6 zeZ$=@nSO&8>urs}-u~2gE>jZ+QPY>_#Y!=cjdnAK2GlJR2k6C&*uQY)*k zC%U5)TmMn~bp`vfzg#ZXc^fiR3kzjM%;G#%79<;6gY$};Km!B8X#n;E%NmZl1q=F6 ze2jRJ1u-vptJP+oVE*G9?nOb08p~M!#Ws<(yy9ryUZ75Syf$8b}z6Z+);1)!(wT~V?a;Zwff z<1fXhl;}%WPgrk&*7~Q#>6A@HcETC7C*xcOj4aS>^M<5l;#naBq zN14zInCfb&Br&IZJ~^ZI!#1TX5`g$f1Rc9!2y1I*!x7nW#~?0rz-+o#u-*6i-v<^4 zs|}{a>$COwCKIT}Fbb}>dQ#!aXdz$Yy?VFCl?W-OR)Ou>XkH#)2qU@N=ZI;HW=6Vq z*}yt)I9$27$?EA zjxAAspliSWamW<21Z@q{qE^_G%|4Fx?(5JSc2{+UF$}4|uW2=~oOEe^r8^<2lDXs- z-=1w2!?du3^?|mH?YM2qAOCI%E8HhP7O6}-XL7PNmF(ih>XV@Ha#kKto_>jerZ;xb z_Ej$y^nTJWB#J@gyIpd6TpfPW+`*FKxF5;=rA`y+A!tF_uE=po*|GT7`- zxvgc1uQR#8cXxw3%oGQW|6G5IP}C=(gV@0~KFfw8A*vs;XDF>~=ph6HWwC--Wey(5 ztXfDaHdnVsJwKLhIh!0~8VjQYyk)Ngm(z|!o%5uQP?n;F=lIw_fg}Sq8 z<-&z};&`V4S6$CoyOajSk(bFTmH8_Vv@11ThHL6QE|n6xQ-~WFa55f|#dlL&Ea9hvHvbeF(Y3r(AC~Z>_r_8}bGPQ4SOD zPne?l+RITGErU6Gbze_OjT5qy=$$SIYc0Jefw9hTp3WiE;Xe0A7i-5N=BIVdUoBrs zcXh=qr=!lM41Mlj@KmaCa{Rd7J5&Rc2&AoV{HUrdHnBc9WT?2#5$&4$8T59}M%HcX zJnHc*z$>K*?Ql$>1by*_aVU%Ep=Jbw#hX+&>@kI)>BBO6=o0C+eE1N^LJx(V-`YLAf5mArq_Wk6j*&+C&#W&b-Z}{pP6# zHwPg(Di1q#+vTT*cs$nmlg3nbn7D3R7?v_zO5;+51?cY7fU_n=m*BHYplq=dWEc@U z>;dHA&#XudjOLwJ|zH)3libav3RVCTBKy|rS;M}K}ZIq=YP?Q`pET_=_taxwnGt>@bR<3B#9@1t`a(|~iZ4`+n->Nv zb9PwoS-%}S1N9V5uy>eT?@UZZ>I)?}?PfO!1x5$yi$%4n?dU(Jg+TQg@U5d`U-|Ss zJ}wm9kqD72bIgu0;$TbnE{*nDmdacs4AH1iLGSk*Dw?Aht^|SJq_y~G z{s=lG8kE3)sa>pf0f`br=pxHZ9QvpE#5@%pKXf#u#EqfED&VRw3f4icc%}=|R(U7r zTRf5{`~yVVX{+y+JnuNqTHnz5%%7Ho_Q^SrNfE-(ioxoX-{(1xL0GYlFKx2PC185C zG0D^JmJZR+;Y~t8W_*`m1nV#f;`HWxkI@(g2No}<|Yg0v_PcF=t z)QC84?k?%AD=RDOccWqa2s>HjCw0&NH>=FY38w-#N57!8OR3bWe3PFWD$8Ddkad?~ z2dpCBvWdgb&$-v%H+-jNr)8U$8mTlXr0@$`of^}4d)CJ*|)>mXRWThV49M0#_`R>KO+x^-r)=!gNL-A|w>G z=}6pP4UTc(MIOE|R(83C&qdE&#Dpum_#>jQ>vTOba!}CW!mK;?r*X1}Pjl6VpMyaK zu6r@OmtP@Fc7PsED~f)eLz#;oCI~d*+IYrpYH_NxSW>>F2{h{BrhJR~%fZ}#Q4q>~ zcIEJa`DKj`Sdc)h?=dra2`fMw8xkK{W-rwC#MAI&$Y#!~2N}=}q(EV~VSrnLTCzIjjNVPFE z>YmCMr=C5Y<&~9{BXTAtrVS?0Oym}#>7Kij>f7UVv^B{bz+!ki*o~I>wllyufEYMI zcVT*xUYhAm$3AiY*lAX1aK~}0hgsR;d4_Qn1gF`Yv9sJJ-#X5(mM*!~b6GjWFZCW8 zDk?W*O1Kk!O~)21spc^j_rl%p`722IOsrc-Tm1zfvaB9+f=!RmgXY&+;UmY zw*}sr`kkU~t3OCdpg|;A!8c6I1)|NleF}Dd3^l3G6bRqRnT2?6i-0$|@{GM82iw=t z_`m=U##UrDy1;W{)+2{`w-fX%b>|f<{dTvu4F7A(>)w&_-0>~@S|W6$o^pSeXfK=V zOWoiXB>0nIG2r@|TEfG=z($k$NSr#k$oQ2;zI#*9)yV1ZVcI*!Z+9({$KGuT*Ng7% z(nT3vk+&%mxhKIZQ&$#f{y<2^q`tYpUUaZ2hjqESfcUnMvQ3_wtM^M%uLl2I3p~$)lrV_P+bq23gIotiB z1`I*N`t1W|-NNDxTxFSOR@g_SRjToR9PY^&L3S_CslEyq>2Ds+&wTY4r-;Z~GnQw4 zfmh2vKZ4iX7T&Z=kbO@%8c^>_D=(pf$00wNhj&hXyVh1Y&=oGs+(bZ4lYb`2$9E$C ziVaLDHg?ZEa8ODNsm#bp7gJE_(3V$e(+t>@&P=IPm6(aGTC+Am5UWOLDQa)NPp|j;H$J!T_jddJ{xg$2uXA1Joa?&Ixj(vN3_NhM zV~008BvK8GbCA-7=}lDUuD??o+|n7{?g9t8&Fy4AX6fj{O}&PFA0MCLH$TkEB3&9 z<}ceFS_P^2I7Wh%Exoib#1~v*b&l<@hoGm^z`P3ZcZOy?= zR%NYxAnZ=9jAld!xCfS(lb(s^$1rx#4}Bo|MSqVd)=<5UKNhwSi?2G(G=X4RE4GYf zRnZX)v9!OenNnNflNaI=qhNPf=@M#QW*}?bCg@!Fe0L=(s7O{zgAy^P@Pk%iO?-C@a zqQW;~7}opeMfad{K6#Xju8lEcy?2KM>>9L}R!u|1?33in7!ow-Wu$Ww$)-d*x?1P4Xf(UiSdkRnQ$&>kC8=>^~;7^2# zO3EAH+Y-8tXrI?*emUHROPI36E3!o%9TgK4!Mn>sw-)a&9pzS{ZX?x`j*82(DCG~6 zZDQRzMH*+sAexIK_H?T15up@J4LLh#}e-65Gy?WGZMm}kgixaNPz))jVeRKMFI^t3c=JeYKjuh~OT~>{+M$~}} zT-}iBP-QXLsP4E^1S^I7+aPWVAC=m=bn2YRn99(h?ZNTk{)>2AWvlW^Mi^nJUD2XR zvDUn)Sr=7l_dIFf%=&*DZGY=Fow!UscfWt^VnH z6*y$5UYS{0c_|?2;>!9l<9d{-g+k|$iR|UcYeGX`4^&{gtC4MqVQPP1%Kiuyl%Vev zzfj48Yx!jXehtM3t{m9b#Bi%ku})>3bOdYzs4x>WR(@R7vH&UQ+@p2CEZa!Fwe#D1~z4T^tZq%-PmtJ|{z$EJ3T;mFnvGvT5ayDh)()Yr`@jSB56 zzAm1&<07EKuJ=Odwl|sRn&o>OaL-^c@R>59+&z>CI-NhdR5AGMJqXs{i5;bTjafW3y=xCO}s^ERJp zYK}?Ohxq*BTDwvOz2FwfaVE<6@O_LWmaZmH$20{J36B2^ zc0t1WLiYXC)^dqgY;gtMHk<9lCfz+hEx3n4%G>^6RYHD3^Q?8+V%+6h+ass96^4dk z*w}Ewy=HA+=Zq$pG4yf|zR-ua>nWu1c&xZ!tNE;Pd5+Jgc+(DYGuB5)vYg`Wfx^R5 zvZDrJ1eNB&-vhP9ok=Ji18QmMe$DBMIPF5S8R|t1e)ZiSq>(ZHFz8{FBFiS{{M-xN z`Oy81r~3|1Fb`+usN*H7VFCtm}A`vK}y`U}c4IOin0se;v`g z{jlA(TOW%$Xz(^c9(8~DTU8~rh*zT?0DU~XBSE{(gZjrE3~iIIQbw^@uW*0K>vZ~S zISC6UCQ_2R{&@)0`gi#5hqebsk$k#N$aISb;V;mF+f|9Qj^s0zN-6taRFn4;+%6bz z$!0(MlAZcyeod4jf~hWIFO*>JR(8RNlvJ?Lq9t0_FQ z?Qn+xIjNAFDf9Flez(jE#@-<#>XhTI85dTrv9i6PpC7K29UJx&Oi&wBurvv5EVk-U z(8O#b_P=RcH!rB07`<4zSOihxo;rk%G6#3;iaQ@&BKwKYTUf4UT%2#TT53E}s^CD0 zKi+k1IX^#ib@7+WdUuH&tB{)5VIxVtWJ}}=v9YE6;y>8c)OCYI0mpt%ovL^BhrSKx z6{IXJ7F*Wfm8n-My_(6_QGQ^yYzzlIYWOQ6N8!C$RD6g@<=EZ7MzG-3_jUdC#*4K` z?;HAmnL}8XlT6sd_GNLRG%@^-7d=gDv2+$O-nWeN3L%kSpfH9}rmnn?LZ41&owLDUwkTqQeXG7{YoIv94pM|eF8 zyYjut@>z#eIr+Y4L3qwUgo*6WcA~Ypl#yeD2e%PtPU$t@z+aU}7l~N%_cnPfvyP1= zysEURO~>^||J?9)LY9jKL+Wzh#^Xv(g#_c&>$LQF>Pgj{!;(=QV z9KrB;9)GG<&LFcsOUcLfsM)}Vw(q6)4GNY@MVth|vJR_7!;?3qjW1Ms1n;Myq@nTy zP!9Sb<)3~+4W$$+HJM;hpMGRML)%}b!=dQ#@9Mn6)KX_J+L-<1v5D3Q?WD@&6zts0 zm31i4SLh&w%9ihH3hSf}WtV3NRp6bp&cn^^eSf%W-YefOBie=A5bV9ts|)eWAye$n zDi5$m55fff+VaH9xnyiDH8OZzEF|sH^5RN4Q2J1cRKmxXNN*keD_HASR=&lpa!{zR zWkl=i(%b6xUm-Q#EA8tI6#Wv%}n^BC@R~3bC>%NHxy;I@)pk4$E&Cvd}R3xPR6rx(1i(jA^AR6k0pB z#^B+8`qqWJNR#=igeh2mO~nGgXVhIfRB~h0O9CQi=aKX7$F;(ND!06^kX<(5^eNq* zX1MlRR&S1klX}{2Ea+5#t~W>^`urfx0IZ1-ppqODRCfXz0mxkbdw4-sam^Tc8_!1nB7~1;8&h0C3IUW_7w*nJ3L0Aqudy8XXwHFEr656a!*gsq7mSLr2nK{d*ydr5%G84-HnrL%U659Ql3N}=l>zp znE~H|{+Rv@JvoW_zi!VSN7^0E%;a_4u(>jMSM{bBe1oHF=n9!!fWJd%V=#AsmcvaOVjD3n0f5M&snrti_yIfvJ==J>)J&7 zK#J%kcaPhGJMw4`fg=TTdm(7;!j^kF2 z-nxY!T_H7ateaLeq~K!{mO3jH^}hMFsmdr6gzLKc!dDlATFuQQtb@Vw?SxCh;6PTT z)_6lS=KZj@BLSV~r{0n2x_arDA>mC#bF?WXKA$DkFUPk5Gv->0@ES|*M4S<#U8*=+ zFmT?kBPbZMq={-pEf!*EJlKkoQjQi=`<0xoU?ORaRGY96=%9ZCEo*~BS{Gh{&2n_8 z6?VGrso78Ba0Xxwf#YqLRt`1IgJhtv=x6MqOY{Saj{DkI5ti@yOyC`c(9@Qdarbg4 z`a@Fa_mX>v?}Hvyy+Vq2$$39B5Y7#K>TYAuIgoK`A(cIZ~~OH1T| z>{F3=wL+c-$@^kYg$SEPG=hy~(`*C5*O4HfDqKbC2d|Oko|0|uK*tE!TNSx7L%$&H zk&6ZzoAA;m+~HXn9@Q^G@O@VCf*ikaS_oFU#79KX5TZCh6+;(=Cq8R%FRpSwz|{#5 zCz}8q&+p@^=3{Heu%^@16T`!a$0A3$KZ4k5S+;lPFE^l++#)iUS{r;xU4I(u8!O*g zhPZrMAKP#E8@Au*6~dMrV%d}qWYsI1jTfysV)M8-`K=(S2cFEor^%chD}Uju3j7#l zbA->~_MZ1``4uNPmk<}ll{3~;fUB@G$c3?}wY`!tfgh2GVD*>Xw^k@%gpSblcMSR} zn+LF6!*b^Zv=pL{aSekD4~!Wb7oR4D4*F`JFY&_A5JD)ZBAqp-5Cm$PNy3$^wYNp0 z_!}@K_p3Zn^M|EOz8N{Te$9lso*0S=JFdL3N4^l9dCVv~dv$L;XBv^0pP%2b1az5~ zPH)}AmOq*C;eb2Y=mtN>S#mpGRAXhH5(agclYOsmGbQ0SJ`-FBlDZ^6VtX?cf^ENV zTrP9l-ul}Mf_fcBdxF_p!=?DoHaG~WScH2tYU`)FHVk)?%~!WSljCD6xK90Bgyp9^ zlg(py&c+}R1)Jp3A$e(6JESsc+uoWAjmklCb~sm%==;bm&CyZ}S+o|sZie{+7iUG{ z3iVc<#6UJZ2BNZoZP8>)PS{eQ&Bfp>4IBfE+2B$1S*8`2i1$Y0e!m;Wz8<^JSz%`8 z@KukkdOmn7$6Lfv^J&U{se>^R`G=I{59Y!#2vpEAD0a@Hc>7h25oR*=dx_39b$VIp zr#4^v z{cqWhsD}HSQ6+=5^~<#7z*)mwu4bFDBb%Qk^fOfvKdmtQSk9!J0cc!ivylEGH;Qc% z-yMPXsn3O9pPE}p-h6>J;l)2##FVTx;*v(0CXSczVpwI%+wpN}ISN&!BJuL56{^VOAN=-(oDXKS(z7Z01j6-;TRj*^ru~VBs$2TTiAl)Y&}+_64MYLE(xiMi01|? z1C%n4-L0B}sy&Q(WxyF0l$|iW9Nw>T0wVA-%r#t6hk6{-5aUygXfEBNN4 zq315EA83$;c^_sRUhujG7S12M_ygH49j7v^isaDB8y}qIYkP88cd?i$5R=B0$0OXV zmdrXR7YjXVS`)f!Wijcj`uZ+UAv(&vAVW` z7sr^4Z|A6f&{r?9RBA(+vSq!e$7A$Qi@{t}+^{`65-`oi9_F6;VLeuUp~5Lj@IO|_ zc%|R{1sA&DKZDPK*F6O>(eMy`w(1H$*grUVqw|&JkJ+-Kzj77_P?_>gjh=S9x09;o z4KnES6~L700R}i2mY1&C5^VFRwYH_ITx;)v+7~XPjGM^Nw`D#!kJqRuUNgZqAt~@@ zZAcvMN^}8?kQFBQBu|=;9;b=nDKW3#kX6@w{nJM!2KUKdx4@9M+wxKA*Q(HKWx+D2 z3^uIx?>_qnvp(NbtsDHy9MgQKeQL=9;j_It^kuMx_Y#LqG?Yxx^CY8EEkRg&g!Sxq za^7XI)UhJsD?ZK`GNDNkk+#RRsotw7ajyCusaGDusCz3A`72f2AO|TZ;@747I+js- z@G2H5l3~ShvF#HjxCq6uI@Rtk97)OAOVp~A0O(3i6NnNApULA_#lZ#c;;xQ|hRAG} z4(bGU``t=uVHZ030zZ$Ac}y*8#81%=&&#jDki{|btqki%a&2V9d*9YIq*{0 zM(S3rd!2hBM;WmhTds|o0n72?==-QXc?8lg2JPc_Q>60p#&Y@fTRZaZ`nSf5+>KgYQ=Eb?**^Z95|`Pl9pda_lq8#!cLRvY1x}m9joGTkO?x z6M6l-?Jz+l3hRx38$)3@%K*E^pn!CZY!S-ArI~Nd{K8yVT^)(4mi89~2O-uE%QjRR z6h5k+YmgJ9ui4xD7KqKSz;gdI;kZcaIpm_~D(hr*R+X}M7#I4fFX?M-39fy>DP!*z zYX4jiFjj7KZKwHbO(4vfS2t$Zav#|j*(c?OlaefJ54|+H-4OvWcQY-gckWme7fz6& zFim>@5prS}i`#>;eqNshXu!Pp_qzJ`yV5Gts10Dg2xRZYh!IUlyi@x}h~2Z9EB1$rhpR?_s8op5^zD zKb9JbjHN2#O^Kw3(4mxsgL2;1rv#CuwYG%jGCj?A&2+MJB)se&=XGmrl>qu{&x2!h z64w>B`eDTFp_DLhVR+qhSy786Hmi=(_c3SEH(=@xg&N87G&x1A?uzhD#2!-%`6}$| zP^4mG7b(cQrE8{n;bMaE)L}A7@_-_o?3XqP?^Q+9ja zIFoeKa=e$aFt4-{>vyeTqlJ2*OH^&|joPA?>+jHAVQ1RA6s!3w7ur6T1%RKg>P{&U z1}7TbRY^K|&2UkIX+>d7aSy&aK~lOxpvw?8SGo04#5lR5Z!S8gDh9rtfqjV@w;Gd^ zwn>8Mj*Oa&E++c2@Edoeevwi}M_aYm)=OO|TtbUH0^f3;yDTZ) zWZP1AI9hVb_mTtU*1i_5@s(6gN0fSExUF9d#H#N6@G0fr})#ZsaSg+wVW$ z6uQ?9w1L|X$u7lpE%7~_RTeUoQhqTdek3a*f;bg(Pisd9LYr=g>RSJ!5j2n*-Vh#_ znpfF?oqpe1*Fi1$n{kOQpQK{xe)KVwi*%lwITzQTJnj6#<<(TXpC&%rNDYz?oo<*S zKZC%2lE1h^D{Cucm^Iu-rf*?mlo83$$)b3F)c%wO?<&;x7d)a@ri`gb8&OG`RcdbTrZX;7R!)0nm=R%A=NO}m5w#-9|-jai> zH`>OmU!FgEBUk8(sjFUz%uN?$422^SC+pT!(%I&+@LDBHzXO8NfL&v zf5>{P_v`)*z>!?p>y{o<6jS^D7cNkfsBfIebyRkwSW+q|%LMo#u?wFPg{v$(hUIzr zWx8bVS#vC#C^Z#o=-^YQ`-}=^QqNf-8PiBa9}#UxOR5ZMOUh4lUcd&O!i(=VP%{qG zvhwC@(;mI?4_4aJjB!-Lr+ZZEC7V2+ARFF1r7pd&=hvaq5G_hV1>84(fCnFRpdS6>lU0L!* zf0gc(Mr*VeGnmZDk-T604!gR%@6h%Enw&BB)dEY&E_dwdh(Fccrt?Ld;(v`-bY{Sv zTNur`%~4h!WBSL`t}yL=*P!d#huy)Zwd7cThe%V?ghweT%0m8Jy`@=?*&280PNlk% zAYxQw8=z(>0I~{a1h;K#oxK^AyJJ%z;nq=xbU?Yl<0<6+)mE~t%eRt(J?rr$P3pIY zqrX)#cVdnDON2MRx54c{=Y)P+x-Co#GpZy>z_(t{O*eTTVB(+Ag^h~B*5B#morz(o z%o)ISr#0WcOS!bxZv~q$@~N;cyPB64ZKM(_*GE3BgV@h%?ki-mTv6teGe3_>O zT%*I6qVtcbj;6`(jz}Ki4lUD5i=WHovdgbUZ_wTtG0HgkmX;#NSAk8vMvX#5}U^5 zF7S43!c(&N_THja8D!149U_1Q&Bx zVDrK&TXY#}6R$3a$3FEWmTO|p63Yn`*Sov#OgQrN{aivZCx;KcSt{#RZ83Z!CzRv$ z0$5q0$IzPC#u`AE6#sXd?t9Yf&G_L23~XBCu>=M>tj7}C{t+!q04jbB^I;3#CO*8( zD?gbM0z1ea6l*Q3)jljF&L=+)BBZIf3{RjNn7}uSVz~tC+|j(Mi*@)Wm3#7V8A=a= zSPF&6md2fPbmO*m`*F{-OJ!({lc10*EbVZcR2JTAqC7;LEpgYF9q17OLmKTlr{Uh} zyPZFv7C2j!nI@bqi$LmztKNlTJKZ=CYleTA6$>(B__9Ws+7nE8)dQ6UUDY+?TofZfdYJkTkb} zt$t#4D{>=M3jKVfLe_fHaw&~U#tAOoG3Dr&xS*iXZIlFS*KJptBp)LJOxeu~RtnvZ zpD$s=Ac=_a=!KZOv2mMtoD6EaWo>A|!CsIJT61Uc65$9&6+)TA7BgtEg$5x;i~M@< z-Cn9;UN;50t-md&d+0XE+G;Q_+4iBABj4A@huMirM1DW%JXWhU-d5P?Rgu@csbzn1 zn&kc+AZeTspb8_Y+u07sy`A&9QRK-5#R$*BDU!7GRG`G&8N91Bl*YMT28 zJxA-pVPBG)Gcx|=)f$mzi&1<$B*bmvj#It^bk+`5r5(fK*&VaYRIoDBp78W2SwVQE zl#(AOVZW-C$3pRHovqxNp7l@t_ zg4ZzfHclrm?7tcVm*VZXonHnhgzq z0uhYHfyUSnkd_ITO!47KZ$FsLb@fS7Tkj`@qC5Lt?gCVB62PV;`R(R z*yNxACPEjx>yuGC*}$^=PFl$jSo^-t$cJngEKn#)R6; zY)Le!swbFxMIMza@F=cKc9;oGs2sD*TlMU@L>KOFJI}wcbpHLZJ80;|gR&p(npzBF zH3i7`v@pJ+7sx1@#uxTVSAJTcFe7i09gTm>F%N<9?xu;c9LMe5rA70mz!!^14)#+h z*BELghc2NWVuVcCGU_owg{j)1cUV zymQloW`lmYSsXU3U}!HTvhZDjE`9#kp46yIzDDwM;Uj+iC0c(Qizo7*kG(Z zhfa(zL)Z1b-~vJqEcgnc(T-9~dUj#)Z?2R>D%^(9m@nvU*~UW9f~`^IHu;*%uyVN( z3ONHEajy1h44-ibl>SA^ly6}~Nw8Ikg#MzpeabVS{!)%l(os-_N^wo5-Zjm&&nZ=t z_g4f?ZASo3A$&ii6}S5?E;t*@-9K!U0yP1{W6Yi)tnvQ+ED82DR z`;2qrBy_KmTSy~XBjT+@DnU|#T%Izecca3B)GXUpx@0|^sXnTr*;qU_@U$QmxxboA zkwwz=76;gwc4?}l!0RaGYy)yH$h|1SWz%~+SoHfUZWBQ?oL`H2IgZVovNb)o^(J1-sa+|Zdy`CP*7)-^?*7X3EJ1B92l&uD4WvH67}h6%;S&u zO1bV1`A*Lj;pQt9y}>&7jd~zmw>uIp4Y|DUicrTUHBV{T5AanrO%u8%ArbXb(s{f8 z?8JZiv8X2%;63ZpTjJWN*wdBW+AzfmLKh~c@P`kI61GJID@_z|uARG|o7QBE%Jt(a za6H#z>7?O5=LIX~OL(Ora*`cM`P%^pl^EugH4{@>#cN=0ti`Td{9Fhz$T$S5o8yEs z5c>_JY%#@{2g%QG-<;b>HL_7rj3?V@u7r~4jw&W-iRW&h^kgr*kGssvNB*Q&$<4gf ze^uv_U3xG=!9Pb;W>a4}Y%Ts?^6dRv4TfG|EkX=3sF$@+%ArZnB<#gBD=07Pk~QaI z7K+A4xsO?ml@mrN!R0YyzEyI05nD}ioJK{?h3mZZF0SY}+(AqGM+271EuDp*NNe3# zUrmnC!P}7Wf%XsyciY3+jt7_9Nc+(Fk(D2IX|CGF&2l?bqKf8)MEwTn1zw|hk20cU zlny#kZEd07Cl30yn?Bn4QtaG^Dp?8iuV6N#Qi&JPx7JBFVtpdXc0m%`Kj@?E*PF-& zLA3t+1Zm-T9zrx(xFfFbV%WKV;!$1GgQ`5d_2=^f>|F*H?n{rqOcLpfE7(F}=aj8} zZ)mpn%5@?MZ>d#@LzNT;Bo7xh`YhU~{XuP)AkR{nBH=Ke>P67+&{i{1y)C?2qC+xS zzzt9!X@bc2e$tT9l_}>&%Mx?F(3>1|qBhU$8gbB-u`f*pDyvXY<-7cO33utUF%-js zpLQzJ%=t~#S0Bl=zaWK52*FFQ5LD7i?&tKR3isblZeZ{ofi_d*B1>Fb8E&Dd2!PI!zT0L&hB=|O8BMw;qpUg=zZmm>MU6+EftS%cV%V2 zuiTiW|B0cYE10;Ug@{p5hhhIH~&ny z^L`z6$}%te8l-|)9m6GhT)UMfF#iE4P{YO#Kw z_S9atz~$!xi!qDUywz@N{E~^1%TlDf`(yBxHsz+$g>36S!Nqoz*lsg*U9YuiI+G+V zmS*Ygd8|nGi^};-oH`r!Vj#6uxbYlSk6@jrdklBbd6ax6K}q-W%6xF%i~Ktp`M^fC z29p6rswh(|Jr^~f=S@bL9I$Gna-Wu(a%IT%irY70b3s}YC&5@vaM{Y5gn_Jh_h zPWc5%7_+D7#wf+i&wVC&UuqK*keV0q|8ishY}m|FA-LA89 z)51z;sR#1gNgpMKQsgZ71#!dd^|V-U*QtKFAwlpq^3dmXitpguH}E{^yjJph+ybz3 zud*(LfALL*_6I=Hn3wyXEcZ+0PhOb!e7Sj}SZ)=b8e1iMY~p(z)gz;vpNRJ=Ft^V@ zx|GJbMHo2o242b6ePeLc$h}PlXx&2CLlu&@LB~PZCI=OPlX60iqzpeO`qpKszCKRz zFCrcK>Aw_dhNXm%I>Suo6G*Z@6q8uWmS@26+#O?Oq)yxb3sPxNPPwQHZ(my6J}75f zxGQGo-uhr3Kj;#+@?L61C@mjHh*|Lea;!^mEnW^nBX8(0xGszlNq(C3;B{I|xbRZd zoLc-s>x)gUdkw$=!oV_y%ABQnV-4}dYF_^`eh~Hu<;FXoWKcN|m5PoEvU2%TB83gO zb+j4xh9lPWmQ8!^%G7#^gvktx?*zO%r_{kECOYn`TiuQ_uouw@N`3QpG7r~C)#ytN zC`h{zwx%H%OL@TUK1N`G!OdG=+PO$*xxXQ~ohC{RPc!{a;38m{@|7(EkV|Q~ulQ6N zlezLDn~(Ni>~)i2@0&*#o)Fx>bY#UE%D^1mf0h*VCs(I?JCH3f2=bg1pIRxC?LXaZ z_uRe}%jh(-|H-lCJwAhGlk4^l!FcqgcD_K;r|BLAZY@haiCix}v-2m+?Q7Wz)7#Y8 z_umX^orobh0;XABFpp!{s|2zfk8AKKBcTjQ0fQS&`Ct^Ckq1!bgcPR&ec ze(TLFg4*83)0b-O*HZ}@Thiczx-ezYr3Fc}9+LVntvS$_+9S*v(h8}8H}z`XSRJJKTRA@%m({=DH!-LY2=8+DAPnuI6<`cgz*NWez z{g&2Roctl~qJ~G_k>BL8-ps?LMNKT%e)lL6&7WA;@`#m^!S&AyA>9*g@8%V3EB5rv z{Z?xizn{}DoA2H7^yQ`#Y5&lBZ$ys%4P;SwNuv03zgHx2bFC9ZaZG(ml^Q54Djko* z!K}ne_iX#if7iZ!SGpHjrgQ-rsFHq41F8Qyck_2{1Q=;NpJr~1U*boLyz?mHCLGuG zAAQwNd)dXCD9P~8l4SX)g>}Sy8)kQsc-}I7)eN~FNAx{N->&7C3q10>xZOw>V7yP~ z__Av&M(T?QdhJk0{tGVrTL)`%!WIF%wCToLIe^S@H}cQXZjX_Atcc!tj(=o;;S^PH`U|t;^M6`P}BCop!#>8Z8eSB6PD> zVmBu|S{Hj0%_$XI{UE-`-vVILkeXh zxWf!2%UIjqT84)WB)w-1Y7^HXzi5+QFYXjDJJP*|kl^i+JViZ>EI|Fh*R@a%o!yJ{ zCcI`MegO=anj$WEMq=W7d2K|rr|aw5w=Hs;^mA$9KUL3{%-+^29r(J9W0-B1w-Z2R zsvFhoq;IZY39d={t|wh;Hk%}zqaTRCzXnV1dD4EPx>YuozoEBJ}*PyTql;U6OZI0*1F5klj@L7)$TXH-3+V+Z9mP*hQ@pDo7<;( zByUOg9F_OS<#|U{=AexsyNG#opNO?ZHSiv~6T;TjO9d1Uf|0!M?i$T_(r1wnxW53< zf;(RJk^WlTwRSu{Iy7$3{W|2Ca?`L{JHWOg)TyuM^z3-iJFGjwn~l>#!*wzmC>eX^)5;Pc^;8h&YOlewt_)W3; zKo2?xs1JMsgs+}%`W(hDf|rV~f&|h5DIxJ{S6cfvk$5We)#D0xf$Z$;KA>^_>v5j0 z|H5QZ1@Yur#5y}Wp8&*~sFv2&Y(T|yR5|8DB8|targeJSBCwYAG`J$%tJCZ9MTbBqLoOre+|}0AQ49uC zWM1h!6(aBPXU7n;ih$a%WpOMHoPYJ$#H)P>AoB(8gjpO+kDSnALjP&$RPtY(HE8{iW z(MGv+Xpq2juMpSc!)>(_;wwu^Sbnb9xmTx?)6*GVa};iEKEyoJumh~Wxv}vC&@#%r zNxjYns(vD=;YA8|d{zC{MhfHxfs6uDY*(qEZx3RIL770) z??p7IlK!2Lf3u51zuzs014tkf&=vudLPY?9DfzL>OZFxgK}nwQ#N?GX;=Al?u z$uT2Fc9~2pC=+B)q9y@4T|6fQ-DLody_S&WJ}zwBux>fMy8Y#@qc|?L!|3s!B|Xn# zyBY@YB7A+zwJd&IPrJQ9?y(&mXXgFKCOwj-!<)*(-pwWc=Rs~~vU@=f?fx?zRV@F3 z8{Cs@p}h-i2Uvp*8Gw$VnZ>luEF@aDL7q80JUo6N zA;E+mF6RDXly83#borB*j{@?UF~DPA@B9A!`!Tf~Z7KnXow_I*UH}Q@58}-<;KNZN z%pQ^7&V!7^i9mH-nSXz-w*6VqWlpMU^qGeV@5+_z{~c=AU@6c)KuaI6ntIivpUd`T!x*Pxd4rU;A?A)!?P2`=;&5SH~uITBMb#tvj%QB7paNW82!1 zhY&p@Bk+k#aJ>xN>~G{H2t!h56vmw7rM*kL<-ah1j3^C#Go(56FXC6ql|Rr~JsA)a zKaqu4p5Jw+;8f=Oth8BoJHyFqU0ioAfI@FkyO=$MiiJ+v1v#s?Cw%LB`}@TaA_@EY zl>W;XUK!dUjZ|NhxH^#EF8QlOFHy0-R-mvs(b@_|xmxrzFpS&gnar zmkI$;+DR4_I@9N89=fQ=f8GGZrEUIe1a_*<%IQ}k_DJC4pUn6FKSr1?9sSn`wEvS4 z?hx;i>Xehv=8@cICMp31Vzpklc!4!M#Upq+jBHeiRCzmexJTwv1; zK3eiP2e@6F-O<(EhtTDnEkIo$XuJOSu!kO4^lVZN@4pP%Q+z<*E{AwH8$*3!$?Ka% zf&Qas7#05h`u6RcMO+81hDwl7P!J}bdX7_(kDLKSrQ%b**OkL45~e@V^LKSAvV{wv z=hmdiz>vs=-@Rm=c7!;wqYGPUBne{TBc>3RjJzyR=PQcOzxov9vHo|5L&Jp+@XPjg z33DmK+{O7P*BcqUoGXiqqa&7z0Fuch2jry6+E^JG4ikmaK9OofW(y>P^;PUO#+nZmBkS!6yKgZ zF)`61kxO%hb%7q9Qjx!MuO^+$T}%SpWF>e>`4;_zf-M{1_3YH>O#ib!fFLtwlSNQw z0|8OvWa+E~TxUJ;XTU1??@9;E`rlU7Bs)Nx$)X^$D4Kn-W;#KP%YK#Qla(iQY+bQ2DpQ{^=^zzz)0S+bq zDz(pV(tWpEe&wK_G2ri8#yJ^4f6&B|&^Uu*vG7}+0ZJ{e4TJRl_KE<)mI{^bi$;>C zK~J5K2^}rJE5G^FQ@+#n}N{++&VByCywTS4A~ESwb!HnZ;x{__;<57h88#5 z06+cuM0WvT2?f z86_gXuhv;q%>Q?GGDL;UVbE@F8`4wX0p-}Etb+L9kdTv^1BKKub#dJ*5*EM_<73=& z4S>Pafyg_Smlsu3n`RY;f-)ceJCKOv8$ghAfBEu>K9IZIiJWQksXO8VQku!pum1ai zYQRR_#p(+D51<3i)G{`P0OIhqh{#A)eSLk4-4krx_)8b?EUEWA5J^*0!vWn$rZk|u zwFh9luP*WyqV`VGlk?}#f6B_ry08Cxrtctc`243+51*l_L_s(}3Gx62c03zciJ9_o zzz_jr{JiSYzwYI~9{oR~{%t7}o5isahHpDC8`VRH28Fr+1L$vPWl!%LvP(Fw8hb}`}jSAkP8Lg*mGj4 z(AyK-*+X}6MR9h*V--#r%=bV{PwLDwPEx@ifTXgA;_hth@eLp}FdkA9($>y_&XxX+ zE1KQP>+xU4)Ffvq3Y{3FVfJ1K14n2iyX@MB6Xc#=>95d}L?iR{>(_Qb)>{qehkZ>{ zD0pI7DlvE()C|Z3D8zjd+5pZVP$6zKMBHZZEYDAjA(x# zEU?pDtF8@en5doPwm`zSEum6l6nf*!MNp`vqoYW2VxryIt(Ac78e4$a`@yVjx$~m221k)H~T6bB;#! zFv_6LdtO`;>LTBIRX)%w0&WZg=46uON^mVQ$Wx{{e}Xk&j+_e8>l79FA4a2yf|xo1 zod*vtAOWuF0fg>L?2hzyX$yb<7AK#2_2vXm-z^iVg4##*9b~O({$8q>qyQU;H$X+a zl^alct#=dv;N*`7?2sv@=Rl$J)6HRhz-4SUkg^0QdGGXS2pTuKAwdsI5CA>~Ug2m4 z>>#9`uD>N~o~(_}vd?R+m53~0AgxNAn&JZdz_07TF96#V7yP?a{u>=CxPaXU@QeQ^ zCj1Wr*RnPL`*LuCYFSy?GlCHt<7@E0v#a?;1&NJAIY2=U5HOl}`AkueWN%@SLH*Ce zJ=p+ka`+NhWXG(h*ZR0{3RjhC15n8^e3CiA^>)=Z5 z8x>Vtcm+lfPHGz>*n_w3ZWwj!PI8txfI~&3Rea?lXW)`!uou>IdEdM~M4kFaw`I01 z&5`j>)TiM(>1HD{GJYXK)vU}IWN2txpw}OVm>P<(*zKf2#}YQbpO?-#-$jm z5Z)NQ`v0~>h=u>=U~fphX!6R8RMlk=Q{P-yN;YustpKoaMFSM<8NS^B=BggRG>ZV5 zZaE!jC*JVQ!qQSiJ8ezwWOO|HQ4a@_Kr0L_6 zg!SCN3G09U^*L#CbMxuRa0828i?b!7mjb9RHuq0Xa&gGI@&eVZJ~SUYr?JXsKu+*I z6+o@a0TNVGfb=IdzW@LL diff --git a/assets/grocery_crud/css/jquery_plugins/uniform/uniform.default.css b/assets/grocery_crud/css/jquery_plugins/uniform/uniform.default.css deleted file mode 100755 index c0eacd0..0000000 --- a/assets/grocery_crud/css/jquery_plugins/uniform/uniform.default.css +++ /dev/null @@ -1,645 +0,0 @@ -/* - -Uniform Theme: Uniform Default -Version: 1.8 -By: Josh Pyles -License: MIT License ---- -For use with the Uniform plugin: -http://pixelmatrixdesign.com/uniform/ ---- -Generated by Uniform Theme Generator: -http://pixelmatrixdesign.com/uniform/themer.html - -*/ - -/* Global Declaration */ - -div.selector, -div.selector span, -div.checker span, -div.radio span, -div.uploader, -div.uploader span.action, -div.button, -div.button span { - background-image: url(images/sprite.png); - background-repeat: no-repeat; - -webkit-font-smoothing: antialiased; -} - -.selector, -.radio, -.checker, -.uploader, -.button, -.selector *, -.radio *, -.checker *, -.uploader *, -.button * { - margin: 0; - padding: 0; -} - -/* INPUT & TEXTAREA */ - -input.text, -input.email, -input.search, -input.tel, -input.url, -input.datetime, -input.date, -input.month, -input.week, -input.time, -input.datetime-local, -input.number, -input.color, -input.password, -select.uniform-multiselect, -textarea.uniform { - font-size: 12px; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-weight: normal; - padding: 3px; - color: #777; - background: url('images/bg-input-focus.png') repeat-x 0px 0px; - background: url('images/bg-input.png') repeat-x 0px 0px; - border-top: solid 1px #aaa; - border-left: solid 1px #aaa; - border-bottom: solid 1px #ccc; - border-right: solid 1px #ccc; - -webkit-border-radius: 3px; - -moz-border-radius: 3px; - border-radius: 3px; - outline: 0; -} - -/* remove default webkit and possible mozilla .search styles */ -input.search, input.search:active { - -moz-appearance: none; - -webkit-appearance: none; -} - -input.text:focus, -input.email:focus, -input.search:focus, -input.tel:focus, -input.url:focus, -input.datetime:focus, -input.date:focus, -input.month:focus, -input.week:focus, -input.time:focus, -input.datetime-local:focus, -input.number:focus, -input.color:focus, -input.password:focus, -select.uniform-multiselect:focus, -textarea.uniform:focus { - -webkit-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3); - -moz-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3); - box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3); - border-color: #999; - background: url('images/bg-input-focus.png') repeat-x 0px 0px; -} - -/* SPRITES */ - -/* Select */ - -div.selector { - background-position: -483px -130px; - line-height: 26px; - height: 26px; -} - -div.selector span { - background-position: right 0px; - height: 26px; - line-height: 26px; -} - -div.selector select { - /* change these to adjust positioning of select element */ - top: 0px; - left: 0px; -} - -div.selector:active, -div.selector.active { - background-position: -483px -156px; -} - -div.selector:active span, -div.selector.active span { - background-position: right -26px; -} - -div.selector.focus, div.selector.hover, div.selector:hover { - background-position: -483px -182px; -} - -div.selector.focus span, div.selector.hover span, div.selector:hover span { - background-position: right -52px; -} - -div.selector.focus:active, -div.selector.focus.active, -div.selector:hover:active, -div.selector.active:hover { - background-position: -483px -208px; -} - -div.selector.focus:active span, -div.selector:hover:active span, -div.selector.active:hover span, -div.selector.focus.active span { - background-position: right -78px; -} - -div.selector.disabled { - background-position: -483px -234px; -} - -div.selector.disabled span { - background-position: right -104px; -} - -/* Checkbox */ - -div.checker { - width: 19px; - height: 19px; -} - -div.checker input { - width: 19px; - height: 19px; -} - -div.checker span { - background-position: 0px -260px; - height: 19px; - width: 19px; -} - -div.checker:active span, -div.checker.active span { - background-position: -19px -260px; -} - -div.checker.focus span, -div.checker:hover span { - background-position: -38px -260px; -} - -div.checker.focus:active span, -div.checker:active:hover span, -div.checker.active:hover span, -div.checker.focus.active span { - background-position: -57px -260px; -} - -div.checker span.checked { - background-position: -76px -260px; -} - -div.checker:active span.checked, -div.checker.active span.checked { - background-position: -95px -260px; -} - -div.checker.focus span.checked, -div.checker:hover span.checked { - background-position: -114px -260px; -} - -div.checker.focus:active span.checked, -div.checker:hover:active span.checked, -div.checker.active:hover span.checked, -div.checker.active.focus span.checked { - background-position: -133px -260px; -} - -div.checker.disabled span, -div.checker.disabled:active span, -div.checker.disabled.active span { - background-position: -152px -260px; -} - -div.checker.disabled span.checked, -div.checker.disabled:active span.checked, -div.checker.disabled.active span.checked { - background-position: -171px -260px; -} - -/* Radio */ - -div.radio { - width: 18px; - height: 18px; -} - -div.radio input { - width: 18px; - height: 18px; -} - -div.radio span { - height: 18px; - width: 18px; - background-position: 0px -279px; -} - -div.radio:active span, -div.radio.active span { - background-position: -18px -279px; -} - -div.radio.focus span, -div.radio:hover span { - background-position: -36px -279px; -} - -div.radio.focus:active span, -div.radio:active:hover span, -div.radio.active:hover span, -div.radio.active.focus span { - background-position: -54px -279px; -} - -div.radio span.checked { - background-position: -72px -279px; -} - -div.radio:active span.checked, -div.radio.active span.checked { - background-position: -90px -279px; -} - -div.radio.focus span.checked, div.radio:hover span.checked { - background-position: -108px -279px; -} - -div.radio.focus:active span.checked, -div.radio:hover:active span.checked, -div.radio.focus.active span.checked, -div.radio.active:hover span.checked { - background-position: -126px -279px; -} - -div.radio.disabled span, -div.radio.disabled:active span, -div.radio.disabled.active span { - background-position: -144px -279px; -} - -div.radio.disabled span.checked, -div.radio.disabled:active span.checked, -div.radio.disabled.active span.checked { - background-position: -162px -279px; -} - -/* Uploader */ - -div.uploader { - background-position: 0px -297px; - height: 28px; -} - -div.uploader span.action { - background-position: right -409px; - height: 24px; - line-height: 24px; -} - -div.uploader span.filename { - height: 24px; - /* change this line to adjust positioning of filename area */ - margin: 2px 0px 2px 2px; - line-height: 24px; -} - -div.uploader.focus, -div.uploader.hover, -div.uploader:hover { - background-position: 0px -353px; -} - -div.uploader.focus span.action, -div.uploader.hover span.action, -div.uploader:hover span.action { - background-position: right -437px; -} - -div.uploader.active span.action, -div.uploader:active span.action { - background-position: right -465px; -} - -div.uploader.focus.active span.action, -div.uploader:focus.active span.action, -div.uploader.focus:active span.action, -div.uploader:focus:active span.action { - background-position: right -493px; -} - -div.uploader.disabled { - background-position: 0px -325px; -} - -div.uploader.disabled span.action { - background-position: right -381px; -} - -div.button { - background-position: 0px -523px; -} - -div.button span { - background-position: right -643px; -} - -div.button.focus, -div.button:focus, -div.button:hover, -div.button.hover { - background-position: 0px -553px; -} - -div.button.focus span, -div.button:focus span, -div.button:hover span, -div.button.hover span { - background-position: right -673px; -} - -div.button.active, -div.button:active { - background-position: 0px -583px; -} - -div.button.active span, -div.button:active span { - background-position: right -703px; - color: #555; -} - -div.button.disabled, -div.button:disabled { - background-position: 0px -613px; -} - -div.button.disabled span, -div.button:disabled span { - background-position: right -733px; - color: #bbb; - cursor: default; -} - -/* PRESENTATION */ - -/* Button */ - -div.button { - height: 30px; -} - -div.button span { - margin-left: 13px; - height: 22px; - padding-top: 8px; - font-weight: bold; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 12px; - letter-spacing: 1px; - text-transform: uppercase; - padding-left: 2px; - padding-right: 15px; -} - -/* Select */ -div.selector { - width: 190px; - font-size: 12px; -} - -div.selector select { - min-width: 190px; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 12px; - border: solid 1px #fff; -} - -div.selector span { - padding: 0px 25px 0px 2px; - cursor: pointer; -} - -div.selector span { - color: #666; - width: 158px; - text-shadow: 0 1px 0 #fff; -} - -div.selector.disabled span { - color: #bbb; -} - -/* Checker */ -div.checker { - margin-right: 5px; -} - -/* Radio */ -div.radio { - margin-right: 3px; -} - -/* Uploader */ -div.uploader { - width: 190px; - cursor: pointer; -} - -div.uploader span.action { - width: 85px; - text-align: center; - text-shadow: #fff 0px 1px 0px; - background-color: #fff; - font-size: 11px; - font-weight: bold; -} - -div.uploader span.filename { - color: #777; - width: 82px; - border-right: solid 1px #bbb; - font-size: 11px; -} - -div.uploader input { - width: 190px; -} - -div.uploader.disabled span.action { - color: #aaa; -} - -div.uploader.disabled span.filename { - border-color: #ddd; - color: #aaa; -} - -/* - -CORE FUNCTIONALITY - -Not advised to edit stuff below this line ------------------------------------------------------ -*/ - -.selector, -.checker, -.button, -.radio, -.uploader { - display: -moz-inline-box; - display: inline-block; - vertical-align: middle; - zoom: 1; - *display: inline; -} - -.selector select:focus, .radio input:focus, .checker input:focus, .uploader input:focus { - outline: 0; -} - -/* Button */ - -div.button a, -div.button button, -div.button input { - position: absolute; -} - -div.button { - cursor: pointer; - position: relative; -} - -div.button span { - display: -moz-inline-box; - display: inline-block; - line-height: 1; - text-align: center; -} - -/* Select */ - -div.selector { - position: relative; - padding-left: 10px; - overflow: hidden; -} - -div.selector span { - display: block; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -div.selector select { - position: absolute; - opacity: 0; - filter: alpha(opacity=0); - -moz-opacity: 0; - height: 25px; - border: none; - background: none; -} - -/* Checker */ - -div.checker { - position: relative; -} - -div.checker span { - display: -moz-inline-box; - display: inline-block; - text-align: center; -} - -div.checker input { - opacity: 0; - filter: alpha(opacity=0); - -moz-opacity: 0; - display: inline-block; - background: none; -} - -/* Radio */ - -div.radio { - position: relative; -} - -div.radio span { - display: -moz-inline-box; - display: inline-block; - text-align: center; -} - -div.radio input { - opacity: 0; - filter: alpha(opacity=0); - -moz-opacity: 0; - text-align: center; - display: inline-block; - background: none; -} - -/* Uploader */ - -div.uploader { - position: relative; - overflow: hidden; - cursor: default; -} - -div.uploader span.action { - float: left; - display: inline; - padding: 2px 0px; - overflow: hidden; - cursor: pointer; -} - -div.uploader span.filename { - padding: 0px 10px; - float: left; - display: block; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - cursor: default; -} - -div.uploader input { - opacity: 0; - filter: alpha(opacity=0); - -moz-opacity: 0; - position: absolute; - top: 0; - right: 0; - bottom: 0; - float: right; - height: 25px; - border: none; - cursor: default; -} diff --git a/assets/grocery_crud/css/ui/index.html b/assets/grocery_crud/css/ui/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/css/ui/index.html +++ b/assets/grocery_crud/css/ui/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/css/ui/simple/images/animated-overlay.gif b/assets/grocery_crud/css/ui/simple/images/animated-overlay.gif old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_flat_0_aaaaaa_40x100.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_flat_0_aaaaaa_40x100.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_flat_75_ffffff_40x100.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_flat_75_ffffff_40x100.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_55_fbf9ee_1x400.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_55_fbf9ee_1x400.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_65_ffffff_1x400.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_65_ffffff_1x400.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_dadada_1x400.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_dadada_1x400.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_e6e6e6_1x400.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_75_e6e6e6_1x400.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_95_fef1ec_1x400.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_glass_95_fef1ec_1x400.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-bg_highlight-soft_75_cccccc_1x100.png b/assets/grocery_crud/css/ui/simple/images/ui-bg_highlight-soft_75_cccccc_1x100.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-icons_222222_256x240.png b/assets/grocery_crud/css/ui/simple/images/ui-icons_222222_256x240.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-icons_2e83ff_256x240.png b/assets/grocery_crud/css/ui/simple/images/ui-icons_2e83ff_256x240.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-icons_333333_256x240.png b/assets/grocery_crud/css/ui/simple/images/ui-icons_333333_256x240.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-icons_454545_256x240.png b/assets/grocery_crud/css/ui/simple/images/ui-icons_454545_256x240.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/images/ui-icons_cd0a0a_256x240.png b/assets/grocery_crud/css/ui/simple/images/ui-icons_cd0a0a_256x240.png old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/css/ui/simple/index.html b/assets/grocery_crud/css/ui/simple/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/css/ui/simple/index.html +++ b/assets/grocery_crud/css/ui/simple/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/css/ui/simple/jquery-ui-1.10.1.custom.min.css b/assets/grocery_crud/css/ui/simple/jquery-ui-1.10.1.custom.min.css old mode 100755 new mode 100644 index aa671e0..66bcfff --- a/assets/grocery_crud/css/ui/simple/jquery-ui-1.10.1.custom.min.css +++ b/assets/grocery_crud/css/ui/simple/jquery-ui-1.10.1.custom.min.css @@ -2,4 +2,7 @@ * http://jqueryui.com * Includes: jquery.ui.core.css, jquery.ui.resizable.css, jquery.ui.selectable.css, jquery.ui.accordion.css, jquery.ui.autocomplete.css, jquery.ui.button.css, jquery.ui.datepicker.css, jquery.ui.dialog.css, jquery.ui.menu.css, jquery.ui.progressbar.css, jquery.ui.slider.css, jquery.ui.spinner.css, jquery.ui.tabs.css, jquery.ui.tooltip.css * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana%2CArial%2Csans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=%23cccccc&bgTextureHeader=highlight_soft&bgImgOpacityHeader=75&borderColorHeader=%23aaaaaa&fcHeader=%23222222&iconColorHeader=%23222222&bgColorContent=%23ffffff&bgTextureContent=flat&bgImgOpacityContent=75&borderColorContent=%23aaaaaa&fcContent=%23222222&iconColorContent=%23222222&bgColorDefault=%23e6e6e6&bgTextureDefault=glass&bgImgOpacityDefault=75&borderColorDefault=%23d3d3d3&fcDefault=%23555555&iconColorDefault=%23333333&bgColorHover=%23dadada&bgTextureHover=glass&bgImgOpacityHover=75&borderColorHover=%23999999&fcHover=%23212121&iconColorHover=%23454545&bgColorActive=%23ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=%23aaaaaa&fcActive=%23212121&iconColorActive=%23454545&bgColorHighlight=%23fbf9ee&bgTextureHighlight=glass&bgImgOpacityHighlight=55&borderColorHighlight=%23fcefa1&fcHighlight=%23363636&iconColorHighlight=%232e83ff&bgColorError=%23fef1ec&bgTextureError=glass&bgImgOpacityError=95&borderColorError=%23cd0a0a&fcError=%23cd0a0a&iconColorError=%23cd0a0a&bgColorOverlay=%23aaaaaa&bgTextureOverlay=flat&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=%23aaaaaa&bgTextureShadow=flat&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px -* Copyright (c) 2013 jQuery Foundation and other contributors Licensed MIT */.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{min-height:0}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-resizable{position:relative}.ui-resizable-handle{position:absolute;font-size:0.1px;display:block}.ui-resizable-disabled .ui-resizable-handle,.ui-resizable-autohide .ui-resizable-handle{display:none}.ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}.ui-selectable-helper{position:absolute;z-index:100;border:1px dotted black}.ui-accordion .ui-accordion-header{display:block;cursor:pointer;position:relative;margin-top:2px;padding:.5em .5em .5em .7em;min-height:0}.ui-accordion .ui-accordion-icons{padding-left:2.2em}.ui-accordion .ui-accordion-noicons{padding-left:.7em}.ui-accordion .ui-accordion-icons .ui-accordion-icons{padding-left:2.2em}.ui-accordion .ui-accordion-header .ui-accordion-header-icon{position:absolute;left:.5em;top:50%;margin-top:-8px}.ui-accordion .ui-accordion-content{padding:1em 2.2em;border-top:0;overflow:auto}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-button{display:inline-block;position:relative;padding:0;line-height:normal;margin-right:.1em;cursor:pointer;vertical-align:middle;text-align:center;overflow:visible}.ui-button,.ui-button:link,.ui-button:visited,.ui-button:hover,.ui-button:active{text-decoration:none}.ui-button-icon-only{width:2.2em}button.ui-button-icon-only{width:2.4em}.ui-button-icons-only{width:3.4em}button.ui-button-icons-only{width:3.7em}.ui-button .ui-button-text{display:block;line-height:normal}.ui-button-text-only .ui-button-text{padding:.4em 1em}.ui-button-icon-only .ui-button-text,.ui-button-icons-only .ui-button-text{padding:.4em;text-indent:-9999999px}.ui-button-text-icon-primary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 1em .4em 2.1em}.ui-button-text-icon-secondary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 2.1em .4em 1em}.ui-button-text-icons .ui-button-text{padding-left:2.1em;padding-right:2.1em}input.ui-button{padding:.4em 1em}.ui-button-icon-only .ui-icon,.ui-button-text-icon-primary .ui-icon,.ui-button-text-icon-secondary .ui-icon,.ui-button-text-icons .ui-icon,.ui-button-icons-only .ui-icon{position:absolute;top:50%;margin-top:-8px}.ui-button-icon-only .ui-icon{left:50%;margin-left:-8px}.ui-button-text-icon-primary .ui-button-icon-primary,.ui-button-text-icons .ui-button-icon-primary,.ui-button-icons-only .ui-button-icon-primary{left:.5em}.ui-button-text-icon-secondary .ui-button-icon-secondary,.ui-button-text-icons .ui-button-icon-secondary,.ui-button-icons-only .ui-button-icon-secondary{right:.5em}.ui-buttonset{margin-right:7px}.ui-buttonset .ui-button{margin-left:0;margin-right:-.3em}input.ui-button::-moz-focus-inner,button.ui-button::-moz-focus-inner{border:0;padding:0}.ui-datepicker{width:17em;padding:.2em .2em 0;display:none}.ui-datepicker .ui-datepicker-header{position:relative;padding:.2em 0}.ui-datepicker .ui-datepicker-prev,.ui-datepicker .ui-datepicker-next{position:absolute;top:2px;width:1.8em;height:1.8em}.ui-datepicker .ui-datepicker-prev-hover,.ui-datepicker .ui-datepicker-next-hover{top:1px}.ui-datepicker .ui-datepicker-prev{left:2px}.ui-datepicker .ui-datepicker-next{right:2px}.ui-datepicker .ui-datepicker-prev-hover{left:1px}.ui-datepicker .ui-datepicker-next-hover{right:1px}.ui-datepicker .ui-datepicker-prev span,.ui-datepicker .ui-datepicker-next span{display:block;position:absolute;left:50%;margin-left:-8px;top:50%;margin-top:-8px}.ui-datepicker .ui-datepicker-title{margin:0 2.3em;line-height:1.8em;text-align:center}.ui-datepicker .ui-datepicker-title select{font-size:1em;margin:1px 0}.ui-datepicker select.ui-datepicker-month-year{width:100%}.ui-datepicker select.ui-datepicker-month,.ui-datepicker select.ui-datepicker-year{width:49%}.ui-datepicker table{width:100%;font-size:.9em;border-collapse:collapse;margin:0 0 .4em}.ui-datepicker th{padding:.7em .3em;text-align:center;font-weight:bold;border:0}.ui-datepicker td{border:0;padding:1px}.ui-datepicker td span,.ui-datepicker td a{display:block;padding:.2em;text-align:right;text-decoration:none}.ui-datepicker .ui-datepicker-buttonpane{background-image:none;margin:.7em 0 0 0;padding:0 .2em;border-left:0;border-right:0;border-bottom:0}.ui-datepicker .ui-datepicker-buttonpane button{float:right;margin:.5em .2em .4em;cursor:pointer;padding:.2em .6em .3em .6em;width:auto;overflow:visible}.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current{float:left}.ui-datepicker.ui-datepicker-multi{width:auto}.ui-datepicker-multi .ui-datepicker-group{float:left}.ui-datepicker-multi .ui-datepicker-group table{width:95%;margin:0 auto .4em}.ui-datepicker-multi-2 .ui-datepicker-group{width:50%}.ui-datepicker-multi-3 .ui-datepicker-group{width:33.3%}.ui-datepicker-multi-4 .ui-datepicker-group{width:25%}.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header{border-left-width:0}.ui-datepicker-multi .ui-datepicker-buttonpane{clear:left}.ui-datepicker-row-break{clear:both;width:100%;font-size:0}.ui-datepicker-rtl{direction:rtl}.ui-datepicker-rtl .ui-datepicker-prev{right:2px;left:auto}.ui-datepicker-rtl .ui-datepicker-next{left:2px;right:auto}.ui-datepicker-rtl .ui-datepicker-prev:hover{right:1px;left:auto}.ui-datepicker-rtl .ui-datepicker-next:hover{left:1px;right:auto}.ui-datepicker-rtl .ui-datepicker-buttonpane{clear:right}.ui-datepicker-rtl .ui-datepicker-buttonpane button{float:left}.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current,.ui-datepicker-rtl .ui-datepicker-group{float:right}.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header{border-right-width:0;border-left-width:1px}.ui-dialog{position:absolute;top:0;left:0;padding:.2em;outline:0}.ui-dialog .ui-dialog-titlebar{padding:.4em 1em;position:relative}.ui-dialog .ui-dialog-title{float:left;margin:.1em 0;white-space:nowrap;width:90%;overflow:hidden;text-overflow:ellipsis}.ui-dialog .ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:21px;margin:-10px 0 0 0;padding:1px;height:20px}.ui-dialog .ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:none;overflow:auto}.ui-dialog .ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin-top:.5em;padding:.3em 1em .5em .4em}.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{float:right}.ui-dialog .ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.ui-dialog .ui-resizable-se{width:12px;height:12px;right:-5px;bottom:-5px;background-position:16px 16px}.ui-draggable .ui-dialog-titlebar{cursor:move}.ui-menu{list-style:none;padding:2px;margin:0;display:block;outline:none}.ui-menu .ui-menu{margin-top:-3px;position:absolute}.ui-menu .ui-menu-item{margin:0;padding:0;width:100%}.ui-menu .ui-menu-divider{margin:5px -2px 5px -2px;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-menu-item a{text-decoration:none;display:block;padding:2px .4em;line-height:1.5;min-height:0;font-weight:normal}.ui-menu .ui-menu-item a.ui-state-focus,.ui-menu .ui-menu-item a.ui-state-active{font-weight:normal;margin:-1px}.ui-menu .ui-state-disabled{font-weight:normal;margin:.4em 0 .2em;line-height:1.5}.ui-menu .ui-state-disabled a{cursor:default}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item a{position:relative;padding-left:2em}.ui-menu .ui-icon{position:absolute;top:.2em;left:.2em}.ui-menu .ui-menu-icon{position:static;float:right}.ui-progressbar{height:2em;text-align:left;overflow:hidden}.ui-progressbar .ui-progressbar-value{margin:-1px;height:100%}.ui-progressbar .ui-progressbar-overlay{background:url("images/animated-overlay.gif");height:100%;filter:alpha(opacity=25);opacity:0.25}.ui-progressbar-indeterminate .ui-progressbar-value{background-image:none}.ui-slider{position:relative;text-align:left}.ui-slider .ui-slider-handle{position:absolute;z-index:2;width:1.2em;height:1.2em;cursor:default}.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background-position:0 0}.ui-slider.ui-state-disabled .ui-slider-handle,.ui-slider.ui-state-disabled .ui-slider-range{filter:inherit}.ui-slider-horizontal{height:.8em}.ui-slider-horizontal .ui-slider-handle{top:-.3em;margin-left:-.6em}.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.ui-slider-horizontal .ui-slider-range-min{left:0}.ui-slider-horizontal .ui-slider-range-max{right:0}.ui-slider-vertical{width:.8em;height:100px}.ui-slider-vertical .ui-slider-handle{left:-.3em;margin-left:0;margin-bottom:-.6em}.ui-slider-vertical .ui-slider-range{left:0;width:100%}.ui-slider-vertical .ui-slider-range-min{bottom:0}.ui-slider-vertical .ui-slider-range-max{top:0}.ui-spinner{position:relative;display:inline-block;overflow:hidden;padding:0;vertical-align:middle}.ui-spinner-input{border:none;background:none;color:inherit;padding:0;margin:.2em 0;vertical-align:middle;margin-left:.4em;margin-right:22px}.ui-spinner-button{width:16px;height:50%;font-size:.5em;padding:0;margin:0;text-align:center;position:absolute;cursor:default;display:block;overflow:hidden;right:0}.ui-spinner a.ui-spinner-button{border-top:none;border-bottom:none;border-right:none}.ui-spinner .ui-icon{position:absolute;margin-top:-8px;top:50%;left:0}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-spinner .ui-icon-triangle-1-s{background-position:-65px -16px}.ui-tabs{position:relative;padding:.2em}.ui-tabs .ui-tabs-nav{margin:0;padding:.2em .2em 0}.ui-tabs .ui-tabs-nav li{list-style:none;float:left;position:relative;top:0;margin:1px .2em 0 0;border-bottom:0;padding:0;white-space:nowrap}.ui-tabs .ui-tabs-nav li a{float:left;padding:.5em 1em;text-decoration:none}.ui-tabs .ui-tabs-nav li.ui-tabs-active{margin-bottom:-1px;padding-bottom:1px}.ui-tabs .ui-tabs-nav li.ui-tabs-active a,.ui-tabs .ui-tabs-nav li.ui-state-disabled a,.ui-tabs .ui-tabs-nav li.ui-tabs-loading a{cursor:text}.ui-tabs .ui-tabs-nav li a,.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a{cursor:pointer}.ui-tabs .ui-tabs-panel{display:block;border-width:0;padding:1em 1.4em;background:none}.ui-tooltip{padding:8px;position:absolute;z-index:9999;max-width:300px;-webkit-box-shadow:0 0 5px #aaa;box-shadow:0 0 5px #aaa}body .ui-tooltip{border-width:2px}.ui-widget{font-family:Verdana,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Verdana,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #aaa;background:#fff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x;color:#222}.ui-widget-content a{color:#222}.ui-widget-header{border:1px solid #aaa;background:#ccc url(images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x;color:#222;font-weight:bold}.ui-widget-header a{color:#222}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #d3d3d3;background:#e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#555}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#555;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #999;background:#dadada url(images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited{color:#212121;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #aaa;background:#fff url(images/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#212121;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #fcefa1;background:#fbf9ee url(images/ui-bg_glass_55_fbf9ee_1x400.png) 50% 50% repeat-x;color:#363636}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#363636}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #cd0a0a;background:#fef1ec url(images/ui-bg_glass_95_fef1ec_1x400.png) 50% 50% repeat-x;color:#cd0a0a}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#cd0a0a}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#cd0a0a}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px;background-position:16px 16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-widget-header .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-state-default .ui-icon{background-image:url(images/ui-icons_333333_256x240.png)}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-active .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-highlight .ui-icon{background-image:url(images/ui-icons_2e83ff_256x240.png)}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url(images/ui-icons_cd0a0a_256x240.png)}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:4px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:4px}.ui-widget-overlay{background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{margin:-8px 0 0 -8px;padding:8px;background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30);border-radius:8px} \ No newline at end of file +* Copyright (c) 2013 jQuery Foundation and other contributors Licensed MIT */.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{min-height:0}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-resizable{position:relative}.ui-resizable-handle{position:absolute;font-size:0.1px;display:block}.ui-resizable-disabled .ui-resizable-handle,.ui-resizable-autohide .ui-resizable-handle{display:none}.ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}.ui-selectable-helper{position:absolute;z-index:100;border:1px dotted black}.ui-accordion .ui-accordion-header{display:block;cursor:pointer;position:relative;margin-top:2px;padding:.5em .5em .5em .7em;min-height:0}.ui-accordion .ui-accordion-icons{padding-left:2.2em}.ui-accordion .ui-accordion-noicons{padding-left:.7em}.ui-accordion .ui-accordion-icons .ui-accordion-icons{padding-left:2.2em}.ui-accordion .ui-accordion-header .ui-accordion-header-icon{position:absolute;left:.5em;top:50%;margin-top:-8px}.ui-accordion .ui-accordion-content{padding:1em 2.2em;border-top:0;overflow:auto}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-button{display:inline-block;position:relative;padding:0;line-height:normal;margin-right:.1em;cursor:pointer;vertical-align:middle;text-align:center;overflow:visible}.ui-button,.ui-button:link,.ui-button:visited,.ui-button:hover,.ui-button:active{text-decoration:none}.ui-button-icon-only{width:2.2em}button.ui-button-icon-only{width:2.4em}.ui-button-icons-only{width:3.4em}button.ui-button-icons-only{width:3.7em}.ui-button .ui-button-text{display:block;line-height:normal}.ui-button-text-only .ui-button-text{padding:.4em 1em}.ui-button-icon-only .ui-button-text,.ui-button-icons-only .ui-button-text{padding:.4em;text-indent:-9999999px}.ui-button-text-icon-primary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 1em .4em 2.1em}.ui-button-text-icon-secondary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 2.1em .4em 1em}.ui-button-text-icons .ui-button-text{padding-left:2.1em;padding-right:2.1em}input.ui-button{padding:.4em 1em}.ui-button-icon-only .ui-icon,.ui-button-text-icon-primary .ui-icon,.ui-button-text-icon-secondary .ui-icon,.ui-button-text-icons .ui-icon,.ui-button-icons-only .ui-icon{position:absolute;top:50%;margin-top:-8px}.ui-button-icon-only .ui-icon{left:50%;margin-left:-8px}.ui-button-text-icon-primary .ui-button-icon-primary,.ui-button-text-icons .ui-button-icon-primary,.ui-button-icons-only .ui-button-icon-primary{left:.5em}.ui-button-text-icon-secondary .ui-button-icon-secondary,.ui-button-text-icons .ui-button-icon-secondary,.ui-button-icons-only .ui-button-icon-secondary{right:.5em}.ui-buttonset{margin-right:7px}.ui-buttonset .ui-button{margin-left:0;margin-right:-.3em}input.ui-button::-moz-focus-inner,button.ui-button::-moz-focus-inner{border:0;padding:0}.ui-datepicker{width:17em;padding:.2em .2em 0;display:none}.ui-datepicker .ui-datepicker-header{position:relative;padding:.2em 0}.ui-datepicker .ui-datepicker-prev,.ui-datepicker .ui-datepicker-next{position:absolute;top:2px;width:1.8em;height:1.8em}.ui-datepicker .ui-datepicker-prev-hover,.ui-datepicker .ui-datepicker-next-hover{top:1px}.ui-datepicker .ui-datepicker-prev{left:2px}.ui-datepicker .ui-datepicker-next{right:2px}.ui-datepicker .ui-datepicker-prev-hover{left:1px}.ui-datepicker .ui-datepicker-next-hover{right:1px}.ui-datepicker .ui-datepicker-prev span,.ui-datepicker .ui-datepicker-next span{display:block;position:absolute;left:50%;margin-left:-8px;top:50%;margin-top:-8px}.ui-datepicker .ui-datepicker-title{margin:0 2.3em;line-height:1.8em;text-align:center}.ui-datepicker .ui-datepicker-title select{font-size:1em;margin:1px 0}.ui-datepicker select.ui-datepicker-month-year{width:100%}.ui-datepicker select.ui-datepicker-month,.ui-datepicker select.ui-datepicker-year{width:49%}.ui-datepicker table{width:100%;font-size:.9em;border-collapse:collapse;margin:0 0 .4em}.ui-datepicker th{padding:.7em .3em;text-align:center;font-weight:bold;border:0}.ui-datepicker td{border:0;padding:1px}.ui-datepicker td span,.ui-datepicker td a{display:block;padding:.2em;text-align:right;text-decoration:none}.ui-datepicker .ui-datepicker-buttonpane{background-image:none;margin:.7em 0 0 0;padding:0 .2em;border-left:0;border-right:0;border-bottom:0}.ui-datepicker .ui-datepicker-buttonpane button{float:right;margin:.5em .2em .4em;cursor:pointer;padding:.2em .6em .3em .6em;width:auto;overflow:visible}.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current{float:left}.ui-datepicker.ui-datepicker-multi{width:auto}.ui-datepicker-multi .ui-datepicker-group{float:left}.ui-datepicker-multi .ui-datepicker-group table{width:95%;margin:0 auto .4em}.ui-datepicker-multi-2 .ui-datepicker-group{width:50%}.ui-datepicker-multi-3 .ui-datepicker-group{width:33.3%}.ui-datepicker-multi-4 .ui-datepicker-group{width:25%}.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header{border-left-width:0}.ui-datepicker-multi .ui-datepicker-buttonpane{clear:left}.ui-datepicker-row-break{clear:both;width:100%;font-size:0}.ui-datepicker-rtl{direction:rtl}.ui-datepicker-rtl .ui-datepicker-prev{right:2px;left:auto}.ui-datepicker-rtl .ui-datepicker-next{left:2px;right:auto}.ui-datepicker-rtl .ui-datepicker-prev:hover{right:1px;left:auto}.ui-datepicker-rtl .ui-datepicker-next:hover{left:1px;right:auto}.ui-datepicker-rtl .ui-datepicker-buttonpane{clear:right}.ui-datepicker-rtl .ui-datepicker-buttonpane button{float:left}.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current,.ui-datepicker-rtl .ui-datepicker-group{float:right}.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header{border-right-width:0;border-left-width:1px}.ui-dialog{position:absolute;top:0;left:0;padding:.2em;outline:0}.ui-dialog .ui-dialog-titlebar{padding:.4em 1em;position:relative}.ui-dialog .ui-dialog-title{float:left;margin:.1em 0;white-space:nowrap;width:90%;overflow:hidden;text-overflow:ellipsis}.ui-dialog .ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:21px;margin:-10px 0 0 0;padding:1px;height:20px}.ui-dialog .ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:none;overflow:auto}.ui-dialog .ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin-top:.5em;padding:.3em 1em .5em .4em}.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{float:right}.ui-dialog .ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.ui-dialog .ui-resizable-se{width:12px;height:12px;right:-5px;bottom:-5px;background-position:16px 16px}.ui-draggable .ui-dialog-titlebar{cursor:move}.ui-menu{list-style:none;padding:2px;margin:0;display:block;outline:none}.ui-menu .ui-menu{margin-top:-3px;position:absolute}.ui-menu .ui-menu-item{margin:0;padding:0;width:100%}.ui-menu .ui-menu-divider{margin:5px -2px 5px -2px;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-menu-item a{text-decoration:none;display:block;padding:2px .4em;line-height:1.5;min-height:0;font-weight:normal}.ui-menu .ui-menu-item a.ui-state-focus,.ui-menu .ui-menu-item a.ui-state-active{font-weight:normal;margin:-1px}.ui-menu .ui-state-disabled{font-weight:normal;margin:.4em 0 .2em;line-height:1.5}.ui-menu .ui-state-disabled a{cursor:default}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item a{position:relative;padding-left:2em}.ui-menu .ui-icon{position:absolute;top:.2em;left:.2em}.ui-menu .ui-menu-icon{position:static;float:right}.ui-progressbar{height:2em;text-align:left;overflow:hidden}.ui-progressbar .ui-progressbar-value{margin:-1px;height:100%}.ui-progressbar .ui-progressbar-overlay{background:url("images/animated-overlay.gif");height:100%;filter:alpha(opacity=25);opacity:0.25}.ui-progressbar-indeterminate .ui-progressbar-value{background-image:none}.ui-slider{position:relative;text-align:left}.ui-slider .ui-slider-handle{position:absolute;z-index:2;width:1.2em;height:1.2em;cursor:default}.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background-position:0 0}.ui-slider.ui-state-disabled .ui-slider-handle,.ui-slider.ui-state-disabled .ui-slider-range{filter:inherit}.ui-slider-horizontal{height:.8em}.ui-slider-horizontal .ui-slider-handle{top:-.3em;margin-left:-.6em}.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.ui-slider-horizontal .ui-slider-range-min{left:0}.ui-slider-horizontal .ui-slider-range-max{right:0}.ui-slider-vertical{width:.8em;height:100px}.ui-slider-vertical .ui-slider-handle{left:-.3em;margin-left:0;margin-bottom:-.6em}.ui-slider-vertical .ui-slider-range{left:0;width:100%}.ui-slider-vertical .ui-slider-range-min{bottom:0}.ui-slider-vertical .ui-slider-range-max{top:0}.ui-spinner{position:relative;display:inline-block;overflow:hidden;padding:0;vertical-align:middle}.ui-spinner-input{border:none;background:none;color:inherit;padding:0;margin:.2em 0;vertical-align:middle;margin-left:.4em;margin-right:22px}.ui-spinner-button{width:16px;height:50%;font-size:.5em;padding:0;margin:0;text-align:center;position:absolute;cursor:default;display:block;overflow:hidden;right:0}.ui-spinner a.ui-spinner-button{border-top:none;border-bottom:none;border-right:none}.ui-spinner .ui-icon{position:absolute;margin-top:-8px;top:50%;left:0}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-spinner .ui-icon-triangle-1-s{background-position:-65px -16px}.ui-tabs{position:relative;padding:.2em}.ui-tabs .ui-tabs-nav{margin:0;padding:.2em .2em 0}.ui-tabs .ui-tabs-nav li{list-style:none;float:left;position:relative;top:0;margin:1px .2em 0 0;border-bottom:0;padding:0;white-space:nowrap}.ui-tabs .ui-tabs-nav li a{float:left;padding:.5em 1em;text-decoration:none}.ui-tabs .ui-tabs-nav li.ui-tabs-active{margin-bottom:-1px;padding-bottom:1px}.ui-tabs .ui-tabs-nav li.ui-tabs-active a,.ui-tabs .ui-tabs-nav li.ui-state-disabled a,.ui-tabs .ui-tabs-nav li.ui-tabs-loading a{cursor:text}.ui-tabs .ui-tabs-nav li a,.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a{cursor:pointer}.ui-tabs .ui-tabs-panel{display:block;border-width:0;padding:1em 1.4em;background:none}.ui-tooltip{padding:8px;position:absolute;z-index:9999;max-width:300px;-webkit-box-shadow:0 0 5px #aaa;box-shadow:0 0 5px #aaa}body .ui-tooltip{border-width:2px}.ui-widget{font-family:Verdana,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Verdana,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #aaa;background:#fff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x;color:#222}.ui-widget-content a{color:#222}.ui-widget-header{border:1px solid #aaa;background:#ccc url(images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x;color:#222;font-weight:bold}.ui-widget-header a{color:#222}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #d3d3d3;background:#e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#555}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#555;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #999;background:#dadada url(images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited{color:#212121;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #aaa;background:#fff url(images/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#212121;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #fcefa1;background:#fbf9ee url(images/ui-bg_glass_55_fbf9ee_1x400.png) 50% 50% repeat-x;color:#363636}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#363636}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #cd0a0a;background:#fef1ec url(images/ui-bg_glass_95_fef1ec_1x400.png) 50% 50% repeat-x;color:#cd0a0a}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#cd0a0a}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#cd0a0a}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px;background-position:16px 16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-widget-header .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-state-default .ui-icon{background-image:url(images/ui-icons_333333_256x240.png)}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-active .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-highlight .ui-icon{background-image:url(images/ui-icons_2e83ff_256x240.png)}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url(images/ui-icons_cd0a0a_256x240.png)}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:4px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:4px}.ui-widget-overlay{background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{margin:-8px 0 0 -8px;padding:8px;background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30);border-radius:8px} + +/* Extra custom CSS */ +.ui-datepicker {width: 18em;} \ No newline at end of file diff --git a/assets/grocery_crud/index.html b/assets/grocery_crud/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/index.html +++ b/assets/grocery_crud/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/js/common/lazyload-min.js b/assets/grocery_crud/js/common/lazyload-min.js old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/js/common/list.js b/assets/grocery_crud/js/common/list.js old mode 100755 new mode 100644 index 1ced06e..ebd9023 --- a/assets/grocery_crud/js/common/list.js +++ b/assets/grocery_crud/js/common/list.js @@ -1,80 +1,82 @@ var js_libraries = []; -var fnOpenEditForm = function (this_element) { - - var href_url = this_element.attr("href"); - - var dialog_height = $(window).height() - 80; - - //Close all - $(".ui-dialog-content").dialog("close"); - - $.ajax({ - url: href_url, - data: { - is_ajax: 'true' - }, - type: 'post', - dataType: 'json', - beforeSend: function () { - this_element.closest('.flexigrid').addClass('loading-opacity'); - }, - complete: function () { - this_element.closest('.flexigrid').removeClass('loading-opacity'); - }, - success: function (data) { - if (typeof CKEDITOR !== 'undefined' && typeof CKEDITOR.instances !== 'undefined') { - $.each(CKEDITOR.instances, function (index) { - delete CKEDITOR.instances[index]; - }); - } - - LazyLoad.loadOnce(data.js_lib_files); - LazyLoad.load(data.js_config_files); - - $.each(data.css_files, function (index, css_file) { - load_css_file(css_file); - }); - - $("
    ").html(data.output).dialog({ - width: 910, - modal: true, - height: dialog_height, - close: function () { - $(this).remove(); - }, - open: function () { - var this_dialog = $(this); - - $('#cancel-button').click(function () { - this_dialog.dialog("close"); - }); - - } - }); - } - }); +var fnOpenEditForm = function(this_element){ + + var href_url = this_element.attr("href"); + + var dialog_height = $(window).height() - 80; + + //Close all + $(".ui-dialog-content").dialog("close"); + + $.ajax({ + url: href_url, + data: { + is_ajax: 'true' + }, + type: 'post', + dataType: 'json', + beforeSend: function() { + this_element.closest('.flexigrid').addClass('loading-opacity'); + this_element.closest('.dataTablesContainer').addClass('loading-opacity'); + }, + complete: function(){ + this_element.closest('.flexigrid').removeClass('loading-opacity'); + this_element.closest('.dataTablesContainer').removeClass('loading-opacity'); + }, + success: function (data) { + if (typeof CKEDITOR !== 'undefined' && typeof CKEDITOR.instances !== 'undefined') { + $.each(CKEDITOR.instances,function(index){ + delete CKEDITOR.instances[index]; + }); + } + + LazyLoad.loadOnce(data.js_lib_files); + LazyLoad.load(data.js_config_files); + + $.each(data.css_files,function(index,css_file){ + load_css_file(css_file); + }); + + $("
    ").html(data.output).dialog({ + width: 910, + modal: true, + height: dialog_height, + close: function(){ + $(this).remove(); + }, + open: function(){ + var this_dialog = $(this); + + $('#cancel-button').click(function(){ + this_dialog.dialog("close"); + }); + + } + }); + } + }); }; var add_edit_button_listener = function () { - //If dialog AJAX forms is turned on from grocery CRUD config - if (dialog_forms) { + //If dialog AJAX forms is turned on from grocery CRUD config + if (dialog_forms) { - $('.edit_button,.add_button').unbind('click'); - $('.edit_button,.add_button').click(function () { + $('.edit_button,.add_button').unbind('click'); + $('.edit_button,.add_button').click(function(){ - fnOpenEditForm($(this)); + fnOpenEditForm($(this)); - return false; - }); + return false; + }); - } + } } -var load_css_file = function (css_file) { - if ($('head').find('link[href="' + css_file + '"]').length == 0) { - $('head').append($('').attr("type", "text/css") - .attr("rel", "stylesheet").attr("href", css_file)); - } +var load_css_file = function(css_file) { + if ($('head').find('link[href="'+css_file+'"]').length == 0) { + $('head').append($('').attr("type","text/css") + .attr("rel","stylesheet").attr("href",css_file)); + } }; diff --git a/assets/grocery_crud/js/index.html b/assets/grocery_crud/js/index.html old mode 100755 new mode 100644 index 04e928c..c942a79 --- a/assets/grocery_crud/js/index.html +++ b/assets/grocery_crud/js/index.html @@ -1,6 +1,6 @@ - 403 Forbidden + 403 Forbidden diff --git a/assets/grocery_crud/js/jquery-1.10.2.min.js b/assets/grocery_crud/js/jquery-1.10.2.min.js deleted file mode 100755 index cdcd81e..0000000 --- a/assets/grocery_crud/js/jquery-1.10.2.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license -//@ sourceMappingURL=jquery-1.10.2.min.map -*/ -(function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.2",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("onload",q))};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,n,r){var i,o;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof x?n[0]:n,x.merge(this,x.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:a,!0)),k.test(i[1])&&x.isPlainObject(n))for(i in n)x.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(o=a.getElementById(i[2]),o&&o.parentNode){if(o.id!==i[2])return r.find(e);this.length=1,this[0]=o}return this.context=a,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return g.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(g.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},l=2),"object"==typeof s||x.isFunction(s)||(s={}),u===l&&(s=this,--l);u>l;l++)if(null!=(o=arguments[l]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(x.isPlainObject(r)||(n=x.isArray(r)))?(n?(n=!1,a=e&&x.isArray(e)?e:[]):a=e&&x.isPlainObject(e)?e:{},s[i]=x.extend(c,a,r)):r!==t&&(s[i]=r));return s},x.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=l),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){if(e===!0?!--x.readyWait:!x.isReady){if(!a.body)return setTimeout(x.ready);x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(a,[x]),x.fn.trigger&&x(a).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray||function(e){return"array"===x.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?c[y.call(e)]||"object":typeof e},isPlainObject:function(e){var n;if(!e||"object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!v.call(e,"constructor")&&!v.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(r){return!1}if(x.support.ownLast)for(n in e)return v.call(e,n);for(n in e);return n===t||v.call(e,n)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||a;var r=k.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=x.trim(n),n&&E.test(n.replace(A,"@").replace(j,"]").replace(S,"")))?Function("return "+n)():(x.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||x.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&x.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(D,"ms-").replace(L,H)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:b&&!b.call("\ufeff\u00a0")?function(e){return null==e?"":b.call(e)}:function(e){return null==e?"":(e+"").replace(C,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(m)return m.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return d.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),x.isFunction(e)?(r=g.call(arguments,2),i=function(){return e.apply(n||this,r.concat(g.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):t},access:function(e,n,r,i,o,a,s){var l=0,u=e.length,c=null==r;if("object"===x.type(r)){o=!0;for(l in r)x.access(e,n,l,r[l],!0,a,s)}else if(i!==t&&(o=!0,x.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(x(e),n)})),n))for(;u>l;l++)n(e[l],r,s?i:i.call(e[l],l,n(e[l],r)));return o?e:c?n.call(e):u?n(e[0],r):a},now:function(){return(new Date).getTime()},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),x.ready.promise=function(t){if(!n)if(n=x.Deferred(),"complete"===a.readyState)setTimeout(x.ready);else if(a.addEventListener)a.addEventListener("DOMContentLoaded",q,!1),e.addEventListener("load",q,!1);else{a.attachEvent("onreadystatechange",q),e.attachEvent("onload",q);var r=!1;try{r=null==e.frameElement&&a.documentElement}catch(i){}r&&r.doScroll&&function o(){if(!x.isReady){try{r.doScroll("left")}catch(e){return setTimeout(o,50)}_(),x.ready()}}()}return n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){c["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=x(a),function(e,t){var n,r,i,o,a,s,l,u,c,p,f,d,h,g,m,y,v,b="sizzle"+-new Date,w=e.document,T=0,C=0,N=st(),k=st(),E=st(),S=!1,A=function(e,t){return e===t?(S=!0,0):0},j=typeof t,D=1<<31,L={}.hasOwnProperty,H=[],q=H.pop,_=H.push,M=H.push,O=H.slice,F=H.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},B="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",P="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",W=R.replace("w","w#"),$="\\["+P+"*("+R+")"+P+"*(?:([*^$|!~]?=)"+P+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+W+")|)|)"+P+"*\\]",I=":("+R+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+$.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+P+"+|((?:^|[^\\\\])(?:\\\\.)*)"+P+"+$","g"),X=RegExp("^"+P+"*,"+P+"*"),U=RegExp("^"+P+"*([>+~]|"+P+")"+P+"*"),V=RegExp(P+"*[+~]"),Y=RegExp("="+P+"*([^\\]'\"]*)"+P+"*\\]","g"),J=RegExp(I),G=RegExp("^"+W+"$"),Q={ID:RegExp("^#("+R+")"),CLASS:RegExp("^\\.("+R+")"),TAG:RegExp("^("+R.replace("w","w*")+")"),ATTR:RegExp("^"+$),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+P+"*(even|odd|(([+-]|)(\\d*)n|)"+P+"*(?:([+-]|)"+P+"*(\\d+)|))"+P+"*\\)|)","i"),bool:RegExp("^(?:"+B+")$","i"),needsContext:RegExp("^"+P+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+P+"*((?:-\\d)?\\d*)"+P+"*\\)|)(?=[^-]|$)","i")},K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,et=/^(?:input|select|textarea|button)$/i,tt=/^h\d$/i,nt=/'|\\/g,rt=RegExp("\\\\([\\da-f]{1,6}"+P+"?|("+P+")|.)","ig"),it=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{M.apply(H=O.call(w.childNodes),w.childNodes),H[w.childNodes.length].nodeType}catch(ot){M={apply:H.length?function(e,t){_.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function at(e,t,n,i){var o,a,s,l,u,c,d,m,y,x;if((t?t.ownerDocument||t:w)!==f&&p(t),t=t||f,n=n||[],!e||"string"!=typeof e)return n;if(1!==(l=t.nodeType)&&9!==l)return[];if(h&&!i){if(o=Z.exec(e))if(s=o[1]){if(9===l){if(a=t.getElementById(s),!a||!a.parentNode)return n;if(a.id===s)return n.push(a),n}else if(t.ownerDocument&&(a=t.ownerDocument.getElementById(s))&&v(t,a)&&a.id===s)return n.push(a),n}else{if(o[2])return M.apply(n,t.getElementsByTagName(e)),n;if((s=o[3])&&r.getElementsByClassName&&t.getElementsByClassName)return M.apply(n,t.getElementsByClassName(s)),n}if(r.qsa&&(!g||!g.test(e))){if(m=d=b,y=t,x=9===l&&e,1===l&&"object"!==t.nodeName.toLowerCase()){c=mt(e),(d=t.getAttribute("id"))?m=d.replace(nt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",u=c.length;while(u--)c[u]=m+yt(c[u]);y=V.test(e)&&t.parentNode||t,x=c.join(",")}if(x)try{return M.apply(n,y.querySelectorAll(x)),n}catch(T){}finally{d||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,n,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>o.cacheLength&&delete t[e.shift()],t[n]=r}return t}function lt(e){return e[b]=!0,e}function ut(e){var t=f.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function ct(e,t){var n=e.split("|"),r=e.length;while(r--)o.attrHandle[n[r]]=t}function pt(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function dt(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return lt(function(t){return t=+t,lt(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}s=at.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},r=at.support={},p=at.setDocument=function(e){var n=e?e.ownerDocument||e:w,i=n.defaultView;return n!==f&&9===n.nodeType&&n.documentElement?(f=n,d=n.documentElement,h=!s(n),i&&i.attachEvent&&i!==i.top&&i.attachEvent("onbeforeunload",function(){p()}),r.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),r.getElementsByTagName=ut(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),r.getElementsByClassName=ut(function(e){return e.innerHTML="
    ",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),r.getById=ut(function(e){return d.appendChild(e).id=b,!n.getElementsByName||!n.getElementsByName(b).length}),r.getById?(o.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){return e.getAttribute("id")===t}}):(delete o.find.ID,o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),o.find.TAG=r.getElementsByTagName?function(e,n){return typeof n.getElementsByTagName!==j?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},o.find.CLASS=r.getElementsByClassName&&function(e,n){return typeof n.getElementsByClassName!==j&&h?n.getElementsByClassName(e):t},m=[],g=[],(r.qsa=K.test(n.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||g.push("\\["+P+"*(?:value|"+B+")"),e.querySelectorAll(":checked").length||g.push(":checked")}),ut(function(e){var t=n.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&g.push("[*^$]="+P+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||g.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),g.push(",.*:")})),(r.matchesSelector=K.test(y=d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.msMatchesSelector))&&ut(function(e){r.disconnectedMatch=y.call(e,"div"),y.call(e,"[s!='']:x"),m.push("!=",I)}),g=g.length&&RegExp(g.join("|")),m=m.length&&RegExp(m.join("|")),v=K.test(d.contains)||d.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},A=d.compareDocumentPosition?function(e,t){if(e===t)return S=!0,0;var i=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t);return i?1&i||!r.sortDetached&&t.compareDocumentPosition(e)===i?e===n||v(w,e)?-1:t===n||v(w,t)?1:c?F.call(c,e)-F.call(c,t):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return S=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:c?F.call(c,e)-F.call(c,t):0;if(o===a)return pt(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?pt(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},n):f},at.matches=function(e,t){return at(e,null,null,t)},at.matchesSelector=function(e,t){if((e.ownerDocument||e)!==f&&p(e),t=t.replace(Y,"='$1']"),!(!r.matchesSelector||!h||m&&m.test(t)||g&&g.test(t)))try{var n=y.call(e,t);if(n||r.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(i){}return at(t,f,null,[e]).length>0},at.contains=function(e,t){return(e.ownerDocument||e)!==f&&p(e),v(e,t)},at.attr=function(e,n){(e.ownerDocument||e)!==f&&p(e);var i=o.attrHandle[n.toLowerCase()],a=i&&L.call(o.attrHandle,n.toLowerCase())?i(e,n,!h):t;return a===t?r.attributes||!h?e.getAttribute(n):(a=e.getAttributeNode(n))&&a.specified?a.value:null:a},at.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},at.uniqueSort=function(e){var t,n=[],i=0,o=0;if(S=!r.detectDuplicates,c=!r.sortStable&&e.slice(0),e.sort(A),S){while(t=e[o++])t===e[o]&&(i=n.push(o));while(i--)e.splice(n[i],1)}return e},a=at.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=a(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=a(t);return n},o=at.selectors={cacheLength:50,createPseudo:lt,match:Q,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(rt,it),e[3]=(e[4]||e[5]||"").replace(rt,it),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||at.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&at.error(e[0]),e},PSEUDO:function(e){var n,r=!e[5]&&e[2];return Q.CHILD.test(e[0])?null:(e[3]&&e[4]!==t?e[2]=e[4]:r&&J.test(r)&&(n=mt(r,!0))&&(n=r.indexOf(")",r.length-n)-r.length)&&(e[0]=e[0].slice(0,n),e[2]=r.slice(0,n)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(rt,it).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=N[e+" "];return t||(t=RegExp("(^|"+P+")"+e+"("+P+"|$)"))&&N(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=at.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[b]||(m[b]={}),u=c[e]||[],d=u[0]===T&&u[1],f=u[0]===T&&u[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[T,d,f];break}}else if(v&&(u=(t[b]||(t[b]={}))[e])&&u[0]===T)f=u[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[b]||(p[b]={}))[e]=[T,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=o.pseudos[e]||o.setFilters[e.toLowerCase()]||at.error("unsupported pseudo: "+e);return r[b]?r(t):r.length>1?(n=[e,e,"",t],o.setFilters.hasOwnProperty(e.toLowerCase())?lt(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=F.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:lt(function(e){var t=[],n=[],r=l(e.replace(z,"$1"));return r[b]?lt(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:lt(function(e){return function(t){return at(e,t).length>0}}),contains:lt(function(e){return function(t){return(t.textContent||t.innerText||a(t)).indexOf(e)>-1}}),lang:lt(function(e){return G.test(e||"")||at.error("unsupported lang: "+e),e=e.replace(rt,it).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===d},focus:function(e){return e===f.activeElement&&(!f.hasFocus||f.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!o.pseudos.empty(e)},header:function(e){return tt.test(e.nodeName)},input:function(e){return et.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},o.pseudos.nth=o.pseudos.eq;for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})o.pseudos[n]=ft(n);for(n in{submit:!0,reset:!0})o.pseudos[n]=dt(n);function gt(){}gt.prototype=o.filters=o.pseudos,o.setFilters=new gt;function mt(e,t){var n,r,i,a,s,l,u,c=k[e+" "];if(c)return t?0:c.slice(0);s=e,l=[],u=o.preFilter;while(s){(!n||(r=X.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),l.push(i=[])),n=!1,(r=U.exec(s))&&(n=r.shift(),i.push({value:n,type:r[0].replace(z," ")}),s=s.slice(n.length));for(a in o.filter)!(r=Q[a].exec(s))||u[a]&&!(r=u[a](r))||(n=r.shift(),i.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?at.error(e):k(e,l).slice(0)}function yt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function vt(e,t,n){var r=t.dir,o=n&&"parentNode"===r,a=C++;return t.first?function(t,n,i){while(t=t[r])if(1===t.nodeType||o)return e(t,n,i)}:function(t,n,s){var l,u,c,p=T+" "+a;if(s){while(t=t[r])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[r])if(1===t.nodeType||o)if(c=t[b]||(t[b]={}),(u=c[r])&&u[0]===p){if((l=u[1])===!0||l===i)return l===!0}else if(u=c[r]=[p],u[1]=e(t,n,s)||i,u[1]===!0)return!0}}function bt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,a=[],s=0,l=e.length,u=null!=t;for(;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function wt(e,t,n,r,i,o){return r&&!r[b]&&(r=wt(r)),i&&!i[b]&&(i=wt(i,o)),lt(function(o,a,s,l){var u,c,p,f=[],d=[],h=a.length,g=o||Nt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:xt(g,f,e,s,l),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,l),r){u=xt(y,d),r(u,[],s,l),c=u.length;while(c--)(p=u[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){u=[],c=y.length;while(c--)(p=y[c])&&u.push(m[c]=p);i(null,y=[],u,l)}c=y.length;while(c--)(p=y[c])&&(u=i?F.call(o,p):f[c])>-1&&(o[u]=!(a[u]=p))}}else y=xt(y===a?y.splice(h,y.length):y),i?i(null,a,y,l):M.apply(a,y)})}function Tt(e){var t,n,r,i=e.length,a=o.relative[e[0].type],s=a||o.relative[" "],l=a?1:0,c=vt(function(e){return e===t},s,!0),p=vt(function(e){return F.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;i>l;l++)if(n=o.relative[e[l].type])f=[vt(bt(f),n)];else{if(n=o.filter[e[l].type].apply(null,e[l].matches),n[b]){for(r=++l;i>r;r++)if(o.relative[e[r].type])break;return wt(l>1&&bt(f),l>1&&yt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&Tt(e.slice(l,r)),i>r&&Tt(e=e.slice(r)),i>r&&yt(e))}f.push(n)}return bt(f)}function Ct(e,t){var n=0,r=t.length>0,a=e.length>0,s=function(s,l,c,p,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,C=u,N=s||a&&o.find.TAG("*",d&&l.parentNode||l),k=T+=null==C?1:Math.random()||.1;for(w&&(u=l!==f&&l,i=n);null!=(h=N[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,l,c)){p.push(h);break}w&&(T=k,i=++n)}r&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,r&&b!==v){g=0;while(m=t[g++])m(x,y,l,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=q.call(p));y=xt(y)}M.apply(p,y),w&&!s&&y.length>0&&v+t.length>1&&at.uniqueSort(p)}return w&&(T=k,u=C),x};return r?lt(s):s}l=at.compile=function(e,t){var n,r=[],i=[],o=E[e+" "];if(!o){t||(t=mt(e)),n=t.length;while(n--)o=Tt(t[n]),o[b]?r.push(o):i.push(o);o=E(e,Ct(i,r))}return o};function Nt(e,t,n){var r=0,i=t.length;for(;i>r;r++)at(e,t[r],n);return n}function kt(e,t,n,i){var a,s,u,c,p,f=mt(e);if(!i&&1===f.length){if(s=f[0]=f[0].slice(0),s.length>2&&"ID"===(u=s[0]).type&&r.getById&&9===t.nodeType&&h&&o.relative[s[1].type]){if(t=(o.find.ID(u.matches[0].replace(rt,it),t)||[])[0],!t)return n;e=e.slice(s.shift().value.length)}a=Q.needsContext.test(e)?0:s.length;while(a--){if(u=s[a],o.relative[c=u.type])break;if((p=o.find[c])&&(i=p(u.matches[0].replace(rt,it),V.test(s[0].type)&&t.parentNode||t))){if(s.splice(a,1),e=i.length&&yt(s),!e)return M.apply(n,i),n;break}}}return l(e,f)(i,t,!h,n,V.test(e)),n}r.sortStable=b.split("").sort(A).join("")===b,r.detectDuplicates=S,p(),r.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(f.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||ct("type|href|height|width",function(e,n,r){return r?t:e.getAttribute(n,"type"===n.toLowerCase()?1:2)}),r.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||ct("value",function(e,n,r){return r||"input"!==e.nodeName.toLowerCase()?t:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||ct(B,function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&i.specified?i.value:e[n]===!0?n.toLowerCase():null}),x.find=at,x.expr=at.selectors,x.expr[":"]=x.expr.pseudos,x.unique=at.uniqueSort,x.text=at.getText,x.isXMLDoc=at.isXML,x.contains=at.contains}(e);var O={};function F(e){var t=O[e]={};return x.each(e.match(T)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?O[e]||F(e):x.extend({},e);var n,r,i,o,a,s,l=[],u=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=l.length,n=!0;l&&o>a;a++)if(l[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,l&&(u?u.length&&c(u.shift()):r?l=[]:p.disable())},p={add:function(){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this},remove:function(){return l&&x.each(arguments,function(e,t){var r;while((r=x.inArray(t,l,r))>-1)l.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?x.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=r=t,this},disabled:function(){return!l},lock:function(){return u=t,r||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!l||i&&!u||(t=t||[],t=[e,t.slice?t.slice():t],n?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var a=o[0],s=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=g.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?g.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,l,u;if(r>1)for(s=Array(r),l=Array(r),u=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(a(t,u,n)).fail(o.reject).progress(a(t,l,s)):--i;return i||o.resolveWith(u,n),o.promise()}}),x.support=function(t){var n,r,o,s,l,u,c,p,f,d=a.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="
    a",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="
    t
    ",o=d.getElementsByTagName("td"),o[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===o[0].offsetHeight,o[0].style.display="",o[1].style.display="none",t.reliableHiddenOffsets=p&&0===o[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",x.swap(l,null!=l.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===d.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(a.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
    ",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(l.style.zoom=1)),l.removeChild(n),n=d=o=r=null)}),n=s=l=u=r=o=null,t -}({});var B=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;function R(e,n,r,i){if(x.acceptData(e)){var o,a,s=x.expando,l=e.nodeType,u=l?x.cache:e,c=l?e[s]:e[s]&&s;if(c&&u[c]&&(i||u[c].data)||r!==t||"string"!=typeof n)return c||(c=l?e[s]=p.pop()||x.guid++:s),u[c]||(u[c]=l?{}:{toJSON:x.noop}),("object"==typeof n||"function"==typeof n)&&(i?u[c]=x.extend(u[c],n):u[c].data=x.extend(u[c].data,n)),a=u[c],i||(a.data||(a.data={}),a=a.data),r!==t&&(a[x.camelCase(n)]=r),"string"==typeof n?(o=a[n],null==o&&(o=a[x.camelCase(n)])):o=a,o}}function W(e,t,n){if(x.acceptData(e)){var r,i,o=e.nodeType,a=o?x.cache:e,s=o?e[x.expando]:x.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){x.isArray(t)?t=t.concat(x.map(t,x.camelCase)):t in r?t=[t]:(t=x.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;while(i--)delete r[t[i]];if(n?!I(r):!x.isEmptyObject(r))return}(n||(delete a[s].data,I(a[s])))&&(o?x.cleanData([e],!0):x.support.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}x.extend({cache:{},noData:{applet:!0,embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(e){return e=e.nodeType?x.cache[e[x.expando]]:e[x.expando],!!e&&!I(e)},data:function(e,t,n){return R(e,t,n)},removeData:function(e,t){return W(e,t)},_data:function(e,t,n){return R(e,t,n,!0)},_removeData:function(e,t){return W(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&x.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),x.fn.extend({data:function(e,n){var r,i,o=null,a=0,s=this[0];if(e===t){if(this.length&&(o=x.data(s),1===s.nodeType&&!x._data(s,"parsedAttrs"))){for(r=s.attributes;r.length>a;a++)i=r[a].name,0===i.indexOf("data-")&&(i=x.camelCase(i.slice(5)),$(s,i,o[i]));x._data(s,"parsedAttrs",!0)}return o}return"object"==typeof e?this.each(function(){x.data(this,e)}):arguments.length>1?this.each(function(){x.data(this,e,n)}):s?$(s,e,x.data(s,e)):null},removeData:function(e){return this.each(function(){x.removeData(this,e)})}});function $(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(P,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:B.test(r)?x.parseJSON(r):r}catch(o){}x.data(e,n,r)}else r=t}return r}function I(e){var t;for(t in e)if(("data"!==t||!x.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}x.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=x._data(e,n),r&&(!i||x.isArray(r)?i=x._data(e,n,x.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),a=function(){x.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return x._data(e,n)||x._data(e,n,{empty:x.Callbacks("once memory").add(function(){x._removeData(e,t+"queue"),x._removeData(e,n)})})}}),x.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?x.queue(this[0],e):n===t?this:this.each(function(){var t=x.queue(this,e,n);x._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=x.Deferred(),a=this,s=this.length,l=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=x._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(l));return l(),o.promise(n)}});var z,X,U=/[\t\r\n\f]/g,V=/\r/g,Y=/^(?:input|select|textarea|button|object)$/i,J=/^(?:a|area)$/i,G=/^(?:checked|selected)$/i,Q=x.support.getSetAttribute,K=x.support.input;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return e=x.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,l="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,l=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,r=0,o=x(this),a=e.match(T)||[];while(t=a[r++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===i||"boolean"===n)&&(this.className&&x._data(this,"__className__",this.className),this.className=this.className||e===!1?"":x._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(U," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=x.isFunction(e),this.each(function(n){var o;1===this.nodeType&&(o=i?e.call(this,n,x(this).val()):e,null==o?o="":"number"==typeof o?o+="":x.isArray(o)&&(o=x.map(o,function(e){return null==e?"":e+""})),r=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=x.valHooks[o.type]||x.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(V,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=x.find.attr(e,"value");return null!=t?t:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;for(;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),a=i.length;while(a--)r=i[a],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,n,r){var o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===i?x.prop(e,n,r):(1===s&&x.isXMLDoc(e)||(n=n.toLowerCase(),o=x.attrHooks[n]||(x.expr.match.bool.test(n)?X:z)),r===t?o&&"get"in o&&null!==(a=o.get(e,n))?a:(a=x.find.attr(e,n),null==a?t:a):null!==r?o&&"set"in o&&(a=o.set(e,r,n))!==t?a:(e.setAttribute(n,r+""),r):(x.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(T);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)?K&&Q||!G.test(n)?e[r]=!1:e[x.camelCase("default-"+n)]=e[r]=!1:x.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!x.isXMLDoc(e),a&&(n=x.propFix[n]||n,o=x.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var t=x.find.attr(e,"tabindex");return t?parseInt(t,10):Y.test(e.nodeName)||J.test(e.nodeName)&&e.href?0:-1}}}}),X={set:function(e,t,n){return t===!1?x.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&x.propFix[n]||n,n):e[x.camelCase("default-"+n)]=e[n]=!0,n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,n){var r=x.expr.attrHandle[n]||x.find.attr;x.expr.attrHandle[n]=K&&Q||!G.test(n)?function(e,n,i){var o=x.expr.attrHandle[n],a=i?t:(x.expr.attrHandle[n]=t)!=r(e,n,i)?n.toLowerCase():null;return x.expr.attrHandle[n]=o,a}:function(e,n,r){return r?t:e[x.camelCase("default-"+n)]?n.toLowerCase():null}}),K&&Q||(x.attrHooks.value={set:function(e,n,r){return x.nodeName(e,"input")?(e.defaultValue=n,t):z&&z.set(e,n,r)}}),Q||(z={set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},x.expr.attrHandle.id=x.expr.attrHandle.name=x.expr.attrHandle.coords=function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&""!==i.value?i.value:null},x.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&r.specified?r.value:t},set:z.set},x.attrHooks.contenteditable={set:function(e,t,n){z.set(e,""===t?!1:t,n)}},x.each(["width","height"],function(e,n){x.attrHooks[n]={set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}}})),x.support.hrefNormalized||x.each(["href","src"],function(e,t){x.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}}),x.support.style||(x.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.support.enctype||(x.propFix.enctype="encoding"),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,n){return x.isArray(n)?e.checked=x.inArray(x(e).val(),n)>=0:t}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}function at(){try{return a.activeElement}catch(e){}}x.event={global:{},add:function(e,n,r,o,a){var s,l,u,c,p,f,d,h,g,m,y,v=x._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=x.guid++),(l=v.events)||(l=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof x===i||e&&x.event.triggered===e.type?t:x.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(T)||[""],u=n.length;while(u--)s=rt.exec(n[u])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),g&&(p=x.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=x.event.special[g]||{},d=x.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&x.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=l[g])||(h=l[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),x.event.global[g]=!0);e=null}},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,f,d,h,g,m=x.hasData(e)&&x._data(e);if(m&&(c=m.events)){t=(t||"").match(T)||[""],u=t.length;while(u--)if(s=rt.exec(t[u])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=x.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),l=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));l&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||x.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)x.event.remove(e,d+t[u],n,r,!0);x.isEmptyObject(c)&&(delete m.handle,x._removeData(e,"events"))}},trigger:function(n,r,i,o){var s,l,u,c,p,f,d,h=[i||a],g=v.call(n,"type")?n.type:n,m=v.call(n,"namespace")?n.namespace.split("."):[];if(u=f=i=i||a,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+x.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),l=0>g.indexOf(":")&&"on"+g,n=n[x.expando]?n:new x.Event(g,"object"==typeof n&&n),n.isTrigger=o?2:3,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:x.makeArray(r,[n]),p=x.event.special[g]||{},o||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!o&&!p.noBubble&&!x.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(u=u.parentNode);u;u=u.parentNode)h.push(u),f=u;f===(i.ownerDocument||a)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((u=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(x._data(u,"events")||{})[n.type]&&x._data(u,"handle"),s&&s.apply(u,r),s=l&&u[l],s&&x.acceptData(u)&&s.apply&&s.apply(u,r)===!1&&n.preventDefault();if(n.type=g,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(h.pop(),r)===!1)&&x.acceptData(i)&&l&&i[g]&&!x.isWindow(i)){f=i[l],f&&(i[l]=null),x.event.triggered=g;try{i[g]()}catch(y){}x.event.triggered=t,f&&(i[l]=f)}return n.result}},dispatch:function(e){e=x.event.fix(e);var n,r,i,o,a,s=[],l=g.call(arguments),u=(x._data(this,"events")||{})[e.type]||[],c=x.event.special[e.type]||{};if(l[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((x.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,l),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],l=n.delegateCount,u=e.target;if(l&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!=this;u=u.parentNode||this)if(1===u.nodeType&&(u.disabled!==!0||"click"!==e.type)){for(o=[],a=0;l>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?x(r,this).index(u)>=0:x.find(r,this,null,[u]).length),o[r]&&o.push(i);o.length&&s.push({elem:u,handlers:o})}return n.length>l&&s.push({elem:this,handlers:n.slice(l)}),s},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,o=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new x.Event(o),t=r.length;while(t--)n=r[t],e[n]=o[n];return e.target||(e.target=o.srcElement||a),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,o):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,o,s=n.button,l=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||a,o=i.documentElement,r=i.body,e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&l&&(e.relatedTarget=l===e.target?n.toElement:l),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==at()&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===at()&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},click:{trigger:function(){return x.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=a.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},x.Event=function(e,n){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&x.extend(this,n),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,t):new x.Event(e,n)},x.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.submitBubbles||(x.event.special.submit={setup:function(){return x.nodeName(this,"form")?!1:(x.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=x.nodeName(n,"input")||x.nodeName(n,"button")?n.form:t;r&&!x._data(r,"submitBubbles")&&(x.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),x._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&x.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return x.nodeName(this,"form")?!1:(x.event.remove(this,"._submit"),t)}}),x.support.changeBubbles||(x.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(x.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),x.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),x.event.simulate("change",this,e,!0)})),!1):(x.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!x._data(t,"changeBubbles")&&(x.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||x.event.simulate("change",this.parentNode,e,!0)}),x._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return x.event.remove(this,"._change"),!Z.test(this.nodeName)}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&a.addEventListener(e,r,!0)},teardown:function(){0===--n&&a.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return x().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=x.guid++)),this.each(function(){x.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,x(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){x.event.remove(this,e,r,n)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?x.event.trigger(e,n,r,!0):t}});var st=/^.[^:#\[\.,]*$/,lt=/^(?:parents|prev(?:Until|All))/,ut=x.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t,n=x(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(x.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e||[],!0))},filter:function(e){return this.pushStack(ft(this,e||[],!1))},is:function(e){return!!ft(this,"string"==typeof e&&ut.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],a=ut.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(a?a.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return x.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(ct[e]||(i=x.unique(i)),lt.test(e)&&(i=i.reverse())),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!x(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(st.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return x.inArray(e,t)>=0!==n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/\s*$/g,At={option:[1,""],legend:[1,"
    ","
    "],area:[1,"",""],param:[1,"",""],thead:[1,"","
    "],tr:[2,"","
    "],col:[2,"","
    "],td:[3,"","
    "],_default:x.support.htmlSerialize?[0,"",""]:[1,"X
    ","
    "]},jt=dt(a),Dt=jt.appendChild(a.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===t?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||a).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(Ft(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&_t(Ft(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&x.cleanData(Ft(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&x.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!x.support.htmlSerialize&&mt.test(e)||!x.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(x.cleanData(Ft(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=d.apply([],e);var r,i,o,a,s,l,u=0,c=this.length,p=this,f=c-1,h=e[0],g=x.isFunction(h);if(g||!(1>=c||"string"!=typeof h||x.support.checkClone)&&Nt.test(h))return this.each(function(r){var i=p.eq(r);g&&(e[0]=h.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(l=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),r=l.firstChild,1===l.childNodes.length&&(l=r),r)){for(a=x.map(Ft(l,"script"),Ht),o=a.length;c>u;u++)i=l,u!==f&&(i=x.clone(i,!0,!0),o&&x.merge(a,Ft(i,"script"))),t.call(this[u],i,u);if(o)for(s=a[a.length-1].ownerDocument,x.map(a,qt),u=0;o>u;u++)i=a[u],kt.test(i.type||"")&&!x._data(i,"globalEval")&&x.contains(s,i)&&(i.src?x._evalUrl(i.src):x.globalEval((i.text||i.textContent||i.innerHTML||"").replace(St,"")));l=r=null}return this}});function Lt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function Ht(e){return e.type=(null!==x.find.attr(e,"type"))+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function _t(e,t){var n,r=0;for(;null!=(n=e[r]);r++)x._data(n,"globalEval",!t||x._data(t[r],"globalEval"))}function Mt(e,t){if(1===t.nodeType&&x.hasData(e)){var n,r,i,o=x._data(e),a=x._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)x.event.add(t,n,s[n][r])}a.data&&(a.data=x.extend({},a.data))}}function Ot(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!x.support.noCloneEvent&&t[x.expando]){i=x._data(t);for(r in i.events)x.removeEvent(t,r,i.handle);t.removeAttribute(x.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),x.support.html5Clone&&e.innerHTML&&!x.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Ct.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=0,i=[],o=x(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),x(o[r])[t](n),h.apply(i,n.get());return this.pushStack(i)}});function Ft(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||x.nodeName(o,n)?s.push(o):x.merge(s,Ft(o,n));return n===t||n&&x.nodeName(e,n)?x.merge([e],s):s}function Bt(e){Ct.test(e.type)&&(e.defaultChecked=e.checked)}x.extend({clone:function(e,t,n){var r,i,o,a,s,l=x.contains(e.ownerDocument,e);if(x.support.html5Clone||x.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(x.support.noCloneEvent&&x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(r=Ft(o),s=Ft(e),a=0;null!=(i=s[a]);++a)r[a]&&Ot(i,r[a]);if(t)if(n)for(s=s||Ft(e),r=r||Ft(o),a=0;null!=(i=s[a]);a++)Mt(i,r[a]);else Mt(e,o);return r=Ft(o,"script"),r.length>0&&_t(r,!l&&Ft(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,l,u,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===x.type(o))x.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),l=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[l]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!x.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!x.support.tbody){o="table"!==l||xt.test(o)?""!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)x.nodeName(u=o.childNodes[i],"tbody")&&!u.childNodes.length&&o.removeChild(u)}x.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),x.support.appendChecked||x.grep(Ft(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===x.inArray(o,r))&&(a=x.contains(o.ownerDocument,o),s=Ft(f.appendChild(o),"script"),a&&_t(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,l=x.expando,u=x.cache,c=x.support.deleteExpando,f=x.event.special;for(;null!=(n=e[s]);s++)if((t||x.acceptData(n))&&(o=n[l],a=o&&u[o])){if(a.events)for(r in a.events)f[r]?x.event.remove(n,r):x.removeEvent(n,r,a.handle); -u[o]&&(delete u[o],c?delete n[l]:typeof n.removeAttribute!==i?n.removeAttribute(l):n[l]=null,p.push(o))}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}}),x.fn.extend({wrapAll:function(e){if(x.isFunction(e))return this.each(function(t){x(this).wrapAll(e.call(this,t))});if(this[0]){var t=x(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+w+")(.*)$","i"),Yt=RegExp("^("+w+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+w+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=x._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=x._data(r,"olddisplay",ln(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&x._data(r,"olddisplay",i?n:x.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}x.fn.extend({css:function(e,n){return x.access(this,function(e,n,r){var i,o,a={},s=0;if(x.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=x.css(e,n[s],!1,o);return a}return r!==t?x.style(e,n,r):x.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){nn(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":x.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,l=x.camelCase(n),u=e.style;if(n=x.cssProps[l]||(x.cssProps[l]=tn(u,l)),s=x.cssHooks[n]||x.cssHooks[l],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:u[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(x.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||x.cssNumber[l]||(r+="px"),x.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(u[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{u[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,l=x.camelCase(n);return n=x.cssProps[l]||(x.cssProps[l]=tn(e.style,l)),s=x.cssHooks[n]||x.cssHooks[l],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||x.isNumeric(o)?o||0:a):a}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s.getPropertyValue(n)||s[n]:t,u=e.style;return s&&(""!==l||x.contains(e.ownerDocument,e)||(l=x.style(e,n)),Yt.test(l)&&Ut.test(n)&&(i=u.width,o=u.minWidth,a=u.maxWidth,u.minWidth=u.maxWidth=u.width=l,l=s.width,u.width=i,u.minWidth=o,u.maxWidth=a)),l}):a.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s[n]:t,u=e.style;return null==l&&u&&u[n]&&(l=u[n]),Yt.test(l)&&!zt.test(n)&&(i=u.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),u.left="fontSize"===n?"1em":l,l=u.pixelLeft+"px",u.left=i,a&&(o.left=a)),""===l?"auto":l});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=x.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=x.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=x.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=x.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=x.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function ln(e){var t=a,n=Gt[e];return n||(n=un(e,t),"none"!==n&&n||(Pt=(Pt||x("').appendTo(content); - } - - wrap.show(); - - busy = false; - - $.fancybox.center(); - - currentOpts.onComplete(currentArray, currentIndex, currentOpts); - - _preload_images(); - }, - - _preload_images = function() { - var href, - objNext; - - if ((currentArray.length -1) > currentIndex) { - href = currentArray[ currentIndex + 1 ].href; - - if (typeof href !== 'undefined' && href.match(imgRegExp)) { - objNext = new Image(); - objNext.src = href; - } - } - - if (currentIndex > 0) { - href = currentArray[ currentIndex - 1 ].href; - - if (typeof href !== 'undefined' && href.match(imgRegExp)) { - objNext = new Image(); - objNext.src = href; - } - } - }, - - _draw = function(pos) { - var dim = { - width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), - height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), - - top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), - left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) - }; - - if (typeof final_pos.opacity !== 'undefined') { - dim.opacity = pos < 0.5 ? 0.5 : pos; - } - - wrap.css(dim); - - content.css({ - 'width' : dim.width - currentOpts.padding * 2, - 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 - }); - }, - - _get_viewport = function() { - return [ - $(window).width() - (currentOpts.margin * 2), - $(window).height() - (currentOpts.margin * 2), - $(document).scrollLeft() + currentOpts.margin, - $(document).scrollTop() + currentOpts.margin - ]; - }, - - _get_zoom_to = function () { - var view = _get_viewport(), - to = {}, - resize = currentOpts.autoScale, - double_padding = currentOpts.padding * 2, - ratio; - - if (currentOpts.width.toString().indexOf('%') > -1) { - to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); - } else { - to.width = currentOpts.width + double_padding; - } - - if (currentOpts.height.toString().indexOf('%') > -1) { - to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); - } else { - to.height = currentOpts.height + double_padding; - } - - if (resize && (to.width > view[0] || to.height > view[1])) { - if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { - ratio = (currentOpts.width ) / (currentOpts.height ); - - if ((to.width ) > view[0]) { - to.width = view[0]; - to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); - } - - if ((to.height) > view[1]) { - to.height = view[1]; - to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); - } - - } else { - to.width = Math.min(to.width, view[0]); - to.height = Math.min(to.height, view[1]); - } - } - - to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); - to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); - - return to; - }, - - _get_obj_pos = function(obj) { - var pos = obj.offset(); - - pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; - pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; - - pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; - pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; - - pos.width = obj.width(); - pos.height = obj.height(); - - return pos; - }, - - _get_zoom_from = function() { - var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, - from = {}, - pos, - view; - - if (orig && orig.length) { - pos = _get_obj_pos(orig); - - from = { - width : pos.width + (currentOpts.padding * 2), - height : pos.height + (currentOpts.padding * 2), - top : pos.top - currentOpts.padding - 20, - left : pos.left - currentOpts.padding - 20 - }; - - } else { - view = _get_viewport(); - - from = { - width : currentOpts.padding * 2, - height : currentOpts.padding * 2, - top : parseInt(view[3] + view[1] * 0.5, 10), - left : parseInt(view[2] + view[0] * 0.5, 10) - }; - } - - return from; - }, - - _animate_loading = function() { - if (!loading.is(':visible')){ - clearInterval(loadingTimer); - return; - } - - $('div', loading).css('top', (loadingFrame * -40) + 'px'); + wrap.removeAttr("style"); + + content.css('border-width', currentOpts.padding); + + if (currentOpts.transitionIn == 'elastic') { + start_pos = _get_zoom_from(); + + content.html( tmp.contents() ); + + wrap.show(); + + if (currentOpts.opacity) { + final_pos.opacity = 0; + } + + fx.prop = 0; + + $(fx).animate({prop: 1}, { + duration : currentOpts.speedIn, + easing : currentOpts.easingIn, + step : _draw, + complete : _finish + }); + + return; + } + + if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { + title.show(); + } + + content + .css({ + 'width' : final_pos.width - currentOpts.padding * 2, + 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 + }) + .html( tmp.contents() ); + + wrap + .css(final_pos) + .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); + }, + + _format_title = function(title) { + if (title && title.length) { + if (currentOpts.titlePosition == 'float') { + return '
    ' + title + '
    '; + } + + return '
    ' + title + '
    '; + } + + return false; + }, + + _process_title = function() { + titleStr = currentOpts.title || ''; + titleHeight = 0; + + title + .empty() + .removeAttr('style') + .removeClass(); + + if (currentOpts.titleShow === false) { + title.hide(); + return; + } + + titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); + + if (!titleStr || titleStr === '') { + title.hide(); + return; + } + + title + .addClass('fancybox-title-' + currentOpts.titlePosition) + .html( titleStr ) + .appendTo( 'body' ) + .show(); + + switch (currentOpts.titlePosition) { + case 'inside': + title + .css({ + 'width' : final_pos.width - (currentOpts.padding * 2), + 'marginLeft' : currentOpts.padding, + 'marginRight' : currentOpts.padding + }); + + titleHeight = title.outerHeight(true); + + title.appendTo( outer ); + + final_pos.height += titleHeight; + break; + + case 'over': + title + .css({ + 'marginLeft' : currentOpts.padding, + 'width' : final_pos.width - (currentOpts.padding * 2), + 'bottom' : currentOpts.padding + }) + .appendTo( outer ); + break; + + case 'float': + title + .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) + .appendTo( wrap ); + break; + + default: + title + .css({ + 'width' : final_pos.width - (currentOpts.padding * 2), + 'paddingLeft' : currentOpts.padding, + 'paddingRight' : currentOpts.padding + }) + .appendTo( wrap ); + break; + } + + title.hide(); + }, + + _set_navigation = function() { + if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { + $(document).bind('keydown.fb', function(e) { + if (e.keyCode == 27 && currentOpts.enableEscapeButton) { + e.preventDefault(); + $.fancybox.close(); + + } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { + e.preventDefault(); + $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); + } + }); + } + + if (!currentOpts.showNavArrows) { + nav_left.hide(); + nav_right.hide(); + return; + } + + if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { + nav_left.show(); + } + + if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { + nav_right.show(); + } + }, + + _finish = function () { + if (!$.support.opacity) { + content.get(0).style.removeAttribute('filter'); + wrap.get(0).style.removeAttribute('filter'); + } + + if (selectedOpts.autoDimensions) { + content.css('height', 'auto'); + } + + wrap.css('height', 'auto'); + + if (titleStr && titleStr.length) { + title.show(); + } + + if (currentOpts.showCloseButton) { + close.show(); + } + + _set_navigation(); + + if (currentOpts.hideOnContentClick) { + content.bind('click', $.fancybox.close); + } + + if (currentOpts.hideOnOverlayClick) { + overlay.bind('click', $.fancybox.close); + } + + $(window).bind("resize.fb", $.fancybox.resize); + + if (currentOpts.centerOnScroll) { + $(window).bind("scroll.fb", $.fancybox.center); + } + + if (currentOpts.type == 'iframe') { + $('').appendTo(content); + } + + wrap.show(); + + busy = false; + + $.fancybox.center(); + + currentOpts.onComplete(currentArray, currentIndex, currentOpts); + + _preload_images(); + }, + + _preload_images = function() { + var href, + objNext; + + if ((currentArray.length -1) > currentIndex) { + href = currentArray[ currentIndex + 1 ].href; + + if (typeof href !== 'undefined' && href.match(imgRegExp)) { + objNext = new Image(); + objNext.src = href; + } + } + + if (currentIndex > 0) { + href = currentArray[ currentIndex - 1 ].href; + + if (typeof href !== 'undefined' && href.match(imgRegExp)) { + objNext = new Image(); + objNext.src = href; + } + } + }, + + _draw = function(pos) { + var dim = { + width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), + height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), + + top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), + left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) + }; + + if (typeof final_pos.opacity !== 'undefined') { + dim.opacity = pos < 0.5 ? 0.5 : pos; + } + + wrap.css(dim); + + content.css({ + 'width' : dim.width - currentOpts.padding * 2, + 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 + }); + }, + + _get_viewport = function() { + return [ + $(window).width() - (currentOpts.margin * 2), + $(window).height() - (currentOpts.margin * 2), + $(document).scrollLeft() + currentOpts.margin, + $(document).scrollTop() + currentOpts.margin + ]; + }, + + _get_zoom_to = function () { + var view = _get_viewport(), + to = {}, + resize = currentOpts.autoScale, + double_padding = currentOpts.padding * 2, + ratio; + + if (currentOpts.width.toString().indexOf('%') > -1) { + to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); + } else { + to.width = currentOpts.width + double_padding; + } + + if (currentOpts.height.toString().indexOf('%') > -1) { + to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); + } else { + to.height = currentOpts.height + double_padding; + } + + if (resize && (to.width > view[0] || to.height > view[1])) { + if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { + ratio = (currentOpts.width ) / (currentOpts.height ); + + if ((to.width ) > view[0]) { + to.width = view[0]; + to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); + } + + if ((to.height) > view[1]) { + to.height = view[1]; + to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); + } + + } else { + to.width = Math.min(to.width, view[0]); + to.height = Math.min(to.height, view[1]); + } + } + + to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); + to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); + + return to; + }, + + _get_obj_pos = function(obj) { + var pos = obj.offset(); + + pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; + pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; + + pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; + pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; + + pos.width = obj.width(); + pos.height = obj.height(); + + return pos; + }, + + _get_zoom_from = function() { + var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, + from = {}, + pos, + view; + + if (orig && orig.length) { + pos = _get_obj_pos(orig); + + from = { + width : pos.width + (currentOpts.padding * 2), + height : pos.height + (currentOpts.padding * 2), + top : pos.top - currentOpts.padding - 20, + left : pos.left - currentOpts.padding - 20 + }; + + } else { + view = _get_viewport(); + + from = { + width : currentOpts.padding * 2, + height : currentOpts.padding * 2, + top : parseInt(view[3] + view[1] * 0.5, 10), + left : parseInt(view[2] + view[0] * 0.5, 10) + }; + } + + return from; + }, + + _animate_loading = function() { + if (!loading.is(':visible')){ + clearInterval(loadingTimer); + return; + } + + $('div', loading).css('top', (loadingFrame * -40) + 'px'); - loadingFrame = (loadingFrame + 1) % 12; - }; + loadingFrame = (loadingFrame + 1) % 12; + }; - /* - * Public methods - */ + /* + * Public methods + */ - $.fn.fancybox = function(options) { - if (!$(this).length) { - return this; - } + $.fn.fancybox = function(options) { + if (!$(this).length) { + return this; + } - $(this) - .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) - .unbind('click.fb') - .bind('click.fb', function(e) { - e.preventDefault(); + $(this) + .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) + .unbind('click.fb') + .bind('click.fb', function(e) { + e.preventDefault(); - if (busy) { - return; - } + if (busy) { + return; + } - busy = true; + busy = true; - $(this).blur(); + $(this).blur(); - selectedArray = []; - selectedIndex = 0; + selectedArray = []; + selectedIndex = 0; - var rel = $(this).attr('rel') || ''; + var rel = $(this).attr('rel') || ''; - if (!rel || rel == '' || rel === 'nofollow') { - selectedArray.push(this); + if (!rel || rel == '' || rel === 'nofollow') { + selectedArray.push(this); - } else { - selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); - selectedIndex = selectedArray.index( this ); - } + } else { + selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); + selectedIndex = selectedArray.index( this ); + } - _start(); + _start(); - return; - }); + return; + }); - return this; - }; + return this; + }; - $.fancybox = function(obj) { - var opts; + $.fancybox = function(obj) { + var opts; - if (busy) { - return; - } + if (busy) { + return; + } - busy = true; - opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; + busy = true; + opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; - selectedArray = []; - selectedIndex = parseInt(opts.index, 10) || 0; + selectedArray = []; + selectedIndex = parseInt(opts.index, 10) || 0; - if ($.isArray(obj)) { - for (var i = 0, j = obj.length; i < j; i++) { - if (typeof obj[i] == 'object') { - $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); - } else { - obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); - } - } + if ($.isArray(obj)) { + for (var i = 0, j = obj.length; i < j; i++) { + if (typeof obj[i] == 'object') { + $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); + } else { + obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); + } + } - selectedArray = jQuery.merge(selectedArray, obj); + selectedArray = jQuery.merge(selectedArray, obj); - } else { - if (typeof obj == 'object') { - $(obj).data('fancybox', $.extend({}, opts, obj)); - } else { - obj = $({}).data('fancybox', $.extend({content : obj}, opts)); - } + } else { + if (typeof obj == 'object') { + $(obj).data('fancybox', $.extend({}, opts, obj)); + } else { + obj = $({}).data('fancybox', $.extend({content : obj}, opts)); + } - selectedArray.push(obj); - } + selectedArray.push(obj); + } - if (selectedIndex > selectedArray.length || selectedIndex < 0) { - selectedIndex = 0; - } + if (selectedIndex > selectedArray.length || selectedIndex < 0) { + selectedIndex = 0; + } - _start(); - }; + _start(); + }; - $.fancybox.showActivity = function() { - clearInterval(loadingTimer); + $.fancybox.showActivity = function() { + clearInterval(loadingTimer); - loading.show(); - loadingTimer = setInterval(_animate_loading, 66); - }; + loading.show(); + loadingTimer = setInterval(_animate_loading, 66); + }; - $.fancybox.hideActivity = function() { - loading.hide(); - }; + $.fancybox.hideActivity = function() { + loading.hide(); + }; - $.fancybox.next = function() { - return $.fancybox.pos( currentIndex + 1); - }; + $.fancybox.next = function() { + return $.fancybox.pos( currentIndex + 1); + }; - $.fancybox.prev = function() { - return $.fancybox.pos( currentIndex - 1); - }; + $.fancybox.prev = function() { + return $.fancybox.pos( currentIndex - 1); + }; - $.fancybox.pos = function(pos) { - if (busy) { - return; - } + $.fancybox.pos = function(pos) { + if (busy) { + return; + } - pos = parseInt(pos); + pos = parseInt(pos); - selectedArray = currentArray; + selectedArray = currentArray; - if (pos > -1 && pos < currentArray.length) { - selectedIndex = pos; - _start(); + if (pos > -1 && pos < currentArray.length) { + selectedIndex = pos; + _start(); - } else if (currentOpts.cyclic && currentArray.length > 1) { - selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; - _start(); - } + } else if (currentOpts.cyclic && currentArray.length > 1) { + selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; + _start(); + } - return; - }; + return; + }; - $.fancybox.cancel = function() { - if (busy) { - return; - } + $.fancybox.cancel = function() { + if (busy) { + return; + } - busy = true; + busy = true; - $.event.trigger('fancybox-cancel'); + $.event.trigger('fancybox-cancel'); - _abort(); + _abort(); - selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); + selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); - busy = false; - }; + busy = false; + }; - // Note: within an iframe use - parent.$.fancybox.close(); - $.fancybox.close = function() { - if (busy || wrap.is(':hidden')) { - return; - } + // Note: within an iframe use - parent.$.fancybox.close(); + $.fancybox.close = function() { + if (busy || wrap.is(':hidden')) { + return; + } - busy = true; + busy = true; - if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { - busy = false; - return; - } + if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { + busy = false; + return; + } - _abort(); + _abort(); - $(close.add( nav_left ).add( nav_right )).hide(); + $(close.add( nav_left ).add( nav_right )).hide(); - $(content.add( overlay )).unbind(); + $(content.add( overlay )).unbind(); - $(window).unbind("resize.fb scroll.fb"); - $(document).unbind('keydown.fb'); + $(window).unbind("resize.fb scroll.fb"); + $(document).unbind('keydown.fb'); - content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); + content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); - if (currentOpts.titlePosition !== 'inside') { - title.empty(); - } + if (currentOpts.titlePosition !== 'inside') { + title.empty(); + } - wrap.stop(); + wrap.stop(); - function _cleanup() { - overlay.fadeOut('fast'); + function _cleanup() { + overlay.fadeOut('fast'); - title.empty().hide(); - wrap.hide(); + title.empty().hide(); + wrap.hide(); - $.event.trigger('fancybox-cleanup'); + $.event.trigger('fancybox-cleanup'); - content.empty(); + content.empty(); - currentOpts.onClosed(currentArray, currentIndex, currentOpts); + currentOpts.onClosed(currentArray, currentIndex, currentOpts); - currentArray = selectedOpts = []; - currentIndex = selectedIndex = 0; - currentOpts = selectedOpts = {}; + currentArray = selectedOpts = []; + currentIndex = selectedIndex = 0; + currentOpts = selectedOpts = {}; - busy = false; - } + busy = false; + } - if (currentOpts.transitionOut == 'elastic') { - start_pos = _get_zoom_from(); + if (currentOpts.transitionOut == 'elastic') { + start_pos = _get_zoom_from(); - var pos = wrap.position(); + var pos = wrap.position(); - final_pos = { - top : pos.top , - left : pos.left, - width : wrap.width(), - height : wrap.height() - }; + final_pos = { + top : pos.top , + left : pos.left, + width : wrap.width(), + height : wrap.height() + }; - if (currentOpts.opacity) { - final_pos.opacity = 1; - } + if (currentOpts.opacity) { + final_pos.opacity = 1; + } - title.empty().hide(); + title.empty().hide(); - fx.prop = 1; + fx.prop = 1; - $(fx).animate({ prop: 0 }, { - duration : currentOpts.speedOut, - easing : currentOpts.easingOut, - step : _draw, - complete : _cleanup - }); + $(fx).animate({ prop: 0 }, { + duration : currentOpts.speedOut, + easing : currentOpts.easingOut, + step : _draw, + complete : _cleanup + }); - } else { - wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); - } - }; + } else { + wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); + } + }; - $.fancybox.resize = function() { - if (overlay.is(':visible')) { - overlay.css('height', $(document).height()); - } + $.fancybox.resize = function() { + if (overlay.is(':visible')) { + overlay.css('height', $(document).height()); + } - $.fancybox.center(true); - }; + $.fancybox.center(true); + }; - $.fancybox.center = function() { - var view, align; + $.fancybox.center = function() { + var view, align; - if (busy) { - return; - } + if (busy) { + return; + } - align = arguments[0] === true ? 1 : 0; - view = _get_viewport(); + align = arguments[0] === true ? 1 : 0; + view = _get_viewport(); - if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { - return; - } + if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { + return; + } - wrap - .stop() - .animate({ - 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), - 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) - }, typeof arguments[0] == 'number' ? arguments[0] : 200); - }; + wrap + .stop() + .animate({ + 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), + 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) + }, typeof arguments[0] == 'number' ? arguments[0] : 200); + }; - $.fancybox.init = function() { - if ($("#fancybox-wrap").length) { - return; - } + $.fancybox.init = function() { + if ($("#fancybox-wrap").length) { + return; + } - $('body').append( - tmp = $('
    '), - loading = $('
    '), - overlay = $('
    '), - wrap = $('
    ') - ); + $('body').append( + tmp = $('
    '), + loading = $('
    '), + overlay = $('
    '), + wrap = $('
    ') + ); - outer = $('
    ') - .append('
    ') - .appendTo( wrap ); - - outer.append( - content = $('
    '), - close = $(''), - title = $('
    '), - - nav_left = $(''), - nav_right = $('') - ); - - close.click($.fancybox.close); - loading.click($.fancybox.cancel); - - nav_left.click(function(e) { - e.preventDefault(); - $.fancybox.prev(); - }); - - nav_right.click(function(e) { - e.preventDefault(); - $.fancybox.next(); - }); - - if ($.fn.mousewheel) { - wrap.bind('mousewheel.fb', function(e, delta) { - if (busy) { - e.preventDefault(); - - } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { - e.preventDefault(); - $.fancybox[ delta > 0 ? 'prev' : 'next'](); - } - }); - } - - if (!$.support.opacity) { - wrap.addClass('fancybox-ie'); - } - - if (isIE6) { - loading.addClass('fancybox-ie6'); - wrap.addClass('fancybox-ie6'); - - $('').prependTo(outer); - } - }; - - $.fn.fancybox.defaults = { - padding : 10, - margin : 40, - opacity : false, - modal : false, - cyclic : false, - scrolling : 'auto', // 'auto', 'yes' or 'no' - - width : 560, - height : 340, - - autoScale : true, - autoDimensions : true, - centerOnScroll : false, - - ajax : {}, - swf : { wmode: 'transparent' }, - - hideOnOverlayClick : true, - hideOnContentClick : false, - - overlayShow : true, - overlayOpacity : 0.7, - overlayColor : '#777', - - titleShow : true, - titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' - titleFormat : null, - titleFromAlt : false, - - transitionIn : 'fade', // 'elastic', 'fade' or 'none' - transitionOut : 'fade', // 'elastic', 'fade' or 'none' - - speedIn : 300, - speedOut : 300, - - changeSpeed : 300, - changeFade : 'fast', - - easingIn : 'swing', - easingOut : 'swing', - - showCloseButton : true, - showNavArrows : true, - enableEscapeButton : true, - enableKeyboardNav : true, - - onStart : function(){}, - onCancel : function(){}, - onComplete : function(){}, - onCleanup : function(){}, - onClosed : function(){}, - onError : function(){} - }; - - $(document).ready(function() { - $.fancybox.init(); - }); + outer = $('
    ') + .append('
    ') + .appendTo( wrap ); + + outer.append( + content = $('
    '), + close = $(''), + title = $('
    '), + + nav_left = $(''), + nav_right = $('') + ); + + close.click($.fancybox.close); + loading.click($.fancybox.cancel); + + nav_left.click(function(e) { + e.preventDefault(); + $.fancybox.prev(); + }); + + nav_right.click(function(e) { + e.preventDefault(); + $.fancybox.next(); + }); + + if ($.fn.mousewheel) { + wrap.bind('mousewheel.fb', function(e, delta) { + if (busy) { + e.preventDefault(); + + } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { + e.preventDefault(); + $.fancybox[ delta > 0 ? 'prev' : 'next'](); + } + }); + } + + if (!$.support.opacity) { + wrap.addClass('fancybox-ie'); + } + + if (isIE6) { + loading.addClass('fancybox-ie6'); + wrap.addClass('fancybox-ie6'); + + $('').prependTo(outer); + } + }; + + $.fn.fancybox.defaults = { + padding : 10, + margin : 40, + opacity : false, + modal : false, + cyclic : false, + scrolling : 'auto', // 'auto', 'yes' or 'no' + + width : 560, + height : 340, + + autoScale : true, + autoDimensions : true, + centerOnScroll : false, + + ajax : {}, + swf : { wmode: 'transparent' }, + + hideOnOverlayClick : true, + hideOnContentClick : false, + + overlayShow : true, + overlayOpacity : 0.7, + overlayColor : '#777', + + titleShow : true, + titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' + titleFormat : null, + titleFromAlt : false, + + transitionIn : 'fade', // 'elastic', 'fade' or 'none' + transitionOut : 'fade', // 'elastic', 'fade' or 'none' + + speedIn : 300, + speedOut : 300, + + changeSpeed : 300, + changeFade : 'fast', + + easingIn : 'swing', + easingOut : 'swing', + + showCloseButton : true, + showNavArrows : true, + enableEscapeButton : true, + enableKeyboardNav : true, + + onStart : function(){}, + onCancel : function(){}, + onComplete : function(){}, + onCleanup : function(){}, + onClosed : function(){}, + onError : function(){} + }; + + $(document).ready(function() { + $.fancybox.init(); + }); })(jQuery); \ No newline at end of file diff --git a/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.js b/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.js old mode 100755 new mode 100644 index d59ca32..a852005 --- a/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.js +++ b/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.js @@ -16,1141 +16,1141 @@ */ ;(function($) { - var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right, + var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right, - selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], + selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], - ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, + ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, - loadingTimer, loadingFrame = 1, + loadingTimer, loadingFrame = 1, - titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('
    ')[0], { prop: 0 }), + titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('
    ')[0], { prop: 0 }), - isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, + isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, - /* - * Private methods - */ + /* + * Private methods + */ - _abort = function() { - loading.hide(); + _abort = function() { + loading.hide(); - imgPreloader.onerror = imgPreloader.onload = null; + imgPreloader.onerror = imgPreloader.onload = null; - if (ajaxLoader) { - ajaxLoader.abort(); - } + if (ajaxLoader) { + ajaxLoader.abort(); + } - tmp.empty(); - }, + tmp.empty(); + }, - _error = function() { - if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { - loading.hide(); - busy = false; - return; - } + _error = function() { + if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { + loading.hide(); + busy = false; + return; + } - selectedOpts.titleShow = false; + selectedOpts.titleShow = false; - selectedOpts.width = 'auto'; - selectedOpts.height = 'auto'; + selectedOpts.width = 'auto'; + selectedOpts.height = 'auto'; - tmp.html( '

    The requested content cannot be loaded.
    Please try again later.

    ' ); + tmp.html( '

    The requested content cannot be loaded.
    Please try again later.

    ' ); - _process_inline(); - }, + _process_inline(); + }, - _start = function() { - var obj = selectedArray[ selectedIndex ], - href, - type, - title, - str, - emb, - ret; + _start = function() { + var obj = selectedArray[ selectedIndex ], + href, + type, + title, + str, + emb, + ret; - _abort(); + _abort(); - selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); + selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); - ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); + ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); - if (ret === false) { - busy = false; - return; - } else if (typeof ret == 'object') { - selectedOpts = $.extend(selectedOpts, ret); - } + if (ret === false) { + busy = false; + return; + } else if (typeof ret == 'object') { + selectedOpts = $.extend(selectedOpts, ret); + } - title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''; + title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''; - if (obj.nodeName && !selectedOpts.orig) { - selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); - } + if (obj.nodeName && !selectedOpts.orig) { + selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); + } - if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) { - title = selectedOpts.orig.attr('alt'); - } + if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) { + title = selectedOpts.orig.attr('alt'); + } - href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; + href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; - if ((/^(?:javascript)/i).test(href) || href == '#') { - href = null; - } + if ((/^(?:javascript)/i).test(href) || href == '#') { + href = null; + } - if (selectedOpts.type) { - type = selectedOpts.type; + if (selectedOpts.type) { + type = selectedOpts.type; - if (!href) { - href = selectedOpts.content; - } + if (!href) { + href = selectedOpts.content; + } - } else if (selectedOpts.content) { - type = 'html'; + } else if (selectedOpts.content) { + type = 'html'; - } else if (href) { - if (href.match(imgRegExp)) { - type = 'image'; + } else if (href) { + if (href.match(imgRegExp)) { + type = 'image'; - } else if (href.match(swfRegExp)) { - type = 'swf'; + } else if (href.match(swfRegExp)) { + type = 'swf'; - } else if ($(obj).hasClass("iframe")) { - type = 'iframe'; + } else if ($(obj).hasClass("iframe")) { + type = 'iframe'; - } else if (href.indexOf("#") === 0) { - type = 'inline'; + } else if (href.indexOf("#") === 0) { + type = 'inline'; - } else { - type = 'ajax'; - } - } + } else { + type = 'ajax'; + } + } - if (!type) { - _error(); - return; - } + if (!type) { + _error(); + return; + } - if (type == 'inline') { - obj = href.substr(href.indexOf("#")); - type = $(obj).length > 0 ? 'inline' : 'ajax'; - } + if (type == 'inline') { + obj = href.substr(href.indexOf("#")); + type = $(obj).length > 0 ? 'inline' : 'ajax'; + } - selectedOpts.type = type; - selectedOpts.href = href; - selectedOpts.title = title; + selectedOpts.type = type; + selectedOpts.href = href; + selectedOpts.title = title; - if (selectedOpts.autoDimensions) { - if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') { - selectedOpts.width = 'auto'; - selectedOpts.height = 'auto'; - } else { - selectedOpts.autoDimensions = false; - } - } + if (selectedOpts.autoDimensions) { + if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') { + selectedOpts.width = 'auto'; + selectedOpts.height = 'auto'; + } else { + selectedOpts.autoDimensions = false; + } + } - if (selectedOpts.modal) { - selectedOpts.overlayShow = true; - selectedOpts.hideOnOverlayClick = false; - selectedOpts.hideOnContentClick = false; - selectedOpts.enableEscapeButton = false; - selectedOpts.showCloseButton = false; - } + if (selectedOpts.modal) { + selectedOpts.overlayShow = true; + selectedOpts.hideOnOverlayClick = false; + selectedOpts.hideOnContentClick = false; + selectedOpts.enableEscapeButton = false; + selectedOpts.showCloseButton = false; + } - selectedOpts.padding = parseInt(selectedOpts.padding, 10); - selectedOpts.margin = parseInt(selectedOpts.margin, 10); + selectedOpts.padding = parseInt(selectedOpts.padding, 10); + selectedOpts.margin = parseInt(selectedOpts.margin, 10); - tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); + tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); - $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { - $(this).replaceWith(content.children()); - }); + $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { + $(this).replaceWith(content.children()); + }); - switch (type) { - case 'html' : - tmp.html( selectedOpts.content ); - _process_inline(); - break; + switch (type) { + case 'html' : + tmp.html( selectedOpts.content ); + _process_inline(); + break; - case 'inline' : - if ( $(obj).parent().is('#fancybox-content') === true) { - busy = false; - return; - } - - $('
    ') - .hide() - .insertBefore( $(obj) ) - .bind('fancybox-cleanup', function() { - $(this).replaceWith(content.children()); - }).bind('fancybox-cancel', function() { - $(this).replaceWith(tmp.children()); - }); + case 'inline' : + if ( $(obj).parent().is('#fancybox-content') === true) { + busy = false; + return; + } + + $('
    ') + .hide() + .insertBefore( $(obj) ) + .bind('fancybox-cleanup', function() { + $(this).replaceWith(content.children()); + }).bind('fancybox-cancel', function() { + $(this).replaceWith(tmp.children()); + }); - $(obj).appendTo(tmp); - - _process_inline(); - break; + $(obj).appendTo(tmp); + + _process_inline(); + break; - case 'image': - busy = false; - - $.fancybox.showActivity(); + case 'image': + busy = false; + + $.fancybox.showActivity(); - imgPreloader = new Image(); + imgPreloader = new Image(); - imgPreloader.onerror = function() { - _error(); - }; + imgPreloader.onerror = function() { + _error(); + }; - imgPreloader.onload = function() { - busy = true; + imgPreloader.onload = function() { + busy = true; - imgPreloader.onerror = imgPreloader.onload = null; + imgPreloader.onerror = imgPreloader.onload = null; - _process_image(); - }; - - imgPreloader.src = href; - break; - - case 'swf': - selectedOpts.scrolling = 'no'; - - str = ''; - emb = ''; + _process_image(); + }; + + imgPreloader.src = href; + break; + + case 'swf': + selectedOpts.scrolling = 'no'; + + str = ''; + emb = ''; - $.each(selectedOpts.swf, function(name, val) { - str += ''; - emb += ' ' + name + '="' + val + '"'; - }); + $.each(selectedOpts.swf, function(name, val) { + str += ''; + emb += ' ' + name + '="' + val + '"'; + }); - str += ''; + str += ''; - tmp.html(str); + tmp.html(str); - _process_inline(); - break; + _process_inline(); + break; - case 'ajax': - busy = false; + case 'ajax': + busy = false; - $.fancybox.showActivity(); + $.fancybox.showActivity(); - selectedOpts.ajax.win = selectedOpts.ajax.success; + selectedOpts.ajax.win = selectedOpts.ajax.success; - ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { - url : href, - data : selectedOpts.ajax.data || {}, - error : function(XMLHttpRequest, textStatus, errorThrown) { - if ( XMLHttpRequest.status > 0 ) { - _error(); - } - }, - success : function(data, textStatus, XMLHttpRequest) { - var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader; - if (o.status == 200) { - if ( typeof selectedOpts.ajax.win == 'function' ) { - ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); + ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { + url : href, + data : selectedOpts.ajax.data || {}, + error : function(XMLHttpRequest, textStatus, errorThrown) { + if ( XMLHttpRequest.status > 0 ) { + _error(); + } + }, + success : function(data, textStatus, XMLHttpRequest) { + var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader; + if (o.status == 200) { + if ( typeof selectedOpts.ajax.win == 'function' ) { + ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); - if (ret === false) { - loading.hide(); - return; - } else if (typeof ret == 'string' || typeof ret == 'object') { - data = ret; - } - } + if (ret === false) { + loading.hide(); + return; + } else if (typeof ret == 'string' || typeof ret == 'object') { + data = ret; + } + } - tmp.html( data ); - _process_inline(); - } - } - })); + tmp.html( data ); + _process_inline(); + } + } + })); - break; + break; - case 'iframe': - _show(); - break; - } - }, + case 'iframe': + _show(); + break; + } + }, - _process_inline = function() { - var - w = selectedOpts.width, - h = selectedOpts.height; + _process_inline = function() { + var + w = selectedOpts.width, + h = selectedOpts.height; - if (w.toString().indexOf('%') > -1) { - w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; + if (w.toString().indexOf('%') > -1) { + w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; - } else { - w = w == 'auto' ? 'auto' : w + 'px'; - } + } else { + w = w == 'auto' ? 'auto' : w + 'px'; + } - if (h.toString().indexOf('%') > -1) { - h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; + if (h.toString().indexOf('%') > -1) { + h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; - } else { - h = h == 'auto' ? 'auto' : h + 'px'; - } + } else { + h = h == 'auto' ? 'auto' : h + 'px'; + } - tmp.wrapInner('
    '); + tmp.wrapInner('
    '); - selectedOpts.width = tmp.width(); - selectedOpts.height = tmp.height(); + selectedOpts.width = tmp.width(); + selectedOpts.height = tmp.height(); - _show(); - }, + _show(); + }, - _process_image = function() { - selectedOpts.width = imgPreloader.width; - selectedOpts.height = imgPreloader.height; + _process_image = function() { + selectedOpts.width = imgPreloader.width; + selectedOpts.height = imgPreloader.height; - $("").attr({ - 'id' : 'fancybox-img', - 'src' : imgPreloader.src, - 'alt' : selectedOpts.title - }).appendTo( tmp ); - - _show(); - }, - - _show = function() { - var pos, equal; - - loading.hide(); + $("").attr({ + 'id' : 'fancybox-img', + 'src' : imgPreloader.src, + 'alt' : selectedOpts.title + }).appendTo( tmp ); + + _show(); + }, + + _show = function() { + var pos, equal; + + loading.hide(); - if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { - $.event.trigger('fancybox-cancel'); + if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { + $.event.trigger('fancybox-cancel'); - busy = false; - return; - } + busy = false; + return; + } - busy = true; + busy = true; - $(content.add( overlay )).unbind(); + $(content.add( overlay )).unbind(); - $(window).unbind("resize.fb scroll.fb"); - $(document).unbind('keydown.fb'); + $(window).unbind("resize.fb scroll.fb"); + $(document).unbind('keydown.fb'); - if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') { - wrap.css('height', wrap.height()); - } - - currentArray = selectedArray; - currentIndex = selectedIndex; - currentOpts = selectedOpts; - - if (currentOpts.overlayShow) { - overlay.css({ - 'background-color' : currentOpts.overlayColor, - 'opacity' : currentOpts.overlayOpacity, - 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto', - 'height' : $(document).height() - }); + if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') { + wrap.css('height', wrap.height()); + } + + currentArray = selectedArray; + currentIndex = selectedIndex; + currentOpts = selectedOpts; + + if (currentOpts.overlayShow) { + overlay.css({ + 'background-color' : currentOpts.overlayColor, + 'opacity' : currentOpts.overlayOpacity, + 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto', + 'height' : $(document).height() + }); - if (!overlay.is(':visible')) { - if (isIE6) { - $('select:not(#fancybox-tmp select)').filter(function() { - return this.style.visibility !== 'hidden'; - }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() { - this.style.visibility = 'inherit'; - }); - } + if (!overlay.is(':visible')) { + if (isIE6) { + $('select:not(#fancybox-tmp select)').filter(function() { + return this.style.visibility !== 'hidden'; + }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() { + this.style.visibility = 'inherit'; + }); + } - overlay.show(); - } - } else { - overlay.hide(); - } + overlay.show(); + } + } else { + overlay.hide(); + } - final_pos = _get_zoom_to(); + final_pos = _get_zoom_to(); - _process_title(); + _process_title(); - if (wrap.is(":visible")) { - $( close.add( nav_left ).add( nav_right ) ).hide(); + if (wrap.is(":visible")) { + $( close.add( nav_left ).add( nav_right ) ).hide(); - pos = wrap.position(), + pos = wrap.position(), - start_pos = { - top : pos.top, - left : pos.left, - width : wrap.width(), - height : wrap.height() - }; + start_pos = { + top : pos.top, + left : pos.left, + width : wrap.width(), + height : wrap.height() + }; - equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); + equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); - content.fadeTo(currentOpts.changeFade, 0.3, function() { - var finish_resizing = function() { - content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); - }; + content.fadeTo(currentOpts.changeFade, 0.3, function() { + var finish_resizing = function() { + content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); + }; - $.event.trigger('fancybox-change'); + $.event.trigger('fancybox-change'); - content - .empty() - .removeAttr('filter') - .css({ - 'border-width' : currentOpts.padding, - 'width' : final_pos.width - currentOpts.padding * 2, - 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 - }); + content + .empty() + .removeAttr('filter') + .css({ + 'border-width' : currentOpts.padding, + 'width' : final_pos.width - currentOpts.padding * 2, + 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 + }); - if (equal) { - finish_resizing(); + if (equal) { + finish_resizing(); - } else { - fx.prop = 0; - - $(fx).animate({prop: 1}, { - duration : currentOpts.changeSpeed, - easing : currentOpts.easingChange, - step : _draw, - complete : finish_resizing - }); - } - }); + } else { + fx.prop = 0; + + $(fx).animate({prop: 1}, { + duration : currentOpts.changeSpeed, + easing : currentOpts.easingChange, + step : _draw, + complete : finish_resizing + }); + } + }); - return; - } + return; + } - wrap.removeAttr("style"); - - content.css('border-width', currentOpts.padding); - - if (currentOpts.transitionIn == 'elastic') { - start_pos = _get_zoom_from(); - - content.html( tmp.contents() ); - - wrap.show(); - - if (currentOpts.opacity) { - final_pos.opacity = 0; - } - - fx.prop = 0; - - $(fx).animate({prop: 1}, { - duration : currentOpts.speedIn, - easing : currentOpts.easingIn, - step : _draw, - complete : _finish - }); - - return; - } - - if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { - title.show(); - } - - content - .css({ - 'width' : final_pos.width - currentOpts.padding * 2, - 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 - }) - .html( tmp.contents() ); - - wrap - .css(final_pos) - .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); - }, - - _format_title = function(title) { - if (title && title.length) { - if (currentOpts.titlePosition == 'float') { - return '
    ' + title + '
    '; - } - - return '
    ' + title + '
    '; - } - - return false; - }, - - _process_title = function() { - titleStr = currentOpts.title || ''; - titleHeight = 0; - - title - .empty() - .removeAttr('style') - .removeClass(); - - if (currentOpts.titleShow === false) { - title.hide(); - return; - } - - titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); - - if (!titleStr || titleStr === '') { - title.hide(); - return; - } - - title - .addClass('fancybox-title-' + currentOpts.titlePosition) - .html( titleStr ) - .appendTo( 'body' ) - .show(); - - switch (currentOpts.titlePosition) { - case 'inside': - title - .css({ - 'width' : final_pos.width - (currentOpts.padding * 2), - 'marginLeft' : currentOpts.padding, - 'marginRight' : currentOpts.padding - }); - - titleHeight = title.outerHeight(true); - - title.appendTo( outer ); - - final_pos.height += titleHeight; - break; - - case 'over': - title - .css({ - 'marginLeft' : currentOpts.padding, - 'width' : final_pos.width - (currentOpts.padding * 2), - 'bottom' : currentOpts.padding - }) - .appendTo( outer ); - break; - - case 'float': - title - .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) - .appendTo( wrap ); - break; - - default: - title - .css({ - 'width' : final_pos.width - (currentOpts.padding * 2), - 'paddingLeft' : currentOpts.padding, - 'paddingRight' : currentOpts.padding - }) - .appendTo( wrap ); - break; - } - - title.hide(); - }, - - _set_navigation = function() { - if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { - $(document).bind('keydown.fb', function(e) { - if (e.keyCode == 27 && currentOpts.enableEscapeButton) { - e.preventDefault(); - $.fancybox.close(); - - } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { - e.preventDefault(); - $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); - } - }); - } - - if (!currentOpts.showNavArrows) { - nav_left.hide(); - nav_right.hide(); - return; - } - - if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { - nav_left.show(); - } - - if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { - nav_right.show(); - } - }, - - _finish = function () { - if (!$.support.opacity) { - content.get(0).style.removeAttribute('filter'); - wrap.get(0).style.removeAttribute('filter'); - } - - if (selectedOpts.autoDimensions) { - content.css('height', 'auto'); - } - - wrap.css('height', 'auto'); - - if (titleStr && titleStr.length) { - title.show(); - } - - if (currentOpts.showCloseButton) { - close.show(); - } - - _set_navigation(); - - if (currentOpts.hideOnContentClick) { - content.bind('click', $.fancybox.close); - } - - if (currentOpts.hideOnOverlayClick) { - overlay.bind('click', $.fancybox.close); - } - - $(window).bind("resize.fb", $.fancybox.resize); - - if (currentOpts.centerOnScroll) { - $(window).bind("scroll.fb", $.fancybox.center); - } - - if (currentOpts.type == 'iframe') { - $('').appendTo(content); - } - - wrap.show(); - - busy = false; - - $.fancybox.center(); - - currentOpts.onComplete(currentArray, currentIndex, currentOpts); - - _preload_images(); - }, - - _preload_images = function() { - var href, - objNext; - - if ((currentArray.length -1) > currentIndex) { - href = currentArray[ currentIndex + 1 ].href; - - if (typeof href !== 'undefined' && href.match(imgRegExp)) { - objNext = new Image(); - objNext.src = href; - } - } - - if (currentIndex > 0) { - href = currentArray[ currentIndex - 1 ].href; - - if (typeof href !== 'undefined' && href.match(imgRegExp)) { - objNext = new Image(); - objNext.src = href; - } - } - }, - - _draw = function(pos) { - var dim = { - width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), - height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), - - top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), - left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) - }; - - if (typeof final_pos.opacity !== 'undefined') { - dim.opacity = pos < 0.5 ? 0.5 : pos; - } - - wrap.css(dim); - - content.css({ - 'width' : dim.width - currentOpts.padding * 2, - 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 - }); - }, - - _get_viewport = function() { - return [ - $(window).width() - (currentOpts.margin * 2), - $(window).height() - (currentOpts.margin * 2), - $(document).scrollLeft() + currentOpts.margin, - $(document).scrollTop() + currentOpts.margin - ]; - }, - - _get_zoom_to = function () { - var view = _get_viewport(), - to = {}, - resize = currentOpts.autoScale, - double_padding = currentOpts.padding * 2, - ratio; - - if (currentOpts.width.toString().indexOf('%') > -1) { - to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); - } else { - to.width = currentOpts.width + double_padding; - } - - if (currentOpts.height.toString().indexOf('%') > -1) { - to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); - } else { - to.height = currentOpts.height + double_padding; - } - - if (resize && (to.width > view[0] || to.height > view[1])) { - if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { - ratio = (currentOpts.width ) / (currentOpts.height ); - - if ((to.width ) > view[0]) { - to.width = view[0]; - to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); - } - - if ((to.height) > view[1]) { - to.height = view[1]; - to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); - } - - } else { - to.width = Math.min(to.width, view[0]); - to.height = Math.min(to.height, view[1]); - } - } - - to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); - to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); - - return to; - }, - - _get_obj_pos = function(obj) { - var pos = obj.offset(); - - pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; - pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; - - pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; - pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; - - pos.width = obj.width(); - pos.height = obj.height(); - - return pos; - }, - - _get_zoom_from = function() { - var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, - from = {}, - pos, - view; - - if (orig && orig.length) { - pos = _get_obj_pos(orig); - - from = { - width : pos.width + (currentOpts.padding * 2), - height : pos.height + (currentOpts.padding * 2), - top : pos.top - currentOpts.padding - 20, - left : pos.left - currentOpts.padding - 20 - }; - - } else { - view = _get_viewport(); - - from = { - width : currentOpts.padding * 2, - height : currentOpts.padding * 2, - top : parseInt(view[3] + view[1] * 0.5, 10), - left : parseInt(view[2] + view[0] * 0.5, 10) - }; - } - - return from; - }, - - _animate_loading = function() { - if (!loading.is(':visible')){ - clearInterval(loadingTimer); - return; - } - - $('div', loading).css('top', (loadingFrame * -40) + 'px'); + wrap.removeAttr("style"); + + content.css('border-width', currentOpts.padding); + + if (currentOpts.transitionIn == 'elastic') { + start_pos = _get_zoom_from(); + + content.html( tmp.contents() ); + + wrap.show(); + + if (currentOpts.opacity) { + final_pos.opacity = 0; + } + + fx.prop = 0; + + $(fx).animate({prop: 1}, { + duration : currentOpts.speedIn, + easing : currentOpts.easingIn, + step : _draw, + complete : _finish + }); + + return; + } + + if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { + title.show(); + } + + content + .css({ + 'width' : final_pos.width - currentOpts.padding * 2, + 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 + }) + .html( tmp.contents() ); + + wrap + .css(final_pos) + .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); + }, + + _format_title = function(title) { + if (title && title.length) { + if (currentOpts.titlePosition == 'float') { + return '
    ' + title + '
    '; + } + + return '
    ' + title + '
    '; + } + + return false; + }, + + _process_title = function() { + titleStr = currentOpts.title || ''; + titleHeight = 0; + + title + .empty() + .removeAttr('style') + .removeClass(); + + if (currentOpts.titleShow === false) { + title.hide(); + return; + } + + titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); + + if (!titleStr || titleStr === '') { + title.hide(); + return; + } + + title + .addClass('fancybox-title-' + currentOpts.titlePosition) + .html( titleStr ) + .appendTo( 'body' ) + .show(); + + switch (currentOpts.titlePosition) { + case 'inside': + title + .css({ + 'width' : final_pos.width - (currentOpts.padding * 2), + 'marginLeft' : currentOpts.padding, + 'marginRight' : currentOpts.padding + }); + + titleHeight = title.outerHeight(true); + + title.appendTo( outer ); + + final_pos.height += titleHeight; + break; + + case 'over': + title + .css({ + 'marginLeft' : currentOpts.padding, + 'width' : final_pos.width - (currentOpts.padding * 2), + 'bottom' : currentOpts.padding + }) + .appendTo( outer ); + break; + + case 'float': + title + .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) + .appendTo( wrap ); + break; + + default: + title + .css({ + 'width' : final_pos.width - (currentOpts.padding * 2), + 'paddingLeft' : currentOpts.padding, + 'paddingRight' : currentOpts.padding + }) + .appendTo( wrap ); + break; + } + + title.hide(); + }, + + _set_navigation = function() { + if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { + $(document).bind('keydown.fb', function(e) { + if (e.keyCode == 27 && currentOpts.enableEscapeButton) { + e.preventDefault(); + $.fancybox.close(); + + } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { + e.preventDefault(); + $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); + } + }); + } + + if (!currentOpts.showNavArrows) { + nav_left.hide(); + nav_right.hide(); + return; + } + + if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { + nav_left.show(); + } + + if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { + nav_right.show(); + } + }, + + _finish = function () { + if (!$.support.opacity) { + content.get(0).style.removeAttribute('filter'); + wrap.get(0).style.removeAttribute('filter'); + } + + if (selectedOpts.autoDimensions) { + content.css('height', 'auto'); + } + + wrap.css('height', 'auto'); + + if (titleStr && titleStr.length) { + title.show(); + } + + if (currentOpts.showCloseButton) { + close.show(); + } + + _set_navigation(); + + if (currentOpts.hideOnContentClick) { + content.bind('click', $.fancybox.close); + } + + if (currentOpts.hideOnOverlayClick) { + overlay.bind('click', $.fancybox.close); + } + + $(window).bind("resize.fb", $.fancybox.resize); + + if (currentOpts.centerOnScroll) { + $(window).bind("scroll.fb", $.fancybox.center); + } + + if (currentOpts.type == 'iframe') { + $('').appendTo(content); + } + + wrap.show(); + + busy = false; + + $.fancybox.center(); + + currentOpts.onComplete(currentArray, currentIndex, currentOpts); + + _preload_images(); + }, + + _preload_images = function() { + var href, + objNext; + + if ((currentArray.length -1) > currentIndex) { + href = currentArray[ currentIndex + 1 ].href; + + if (typeof href !== 'undefined' && href.match(imgRegExp)) { + objNext = new Image(); + objNext.src = href; + } + } + + if (currentIndex > 0) { + href = currentArray[ currentIndex - 1 ].href; + + if (typeof href !== 'undefined' && href.match(imgRegExp)) { + objNext = new Image(); + objNext.src = href; + } + } + }, + + _draw = function(pos) { + var dim = { + width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), + height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), + + top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), + left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) + }; + + if (typeof final_pos.opacity !== 'undefined') { + dim.opacity = pos < 0.5 ? 0.5 : pos; + } + + wrap.css(dim); + + content.css({ + 'width' : dim.width - currentOpts.padding * 2, + 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 + }); + }, + + _get_viewport = function() { + return [ + $(window).width() - (currentOpts.margin * 2), + $(window).height() - (currentOpts.margin * 2), + $(document).scrollLeft() + currentOpts.margin, + $(document).scrollTop() + currentOpts.margin + ]; + }, + + _get_zoom_to = function () { + var view = _get_viewport(), + to = {}, + resize = currentOpts.autoScale, + double_padding = currentOpts.padding * 2, + ratio; + + if (currentOpts.width.toString().indexOf('%') > -1) { + to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); + } else { + to.width = currentOpts.width + double_padding; + } + + if (currentOpts.height.toString().indexOf('%') > -1) { + to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); + } else { + to.height = currentOpts.height + double_padding; + } + + if (resize && (to.width > view[0] || to.height > view[1])) { + if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { + ratio = (currentOpts.width ) / (currentOpts.height ); + + if ((to.width ) > view[0]) { + to.width = view[0]; + to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); + } + + if ((to.height) > view[1]) { + to.height = view[1]; + to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); + } + + } else { + to.width = Math.min(to.width, view[0]); + to.height = Math.min(to.height, view[1]); + } + } + + to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); + to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); + + return to; + }, + + _get_obj_pos = function(obj) { + var pos = obj.offset(); + + pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; + pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; + + pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; + pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; + + pos.width = obj.width(); + pos.height = obj.height(); + + return pos; + }, + + _get_zoom_from = function() { + var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, + from = {}, + pos, + view; + + if (orig && orig.length) { + pos = _get_obj_pos(orig); + + from = { + width : pos.width + (currentOpts.padding * 2), + height : pos.height + (currentOpts.padding * 2), + top : pos.top - currentOpts.padding - 20, + left : pos.left - currentOpts.padding - 20 + }; + + } else { + view = _get_viewport(); + + from = { + width : currentOpts.padding * 2, + height : currentOpts.padding * 2, + top : parseInt(view[3] + view[1] * 0.5, 10), + left : parseInt(view[2] + view[0] * 0.5, 10) + }; + } + + return from; + }, + + _animate_loading = function() { + if (!loading.is(':visible')){ + clearInterval(loadingTimer); + return; + } + + $('div', loading).css('top', (loadingFrame * -40) + 'px'); - loadingFrame = (loadingFrame + 1) % 12; - }; + loadingFrame = (loadingFrame + 1) % 12; + }; - /* - * Public methods - */ + /* + * Public methods + */ - $.fn.fancybox = function(options) { - if (!$(this).length) { - return this; - } + $.fn.fancybox = function(options) { + if (!$(this).length) { + return this; + } - $(this) - .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) - .unbind('click.fb') - .bind('click.fb', function(e) { - e.preventDefault(); + $(this) + .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) + .unbind('click.fb') + .bind('click.fb', function(e) { + e.preventDefault(); - if (busy) { - return; - } + if (busy) { + return; + } - busy = true; + busy = true; - $(this).blur(); + $(this).blur(); - selectedArray = []; - selectedIndex = 0; + selectedArray = []; + selectedIndex = 0; - var rel = $(this).attr('rel') || ''; + var rel = $(this).attr('rel') || ''; - if (!rel || rel == '' || rel === 'nofollow') { - selectedArray.push(this); + if (!rel || rel == '' || rel === 'nofollow') { + selectedArray.push(this); - } else { - selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); - selectedIndex = selectedArray.index( this ); - } + } else { + selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); + selectedIndex = selectedArray.index( this ); + } - _start(); + _start(); - return; - }); + return; + }); - return this; - }; + return this; + }; - $.fancybox = function(obj) { - var opts; + $.fancybox = function(obj) { + var opts; - if (busy) { - return; - } + if (busy) { + return; + } - busy = true; - opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; + busy = true; + opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; - selectedArray = []; - selectedIndex = parseInt(opts.index, 10) || 0; + selectedArray = []; + selectedIndex = parseInt(opts.index, 10) || 0; - if ($.isArray(obj)) { - for (var i = 0, j = obj.length; i < j; i++) { - if (typeof obj[i] == 'object') { - $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); - } else { - obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); - } - } + if ($.isArray(obj)) { + for (var i = 0, j = obj.length; i < j; i++) { + if (typeof obj[i] == 'object') { + $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); + } else { + obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); + } + } - selectedArray = jQuery.merge(selectedArray, obj); + selectedArray = jQuery.merge(selectedArray, obj); - } else { - if (typeof obj == 'object') { - $(obj).data('fancybox', $.extend({}, opts, obj)); - } else { - obj = $({}).data('fancybox', $.extend({content : obj}, opts)); - } + } else { + if (typeof obj == 'object') { + $(obj).data('fancybox', $.extend({}, opts, obj)); + } else { + obj = $({}).data('fancybox', $.extend({content : obj}, opts)); + } - selectedArray.push(obj); - } + selectedArray.push(obj); + } - if (selectedIndex > selectedArray.length || selectedIndex < 0) { - selectedIndex = 0; - } + if (selectedIndex > selectedArray.length || selectedIndex < 0) { + selectedIndex = 0; + } - _start(); - }; + _start(); + }; - $.fancybox.showActivity = function() { - clearInterval(loadingTimer); + $.fancybox.showActivity = function() { + clearInterval(loadingTimer); - loading.show(); - loadingTimer = setInterval(_animate_loading, 66); - }; + loading.show(); + loadingTimer = setInterval(_animate_loading, 66); + }; - $.fancybox.hideActivity = function() { - loading.hide(); - }; + $.fancybox.hideActivity = function() { + loading.hide(); + }; - $.fancybox.next = function() { - return $.fancybox.pos( currentIndex + 1); - }; + $.fancybox.next = function() { + return $.fancybox.pos( currentIndex + 1); + }; - $.fancybox.prev = function() { - return $.fancybox.pos( currentIndex - 1); - }; + $.fancybox.prev = function() { + return $.fancybox.pos( currentIndex - 1); + }; - $.fancybox.pos = function(pos) { - if (busy) { - return; - } + $.fancybox.pos = function(pos) { + if (busy) { + return; + } - pos = parseInt(pos); + pos = parseInt(pos); - selectedArray = currentArray; + selectedArray = currentArray; - if (pos > -1 && pos < currentArray.length) { - selectedIndex = pos; - _start(); + if (pos > -1 && pos < currentArray.length) { + selectedIndex = pos; + _start(); - } else if (currentOpts.cyclic && currentArray.length > 1) { - selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; - _start(); - } + } else if (currentOpts.cyclic && currentArray.length > 1) { + selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; + _start(); + } - return; - }; + return; + }; - $.fancybox.cancel = function() { - if (busy) { - return; - } + $.fancybox.cancel = function() { + if (busy) { + return; + } - busy = true; + busy = true; - $.event.trigger('fancybox-cancel'); + $.event.trigger('fancybox-cancel'); - _abort(); + _abort(); - selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); + selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); - busy = false; - }; + busy = false; + }; - // Note: within an iframe use - parent.$.fancybox.close(); - $.fancybox.close = function() { - if (busy || wrap.is(':hidden')) { - return; - } + // Note: within an iframe use - parent.$.fancybox.close(); + $.fancybox.close = function() { + if (busy || wrap.is(':hidden')) { + return; + } - busy = true; + busy = true; - if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { - busy = false; - return; - } + if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { + busy = false; + return; + } - _abort(); + _abort(); - $(close.add( nav_left ).add( nav_right )).hide(); + $(close.add( nav_left ).add( nav_right )).hide(); - $(content.add( overlay )).unbind(); + $(content.add( overlay )).unbind(); - $(window).unbind("resize.fb scroll.fb"); - $(document).unbind('keydown.fb'); + $(window).unbind("resize.fb scroll.fb"); + $(document).unbind('keydown.fb'); - content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); + content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); - if (currentOpts.titlePosition !== 'inside') { - title.empty(); - } + if (currentOpts.titlePosition !== 'inside') { + title.empty(); + } - wrap.stop(); + wrap.stop(); - function _cleanup() { - overlay.fadeOut('fast'); + function _cleanup() { + overlay.fadeOut('fast'); - title.empty().hide(); - wrap.hide(); + title.empty().hide(); + wrap.hide(); - $.event.trigger('fancybox-cleanup'); + $.event.trigger('fancybox-cleanup'); - content.empty(); + content.empty(); - currentOpts.onClosed(currentArray, currentIndex, currentOpts); + currentOpts.onClosed(currentArray, currentIndex, currentOpts); - currentArray = selectedOpts = []; - currentIndex = selectedIndex = 0; - currentOpts = selectedOpts = {}; + currentArray = selectedOpts = []; + currentIndex = selectedIndex = 0; + currentOpts = selectedOpts = {}; - busy = false; - } + busy = false; + } - if (currentOpts.transitionOut == 'elastic') { - start_pos = _get_zoom_from(); + if (currentOpts.transitionOut == 'elastic') { + start_pos = _get_zoom_from(); - var pos = wrap.position(); + var pos = wrap.position(); - final_pos = { - top : pos.top , - left : pos.left, - width : wrap.width(), - height : wrap.height() - }; + final_pos = { + top : pos.top , + left : pos.left, + width : wrap.width(), + height : wrap.height() + }; - if (currentOpts.opacity) { - final_pos.opacity = 1; - } + if (currentOpts.opacity) { + final_pos.opacity = 1; + } - title.empty().hide(); + title.empty().hide(); - fx.prop = 1; + fx.prop = 1; - $(fx).animate({ prop: 0 }, { - duration : currentOpts.speedOut, - easing : currentOpts.easingOut, - step : _draw, - complete : _cleanup - }); + $(fx).animate({ prop: 0 }, { + duration : currentOpts.speedOut, + easing : currentOpts.easingOut, + step : _draw, + complete : _cleanup + }); - } else { - wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); - } - }; + } else { + wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); + } + }; - $.fancybox.resize = function() { - if (overlay.is(':visible')) { - overlay.css('height', $(document).height()); - } + $.fancybox.resize = function() { + if (overlay.is(':visible')) { + overlay.css('height', $(document).height()); + } - $.fancybox.center(true); - }; + $.fancybox.center(true); + }; - $.fancybox.center = function() { - var view, align; + $.fancybox.center = function() { + var view, align; - if (busy) { - return; - } + if (busy) { + return; + } - align = arguments[0] === true ? 1 : 0; - view = _get_viewport(); + align = arguments[0] === true ? 1 : 0; + view = _get_viewport(); - if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { - return; - } + if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { + return; + } - wrap - .stop() - .animate({ - 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), - 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) - }, typeof arguments[0] == 'number' ? arguments[0] : 200); - }; + wrap + .stop() + .animate({ + 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), + 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) + }, typeof arguments[0] == 'number' ? arguments[0] : 200); + }; - $.fancybox.init = function() { - if ($("#fancybox-wrap").length) { - return; - } + $.fancybox.init = function() { + if ($("#fancybox-wrap").length) { + return; + } - $('body').append( - tmp = $('
    '), - loading = $('
    '), - overlay = $('
    '), - wrap = $('
    ') - ); + $('body').append( + tmp = $('
    '), + loading = $('
    '), + overlay = $('
    '), + wrap = $('
    ') + ); - outer = $('
    ') - .append('
    ') - .appendTo( wrap ); - - outer.append( - content = $('
    '), - close = $(''), - title = $('
    '), - - nav_left = $(''), - nav_right = $('') - ); - - close.click($.fancybox.close); - loading.click($.fancybox.cancel); - - nav_left.click(function(e) { - e.preventDefault(); - $.fancybox.prev(); - }); - - nav_right.click(function(e) { - e.preventDefault(); - $.fancybox.next(); - }); - - if ($.fn.mousewheel) { - wrap.bind('mousewheel.fb', function(e, delta) { - if (busy) { - e.preventDefault(); - - } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { - e.preventDefault(); - $.fancybox[ delta > 0 ? 'prev' : 'next'](); - } - }); - } - - if (!$.support.opacity) { - wrap.addClass('fancybox-ie'); - } - - if (isIE6) { - loading.addClass('fancybox-ie6'); - wrap.addClass('fancybox-ie6'); - - $('').prependTo(outer); - } - }; - - $.fn.fancybox.defaults = { - padding : 10, - margin : 40, - opacity : false, - modal : false, - cyclic : false, - scrolling : 'auto', // 'auto', 'yes' or 'no' - - width : 560, - height : 340, - - autoScale : true, - autoDimensions : true, - centerOnScroll : false, - - ajax : {}, - swf : { wmode: 'transparent' }, - - hideOnOverlayClick : true, - hideOnContentClick : false, - - overlayShow : true, - overlayOpacity : 0.7, - overlayColor : '#777', - - titleShow : true, - titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' - titleFormat : null, - titleFromAlt : false, - - transitionIn : 'fade', // 'elastic', 'fade' or 'none' - transitionOut : 'fade', // 'elastic', 'fade' or 'none' - - speedIn : 300, - speedOut : 300, - - changeSpeed : 300, - changeFade : 'fast', - - easingIn : 'swing', - easingOut : 'swing', - - showCloseButton : true, - showNavArrows : true, - enableEscapeButton : true, - enableKeyboardNav : true, - - onStart : function(){}, - onCancel : function(){}, - onComplete : function(){}, - onCleanup : function(){}, - onClosed : function(){}, - onError : function(){} - }; - - $(document).ready(function() { - $.fancybox.init(); - }); + outer = $('
    ') + .append('
    ') + .appendTo( wrap ); + + outer.append( + content = $('
    '), + close = $(''), + title = $('
    '), + + nav_left = $(''), + nav_right = $('') + ); + + close.click($.fancybox.close); + loading.click($.fancybox.cancel); + + nav_left.click(function(e) { + e.preventDefault(); + $.fancybox.prev(); + }); + + nav_right.click(function(e) { + e.preventDefault(); + $.fancybox.next(); + }); + + if ($.fn.mousewheel) { + wrap.bind('mousewheel.fb', function(e, delta) { + if (busy) { + e.preventDefault(); + + } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { + e.preventDefault(); + $.fancybox[ delta > 0 ? 'prev' : 'next'](); + } + }); + } + + if (!$.support.opacity) { + wrap.addClass('fancybox-ie'); + } + + if (isIE6) { + loading.addClass('fancybox-ie6'); + wrap.addClass('fancybox-ie6'); + + $('').prependTo(outer); + } + }; + + $.fn.fancybox.defaults = { + padding : 10, + margin : 40, + opacity : false, + modal : false, + cyclic : false, + scrolling : 'auto', // 'auto', 'yes' or 'no' + + width : 560, + height : 340, + + autoScale : true, + autoDimensions : true, + centerOnScroll : false, + + ajax : {}, + swf : { wmode: 'transparent' }, + + hideOnOverlayClick : true, + hideOnContentClick : false, + + overlayShow : true, + overlayOpacity : 0.7, + overlayColor : '#777', + + titleShow : true, + titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' + titleFormat : null, + titleFromAlt : false, + + transitionIn : 'fade', // 'elastic', 'fade' or 'none' + transitionOut : 'fade', // 'elastic', 'fade' or 'none' + + speedIn : 300, + speedOut : 300, + + changeSpeed : 300, + changeFade : 'fast', + + easingIn : 'swing', + easingOut : 'swing', + + showCloseButton : true, + showNavArrows : true, + enableEscapeButton : true, + enableKeyboardNav : true, + + onStart : function(){}, + onCancel : function(){}, + onComplete : function(){}, + onCleanup : function(){}, + onClosed : function(){}, + onError : function(){} + }; + + $(document).ready(function() { + $.fancybox.init(); + }); })(jQuery); \ No newline at end of file diff --git a/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.pack.js b/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.pack.js old mode 100755 new mode 100644 index b97e31e..1373ed0 --- a/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.pack.js +++ b/assets/grocery_crud/js/jquery_plugins/jquery.fancybox.pack.js @@ -3,10 +3,10 @@ * Simple and fancy lightbox alternative * * Examples and documentation at: http://fancybox.net - * + * * Copyright (c) 2008 - 2010 Janis Skarnelis * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. - * + * * Version: 1.3.4 (11/11/2010) * Requires: jQuery v1.3+ * diff --git a/assets/grocery_crud/js/jquery_plugins/jquery.fileupload.js b/assets/grocery_crud/js/jquery_plugins/jquery.fileupload.js old mode 100755 new mode 100644 diff --git a/assets/grocery_crud/js/jquery_plugins/jquery.form.js b/assets/grocery_crud/js/jquery_plugins/jquery.form.js new file mode 100644 index 0000000..9606f91 --- /dev/null +++ b/assets/grocery_crud/js/jquery_plugins/jquery.form.js @@ -0,0 +1,1278 @@ +/*! + * jQuery Form Plugin + * version: 3.50.0-2014.02.05 + * Requires jQuery v1.5 or later + * Copyright (c) 2013 M. Alsup + * Examples and documentation at: http://malsup.com/jquery/form/ + * Project repository: https://github.com/malsup/form + * Dual licensed under the MIT and GPL licenses. + * https://github.com/malsup/form#copyright-and-license + */ +/*global ActiveXObject */ + +// AMD support +(function (factory) { + "use strict"; + if (typeof define === 'function' && define.amd) { + // using AMD; register as anon module + define(['jquery'], factory); + } else { + // no AMD; invoke directly + factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto ); + } +} + +(function($) { +"use strict"; + +/* + Usage Note: + ----------- + Do not use both ajaxSubmit and ajaxForm on the same form. These + functions are mutually exclusive. Use ajaxSubmit if you want + to bind your own submit handler to the form. For example, + + $(document).ready(function() { + $('#myForm').on('submit', function(e) { + e.preventDefault(); // <-- important + $(this).ajaxSubmit({ + target: '#output' + }); + }); + }); + + Use ajaxForm when you want the plugin to manage all the event binding + for you. For example, + + $(document).ready(function() { + $('#myForm').ajaxForm({ + target: '#output' + }); + }); + + You can also use ajaxForm with delegation (requires jQuery v1.7+), so the + form does not have to exist when you invoke ajaxForm: + + $('#myForm').ajaxForm({ + delegation: true, + target: '#output' + }); + + When using ajaxForm, the ajaxSubmit function will be invoked for you + at the appropriate time. +*/ + +/** + * Feature detection + */ +var feature = {}; +feature.fileapi = $("").get(0).files !== undefined; +feature.formdata = window.FormData !== undefined; + +var hasProp = !!$.fn.prop; + +// attr2 uses prop when it can but checks the return type for +// an expected string. this accounts for the case where a form +// contains inputs with names like "action" or "method"; in those +// cases "prop" returns the element +$.fn.attr2 = function() { + if ( ! hasProp ) { + return this.attr.apply(this, arguments); + } + var val = this.prop.apply(this, arguments); + if ( ( val && val.jquery ) || typeof val === 'string' ) { + return val; + } + return this.attr.apply(this, arguments); +}; + +/** + * ajaxSubmit() provides a mechanism for immediately submitting + * an HTML form using AJAX. + */ +$.fn.ajaxSubmit = function(options) { + /*jshint scripturl:true */ + + // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) + if (!this.length) { + log('ajaxSubmit: skipping submit process - no element selected'); + return this; + } + + var method, action, url, $form = this; + + if (typeof options == 'function') { + options = { success: options }; + } + else if ( options === undefined ) { + options = {}; + } + + method = options.type || this.attr2('method'); + action = options.url || this.attr2('action'); + + url = (typeof action === 'string') ? $.trim(action) : ''; + url = url || window.location.href || ''; + if (url) { + // clean url (don't include hash vaue) + url = (url.match(/^([^#]+)/)||[])[1]; + } + + options = $.extend(true, { + url: url, + success: $.ajaxSettings.success, + type: method || $.ajaxSettings.type, + iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' + }, options); + + // hook for manipulating the form data before it is extracted; + // convenient for use with rich editors like tinyMCE or FCKEditor + var veto = {}; + this.trigger('form-pre-serialize', [this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); + return this; + } + + // provide opportunity to alter form data before it is serialized + if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSerialize callback'); + return this; + } + + var traditional = options.traditional; + if ( traditional === undefined ) { + traditional = $.ajaxSettings.traditional; + } + + var elements = []; + var qx, a = this.formToArray(options.semantic, elements); + if (options.data) { + options.extraData = options.data; + qx = $.param(options.data, traditional); + } + + // give pre-submit callback an opportunity to abort the submit + if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSubmit callback'); + return this; + } + + // fire vetoable 'validate' event + this.trigger('form-submit-validate', [a, this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); + return this; + } + + var q = $.param(a, traditional); + if (qx) { + q = ( q ? (q + '&' + qx) : qx ); + } + if (options.type.toUpperCase() == 'GET') { + options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; + options.data = null; // data is null for 'get' + } + else { + options.data = q; // data is the query string for 'post' + } + + var callbacks = []; + if (options.resetForm) { + callbacks.push(function() { $form.resetForm(); }); + } + if (options.clearForm) { + callbacks.push(function() { $form.clearForm(options.includeHidden); }); + } + + // perform a load on the target only if dataType is not provided + if (!options.dataType && options.target) { + var oldSuccess = options.success || function(){}; + callbacks.push(function(data) { + var fn = options.replaceTarget ? 'replaceWith' : 'html'; + $(options.target)[fn](data).each(oldSuccess, arguments); + }); + } + else if (options.success) { + callbacks.push(options.success); + } + + options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg + var context = options.context || this ; // jQuery 1.4+ supports scope context + for (var i=0, max=callbacks.length; i < max; i++) { + callbacks[i].apply(context, [data, status, xhr || $form, $form]); + } + }; + + if (options.error) { + var oldError = options.error; + options.error = function(xhr, status, error) { + var context = options.context || this; + oldError.apply(context, [xhr, status, error, $form]); + }; + } + + if (options.complete) { + var oldComplete = options.complete; + options.complete = function(xhr, status) { + var context = options.context || this; + oldComplete.apply(context, [xhr, status, $form]); + }; + } + + // are there files to upload? + + // [value] (issue #113), also see comment: + // https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219 + var fileInputs = $('input[type=file]:enabled', this).filter(function() { return $(this).val() !== ''; }); + + var hasFileInputs = fileInputs.length > 0; + var mp = 'multipart/form-data'; + var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); + + var fileAPI = feature.fileapi && feature.formdata; + log("fileAPI :" + fileAPI); + var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI; + + var jqxhr; + + // options.iframe allows user to force iframe mode + // 06-NOV-09: now defaulting to iframe mode if file input is detected + if (options.iframe !== false && (options.iframe || shouldUseFrame)) { + // hack to fix Safari hang (thanks to Tim Molendijk for this) + // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + if (options.closeKeepAlive) { + $.get(options.closeKeepAlive, function() { + jqxhr = fileUploadIframe(a); + }); + } + else { + jqxhr = fileUploadIframe(a); + } + } + else if ((hasFileInputs || multipart) && fileAPI) { + jqxhr = fileUploadXhr(a); + } + else { + jqxhr = $.ajax(options); + } + + $form.removeData('jqxhr').data('jqxhr', jqxhr); + + // clear element array + for (var k=0; k < elements.length; k++) { + elements[k] = null; + } + + // fire 'notify' event + this.trigger('form-submit-notify', [this, options]); + return this; + + // utility fn for deep serialization + function deepSerialize(extraData){ + var serialized = $.param(extraData, options.traditional).split('&'); + var len = serialized.length; + var result = []; + var i, part; + for (i=0; i < len; i++) { + // #252; undo param space replacement + serialized[i] = serialized[i].replace(/\+/g,' '); + part = serialized[i].split('='); + // #278; use array instead of object storage, favoring array serializations + result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]); + } + return result; + } + + // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz) + function fileUploadXhr(a) { + var formdata = new FormData(); + + for (var i=0; i < a.length; i++) { + formdata.append(a[i].name, a[i].value); + } + + if (options.extraData) { + var serializedData = deepSerialize(options.extraData); + for (i=0; i < serializedData.length; i++) { + if (serializedData[i]) { + formdata.append(serializedData[i][0], serializedData[i][1]); + } + } + } + + options.data = null; + + var s = $.extend(true, {}, $.ajaxSettings, options, { + contentType: false, + processData: false, + cache: false, + type: method || 'POST' + }); + + if (options.uploadProgress) { + // workaround because jqXHR does not expose upload property + s.xhr = function() { + var xhr = $.ajaxSettings.xhr(); + if (xhr.upload) { + xhr.upload.addEventListener('progress', function(event) { + var percent = 0; + var position = event.loaded || event.position; /*event.position is deprecated*/ + var total = event.total; + if (event.lengthComputable) { + percent = Math.ceil(position / total * 100); + } + options.uploadProgress(event, position, total, percent); + }, false); + } + return xhr; + }; + } + + s.data = null; + var beforeSend = s.beforeSend; + s.beforeSend = function(xhr, o) { + //Send FormData() provided by user + if (options.formData) { + o.data = options.formData; + } + else { + o.data = formdata; + } + if(beforeSend) { + beforeSend.call(this, xhr, o); + } + }; + return $.ajax(s); + } + + // private function for handling file uploads (hat tip to YAHOO!) + function fileUploadIframe(a) { + var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle; + var deferred = $.Deferred(); + + // #341 + deferred.abort = function(status) { + xhr.abort(status); + }; + + if (a) { + // ensure that every serialized input is still enabled + for (i=0; i < elements.length; i++) { + el = $(elements[i]); + if ( hasProp ) { + el.prop('disabled', false); + } + else { + el.removeAttr('disabled'); + } + } + } + + s = $.extend(true, {}, $.ajaxSettings, options); + s.context = s.context || s; + id = 'jqFormIO' + (new Date().getTime()); + if (s.iframeTarget) { + $io = $(s.iframeTarget); + n = $io.attr2('name'); + if (!n) { + $io.attr2('name', id); + } + else { + id = n; + } + } + else { + $io = $('');return s.append(t,true);};j.add('maximize',{init:function(s){var t=s.lang,u=a.document,v=u.getWindow(),w,x,y,z;function A(){var C=v.getViewPaneSize();z&&z.setStyles({width:C.width+'px',height:C.height+'px'});s.resize(C.width,C.height,null,true);};var B=2;s.addCommand('maximize',{modes:{wysiwyg:!b.iOS,source:!b.iOS},readOnly:1,editorFocus:false,exec:function(){var C=s.container.getChild(1),D=s.getThemeSpace('contents');if(s.mode=='wysiwyg'){var E=s.getSelection();w=E&&E.getRanges();x=v.getScrollPosition();}else{var F=s.textarea.$;w=!c&&[F.selectionStart,F.selectionEnd];x=[F.scrollLeft,F.scrollTop];}if(this.state==2){v.on('resize',A);y=v.getScrollPosition();var G=s.container;while(G=G.getParent()){G.setCustomData('maximize_saved_styles',o(G));G.setStyle('z-index',s.config.baseFloatZIndex-1);}D.setCustomData('maximize_saved_styles',o(D,true));C.setCustomData('maximize_saved_styles',o(C,true));var H={overflow:b.webkit?'':'hidden',width:0,height:0};u.getDocumentElement().setStyles(H);!b.gecko&&u.getDocumentElement().setStyle('position','fixed');!(b.gecko&&b.quirks)&&u.getBody().setStyles(H);c?setTimeout(function(){v.$.scrollTo(0,0);},0):v.$.scrollTo(0,0);C.setStyle('position',b.gecko&&b.quirks?'fixed':'absolute');C.$.offsetLeft;C.setStyles({'z-index':s.config.baseFloatZIndex-1,left:'0px',top:'0px'});z=r(C);C.addClass('cke_maximized');A();var I=C.getDocumentPosition();C.setStyles({left:-1*I.x+'px',top:-1*I.y+'px'}); -b.gecko&&q(s);}else if(this.state==1){v.removeListener('resize',A);var J=[D,C];for(var K=0;K ');s.children.length=0;s.add(u);var v=s.attributes;delete v['aria-label'];delete v.contenteditable;delete v.title;}return t;}}},5);if(p)p.addRules({elements:{div:function(r){var s=r.attributes,t=s&&s.style,u=t&&r.children.length==1&&r.children[0],v=u&&u.name=='span'&&u.attributes.style;if(v&&/page-break-after\s*:\s*always/i.test(t)&&/display\s*:\s*none/i.test(v)){s.contenteditable='false';s['class']='cke_pagebreak';s['data-cke-display-name']='pagebreak';s['aria-label']=n;s.title=n;r.children.length=0;}}}});},requires:['fakeobjects']});j.pagebreakCmd={exec:function(m){var n=m.lang.pagebreakAlt,o=h.createFromHtml('
    '+'
    ',m.document),p=m.getSelection().getRanges(true);m.fire('saveSnapshot');for(var q,r=p.length-1;r>=0;r--){q=p[r];if(r1&&n.substr(n.length-1,1)=='%')n=parseInt(window.screen.width*parseInt(n,10)/100,10);if(typeof o=='string'&&o.length>1&&o.substr(o.length-1,1)=='%')o=parseInt(window.screen.height*parseInt(o,10)/100,10);if(n<640)n=640;if(o<420)o=420;var q=parseInt((window.screen.height-o)/2,10),r=parseInt((window.screen.width-n)/2,10);p=(p||'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes')+',width='+n+',height='+o+',top='+q+',left='+r;var s=window.open('',null,p,true);if(!s)return false;try{var t=navigator.userAgent.toLowerCase();if(t.indexOf(' chrome/')==-1){s.moveTo(r,q);s.resizeTo(n,o);}s.focus();s.location.href=m;}catch(u){s=window.open(m,null,p,true);}return true;}});(function(){var m,n={modes:{wysiwyg:1,source:1},canUndo:false,readOnly:1,exec:function(p){var q,r=p.config,s=r.baseHref?'':'',t=b.isCustomDomain();if(r.fullPage)q=p.getData().replace(//,'$&'+s).replace(/[^>]*(?=<\/title>)/,'$& — '+p.lang.preview);else{var u=''+''+s+''+p.lang.preview+''+e.buildStyleHtml(p.config.contentsCss)+''+u+p.getData()+'';}var w=640,x=420,y=80;try{var z=window.screen;w=Math.round(z.width*0.8);x=Math.round(z.height*0.7);y=Math.round(z.width*0.1);}catch(D){}var A='';if(t){window._cke_htmlToLoad=q;A='javascript:void( (function(){document.open();document.domain="'+document.domain+'";'+'document.write( window.opener._cke_htmlToLoad );'+'document.close();'+'window.opener._cke_htmlToLoad = null;'+'})() )'; -}if(b.gecko){window._cke_htmlToLoad=q;A=m+'preview.html';}var B=window.open(A,null,'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+w+',height='+x+',left='+y);if(!t&&!b.gecko){var C=B.document;C.open();C.write(q);C.close();b.webkit&&setTimeout(function(){C.body.innerHTML+='';},0);}}},o='preview';j.add(o,{init:function(p){m=this.path;p.addCommand(o,n);p.ui.addButton('Preview',{label:p.lang.preview,command:o});}});})();j.add('print',{init:function(m){var n='print',o=m.addCommand(n,j.print);m.ui.addButton('Print',{label:m.lang.print,command:n});}});j.print={exec:function(m){if(b.opera)return;else if(b.gecko)m.window.$.print();else m.document.$.execCommand('Print');},canUndo:false,readOnly:1,modes:{wysiwyg:!b.opera}};j.add('removeformat',{requires:['selection'],init:function(m){m.addCommand('removeFormat',j.removeformat.commands.removeformat);m.ui.addButton('RemoveFormat',{label:m.lang.removeFormat,command:'removeFormat'});m._.removeFormat={filters:[]};}});j.removeformat={commands:{removeformat:{exec:function(m){var n=m._.removeFormatRegex||(m._.removeFormatRegex=new RegExp('^(?:'+m.config.removeFormatTags.replace(/,/g,'|')+')$','i')),o=m._.removeAttributes||(m._.removeAttributes=m.config.removeFormatAttributes.split(',')),p=j.removeformat.filter,q=m.getSelection().getRanges(1),r=q.createIterator(),s;while(s=r.getNextRange()){if(!s.collapsed)s.enlarge(1);var t=s.createBookmark(),u=t.startNode,v=t.endNode,w,x=function(z){var A=new d.elementPath(z),B=A.elements;for(var C=1,D;D=B[C];C++){if(D.equals(A.block)||D.equals(A.blockLimit))break;if(n.test(D.getName())&&p(m,D))z.breakParent(D);}};x(u);if(v){x(v);w=u.getNextSourceNode(true,1);while(w){if(w.equals(v))break;var y=w.getNextSourceNode(false,1);if(!(w.getName()=='img'&&w.data('cke-realelement'))&&p(m,w))if(n.test(w.getName()))w.remove(1);else{w.removeAttributes(o);m.fire('removeFormatCleanup',w);}w=y;}}s.moveToBookmark(t);}m.getSelection().selectRanges(q);}}},filter:function(m,n){var o=m._.removeFormat.filters;for(var p=0;pr.width&&(n.resize_minWidth=r.width);n.resize_minHeight>r.height&&(n.resize_minHeight=r.height);a.document.on('mousemove',u);a.document.on('mouseup',v);if(m.document){m.document.on('mousemove',u);m.document.on('mouseup',v);}});m.on('destroy',function(){e.removeFunction(w);});m.on('themeSpace',function(x){if(x.data.space=='bottom'){var y='';if(s&&!t)y=' cke_resizer_horizontal';if(!s&&t)y=' cke_resizer_vertical';var z='
    ';o=='ltr'&&y=='ltr'?x.data.html+=z:x.data.html=z+x.data.html;}},m,null,100);}}});(function(){var m={modes:{wysiwyg:1,source:1},readOnly:1,exec:function(o){var p=o.element.$.form;if(p)try{p.submit();}catch(q){if(p.submit.click)p.submit.click();}}},n='save';j.add(n,{init:function(o){var p=o.addCommand(n,m);p.modes={wysiwyg:!!o.element.$.form};o.ui.addButton('Save',{label:o.lang.save,command:n});}});})();(function(){var m='scaytcheck',n='';function o(t,u){var v=0,w;for(w in u){if(u[w]==t){v=1;break;}}return v;};var p=function(){var t=this,u=function(){var y=t.config,z={};z.srcNodeRef=t.document.getWindow().$.frameElement;z.assocApp='CKEDITOR.'+a.version+'@'+a.revision;z.customerid=y.scayt_customerid||'1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';z.customDictionaryIds=y.scayt_customDictionaryIds||'';z.userDictionaryName=y.scayt_userDictionaryName||'';z.sLang=y.scayt_sLang||'en_US'; -z.onLoad=function(){if(!(c&&b.version<8))this.addStyle(this.selectorCss(),'padding-bottom: 2px !important;');if(t.focusManager.hasFocus&&!q.isControlRestored(t))this.focus();};z.onBeforeChange=function(){if(q.getScayt(t)&&!t.checkDirty())setTimeout(function(){t.resetDirty();},0);};var A=window.scayt_custom_params;if(typeof A=='object')for(var B in A)z[B]=A[B];if(q.getControlId(t))z.id=q.getControlId(t);var C=new window.scayt(z);C.afterMarkupRemove.push(function(E){new h(E,C.document).mergeSiblings();});var D=q.instances[t.name];if(D){C.sLang=D.sLang;C.option(D.option());C.paused=D.paused;}q.instances[t.name]=C;try{C.setDisabled(q.isPaused(t)===false);}catch(E){}t.fire('showScaytState');};t.on('contentDom',u);t.on('contentDomUnload',function(){var y=a.document.getElementsByTag('script'),z=/^dojoIoScript(\d+)$/i,A=/^https?:\/\/svc\.webspellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;for(var B=0;B=0){this.setState(0);q.loadEngine(t);}}};j.add('scayt',{requires:['menubutton'],beforeInit:function(t){var u=t.config.scayt_contextMenuItemsOrder||'suggest|moresuggest|control',v='';u=u.split('|');if(u&&u.length)for(var w=0;w tr > td, .%1 table.%2 > tr > th,','.%1 table.%2 > tbody > tr > td, .%1 table.%2 > tbody > tr > th,','.%1 table.%2 > thead > tr > td, .%1 table.%2 > thead > tr > th,','.%1 table.%2 > tfoot > tr > td, .%1 table.%2 > tfoot > tr > th','{','border : #d3d3d3 1px dotted','}']).join('');n=o.replace(/%2/g,m).replace(/%1/g,'cke_show_borders ');var p={preserveState:true,editorFocus:false,readOnly:1,exec:function(q){this.toggleState();this.refresh(q);},refresh:function(q){if(q.document){var r=this.state==1?'addClass':'removeClass';q.document.getBody()[r]('cke_show_borders');}}};j.add('showborders',{requires:['wysiwygarea'],modes:{wysiwyg:1},init:function(q){var r=q.addCommand('showborders',p);r.canUndo=false;if(q.config.startupShowBorders!==false)r.setState(1);q.addCss(n);q.on('mode',function(){if(r.state!=0)r.refresh(q);},null,null,100);q.on('contentDom',function(){if(r.state!=0)r.refresh(q);});q.on('removeFormatCleanup',function(s){var t=s.data;if(q.getCommand('showborders').state==1&&t.is('table')&&(!t.hasAttribute('border')||parseInt(t.getAttribute('border'),10)<=0))t.addClass(m);});},afterInit:function(q){var r=q.dataProcessor,s=r&&r.dataFilter,t=r&&r.htmlFilter; -if(s)s.addRules({elements:{table:function(u){var v=u.attributes,w=v['class'],x=parseInt(v.border,10);if((!x||x<=0)&&(!w||w.indexOf(m)==-1))v['class']=(w||'')+' '+m;}}});if(t)t.addRules({elements:{table:function(u){var v=u.attributes,w=v['class'];w&&(v['class']=w.replace(m,'').replace(/\s{2}/,' ').replace(/^\s+|\s+$/,''));}}});}});a.on('dialogDefinition',function(q){var r=q.data.name;if(r=='table'||r=='tableProperties'){var s=q.data.definition,t=s.getContents('info'),u=t.get('txtBorder'),v=u.commit;u.commit=e.override(v,function(y){return function(z,A){y.apply(this,arguments);var B=parseInt(this.getValue(),10);A[!B||B<=0?'addClass':'removeClass'](m);};});var w=s.getContents('advanced'),x=w&&w.get('advCSSClasses');if(x){x.setup=e.override(x.setup,function(y){return function(){y.apply(this,arguments);this.setValue(this.getValue().replace(/cke_show_border/,''));};});x.commit=e.override(x.commit,function(y){return function(z,A){y.apply(this,arguments);if(!parseInt(A.getAttribute('border'),10))A.addClass('cke_show_border');};});}}});})();j.add('sourcearea',{requires:['editingblock'],init:function(m){var n=j.sourcearea,o=a.document.getWindow();m.on('editingBlockReady',function(){var p,q;m.addMode('source',{load:function(r,s){if(c&&b.version<8)r.setStyle('position','relative');m.textarea=p=new h('textarea');p.setAttributes({dir:'ltr',tabIndex:b.webkit?-1:m.tabIndex,role:'textbox','aria-label':m.lang.editorTitle.replace('%1',m.name)});p.addClass('cke_source');p.addClass('cke_enable_context_menu');m.readOnly&&p.setAttribute('readOnly','readonly');var t={width:b.ie7Compat?'99%':'100%',height:'100%',resize:'none',outline:'none','text-align':'left'};if(c){q=function(){p.hide();p.setStyle('height',r.$.clientHeight+'px');p.setStyle('width',r.$.clientWidth+'px');p.show();};m.on('resize',q);o.on('resize',q);setTimeout(q,0);}r.setHtml('');r.append(p);p.setStyles(t);m.fire('ariaWidget',p);p.on('blur',function(){m.focusManager.blur();});p.on('focus',function(){m.focusManager.focus();});m.mayBeDirty=true;this.loadData(s);var u=m.keystrokeHandler;if(u)u.attach(p);setTimeout(function(){m.mode='source';m.fire('mode',{previousMode:m._.previousMode});},b.gecko||b.webkit?100:0);},loadData:function(r){p.setValue(r);m.fire('dataReady');},getData:function(){return p.getValue();},getSnapshotData:function(){return p.getValue();},unload:function(r){p.clearCustomData();m.textarea=p=null;if(q){m.removeListener('resize',q);o.removeListener('resize',q);}if(c&&b.version<8)r.removeStyle('position'); -},focus:function(){p.focus();}});});m.on('readOnly',function(){if(m.mode=='source')if(m.readOnly)m.textarea.setAttribute('readOnly','readonly');else m.textarea.removeAttribute('readOnly');});m.addCommand('source',n.commands.source);if(m.ui.addButton)m.ui.addButton('Source',{label:m.lang.source,command:'source'});m.on('mode',function(){m.getCommand('source').setState(m.mode=='source'?1:2);});}});j.sourcearea={commands:{source:{modes:{wysiwyg:1,source:1},editorFocus:false,readOnly:1,exec:function(m){if(m.mode=='wysiwyg')m.fire('saveSnapshot');m.getCommand('source').setState(0);m.setMode(m.mode=='source'?'wysiwyg':'source');},canUndo:false}}};(function(){j.add('stylescombo',{requires:['richcombo','styles'],init:function(n){var o=n.config,p=n.lang.stylesCombo,q={},r=[],s;function t(u){n.getStylesSet(function(v){if(!r.length){var w,x;for(var y=0,z=v.length;y0)return;if(S.type==1&&m.test(S.getName())&&!S.getCustomData('selected_cell')){h.setMarker(J,S,'selected_cell',true);I.push(S);}};for(var L=0;L1&&V&&U[Y]==V[Y]){Z=U[Y];Z.rowSpan+=1;}else{Z=new h(U[Y]).clone();Z.removeAttribute('rowSpan');!c&&Z.appendBogus();X.append(Z);Z=Z.$;}Y+=Z.colSpan-1;}H?X.insertBefore(S):X.insertAfter(S);};function q(G){if(G instanceof d.selection){var H=n(G),I=H[0],J=I.getAscendant('table'),K=e.buildTableMap(J),L=H[0].getParent(),M=L.$.rowIndex,N=H[H.length-1],O=N.getParent().$.rowIndex+N.$.rowSpan-1,P=[]; -for(var Q=M;Q<=O;Q++){var R=K[Q],S=new h(J.$.rows[Q]);for(var T=0;T0?X[M-1]:null)||J.$.parentNode);for(Q=P.length;Q>=0;Q--)q(P[Q]);return Y;}else if(G instanceof h){J=G.getAscendant('table');if(J.$.rows.length==1)J.remove();else G.remove();}return null;};function r(G,H){var I=G.getParent(),J=I.$.cells,K=0;for(var L=0;LI)I=K;}return I;};function t(G,H){var I=n(G),J=I[0],K=J.getAscendant('table'),L=s(I,1),M=s(I),N=H?L:M,O=e.buildTableMap(K),P=[],Q=[],R=O.length;for(var S=0;S1&&Q[S]==P[S]){U=P[S];U.colSpan+=1;}else{U=new h(P[S]).clone();U.removeAttribute('colSpan');!c&&U.appendBogus();U[H?'insertBefore':'insertAfter'].call(U,new h(P[S]));U=U.$;}S+=U.rowSpan-1;}};function u(G){var H=n(G),I=H[0],J=H[H.length-1],K=I.getAscendant('table'),L=e.buildTableMap(K),M,N,O=[];for(var P=0,Q=L.length;P1){L=H[J-1]+1;break;}}if(!L)L=H[0]>0?H[0]-1:H[H.length-1]+1;var N=I.$.rows;for(J=0,K=N.length;J=0;K--)x(H[K]);if(J)z(J,true);else if(I)I.remove();}else if(G instanceof h){var L=G.getParent();if(L.getChildCount()==1)L.remove(); -else G.remove();}};function y(G){var H=G.getBogus();H&&H.remove();G.trim();};function z(G,H){var I=new d.range(G.getDocument());if(!I['moveToElementEdit'+(H?'End':'Start')](G)){I.selectNodeContents(G);I.collapse(H?false:true);}I.select(true);};function A(G,H,I){var J=G[H];if(typeof I=='undefined')return J;for(var K=0;J&&K1)J+=K[H].rowSpan-1;}return I;};function C(G,H,I){var J=n(G),K;if((H?J.length!=1:J.length<2)||(K=G.getCommonAncestor())&&K.type==1&&K.is('table'))return false;var L,M=J[0],N=M.getAscendant('table'),O=e.buildTableMap(N),P=O.length,Q=O[0].length,R=M.getParent().$.rowIndex,S=A(O,R,M);if(H){var T;try{var U=parseInt(M.getAttribute('rowspan'),10)||1,V=parseInt(M.getAttribute('colspan'),10)||1;T=O[H=='up'?R-U:H=='down'?R+U:R][H=='left'?S-V:H=='right'?S+V:S];}catch(an){return false;}if(!T||M.$==T)return false;J[H=='up'||H=='left'?'unshift':'push'](new h(T));}var W=M.getDocument(),X=R,Y=0,Z=0,aa=!I&&new d.documentFragment(W),ab=0;for(var ac=0;ac=Q)M.removeAttribute('rowSpan');else M.$.rowSpan=Y;if(Y>=P)M.removeAttribute('colSpan');else M.$.colSpan=Z;var ak=new d.nodeList(N.$.rows),al=ak.count();for(ac=al-1;ac>=0;ac--){var am=ak.getItem(ac);if(!am.$.cells.length){am.remove();al++;continue;}}return M;}else return Y*Z==ab;};function D(G,H){var I=n(G);if(I.length>1)return false;else if(H)return true;var J=I[0],K=J.getParent(),L=K.getAscendant('table'),M=e.buildTableMap(L),N=K.$.rowIndex,O=A(M,N,J),P=J.$.rowSpan,Q,R,S,T;if(P>1){R=Math.ceil(P/2);S=Math.floor(P/2);T=N+R;var U=new h(L.$.rows[T]),V=A(M,T),W;Q=J.clone();for(var X=0;XO){Q.insertBefore(new h(W));break;}else W=null;}if(!W)U.append(Q,true);}else{S=R=1;U=K.clone();U.insertAfter(K);U.append(Q=J.clone());var Y=A(M,N);for(var Z=0;Z1)return false;else if(H)return true;var J=I[0],K=J.getParent(),L=K.getAscendant('table'),M=e.buildTableMap(L),N=K.$.rowIndex,O=A(M,N,J),P=J.$.colSpan,Q,R,S;if(P>1){R=Math.ceil(P/2);S=Math.floor(P/2);}else{S=R=1;var T=B(M,O);for(var U=0;U0?2:0}; -}},tablecell_insertBefore:{label:H.cell.insertBefore,group:'tablecell',command:'cellInsertBefore',order:5},tablecell_insertAfter:{label:H.cell.insertAfter,group:'tablecell',command:'cellInsertAfter',order:10},tablecell_delete:{label:H.cell.deleteCell,group:'tablecell',command:'cellDelete',order:15},tablecell_merge:{label:H.cell.merge,group:'tablecell',command:'cellMerge',order:16},tablecell_merge_right:{label:H.cell.mergeRight,group:'tablecell',command:'cellMergeRight',order:17},tablecell_merge_down:{label:H.cell.mergeDown,group:'tablecell',command:'cellMergeDown',order:18},tablecell_split_horizontal:{label:H.cell.splitHorizontal,group:'tablecell',command:'cellHorizontalSplit',order:19},tablecell_split_vertical:{label:H.cell.splitVertical,group:'tablecell',command:'cellVerticalSplit',order:20},tablecell_properties:{label:H.cell.title,group:'tablecellproperties',command:'cellProperties',order:21},tablerow:{label:H.row.menu,group:'tablerow',order:1,getItems:function(){return{tablerow_insertBefore:2,tablerow_insertAfter:2,tablerow_delete:2};}},tablerow_insertBefore:{label:H.row.insertBefore,group:'tablerow',command:'rowInsertBefore',order:5},tablerow_insertAfter:{label:H.row.insertAfter,group:'tablerow',command:'rowInsertAfter',order:10},tablerow_delete:{label:H.row.deleteRow,group:'tablerow',command:'rowDelete',order:15},tablecolumn:{label:H.column.menu,group:'tablecolumn',order:1,getItems:function(){return{tablecolumn_insertBefore:2,tablecolumn_insertAfter:2,tablecolumn_delete:2};}},tablecolumn_insertBefore:{label:H.column.insertBefore,group:'tablecolumn',command:'columnInsertBefore',order:5},tablecolumn_insertAfter:{label:H.column.insertAfter,group:'tablecolumn',command:'columnInsertAfter',order:10},tablecolumn_delete:{label:H.column.deleteColumn,group:'tablecolumn',command:'columnDelete',order:15}});if(G.contextMenu)G.contextMenu.addListener(function(I,J){if(!I||I.isReadOnly())return null;while(I){if(I.getName() in F)return{tablecell:2,tablerow:2,tablecolumn:2};I=I.getParent();}return null;});},getSelectedCells:n};j.add('tabletools',j.tabletools);})();e.buildTableMap=function(m){var n=m.$.rows,o=-1,p=[];for(var q=0;qp&&(!s||!t||vt){s=v;t=u;}}else{if(q&&u==p){s=v;break;}if(ut)){s=v;t=u;}}}if(s)s.focus();};(function(){j.add('templates',{requires:['dialog'],init:function(o){a.dialog.add('templates',a.getUrl(this.path+'dialogs/templates.js'));o.addCommand('templates',new a.dialogCommand('templates')); -o.ui.addButton('Templates',{label:o.lang.templates.button,command:'templates'});}});var m={},n={};a.addTemplates=function(o,p){m[o]=p;};a.getTemplates=function(o){return m[o];};a.loadTemplates=function(o,p){var q=[];for(var r=0,s=o.length;r':' style="display:none">');t.push('',o.lang.toolbars,'');var w=o.toolbox.toolbars,x=o.config.toolbar instanceof Array?o.config.toolbar:o.config['toolbar_'+o.config.toolbar];for(var y=0;y');v=0;}if(C==='/'){t.push('
    ');continue;}D=C.items||C;for(var E=0;E');B&&t.push('',B,'');t.push('');var I=w.push(A)-1;if(I>0){A.previous=w[I-1];A.previous.next=A;}}if(H){if(!v){t.push('');v=1;}}else if(v){t.push('');v=0;}var J=F.render(o,t);I=A.items.push(J)-1;if(I>0){J.previous=A.items[I-1];J.previous.next=J;}J.toolbar=A;J.onkey=q;J.onfocus=function(){if(!o.toolbox.focusCommandExecuted)o.focus();};}}if(v){t.push('');v=0;}if(A)t.push('');}t.push('
    ');if(o.config.toolbarCanCollapse){var K=e.addFunction(function(){o.execCommand('toolbarCollapse');});o.on('destroy',function(){e.removeFunction(K);});var L=e.getNextId();o.addCommand('toolbarCollapse',{readOnly:1,exec:function(M){var N=a.document.getById(L),O=N.getPrevious(),P=M.getThemeSpace('contents'),Q=O.getParent(),R=parseInt(P.$.style.height,10),S=Q.$.offsetHeight,T=!O.isVisible();if(!T){O.hide();N.addClass('cke_toolbox_collapser_min');N.setAttribute('title',M.lang.toolbarExpand);}else{O.show();N.removeClass('cke_toolbox_collapser_min');N.setAttribute('title',M.lang.toolbarCollapse);}N.getFirst().setText(T?'▲':'◀');var U=Q.$.offsetHeight-S;P.setStyle('height',R-U+'px');M.fire('resize');},modes:{wysiwyg:1,source:1}});t.push('','','');}r.data.html+=t.join('');}});o.on('destroy',function(){var r,s=0,t,u,v;r=this.toolbox.toolbars;for(;s');return{};}};}});}});})();a.UI_SEPARATOR='separator';i.toolbarLocation='top';i.toolbar_Basic=[['Bold','Italic','-','NumberedList','BulletedList','-','Link','Unlink','-','About']];i.toolbar_Full=[{name:'document',items:['Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates']},{name:'clipboard',items:['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']},{name:'editing',items:['Find','Replace','-','SelectAll','-','SpellChecker','Scayt']},{name:'forms',items:['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField']},'/',{name:'basicstyles',items:['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']},{name:'paragraph',items:['NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl']},{name:'links',items:['Link','Unlink','Anchor']},{name:'insert',items:['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe']},'/',{name:'styles',items:['Styles','Format','Font','FontSize']},{name:'colors',items:['TextColor','BGColor']},{name:'tools',items:['Maximize','ShowBlocks','-','About']}]; -i.toolbar='Full';i.toolbarCanCollapse=true;(function(){j.add('undo',{requires:['selection','wysiwygarea'],init:function(s){var t=new o(s),u=s.addCommand('undo',{exec:function(){if(t.undo()){s.selectionChange();this.fire('afterUndo');}},state:0,canUndo:false}),v=s.addCommand('redo',{exec:function(){if(t.redo()){s.selectionChange();this.fire('afterRedo');}},state:0,canUndo:false});t.onChange=function(){u.setState(t.undoable()?2:0);v.setState(t.redoable()?2:0);};function w(x){if(t.enabled&&x.data.command.canUndo!==false)t.save();};s.on('beforeCommandExec',w);s.on('afterCommandExec',w);s.on('saveSnapshot',function(x){t.save(x.data&&x.data.contentOnly);});s.on('contentDom',function(){s.document.on('keydown',function(x){if(!x.data.$.ctrlKey&&!x.data.$.metaKey)t.type(x);});});s.on('beforeModeUnload',function(){s.mode=='wysiwyg'&&t.save(true);});s.on('mode',function(){t.enabled=s.readOnly?false:s.mode=='wysiwyg';t.onChange();});s.ui.addButton('Undo',{label:s.lang.undo,command:'undo'});s.ui.addButton('Redo',{label:s.lang.redo,command:'redo'});s.resetUndo=function(){t.reset();s.fire('saveSnapshot');};s.on('updateSnapshot',function(){if(t.currentImage)t.update();});}});j.undo={};var m=j.undo.Image=function(s){this.editor=s;s.fire('beforeUndoImage');var t=s.getSnapshot(),u=t&&s.getSelection();c&&t&&(t=t.replace(/\s+data-cke-expando=".*?"/g,''));this.contents=t;this.bookmarks=u&&u.createBookmarks2(true);s.fire('afterUndoImage');},n=/\b(?:href|src|name)="[^"]*?"/gi;m.prototype={equals:function(s,t){var u=this.contents,v=s.contents;if(c&&(b.ie7Compat||b.ie6Compat)){u=u.replace(n,'');v=v.replace(n,'');}if(u!=v)return false;if(t)return true;var w=this.bookmarks,x=s.bookmarks;if(w||x){if(!w||!x||w.length!=x.length)return false;for(var y=0;y25){this.save(false,null,false);this.modifiersCount=1;}}else if(!y){this.modifiersCount=0;this.typesCount++;if(this.typesCount>25){this.save(false,null,false);this.typesCount=1;}}},reset:function(){var s=this;s.lastKeystroke=0;s.snapshots=[];s.index=-1;s.limit=s.editor.config.undoStackSize||20;s.currentImage=null;s.hasUndo=false;s.hasRedo=false;s.resetType();},resetType:function(){var s=this;s.typing=false;delete s.lastKeystroke;s.typesCount=0;s.modifiersCount=0;},fireChange:function(){var s=this;s.hasUndo=!!s.getNextImage(true);s.hasRedo=!!s.getNextImage(false);s.resetType();s.onChange();},save:function(s,t,u){var w=this;var v=w.snapshots;if(!t)t=new m(w.editor);if(t.contents===false)return false;if(w.currentImage&&t.equals(w.currentImage,s))return false;v.splice(w.index+1,v.length-w.index-1);if(v.length==w.limit)v.shift();w.index=v.push(t)-1;w.currentImage=t;if(u!==false)w.fireChange();return true;},restoreImage:function(s){var w=this;var t=w.editor,u;if(s.bookmarks){t.focus();u=t.getSelection();}w.editor.loadSnapshot(s.contents);if(s.bookmarks)u.selectBookmarks(s.bookmarks);else if(c){var v=w.editor.document.getBody().$.createTextRange();v.collapse(true);v.select();}w.index=s.index;w.update();w.fireChange();},getNextImage:function(s){var x=this;var t=x.snapshots,u=x.currentImage,v,w;if(u)if(s)for(w=x.index-1;w>=0;w--){v=t[w];if(!u.equals(v,true)){v.index=w;return v;}}else for(w=x.index+1;w]*>)\s*<(p|div|address|h\d|center|pre)[^>]*>\s*(?:]*>| |\u00A0| )?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi,n=d.walker.whitespaces(true),o=d.walker.bogus(true),p=function(E){return n(E)&&o(E);};function q(E){return E.isBlockBoundary()&&f.$empty[E.getName()];};function r(E){return function(F){if(this.mode=='wysiwyg'){this.focus(); -var G=this.getSelection(),H=G.isLocked;H&&G.unlock();this.fire('saveSnapshot');E.call(this,F.data);H&&this.getSelection().lock();var I=this;setTimeout(function(){try{I.fire('saveSnapshot');}catch(J){setTimeout(function(){I.fire('saveSnapshot');},200);}},0);}};};function s(E){var N=this;if(N.dataProcessor)E=N.dataProcessor.toHtml(E);if(!E)return;var F=N.getSelection(),G=F.getRanges()[0];if(G.checkReadOnly())return;if(b.opera){var H=new d.elementPath(G.startContainer);if(H.block){var I=a.htmlParser.fragment.fromHtml(E,false).children;for(var J=0,K=I.length;J'+Q+'';});I=I.replace(/\n/g,'
    ');if(!(H||c))I=I.replace(new RegExp('
    (?=)'),function(O){return e.repeat(O,2);});if(b.gecko||b.webkit){var K=new d.elementPath(F.getStartElement()),L=[];for(var M=0;M/));else if(N in f.$block)break;}I=L.join('')+I;}s.call(this,I);};function u(E){var F=this.getSelection(),G=F.getRanges(),H=E.getName(),I=f.$block[H],J=F.isLocked;if(J)F.unlock();var K,L,M,N;for(var O=G.length-1;O>=0;O--){K=G[O];if(!K.checkReadOnly()){K.deleteContents(1);L=!O&&E||E.clone(1);var P,Q;if(I)while((P=K.getCommonAncestor(0,1))&&(Q=f[P.getName()])&&!(Q&&Q[H])){if(P.getName() in f.span)K.splitElement(P);else if(K.checkStartOfBlock()&&K.checkEndOfBlock()){K.setStartBefore(P);K.collapse(true);P.remove();}else K.splitBlock();}K.insertNode(L); -if(!M)M=L;}}if(M){K.moveToPosition(M,4);if(I){var R=M.getNext(p),S=R&&R.type==1&&R.getName();if(S&&f.$block[S]){if(f[S]['#'])K.moveToElementEditStart(R);else K.moveToElementEditEnd(M);}else if(!R){R=K.fixBlock(true,this.config.enterMode==3?'div':'p');K.moveToElementEditStart(R);}}}F.selectRanges([K]);if(J)this.getSelection().lock();};function v(E){if(!E.checkDirty())setTimeout(function(){E.resetDirty();},0);};var w=d.walker.whitespaces(true),x=d.walker.bookmark(false,true);function y(E){return w(E)&&x(E);};function z(E){return E.type==3&&e.trim(E.getText()).match(/^(?: |\xa0)$/);};function A(E){if(E.isLocked){E.unlock();setTimeout(function(){E.lock();},0);}};function B(E){return E.getOuterHtml().match(m);};w=d.walker.whitespaces(true);function C(E){var F=E.window,G=E.document,H=E.document.getBody(),I=H.getFirst(),J=H.getChildren().count();if(!J||J==1&&I.type==1&&I.hasAttribute('_moz_editor_bogus_node')){v(E);var K=E.element.getDocument(),L=K.getDocumentElement(),M=L.$.scrollTop,N=L.$.scrollLeft,O=G.$.createEvent('KeyEvents');O.initKeyEvent('keypress',true,true,F.$,false,false,false,false,0,32);G.$.dispatchEvent(O);if(M!=L.$.scrollTop||N!=L.$.scrollLeft)K.getWindow().$.scrollTo(N,M);J&&H.getFirst().remove();G.getBody().appendBogus();var P=new d.range(G);P.setStartAt(H,1);P.select();}};function D(E){var F=E.editor,G=E.data.path,H=G.blockLimit,I=E.data.selection,J=I.getRanges()[0],K=F.document.getBody(),L=F.config.enterMode;if(b.gecko){var M=G.block||G.blockLimit,N=M&&M.getLast(y);if(M&&M.isBlockBoundary()&&!(N&&N.type==1&&N.isBlockBoundary())&&!M.is('pre')&&!M.getBogus())M.appendBogus();}if(F.config.autoParagraph!==false&&L!=2&&J.collapsed&&H.getName()=='body'&&!G.block){var O=J.fixBlock(true,F.config.enterMode==3?'div':'p');if(c){var P=O.getFirst(y);P&&z(P)&&P.remove();}if(B(O)){var Q=O.getNext(w);if(Q&&Q.type==1&&!q(Q)){J.moveToElementEditStart(Q);O.remove();}else{Q=O.getPrevious(w);if(Q&&Q.type==1&&!q(Q)){J.moveToElementEditEnd(Q);O.remove();}}}J.select();E.cancel();}var R=new d.range(F.document);R.moveToElementEditEnd(F.document.getBody());var S=new d.elementPath(R.startContainer);if(!S.blockLimit.is('body')){var T;if(L!=2)T=K.append(F.document.createElement(L==1?'p':'div'));else T=K;if(!c)T.appendBogus();}};j.add('wysiwygarea',{requires:['editingblock'],init:function(E){var F=E.config.enterMode!=2&&E.config.autoParagraph!==false?E.config.enterMode==3?'div':'p':false,G=E.lang.editorTitle.replace('%1',E.name),H=E.lang.editorHelp;if(c)G+=', '+H;var I=a.document.getWindow(),J; -E.on('editingBlockReady',function(){var M,N,O,P,Q,R,S,T=b.isCustomDomain(),U=function(X){if(N)N.remove();var Y='document.open();'+(T?'document.domain="'+document.domain+'";':'')+'document.close();';Y=b.air?'javascript:void(0)':c?'javascript:void(function(){'+encodeURIComponent(Y)+'}())':'';var Z=e.getNextId();N=h.createFromHtml('');if(document.location.protocol=='chrome:')a.event.useCapture=true;N.on('load',function(aa){Q=1;aa.removeListener();var ab=N.getFrameDocument();ab.write(X);b.air&&W(ab.getWindow().$);});if(document.location.protocol=='chrome:')a.event.useCapture=false;M.append(h.createFromHtml(''+H+''));M.append(N);if(b.webkit){S=function(){M.setStyle('width','100%');N.hide();N.setSize('width',M.getSize('width'));M.removeStyle('width');N.show();};I.on('resize',S);}};J=e.addFunction(W);var V='';function W(X){if(!Q)return;Q=0;E.fire('ariaWidget',N);var Y=X.document,Z=Y.body,aa=Y.getElementById('cke_actscrpt');aa&&aa.parentNode.removeChild(aa);Z.spellcheck=!E.config.disableNativeSpellChecker;var ab=!E.readOnly;if(c){Z.hideFocus=true;Z.disabled=true;Z.contentEditable=ab;Z.removeAttribute('disabled');}else setTimeout(function(){if(b.gecko&&b.version>=10900||b.opera)Y.$.body.contentEditable=ab;else if(b.webkit)Y.$.body.parentNode.contentEditable=ab;else Y.$.designMode=ab?'off':'on';},0);ab&&b.gecko&&e.setTimeout(C,0,null,E);X=E.window=new d.window(X);Y=E.document=new g(Y);ab&&Y.on('dblclick',function(ag){var ah=ag.data.getTarget(),ai={element:ah,dialog:''};E.fire('doubleclick',ai);ai.dialog&&E.openDialog(ai.dialog);});c&&Y.on('click',function(ag){var ah=ag.data.getTarget();if(ah.is('input')){var ai=ah.getAttribute('type');if(ai=='submit'||ai=='reset')ag.data.preventDefault();}});if(!(c||b.opera))Y.on('mousedown',function(ag){var ah=ag.data.getTarget();if(ah.is('img','hr','input','textarea','select'))E.getSelection().selectElement(ah);});if(b.gecko)Y.on('mouseup',function(ag){if(ag.data.$.button==2){var ah=ag.data.getTarget();if(!ah.getOuterHtml().replace(m,'')){var ai=new d.range(Y);ai.moveToElementEditStart(ah);ai.select(true);}}}); -Y.on('click',function(ag){ag=ag.data;if(ag.getTarget().is('a')&&ag.$.button!=2)ag.preventDefault();});if(b.webkit){Y.on('mousedown',function(){ad=1;});Y.on('click',function(ag){if(ag.data.getTarget().is('input','select'))ag.data.preventDefault();});Y.on('mouseup',function(ag){if(ag.data.getTarget().is('input','textarea'))ag.data.preventDefault();});}var ac=c?N:X;ac.on('blur',function(){E.focusManager.blur();});var ad;ac.on('focus',function(){var ag=E.document;if(b.gecko||b.opera)ag.getBody().focus();else if(b.webkit)if(!ad){E.document.getDocumentElement().focus();ad=1;}E.focusManager.focus();});var ae=E.keystrokeHandler;ae.blockedKeystrokes[8]=!ab;ae.attach(Y);Y.getDocumentElement().addClass(Y.$.compatMode);E.on('key',function(ag){if(E.mode!='wysiwyg')return;var ah=ag.data.keyCode;if(ah in {8:1,46:1}){var ai=E.getSelection(),aj=ai.getSelectedElement(),ak=ai.getRanges()[0],al=new d.elementPath(ak.startContainer),am,an,ao,ap=ah==8;if(aj){E.fire('saveSnapshot');ak.moveToPosition(aj,3);aj.remove();ak.select();E.fire('saveSnapshot');ag.cancel();}else if(ak.collapsed)if((am=al.block)&&ak[ap?'checkStartOfBlock':'checkEndOfBlock']()&&(ao=am[ap?'getPrevious':'getNext'](n))&&ao.is('table')){E.fire('saveSnapshot');if(ak[ap?'checkEndOfBlock':'checkStartOfBlock']())am.remove();ak['moveToElementEdit'+(ap?'End':'Start')](ao);ak.select();E.fire('saveSnapshot');ag.cancel();}else if(al.blockLimit.is('td')&&(an=al.blockLimit.getAscendant('table'))&&ak.checkBoundaryOfElement(an,ap?1:2)&&(ao=an[ap?'getPrevious':'getNext'](n))){E.fire('saveSnapshot');ak['moveToElementEdit'+(ap?'End':'Start')](ao);if(ak.checkStartOfBlock()&&ak.checkEndOfBlock())ao.remove();else ak.select();E.fire('saveSnapshot');ag.cancel();}}if(ah==33||ah==34)if(b.gecko){var aq=Y.getBody();if(X.$.innerHeight>aq.$.offsetHeight){ak=new d.range(Y);ak[ah==33?'moveToElementEditStart':'moveToElementEditEnd'](aq);ak.select();ag.cancel();}}});if(c&&Y.$.compatMode=='CSS1Compat'){var af={33:1,34:1};Y.on('keydown',function(ag){if(ag.data.getKeystroke() in af)setTimeout(function(){E.getSelection().scrollIntoView();},0);});}if(c&&E.config.enterMode!=1)Y.on('selectionchange',function(){var ag=Y.getBody(),ah=E.getSelection(),ai=ah&&ah.getRanges()[0];if(ai&&ag.getHtml().match(/^

     <\/p>$/i)&&ai.startContainer.equals(ag))setTimeout(function(){ai=E.getSelection().getRanges()[0];if(!ai.startContainer.equals('body')){ag.getFirst().remove(1);ai.moveToElementEditEnd(ag);ai.select(1);}},0);});if(E.contextMenu)E.contextMenu.addTarget(Y,E.config.browserContextMenuOnCtrl!==false); -setTimeout(function(){E.fire('contentDom');if(R){E.mode='wysiwyg';E.fire('mode',{previousMode:E._.previousMode});R=false;}O=false;if(P){E.focus();P=false;}setTimeout(function(){E.fire('dataReady');},0);try{E.document.$.execCommand('2D-position',false,true);}catch(ag){}try{E.document.$.execCommand('enableInlineTableEditing',false,!E.config.disableNativeTableHandles);}catch(ah){}if(E.config.disableObjectResizing)try{E.document.$.execCommand('enableObjectResizing',false,false);}catch(ai){E.document.getBody().on(c?'resizestart':'resize',function(aj){aj.data.preventDefault();});}if(c)setTimeout(function(){if(E.document){var aj=E.document.$.body;aj.runtimeStyle.marginBottom='0px';aj.runtimeStyle.marginBottom='';}},1000);},0);};E.addMode('wysiwyg',{load:function(X,Y,Z){M=X;if(c&&b.quirks)X.setStyle('position','relative');E.mayBeDirty=true;R=true;if(Z)this.loadSnapshotData(Y);else this.loadData(Y);},loadData:function(X){O=true;E._.dataStore={id:1};var Y=E.config,Z=Y.fullPage,aa=Y.docType,ab='';!Z&&(ab=e.buildStyleHtml(E.config.contentsCss)+ab);var ac=Y.baseHref?'':'';if(Z)X=X.replace(/]*>/i,function(ad){E.docType=aa=ad;return '';}).replace(/<\?xml\s[^\?]*\?>/i,function(ad){E.xmlDeclaration=ad;return '';});if(E.dataProcessor)X=E.dataProcessor.toHtml(X,F);if(Z){if(!/]/.test(X))X=''+X;if(!/]/.test(X))X=''+X+'';if(!/]/.test(X))X=X.replace(/]*>/,'$&');else if(!/]/.test(X))X=X.replace(/]*>/,'$&');ac&&(X=X.replace(//,'$&'+ac));X=X.replace(/<\/head\s*>/,ab+'$&');X=aa+X;}else X=Y.docType+''+''+''+G+''+ac+ab+''+''+X+'';if(b.gecko)X=X.replace(/
    (?=\s*<\/(:?html|body)>)/,'$&
    ');X+=V;this.onDispose();U(X);},getData:function(){var X=E.config,Y=X.fullPage,Z=Y&&E.docType,aa=Y&&E.xmlDeclaration,ab=N.getFrameDocument(),ac=Y?ab.getDocumentElement().getOuterHtml():ab.getBody().getHtml();if(b.gecko)ac=ac.replace(/
    (?=\s*(:?$|<\/body>))/,'');if(E.dataProcessor)ac=E.dataProcessor.toDataFormat(ac,F);if(X.ignoreEmptyParagraph)ac=ac.replace(m,function(ad,ae){return ae;});if(aa)ac=aa+'\n'+ac;if(Z)ac=Z+'\n'+ac; -return ac;},getSnapshotData:function(){return N.getFrameDocument().getBody().getHtml();},loadSnapshotData:function(X){N.getFrameDocument().getBody().setHtml(X);},onDispose:function(){if(!E.document)return;E.document.getDocumentElement().clearCustomData();E.document.getBody().clearCustomData();E.window.clearCustomData();E.document.clearCustomData();N.clearCustomData();N.remove();},unload:function(X){this.onDispose();if(S)I.removeListener('resize',S);E.window=E.document=N=M=P=null;E.fire('contentDomUnload');},focus:function(){var X=E.window;if(O)P=true;else if(X){var Y=E.getSelection(),Z=Y&&Y.getNative();if(Z&&Z.type=='Control')return;b.air?setTimeout(function(){X.focus();},0):X.focus();E.selectionChange();}}});E.on('insertHtml',r(s),null,null,20);E.on('insertElement',r(u),null,null,20);E.on('insertText',r(t),null,null,20);E.on('selectionChange',function(X){if(E.readOnly)return;var Y=E.getSelection();if(Y&&!Y.isLocked){var Z=E.checkDirty();E.fire('saveSnapshot',{contentOnly:1});D.call(this,X);E.fire('updateSnapshot');!Z&&E.resetDirty();}},null,null,1);});E.on('contentDom',function(){var M=E.document.getElementsByTag('title').getItem(0);M.data('cke-title',E.document.$.title);c&&(E.document.$.title=G);});E.on('readOnly',function(){if(E.mode=='wysiwyg'){var M=E.getMode();M.loadData(M.getData());}});if(a.document.$.documentMode>=8){E.addCss('html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}');var K=[];for(var L in f.$removeEmpty)K.push('html.CSS1Compat '+L+'[contenteditable=false]');E.addCss(K.join(',')+'{ display:inline-block;}');}else if(b.gecko){E.addCss('html { height: 100% !important; }');E.addCss('img:-moz-broken { -moz-force-broken-image-icon : 1;\tmin-width : 24px; min-height : 24px; }');}E.addCss('html {\t_overflow-y: scroll; cursor: text;\t*cursor:auto;}');E.addCss('img, input, textarea { cursor: default;}');E.on('insertElement',function(M){var N=M.data;if(N.type==1&&(N.is('input')||N.is('textarea'))){var O=N.getAttribute('contenteditable')=='false';if(!O){N.data('cke-editable',N.hasAttribute('contenteditable')?'true':'1');N.setAttribute('contenteditable',false);}}});}});if(b.gecko)(function(){var E=document.body;if(!E)window.addEventListener('load',arguments.callee,false);else{var F=E.getAttribute('onpageshow');E.setAttribute('onpageshow',(F?F+';':'')+'event.persisted && (function(){'+'var allInstances = CKEDITOR.instances, editor, doc;'+'for ( var i in allInstances )'+'{'+'\teditor = allInstances[ i ];'+'\tdoc = editor.document;'+'\tif ( doc )'+'\t{'+'\t\tdoc.$.designMode = "off";'+'\t\tdoc.$.designMode = "on";'+'\t}'+'}'+'})();'); -}})();})();i.disableObjectResizing=false;i.disableNativeTableHandles=true;i.disableNativeSpellChecker=true;i.ignoreEmptyParagraph=true;j.add('wsc',{requires:['dialog'],init:function(m){var n='checkspell',o=m.addCommand(n,new a.dialogCommand(n));o.modes={wysiwyg:!b.opera&&!b.air&&document.domain==window.location.hostname};m.ui.addButton('SpellChecker',{label:m.lang.spellCheck.toolbar,command:n});a.dialog.add(n,this.path+'dialogs/wsc.js');}});i.wsc_customerId=i.wsc_customerId||'1:ua3xw1-2XyGJ3-GWruD3-6OFNT1-oXcuB1-nR6Bp4-hgQHc-EcYng3-sdRXG3-NOfFk';i.wsc_customLoaderScript=i.wsc_customLoaderScript||null;a.DIALOG_RESIZE_NONE=0;a.DIALOG_RESIZE_WIDTH=1;a.DIALOG_RESIZE_HEIGHT=2;a.DIALOG_RESIZE_BOTH=3;(function(){var m=e.cssLength;function n(R){return!!this._.tabs[R][0].$.offsetHeight;};function o(){var V=this;var R=V._.currentTabId,S=V._.tabIdList.length,T=e.indexOf(V._.tabIdList,R)+S;for(var U=T-1;U>T-S;U--){if(n.call(V,V._.tabIdList[U%S]))return V._.tabIdList[U%S];}return null;};function p(){var V=this;var R=V._.currentTabId,S=V._.tabIdList.length,T=e.indexOf(V._.tabIdList,R);for(var U=T+1;U1){ah._.tabBarMode=true; -ah._.tabs[ah._.currentTabId][0].focus();Z=1;}else if((as==37||as==39)&&ah._.tabBarMode){aw=as==(at?39:37)?o.call(ah):p.call(ah);ah.selectPage(aw);ah._.tabs[aw][0].focus();Z=1;}else if((as==13||as==32)&&ah._.tabBarMode){ay.selectPage(ay._.currentTabId);ay._.tabBarMode=false;ay._.currentFocusIndex=-1;ak(1);Z=1;}else if(as==13){var ax=ar.data.getTarget();if(!ax.is('a','button','select','textarea')&&(!ax.is('input')||ax.$.type!='button')){au=ay.getButton('ok');au&&e.setTimeout(au.click,0,au);Z=1;}aa=1;}else if(as==27){au=ay.getButton('cancel');if(au)e.setTimeout(au.click,0,au);else if(ay.fire('cancel',{hide:true}).hide!==false)ay.hide();aa=1;}else return;am(ar);};function am(ar){if(Z)ar.data.preventDefault(1);else if(aa)ar.data.stopPropagation();};var an=this._.element;this.on('show',function(){an.on('keydown',al,this);if(b.opera||b.gecko)an.on('keypress',am,this);});this.on('hide',function(){an.removeListener('keydown',al);if(b.opera||b.gecko)an.removeListener('keypress',am);ai(function(ar){s.apply(ar);});});this.on('iframeAdded',function(ar){var as=new g(ar.data.iframe.$.contentWindow.document);as.on('keydown',al,this,null,0);});this.on('show',function(){var av=this;aj();if(R.config.dialog_startupFocusTab&&ah._.pageCount>1){ah._.tabBarMode=true;ah._.tabs[ah._.currentTabId][0].focus();}else if(!av._.hasFocus){av._.currentFocusIndex=-1;if(T.onFocus){var ar=T.onFocus.call(av);ar&&ar.focus();}else ak(1);if(av._.editor.mode=='wysiwyg'&&c){var as=R.document.$.selection,at=as.createRange();if(at)if(at.parentElement&&at.parentElement().ownerDocument==R.document.$||at.item&&at.item(0).ownerDocument==R.document.$){var au=document.body.createTextRange();au.moveToElementText(av.getElement().getFirst().$);au.collapse(true);au.select();}}}},this,null,4294967295);if(b.ie6Compat)this.on('load',function(ar){var as=this.getElement(),at=as.getFirst();at.remove();at.appendTo(as);},this);B(this);C(this);new d.text(T.title,a.document).appendTo(this.parts.title);for(Y=0;Y0?S:0)+'px'};aa[V?'right':'left']=(R>0?R:0)+'px';U.setStyles(aa);T&&(ab._.moved=1);},getPosition:function(){return e.extend({},this._.position);},show:function(){var R=this._.element,S=this.definition;if(!(R.getParent()&&R.getParent().equals(a.document.getBody())))R.appendTo(a.document.getBody());else R.setStyle('display','block');if(b.gecko&&b.version<10900){var T=this.parts.dialog;T.setStyle('position','absolute');setTimeout(function(){T.setStyle('position','fixed');},0);}this.resize(this._.contentSize&&this._.contentSize.width||S.width||S.minWidth,this._.contentSize&&this._.contentSize.height||S.height||S.minHeight);this.reset();this.selectPage(this.definition.contents[0].id);if(a.dialog._.currentZIndex===null)a.dialog._.currentZIndex=this._.editor.config.baseFloatZIndex; -this._.element.getFirst().setStyle('z-index',a.dialog._.currentZIndex+=10);if(a.dialog._.currentTop===null){a.dialog._.currentTop=this;this._.parentDialog=null;H(this._.editor);}else{this._.parentDialog=a.dialog._.currentTop;var U=this._.parentDialog.getElement().getFirst();U.$.style.zIndex-=Math.floor(this._.editor.config.baseFloatZIndex/2);a.dialog._.currentTop=this;}R.on('keydown',L);R.on(b.opera?'keypress':'keyup',M);this._.hasFocus=false;e.setTimeout(function(){this.layout();u(this);this.parts.dialog.setStyle('visibility','');this.fireOnce('load',{});k.fire('ready',this);this.fire('show',{});this._.editor.fire('dialogShow',this);this.foreach(function(V){V.setInitValue&&V.setInitValue();});},100,this);},layout:function(){var X=this;var R=X.parts.dialog,S=X.getSize(),T=a.document.getWindow(),U=T.getViewPaneSize(),V=(U.width-S.width)/2,W=(U.height-S.height)/2;if(!b.ie6Compat)if(S.height+(W>0?W:0)>U.height||S.width+(V>0?V:0)>U.width)R.setStyle('position','absolute');else R.setStyle('position','fixed');X.move(X._.moved?X._.position.x:V,X._.moved?X._.position.y:W);},foreach:function(R){var U=this;for(var S in U._.contents)for(var T in U._.contents[S])R.call(U,U._.contents[S][T]);return U;},reset:(function(){var R=function(S){if(S.reset)S.reset(1);};return function(){this.foreach(R);return this;};})(),setupContent:function(){var R=arguments;this.foreach(function(S){if(S.setup)S.setup.apply(S,R);});},commitContent:function(){var R=arguments;this.foreach(function(S){if(c&&this._.currentFocusIndex==S.focusIndex)S.getInputElement().$.blur();if(S.commit)S.commit.apply(S,R);});},hide:function(){if(!this.parts.dialog.isVisible())return;this.fire('hide',{});this._.editor.fire('dialogHide',this);this.selectPage(this._.tabIdList[0]);var R=this._.element;R.setStyle('display','none');this.parts.dialog.setStyle('visibility','hidden');O(this);while(a.dialog._.currentTop!=this)a.dialog._.currentTop.hide();if(!this._.parentDialog)I();else{var S=this._.parentDialog.getElement().getFirst();S.setStyle('z-index',parseInt(S.$.style.zIndex,10)+Math.floor(this._.editor.config.baseFloatZIndex/2));}a.dialog._.currentTop=this._.parentDialog;if(!this._.parentDialog){a.dialog._.currentZIndex=null;R.removeListener('keydown',L);R.removeListener(b.opera?'keypress':'keyup',M);var T=this._.editor;T.focus();if(T.mode=='wysiwyg'&&c){var U=T.getSelection();U&&U.unlock(true);}}else a.dialog._.currentZIndex-=10;delete this._.parentDialog;this.foreach(function(V){V.resetInitValue&&V.resetInitValue(); -});},addPage:function(R){var ad=this;var S=[],T=R.label?' title="'+e.htmlEncode(R.label)+'"':'',U=R.elements,V=a.dialog._.uiElementBuilders.vbox.build(ad,{type:'vbox',className:'cke_dialog_page_contents',children:R.elements,expand:!!R.expand,padding:R.padding,style:R.style||'width: 100%;height:100%'},S),W=h.createFromHtml(S.join(''));W.setAttribute('role','tabpanel');var X=b,Y='cke_'+R.id+'_'+e.getNextNumber(),Z=h.createFromHtml(['0?' cke_last':'cke_first',T,!!R.hidden?' style="display:none"':'',' id="',Y,'"',X.gecko&&X.version>=10900&&!X.hc?'':' href="javascript:void(0)"',' tabIndex="-1"',' hidefocus="true"',' role="tab">',R.label,''].join(''));W.setAttribute('aria-labelledby',Y);ad._.tabs[R.id]=[Z,W];ad._.tabIdList.push(R.id);!R.hidden&&ad._.pageCount++;ad._.lastTab=Z;ad.updateStyle();var aa=ad._.contents[R.id]={},ab,ac=V.getChild();while(ab=ac.shift()){aa[ab.id]=ab;if(typeof ab.getChild=='function')ac.push.apply(ac,ab.getChild());}W.setAttribute('name',R.id);W.appendTo(ad.parts.contents);Z.unselectable();ad.parts.tabs.append(Z);if(R.accessKey){N(ad,ad,'CTRL+'+R.accessKey,Q,P);ad._.accessKeyMap['CTRL+'+R.accessKey]=R.id;}},selectPage:function(R){if(this._.currentTabId==R)return;if(this.fire('selectPage',{page:R,currentPage:this._.currentTabId})===true)return;for(var S in this._.tabs){var T=this._.tabs[S][0],U=this._.tabs[S][1];if(S!=R){T.removeClass('cke_dialog_tab_selected');U.hide();}U.setAttribute('aria-hidden',S!=R);}var V=this._.tabs[R];V[0].addClass('cke_dialog_tab_selected');if(b.ie6Compat||b.ie7Compat){q(V[1]);V[1].show();setTimeout(function(){q(V[1],1);},0);}else V[1].show();this._.currentTabId=R;this._.currentTabIndex=e.indexOf(this._.tabIdList,R);},updateStyle:function(){this.parts.dialog[(this._.pageCount===1?'add':'remove')+'Class']('cke_single_page');},hidePage:function(R){var T=this;var S=T._.tabs[R]&&T._.tabs[R][0];if(!S||T._.pageCount==1||!S.isVisible())return;else if(R==T._.currentTabId)T.selectPage(o.call(T));S.hide();T._.pageCount--;T.updateStyle();},showPage:function(R){var T=this;var S=T._.tabs[R]&&T._.tabs[R][0];if(!S)return;S.show();T._.pageCount++;T.updateStyle();},getElement:function(){return this._.element;},getName:function(){return this._.name;},getContentElement:function(R,S){var T=this._.contents[R];return T&&T[S];},getValueOf:function(R,S){return this.getContentElement(R,S).getValue();},setValueOf:function(R,S,T){return this.getContentElement(R,S).setValue(T);},getButton:function(R){return this._.buttons[R]; -},click:function(R){return this._.buttons[R].click();},disableButton:function(R){return this._.buttons[R].disable();},enableButton:function(R){return this._.buttons[R].enable();},getPageCount:function(){return this._.pageCount;},getParentEditor:function(){return this._.editor;},getSelectedElement:function(){return this.getParentEditor().getSelection().getSelectedElement();},addFocusable:function(R,S){var U=this;if(typeof S=='undefined'){S=U._.focusList.length;U._.focusList.push(new t(U,R,S));}else{U._.focusList.splice(S,0,new t(U,R,S));for(var T=S+1;Tac.width-ab.width-W)ah=ac.width-ab.width+(V.lang.dir=='rtl'?0:X[1]);else ah=T.x;if(T.y+X[0]ac.height-ab.height-W)ai=ac.height-ab.height+X[2];else ai=T.y;R.move(ah,ai,1);aa.data.preventDefault();};function Z(aa){a.document.removeListener('mousemove',Y);a.document.removeListener('mouseup',Z);if(b.ie6Compat){var ab=F.getChild(0).getFrameDocument();ab.removeListener('mousemove',Y);ab.removeListener('mouseup',Z);}};R.parts.title.on('mousedown',function(aa){S={x:aa.data.$.screenX,y:aa.data.$.screenY};a.document.on('mousemove',Y);a.document.on('mouseup',Z);T=R.getPosition();if(b.ie6Compat){var ab=F.getChild(0).getFrameDocument();ab.on('mousemove',Y);ab.on('mouseup',Z);}aa.data.preventDefault();},R);};function C(R){var S=R.definition,T=S.resizable;if(T==0)return;var U=R.getParentEditor(),V,W,X,Y,Z,aa,ab=e.addFunction(function(ae){Z=R.getSize();var af=R.parts.contents,ag=af.$.getElementsByTagName('iframe').length;if(ag){aa=h.createFromHtml('

    ');af.append(aa);}W=Z.height-R.parts.contents.getSize('height',!(b.gecko||b.opera||c&&b.quirks));V=Z.width-R.parts.contents.getSize('width',1);Y={x:ae.screenX,y:ae.screenY};X=a.document.getWindow().getViewPaneSize();a.document.on('mousemove',ac);a.document.on('mouseup',ad);if(b.ie6Compat){var ah=F.getChild(0).getFrameDocument();ah.on('mousemove',ac);ah.on('mouseup',ad);}ae.preventDefault&&ae.preventDefault();});R.on('load',function(){var ae='';if(T==1)ae=' cke_resizer_horizontal';else if(T==2)ae=' cke_resizer_vertical';var af=h.createFromHtml('
    '); -R.parts.footer.append(af,1);});U.on('destroy',function(){e.removeFunction(ab);});function ac(ae){var af=U.lang.dir=='rtl',ag=(ae.data.$.screenX-Y.x)*(af?-1:1),ah=ae.data.$.screenY-Y.y,ai=Z.width,aj=Z.height,ak=ai+ag*(R._.moved?1:2),al=aj+ah*(R._.moved?1:2),am=R._.element.getFirst(),an=af&&am.getComputedStyle('right'),ao=R.getPosition();if(ao.y+al>X.height)al=X.height-ao.y;if((af?an:ao.x)+ak>X.width)ak=X.width-(af?an:ao.x);if(T==1||T==3)ai=Math.max(S.minWidth||0,ak-V);if(T==2||T==3)aj=Math.max(S.minHeight||0,al-W);R.resize(ai,aj);if(!R._.moved)R.layout();ae.data.preventDefault();};function ad(){a.document.removeListener('mouseup',ad);a.document.removeListener('mousemove',ac);if(aa){aa.remove();aa=null;}if(b.ie6Compat){var ae=F.getChild(0).getFrameDocument();ae.removeListener('mouseup',ad);ae.removeListener('mousemove',ac);}};};var D,E={},F;function G(R){R.data.preventDefault(1);};function H(R){var S=a.document.getWindow(),T=R.config,U=T.dialog_backgroundCoverColor||'white',V=T.dialog_backgroundCoverOpacity,W=T.baseFloatZIndex,X=e.genKey(U,V,W),Y=E[X];if(!Y){var Z=['
    '];if(b.ie6Compat){var aa=b.isCustomDomain(),ab="";Z.push('');}Z.push('
    ');Y=h.createFromHtml(Z.join(''));Y.setOpacity(V!=undefined?V:0.5);Y.on('keydown',G);Y.on('keypress',G);Y.on('keyup',G);Y.appendTo(a.document.getBody());E[X]=Y;}else Y.show();F=Y;var ac=function(){var af=S.getViewPaneSize();Y.setStyles({width:af.width+'px',height:af.height+'px'});},ad=function(){var af=S.getScrollPosition(),ag=a.dialog._.currentTop;Y.setStyles({left:af.x+'px',top:af.y+'px'});if(ag)do{var ah=ag.getPosition();ag.move(ah.x,ah.y);}while(ag=ag._.parentDialog)};D=ac;S.on('resize',ac);ac();if(!(b.mac&&b.webkit))Y.focus();if(b.ie6Compat){var ae=function(){ad();arguments.callee.prevScrollHandler.apply(this,arguments);};S.$.setTimeout(function(){ae.prevScrollHandler=window.onscroll||(function(){}); -window.onscroll=ae;},0);ad();}};function I(){if(!F)return;var R=a.document.getWindow();F.hide();R.removeListener('resize',D);if(b.ie6Compat)R.$.setTimeout(function(){var S=window.onscroll&&window.onscroll.prevScrollHandler;window.onscroll=S||null;},0);D=null;};function J(){for(var R in E)E[R].remove();E={};};var K={},L=function(R){var S=R.data.$.ctrlKey||R.data.$.metaKey,T=R.data.$.altKey,U=R.data.$.shiftKey,V=String.fromCharCode(R.data.$.keyCode),W=K[(S?'CTRL+':'')+(T?'ALT+':'')+(U?'SHIFT+':'')+V];if(!W||!W.length)return;W=W[W.length-1];W.keydown&&W.keydown.call(W.uiElement,W.dialog,W.key);R.data.preventDefault();},M=function(R){var S=R.data.$.ctrlKey||R.data.$.metaKey,T=R.data.$.altKey,U=R.data.$.shiftKey,V=String.fromCharCode(R.data.$.keyCode),W=K[(S?'CTRL+':'')+(T?'ALT+':'')+(U?'SHIFT+':'')+V];if(!W||!W.length)return;W=W[W.length-1];if(W.keyup){W.keyup.call(W.uiElement,W.dialog,W.key);R.data.preventDefault();}},N=function(R,S,T,U,V){var W=K[T]||(K[T]=[]);W.push({uiElement:R,dialog:S,key:T,keyup:V||R.accessKeyUp,keydown:U||R.accessKeyDown});},O=function(R){for(var S in K){var T=K[S];for(var U=T.length-1;U>=0;U--){if(T[U].dialog==R||T[U].uiElement==R)T.splice(U,1);}if(T.length===0)delete K[S];}},P=function(R,S){if(R._.accessKeyMap[S])R.selectPage(R._.accessKeyMap[S]);},Q=function(R,S){};(function(){k.dialog={uiElement:function(R,S,T,U,V,W,X){if(arguments.length<4)return;var Y=(U.call?U(S):U)||'div',Z=['<',Y,' '],aa=(V&&V.call?V(S):V)||{},ab=(W&&W.call?W(S):W)||{},ac=(X&&X.call?X.call(this,R,S):X)||'',ad=this.domId=ab.id||e.getNextId()+'_uiElement',ae=this.id=S.id,af;ab.id=ad;var ag={};if(S.type)ag['cke_dialog_ui_'+S.type]=1;if(S.className)ag[S.className]=1;if(S.disabled)ag.cke_disabled=1;var ah=ab['class']&&ab['class'].split?ab['class'].split(' '):[];for(af=0;af=0;af--){if(aj[af]==='')aj.splice(af,1);}if(aj.length>0)ab.style=(ab.style?ab.style+'; ':'')+aj.join('; ');for(af in ab)Z.push(af+'="'+e.htmlEncode(ab[af])+'" ');Z.push('>',ac,'');T.push(Z.join(''));(this._||(this._={})).dialog=R;if(typeof S.isChanged=='boolean')this.isChanged=function(){return S.isChanged;};if(typeof S.isChanged=='function')this.isChanged=S.isChanged; -if(typeof S.setValue=='function')this.setValue=e.override(this.setValue,function(am){return function(an){am.call(this,S.setValue.call(this,an));};});if(typeof S.getValue=='function')this.getValue=e.override(this.getValue,function(am){return function(){return S.getValue.call(this,am.call(this));};});a.event.implementOn(this);this.registerEvents(S);if(this.accessKeyUp&&this.accessKeyDown&&S.accessKey)N(this,R,'CTRL+'+S.accessKey);var al=this;R.on('load',function(){var am=al.getInputElement();if(am){var an=al.type in {checkbox:1,ratio:1}&&c&&b.version<8?'cke_dialog_ui_focused':'';am.on('focus',function(){R._.tabBarMode=false;R._.hasFocus=true;al.fire('focus');an&&this.addClass(an);});am.on('blur',function(){al.fire('blur');an&&this.removeClass(an);});}});if(this.keyboardFocusable){this.tabIndex=S.tabIndex||0;this.focusIndex=R._.focusList.push(this)-1;this.on('focus',function(){R._.currentFocusIndex=al.focusIndex;});}e.extend(this,S);},hbox:function(R,S,T,U,V){if(arguments.length<4)return;this._||(this._={});var W=this._.children=S,X=V&&V.widths||null,Y=V&&V.height||null,Z={},aa,ab=function(){var ad=[''];for(aa=0;aa0)ad.push('style="'+af.join('; ')+'" ');ad.push('>',T[aa],'');}ad.push('');return ad.join('');},ac={role:'presentation'};V&&V.align&&(ac.align=V.align);k.dialog.uiElement.call(this,R,V||{type:'hbox'},U,'table',Z,ac,ab);},vbox:function(R,S,T,U,V){if(arguments.length<3)return;this._||(this._={});var W=this._.children=S,X=V&&V.width||null,Y=V&&V.heights||null,Z=function(){var aa=['');for(var ab=0;ab');}aa.push('
    0)aa.push('style="',ac.join('; '),'" ');aa.push(' class="cke_dialog_ui_vbox_child">',T[ab],'
    ');return aa.join('');};k.dialog.uiElement.call(this,R,V||{type:'vbox'},U,'div',null,{role:'presentation'},Z);}};})();k.dialog.uiElement.prototype={getElement:function(){return a.document.getById(this.domId);},getInputElement:function(){return this.getElement();},getDialog:function(){return this._.dialog;},setValue:function(R,S){this.getInputElement().setValue(R);!S&&this.fire('change',{value:R});return this;},getValue:function(){return this.getInputElement().getValue();},isChanged:function(){return false;},selectParentTab:function(){var U=this;var R=U.getInputElement(),S=R,T;while((S=S.getParent())&&S.$.className.search('cke_dialog_page_contents')==-1){}if(!S)return U;T=S.getAttribute('name');if(U._.dialog._.currentTabId!=T)U._.dialog.selectPage(T);return U;},focus:function(){this.selectParentTab().getInputElement().focus();return this;},registerEvents:function(R){var S=/^on([A-Z]\w+)/,T,U=function(W,X,Y,Z){X.on('load',function(){W.getInputElement().on(Y,Z,W);});};for(var V in R){if(!(T=V.match(S)))continue;if(this.eventProcessors[V])this.eventProcessors[V].call(this,this._.dialog,R[V]);else U(this,this._.dialog,T[1].toLowerCase(),R[V]);}return this;},eventProcessors:{onLoad:function(R,S){R.on('load',S,this);},onShow:function(R,S){R.on('show',S,this);},onHide:function(R,S){R.on('hide',S,this);}},accessKeyDown:function(R,S){this.focus();},accessKeyUp:function(R,S){},disable:function(){var R=this.getElement(),S=this.getInputElement();S.setAttribute('disabled','true');R.addClass('cke_disabled');},enable:function(){var R=this.getElement(),S=this.getInputElement();S.removeAttribute('disabled');R.removeClass('cke_disabled');},isEnabled:function(){return!this.getElement().hasClass('cke_disabled');},isVisible:function(){return this.getInputElement().isVisible();},isFocusable:function(){if(!this.isEnabled()||!this.isVisible())return false;return true;}};k.dialog.hbox.prototype=e.extend(new k.dialog.uiElement(),{getChild:function(R){var S=this;if(arguments.length<1)return S._.children.concat();if(!R.splice)R=[R];if(R.length<2)return S._.children[R[0]];else return S._.children[R[0]]&&S._.children[R[0]].getChild?S._.children[R[0]].getChild(R.slice(1,R.length)):null;}},true);k.dialog.vbox.prototype=new k.dialog.hbox(); -(function(){var R={build:function(S,T,U){var V=T.children,W,X=[],Y=[];for(var Z=0;Z',T||U.name,'');return V.join('');}};a.style.getStyleText=function(T){var U=T._ST;if(U)return U;U=T.styles;var V=T.attributes&&T.attributes.style||'',W='';if(V.length)V=V.replace(o,';');for(var X in U){var Y=U[X],Z=(X+':'+Y).replace(o,';');if(Y=='inherit')W+=Z;else V+=Z;}if(V.length)V=P(V);V+=W;return T._ST=V;};function s(T){var U,V;while(T=T.getParent()){if(T.getName()=='body')break;if(T.getAttribute('data-nostyle'))U=T;else if(!V){var W=T.getAttribute('contentEditable');if(W=='false')U=T;else if(W=='true')V=1;}}return U;};function t(T){var ay=this;var U=T.document;if(T.collapsed){var V=J(ay,U);T.insertNode(V);T.moveToPosition(V,2);return;}var W=ay.element,X=ay._.definition,Y,Z=X.ignoreReadonly,aa=Z||X.includeReadonly;if(aa==undefined)aa=U.getCustomData('cke_includeReadonly');var ab=f[W]||(Y=true,f.span);T.enlarge(1,1);T.trim();var ac=T.createBookmark(),ad=ac.startNode,ae=ac.endNode,af=ad,ag;if(!Z){var ah=s(ad),ai=s(ae);if(ah)af=ah.getNextSourceNode(true);if(ai)ae=ai;}if(af.getPosition(ae)==2)af=0;while(af){var aj=false;if(af.equals(ae)){af=null;aj=true;}else{var ak=af.type,al=ak==1?af.getName():null,am=al&&af.getAttribute('contentEditable')=='false',an=al&&af.getAttribute('data-nostyle');if(al&&af.data('cke-bookmark')){af=af.getNextSourceNode(true);continue;}if(!al||ab[al]&&!an&&(!am||aa)&&(af.getPosition(ae)|4|0|8)==4+0+8&&(!X.childRule||X.childRule(af))){var ao=af.getParent(); -if(ao&&((ao.getDtd()||f.span)[W]||Y)&&(!X.parentRule||X.parentRule(ao))){if(!ag&&(!al||!f.$removeEmpty[al]||(af.getPosition(ae)|4|0|8)==4+0+8)){ag=new d.range(U);ag.setStartBefore(af);}if(ak==3||am||ak==1&&!af.getChildCount()){var ap=af,aq;while((aj=!ap.getNext(q))&&(aq=ap.getParent(),ab[aq.getName()])&&(aq.getPosition(ad)|2|0|8)==2+0+8&&(!X.childRule||X.childRule(aq)))ap=aq;ag.setEndAfter(ap);}}else aj=true;}else aj=true;af=af.getNextSourceNode(an||am);}if(aj&&ag&&!ag.collapsed){var ar=J(ay,U),as=ar.hasAttributes(),at=ag.getCommonAncestor(),au={styles:{},attrs:{},blockedStyles:{},blockedAttrs:{}},av,aw,ax;while(ar&&at){if(at.getName()==W){for(av in X.attributes){if(au.blockedAttrs[av]||!(ax=at.getAttribute(aw)))continue;if(ar.getAttribute(av)==ax)au.attrs[av]=1;else au.blockedAttrs[av]=1;}for(aw in X.styles){if(au.blockedStyles[aw]||!(ax=at.getStyle(aw)))continue;if(ar.getStyle(aw)==ax)au.styles[aw]=1;else au.blockedStyles[aw]=1;}}at=at.getParent();}for(av in au.attrs)ar.removeAttribute(av);for(aw in au.styles)ar.removeStyle(aw);if(as&&!ar.hasAttributes())ar=null;if(ar){ag.extractContents().appendTo(ar);G(ay,ar);ag.insertNode(ar);ar.mergeSiblings();if(!c)ar.$.normalize();}else{ar=new h('span');ag.extractContents().appendTo(ar);ag.insertNode(ar);G(ay,ar);ar.remove(true);}ag=null;}}T.moveToBookmark(ac);T.shrink(2);};function u(T){T.enlarge(1,1);var U=T.createBookmark(),V=U.startNode;if(T.collapsed){var W=new d.elementPath(V.getParent()),X;for(var Y=0,Z;Y'+V+'';else T.setHtml(V);U.remove();};function B(T){var U=/(\S\s*)\n(?:\s|(]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi,V=T.getName(),W=C(T.getOuterHtml(),U,function(Y,Z,aa){return Z+''+aa+'
    ';}),X=[];W.replace(/([\s\S]*?)<\/pre>/gi,function(Y,Z){X.push(Z);});return X;};function C(T,U,V){var W='',X='';T=T.replace(/(^]+data-cke-bookmark.*?\/span>)|(]+data-cke-bookmark.*?\/span>$)/gi,function(Y,Z,aa){Z&&(W=Z);aa&&(X=aa);return '';});return W+T.replace(U,V)+X;};function D(T,U){var V;if(T.length>1)V=new d.documentFragment(U.getDocument());for(var W=0;W');X=X.replace(/[ \t]{2,}/g,function(Z){return e.repeat(' ',Z.length-1)+' ';});if(V){var Y=U.clone();Y.setHtml(X);V.append(Y);}else U.setHtml(X);}return V||U;};function E(T,U){var V=T.getBogus();V&&V.remove();var W=T.getHtml();W=C(W,/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g,'');W=W.replace(/[ \t\r\n]*(]*>)[ \t\r\n]*/gi,'$1');W=W.replace(/([ \t\n\r]+| )/g,' ');W=W.replace(/]*>/gi,'\n');if(c){var X=T.getDocument().createElement('div');X.append(U);U.$.outerHTML='
    '+W+'
    ';U.copyAttributes(X.getFirst());U=X.getFirst().remove();}else U.setHtml(W);return U;};function F(T,U){var V=T._.definition,W=V.attributes,X=V.styles,Y=N(T)[U.getName()],Z=e.isEmpty(W)&&e.isEmpty(X);for(var aa in W){if((aa=='class'||T._.definition.fullMatch)&&U.getAttribute(aa)!=O(aa,W[aa]))continue;Z=U.hasAttribute(aa);U.removeAttribute(aa);}for(var ab in X){if(T._.definition.fullMatch&&U.getStyle(ab)!=O(ab,X[ab],true))continue;Z=Z||!!U.getStyle(ab);U.removeStyle(ab);}H(U,Y,m[U.getName()]);if(Z)!f.$block[U.getName()]||T._.enterMode==2&&!U.hasAttributes()?I(U):U.renameNode(T._.enterMode==1?'p':'div');};function G(T,U){var V=T._.definition,W=V.attributes,X=V.styles,Y=N(T),Z=U.getElementsByTag(T.element);for(var aa=Z.count();--aa>=0;)F(T,Z.getItem(aa));for(var ab in Y){if(ab!=T.element){Z=U.getElementsByTag(ab);for(aa=Z.count()-1;aa>=0;aa--){var ac=Z.getItem(aa);H(ac,Y[ab]);}}}};function H(T,U,V){var W=U&&U.attributes;if(W)for(var X=0;X0)H+=(F.$.offsetWidth||0)-(F.$.clientWidth||0)+3;H+=4;F.setStyle('width',H+'px');v.element.addClass('cke_frameLoaded');var I=v.element.$.scrollHeight;if(c&&b.quirks&&I>0)I+=(F.$.offsetHeight||0)-(F.$.clientHeight||0)+3;F.setStyle('height',I+'px');u._.currentBlock.element.setStyle('display','none').removeStyle('display');}else F.removeStyle('height');if(A)B-=w.$.offsetWidth;w.setStyle('left',B+'px');var J=u.element,K=J.getWindow(),L=w.$.getBoundingClientRect(),M=K.getViewPaneSize(),N=L.width||L.right-L.left,O=L.height||L.bottom-L.top,P=A?L.right:M.width-L.left,Q=A?M.width-L.right:L.left;if(A){if(PN)B+=N;else if(M.width>N)B-=L.left;else B=B-L.right+M.width;}else if(PN)B-=N;else if(M.width>N)B=B-L.right+M.width;else B-=L.left; -var R=M.height-L.top,S=L.top;if(RO)C-=O;else if(M.height>O)C=C-L.bottom+M.height;else C-=L.top;if(c){var T=new h(w.$.offsetParent),U=T;if(U.getName()=='html')U=U.getDocument().getBody();if(U.getComputedStyle('direction')=='rtl')if(b.ie8Compat)B-=w.getDocument().getDocumentElement().$.scrollLeft*2;else B-=T.$.scrollWidth-T.$.clientWidth;}var V=w.getFirst(),W;if(W=V.getCustomData('activePanel'))W.onHide&&W.onHide.call(this,1);V.setCustomData('activePanel',this);w.setStyles({top:C+'px',left:B+'px'});w.setOpacity(1);},this);u.isLoaded?E():u.onLoad=E;e.setTimeout(function(){x.$.contentWindow.focus();this.allowBlur(true);},0,this);},b.air?200:0,this);this.visible=1;if(this.onShow)this.onShow.call(this);n=0;},hide:function(p){var r=this;if(r.visible&&(!r.onHide||r.onHide.call(r)!==true)){r.hideChild();b.gecko&&r._.iframe.getFrameDocument().$.activeElement.blur();r.element.setStyle('display','none');r.visible=0;r.element.getFirst().removeCustomData('activePanel');var q=p!==false&&r._.returnFocus;if(q){if(b.webkit&&q.type)q.getWindow().$.focus();q.focus();}}},allowBlur:function(p){var q=this._.panel;if(p!=undefined)q.allowBlur=p;return q.allowBlur;},showAsChild:function(p,q,r,s,t,u){if(this._.activeChild==p&&p._.panel._.offsetParentId==r.getId())return;this.hideChild();p.onHide=e.bind(function(){e.setTimeout(function(){if(!this._.focused)this.hide();},0,this);},this);this._.activeChild=p;this._.focused=false;p.showBlock(q,r,s,t,u);if(b.ie7Compat||b.ie8&&b.ie6Compat)setTimeout(function(){p.element.getChild(0).$.style.cssText+='';},100);},hideChild:function(){var p=this._.activeChild;if(p){delete p.onHide;delete p._.returnFocus;delete this._.activeChild;p.hide();}}}});a.on('instanceDestroyed',function(){var p=e.isEmpty(a.instances);for(var q in m){var r=m[q];if(p)r.destroy();else r.element.hide();}p&&(m={});});})();j.add('menu',{beforeInit:function(m){var n=m.config.menu_groups.split(','),o=m._.menuGroups={},p=m._.menuItems={};for(var q=0;q'],B=r.length,C=B&&r[0].group;for(var D=0;D
    ');C=E.group;}E.render(this,D,A);}A.push('
    ');u.setHtml(A.join(''));k.fire('ready',this);if(this.parent)this.parent._.panel.showAsChild(t,this.id,n,o,p,q);else t.showBlock(this.id,n,o,p,q);s.fire('menuShow',[t]);},addListener:function(n){this._.listeners.push(n);},hide:function(n){var o=this;o._.onHide&&o._.onHide();o._.panel&&o._.panel.hide(n);}}});function m(n){n.sort(function(o,p){if(o.groupp.group)return 1;return o.orderp.order?1:0;});};a.menuItem=e.createClass({$:function(n,o,p){var q=this;e.extend(q,p,{order:0,className:'cke_button_'+o});q.group=n._.menuGroups[q.group];q.editor=n;q.name=o;},proto:{render:function(n,o,p){var w=this;var q=n.id+String(o),r=typeof w.state=='undefined'?2:w.state,s=' cke_'+(r==1?'on':r==0?'disabled':'off'),t=w.label;if(w.className)s+=' '+w.className;var u=w.getItems;p.push(''+''+'');if(u)p.push('','&#',w.editor.lang.dir=='rtl'?'9668':'9658',';','');p.push(t,'');}}});})();i.menu_groups='clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea,div'; -(function(){var m;j.add('editingblock',{init:function(n){if(!n.config.editingBlock)return;n.on('themeSpace',function(o){if(o.data.space=='contents')o.data.html+='
    ';});n.on('themeLoaded',function(){n.fireOnce('editingBlockReady');});n.on('uiReady',function(){n.setMode(n.config.startupMode);});n.on('afterSetData',function(){if(!m){function o(){m=true;n.getMode().loadData(n.getData());m=false;};if(n.mode)o();else n.on('mode',function(){if(n.mode){o();n.removeListener('mode',arguments.callee);}});}});n.on('beforeGetData',function(){if(!m&&n.mode){m=true;n.setData(n.getMode().getData(),null,1);m=false;}});n.on('getSnapshot',function(o){if(n.mode)o.data=n.getMode().getSnapshotData();});n.on('loadSnapshot',function(o){if(n.mode)n.getMode().loadSnapshotData(o.data);});n.on('mode',function(o){o.removeListener();b.webkit&&n.container.on('focus',function(){n.focus();});if(n.config.startupFocus)n.focus();setTimeout(function(){n.fireOnce('instanceReady');a.fire('instanceReady',null,n);},0);});n.on('destroy',function(){var o=this;if(o.mode)o._.modes[o.mode].unload(o.getThemeSpace('contents'));});}});a.editor.prototype.mode='';a.editor.prototype.addMode=function(n,o){o.name=n;(this._.modes||(this._.modes={}))[n]=o;};a.editor.prototype.setMode=function(n){this.fire('beforeSetMode',{newMode:n});var o,p=this.getThemeSpace('contents'),q=this.checkDirty();if(this.mode){if(n==this.mode)return;this._.previousMode=this.mode;this.fire('beforeModeUnload');var r=this.getMode();o=r.getData();r.unload(p);this.mode='';}p.setHtml('');var s=this.getMode(n);if(!s)throw '[CKEDITOR.editor.setMode] Unknown mode "'+n+'".';if(!q)this.on('mode',function(){this.resetDirty();this.removeListener('mode',arguments.callee);});s.load(p,typeof o!='string'?this.getData():o);};a.editor.prototype.getMode=function(n){return this._.modes&&this._.modes[n||this.mode];};a.editor.prototype.focus=function(){this.forceNextSelectionCheck();var n=this.getMode();if(n)n.focus();};})();i.startupMode='wysiwyg';i.editingBlock=true;(function(){function m(){var G=this;try{var D=G.getSelection();if(!D||!D.document.getWindow().$)return;var E=D.getStartElement(),F=new d.elementPath(E);if(!F.compare(G._.selectionPreviousPath)){G._.selectionPreviousPath=F;G.fire('selectionChange',{selection:D,path:F,element:E});}}catch(H){}};var n,o;function p(){o=true;if(n)return;q.call(this);n=e.setTimeout(q,200,this);};function q(){n=null;if(o){e.setTimeout(m,0,this);o=false;}};function r(D){function E(I,J){if(!I||I.type==3)return false; -var K=D.clone();return K['moveToElementEdit'+(J?'End':'Start')](I);};var F=D.startContainer,G=D.getPreviousNode(A,null,F),H=D.getNextNode(A,null,F);if(E(G)||E(H,1))return true;if(!(G||H)&&!(F.type==1&&F.isBlockBoundary()&&F.getBogus()))return true;return false;};var s={modes:{wysiwyg:1,source:1},readOnly:c||b.webkit,exec:function(D){switch(D.mode){case 'wysiwyg':D.document.$.execCommand('SelectAll',false,null);D.forceNextSelectionCheck();D.selectionChange();break;case 'source':var E=D.textarea.$;if(c)E.createTextRange().execCommand('SelectAll');else{E.selectionStart=0;E.selectionEnd=E.value.length;}E.focus();}},canUndo:false};function t(D){w(D);var E=D.createText('​');D.setCustomData('cke-fillingChar',E);return E;};function u(D){return D&&D.getCustomData('cke-fillingChar');};function v(D){var E=D&&u(D);if(E)if(E.getCustomData('ready'))w(D);else E.setCustomData('ready',1);};function w(D){var E=D&&D.removeCustomData('cke-fillingChar');if(E){var F,G=D.getSelection().getNative(),H=G&&G.type!='None'&&G.getRangeAt(0);if(E.getLength()>1&&H&&H.intersectsNode(E.$)){F=[G.anchorOffset,G.focusOffset];var I=G.anchorNode==E.$&&G.anchorOffset>0,J=G.focusNode==E.$&&G.focusOffset>0;I&&F[0]--;J&&F[1]--;x(G)&&F.unshift(F.pop());}E.setText(E.getText().replace(/\u200B/g,''));if(F){var K=G.getRangeAt(0);K.setStart(K.startContainer,F[0]);K.setEnd(K.startContainer,F[1]);G.removeAllRanges();G.addRange(K);}}};function x(D){if(!D.isCollapsed){var E=D.getRangeAt(0);E.setStart(D.anchorNode,D.anchorOffset);E.setEnd(D.focusNode,D.focusOffset);return E.collapsed;}};j.add('selection',{init:function(D){if(b.webkit){D.on('selectionChange',function(){v(D.document);});D.on('beforeSetMode',function(){w(D.document);});var E,F;function G(){var I=D.document,J=u(I);if(J){var K=I.$.defaultView.getSelection();if(K.type=='Caret'&&K.anchorNode==J.$)F=1;E=J.getText();J.setText(E.replace(/\u200B/g,''));}};function H(){var I=D.document,J=u(I);if(J){J.setText(E);if(F){I.$.defaultView.getSelection().setPosition(J.$,J.getLength());F=0;}}};D.on('beforeUndoImage',G);D.on('afterUndoImage',H);D.on('beforeGetData',G,null,null,0);D.on('getData',H);}D.on('contentDom',function(){var I=D.document,J=a.document,K=I.getBody(),L=I.getDocumentElement();if(c){var M,N,O=1;K.on('focusin',function(V){if(V.data.$.srcElement.nodeName!='BODY')return;var W=I.getCustomData('cke_locked_selection');if(W){W.unlock(1);W.lock();}else if(M&&O){try{M.select();}catch(X){}M=null;}});K.on('focus',function(){N=1;U();});K.on('beforedeactivate',function(V){if(V.data.$.toElement)return; -N=0;O=1;});c&&D.on('blur',function(){try{I.$.selection.empty();}catch(V){}});L.on('mousedown',function(){O=0;});L.on('mouseup',function(){O=1;});var P;K.on('mousedown',function(V){if(V.data.$.button==2){var W=D.document.$.selection;if(W.type=='None')P=D.window.getScrollPosition();}T();});K.on('mouseup',function(V){if(V.data.$.button==2&&P){D.document.$.documentElement.scrollLeft=P.x;D.document.$.documentElement.scrollTop=P.y;}P=null;N=1;setTimeout(function(){U(true);},0);});K.on('keydown',T);K.on('keyup',function(){N=1;U();});if(I.$.compatMode!='BackCompat'){if(b.ie7Compat||b.ie6Compat){function Q(V,W,X){try{V.moveToPoint(W,X);}catch(Y){}};L.on('mousedown',function(V){function W(ab){ab=ab.data.$;if(Z){var ac=K.$.createTextRange();Q(ac,ab.x,ab.y);Z.setEndPoint(aa.compareEndPoints('StartToStart',ac)<0?'EndToEnd':'StartToStart',ac);Z.select();}};function X(){J.removeListener('mouseup',Y);L.removeListener('mouseup',Y);};function Y(){L.removeListener('mousemove',W);X();Z.select();};V=V.data;if(V.getTarget().is('html')&&V.$.x0)P=Q-1;else if(R<0)O=Q+1;else if(b.ie9Compat&&L.tagName=='BR'){var U=J.defaultView.getSelection();return{container:U[H?'anchorNode':'focusNode'],offset:U[H?'anchorOffset':'focusOffset']};}else return{container:I,offset:E(L)};}if(Q==-1||Q==K.length-1&&R<0){N.moveToElementText(I);N.setEndPoint('StartToStart',G);S=N.text.replace(/(\r\n|\r)/g,'\n').length;K=I.childNodes;if(!S){L=K[K.length-1];if(L.nodeType!=3)return{container:I,offset:K.length};else return{container:L,offset:L.nodeValue.length};}var V=K.length; -while(S>0&&V>0){M=K[--V];if(M.nodeType==3){T=M;S-=M.nodeValue.length;}}return{container:T,offset:-S};}else{N.collapse(R>0?true:false);N.setEndPoint(R>0?'StartToStart':'EndToStart',G);S=N.text.replace(/(\r\n|\r)/g,'\n').length;if(!S)return{container:I,offset:E(L)+(R>0?0:1)};while(S>0)try{M=L[R>0?'previousSibling':'nextSibling'];if(M.nodeType==3){S-=M.nodeValue.length;T=M;}L=M;}catch(W){return{container:I,offset:E(L)};}return{container:T,offset:R>0?-S:T.nodeValue.length+S};}};return function(){var Q=this;var G=Q.getNative(),H=G&&G.createRange(),I=Q.getType(),J;if(!G)return[];if(I==2){J=new d.range(Q.document);var K=F(H,true);J.setStart(new d.node(K.container),K.offset);K=F(H);J.setEnd(new d.node(K.container),K.offset);if(J.endContainer.getPosition(J.startContainer)&4&&J.endOffset<=J.startContainer.getIndex())J.collapse();return[J];}else if(I==3){var L=[];for(var M=0;M=L.getLength())P.setStartAfter(L);else P.setStartBefore(L);if(M&&M.type==3)if(!O)P.setEndBefore(M);else P.setEndAfter(M);var Q=new d.walker(P);Q.evaluator=function(R){if(R.type==1&&R.isReadOnly()){var S=I.clone();I.setEndBefore(R);if(I.collapsed)G.splice(H--,1);if(!(R.getPosition(P.endContainer)&16)){S.setStartAfter(R);if(!S.collapsed)G.splice(H+1,0,S);}return true;}return false;};Q.next();}}return F.ranges;};})(),getStartElement:function(){var K=this;var D=K._.cache;if(D.startElement!==undefined)return D.startElement; -var E,F=K.getNative();switch(K.getType()){case 3:return K.getSelectedElement();case 2:var G=K.getRanges()[0];if(G){if(!G.collapsed){G.optimize();while(1){var H=G.startContainer,I=G.startOffset;if(I==(H.getChildCount?H.getChildCount():H.getLength())&&!H.isBlockBoundary())G.setStartAfter(H);else break;}E=G.startContainer;if(E.type!=1)return E.getParent();E=E.getChild(G.startOffset);if(!E||E.type!=1)E=G.startContainer;else{var J=E.getFirst();while(J&&J.type==1){E=J;J=J.getFirst();}}}else{E=G.startContainer;if(E.type!=1)E=E.getParent();}E=E.$;}}return D.startElement=E?new h(E):null;},getSelectedElement:function(){var D=this._.cache;if(D.selectedElement!==undefined)return D.selectedElement;var E=this,F=e.tryThese(function(){return E.getNative().createRange().item(0);},function(){var G,H,I=E.getRanges()[0],J=I.getCommonAncestor(1,1),K={table:1,ul:1,ol:1,dl:1};for(var L in K){if(G=J.getAscendant(L,1))break;}if(G){var M=new d.range(this.document);M.setStartAt(G,1);M.setEnd(I.startContainer,I.startOffset);var N=e.extend(K,f.$listItem,f.$tableContent),O=new d.walker(M),P=function(Q,R){return function(S,T){if(S.type==3&&(!e.trim(S.getText())||S.getParent().data('cke-bookmark')))return true;var U;if(S.type==1){U=S.getName();if(U=='br'&&R&&S.equals(S.getParent().getBogus()))return true;if(T&&U in N||U in f.$removeEmpty)return true;}Q.halted=1;return false;};};O.guard=P(O);if(O.checkBackward()&&!O.halted){O=new d.walker(M);M.setStart(I.endContainer,I.endOffset);M.setEndAt(G,2);O.guard=P(O,1);if(O.checkForward()&&!O.halted)H=G.$;}}if(!H)throw 0;return H;},function(){var G=E.getRanges()[0],H,I;for(var J=2;J&&!((H=G.getEnclosedNode())&&H.type==1&&y[H.getName()]&&(I=H));J--)G.shrink(1);return I.$;});return D.selectedElement=F?new h(F):null;},getSelectedText:function(){var D=this._.cache;if(D.selectedText!==undefined)return D.selectedText;var E='',F=this.getNative();if(this.getType()==2)E=c?F.createRange().text:F.toString();return D.selectedText=E;},lock:function(){var D=this;D.getRanges();D.getStartElement();D.getSelectedElement();D.getSelectedText();D._.cache.nativeSel={};D.isLocked=1;D.document.setCustomData('cke_locked_selection',D);},unlock:function(D){var I=this;var E=I.document,F=E.getCustomData('cke_locked_selection');if(F){E.setCustomData('cke_locked_selection',null);if(D){var G=F.getSelectedElement(),H=!G&&F.getRanges();I.isLocked=0;I.reset();if(G)I.selectElement(G);else I.selectRanges(H);}}if(!F||!D){I.isLocked=0;I.reset();}},reset:function(){this._.cache={};},selectElement:function(D){var F=this; -if(F.isLocked){var E=new d.range(F.document);E.setStartBefore(D);E.setEndAfter(D);F._.cache.selectedElement=D;F._.cache.startElement=D;F._.cache.ranges=new d.rangeList(E);F._.cache.type=3;return;}E=new d.range(D.getDocument());E.setStartBefore(D);E.setEndAfter(D);E.select();F.document.fire('selectionchange');F.reset();},selectRanges:function(D){var R=this;if(R.isLocked){R._.cache.selectedElement=null;R._.cache.startElement=D[0]&&D[0].getTouchedStartNode();R._.cache.ranges=new d.rangeList(D);R._.cache.type=2;return;}if(c){if(D.length>1){var E=D[D.length-1];D[0].setEnd(E.endContainer,E.endOffset);D.length=1;}if(D[0])D[0].select();R.reset();}else{var F=R.getNative();if(!F)return;if(D.length){F.removeAllRanges();b.webkit&&w(R.document);}for(var G=0;G=0){M.collapse(1);N.setEnd(M.endContainer.$,M.endOffset);}else throw S;}F.addRange(N);}R.document.fire('selectionchange');R.reset();}},createBookmarks:function(D){return this.getRanges().createBookmarks(D);},createBookmarks2:function(D){return this.getRanges().createBookmarks2(D);},selectBookmarks:function(D){var E=[];for(var F=0;F','','',this.label,'','=10900&&!o.hc?'':" href=\"javascript:void('"+this.label+"')\"",' role="button" aria-labelledby="',p,'_label" aria-describedby="',p,'_text" aria-haspopup="true"'); -if(b.opera||b.gecko&&b.mac)n.push(' onkeypress="return false;"');if(b.gecko)n.push(' onblur="this.style.cssText = this.style.cssText;"');n.push(' onkeydown="CKEDITOR.tools.callFunction( ',t,', event, this );" onfocus="return CKEDITOR.tools.callFunction(',u,', event);" '+(c?'onclick="return false;" onmouseup':'onclick')+'="CKEDITOR.tools.callFunction(',q,', this); return false;">'+this.label+''+''+''+(b.hc?'▼':b.air?' ':'')+''+''+''+'');if(this.onRender)this.onRender();return r;},createPanel:function(m){if(this._.panel)return;var n=this._.panelDefinition,o=this._.panelDefinition.block,p=n.parent||a.document.getBody(),q=new k.floatPanel(m,p,n),r=q.addListBlock(this.id,o),s=this;q.onShow=function(){if(s.className)this.element.getFirst().addClass(s.className+'_panel');s.setState(1);r.focus(!s.multiSelect&&s.getValue());s._.on=1;if(s.onOpen)s.onOpen();};q.onHide=function(t){if(s.className)this.element.getFirst().removeClass(s.className+'_panel');s.setState(s.modes&&s.modes[m.mode]?2:0);s._.on=0;if(!t&&s.onClose)s.onClose();};q.onEscape=function(){q.hide();};r.onClick=function(t,u){s.document.getWindow().focus();if(s.onClick)s.onClick.call(s,t,u);if(u)s.setValue(t,s._.items[t]);else s.setValue('');q.hide(false);};this._.panel=q;this._.list=r;q.getBlock(this.id).onHide=function(){s._.on=0;s.setState(2);};if(this.init)this.init();},setValue:function(m,n){var p=this;p._.value=m;var o=p.document.getById('cke_'+p.id+'_text');if(o){if(!(m||n)){n=p.label;o.addClass('cke_inline_label');}else o.removeClass('cke_inline_label');o.setHtml(typeof n!='undefined'?n:m);}},getValue:function(){return this._.value||'';},unmarkAll:function(){this._.list.unmarkAll();},mark:function(m){this._.list.mark(m);},hideItem:function(m){this._.list.hideItem(m);},hideGroup:function(m){this._.list.hideGroup(m);},showAll:function(){this._.list.showAll();},add:function(m,n,o){this._.items[m]=o||m;this._.list.add(m,n,o);},startGroup:function(m){this._.list.startGroup(m);},commit:function(){var m=this;if(!m._.committed){m._.list.commit();m._.committed=1;k.fire('ready',m);}m._.committed=1;},setState:function(m){var n=this;if(n._.state==m)return;n.document.getById('cke_'+n.id).setState(m);n._.state=m;}}});k.prototype.addRichCombo=function(m,n){this.add(m,'richcombo',n);};j.add('htmlwriter');a.htmlWriter=e.createClass({base:a.htmlParser.basicWriter,$:function(){var o=this; -o.base();o.indentationChars='\t';o.selfClosingEnd=' />';o.lineBreakChars='\n';o.forceSimpleAmpersand=0;o.sortAttributes=1;o._.indent=0;o._.indentation='';o._.inPre=0;o._.rules={};var m=f;for(var n in e.extend({},m.$nonBodyContent,m.$block,m.$listItem,m.$tableContent))o.setRules(n,{indent:1,breakBeforeOpen:1,breakAfterOpen:1,breakBeforeClose:!m[n]['#'],breakAfterClose:1});o.setRules('br',{breakAfterOpen:1});o.setRules('title',{indent:0,breakAfterOpen:0});o.setRules('style',{indent:0,breakBeforeClose:1});o.setRules('pre',{indent:0});},proto:{openTag:function(m,n){var p=this;var o=p._.rules[m];if(p._.indent)p.indentation();else if(o&&o.breakBeforeOpen){p.lineBreak();p.indentation();}p._.output.push('<',m);},openTagClose:function(m,n){var p=this;var o=p._.rules[m];if(n)p._.output.push(p.selfClosingEnd);else{p._.output.push('>');if(o&&o.indent)p._.indentation+=p.indentationChars;}if(o&&o.breakAfterOpen)p.lineBreak();m=='pre'&&(p._.inPre=1);},attribute:function(m,n){if(typeof n=='string'){this.forceSimpleAmpersand&&(n=n.replace(/&/g,'&'));n=e.htmlEncodeAttr(n);}this._.output.push(' ',m,'="',n,'"');},closeTag:function(m){var o=this;var n=o._.rules[m];if(n&&n.indent)o._.indentation=o._.indentation.substr(o.indentationChars.length);if(o._.indent)o.indentation();else if(n&&n.breakBeforeClose){o.lineBreak();o.indentation();}o._.output.push('');m=='pre'&&(o._.inPre=0);if(n&&n.breakAfterClose)o.lineBreak();},text:function(m){var n=this;if(n._.indent){n.indentation();!n._.inPre&&(m=e.ltrim(m));}n._.output.push(m);},comment:function(m){if(this._.indent)this.indentation();this._.output.push('');},lineBreak:function(){var m=this;if(!m._.inPre&&m._.output.length>0)m._.output.push(m.lineBreakChars);m._.indent=1;},indentation:function(){var m=this;if(!m._.inPre)m._.output.push(m._.indentation);m._.indent=0;},setRules:function(m,n){var o=this._.rules[m];if(o)e.extend(o,n,true);else this._.rules[m]=n;}}});j.add('menubutton',{requires:['button','menu'],beforeInit:function(m){m.ui.addHandler('menubutton',k.menuButton.handler);}});a.UI_MENUBUTTON='menubutton';(function(){var m=function(n){var o=this._;if(o.state===0)return;o.previousState=o.state;var p=o.menu;if(!p){p=o.menu=new a.menu(n,{panel:{className:n.skinClass+' cke_contextmenu',attributes:{'aria-label':n.lang.common.options}}});p.onHide=e.bind(function(){this.setState(this.modes&&this.modes[n.mode]?o.previousState:0);},this);if(this.onMenu)p.addListener(this.onMenu);}if(o.on){p.hide();return;}this.setState(1); -p.show(a.document.getById(this._.id),4);};k.menuButton=e.createClass({base:k.button,$:function(n){var o=n.panel;delete n.panel;this.base(n);this.hasArrow=true;this.click=m;},statics:{handler:{create:function(n){return new k.menuButton(n);}}}});})();j.add('dialogui');(function(){var m=function(u){var x=this;x._||(x._={});x._['default']=x._.initValue=u['default']||'';x._.required=u.required||false;var v=[x._];for(var w=1;w',v.label,'','');else{var D={type:'hbox',widths:v.widths,padding:0,children:[{type:'html',html:'
    ');return o;},getHolderElement:function(){var m=this._.holder;if(!m){if(this.forceIFrame||this.css.length){var n=this.document.getById(this.id+'_frame'),o=n.getParent(),p=o.getAttribute('dir'),q=o.getParent().getAttribute('class'),r=o.getParent().getAttribute('lang'),s=n.getFrameDocument();b.iOS&&o.setStyles({overflow:'scroll','-webkit-overflow-scrolling':'touch'});var t=e.addFunction(e.bind(function(w){this.isLoaded=true;if(this.onLoad)this.onLoad();},this)),u=''+''+''+e.buildStyleHtml(this.css)+''+''+''; -s.write(u);var v=s.getWindow();v.$.CKEDITOR=a;s.on('key'+(b.opera?'press':'down'),function(w){var z=this;var x=w.data.getKeystroke(),y=z.document.getById(z.id).getAttribute('dir');if(z._.onKeyDown&&z._.onKeyDown(x)===false){w.data.preventDefault();return;}if(x==27||x==(y=='rtl'?39:37))if(z.onEscape&&z.onEscape(x)===false)w.data.preventDefault();},this);m=s.getBody();m.unselectable();b.air&&e.callFunction(t);}else m=this.document.getById(this.id);this._.holder=m;}return m;},addBlock:function(m,n){var o=this;n=o._.blocks[m]=n instanceof k.panel.block?n:new k.panel.block(o.getHolderElement(),n);if(!o._.currentBlock)o.showBlock(m);return n;},getBlock:function(m){return this._.blocks[m];},showBlock:function(m){var r=this;var n=r._.blocks,o=n[m],p=r._.currentBlock,q=!r.forceIFrame||c?r._.holder:r.document.getById(r.id+'_frame');if(p){q.removeAttributes(p.attributes);p.hide();}r._.currentBlock=o;q.setAttributes(o.attributes);a.fire('ariaWidget',q);o._.focusIndex=-1;r._.onKeyDown=o.onKeyDown&&e.bind(o.onKeyDown,o);o.show();return o;},destroy:function(){this.element&&this.element.remove();}};k.panel.block=e.createClass({$:function(m,n){var o=this;o.element=m.append(m.getDocument().createElement('div',{attributes:{tabIndex:-1,'class':'cke_panel_block',role:'presentation'},styles:{display:'none'}}));if(n)e.extend(o,n);if(!o.attributes.title)o.attributes.title=o.attributes['aria-label'];o.keys={};o._.focusIndex=-1;o.element.disableContextMenu();},_:{markItem:function(m){var p=this;if(m==-1)return;var n=p.element.getElementsByTag('a'),o=n.getItem(p._.focusIndex=m);if(b.webkit||b.opera)o.getDocument().getWindow().focus();o.focus();p.onMark&&p.onMark(o);}},proto:{show:function(){this.element.setStyle('display','');},hide:function(){var m=this;if(!m.onHide||m.onHide.call(m)!==true)m.element.setStyle('display','none');},onKeyDown:function(m){var r=this;var n=r.keys[m];switch(n){case 'next':var o=r._.focusIndex,p=r.element.getElementsByTag('a'),q;while(q=p.getItem(++o)){if(q.getAttribute('_cke_focus')&&q.$.offsetWidth){r._.focusIndex=o;q.focus();break;}}return false;case 'prev':o=r._.focusIndex;p=r.element.getElementsByTag('a');while(o>0&&(q=p.getItem(--o))){if(q.getAttribute('_cke_focus')&&q.$.offsetWidth){r._.focusIndex=o;q.focus();break;}}return false;case 'click':case 'mouseup':o=r._.focusIndex;q=o>=0&&r.element.getElementsByTag('a').getItem(o);if(q)q.$[n]?q.$[n]():q.$['on'+n]();return false;}return true;}}});j.add('listblock',{requires:['panel'],onLoad:function(){k.panel.prototype.addListBlock=function(m,n){return this.addBlock(m,new k.listBlock(this.getHolderElement(),n)); -};k.listBlock=e.createClass({base:k.panel.block,$:function(m,n){var q=this;n=n||{};var o=n.attributes||(n.attributes={});(q.multiSelect=!!n.multiSelect)&&(o['aria-multiselectable']=true);!o.role&&(o.role='listbox');q.base.apply(q,arguments);var p=q.keys;p[40]='next';p[9]='next';p[38]='prev';p[2228224+9]='prev';p[32]=c?'mouseup':'click';c&&(p[13]='mouseup');q._.pendingHtml=[];q._.items={};q._.groups={};},_:{close:function(){if(this._.started){this._.pendingHtml.push('');delete this._.started;}},getClick:function(){if(!this._.click)this._.click=e.addFunction(function(m){var o=this;var n=true;if(o.multiSelect)n=o.toggle(m);else o.mark(m);if(o.onClick)o.onClick(m,n);},this);return this._.click;}},proto:{add:function(m,n,o){var r=this;var p=r._.pendingHtml,q=e.getNextId();if(!r._.started){p.push('
    ',a.document);a.document.getBody().append(f);}if(!/%$/.test(g)){f.setStyle('width',g);return f.$.clientWidth;}return g;};})(),repeat:function(f,g){return new Array(g+1).join(f);},tryThese:function(){var f;for(var g=0,h=arguments.length;g8))&&i)h=i+':'+h;return new d.nodeList(this.$.getElementsByTagName(h));},getHead:function(){var h=this.$.getElementsByTagName('head')[0];if(!h)h=this.getDocumentElement().append(new d.element('head'),true);else h=new d.element(h);return(this.getHead=function(){return h;})();},getBody:function(){var h=new d.element(this.$.body);return(this.getBody=function(){return h;})();},getDocumentElement:function(){var h=new d.element(this.$.documentElement);return(this.getDocumentElement=function(){return h;})();},getWindow:function(){var h=new d.window(this.$.parentWindow||this.$.defaultView);return(this.getWindow=function(){return h;})();},write:function(h){var i=this;i.$.open('text/html','replace');b.isCustomDomain()&&(i.$.domain=document.domain);i.$.write(h);i.$.close();}});d.node=function(h){if(h){var i=h.nodeType==9?'document':h.nodeType==1?'element':h.nodeType==3?'text':h.nodeType==8?'comment':'domObject';return new d[i](h);}return this;};d.node.prototype=new d.domObject();a.NODE_ELEMENT=1; +a.NODE_DOCUMENT=9;a.NODE_TEXT=3;a.NODE_COMMENT=8;a.NODE_DOCUMENT_FRAGMENT=11;a.POSITION_IDENTICAL=0;a.POSITION_DISCONNECTED=1;a.POSITION_FOLLOWING=2;a.POSITION_PRECEDING=4;a.POSITION_IS_CONTAINED=8;a.POSITION_CONTAINS=16;e.extend(d.node.prototype,{appendTo:function(h,i){h.append(this,i);return h;},clone:function(h,i){var j=this.$.cloneNode(h),k=function(l){if(l.nodeType!=1)return;if(!i)l.removeAttribute('id',false);l['data-cke-expando']=undefined;if(h){var m=l.childNodes;for(var n=0;n]*>/g,''):l;},getOuterHtml:function(){var m=this;if(m.$.outerHTML)return m.$.outerHTML.replace(/<\?[^>]*>/,'');var l=m.$.ownerDocument.createElement('div');l.appendChild(m.$.cloneNode(true));return l.innerHTML;},setHtml:function(l){return this.$.innerHTML=l;},setText:function(l){h.prototype.setText=this.$.innerText!=undefined?function(m){return this.$.innerText=m;}:function(m){return this.$.textContent=m;};return this.setText(l);},getAttribute:(function(){var l=function(m){return this.$.getAttribute(m,2);};if(c&&(b.ie7Compat||b.ie6Compat))return function(m){var q=this;switch(m){case 'class':m='className';break;case 'http-equiv':m='httpEquiv';break;case 'name':return q.$.name;case 'tabindex':var n=l.call(q,m);if(n!==0&&q.$.tabIndex===0)n=null;return n;break;case 'checked':var o=q.$.attributes.getNamedItem(m),p=o.specified?o.nodeValue:q.$.checked;return p?'checked':null;case 'hspace':case 'value':return q.$[m];case 'style':return q.$.style.cssText;case 'contenteditable':case 'contentEditable':return q.$.attributes.getNamedItem('contentEditable').specified?q.$.getAttribute('contentEditable'):null;}return l.call(q,m);};else return l;})(),getChildren:function(){return new d.nodeList(this.$.childNodes);},getComputedStyle:c?function(l){return this.$.currentStyle[e.cssStyleToDomStyle(l)];}:function(l){var m=this.getWindow().$.getComputedStyle(this.$,null);return m?m.getPropertyValue(l):'';},getDtd:function(){var l=f[this.getName()];this.getDtd=function(){return l;};return l;},getElementsByTag:g.prototype.getElementsByTag,getTabIndex:c?function(){var l=this.$.tabIndex;if(l===0&&!f.$tabIndex[this.getName()]&&parseInt(this.getAttribute('tabindex'),10)!==0)l=-1;return l;}:b.webkit?function(){var l=this.$.tabIndex;if(l==undefined){l=parseInt(this.getAttribute('tabindex'),10);if(isNaN(l))l=-1;}return l;}:function(){return this.$.tabIndex;},getText:function(){return this.$.textContent||this.$.innerText||'';},getWindow:function(){return this.getDocument().getWindow();},getId:function(){return this.$.id||null;},getNameAtt:function(){return this.$.name||null;},getName:function(){var l=this.$.nodeName.toLowerCase();if(c&&!(document.documentMode>8)){var m=this.$.scopeName;if(m!='HTML')l=m.toLowerCase()+':'+l;}return(this.getName=function(){return l; +})();},getValue:function(){return this.$.value;},getFirst:function(l){var m=this.$.firstChild,n=m&&new d.node(m);if(n&&l&&!l(n))n=n.getNext(l);return n;},getLast:function(l){var m=this.$.lastChild,n=m&&new d.node(m);if(n&&l&&!l(n))n=n.getPrevious(l);return n;},getStyle:function(l){return this.$.style[e.cssStyleToDomStyle(l)];},is:function(){var l=this.getName();for(var m=0;m0&&(m>2||!n[l[0].nodeName]||m==2&&!n[l[1].nodeName]);},hasAttribute:(function(){function l(m){var n=this.$.attributes.getNamedItem(m);return!!(n&&n.specified);};return c&&b.version<8?function(m){if(m=='name')return!!this.$.name;return l.call(this,m);}:l;})(),hide:function(){this.setStyle('display','none');},moveChildren:function(l,m){var n=this.$; +l=l.$;if(n==l)return;var o;if(m)while(o=n.lastChild)l.insertBefore(n.removeChild(o),l.firstChild);else while(o=n.firstChild)l.appendChild(n.removeChild(o));},mergeSiblings:(function(){function l(m,n,o){if(n&&n.type==1){var p=[];while(n.data('cke-bookmark')||n.isEmptyInlineRemoveable()){p.push(n);n=o?n.getNext():n.getPrevious();if(!n||n.type!=1)return;}if(m.isIdentical(n)){var q=o?m.getLast():m.getFirst();while(p.length)p.shift().move(m,!o);n.moveChildren(m,!o);n.remove();if(q&&q.type==1)q.mergeSiblings();}}};return function(m){var n=this;if(!(m===false||f.$removeEmpty[n.getName()]||n.is('a')))return;l(n,n.getNext(),true);l(n,n.getPrevious());};})(),show:function(){this.setStyles({display:'',visibility:''});},setAttribute:(function(){var l=function(m,n){this.$.setAttribute(m,n);return this;};if(c&&(b.ie7Compat||b.ie6Compat))return function(m,n){var o=this;if(m=='class')o.$.className=n;else if(m=='style')o.$.style.cssText=n;else if(m=='tabindex')o.$.tabIndex=n;else if(m=='checked')o.$.checked=n;else if(m=='contenteditable')l.call(o,'contentEditable',n);else l.apply(o,arguments);return o;};else if(b.ie8Compat&&b.secure)return function(m,n){if(m=='src'&&n.match(/^http:\/\//))try{l.apply(this,arguments);}catch(o){}else l.apply(this,arguments);return this;};else return l;})(),setAttributes:function(l){for(var m in l)this.setAttribute(m,l[m]);return this;},setValue:function(l){this.$.value=l;return this;},removeAttribute:(function(){var l=function(m){this.$.removeAttribute(m);};if(c&&(b.ie7Compat||b.ie6Compat))return function(m){if(m=='class')m='className';else if(m=='tabindex')m='tabIndex';else if(m=='contenteditable')m='contentEditable';l.call(this,m);};else return l;})(),removeAttributes:function(l){if(e.isArray(l))for(var m=0;m=100?'':'progid:DXImageTransform.Microsoft.Alpha(opacity='+l+')');}else this.setStyle('opacity',l); +},unselectable:b.gecko?function(){this.$.style.MozUserSelect='none';this.on('dragstart',function(l){l.data.preventDefault();});}:b.webkit?function(){this.$.style.KhtmlUserSelect='none';this.on('dragstart',function(l){l.data.preventDefault();});}:function(){if(c||b.opera){var l=this.$,m=l.getElementsByTagName('*'),n,o=0;l.unselectable='on';while(n=m[o++])switch(n.tagName.toLowerCase()){case 'iframe':case 'textarea':case 'input':case 'select':break;default:n.unselectable='on';}}},getPositionedAncestor:function(){var l=this;while(l.getName()!='html'){if(l.getComputedStyle('position')!='static')return l;l=l.getParent();}return null;},getDocumentPosition:function(l){var G=this;var m=0,n=0,o=G.getDocument(),p=o.getBody(),q=o.$.compatMode=='BackCompat';if(document.documentElement.getBoundingClientRect){var r=G.$.getBoundingClientRect(),s=o.$,t=s.documentElement,u=t.clientTop||p.$.clientTop||0,v=t.clientLeft||p.$.clientLeft||0,w=true;if(c){var x=o.getDocumentElement().contains(G),y=o.getBody().contains(G);w=q&&y||!q&&x;}if(w){m=r.left+(!q&&t.scrollLeft||p.$.scrollLeft);m-=v;n=r.top+(!q&&t.scrollTop||p.$.scrollTop);n-=u;}}else{var z=G,A=null,B;while(z&&!(z.getName()=='body'||z.getName()=='html')){m+=z.$.offsetLeft-z.$.scrollLeft;n+=z.$.offsetTop-z.$.scrollTop;if(!z.equals(G)){m+=z.$.clientLeft||0;n+=z.$.clientTop||0;}var C=A;while(C&&!C.equals(z)){m-=C.$.scrollLeft;n-=C.$.scrollTop;C=C.getParent();}A=z;z=(B=z.$.offsetParent)?new h(B):null;}}if(l){var D=G.getWindow(),E=l.getWindow();if(!D.equals(E)&&D.$.frameElement){var F=new h(D.$.frameElement).getDocumentPosition(l);m+=F.x;n+=F.y;}}if(!document.documentElement.getBoundingClientRect)if(b.gecko&&!q){m+=G.$.clientLeft?1:0;n+=G.$.clientTop?1:0;}return{x:m,y:n};},scrollIntoView:function(l){var m=this.getParent();if(!m)return;do{var n=m.$.clientWidth&&m.$.clientWidth0)q(0,m===true?A.y:m===false?B.y:A.y<0?A.y:B.y);if(n&&(A.x<0||B.x>0))q(A.x<0?A.x:B.x,0);},setState:function(l){var m=this;switch(l){case 1:m.addClass('cke_on');m.removeClass('cke_off');m.removeClass('cke_disabled');break;case 0:m.addClass('cke_disabled');m.removeClass('cke_off');m.removeClass('cke_on');break;default:m.addClass('cke_off');m.removeClass('cke_on');m.removeClass('cke_disabled');break;}},getFrameDocument:function(){var l=this.$;try{l.contentWindow.document;}catch(m){l.src=l.src;if(c&&b.version<7)window.showModalDialog('javascript:document.write("")');}return l&&new g(l.contentWindow.document);},copyAttributes:function(l,m){var s=this;var n=s.$.attributes;m=m||{};for(var o=0;o0&&m)m=m.childNodes[l.shift()];return m?new d.node(m):null;},getChildCount:function(){return this.$.childNodes.length;},disableContextMenu:function(){this.on('contextmenu',function(l){if(!l.data.getTarget().hasClass('cke_enable_context_menu'))l.data.preventDefault();});},getDirection:function(l){var m=this;return l?m.getComputedStyle('direction')||m.getDirection()||m.getDocument().$.dir||m.getDocument().getBody().getDirection(1):m.getStyle('direction')||m.getAttribute('dir');},data:function(l,m){l='data-'+l;if(m===undefined)return this.getAttribute(l);else if(m===false)this.removeAttribute(l);else this.setAttribute(l,m);return null;}});var i={width:['border-left-width','border-right-width','padding-left','padding-right'],height:['border-top-width','border-bottom-width','padding-top','padding-bottom']}; +function j(l){var m=['top','left','right','bottom'],n;if(l=='border')n=['color','style','width'];var o=[];for(var p=0;p',bodyId:'',bodyClass:'',fullPage:false,height:200,plugins:'about,a11yhelp,basicstyles,bidi,blockquote,button,clipboard,colorbutton,colordialog,contextmenu,dialogadvtab,div,elementspath,enterkey,entities,filebrowser,find,flash,font,format,forms,horizontalrule,htmldataprocessor,iframe,image,indent,justify,keystrokes,link,list,liststyle,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,showblocks,showborders,smiley,sourcearea,specialchar,stylescombo,tab,table,tabletools,templates,toolbar,undo,wsc,wysiwygarea',extraPlugins:'',removePlugins:'',protectedSource:[],tabIndex:0,theme:'default',skin:'kama',width:'',baseFloatZIndex:10000}; +var i=a.config;a.focusManager=function(j){if(j.focusManager)return j.focusManager;this.hasFocus=false;this._={editor:j};return this;};a.focusManager.prototype={focus:function(){var k=this;if(k._.timer)clearTimeout(k._.timer);if(!k.hasFocus){if(a.currentInstance)a.currentInstance.focusManager.forceBlur();var j=k._.editor;j.container.getChild(1).addClass('cke_focus');k.hasFocus=true;j.fire('focus');}},blur:function(){var j=this;if(j._.timer)clearTimeout(j._.timer);j._.timer=setTimeout(function(){delete j._.timer;j.forceBlur();},100);},forceBlur:function(){if(this.hasFocus){var j=this._.editor;j.container.getChild(1).removeClass('cke_focus');this.hasFocus=false;j.fire('blur');}}};(function(){var j={};a.lang={languages:{af:1,ar:1,bg:1,bn:1,bs:1,ca:1,cs:1,cy:1,da:1,de:1,el:1,'en-au':1,'en-ca':1,'en-gb':1,en:1,eo:1,es:1,et:1,eu:1,fa:1,fi:1,fo:1,'fr-ca':1,fr:1,gl:1,gu:1,he:1,hi:1,hr:1,hu:1,is:1,it:1,ja:1,ka:1,km:1,ko:1,ku:1,lt:1,lv:1,mn:1,ms:1,nb:1,nl:1,no:1,pl:1,'pt-br':1,pt:1,ro:1,ru:1,sk:1,sl:1,'sr-latn':1,sr:1,sv:1,th:1,tr:1,ug:1,uk:1,vi:1,'zh-cn':1,zh:1},load:function(k,l,m){if(!k||!a.lang.languages[k])k=this.detect(l,k);if(!this[k])a.scriptLoader.load(a.getUrl('lang/'+k+'.js'),function(){m(k,this[k]);},this);else m(k,this[k]);},detect:function(k,l){var m=this.languages;l=l||navigator.userLanguage||navigator.language||k;var n=l.toLowerCase().match(/([a-z]+)(?:-([a-z]+))?/),o=n[1],p=n[2];if(m[o+'-'+p])o=o+'-'+p;else if(!m[o])o=null;a.lang.detect=o?function(){return o;}:function(q){return q;};return o||k;}};})();a.scriptLoader=(function(){var j={},k={};return{load:function(l,m,n,o){var p=typeof l=='string';if(p)l=[l];if(!n)n=a;var q=l.length,r=[],s=[],t=function(y){if(m)if(p)m.call(n,y);else m.call(n,r,s);};if(q===0){t(true);return;}var u=function(y,z){(z?r:s).push(y);if(--q<=0){o&&a.document.getDocumentElement().removeStyle('cursor');t(z);}},v=function(y,z){j[y]=1;var A=k[y];delete k[y];for(var B=0;B1)return;var A=new h('script');A.setAttributes({type:'text/javascript',src:y});if(m)if(c)A.$.onreadystatechange=function(){if(A.$.readyState=='loaded'||A.$.readyState=='complete'){A.$.onreadystatechange=null;v(y,true);}};else{A.$.onload=function(){setTimeout(function(){v(y,true);},0);};A.$.onerror=function(){v(y,false);};}A.appendTo(a.document.getHead());};o&&a.document.getDocumentElement().setStyle('cursor','wait');for(var x=0;x1)return;var w=!p.css||!p.css.length,x=!p.js||!p.js.length,y=function(){if(w&&x){p._isLoaded=1;for(var B=0;B=0?x.langCode:J[0];if(!I.langEntries||!I.langEntries[L])G.push(a.getUrl(K+'lang/'+L+'.js'));else{e.extend(x.lang,I.langEntries[L]);L=null;}}F.push(L);E.push(I);}a.scriptLoader.load(G,function(){var M=['beforeInit','init','afterInit'];for(var N=0;N]+)>)|(?:!--([\\S|\\s]*?)-->)|(?:([^\\s>]+)\\s*((?:(?:\"[^\"]*\")|(?:'[^']*')|[^\"'>])*)\\/?>))",'g')};};(function(){var l=/([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g,m={checked:1,compact:1,declare:1,defer:1,disabled:1,ismap:1,multiple:1,nohref:1,noresize:1,noshade:1,nowrap:1,readonly:1,selected:1};a.htmlParser.prototype={onTagOpen:function(){},onTagClose:function(){},onText:function(){},onCDATA:function(){},onComment:function(){},parse:function(n){var A=this;var o,p,q=0,r;while(o=A._.htmlPartsRegex.exec(n)){var s=o.index;if(s>q){var t=n.substring(q,s);if(r)r.push(t);else A.onText(t);}q=A._.htmlPartsRegex.lastIndex;if(p=o[1]){p=p.toLowerCase();if(r&&f.$cdata[p]){A.onCDATA(r.join(''));r=null;}if(!r){A.onTagClose(p);continue;}}if(r){r.push(o[0]);continue;}if(p=o[3]){p=p.toLowerCase();if(/="/.test(p))continue; +var u={},v,w=o[4],x=!!(w&&w.charAt(w.length-1)=='/');if(w)while(v=l.exec(w)){var y=v[1].toLowerCase(),z=v[2]||v[3]||v[4]||'';if(!z&&m[y])u[y]=y;else u[y]=z;}A.onTagOpen(p,u,x);if(!r&&f.$cdata[p])r=[];continue;}if(p=o[2])A.onComment(p);}if(n.length>q)A.onText(n.substring(q,n.length));}};})();a.htmlParser.comment=function(l){this.value=l;this._={isBlockLike:false};};a.htmlParser.comment.prototype={type:8,writeHtml:function(l,m){var n=this.value;if(m){if(!(n=m.onComment(n,this)))return;if(typeof n!='string'){n.parent=this.parent;n.writeHtml(l,m);return;}}l.comment(n);}};(function(){a.htmlParser.text=function(l){this.value=l;this._={isBlockLike:false};};a.htmlParser.text.prototype={type:3,writeHtml:function(l,m){var n=this.value;if(m&&!(n=m.onText(n,this)))return;l.text(n);}};})();(function(){a.htmlParser.cdata=function(l){this.value=l;};a.htmlParser.cdata.prototype={type:3,writeHtml:function(l){l.write(this.value);}};})();a.htmlParser.fragment=function(){this.children=[];this.parent=null;this._={isBlockLike:true,hasInlineStarted:false};};(function(){var l=e.extend({table:1,ul:1,ol:1,dl:1},f.table,f.ul,f.ol,f.dl),m=c&&b.version<8?{dd:1,dt:1}:{},n={ol:1,ul:1},o=e.extend({},{html:1},f.html,f.body,f.head,{style:1,script:1});function p(q){return q.name=='a'&&q.attributes.href||f.$removeEmpty[q.name];};a.htmlParser.fragment.fromHtml=function(q,r,s){var t=new a.htmlParser(),u=s||new a.htmlParser.fragment(),v=[],w=[],x=u,y=false,z=false;function A(D){var E;if(v.length>0)for(var F=0;F=0;E--){if(D==v[E].name){v.splice(E,1);return;}}var F=[],G=[],H=x;while(H!=u&&H.name!=D){if(!H._.isBlockLike)G.unshift(H);F.push(H);H=H.returnPoint||H.parent;}if(H!=u){for(E=0;E0?t.children[r-1]:null;if(s){if(q._.isBlockLike&&s.type==3){s.value=e.rtrim(s.value);if(s.value.length===0){t.children.pop();t.add(q);return;}}s.next=q;}q.previous=s;q.parent=t;t.children.splice(r,0,q);t._.hasInlineStarted=q.type==3||q.type==1&&!q._.isBlockLike;},writeHtml:function(q,r){var s;this.filterChildren=function(){var t=new a.htmlParser.basicWriter();this.writeChildrenHtml.call(this,t,r,true);var u=t.getHtml();this.children=new a.htmlParser.fragment.fromHtml(u).children;s=1;};!this.name&&r&&r.onFragment(this);this.writeChildrenHtml(q,s?null:r);},writeChildrenHtml:function(q,r){for(var s=0;sn?1:0;};a.htmlParser.element.prototype={type:1,add:a.htmlParser.fragment.prototype.add,clone:function(){return new a.htmlParser.element(this.name,this.attributes);},writeHtml:function(m,n){var o=this.attributes,p=this,q=p.name,r,s,t,u;p.filterChildren=function(){if(!u){var B=new a.htmlParser.basicWriter();a.htmlParser.fragment.prototype.writeChildrenHtml.call(p,B,n);p.children=new a.htmlParser.fragment.fromHtml(B.getHtml(),0,p.clone()).children;u=1;}};if(n){for(;;){if(!(q=n.onElementName(q)))return;p.name=q;if(!(p=n.onElement(p)))return;p.parent=this.parent;if(p.name==q)break;if(p.type!=1){p.writeHtml(m,n);return;}q=p.name;if(!q){for(var v=0,w=this.children.length;v=0;u--){var x=r[u];if(x){x.pri=s;q.splice(t,0,x);}}}};function n(q,r,s){if(r)for(var t in r){var u=q[t];q[t]=o(u,r[t],s);if(!u)q.$length++;}};function o(q,r,s){if(r){r.pri=s;if(q){if(!q.splice){if(q.pri>s)q=[r,q];else q=[q,r];q.filter=p;}else m(q,r,s);return q;}else{r.filter=r;return r;}}};function p(q){var r=q.type||q instanceof a.htmlParser.fragment;for(var s=0;s');else this._.output.push('>');},attribute:function(l,m){if(typeof m=='string')m=e.htmlEncodeAttr(m);this._.output.push(' ',l,'="',m,'"');},closeTag:function(l){this._.output.push('');},text:function(l){this._.output.push(l);},comment:function(l){this._.output.push('');},write:function(l){this._.output.push(l); +},reset:function(){this._.output=[];this._.indent=false;},getHtml:function(l){var m=this._.output.join('');if(l)this.reset();return m;}}});delete a.loadFullCore;a.instances={};a.document=new g(document);a.add=function(l){a.instances[l.name]=l;l.on('focus',function(){if(a.currentInstance!=l){a.currentInstance=l;a.fire('currentInstance');}});l.on('blur',function(){if(a.currentInstance==l){a.currentInstance=null;a.fire('currentInstance');}});};a.remove=function(l){delete a.instances[l.name];};a.on('instanceDestroyed',function(){if(e.isEmpty(this.instances))a.fire('reset');});a.TRISTATE_ON=1;a.TRISTATE_OFF=2;a.TRISTATE_DISABLED=0;d.comment=function(l,m){if(typeof l=='string')l=(m?m.$:document).createComment(l);d.domObject.call(this,l);};d.comment.prototype=new d.node();e.extend(d.comment.prototype,{type:8,getOuterHtml:function(){return '';}});(function(){var l={address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,dd:1,legend:1,caption:1},m={body:1,div:1,table:1,tbody:1,tr:1,td:1,th:1,form:1,fieldset:1},n=function(o){var p=o.getChildren();for(var q=0,r=p.count();q0)v=v.getChild(z-1);else v=A(v,true)===false?null:v.getPreviousSourceNode(true,C,A);}else{v=w;if(v.type==1)if(!(v=v.getChild(y)))v=A(w,true)===false?null:w.getNextSourceNode(true,C,A);}if(v&&A(v)===false)v=null;}while(v&&!this._.end){this.current=v;if(!this.evaluator||this.evaluator(v)!==false){if(!t)return v;}else if(t&&this.evaluator)return false;v=v[D](false,C,A);}this.end();return this.current=null;};function m(s){var t,u=null;while(t=l.call(this,s))u=t;return u;};d.walker=e.createClass({$:function(s){this.range=s;this._={};},proto:{end:function(){this._.end=1;},next:function(){return l.call(this);},previous:function(){return l.call(this,1);},checkForward:function(){return l.call(this,0,1)!==false;},checkBackward:function(){return l.call(this,1,1)!==false;},lastForward:function(){return m.call(this);},lastBackward:function(){return m.call(this,1);},reset:function(){delete this.current;this._={};}}});var n={block:1,'list-item':1,table:1,'table-row-group':1,'table-header-group':1,'table-footer-group':1,'table-row':1,'table-column-group':1,'table-column':1,'table-cell':1,'table-caption':1};h.prototype.isBlockBoundary=function(s){var t=s?e.extend({},f.$block,s||{}):f.$block; +return this.getComputedStyle('float')=='none'&&n[this.getComputedStyle('display')]||t[this.getName()];};d.walker.blockBoundary=function(s){return function(t,u){return!(t.type==1&&t.isBlockBoundary(s));};};d.walker.listItemBoundary=function(){return this.blockBoundary({br:1});};d.walker.bookmark=function(s,t){function u(v){return v&&v.getName&&v.getName()=='span'&&v.data('cke-bookmark');};return function(v){var w,x;w=v&&!v.getName&&(x=v.getParent())&&u(x);w=s?w:w||u(v);return!!(t^w);};};d.walker.whitespaces=function(s){return function(t){var u;if(t&&t.type==3)u=!e.trim(t.getText())||b.webkit&&t.getText()=='​';return!!(s^u);};};d.walker.invisible=function(s){var t=d.walker.whitespaces();return function(u){var v;if(t(u))v=1;else{if(u.type==3)u=u.getParent();v=!u.$.offsetHeight;}return!!(s^v);};};d.walker.nodeType=function(s,t){return function(u){return!!(t^u.type==s);};};d.walker.bogus=function(s){function t(u){return!p(u)&&!q(u);};return function(u){var v=!c?u.is&&u.is('br'):u.getText&&o.test(u.getText());if(v){var w=u.getParent(),x=u.getNext(t);v=w.isBlockBoundary()&&(!x||x.type==1&&x.isBlockBoundary());}return!!(s^v);};};var o=/^[\t\r\n ]*(?: |\xa0)$/,p=d.walker.whitespaces(),q=d.walker.bookmark(),r=function(s){return q(s)||p(s)||s.type==1&&s.getName() in f.$inline&&!(s.getName() in f.$empty);};h.prototype.getBogus=function(){var s=this;do s=s.getPreviousSourceNode();while(r(s));if(s&&(!c?s.is&&s.is('br'):s.getText&&o.test(s.getText())))return s;return false;};})();d.range=function(l){var m=this;m.startContainer=null;m.startOffset=null;m.endContainer=null;m.endOffset=null;m.collapsed=true;m.document=l;};(function(){var l=function(v){v.collapsed=v.startContainer&&v.endContainer&&v.startContainer.equals(v.endContainer)&&v.startOffset==v.endOffset;},m=function(v,w,x,y){v.optimizeBookmark();var z=v.startContainer,A=v.endContainer,B=v.startOffset,C=v.endOffset,D,E;if(A.type==3)A=A.split(C);else if(A.getChildCount()>0)if(C>=A.getChildCount()){A=A.append(v.document.createText(''));E=true;}else A=A.getChild(C);if(z.type==3){z.split(B);if(z.equals(A))A=z.getNext();}else if(!B){z=z.getFirst().insertBeforeMe(v.document.createText(''));D=true;}else if(B>=z.getChildCount()){z=z.append(v.document.createText(''));D=true;}else z=z.getChild(B).getPrevious();var F=z.getParents(),G=A.getParents(),H,I,J;for(H=0;H0&&!L.equals(A))M=K.append(L.clone());if(!F[Q]||L.$.parentNode!=F[Q].$.parentNode){N=L.getPrevious();while(N){if(N.equals(F[Q])||N.equals(z))break;O=N.getPrevious();if(w==2)K.$.insertBefore(N.$.cloneNode(true),K.$.firstChild);else{N.remove();if(w==1)K.$.insertBefore(N.$,K.$.firstChild);}N=O;}}if(K)K=M;}if(w==2){var R=v.startContainer;if(R.type==3){R.$.data+=R.$.nextSibling.data;R.$.parentNode.removeChild(R.$.nextSibling);}var S=v.endContainer;if(S.type==3&&S.$.nextSibling){S.$.data+=S.$.nextSibling.data;S.$.parentNode.removeChild(S.$.nextSibling);}}else{if(I&&J&&(z.$.parentNode!=I.$.parentNode||A.$.parentNode!=J.$.parentNode)){var T=J.getIndex();if(D&&J.$.parentNode==z.$.parentNode)T--;if(y&&I.type==1){var U=h.createFromHtml(' ',v.document);U.insertAfter(I);I.mergeSiblings(false);v.moveToBookmark({startNode:U});}else v.setStart(J.getParent(),T);}v.collapse(true);}if(D)z.remove();if(E&&A.$.parentNode)A.remove();},n={abbr:1,acronym:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1};function o(){var v=false,w=d.walker.whitespaces(),x=d.walker.bookmark(true),y=d.walker.bogus();return function(z){if(x(z)||w(z))return true;if(y(z)&&!v){v=true;return true;}if(z.type==3&&(z.hasAscendant('pre')||e.trim(z.getText()).length))return false;if(z.type==1&&!n[z.getName()])return false;return true;};};var p=d.walker.bogus();function q(v){var w=d.walker.whitespaces(),x=d.walker.bookmark(1);return function(y){if(x(y)||w(y))return true;return!v&&p(y)||y.type==1&&y.getName() in f.$removeEmpty;};};var r=new d.walker.whitespaces(),s=new d.walker.bookmark(),t=/^[\t\r\n ]*(?: |\xa0)$/;function u(v){return!r(v)&&!s(v);};d.range.prototype={clone:function(){var w=this;var v=new d.range(w.document);v.startContainer=w.startContainer;v.startOffset=w.startOffset;v.endContainer=w.endContainer;v.endOffset=w.endOffset;v.collapsed=w.collapsed;return v;},collapse:function(v){var w=this;if(v){w.endContainer=w.startContainer;w.endOffset=w.startOffset;}else{w.startContainer=w.endContainer;w.startOffset=w.endOffset;}w.collapsed=true;},cloneContents:function(){var v=new d.documentFragment(this.document);if(!this.collapsed)m(this,2,v);return v;},deleteContents:function(v){if(this.collapsed)return; +m(this,0,null,v);},extractContents:function(v){var w=new d.documentFragment(this.document);if(!this.collapsed)m(this,1,w,v);return w;},createBookmark:function(v){var B=this;var w,x,y,z,A=B.collapsed;w=B.document.createElement('span');w.data('cke-bookmark',1);w.setStyle('display','none');w.setHtml(' ');if(v){y='cke_bm_'+e.getNextNumber();w.setAttribute('id',y+(A?'C':'S'));}if(!A){x=w.clone();x.setHtml(' ');if(v)x.setAttribute('id',y+'E');z=B.clone();z.collapse();z.insertNode(x);}z=B.clone();z.collapse(true);z.insertNode(w);if(x){B.setStartAfter(w);B.setEndBefore(x);}else B.moveToPosition(w,4);return{startNode:v?y+(A?'C':'S'):w,endNode:v?y+'E':x,serializable:v,collapsed:A};},createBookmark2:function(v){var D=this;var w=D.startContainer,x=D.endContainer,y=D.startOffset,z=D.endOffset,A=D.collapsed,B,C;if(!w||!x)return{start:0,end:0};if(v){if(w.type==1){B=w.getChild(y);if(B&&B.type==3&&y>0&&B.getPrevious().type==3){w=B;y=0;}if(B&&B.type==1)y=B.getIndex(1);}while(w.type==3&&(C=w.getPrevious())&&C.type==3){w=C;y+=C.getLength();}if(!A){if(x.type==1){B=x.getChild(z);if(B&&B.type==3&&z>0&&B.getPrevious().type==3){x=B;z=0;}if(B&&B.type==1)z=B.getIndex(1);}while(x.type==3&&(C=x.getPrevious())&&C.type==3){x=C;z+=C.getLength();}}}return{start:w.getAddress(v),end:A?null:x.getAddress(v),startOffset:y,endOffset:z,normalized:v,collapsed:A,is2:true};},moveToBookmark:function(v){var D=this;if(v.is2){var w=D.document.getByAddress(v.start,v.normalized),x=v.startOffset,y=v.end&&D.document.getByAddress(v.end,v.normalized),z=v.endOffset;D.setStart(w,x);if(y)D.setEnd(y,z);else D.collapse(true);}else{var A=v.serializable,B=A?D.document.getById(v.startNode):v.startNode,C=A?D.document.getById(v.endNode):v.endNode;D.setStartBefore(B);B.remove();if(C){D.setEndBefore(C);C.remove();}else D.collapse(true);}},getBoundaryNodes:function(){var A=this;var v=A.startContainer,w=A.endContainer,x=A.startOffset,y=A.endOffset,z;if(v.type==1){z=v.getChildCount();if(z>x)v=v.getChild(x);else if(z<1)v=v.getPreviousSourceNode();else{v=v.$;while(v.lastChild)v=v.lastChild;v=new d.node(v);v=v.getNextSourceNode()||v;}}if(w.type==1){z=w.getChildCount();if(z>y)w=w.getChild(y).getPreviousSourceNode(true);else if(z<1)w=w.getPreviousSourceNode();else{w=w.$;while(w.lastChild)w=w.lastChild;w=new d.node(w);}}if(v.getPosition(w)&2)v=w;return{startNode:v,endNode:w};},getCommonAncestor:function(v,w){var A=this;var x=A.startContainer,y=A.endContainer,z;if(x.equals(y)){if(v&&x.type==1&&A.startOffset==A.endOffset-1)z=x.getChild(A.startOffset); +else z=x;}else z=x.getCommonAncestor(y);return w&&!z.is?z.getParent():z;},optimize:function(){var x=this;var v=x.startContainer,w=x.startOffset;if(v.type!=1)if(!w)x.setStartBefore(v);else if(w>=v.getLength())x.setStartAfter(v);v=x.endContainer;w=x.endOffset;if(v.type!=1)if(!w)x.setEndBefore(v);else if(w>=v.getLength())x.setEndAfter(v);},optimizeBookmark:function(){var x=this;var v=x.startContainer,w=x.endContainer;if(v.is&&v.is('span')&&v.data('cke-bookmark'))x.setStartAt(v,3);if(w&&w.is&&w.is('span')&&w.data('cke-bookmark'))x.setEndAt(w,4);},trim:function(v,w){var D=this;var x=D.startContainer,y=D.startOffset,z=D.collapsed;if((!v||z)&&x&&x.type==3){if(!y){y=x.getIndex();x=x.getParent();}else if(y>=x.getLength()){y=x.getIndex()+1;x=x.getParent();}else{var A=x.split(y);y=x.getIndex()+1;x=x.getParent();if(D.startContainer.equals(D.endContainer))D.setEnd(A,D.endOffset-D.startOffset);else if(x.equals(D.endContainer))D.endOffset+=1;}D.setStart(x,y);if(z){D.collapse(true);return;}}var B=D.endContainer,C=D.endOffset;if(!(w||z)&&B&&B.type==3){if(!C){C=B.getIndex();B=B.getParent();}else if(C>=B.getLength()){C=B.getIndex()+1;B=B.getParent();}else{B.split(C);C=B.getIndex()+1;B=B.getParent();}D.setEnd(B,C);}},enlarge:function(v,w){switch(v){case 1:if(this.collapsed)return;var x=this.getCommonAncestor(),y=this.document.getBody(),z,A,B,C,D,E=false,F,G,H=this.startContainer,I=this.startOffset;if(H.type==3){if(I){H=!e.trim(H.substring(0,I)).length&&H;E=!!H;}if(H)if(!(C=H.getPrevious()))B=H.getParent();}else{if(I)C=H.getChild(I-1)||H.getLast();if(!C)B=H;}while(B||C){if(B&&!C){if(!D&&B.equals(x))D=true;if(!y.contains(B))break;if(!E||B.getComputedStyle('display')!='inline'){E=false;if(D)z=B;else this.setStartBefore(B);}C=B.getPrevious();}while(C){F=false;if(C.type==8){C=C.getPrevious();continue;}else if(C.type==3){G=C.getText();if(/[^\s\ufeff]/.test(G))C=null;F=/[\s\ufeff]$/.test(G);}else if((C.$.offsetWidth>0||w&&C.is('br'))&&!C.data('cke-bookmark'))if(E&&f.$removeEmpty[C.getName()]){G=C.getText();if(/[^\s\ufeff]/.test(G))C=null;else{var J=C.$.getElementsByTagName('*');for(var K=0,L;L=J[K++];){if(!f.$removeEmpty[L.nodeName.toLowerCase()]){C=null;break;}}}if(C)F=!!G.length;}else C=null;if(F)if(E){if(D)z=B;else if(B)this.setStartBefore(B);}else E=true;if(C){var M=C.getPrevious();if(!B&&!M){B=C;C=null;break;}C=M;}else B=null;}if(B)B=B.getParent();}H=this.endContainer;I=this.endOffset;B=C=null;D=E=false;if(H.type==3){H=!e.trim(H.substring(I)).length&&H;E=!(H&&H.getLength());if(H)if(!(C=H.getNext()))B=H.getParent(); +}else{C=H.getChild(I);if(!C)B=H;}while(B||C){if(B&&!C){if(!D&&B.equals(x))D=true;if(!y.contains(B))break;if(!E||B.getComputedStyle('display')!='inline'){E=false;if(D)A=B;else if(B)this.setEndAfter(B);}C=B.getNext();}while(C){F=false;if(C.type==3){G=C.getText();if(/[^\s\ufeff]/.test(G))C=null;F=/^[\s\ufeff]/.test(G);}else if(C.type==1){if((C.$.offsetWidth>0||w&&C.is('br'))&&!C.data('cke-bookmark'))if(E&&f.$removeEmpty[C.getName()]){G=C.getText();if(/[^\s\ufeff]/.test(G))C=null;else{J=C.$.getElementsByTagName('*');for(K=0;L=J[K++];){if(!f.$removeEmpty[L.nodeName.toLowerCase()]){C=null;break;}}}if(C)F=!!G.length;}else C=null;}else F=1;if(F)if(E)if(D)A=B;else this.setEndAfter(B);if(C){M=C.getNext();if(!B&&!M){B=C;C=null;break;}C=M;}else B=null;}if(B)B=B.getParent();}if(z&&A){x=z.contains(A)?A:z;this.setStartBefore(x);this.setEndAfter(x);}break;case 2:case 3:var N=new d.range(this.document);y=this.document.getBody();N.setStartAt(y,1);N.setEnd(this.startContainer,this.startOffset);var O=new d.walker(N),P,Q,R=d.walker.blockBoundary(v==3?{br:1}:null),S=function(Y){var Z=R(Y);if(!Z)P=Y;return Z;},T=function(Y){var Z=S(Y);if(!Z&&Y.is&&Y.is('br'))Q=Y;return Z;};O.guard=S;B=O.lastBackward();P=P||y;this.setStartAt(P,!P.is('br')&&(!B&&this.checkStartOfBlock()||B&&P.contains(B))?1:4);if(v==3){var U=this.clone();O=new d.walker(U);var V=d.walker.whitespaces(),W=d.walker.bookmark();O.evaluator=function(Y){return!V(Y)&&!W(Y);};var X=O.previous();if(X&&X.type==1&&X.is('br'))return;}N=this.clone();N.collapse();N.setEndAt(y,2);O=new d.walker(N);O.guard=v==3?T:S;P=null;B=O.lastForward();P=P||y;this.setEndAt(P,!B&&this.checkEndOfBlock()||B&&P.contains(B)?2:3);if(Q)this.setEndAfter(Q);}},shrink:function(v,w){if(!this.collapsed){v=v||2;var x=this.clone(),y=this.startContainer,z=this.endContainer,A=this.startOffset,B=this.endOffset,C=this.collapsed,D=1,E=1;if(y&&y.type==3)if(!A)x.setStartBefore(y);else if(A>=y.getLength())x.setStartAfter(y);else{x.setStartBefore(y);D=0;}if(z&&z.type==3)if(!B)x.setEndBefore(z);else if(B>=z.getLength())x.setEndAfter(z);else{x.setEndAfter(z);E=0;}var F=new d.walker(x),G=d.walker.bookmark();F.evaluator=function(K){return K.type==(v==1?1:3);};var H;F.guard=function(K,L){if(G(K))return true;if(v==1&&K.type==3)return false;if(L&&K.equals(H))return false;if(!L&&K.type==1)H=K;return true;};if(D){var I=F[v==1?'lastForward':'next']();I&&this.setStartAt(I,w?1:3);}if(E){F.reset();var J=F[v==1?'lastBackward':'previous']();J&&this.setEndAt(J,w?2:4);}return!!(D||E); +}},insertNode:function(v){var z=this;z.optimizeBookmark();z.trim(false,true);var w=z.startContainer,x=z.startOffset,y=w.getChild(x);if(y)v.insertBefore(y);else w.append(v);if(v.getParent().equals(z.endContainer))z.endOffset++;z.setStartBefore(v);},moveToPosition:function(v,w){this.setStartAt(v,w);this.collapse(true);},selectNodeContents:function(v){this.setStart(v,0);this.setEnd(v,v.type==3?v.getLength():v.getChildCount());},setStart:function(v,w){var x=this;if(v.type==1&&f.$empty[v.getName()])w=v.getIndex(),v=v.getParent();x.startContainer=v;x.startOffset=w;if(!x.endContainer){x.endContainer=v;x.endOffset=w;}l(x);},setEnd:function(v,w){var x=this;if(v.type==1&&f.$empty[v.getName()])w=v.getIndex()+1,v=v.getParent();x.endContainer=v;x.endOffset=w;if(!x.startContainer){x.startContainer=v;x.startOffset=w;}l(x);},setStartAfter:function(v){this.setStart(v.getParent(),v.getIndex()+1);},setStartBefore:function(v){this.setStart(v.getParent(),v.getIndex());},setEndAfter:function(v){this.setEnd(v.getParent(),v.getIndex()+1);},setEndBefore:function(v){this.setEnd(v.getParent(),v.getIndex());},setStartAt:function(v,w){var x=this;switch(w){case 1:x.setStart(v,0);break;case 2:if(v.type==3)x.setStart(v,v.getLength());else x.setStart(v,v.getChildCount());break;case 3:x.setStartBefore(v);break;case 4:x.setStartAfter(v);}l(x);},setEndAt:function(v,w){var x=this;switch(w){case 1:x.setEnd(v,0);break;case 2:if(v.type==3)x.setEnd(v,v.getLength());else x.setEnd(v,v.getChildCount());break;case 3:x.setEndBefore(v);break;case 4:x.setEndAfter(v);}l(x);},fixBlock:function(v,w){var z=this;var x=z.createBookmark(),y=z.document.createElement(w);z.collapse(v);z.enlarge(2);z.extractContents().appendTo(y);y.trim();if(!c)y.appendBogus();z.insertNode(y);z.moveToBookmark(x);return y;},splitBlock:function(v){var F=this;var w=new d.elementPath(F.startContainer),x=new d.elementPath(F.endContainer),y=w.blockLimit,z=x.blockLimit,A=w.block,B=x.block,C=null;if(!y.equals(z))return null;if(v!='br'){if(!A){A=F.fixBlock(true,v);B=new d.elementPath(F.endContainer).block;}if(!B)B=F.fixBlock(false,v);}var D=A&&F.checkStartOfBlock(),E=B&&F.checkEndOfBlock();F.deleteContents();if(A&&A.equals(B))if(E){C=new d.elementPath(F.startContainer);F.moveToPosition(B,4);B=null;}else if(D){C=new d.elementPath(F.startContainer);F.moveToPosition(A,3);A=null;}else{B=F.splitElement(A);if(!c&&!A.is('ul','ol'))A.appendBogus();}return{previousBlock:A,nextBlock:B,wasStartOfBlock:D,wasEndOfBlock:E,elementPath:C};},splitElement:function(v){var y=this; +if(!y.collapsed)return null;y.setEndAt(v,2);var w=y.extractContents(),x=v.clone(false);w.appendTo(x);x.insertAfter(v);y.moveToPosition(v,4);return x;},checkBoundaryOfElement:function(v,w){var x=w==1,y=this.clone();y.collapse(x);y[x?'setStartAt':'setEndAt'](v,x?1:2);var z=new d.walker(y);z.evaluator=q(x);return z[x?'checkBackward':'checkForward']();},checkStartOfBlock:function(){var B=this;var v=B.startContainer,w=B.startOffset;if(c&&w&&v.type==3){var x=e.ltrim(v.substring(0,w));if(t.test(x))B.trim(0,1);}var y=new d.elementPath(B.startContainer),z=B.clone();z.collapse(true);z.setStartAt(y.block||y.blockLimit,1);var A=new d.walker(z);A.evaluator=o();return A.checkBackward();},checkEndOfBlock:function(){var B=this;var v=B.endContainer,w=B.endOffset;if(c&&v.type==3){var x=e.rtrim(v.substring(w));if(t.test(x))B.trim(1,0);}var y=new d.elementPath(B.endContainer),z=B.clone();z.collapse(false);z.setEndAt(y.block||y.blockLimit,2);var A=new d.walker(z);A.evaluator=o();return A.checkForward();},getPreviousNode:function(v,w,x){var y=this.clone();y.collapse(1);y.setStartAt(x||this.document.getBody(),1);var z=new d.walker(y);z.evaluator=v;z.guard=w;return z.previous();},getNextNode:function(v,w,x){var y=this.clone();y.collapse();y.setEndAt(x||this.document.getBody(),2);var z=new d.walker(y);z.evaluator=v;z.guard=w;return z.next();},checkReadOnly:(function(){function v(w,x){while(w){if(w.type==1)if(w.getAttribute('contentEditable')=='false'&&!w.data('cke-editable'))return 0;else if(w.is('html')||w.getAttribute('contentEditable')=='true'&&(w.contains(x)||w.equals(x)))break;w=w.getParent();}return 1;};return function(){var w=this.startContainer,x=this.endContainer;return!(v(w,x)&&v(x,w));};})(),moveToElementEditablePosition:function(v,w){function x(z,A){var B;if(z.type==1&&z.isEditable(false))B=z[w?'getLast':'getFirst'](u);if(!A&&!B)B=z[w?'getPrevious':'getNext'](u);return B;};if(v.type==1&&!v.isEditable(false)){this.moveToPosition(v,w?4:3);return true;}var y=0;while(v){if(v.type==3){if(w&&this.checkEndOfBlock()&&t.test(v.getText()))this.moveToPosition(v,3);else this.moveToPosition(v,w?4:3);y=1;break;}if(v.type==1)if(v.isEditable()){this.moveToPosition(v,w?2:1);y=1;}else if(w&&v.is('br')&&this.checkEndOfBlock())this.moveToPosition(v,3);v=x(v,y);}return!!y;},moveToElementEditStart:function(v){return this.moveToElementEditablePosition(v);},moveToElementEditEnd:function(v){return this.moveToElementEditablePosition(v,true);},getEnclosedNode:function(){var v=this.clone();v.optimize(); +if(v.startContainer.type!=1||v.endContainer.type!=1)return null;var w=new d.walker(v),x=d.walker.bookmark(true),y=d.walker.whitespaces(true),z=function(B){return y(B)&&x(B);};v.evaluator=z;var A=w.next();w.reset();return A&&A.equals(w.previous())?A:null;},getTouchedStartNode:function(){var v=this.startContainer;if(this.collapsed||v.type!=1)return v;return v.getChild(this.startOffset)||v;},getTouchedEndNode:function(){var v=this.endContainer;if(this.collapsed||v.type!=1)return v;return v.getChild(this.endOffset-1)||v;}};})();a.POSITION_AFTER_START=1;a.POSITION_BEFORE_END=2;a.POSITION_BEFORE_START=3;a.POSITION_AFTER_END=4;a.ENLARGE_ELEMENT=1;a.ENLARGE_BLOCK_CONTENTS=2;a.ENLARGE_LIST_ITEM_CONTENTS=3;a.START=1;a.END=2;a.STARTEND=3;a.SHRINK_ELEMENT=1;a.SHRINK_TEXT=2;(function(){d.rangeList=function(n){if(n instanceof d.rangeList)return n;if(!n)n=[];else if(n instanceof d.range)n=[n];return e.extend(n,l);};var l={createIterator:function(){var n=this,o=d.walker.bookmark(),p=function(s){return!(s.is&&s.is('tr'));},q=[],r;return{getNextRange:function(s){r=r==undefined?0:r+1;var t=n[r];if(t&&n.length>1){if(!r)for(var u=n.length-1;u>=0;u--)q.unshift(n[u].createBookmark(true));if(s){var v=0;while(n[r+v+1]){var w=t.document,x=0,y=w.getById(q[v].endNode),z=w.getById(q[v+1].startNode),A;while(1){A=y.getNextSourceNode(false);if(!z.equals(A)){if(o(A)||A.type==1&&A.isBlockBoundary()){y=A;continue;}}else x=1;break;}if(!x)break;v++;}}t.moveToBookmark(q.shift());while(v--){A=n[++r];A.moveToBookmark(q.shift());t.setEnd(A.endContainer,A.endOffset);}}return t;}};},createBookmarks:function(n){var s=this;var o=[],p;for(var q=0;q',a.document);l.appendTo(a.document.getHead());try{b.hc=l.getComputedStyle('border-top-color')==l.getComputedStyle('border-right-color');}catch(m){b.hc=false;}if(b.hc)b.cssClass+=' cke_hc';l.remove();})();j.load(i.corePlugins.split(','),function(){a.status='loaded';a.fire('loaded');var l=a._.pending;if(l){delete a._.pending;for(var m=0;m0){z=A.shift();while(!z.getParent().equals(D))z=z.getParent();if(!z.equals(H))E.push(z);H=z;}while(E.length>0){z=E.shift();if(z.getName()=='blockquote'){var I=new d.documentFragment(q.document);while(z.getFirst()){I.append(z.getFirst().remove());A.push(I.getLast());}I.replace(z);}else A.push(z);}var J=q.document.createElement('blockquote');J.insertBefore(A[0]);while(A.length>0){z=A.shift();J.append(z);}}else if(r==1){var K=[],L={};while(z=y.getNextParagraph()){var M=null,N=null;while(z.getParent()){if(z.getParent().getName()=='blockquote'){M=z.getParent();N=z;break;}z=z.getParent();}if(M&&N&&!N.getCustomData('blockquote_moveout')){K.push(N);h.setMarker(L,N,'blockquote_moveout',true);}}h.clearAllMarkers(L);var O=[],P=[];L={};while(K.length>0){var Q=K.shift();J=Q.getParent();if(!Q.getPrevious())Q.remove().insertBefore(J);else if(!Q.getNext())Q.remove().insertAfter(J);else{Q.breakParent(Q.getParent());P.push(Q.getNext());}if(!J.getCustomData('blockquote_processed')){P.push(J);h.setMarker(L,J,'blockquote_processed',true);}O.push(Q);}h.clearAllMarkers(L);for(F=P.length-1;F>=0;F--){J=P[F];if(o(J))J.remove();}if(q.config.enterMode==2){var R=true;while(O.length){Q=O.shift();if(Q.getName()=='div'){I=new d.documentFragment(q.document);var S=R&&Q.getPrevious()&&!(Q.getPrevious().type==1&&Q.getPrevious().isBlockBoundary());if(S)I.append(q.document.createElement('br'));var T=Q.getNext()&&!(Q.getNext().type==1&&Q.getNext().isBlockBoundary());while(Q.getFirst())Q.getFirst().remove().appendTo(I);if(T)I.append(q.document.createElement('br'));I.replace(Q);R=false;}}}}s.selectBookmarks(u);q.focus();}};j.add('blockquote',{init:function(q){q.addCommand('blockquote',p);q.ui.addButton('Blockquote',{label:q.lang.blockquote,command:'blockquote'});q.on('selectionChange',n);},requires:['domiterator']});})();j.add('button',{beforeInit:function(m){m.ui.addHandler('button',k.button.handler);}});a.UI_BUTTON='button';k.button=function(m){e.extend(this,m,{title:m.label,className:m.className||m.command&&'cke_button_'+m.command||'',click:m.click||(function(n){n.execCommand(m.command); +})});this._={};};k.button.handler={create:function(m){return new k.button(m);}};(function(){k.button.prototype={render:function(m,n){var o=b,p=this._.id=e.getNextId(),q='',r=this.command,s;this._.editor=m;var t={id:p,button:this,editor:m,focus:function(){var z=a.document.getById(p);z.focus();},execute:function(){if(c&&b.version<7)e.setTimeout(function(){this.button.click(m);},0,this);else this.button.click(m);}},u=e.addFunction(function(z){if(t.onkey){z=new d.event(z);return t.onkey(t,z.getKeystroke())!==false;}}),v=e.addFunction(function(z){var A;if(t.onfocus)A=t.onfocus(t,new d.event(z))!==false;if(b.gecko&&b.version<10900)z.preventBubble();return A;});t.clickFn=s=e.addFunction(t.execute,t);if(this.modes){var w={};function x(){var z=m.mode;if(z){var A=this.modes[z]?w[z]!=undefined?w[z]:2:0;this.setState(m.readOnly&&!this.readOnly?0:A);}};m.on('beforeModeUnload',function(){if(m.mode&&this._.state!=0)w[m.mode]=this._.state;},this);m.on('mode',x,this);!this.readOnly&&m.on('readOnly',x,this);}else if(r){r=m.getCommand(r);if(r){r.on('state',function(){this.setState(r.state);},this);q+='cke_'+(r.state==1?'on':r.state==0?'disabled':'off');}}if(!r)q+='cke_off';if(this.className)q+=' '+this.className;n.push('','=10900&&!o.hc?'':'" href="javascript:void(\''+(this.title||'').replace("'",'')+"')\"",' title="',this.title,'" tabindex="-1" hidefocus="true" role="button" aria-labelledby="'+p+'_label"'+(this.hasArrow?' aria-haspopup="true"':''));if(o.opera||o.gecko&&o.mac)n.push(' onkeypress="return false;"');if(o.gecko)n.push(' onblur="this.style.cssText = this.style.cssText;"');n.push(' onkeydown="return CKEDITOR.tools.callFunction(',u,', event);" onfocus="return CKEDITOR.tools.callFunction(',v,', event);" '+(c?'onclick="return false;" onmouseup':'onclick')+'="CKEDITOR.tools.callFunction(',s,', this); return false;"> ',this.label,'');if(this.hasArrow)n.push(''+(b.hc?'▼':' ')+'');n.push('','');if(this.onRender)this.onRender();return t;},setState:function(m){if(this._.state==m)return false;this._.state=m;var n=a.document.getById(this._.id);if(n){n.setState(m); +m==0?n.setAttribute('aria-disabled',true):n.removeAttribute('aria-disabled');m==1?n.setAttribute('aria-pressed',true):n.removeAttribute('aria-pressed');return true;}else return false;}};})();k.prototype.addButton=function(m,n){this.add(m,'button',n);};(function(){var m=function(y,z){var A=y.document,B=A.getBody(),C=false,D=function(){C=true;};B.on(z,D);(b.version>7?A.$:A.$.selection.createRange()).execCommand(z);B.removeListener(z,D);return C;},n=c?function(y,z){return m(y,z);}:function(y,z){try{return y.document.$.execCommand(z,false,null);}catch(A){return false;}},o=function(y){var z=this;z.type=y;z.canUndo=z.type=='cut';z.startDisabled=true;};o.prototype={exec:function(y,z){this.type=='cut'&&t(y);var A=n(y,this.type);if(!A)alert(y.lang.clipboard[this.type+'Error']);return A;}};var p={canUndo:false,exec:c?function(y){y.focus();if(!y.document.getBody().fire('beforepaste')&&!m(y,'paste')){y.fire('pasteDialog');return false;}}:function(y){try{if(!y.document.getBody().fire('beforepaste')&&!y.document.$.execCommand('Paste',false,null))throw 0;}catch(z){setTimeout(function(){y.fire('pasteDialog');},0);return false;}}},q=function(y){if(this.mode!='wysiwyg')return;switch(y.data.keyCode){case 1114112+86:case 2228224+45:var z=this.document.getBody();if(b.opera||b.gecko)z.fire('paste');return;case 1114112+88:case 2228224+46:var A=this;this.fire('saveSnapshot');setTimeout(function(){A.fire('saveSnapshot');},0);}};function r(y){y.cancel();};function s(y,z,A){var B=this.document;if(B.getById('cke_pastebin'))return;if(z=='text'&&y.data&&y.data.$.clipboardData){var C=y.data.$.clipboardData.getData('text/plain');if(C){y.data.preventDefault();A(C);return;}}var D=this.getSelection(),E=new d.range(B),F=new h(z=='text'?'textarea':b.webkit?'body':'div',B);F.setAttribute('id','cke_pastebin');b.webkit&&F.append(B.createText('\xa0'));B.getBody().append(F);F.setStyles({position:'absolute',top:D.getStartElement().getDocumentPosition().y+'px',width:'1px',height:'1px',overflow:'hidden'});F.setStyle(this.config.contentsLangDirection=='ltr'?'left':'right','-1000px');var G=D.createBookmarks();this.on('selectionChange',r,null,null,0);if(z=='text')F.$.focus();else{E.setStartAt(F,1);E.setEndAt(F,2);E.select(true);}var H=this;window.setTimeout(function(){H.document.getBody().focus();H.removeListener('selectionChange',r);if(b.ie7Compat){D.selectBookmarks(G);F.remove();}else{F.remove();D.selectBookmarks(G);}var I;F=b.webkit&&(I=F.getFirst())&&I.is&&I.hasClass('Apple-style-span')?I:F;A(F['get'+(z=='text'?'Value':'Html')]()); +},0);};function t(y){if(!c||b.quirks)return;var z=y.getSelection(),A;if(z.getType()==3&&(A=z.getSelectedElement())){var B=z.getRanges()[0],C=y.document.createText('');C.insertBefore(A);B.setStartBefore(C);B.setEndAfter(A);z.selectRanges([B]);setTimeout(function(){if(A.getParent()){C.remove();z.selectElement(A);}},0);}};var u,v;function w(y,z){var A;if(v&&y in {Paste:1,Cut:1})return 0;if(y=='Paste'){c&&(u=1);try{A=z.document.$.queryCommandEnabled(y)||b.webkit;}catch(D){}u=0;}else{var B=z.getSelection(),C=B&&B.getRanges();A=B&&!(C.length==1&&C[0].collapsed);}return A?2:0;};function x(){var z=this;if(z.mode!='wysiwyg')return;var y=w('Paste',z);z.getCommand('cut').setState(w('Cut',z));z.getCommand('copy').setState(w('Copy',z));z.getCommand('paste').setState(y);z.fire('pasteState',y);};j.add('clipboard',{requires:['dialog','htmldataprocessor'],init:function(y){y.on('paste',function(A){var B=A.data;if(B.html)y.insertHtml(B.html);else if(B.text)y.insertText(B.text);setTimeout(function(){y.fire('afterPaste');},0);},null,null,1000);y.on('pasteDialog',function(A){setTimeout(function(){y.openDialog('paste');},0);});y.on('pasteState',function(A){y.getCommand('paste').setState(A.data);});function z(A,B,C,D){var E=y.lang[B];y.addCommand(B,C);y.ui.addButton(A,{label:E,command:B});if(y.addMenuItems)y.addMenuItem(B,{label:E,command:B,group:'clipboard',order:D});};z('Cut','cut',new o('cut'),1);z('Copy','copy',new o('copy'),4);z('Paste','paste',p,8);a.dialog.add('paste',a.getUrl(this.path+'dialogs/paste.js'));y.on('key',q,y);y.on('contentDom',function(){var A=y.document.getBody();A.on(!c?'paste':'beforepaste',function(B){if(u)return;var C=B.data&&B.data.$;if(c&&C&&!C.ctrlKey)return;var D={mode:'html'};y.fire('beforePaste',D);s.call(y,B,D.mode,function(E){if(!(E=e.trim(E.replace(/]+data-cke-bookmark[^<]*?<\/span>/ig,''))))return;var F={};F[D.mode]=E;y.fire('paste',F);});});if(c){A.on('contextmenu',function(){u=1;setTimeout(function(){u=0;},0);});A.on('paste',function(B){if(!y.document.getById('cke_pastebin')){B.data.preventDefault();u=0;p.exec(y);}});}A.on('beforecut',function(){!u&&t(y);});A.on('mouseup',function(){setTimeout(function(){x.call(y);},0);},y);A.on('keyup',x,y);});y.on('selectionChange',function(A){v=A.data.selection.getRanges()[0].checkReadOnly();x.call(y);});if(y.contextMenu)y.contextMenu.addListener(function(A,B){var C=B.getRanges()[0].checkReadOnly();return{cut:w('Cut',y),copy:w('Copy',y),paste:w('Paste',y)};});}});})();j.add('colorbutton',{requires:['panelbutton','floatpanel','styles'],init:function(m){var n=m.config,o=m.lang.colorButton,p; +if(!b.hc){q('TextColor','fore',o.textColorTitle);q('BGColor','back',o.bgColorTitle);}function q(t,u,v){var w=e.getNextId()+'_colorBox';m.ui.add(t,'panelbutton',{label:v,title:v,className:'cke_button_'+t.toLowerCase(),modes:{wysiwyg:1},panel:{css:m.skin.editor.css,attributes:{role:'listbox','aria-label':o.panelTitle}},onBlock:function(x,y){y.autoSize=true;y.element.addClass('cke_colorblock');y.element.setHtml(r(x,u,w));y.element.getDocument().getBody().setStyle('overflow','hidden');k.fire('ready',this);var z=y.keys,A=m.lang.dir=='rtl';z[A?37:39]='next';z[40]='next';z[9]='next';z[A?39:37]='prev';z[38]='prev';z[2228224+9]='prev';z[32]='click';},onOpen:function(){var x=m.getSelection(),y=x&&x.getStartElement(),z=new d.elementPath(y),A;y=z.block||z.blockLimit||m.document.getBody();do A=y&&y.getComputedStyle(u=='back'?'background-color':'color')||'transparent';while(u=='back'&&A=='transparent'&&y&&(y=y.getParent()));if(!A||A=='transparent')A='#ffffff';this._.panel._.iframe.getFrameDocument().getById(w).setStyle('background-color',A);}});};function r(t,u,v){var w=[],x=n.colorButton_colors.split(','),y=e.addFunction(function(E,F){if(E=='?'){var G=arguments.callee;function H(J){this.removeListener('ok',H);this.removeListener('cancel',H);J.name=='ok'&&G(this.getContentElement('picker','selectedColor').getValue(),F);};m.openDialog('colordialog',function(){this.on('ok',H);this.on('cancel',H);});return;}m.focus();t.hide(false);m.fire('saveSnapshot');new a.style(n['colorButton_'+F+'Style'],{color:'inherit'}).remove(m.document);if(E){var I=n['colorButton_'+F+'Style'];I.childRule=F=='back'?function(J){return s(J);}:function(J){return!(J.is('a')||J.getElementsByTag('a').count())||s(J);};new a.style(I,{color:E}).apply(m.document);}m.fire('saveSnapshot');});w.push('
    ',o.auto,'
    ');for(var z=0;z');var A=x[z].split('/'),B=A[0],C=A[1]||B;if(!A[1])B='#'+B.replace(/^(.)(.)(.)$/,'$1$1$2$2$3$3');var D=m.lang.colors[C]||C;w.push(''); +}if(n.colorButton_enableMore===undefined||n.colorButton_enableMore)w.push('');w.push('
    ',o.more,'
    ');return w.join('');};function s(t){return t.getAttribute('contentEditable')=='false'||t.getAttribute('data-nostyle');};}});i.colorButton_colors='000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';i.colorButton_foreStyle={element:'span',styles:{color:'#(color)'},overrides:[{element:'font',attributes:{color:null}}]};i.colorButton_backStyle={element:'span',styles:{'background-color':'#(color)'}};j.colordialog={requires:['dialog'],init:function(m){m.addCommand('colordialog',new a.dialogCommand('colordialog'));a.dialog.add('colordialog',this.path+'dialogs/colordialog.js');}};j.add('colordialog',j.colordialog);j.add('contextmenu',{requires:['menu'],onLoad:function(){j.contextMenu=e.createClass({base:a.menu,$:function(m){this.base.call(this,m,{panel:{className:m.skinClass+' cke_contextmenu',attributes:{'aria-label':m.lang.contextmenu.options}}});},proto:{addTarget:function(m,n){if(b.opera&&!('oncontextmenu' in document.body)){var o;m.on('mousedown',function(s){s=s.data;if(s.$.button!=2){if(s.getKeystroke()==1114112+1)m.fire('contextmenu',s);return;}if(n&&(b.mac?s.$.metaKey:s.$.ctrlKey))return;var t=s.getTarget();if(!o){var u=t.getDocument();o=u.createElement('input');o.$.type='button';u.getBody().append(o);}o.setAttribute('style','position:absolute;top:'+(s.$.clientY-2)+'px;left:'+(s.$.clientX-2)+'px;width:5px;height:5px;opacity:0.01');});m.on('mouseup',function(s){if(o){o.remove();o=undefined;m.fire('contextmenu',s.data);}});}m.on('contextmenu',function(s){var t=s.data;if(n&&(b.webkit?p:b.mac?t.$.metaKey:t.$.ctrlKey))return;t.preventDefault();var u=t.getTarget().getDocument().getDocumentElement(),v=t.$.clientX,w=t.$.clientY;e.setTimeout(function(){this.open(u,null,v,w);},c?200:0,this);},this);if(b.opera)m.on('keypress',function(s){var t=s.data;if(t.$.keyCode===0)t.preventDefault();});if(b.webkit){var p,q=function(s){p=b.mac?s.data.$.metaKey:s.data.$.ctrlKey;},r=function(){p=0;};m.on('keydown',q);m.on('keyup',r); +m.on('contextmenu',r);}},open:function(m,n,o,p){this.editor.focus();m=m||a.document.getDocumentElement();this.show(m,n,o,p);}}});},beforeInit:function(m){m.contextMenu=new j.contextMenu(m);m.addCommand('contextMenu',{exec:function(){m.contextMenu.open(m.document.getBody());}});}});(function(){function m(o){var p=this.att,q=o&&o.hasAttribute(p)&&o.getAttribute(p)||'';if(q!==undefined)this.setValue(q);};function n(){var o;for(var p=0;p 
    ';j.add('elementspath',{requires:['selection'],init:function(o){var p='cke_path_'+o.name,q,r=function(){if(!q)q=a.document.getById(p);return q;},s='cke_elementspath_'+e.getNextNumber()+'_';o._.elementsPath={idBase:s,filters:[]};o.on('themeSpace',function(x){if(x.data.space=='bottom')x.data.html+=''+o.lang.elementsPath.eleLabel+''+'
    '+n+'
    ';});function t(x){o.focus();var y=o._.elementsPath.list[x];if(y.is('body')){var z=new d.range(o.document);z.selectNodeContents(y);z.select();}else o.getSelection().selectElement(y);};var u=e.addFunction(t),v=e.addFunction(function(x,y){var z=o._.elementsPath.idBase,A;y=new d.event(y);var B=o.lang.dir=='rtl';switch(y.getKeystroke()){case B?39:37:case 9:A=a.document.getById(z+(x+1));if(!A)A=a.document.getById(z+'0');A.focus();return false;case B?37:39:case 2228224+9:A=a.document.getById(z+(x-1));if(!A)A=a.document.getById(z+(o._.elementsPath.list.length-1));A.focus();return false;case 27:o.focus();return false;case 13:case 32:t(x);return false;}return true;});o.on('selectionChange',function(x){var y=b,z=x.data.selection,A=z.getStartElement(),B=[],C=x.editor,D=C._.elementsPath.list=[],E=C._.elementsPath.filters;while(A){var F=0,G;if(A.data('cke-display-name'))G=A.data('cke-display-name');else if(A.data('cke-real-element-type'))G=A.data('cke-real-element-type');else G=A.getName();for(var H=0;H',G,''+L+'','');}if(G=='body')break;A=A.getParent();}var M=r();M.setHtml(B.join('')+n);C.fire('elementsPathUpdate',{space:M});});function w(){q&&q.setHtml(n);delete o._.elementsPath.list;};o.on('readOnly',w);o.on('contentDomUnload',w);o.addCommand('elementsPathFocus',m.toolbarFocus);}});})();(function(){j.add('enterkey',{requires:['keystrokes','indent'],init:function(t){t.addCommand('enter',{modes:{wysiwyg:1},editorFocus:false,exec:function(v){r(v);}});t.addCommand('shiftEnter',{modes:{wysiwyg:1},editorFocus:false,exec:function(v){q(v);}});var u=t.keystrokeHandler.keystrokes;u[13]='enter';u[2228224+13]='shiftEnter';}});j.enterkey={enterBlock:function(t,u,v,w){v=v||s(t);if(!v)return;var x=v.document,y=v.checkStartOfBlock(),z=v.checkEndOfBlock(),A=new d.elementPath(v.startContainer),B=A.block;if(y&&z){if(B&&(B.is('li')||B.getParent().is('li'))){t.execCommand('outdent');return;}if(B&&B.getParent().is('blockquote')){B.breakParent(B.getParent());if(!B.getPrevious().getFirst(d.walker.invisible(1)))B.getPrevious().remove();if(!B.getNext().getFirst(d.walker.invisible(1)))B.getNext().remove();v.moveToElementEditStart(B);v.select();return;}}else if(B&&B.is('pre')){if(!z){n(t,u,v,w);return;}}else if(B&&f.$captionBlock[B.getName()]){n(t,u,v,w);return;}var C=u==3?'div':'p',D=v.splitBlock(C);if(!D)return;var E=D.previousBlock,F=D.nextBlock,G=D.wasStartOfBlock,H=D.wasEndOfBlock,I;if(F){I=F.getParent();if(I.is('li')){F.breakParent(I);F.move(F.getNext(),1);}}else if(E&&(I=E.getParent())&&I.is('li')){E.breakParent(I);I=E.getNext();v.moveToElementEditStart(I);E.move(E.getPrevious());}if(!G&&!H){if(F.is('li')&&(I=F.getFirst(d.walker.invisible(true)))&&I.is&&I.is('ul','ol'))(c?x.createText('\xa0'):x.createElement('br')).insertBefore(I);if(F)v.moveToElementEditStart(F);}else{var J,K;if(E){if(E.is('li')||!(p.test(E.getName())||E.is('pre')))J=E.clone();}else if(F)J=F.clone();if(!J){if(I&&I.is('li'))J=I;else{J=x.createElement(C);if(E&&(K=E.getDirection()))J.setAttribute('dir',K); +}}else if(w&&!J.is('li'))J.renameNode(C);var L=D.elementPath;if(L)for(var M=0,N=L.elements.length;M0;v--)u[v].deleteContents();return u[0];};})();(function(){var m='nbsp,gt,lt,amp',n='quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,euro',o='Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,OElig,oelig,Scaron,scaron,Yuml',p='Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,upsih,piv'; +function q(r,s){var t={},u=[],v={nbsp:'\xa0',shy:'­',gt:'>',lt:'<',amp:'&',apos:"'",quot:'"'};r=r.replace(/\b(nbsp|shy|gt|lt|amp|apos|quot)(?:,|$)/g,function(A,B){var C=s?'&'+B+';':v[B],D=s?v[B]:'&'+B+';';t[C]=D;u.push(C);return '';});if(!s&&r){r=r.split(',');var w=document.createElement('div'),x;w.innerHTML='&'+r.join(';&')+';';x=w.innerHTML;w=null;for(var y=0;y0;case 'checked':return!!q.$.checked;case 'value':var p=q.getAttribute('type');return p=='checkbox'||p=='radio'?q.$.value!='on':q.$.value;}return m.apply(q,arguments);};});(function(){var m={canUndo:false,exec:function(o){var p=o.document.createElement('hr');o.insertElement(p);}},n='horizontalrule';j.add(n,{init:function(o){o.addCommand(n,m);o.ui.addButton('HorizontalRule',{label:o.lang.horizontalrule,command:n});}});})();(function(){var m=/^[\t\r\n ]*(?: |\xa0)$/,n='{cke_protected}';function o(U){var V=U.children.length,W=U.children[V-1];while(W&&W.type==3&&!e.trim(W.value))W=U.children[--V];return W;};function p(U){var V=U.parent;return V?e.indexOf(V.children,U):-1;};function q(U,V){var W=U.children,X=o(U);if(X){if((V||!c)&&X.type==1&&X.name=='br')W.pop();if(X.type==3&&m.test(X.value))W.pop();}};function r(U,V,W){if(!V&&(!W||typeof W=='function'&&W(U)===false))return false;if(V&&c&&(document.documentMode>7||U.name in f.tr||U.name in f.$listItem))return false;var X=o(U);return!X||X&&(X.type==1&&X.name=='br'||U.name=='form'&&X.name=='input');};function s(U,V){return function(W){q(W,!U);if(r(W,!U,V))if(U||c)W.add(new a.htmlParser.text('\xa0'));else W.add(new a.htmlParser.element('br',{}));};};var t=f,u=['caption','colgroup','col','thead','tfoot','tbody'],v=e.extend({},t.$block,t.$listItem,t.$tableContent);for(var w in v){if(!('br' in t[w]))delete v[w];}delete v.pre;var x={elements:{},attributeNames:[[/^on/,'data-cke-pa-on']]},y={elements:{}};for(w in v)y.elements[w]=s();var z={elementNames:[[/^cke:/,''],[/^\?xml:namespace$/,'']],attributeNames:[[/^data-cke-(saved|pa)-/,''],[/^data-cke-.*/,''],['hidefocus','']],elements:{$:function(U){var V=U.attributes; +if(V){if(V['data-cke-temp'])return false;var W=['name','href','src'],X;for(var Y=0;Y-1&&Z>-1&&Y!=Z)){Y=p(W);Z=p(X);}return Y>Z?1:-1;});},embed:function(U){var V=U.parent;if(V&&V.name=='object'){var W=V.attributes.width,X=V.attributes.height;W&&(U.attributes.width=W);X&&(U.attributes.height=X);}},param:function(U){U.children=[];U.isEmpty=true;return U;},a:function(U){if(!(U.children.length||U.attributes.name||U.attributes['data-cke-saved-name']))return false;},span:function(U){if(U.attributes['class']=='Apple-style-span')delete U.name;},pre:function(U){c&&q(U);},html:function(U){delete U.attributes.contenteditable;delete U.attributes['class'];},body:function(U){delete U.attributes.spellcheck;delete U.attributes.contenteditable;},style:function(U){var V=U.children[0];V&&V.value&&(V.value=e.trim(V.value));if(!U.attributes.type)U.attributes.type='text/css';},title:function(U){var V=U.children[0];V&&(V.value=U.attributes['data-cke-title']||'');}},attributes:{'class':function(U,V){return e.ltrim(U.replace(/(?:^|\s+)cke_[^\s]*/g,''))||false;}}};if(c)z.attributes.style=function(U,V){return U.replace(/(^|;)([^\:]+)/g,function(W){return W.toLowerCase();});};function A(U){var V=U.attributes;if(V.contenteditable!='false')V['data-cke-editable']=V.contenteditable?'true':1;V.contenteditable='false';};function B(U){var V=U.attributes;switch(V['data-cke-editable']){case 'true':V.contenteditable='true';break;case '1':delete V.contenteditable;break;}};for(w in {input:1,textarea:1}){x.elements[w]=A;z.elements[w]=B;}var C=/<(a|area|img|input|source)\b([^>]*)>/gi,D=/\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,E=/(?:])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,F=/([^<]*)<\/cke:encoded>/gi,G=/(<\/?)((?:object|embed|param|html|body|head|title)[^>]*>)/gi,H=/(<\/?)cke:((?:html|body|head|title)[^>]*>)/gi,I=/]*?)\/?>(?!\s*<\/cke:\1)/gi;function J(U){return U.replace(C,function(V,W,X){return '<'+W+X.replace(D,function(Y,Z){if(!/^on/.test(Z)&&X.indexOf('data-cke-saved-'+Z)==-1)return ' data-cke-saved-'+Y+' data-cke-'+a.rnd+'-'+Y;return Y;})+'>';});};function K(U){return U.replace(E,function(V){return ''+encodeURIComponent(V)+'';});};function L(U){return U.replace(F,function(V,W){return decodeURIComponent(W); +});};function M(U){return U.replace(G,'$1cke:$2');};function N(U){return U.replace(H,'$1$2');};function O(U){return U.replace(I,'');};function P(U){return U.replace(/(]*>)(\r\n|\n)/g,'$1$2$2');};function Q(U){return U.replace(//g,function(V){return '';});};function R(U){return U.replace(//g,function(V,W){return decodeURIComponent(W);});};function S(U,V){var W=V._.dataStore;return U.replace(//g,function(X,Y){return decodeURIComponent(Y);}).replace(/\{cke_protected_(\d+)\}/g,function(X,Y){return W&&W[Y]||'';});};function T(U,V){var W=[],X=V.config.protectedSource,Y=V._.dataStore||(V._.dataStore={id:1}),Z=/<\!--\{cke_temp(comment)?\}(\d*?)-->/g,aa=[//gi,//gi].concat(X);U=U.replace(//g,function(ac){return '';});for(var ab=0;ab';});U=U.replace(Z,function(ac,ad,ae){return '';});return U.replace(/(['"]).*?\1/g,function(ac){return ac.replace(//g,function(ad,ae){Y[Y.id]=decodeURIComponent(ae);return '{cke_protected_'+Y.id++ +'}';});});};j.add('htmldataprocessor',{requires:['htmlwriter'],init:function(U){var V=U.dataProcessor=new a.htmlDataProcessor(U);V.writer.forceSimpleAmpersand=U.config.forceSimpleAmpersand;V.dataFilter.addRules(x);V.dataFilter.addRules(y);V.htmlFilter.addRules(z);var W={elements:{}};for(w in v)W.elements[w]=s(true,U.config.fillEmptyBlocks);V.htmlFilter.addRules(W);},onLoad:function(){!('fillEmptyBlocks' in i)&&(i.fillEmptyBlocks=1);}});a.htmlDataProcessor=function(U){var V=this;V.editor=U;V.writer=new a.htmlWriter();V.dataFilter=new a.htmlParser.filter();V.htmlFilter=new a.htmlParser.filter();};a.htmlDataProcessor.prototype={toHtml:function(U,V){U=T(U,this.editor);U=J(U);U=K(U);U=M(U);U=O(U);U=P(U);var W=new h('div');W.setHtml('a'+U);U=W.getHtml().substr(1);U=U.replace(new RegExp(' data-cke-'+a.rnd+'-','ig'),' ');U=N(U);U=L(U);U=R(U);var X=a.htmlParser.fragment.fromHtml(U,V),Y=new a.htmlParser.basicWriter();X.writeHtml(Y,this.dataFilter);U=Y.getHtml(true);U=Q(U); +return U;},toDataFormat:function(U,V){var W=this.writer,X=a.htmlParser.fragment.fromHtml(U,V);W.reset();X.writeHtml(W,this.htmlFilter);var Y=W.getHtml(true);Y=R(Y);Y=S(Y,this.editor);return Y;}};})();(function(){j.add('iframe',{requires:['dialog','fakeobjects'],init:function(m){var n='iframe',o=m.lang.iframe;a.dialog.add(n,this.path+'dialogs/iframe.js');m.addCommand(n,new a.dialogCommand(n));m.addCss('img.cke_iframe{background-image: url('+a.getUrl(this.path+'images/placeholder.png')+');'+'background-position: center center;'+'background-repeat: no-repeat;'+'border: 1px solid #a9a9a9;'+'width: 80px;'+'height: 80px;'+'}');m.ui.addButton('Iframe',{label:o.toolbar,command:n});m.on('doubleclick',function(p){var q=p.data.element;if(q.is('img')&&q.data('cke-real-element-type')=='iframe')p.data.dialog='iframe';});if(m.addMenuItems)m.addMenuItems({iframe:{label:o.title,command:'iframe',group:'image'}});if(m.contextMenu)m.contextMenu.addListener(function(p,q){if(p&&p.is('img')&&p.data('cke-real-element-type')=='iframe')return{iframe:2};});},afterInit:function(m){var n=m.dataProcessor,o=n&&n.dataFilter;if(o)o.addRules({elements:{iframe:function(p){return m.createFakeParserElement(p,'cke_iframe','iframe',true);}}});}});})();(function(){j.add('image',{requires:['dialog'],init:function(o){var p='image';a.dialog.add(p,this.path+'dialogs/image.js');o.addCommand(p,new a.dialogCommand(p));o.ui.addButton('Image',{label:o.lang.common.image,command:p});o.on('doubleclick',function(q){var r=q.data.element;if(r.is('img')&&!r.data('cke-realelement')&&!r.isReadOnly())q.data.dialog='image';});if(o.addMenuItems)o.addMenuItems({image:{label:o.lang.image.menu,command:'image',group:'image'}});if(o.contextMenu)o.contextMenu.addListener(function(q,r){if(m(o,q))return{image:2};});},afterInit:function(o){p('left');p('right');p('center');p('block');function p(q){var r=o.getCommand('justify'+q);if(r){if(q=='left'||q=='right')r.on('exec',function(s){var t=m(o),u;if(t){u=n(t);if(u==q){t.removeStyle('float');if(q==n(t))t.removeAttribute('align');}else t.setStyle('float',q);s.cancel();}});r.on('refresh',function(s){var t=m(o),u;if(t){u=n(t);this.setState(u==q?1:q=='right'||q=='left'?2:0);s.cancel();}});}};}});function m(o,p){if(!p){var q=o.getSelection();p=q.getType()==3&&q.getSelectedElement();}if(p&&p.is('img')&&!p.data('cke-realelement')&&!p.isReadOnly())return p;};function n(o){var p=o.getStyle('float');if(p=='inherit'||p=='none')p=0;if(!p)p=o.getAttribute('align');return p;};})();i.image_removeLinkByEmptyURL=true; +(function(){var m={ol:1,ul:1},n=d.walker.whitespaces(true),o=d.walker.bookmark(false,true);function p(t){var B=this;if(t.editor.readOnly)return null;var u=t.editor,v=t.data.path,w=v&&v.contains(m),x=v.block||v.blockLimit;if(w)return B.setState(2);if(!B.useIndentClasses&&B.name=='indent')return B.setState(2);if(!x)return B.setState(0);if(B.useIndentClasses){var y=x.$.className.match(B.classNameRegex),z=0;if(y){y=y[1];z=B.indentClassMap[y];}if(B.name=='outdent'&&!z||B.name=='indent'&&z==u.config.indentClasses.length)return B.setState(0);return B.setState(2);}else{var A=parseInt(x.getStyle(r(x)),10);if(isNaN(A))A=0;if(A<=0)return B.setState(0);return B.setState(2);}};function q(t,u){var w=this;w.name=u;w.useIndentClasses=t.config.indentClasses&&t.config.indentClasses.length>0;if(w.useIndentClasses){w.classNameRegex=new RegExp('(?:^|\\s+)('+t.config.indentClasses.join('|')+')(?=$|\\s)');w.indentClassMap={};for(var v=0;v0){var Z=X[T].parent;X[T].parent=new h(Z.getName(),Z.getDocument());}}for(T=W.getCustomData('listarray_index')+1;TY;T++)X[T].indent+=U;var aa=j.list.arrayToList(X,v,null,t.config.enterMode,M.getDirection());if(u.name=='outdent'){var ab;if((ab=M.getParent())&&ab.is('li')){var ac=aa.listNode.getChildren(),ad=[],ae=ac.count(),af;for(T=ae-1;T>=0;T--){if((af=ac.getItem(T))&&af.is&&af.is('li'))ad.push(af);}}}if(aa)aa.listNode.replace(M);if(ad&&ad.length)for(T=0;T0)M.addClass(t.config.indentClasses[P-1]);}else{var Q=r(M,N),R=parseInt(M.getStyle(Q),10);if(isNaN(R))R=0;var S=t.config.indentOffset||40;R+=(u.name=='indent'?1:-1)*S;if(R<0)return false;R=Math.max(R,0);R=Math.ceil(R/S)*S;M.setStyle(Q,R?R+(t.config.indentUnit||'px'):'');if(M.getAttribute('style')==='')M.removeAttribute('style');}h.setMarker(v,M,'indent_processed',1);return true;};var z=t.getSelection(),A=z.createBookmarks(1),B=z&&z.getRanges(1),C,D=B.createIterator();while(C=D.getNextRange()){var E=C.getCommonAncestor(),F=E;while(F&&!(F.type==1&&m[F.getName()]))F=F.getParent();if(!F){var G=C.getEnclosedNode();if(G&&G.type==1&&G.getName() in m){C.setStartAt(G,1);C.setEndAt(G,2);F=G;}}if(F&&C.startContainer.type==1&&C.startContainer.getName() in m){var H=new d.walker(C);H.evaluator=s;C.startContainer=H.next();}if(F&&C.endContainer.type==1&&C.endContainer.getName() in m){H=new d.walker(C);H.evaluator=s;C.endContainer=H.previous();}if(F){var I=F.getFirst(s),J=!!I.getNext(s),K=C.startContainer,L=I.equals(K)||I.contains(K);if(!(L&&(u.name=='indent'||u.useIndentClasses||parseInt(F.getStyle(r(F)),10))&&y(F,!J&&I.getDirection())))w(F);}else x();}h.clearAllMarkers(v);t.forceNextSelectionCheck();z.selectBookmarks(A);}};j.add('indent',{init:function(t){var u=t.addCommand('indent',new q(t,'indent')),v=t.addCommand('outdent',new q(t,'outdent'));t.ui.addButton('Indent',{label:t.lang.indent,command:'indent'});t.ui.addButton('Outdent',{label:t.lang.outdent,command:'outdent'});t.on('selectionChange',e.bind(p,u));t.on('selectionChange',e.bind(p,v));if(b.ie6Compat||b.ie7Compat)t.addCss('ul,ol{\tmargin-left: 0px;\tpadding-left: 40px;}');t.on('dirChanged',function(w){var x=new d.range(t.document);x.setStartBefore(w.data.node);x.setEndAfter(w.data.node);var y=new d.walker(x),z;while(z=y.next()){if(z.type==1){if(!z.equals(w.data.node)&&z.getDirection()){x.setStartAfter(z);y=new d.walker(x);continue;}var A=t.config.indentClasses;if(A){var B=w.data.dir=='ltr'?['_rtl','']:['','_rtl']; +for(var C=0;C=0;z--){w=u[z].createIterator();w.enlargeBr=s!=2;while(x=w.getNextParagraph(s==1?'p':'div')){x.removeAttribute('align');x.removeStyle('text-align');var A=v&&(x.$.className=e.ltrim(x.$.className.replace(C.cssClassRegex,''))),B=C.state==2&&(!y||m(x,true)!=C.value);if(v){if(B)x.addClass(v);else if(!A)x.removeAttribute('class');}else if(B)x.setStyle('text-align',C.value);}}q.focus();q.forceNextSelectionCheck();r.selectBookmarks(t);},refresh:function(q){var r=q.block||q.blockLimit;this.setState(r.getName()!='body'&&m(r,this.editor.config.useComputedState)==this.value?1:2); +}};j.add('justify',{init:function(q){var r=new o(q,'justifyleft','left'),s=new o(q,'justifycenter','center'),t=new o(q,'justifyright','right'),u=new o(q,'justifyblock','justify');q.addCommand('justifyleft',r);q.addCommand('justifycenter',s);q.addCommand('justifyright',t);q.addCommand('justifyblock',u);q.ui.addButton('JustifyLeft',{label:q.lang.justify.left,command:'justifyleft'});q.ui.addButton('JustifyCenter',{label:q.lang.justify.center,command:'justifycenter'});q.ui.addButton('JustifyRight',{label:q.lang.justify.right,command:'justifyright'});q.ui.addButton('JustifyBlock',{label:q.lang.justify.block,command:'justifyblock'});q.on('selectionChange',e.bind(n,r));q.on('selectionChange',e.bind(n,t));q.on('selectionChange',e.bind(n,s));q.on('selectionChange',e.bind(n,u));q.on('dirChanged',p);},requires:['domiterator']});})();j.add('keystrokes',{beforeInit:function(m){m.keystrokeHandler=new a.keystrokeHandler(m);m.specialKeys={};},init:function(m){var n=m.config.keystrokes,o=m.config.blockedKeystrokes,p=m.keystrokeHandler.keystrokes,q=m.keystrokeHandler.blockedKeystrokes;for(var r=0;r7))Y.append(T.createText('\xa0'));Y.append(af.listNode);W=af.nextIndex;}else if(ac.indent==-1&&!P&&ad){if(m[ad.getName()]){Y=ac.element.clone(false,true);if(Z!=ad.getDirection(1))Y.setAttribute('dir',Z);}else Y=new d.documentFragment(T);var ag=ad.getDirection(1)!=Z,ah=ac.element,ai=ah.getAttribute('class'),aj=ah.getAttribute('style'),ak=Y.type==11&&(Q!=2||ag||aj||ai),al,am=ac.contents.length;for(S=0;SQ[S-1].indent+1){var W=Q[S-1].indent+1-Q[S].indent,X=Q[S].indent;while(Q[S]&&Q[S].indent>=X){Q[S].indent+=W;S++;}S--;}}var Y=j.list.arrayToList(Q,P,null,N.config.enterMode,O.root.getAttribute('dir')),Z=Y.listNode,aa,ab;function ac(ad){if((aa=Z[ad?'getFirst':'getLast']())&&!(aa.is&&aa.isBlockBoundary())&&(ab=O.root[ad?'getPrevious':'getNext'](d.walker.whitespaces(true)))&&!(ab.is&&ab.isBlockBoundary({br:1})))N.document.createElement('br')[ad?'insertBefore':'insertAfter'](aa); +};ac(true);ac();Z.replace(O.root);};function z(N,O){this.name=N;this.type=O;};var A=d.walker.nodeType(1);function B(N,O,P,Q){var R,S;while(R=N[Q?'getLast':'getFirst'](A)){if((S=R.getDirection(1))!==O.getDirection(1))R.setAttribute('dir',S);R.remove();P?R[Q?'insertBefore':'insertAfter'](P):O.append(R,Q);}};z.prototype={exec:function(N){var aq=this;var O=N.document,P=N.config,Q=N.getSelection(),R=Q&&Q.getRanges(true);if(!R||R.length<1)return;if(aq.state==2){var S=O.getBody();if(!S.getFirst(q)){P.enterMode==2?S.appendBogus():R[0].fixBlock(1,P.enterMode==1?'p':'div');Q.selectRanges(R);}else{var T=R.length==1&&R[0],U=T&&T.getEnclosedNode();if(U&&U.is&&aq.type==U.getName())aq.setState(1);}}var V=Q.createBookmarks(true),W=[],X={},Y=R.createIterator(),Z=0;while((T=Y.getNextRange())&&++Z){var aa=T.getBoundaryNodes(),ab=aa.startNode,ac=aa.endNode;if(ab.type==1&&ab.getName()=='td')T.setStartAt(aa.startNode,1);if(ac.type==1&&ac.getName()=='td')T.setEndAt(aa.endNode,2);var ad=T.createIterator(),ae;ad.forceBrBreak=aq.state==2;while(ae=ad.getNextParagraph()){if(ae.getCustomData('list_block'))continue;else h.setMarker(X,ae,'list_block',1);var af=new d.elementPath(ae),ag=af.elements,ah=ag.length,ai=null,aj=0,ak=af.blockLimit,al;for(var am=ah-1;am>=0&&(al=ag[am]);am--){if(m[al.getName()]&&ak.contains(al)){ak.removeCustomData('list_group_object_'+Z);var an=al.getCustomData('list_group_object');if(an)an.contents.push(ae);else{an={root:al,contents:[ae]};W.push(an);h.setMarker(X,al,'list_group_object',an);}aj=1;break;}}if(aj)continue;var ao=ak;if(ao.getCustomData('list_group_object_'+Z))ao.getCustomData('list_group_object_'+Z).contents.push(ae);else{an={root:ao,contents:[ae]};h.setMarker(X,ao,'list_group_object_'+Z,an);W.push(an);}}}var ap=[];while(W.length>0){an=W.shift();if(aq.state==2){if(m[an.root.getName()])v.call(aq,N,an,X,ap);else x.call(aq,N,an,ap);}else if(aq.state==1&&m[an.root.getName()])y.call(aq,N,an,X);}for(am=0;am0)for(var u=t.length-1;u>=0;u--){var v=t[u][0],w=t[u][1];if(w)v.insertBefore(w);else v.appendTo(s);}};function o(s,t){var u=m(s),v={},w=s.$;if(!t){v['class']=w.className||'';w.className='';}v.inline=w.style.cssText||'';if(!t)w.style.cssText='position: static; overflow: visible';n(u);return v;};function p(s,t){var u=m(s),v=s.$;if('class' in t)v.className=t['class'];if('inline' in t)v.style.cssText=t.inline;n(u);};function q(s){var t=a.instances;for(var u in t){var v=t[u];if(v.mode=='wysiwyg'&&!v.readOnly){var w=v.document.getBody();w.setAttribute('contentEditable',false);w.setAttribute('contentEditable',true);}}if(s.focusManager.hasFocus){s.toolbox.focus();s.focus();}};function r(s){if(!c||b.version>6)return null;var t=h.createFromHtml('');return s.append(t,true);};j.add('maximize',{init:function(s){var t=s.lang,u=a.document,v=u.getWindow(),w,x,y,z;function A(){var C=v.getViewPaneSize();z&&z.setStyles({width:C.width+'px',height:C.height+'px'});s.resize(C.width,C.height,null,true);};var B=2;s.addCommand('maximize',{modes:{wysiwyg:!b.iOS,source:!b.iOS},readOnly:1,editorFocus:false,exec:function(){var C=s.container.getChild(1),D=s.getThemeSpace('contents');if(s.mode=='wysiwyg'){var E=s.getSelection();w=E&&E.getRanges();x=v.getScrollPosition();}else{var F=s.textarea.$;w=!c&&[F.selectionStart,F.selectionEnd];x=[F.scrollLeft,F.scrollTop];}if(this.state==2){v.on('resize',A);y=v.getScrollPosition();var G=s.container;while(G=G.getParent()){G.setCustomData('maximize_saved_styles',o(G));G.setStyle('z-index',s.config.baseFloatZIndex-1);}D.setCustomData('maximize_saved_styles',o(D,true));C.setCustomData('maximize_saved_styles',o(C,true));var H={overflow:b.webkit?'':'hidden',width:0,height:0};u.getDocumentElement().setStyles(H);!b.gecko&&u.getDocumentElement().setStyle('position','fixed');!(b.gecko&&b.quirks)&&u.getBody().setStyles(H);c?setTimeout(function(){v.$.scrollTo(0,0);},0):v.$.scrollTo(0,0);C.setStyle('position',b.gecko&&b.quirks?'fixed':'absolute');C.$.offsetLeft;C.setStyles({'z-index':s.config.baseFloatZIndex-1,left:'0px',top:'0px'});z=r(C);C.addClass('cke_maximized');A();var I=C.getDocumentPosition();C.setStyles({left:-1*I.x+'px',top:-1*I.y+'px'}); +b.gecko&&q(s);}else if(this.state==1){v.removeListener('resize',A);var J=[D,C];for(var K=0;K 
    ');s.children.length=0;s.add(u);var v=s.attributes;delete v['aria-label'];delete v.contenteditable;delete v.title;}return t;}}},5);if(p)p.addRules({elements:{div:function(r){var s=r.attributes,t=s&&s.style,u=t&&r.children.length==1&&r.children[0],v=u&&u.name=='span'&&u.attributes.style;if(v&&/page-break-after\s*:\s*always/i.test(t)&&/display\s*:\s*none/i.test(v)){s.contenteditable='false';s['class']='cke_pagebreak';s['data-cke-display-name']='pagebreak';s['aria-label']=n;s.title=n;r.children.length=0;}}}});},requires:['fakeobjects']});j.pagebreakCmd={exec:function(m){var n=m.lang.pagebreakAlt,o=h.createFromHtml('
    '+'
    ',m.document),p=m.getSelection().getRanges(true);m.fire('saveSnapshot');for(var q,r=p.length-1;r>=0;r--){q=p[r];if(r1&&n.substr(n.length-1,1)=='%')n=parseInt(window.screen.width*parseInt(n,10)/100,10);if(typeof o=='string'&&o.length>1&&o.substr(o.length-1,1)=='%')o=parseInt(window.screen.height*parseInt(o,10)/100,10);if(n<640)n=640;if(o<420)o=420;var q=parseInt((window.screen.height-o)/2,10),r=parseInt((window.screen.width-n)/2,10);p=(p||'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes')+',width='+n+',height='+o+',top='+q+',left='+r;var s=window.open('',null,p,true);if(!s)return false;try{var t=navigator.userAgent.toLowerCase();if(t.indexOf(' chrome/')==-1){s.moveTo(r,q);s.resizeTo(n,o);}s.focus();s.location.href=m;}catch(u){s=window.open(m,null,p,true);}return true;}});(function(){var m,n={modes:{wysiwyg:1,source:1},canUndo:false,readOnly:1,exec:function(p){var q,r=p.config,s=r.baseHref?'':'',t=b.isCustomDomain();if(r.fullPage)q=p.getData().replace(//,'$&'+s).replace(/[^>]*(?=<\/title>)/,'$& — '+p.lang.preview);else{var u=''+''+s+''+p.lang.preview+''+e.buildStyleHtml(p.config.contentsCss)+''+u+p.getData()+'';}var w=640,x=420,y=80;try{var z=window.screen;w=Math.round(z.width*0.8);x=Math.round(z.height*0.7);y=Math.round(z.width*0.1);}catch(D){}var A='';if(t){window._cke_htmlToLoad=q;A='javascript:void( (function(){document.open();document.domain="'+document.domain+'";'+'document.write( window.opener._cke_htmlToLoad );'+'document.close();'+'window.opener._cke_htmlToLoad = null;'+'})() )'; +}if(b.gecko){window._cke_htmlToLoad=q;A=m+'preview.html';}var B=window.open(A,null,'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+w+',height='+x+',left='+y);if(!t&&!b.gecko){var C=B.document;C.open();C.write(q);C.close();b.webkit&&setTimeout(function(){C.body.innerHTML+='';},0);}}},o='preview';j.add(o,{init:function(p){m=this.path;p.addCommand(o,n);p.ui.addButton('Preview',{label:p.lang.preview,command:o});}});})();j.add('print',{init:function(m){var n='print',o=m.addCommand(n,j.print);m.ui.addButton('Print',{label:m.lang.print,command:n});}});j.print={exec:function(m){if(b.opera)return;else if(b.gecko)m.window.$.print();else m.document.$.execCommand('Print');},canUndo:false,readOnly:1,modes:{wysiwyg:!b.opera}};j.add('removeformat',{requires:['selection'],init:function(m){m.addCommand('removeFormat',j.removeformat.commands.removeformat);m.ui.addButton('RemoveFormat',{label:m.lang.removeFormat,command:'removeFormat'});m._.removeFormat={filters:[]};}});j.removeformat={commands:{removeformat:{exec:function(m){var n=m._.removeFormatRegex||(m._.removeFormatRegex=new RegExp('^(?:'+m.config.removeFormatTags.replace(/,/g,'|')+')$','i')),o=m._.removeAttributes||(m._.removeAttributes=m.config.removeFormatAttributes.split(',')),p=j.removeformat.filter,q=m.getSelection().getRanges(1),r=q.createIterator(),s;while(s=r.getNextRange()){if(!s.collapsed)s.enlarge(1);var t=s.createBookmark(),u=t.startNode,v=t.endNode,w,x=function(z){var A=new d.elementPath(z),B=A.elements;for(var C=1,D;D=B[C];C++){if(D.equals(A.block)||D.equals(A.blockLimit))break;if(n.test(D.getName())&&p(m,D))z.breakParent(D);}};x(u);if(v){x(v);w=u.getNextSourceNode(true,1);while(w){if(w.equals(v))break;var y=w.getNextSourceNode(false,1);if(!(w.getName()=='img'&&w.data('cke-realelement'))&&p(m,w))if(n.test(w.getName()))w.remove(1);else{w.removeAttributes(o);m.fire('removeFormatCleanup',w);}w=y;}}s.moveToBookmark(t);}m.getSelection().selectRanges(q);}}},filter:function(m,n){var o=m._.removeFormat.filters;for(var p=0;pr.width&&(n.resize_minWidth=r.width);n.resize_minHeight>r.height&&(n.resize_minHeight=r.height);a.document.on('mousemove',u);a.document.on('mouseup',v);if(m.document){m.document.on('mousemove',u);m.document.on('mouseup',v);}});m.on('destroy',function(){e.removeFunction(w);});m.on('themeSpace',function(x){if(x.data.space=='bottom'){var y='';if(s&&!t)y=' cke_resizer_horizontal';if(!s&&t)y=' cke_resizer_vertical';var z='
    ';o=='ltr'&&y=='ltr'?x.data.html+=z:x.data.html=z+x.data.html;}},m,null,100);}}});(function(){var m={modes:{wysiwyg:1,source:1},readOnly:1,exec:function(o){var p=o.element.$.form;if(p)try{p.submit();}catch(q){if(p.submit.click)p.submit.click();}}},n='save';j.add(n,{init:function(o){var p=o.addCommand(n,m);p.modes={wysiwyg:!!o.element.$.form};o.ui.addButton('Save',{label:o.lang.save,command:n});}});})();(function(){var m='scaytcheck',n='';function o(t,u){var v=0,w;for(w in u){if(u[w]==t){v=1;break;}}return v;};var p=function(){var t=this,u=function(){var y=t.config,z={};z.srcNodeRef=t.document.getWindow().$.frameElement;z.assocApp='CKEDITOR.'+a.version+'@'+a.revision;z.customerid=y.scayt_customerid||'1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';z.customDictionaryIds=y.scayt_customDictionaryIds||'';z.userDictionaryName=y.scayt_userDictionaryName||'';z.sLang=y.scayt_sLang||'en_US'; +z.onLoad=function(){if(!(c&&b.version<8))this.addStyle(this.selectorCss(),'padding-bottom: 2px !important;');if(t.focusManager.hasFocus&&!q.isControlRestored(t))this.focus();};z.onBeforeChange=function(){if(q.getScayt(t)&&!t.checkDirty())setTimeout(function(){t.resetDirty();},0);};var A=window.scayt_custom_params;if(typeof A=='object')for(var B in A)z[B]=A[B];if(q.getControlId(t))z.id=q.getControlId(t);var C=new window.scayt(z);C.afterMarkupRemove.push(function(E){new h(E,C.document).mergeSiblings();});var D=q.instances[t.name];if(D){C.sLang=D.sLang;C.option(D.option());C.paused=D.paused;}q.instances[t.name]=C;try{C.setDisabled(q.isPaused(t)===false);}catch(E){}t.fire('showScaytState');};t.on('contentDom',u);t.on('contentDomUnload',function(){var y=a.document.getElementsByTag('script'),z=/^dojoIoScript(\d+)$/i,A=/^https?:\/\/svc\.webspellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;for(var B=0;B=0){this.setState(0);q.loadEngine(t);}}};j.add('scayt',{requires:['menubutton'],beforeInit:function(t){var u=t.config.scayt_contextMenuItemsOrder||'suggest|moresuggest|control',v='';u=u.split('|');if(u&&u.length)for(var w=0;w tr > td, .%1 table.%2 > tr > th,','.%1 table.%2 > tbody > tr > td, .%1 table.%2 > tbody > tr > th,','.%1 table.%2 > thead > tr > td, .%1 table.%2 > thead > tr > th,','.%1 table.%2 > tfoot > tr > td, .%1 table.%2 > tfoot > tr > th','{','border : #d3d3d3 1px dotted','}']).join('');n=o.replace(/%2/g,m).replace(/%1/g,'cke_show_borders ');var p={preserveState:true,editorFocus:false,readOnly:1,exec:function(q){this.toggleState();this.refresh(q);},refresh:function(q){if(q.document){var r=this.state==1?'addClass':'removeClass';q.document.getBody()[r]('cke_show_borders');}}};j.add('showborders',{requires:['wysiwygarea'],modes:{wysiwyg:1},init:function(q){var r=q.addCommand('showborders',p);r.canUndo=false;if(q.config.startupShowBorders!==false)r.setState(1);q.addCss(n);q.on('mode',function(){if(r.state!=0)r.refresh(q);},null,null,100);q.on('contentDom',function(){if(r.state!=0)r.refresh(q);});q.on('removeFormatCleanup',function(s){var t=s.data;if(q.getCommand('showborders').state==1&&t.is('table')&&(!t.hasAttribute('border')||parseInt(t.getAttribute('border'),10)<=0))t.addClass(m);});},afterInit:function(q){var r=q.dataProcessor,s=r&&r.dataFilter,t=r&&r.htmlFilter; +if(s)s.addRules({elements:{table:function(u){var v=u.attributes,w=v['class'],x=parseInt(v.border,10);if((!x||x<=0)&&(!w||w.indexOf(m)==-1))v['class']=(w||'')+' '+m;}}});if(t)t.addRules({elements:{table:function(u){var v=u.attributes,w=v['class'];w&&(v['class']=w.replace(m,'').replace(/\s{2}/,' ').replace(/^\s+|\s+$/,''));}}});}});a.on('dialogDefinition',function(q){var r=q.data.name;if(r=='table'||r=='tableProperties'){var s=q.data.definition,t=s.getContents('info'),u=t.get('txtBorder'),v=u.commit;u.commit=e.override(v,function(y){return function(z,A){y.apply(this,arguments);var B=parseInt(this.getValue(),10);A[!B||B<=0?'addClass':'removeClass'](m);};});var w=s.getContents('advanced'),x=w&&w.get('advCSSClasses');if(x){x.setup=e.override(x.setup,function(y){return function(){y.apply(this,arguments);this.setValue(this.getValue().replace(/cke_show_border/,''));};});x.commit=e.override(x.commit,function(y){return function(z,A){y.apply(this,arguments);if(!parseInt(A.getAttribute('border'),10))A.addClass('cke_show_border');};});}}});})();j.add('sourcearea',{requires:['editingblock'],init:function(m){var n=j.sourcearea,o=a.document.getWindow();m.on('editingBlockReady',function(){var p,q;m.addMode('source',{load:function(r,s){if(c&&b.version<8)r.setStyle('position','relative');m.textarea=p=new h('textarea');p.setAttributes({dir:'ltr',tabIndex:b.webkit?-1:m.tabIndex,role:'textbox','aria-label':m.lang.editorTitle.replace('%1',m.name)});p.addClass('cke_source');p.addClass('cke_enable_context_menu');m.readOnly&&p.setAttribute('readOnly','readonly');var t={width:b.ie7Compat?'99%':'100%',height:'100%',resize:'none',outline:'none','text-align':'left'};if(c){q=function(){p.hide();p.setStyle('height',r.$.clientHeight+'px');p.setStyle('width',r.$.clientWidth+'px');p.show();};m.on('resize',q);o.on('resize',q);setTimeout(q,0);}r.setHtml('');r.append(p);p.setStyles(t);m.fire('ariaWidget',p);p.on('blur',function(){m.focusManager.blur();});p.on('focus',function(){m.focusManager.focus();});m.mayBeDirty=true;this.loadData(s);var u=m.keystrokeHandler;if(u)u.attach(p);setTimeout(function(){m.mode='source';m.fire('mode',{previousMode:m._.previousMode});},b.gecko||b.webkit?100:0);},loadData:function(r){p.setValue(r);m.fire('dataReady');},getData:function(){return p.getValue();},getSnapshotData:function(){return p.getValue();},unload:function(r){p.clearCustomData();m.textarea=p=null;if(q){m.removeListener('resize',q);o.removeListener('resize',q);}if(c&&b.version<8)r.removeStyle('position'); +},focus:function(){p.focus();}});});m.on('readOnly',function(){if(m.mode=='source')if(m.readOnly)m.textarea.setAttribute('readOnly','readonly');else m.textarea.removeAttribute('readOnly');});m.addCommand('source',n.commands.source);if(m.ui.addButton)m.ui.addButton('Source',{label:m.lang.source,command:'source'});m.on('mode',function(){m.getCommand('source').setState(m.mode=='source'?1:2);});}});j.sourcearea={commands:{source:{modes:{wysiwyg:1,source:1},editorFocus:false,readOnly:1,exec:function(m){if(m.mode=='wysiwyg')m.fire('saveSnapshot');m.getCommand('source').setState(0);m.setMode(m.mode=='source'?'wysiwyg':'source');},canUndo:false}}};(function(){j.add('stylescombo',{requires:['richcombo','styles'],init:function(n){var o=n.config,p=n.lang.stylesCombo,q={},r=[],s;function t(u){n.getStylesSet(function(v){if(!r.length){var w,x;for(var y=0,z=v.length;y0)return;if(S.type==1&&m.test(S.getName())&&!S.getCustomData('selected_cell')){h.setMarker(J,S,'selected_cell',true);I.push(S);}};for(var L=0;L1&&V&&U[Y]==V[Y]){Z=U[Y];Z.rowSpan+=1;}else{Z=new h(U[Y]).clone();Z.removeAttribute('rowSpan');!c&&Z.appendBogus();X.append(Z);Z=Z.$;}Y+=Z.colSpan-1;}H?X.insertBefore(S):X.insertAfter(S);};function q(G){if(G instanceof d.selection){var H=n(G),I=H[0],J=I.getAscendant('table'),K=e.buildTableMap(J),L=H[0].getParent(),M=L.$.rowIndex,N=H[H.length-1],O=N.getParent().$.rowIndex+N.$.rowSpan-1,P=[]; +for(var Q=M;Q<=O;Q++){var R=K[Q],S=new h(J.$.rows[Q]);for(var T=0;T0?X[M-1]:null)||J.$.parentNode);for(Q=P.length;Q>=0;Q--)q(P[Q]);return Y;}else if(G instanceof h){J=G.getAscendant('table');if(J.$.rows.length==1)J.remove();else G.remove();}return null;};function r(G,H){var I=G.getParent(),J=I.$.cells,K=0;for(var L=0;LI)I=K;}return I;};function t(G,H){var I=n(G),J=I[0],K=J.getAscendant('table'),L=s(I,1),M=s(I),N=H?L:M,O=e.buildTableMap(K),P=[],Q=[],R=O.length;for(var S=0;S1&&Q[S]==P[S]){U=P[S];U.colSpan+=1;}else{U=new h(P[S]).clone();U.removeAttribute('colSpan');!c&&U.appendBogus();U[H?'insertBefore':'insertAfter'].call(U,new h(P[S]));U=U.$;}S+=U.rowSpan-1;}};function u(G){var H=n(G),I=H[0],J=H[H.length-1],K=I.getAscendant('table'),L=e.buildTableMap(K),M,N,O=[];for(var P=0,Q=L.length;P1){L=H[J-1]+1;break;}}if(!L)L=H[0]>0?H[0]-1:H[H.length-1]+1;var N=I.$.rows;for(J=0,K=N.length;J=0;K--)x(H[K]);if(J)z(J,true);else if(I)I.remove();}else if(G instanceof h){var L=G.getParent();if(L.getChildCount()==1)L.remove(); +else G.remove();}};function y(G){var H=G.getBogus();H&&H.remove();G.trim();};function z(G,H){var I=new d.range(G.getDocument());if(!I['moveToElementEdit'+(H?'End':'Start')](G)){I.selectNodeContents(G);I.collapse(H?false:true);}I.select(true);};function A(G,H,I){var J=G[H];if(typeof I=='undefined')return J;for(var K=0;J&&K1)J+=K[H].rowSpan-1;}return I;};function C(G,H,I){var J=n(G),K;if((H?J.length!=1:J.length<2)||(K=G.getCommonAncestor())&&K.type==1&&K.is('table'))return false;var L,M=J[0],N=M.getAscendant('table'),O=e.buildTableMap(N),P=O.length,Q=O[0].length,R=M.getParent().$.rowIndex,S=A(O,R,M);if(H){var T;try{var U=parseInt(M.getAttribute('rowspan'),10)||1,V=parseInt(M.getAttribute('colspan'),10)||1;T=O[H=='up'?R-U:H=='down'?R+U:R][H=='left'?S-V:H=='right'?S+V:S];}catch(an){return false;}if(!T||M.$==T)return false;J[H=='up'||H=='left'?'unshift':'push'](new h(T));}var W=M.getDocument(),X=R,Y=0,Z=0,aa=!I&&new d.documentFragment(W),ab=0;for(var ac=0;ac=Q)M.removeAttribute('rowSpan');else M.$.rowSpan=Y;if(Y>=P)M.removeAttribute('colSpan');else M.$.colSpan=Z;var ak=new d.nodeList(N.$.rows),al=ak.count();for(ac=al-1;ac>=0;ac--){var am=ak.getItem(ac);if(!am.$.cells.length){am.remove();al++;continue;}}return M;}else return Y*Z==ab;};function D(G,H){var I=n(G);if(I.length>1)return false;else if(H)return true;var J=I[0],K=J.getParent(),L=K.getAscendant('table'),M=e.buildTableMap(L),N=K.$.rowIndex,O=A(M,N,J),P=J.$.rowSpan,Q,R,S,T;if(P>1){R=Math.ceil(P/2);S=Math.floor(P/2);T=N+R;var U=new h(L.$.rows[T]),V=A(M,T),W;Q=J.clone();for(var X=0;XO){Q.insertBefore(new h(W));break;}else W=null;}if(!W)U.append(Q,true);}else{S=R=1;U=K.clone();U.insertAfter(K);U.append(Q=J.clone());var Y=A(M,N);for(var Z=0;Z1)return false;else if(H)return true;var J=I[0],K=J.getParent(),L=K.getAscendant('table'),M=e.buildTableMap(L),N=K.$.rowIndex,O=A(M,N,J),P=J.$.colSpan,Q,R,S;if(P>1){R=Math.ceil(P/2);S=Math.floor(P/2);}else{S=R=1;var T=B(M,O);for(var U=0;U0?2:0}; +}},tablecell_insertBefore:{label:H.cell.insertBefore,group:'tablecell',command:'cellInsertBefore',order:5},tablecell_insertAfter:{label:H.cell.insertAfter,group:'tablecell',command:'cellInsertAfter',order:10},tablecell_delete:{label:H.cell.deleteCell,group:'tablecell',command:'cellDelete',order:15},tablecell_merge:{label:H.cell.merge,group:'tablecell',command:'cellMerge',order:16},tablecell_merge_right:{label:H.cell.mergeRight,group:'tablecell',command:'cellMergeRight',order:17},tablecell_merge_down:{label:H.cell.mergeDown,group:'tablecell',command:'cellMergeDown',order:18},tablecell_split_horizontal:{label:H.cell.splitHorizontal,group:'tablecell',command:'cellHorizontalSplit',order:19},tablecell_split_vertical:{label:H.cell.splitVertical,group:'tablecell',command:'cellVerticalSplit',order:20},tablecell_properties:{label:H.cell.title,group:'tablecellproperties',command:'cellProperties',order:21},tablerow:{label:H.row.menu,group:'tablerow',order:1,getItems:function(){return{tablerow_insertBefore:2,tablerow_insertAfter:2,tablerow_delete:2};}},tablerow_insertBefore:{label:H.row.insertBefore,group:'tablerow',command:'rowInsertBefore',order:5},tablerow_insertAfter:{label:H.row.insertAfter,group:'tablerow',command:'rowInsertAfter',order:10},tablerow_delete:{label:H.row.deleteRow,group:'tablerow',command:'rowDelete',order:15},tablecolumn:{label:H.column.menu,group:'tablecolumn',order:1,getItems:function(){return{tablecolumn_insertBefore:2,tablecolumn_insertAfter:2,tablecolumn_delete:2};}},tablecolumn_insertBefore:{label:H.column.insertBefore,group:'tablecolumn',command:'columnInsertBefore',order:5},tablecolumn_insertAfter:{label:H.column.insertAfter,group:'tablecolumn',command:'columnInsertAfter',order:10},tablecolumn_delete:{label:H.column.deleteColumn,group:'tablecolumn',command:'columnDelete',order:15}});if(G.contextMenu)G.contextMenu.addListener(function(I,J){if(!I||I.isReadOnly())return null;while(I){if(I.getName() in F)return{tablecell:2,tablerow:2,tablecolumn:2};I=I.getParent();}return null;});},getSelectedCells:n};j.add('tabletools',j.tabletools);})();e.buildTableMap=function(m){var n=m.$.rows,o=-1,p=[];for(var q=0;qp&&(!s||!t||vt){s=v;t=u;}}else{if(q&&u==p){s=v;break;}if(ut)){s=v;t=u;}}}if(s)s.focus();};(function(){j.add('templates',{requires:['dialog'],init:function(o){a.dialog.add('templates',a.getUrl(this.path+'dialogs/templates.js'));o.addCommand('templates',new a.dialogCommand('templates')); +o.ui.addButton('Templates',{label:o.lang.templates.button,command:'templates'});}});var m={},n={};a.addTemplates=function(o,p){m[o]=p;};a.getTemplates=function(o){return m[o];};a.loadTemplates=function(o,p){var q=[];for(var r=0,s=o.length;r':' style="display:none">');t.push('',o.lang.toolbars,'');var w=o.toolbox.toolbars,x=o.config.toolbar instanceof Array?o.config.toolbar:o.config['toolbar_'+o.config.toolbar];for(var y=0;y');v=0;}if(C==='/'){t.push('
    ');continue;}D=C.items||C;for(var E=0;E');B&&t.push('',B,'');t.push('');var I=w.push(A)-1;if(I>0){A.previous=w[I-1];A.previous.next=A;}}if(H){if(!v){t.push('');v=1;}}else if(v){t.push('');v=0;}var J=F.render(o,t);I=A.items.push(J)-1;if(I>0){J.previous=A.items[I-1];J.previous.next=J;}J.toolbar=A;J.onkey=q;J.onfocus=function(){if(!o.toolbox.focusCommandExecuted)o.focus();};}}if(v){t.push('
    ');v=0;}if(A)t.push('');}t.push('');if(o.config.toolbarCanCollapse){var K=e.addFunction(function(){o.execCommand('toolbarCollapse');});o.on('destroy',function(){e.removeFunction(K);});var L=e.getNextId();o.addCommand('toolbarCollapse',{readOnly:1,exec:function(M){var N=a.document.getById(L),O=N.getPrevious(),P=M.getThemeSpace('contents'),Q=O.getParent(),R=parseInt(P.$.style.height,10),S=Q.$.offsetHeight,T=!O.isVisible();if(!T){O.hide();N.addClass('cke_toolbox_collapser_min');N.setAttribute('title',M.lang.toolbarExpand);}else{O.show();N.removeClass('cke_toolbox_collapser_min');N.setAttribute('title',M.lang.toolbarCollapse);}N.getFirst().setText(T?'▲':'◀');var U=Q.$.offsetHeight-S;P.setStyle('height',R-U+'px');M.fire('resize');},modes:{wysiwyg:1,source:1}});t.push('','','');}r.data.html+=t.join('');}});o.on('destroy',function(){var r,s=0,t,u,v;r=this.toolbox.toolbars;for(;s');return{};}};}});}});})();a.UI_SEPARATOR='separator';i.toolbarLocation='top';i.toolbar_Basic=[['Bold','Italic','-','NumberedList','BulletedList','-','Link','Unlink','-','About']];i.toolbar_Full=[{name:'document',items:['Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates']},{name:'clipboard',items:['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']},{name:'editing',items:['Find','Replace','-','SelectAll','-','SpellChecker','Scayt']},{name:'forms',items:['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField']},'/',{name:'basicstyles',items:['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']},{name:'paragraph',items:['NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl']},{name:'links',items:['Link','Unlink','Anchor']},{name:'insert',items:['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe']},'/',{name:'styles',items:['Styles','Format','Font','FontSize']},{name:'colors',items:['TextColor','BGColor']},{name:'tools',items:['Maximize','ShowBlocks','-','About']}]; +i.toolbar='Full';i.toolbarCanCollapse=true;(function(){j.add('undo',{requires:['selection','wysiwygarea'],init:function(s){var t=new o(s),u=s.addCommand('undo',{exec:function(){if(t.undo()){s.selectionChange();this.fire('afterUndo');}},state:0,canUndo:false}),v=s.addCommand('redo',{exec:function(){if(t.redo()){s.selectionChange();this.fire('afterRedo');}},state:0,canUndo:false});t.onChange=function(){u.setState(t.undoable()?2:0);v.setState(t.redoable()?2:0);};function w(x){if(t.enabled&&x.data.command.canUndo!==false)t.save();};s.on('beforeCommandExec',w);s.on('afterCommandExec',w);s.on('saveSnapshot',function(x){t.save(x.data&&x.data.contentOnly);});s.on('contentDom',function(){s.document.on('keydown',function(x){if(!x.data.$.ctrlKey&&!x.data.$.metaKey)t.type(x);});});s.on('beforeModeUnload',function(){s.mode=='wysiwyg'&&t.save(true);});s.on('mode',function(){t.enabled=s.readOnly?false:s.mode=='wysiwyg';t.onChange();});s.ui.addButton('Undo',{label:s.lang.undo,command:'undo'});s.ui.addButton('Redo',{label:s.lang.redo,command:'redo'});s.resetUndo=function(){t.reset();s.fire('saveSnapshot');};s.on('updateSnapshot',function(){if(t.currentImage)t.update();});}});j.undo={};var m=j.undo.Image=function(s){this.editor=s;s.fire('beforeUndoImage');var t=s.getSnapshot(),u=t&&s.getSelection();c&&t&&(t=t.replace(/\s+data-cke-expando=".*?"/g,''));this.contents=t;this.bookmarks=u&&u.createBookmarks2(true);s.fire('afterUndoImage');},n=/\b(?:href|src|name)="[^"]*?"/gi;m.prototype={equals:function(s,t){var u=this.contents,v=s.contents;if(c&&(b.ie7Compat||b.ie6Compat)){u=u.replace(n,'');v=v.replace(n,'');}if(u!=v)return false;if(t)return true;var w=this.bookmarks,x=s.bookmarks;if(w||x){if(!w||!x||w.length!=x.length)return false;for(var y=0;y25){this.save(false,null,false);this.modifiersCount=1;}}else if(!y){this.modifiersCount=0;this.typesCount++;if(this.typesCount>25){this.save(false,null,false);this.typesCount=1;}}},reset:function(){var s=this;s.lastKeystroke=0;s.snapshots=[];s.index=-1;s.limit=s.editor.config.undoStackSize||20;s.currentImage=null;s.hasUndo=false;s.hasRedo=false;s.resetType();},resetType:function(){var s=this;s.typing=false;delete s.lastKeystroke;s.typesCount=0;s.modifiersCount=0;},fireChange:function(){var s=this;s.hasUndo=!!s.getNextImage(true);s.hasRedo=!!s.getNextImage(false);s.resetType();s.onChange();},save:function(s,t,u){var w=this;var v=w.snapshots;if(!t)t=new m(w.editor);if(t.contents===false)return false;if(w.currentImage&&t.equals(w.currentImage,s))return false;v.splice(w.index+1,v.length-w.index-1);if(v.length==w.limit)v.shift();w.index=v.push(t)-1;w.currentImage=t;if(u!==false)w.fireChange();return true;},restoreImage:function(s){var w=this;var t=w.editor,u;if(s.bookmarks){t.focus();u=t.getSelection();}w.editor.loadSnapshot(s.contents);if(s.bookmarks)u.selectBookmarks(s.bookmarks);else if(c){var v=w.editor.document.getBody().$.createTextRange();v.collapse(true);v.select();}w.index=s.index;w.update();w.fireChange();},getNextImage:function(s){var x=this;var t=x.snapshots,u=x.currentImage,v,w;if(u)if(s)for(w=x.index-1;w>=0;w--){v=t[w];if(!u.equals(v,true)){v.index=w;return v;}}else for(w=x.index+1;w]*>)\s*<(p|div|address|h\d|center|pre)[^>]*>\s*(?:]*>| |\u00A0| )?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi,n=d.walker.whitespaces(true),o=d.walker.bogus(true),p=function(E){return n(E)&&o(E);};function q(E){return E.isBlockBoundary()&&f.$empty[E.getName()];};function r(E){return function(F){if(this.mode=='wysiwyg'){this.focus(); +var G=this.getSelection(),H=G.isLocked;H&&G.unlock();this.fire('saveSnapshot');E.call(this,F.data);H&&this.getSelection().lock();var I=this;setTimeout(function(){try{I.fire('saveSnapshot');}catch(J){setTimeout(function(){I.fire('saveSnapshot');},200);}},0);}};};function s(E){var N=this;if(N.dataProcessor)E=N.dataProcessor.toHtml(E);if(!E)return;var F=N.getSelection(),G=F.getRanges()[0];if(G.checkReadOnly())return;if(b.opera){var H=new d.elementPath(G.startContainer);if(H.block){var I=a.htmlParser.fragment.fromHtml(E,false).children;for(var J=0,K=I.length;J'+Q+'';});I=I.replace(/\n/g,'
    ');if(!(H||c))I=I.replace(new RegExp('
    (?=)'),function(O){return e.repeat(O,2);});if(b.gecko||b.webkit){var K=new d.elementPath(F.getStartElement()),L=[];for(var M=0;M/));else if(N in f.$block)break;}I=L.join('')+I;}s.call(this,I);};function u(E){var F=this.getSelection(),G=F.getRanges(),H=E.getName(),I=f.$block[H],J=F.isLocked;if(J)F.unlock();var K,L,M,N;for(var O=G.length-1;O>=0;O--){K=G[O];if(!K.checkReadOnly()){K.deleteContents(1);L=!O&&E||E.clone(1);var P,Q;if(I)while((P=K.getCommonAncestor(0,1))&&(Q=f[P.getName()])&&!(Q&&Q[H])){if(P.getName() in f.span)K.splitElement(P);else if(K.checkStartOfBlock()&&K.checkEndOfBlock()){K.setStartBefore(P);K.collapse(true);P.remove();}else K.splitBlock();}K.insertNode(L); +if(!M)M=L;}}if(M){K.moveToPosition(M,4);if(I){var R=M.getNext(p),S=R&&R.type==1&&R.getName();if(S&&f.$block[S]){if(f[S]['#'])K.moveToElementEditStart(R);else K.moveToElementEditEnd(M);}else if(!R){R=K.fixBlock(true,this.config.enterMode==3?'div':'p');K.moveToElementEditStart(R);}}}F.selectRanges([K]);if(J)this.getSelection().lock();};function v(E){if(!E.checkDirty())setTimeout(function(){E.resetDirty();},0);};var w=d.walker.whitespaces(true),x=d.walker.bookmark(false,true);function y(E){return w(E)&&x(E);};function z(E){return E.type==3&&e.trim(E.getText()).match(/^(?: |\xa0)$/);};function A(E){if(E.isLocked){E.unlock();setTimeout(function(){E.lock();},0);}};function B(E){return E.getOuterHtml().match(m);};w=d.walker.whitespaces(true);function C(E){var F=E.window,G=E.document,H=E.document.getBody(),I=H.getFirst(),J=H.getChildren().count();if(!J||J==1&&I.type==1&&I.hasAttribute('_moz_editor_bogus_node')){v(E);var K=E.element.getDocument(),L=K.getDocumentElement(),M=L.$.scrollTop,N=L.$.scrollLeft,O=G.$.createEvent('KeyEvents');O.initKeyEvent('keypress',true,true,F.$,false,false,false,false,0,32);G.$.dispatchEvent(O);if(M!=L.$.scrollTop||N!=L.$.scrollLeft)K.getWindow().$.scrollTo(N,M);J&&H.getFirst().remove();G.getBody().appendBogus();var P=new d.range(G);P.setStartAt(H,1);P.select();}};function D(E){var F=E.editor,G=E.data.path,H=G.blockLimit,I=E.data.selection,J=I.getRanges()[0],K=F.document.getBody(),L=F.config.enterMode;if(b.gecko){var M=G.block||G.blockLimit,N=M&&M.getLast(y);if(M&&M.isBlockBoundary()&&!(N&&N.type==1&&N.isBlockBoundary())&&!M.is('pre')&&!M.getBogus())M.appendBogus();}if(F.config.autoParagraph!==false&&L!=2&&J.collapsed&&H.getName()=='body'&&!G.block){var O=J.fixBlock(true,F.config.enterMode==3?'div':'p');if(c){var P=O.getFirst(y);P&&z(P)&&P.remove();}if(B(O)){var Q=O.getNext(w);if(Q&&Q.type==1&&!q(Q)){J.moveToElementEditStart(Q);O.remove();}else{Q=O.getPrevious(w);if(Q&&Q.type==1&&!q(Q)){J.moveToElementEditEnd(Q);O.remove();}}}J.select();E.cancel();}var R=new d.range(F.document);R.moveToElementEditEnd(F.document.getBody());var S=new d.elementPath(R.startContainer);if(!S.blockLimit.is('body')){var T;if(L!=2)T=K.append(F.document.createElement(L==1?'p':'div'));else T=K;if(!c)T.appendBogus();}};j.add('wysiwygarea',{requires:['editingblock'],init:function(E){var F=E.config.enterMode!=2&&E.config.autoParagraph!==false?E.config.enterMode==3?'div':'p':false,G=E.lang.editorTitle.replace('%1',E.name),H=E.lang.editorHelp;if(c)G+=', '+H;var I=a.document.getWindow(),J; +E.on('editingBlockReady',function(){var M,N,O,P,Q,R,S,T=b.isCustomDomain(),U=function(X){if(N)N.remove();var Y='document.open();'+(T?'document.domain="'+document.domain+'";':'')+'document.close();';Y=b.air?'javascript:void(0)':c?'javascript:void(function(){'+encodeURIComponent(Y)+'}())':'';var Z=e.getNextId();N=h.createFromHtml('');if(document.location.protocol=='chrome:')a.event.useCapture=true;N.on('load',function(aa){Q=1;aa.removeListener();var ab=N.getFrameDocument();ab.write(X);b.air&&W(ab.getWindow().$);});if(document.location.protocol=='chrome:')a.event.useCapture=false;M.append(h.createFromHtml(''+H+''));M.append(N);if(b.webkit){S=function(){M.setStyle('width','100%');N.hide();N.setSize('width',M.getSize('width'));M.removeStyle('width');N.show();};I.on('resize',S);}};J=e.addFunction(W);var V='';function W(X){if(!Q)return;Q=0;E.fire('ariaWidget',N);var Y=X.document,Z=Y.body,aa=Y.getElementById('cke_actscrpt');aa&&aa.parentNode.removeChild(aa);Z.spellcheck=!E.config.disableNativeSpellChecker;var ab=!E.readOnly;if(c){Z.hideFocus=true;Z.disabled=true;Z.contentEditable=ab;Z.removeAttribute('disabled');}else setTimeout(function(){if(b.gecko&&b.version>=10900||b.opera)Y.$.body.contentEditable=ab;else if(b.webkit)Y.$.body.parentNode.contentEditable=ab;else Y.$.designMode=ab?'off':'on';},0);ab&&b.gecko&&e.setTimeout(C,0,null,E);X=E.window=new d.window(X);Y=E.document=new g(Y);ab&&Y.on('dblclick',function(ag){var ah=ag.data.getTarget(),ai={element:ah,dialog:''};E.fire('doubleclick',ai);ai.dialog&&E.openDialog(ai.dialog);});c&&Y.on('click',function(ag){var ah=ag.data.getTarget();if(ah.is('input')){var ai=ah.getAttribute('type');if(ai=='submit'||ai=='reset')ag.data.preventDefault();}});if(!(c||b.opera))Y.on('mousedown',function(ag){var ah=ag.data.getTarget();if(ah.is('img','hr','input','textarea','select'))E.getSelection().selectElement(ah);});if(b.gecko)Y.on('mouseup',function(ag){if(ag.data.$.button==2){var ah=ag.data.getTarget();if(!ah.getOuterHtml().replace(m,'')){var ai=new d.range(Y);ai.moveToElementEditStart(ah);ai.select(true);}}}); +Y.on('click',function(ag){ag=ag.data;if(ag.getTarget().is('a')&&ag.$.button!=2)ag.preventDefault();});if(b.webkit){Y.on('mousedown',function(){ad=1;});Y.on('click',function(ag){if(ag.data.getTarget().is('input','select'))ag.data.preventDefault();});Y.on('mouseup',function(ag){if(ag.data.getTarget().is('input','textarea'))ag.data.preventDefault();});}var ac=c?N:X;ac.on('blur',function(){E.focusManager.blur();});var ad;ac.on('focus',function(){var ag=E.document;if(b.gecko||b.opera)ag.getBody().focus();else if(b.webkit)if(!ad){E.document.getDocumentElement().focus();ad=1;}E.focusManager.focus();});var ae=E.keystrokeHandler;ae.blockedKeystrokes[8]=!ab;ae.attach(Y);Y.getDocumentElement().addClass(Y.$.compatMode);E.on('key',function(ag){if(E.mode!='wysiwyg')return;var ah=ag.data.keyCode;if(ah in {8:1,46:1}){var ai=E.getSelection(),aj=ai.getSelectedElement(),ak=ai.getRanges()[0],al=new d.elementPath(ak.startContainer),am,an,ao,ap=ah==8;if(aj){E.fire('saveSnapshot');ak.moveToPosition(aj,3);aj.remove();ak.select();E.fire('saveSnapshot');ag.cancel();}else if(ak.collapsed)if((am=al.block)&&ak[ap?'checkStartOfBlock':'checkEndOfBlock']()&&(ao=am[ap?'getPrevious':'getNext'](n))&&ao.is('table')){E.fire('saveSnapshot');if(ak[ap?'checkEndOfBlock':'checkStartOfBlock']())am.remove();ak['moveToElementEdit'+(ap?'End':'Start')](ao);ak.select();E.fire('saveSnapshot');ag.cancel();}else if(al.blockLimit.is('td')&&(an=al.blockLimit.getAscendant('table'))&&ak.checkBoundaryOfElement(an,ap?1:2)&&(ao=an[ap?'getPrevious':'getNext'](n))){E.fire('saveSnapshot');ak['moveToElementEdit'+(ap?'End':'Start')](ao);if(ak.checkStartOfBlock()&&ak.checkEndOfBlock())ao.remove();else ak.select();E.fire('saveSnapshot');ag.cancel();}}if(ah==33||ah==34)if(b.gecko){var aq=Y.getBody();if(X.$.innerHeight>aq.$.offsetHeight){ak=new d.range(Y);ak[ah==33?'moveToElementEditStart':'moveToElementEditEnd'](aq);ak.select();ag.cancel();}}});if(c&&Y.$.compatMode=='CSS1Compat'){var af={33:1,34:1};Y.on('keydown',function(ag){if(ag.data.getKeystroke() in af)setTimeout(function(){E.getSelection().scrollIntoView();},0);});}if(c&&E.config.enterMode!=1)Y.on('selectionchange',function(){var ag=Y.getBody(),ah=E.getSelection(),ai=ah&&ah.getRanges()[0];if(ai&&ag.getHtml().match(/^

     <\/p>$/i)&&ai.startContainer.equals(ag))setTimeout(function(){ai=E.getSelection().getRanges()[0];if(!ai.startContainer.equals('body')){ag.getFirst().remove(1);ai.moveToElementEditEnd(ag);ai.select(1);}},0);});if(E.contextMenu)E.contextMenu.addTarget(Y,E.config.browserContextMenuOnCtrl!==false); +setTimeout(function(){E.fire('contentDom');if(R){E.mode='wysiwyg';E.fire('mode',{previousMode:E._.previousMode});R=false;}O=false;if(P){E.focus();P=false;}setTimeout(function(){E.fire('dataReady');},0);try{E.document.$.execCommand('2D-position',false,true);}catch(ag){}try{E.document.$.execCommand('enableInlineTableEditing',false,!E.config.disableNativeTableHandles);}catch(ah){}if(E.config.disableObjectResizing)try{E.document.$.execCommand('enableObjectResizing',false,false);}catch(ai){E.document.getBody().on(c?'resizestart':'resize',function(aj){aj.data.preventDefault();});}if(c)setTimeout(function(){if(E.document){var aj=E.document.$.body;aj.runtimeStyle.marginBottom='0px';aj.runtimeStyle.marginBottom='';}},1000);},0);};E.addMode('wysiwyg',{load:function(X,Y,Z){M=X;if(c&&b.quirks)X.setStyle('position','relative');E.mayBeDirty=true;R=true;if(Z)this.loadSnapshotData(Y);else this.loadData(Y);},loadData:function(X){O=true;E._.dataStore={id:1};var Y=E.config,Z=Y.fullPage,aa=Y.docType,ab='';!Z&&(ab=e.buildStyleHtml(E.config.contentsCss)+ab);var ac=Y.baseHref?'':'';if(Z)X=X.replace(/]*>/i,function(ad){E.docType=aa=ad;return '';}).replace(/<\?xml\s[^\?]*\?>/i,function(ad){E.xmlDeclaration=ad;return '';});if(E.dataProcessor)X=E.dataProcessor.toHtml(X,F);if(Z){if(!/]/.test(X))X=''+X;if(!/]/.test(X))X=''+X+'';if(!/]/.test(X))X=X.replace(/]*>/,'$&');else if(!/]/.test(X))X=X.replace(/]*>/,'$&');ac&&(X=X.replace(//,'$&'+ac));X=X.replace(/<\/head\s*>/,ab+'$&');X=aa+X;}else X=Y.docType+''+''+''+G+''+ac+ab+''+''+X+'';if(b.gecko)X=X.replace(/
    (?=\s*<\/(:?html|body)>)/,'$&
    ');X+=V;this.onDispose();U(X);},getData:function(){var X=E.config,Y=X.fullPage,Z=Y&&E.docType,aa=Y&&E.xmlDeclaration,ab=N.getFrameDocument(),ac=Y?ab.getDocumentElement().getOuterHtml():ab.getBody().getHtml();if(b.gecko)ac=ac.replace(/
    (?=\s*(:?$|<\/body>))/,'');if(E.dataProcessor)ac=E.dataProcessor.toDataFormat(ac,F);if(X.ignoreEmptyParagraph)ac=ac.replace(m,function(ad,ae){return ae;});if(aa)ac=aa+'\n'+ac;if(Z)ac=Z+'\n'+ac; +return ac;},getSnapshotData:function(){return N.getFrameDocument().getBody().getHtml();},loadSnapshotData:function(X){N.getFrameDocument().getBody().setHtml(X);},onDispose:function(){if(!E.document)return;E.document.getDocumentElement().clearCustomData();E.document.getBody().clearCustomData();E.window.clearCustomData();E.document.clearCustomData();N.clearCustomData();N.remove();},unload:function(X){this.onDispose();if(S)I.removeListener('resize',S);E.window=E.document=N=M=P=null;E.fire('contentDomUnload');},focus:function(){var X=E.window;if(O)P=true;else if(X){var Y=E.getSelection(),Z=Y&&Y.getNative();if(Z&&Z.type=='Control')return;b.air?setTimeout(function(){X.focus();},0):X.focus();E.selectionChange();}}});E.on('insertHtml',r(s),null,null,20);E.on('insertElement',r(u),null,null,20);E.on('insertText',r(t),null,null,20);E.on('selectionChange',function(X){if(E.readOnly)return;var Y=E.getSelection();if(Y&&!Y.isLocked){var Z=E.checkDirty();E.fire('saveSnapshot',{contentOnly:1});D.call(this,X);E.fire('updateSnapshot');!Z&&E.resetDirty();}},null,null,1);});E.on('contentDom',function(){var M=E.document.getElementsByTag('title').getItem(0);M.data('cke-title',E.document.$.title);c&&(E.document.$.title=G);});E.on('readOnly',function(){if(E.mode=='wysiwyg'){var M=E.getMode();M.loadData(M.getData());}});if(a.document.$.documentMode>=8){E.addCss('html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}');var K=[];for(var L in f.$removeEmpty)K.push('html.CSS1Compat '+L+'[contenteditable=false]');E.addCss(K.join(',')+'{ display:inline-block;}');}else if(b.gecko){E.addCss('html { height: 100% !important; }');E.addCss('img:-moz-broken { -moz-force-broken-image-icon : 1;\tmin-width : 24px; min-height : 24px; }');}E.addCss('html {\t_overflow-y: scroll; cursor: text;\t*cursor:auto;}');E.addCss('img, input, textarea { cursor: default;}');E.on('insertElement',function(M){var N=M.data;if(N.type==1&&(N.is('input')||N.is('textarea'))){var O=N.getAttribute('contenteditable')=='false';if(!O){N.data('cke-editable',N.hasAttribute('contenteditable')?'true':'1');N.setAttribute('contenteditable',false);}}});}});if(b.gecko)(function(){var E=document.body;if(!E)window.addEventListener('load',arguments.callee,false);else{var F=E.getAttribute('onpageshow');E.setAttribute('onpageshow',(F?F+';':'')+'event.persisted && (function(){'+'var allInstances = CKEDITOR.instances, editor, doc;'+'for ( var i in allInstances )'+'{'+'\teditor = allInstances[ i ];'+'\tdoc = editor.document;'+'\tif ( doc )'+'\t{'+'\t\tdoc.$.designMode = "off";'+'\t\tdoc.$.designMode = "on";'+'\t}'+'}'+'})();'); +}})();})();i.disableObjectResizing=false;i.disableNativeTableHandles=true;i.disableNativeSpellChecker=true;i.ignoreEmptyParagraph=true;j.add('wsc',{requires:['dialog'],init:function(m){var n='checkspell',o=m.addCommand(n,new a.dialogCommand(n));o.modes={wysiwyg:!b.opera&&!b.air&&document.domain==window.location.hostname};m.ui.addButton('SpellChecker',{label:m.lang.spellCheck.toolbar,command:n});a.dialog.add(n,this.path+'dialogs/wsc.js');}});i.wsc_customerId=i.wsc_customerId||'1:ua3xw1-2XyGJ3-GWruD3-6OFNT1-oXcuB1-nR6Bp4-hgQHc-EcYng3-sdRXG3-NOfFk';i.wsc_customLoaderScript=i.wsc_customLoaderScript||null;a.DIALOG_RESIZE_NONE=0;a.DIALOG_RESIZE_WIDTH=1;a.DIALOG_RESIZE_HEIGHT=2;a.DIALOG_RESIZE_BOTH=3;(function(){var m=e.cssLength;function n(R){return!!this._.tabs[R][0].$.offsetHeight;};function o(){var V=this;var R=V._.currentTabId,S=V._.tabIdList.length,T=e.indexOf(V._.tabIdList,R)+S;for(var U=T-1;U>T-S;U--){if(n.call(V,V._.tabIdList[U%S]))return V._.tabIdList[U%S];}return null;};function p(){var V=this;var R=V._.currentTabId,S=V._.tabIdList.length,T=e.indexOf(V._.tabIdList,R);for(var U=T+1;U1){ah._.tabBarMode=true; +ah._.tabs[ah._.currentTabId][0].focus();Z=1;}else if((as==37||as==39)&&ah._.tabBarMode){aw=as==(at?39:37)?o.call(ah):p.call(ah);ah.selectPage(aw);ah._.tabs[aw][0].focus();Z=1;}else if((as==13||as==32)&&ah._.tabBarMode){ay.selectPage(ay._.currentTabId);ay._.tabBarMode=false;ay._.currentFocusIndex=-1;ak(1);Z=1;}else if(as==13){var ax=ar.data.getTarget();if(!ax.is('a','button','select','textarea')&&(!ax.is('input')||ax.$.type!='button')){au=ay.getButton('ok');au&&e.setTimeout(au.click,0,au);Z=1;}aa=1;}else if(as==27){au=ay.getButton('cancel');if(au)e.setTimeout(au.click,0,au);else if(ay.fire('cancel',{hide:true}).hide!==false)ay.hide();aa=1;}else return;am(ar);};function am(ar){if(Z)ar.data.preventDefault(1);else if(aa)ar.data.stopPropagation();};var an=this._.element;this.on('show',function(){an.on('keydown',al,this);if(b.opera||b.gecko)an.on('keypress',am,this);});this.on('hide',function(){an.removeListener('keydown',al);if(b.opera||b.gecko)an.removeListener('keypress',am);ai(function(ar){s.apply(ar);});});this.on('iframeAdded',function(ar){var as=new g(ar.data.iframe.$.contentWindow.document);as.on('keydown',al,this,null,0);});this.on('show',function(){var av=this;aj();if(R.config.dialog_startupFocusTab&&ah._.pageCount>1){ah._.tabBarMode=true;ah._.tabs[ah._.currentTabId][0].focus();}else if(!av._.hasFocus){av._.currentFocusIndex=-1;if(T.onFocus){var ar=T.onFocus.call(av);ar&&ar.focus();}else ak(1);if(av._.editor.mode=='wysiwyg'&&c){var as=R.document.$.selection,at=as.createRange();if(at)if(at.parentElement&&at.parentElement().ownerDocument==R.document.$||at.item&&at.item(0).ownerDocument==R.document.$){var au=document.body.createTextRange();au.moveToElementText(av.getElement().getFirst().$);au.collapse(true);au.select();}}}},this,null,4294967295);if(b.ie6Compat)this.on('load',function(ar){var as=this.getElement(),at=as.getFirst();at.remove();at.appendTo(as);},this);B(this);C(this);new d.text(T.title,a.document).appendTo(this.parts.title);for(Y=0;Y0?S:0)+'px'};aa[V?'right':'left']=(R>0?R:0)+'px';U.setStyles(aa);T&&(ab._.moved=1);},getPosition:function(){return e.extend({},this._.position);},show:function(){var R=this._.element,S=this.definition;if(!(R.getParent()&&R.getParent().equals(a.document.getBody())))R.appendTo(a.document.getBody());else R.setStyle('display','block');if(b.gecko&&b.version<10900){var T=this.parts.dialog;T.setStyle('position','absolute');setTimeout(function(){T.setStyle('position','fixed');},0);}this.resize(this._.contentSize&&this._.contentSize.width||S.width||S.minWidth,this._.contentSize&&this._.contentSize.height||S.height||S.minHeight);this.reset();this.selectPage(this.definition.contents[0].id);if(a.dialog._.currentZIndex===null)a.dialog._.currentZIndex=this._.editor.config.baseFloatZIndex; +this._.element.getFirst().setStyle('z-index',a.dialog._.currentZIndex+=10);if(a.dialog._.currentTop===null){a.dialog._.currentTop=this;this._.parentDialog=null;H(this._.editor);}else{this._.parentDialog=a.dialog._.currentTop;var U=this._.parentDialog.getElement().getFirst();U.$.style.zIndex-=Math.floor(this._.editor.config.baseFloatZIndex/2);a.dialog._.currentTop=this;}R.on('keydown',L);R.on(b.opera?'keypress':'keyup',M);this._.hasFocus=false;e.setTimeout(function(){this.layout();u(this);this.parts.dialog.setStyle('visibility','');this.fireOnce('load',{});k.fire('ready',this);this.fire('show',{});this._.editor.fire('dialogShow',this);this.foreach(function(V){V.setInitValue&&V.setInitValue();});},100,this);},layout:function(){var X=this;var R=X.parts.dialog,S=X.getSize(),T=a.document.getWindow(),U=T.getViewPaneSize(),V=(U.width-S.width)/2,W=(U.height-S.height)/2;if(!b.ie6Compat)if(S.height+(W>0?W:0)>U.height||S.width+(V>0?V:0)>U.width)R.setStyle('position','absolute');else R.setStyle('position','fixed');X.move(X._.moved?X._.position.x:V,X._.moved?X._.position.y:W);},foreach:function(R){var U=this;for(var S in U._.contents)for(var T in U._.contents[S])R.call(U,U._.contents[S][T]);return U;},reset:(function(){var R=function(S){if(S.reset)S.reset(1);};return function(){this.foreach(R);return this;};})(),setupContent:function(){var R=arguments;this.foreach(function(S){if(S.setup)S.setup.apply(S,R);});},commitContent:function(){var R=arguments;this.foreach(function(S){if(c&&this._.currentFocusIndex==S.focusIndex)S.getInputElement().$.blur();if(S.commit)S.commit.apply(S,R);});},hide:function(){if(!this.parts.dialog.isVisible())return;this.fire('hide',{});this._.editor.fire('dialogHide',this);this.selectPage(this._.tabIdList[0]);var R=this._.element;R.setStyle('display','none');this.parts.dialog.setStyle('visibility','hidden');O(this);while(a.dialog._.currentTop!=this)a.dialog._.currentTop.hide();if(!this._.parentDialog)I();else{var S=this._.parentDialog.getElement().getFirst();S.setStyle('z-index',parseInt(S.$.style.zIndex,10)+Math.floor(this._.editor.config.baseFloatZIndex/2));}a.dialog._.currentTop=this._.parentDialog;if(!this._.parentDialog){a.dialog._.currentZIndex=null;R.removeListener('keydown',L);R.removeListener(b.opera?'keypress':'keyup',M);var T=this._.editor;T.focus();if(T.mode=='wysiwyg'&&c){var U=T.getSelection();U&&U.unlock(true);}}else a.dialog._.currentZIndex-=10;delete this._.parentDialog;this.foreach(function(V){V.resetInitValue&&V.resetInitValue(); +});},addPage:function(R){var ad=this;var S=[],T=R.label?' title="'+e.htmlEncode(R.label)+'"':'',U=R.elements,V=a.dialog._.uiElementBuilders.vbox.build(ad,{type:'vbox',className:'cke_dialog_page_contents',children:R.elements,expand:!!R.expand,padding:R.padding,style:R.style||'width: 100%;height:100%'},S),W=h.createFromHtml(S.join(''));W.setAttribute('role','tabpanel');var X=b,Y='cke_'+R.id+'_'+e.getNextNumber(),Z=h.createFromHtml(['0?' cke_last':'cke_first',T,!!R.hidden?' style="display:none"':'',' id="',Y,'"',X.gecko&&X.version>=10900&&!X.hc?'':' href="javascript:void(0)"',' tabIndex="-1"',' hidefocus="true"',' role="tab">',R.label,''].join(''));W.setAttribute('aria-labelledby',Y);ad._.tabs[R.id]=[Z,W];ad._.tabIdList.push(R.id);!R.hidden&&ad._.pageCount++;ad._.lastTab=Z;ad.updateStyle();var aa=ad._.contents[R.id]={},ab,ac=V.getChild();while(ab=ac.shift()){aa[ab.id]=ab;if(typeof ab.getChild=='function')ac.push.apply(ac,ab.getChild());}W.setAttribute('name',R.id);W.appendTo(ad.parts.contents);Z.unselectable();ad.parts.tabs.append(Z);if(R.accessKey){N(ad,ad,'CTRL+'+R.accessKey,Q,P);ad._.accessKeyMap['CTRL+'+R.accessKey]=R.id;}},selectPage:function(R){if(this._.currentTabId==R)return;if(this.fire('selectPage',{page:R,currentPage:this._.currentTabId})===true)return;for(var S in this._.tabs){var T=this._.tabs[S][0],U=this._.tabs[S][1];if(S!=R){T.removeClass('cke_dialog_tab_selected');U.hide();}U.setAttribute('aria-hidden',S!=R);}var V=this._.tabs[R];V[0].addClass('cke_dialog_tab_selected');if(b.ie6Compat||b.ie7Compat){q(V[1]);V[1].show();setTimeout(function(){q(V[1],1);},0);}else V[1].show();this._.currentTabId=R;this._.currentTabIndex=e.indexOf(this._.tabIdList,R);},updateStyle:function(){this.parts.dialog[(this._.pageCount===1?'add':'remove')+'Class']('cke_single_page');},hidePage:function(R){var T=this;var S=T._.tabs[R]&&T._.tabs[R][0];if(!S||T._.pageCount==1||!S.isVisible())return;else if(R==T._.currentTabId)T.selectPage(o.call(T));S.hide();T._.pageCount--;T.updateStyle();},showPage:function(R){var T=this;var S=T._.tabs[R]&&T._.tabs[R][0];if(!S)return;S.show();T._.pageCount++;T.updateStyle();},getElement:function(){return this._.element;},getName:function(){return this._.name;},getContentElement:function(R,S){var T=this._.contents[R];return T&&T[S];},getValueOf:function(R,S){return this.getContentElement(R,S).getValue();},setValueOf:function(R,S,T){return this.getContentElement(R,S).setValue(T);},getButton:function(R){return this._.buttons[R]; +},click:function(R){return this._.buttons[R].click();},disableButton:function(R){return this._.buttons[R].disable();},enableButton:function(R){return this._.buttons[R].enable();},getPageCount:function(){return this._.pageCount;},getParentEditor:function(){return this._.editor;},getSelectedElement:function(){return this.getParentEditor().getSelection().getSelectedElement();},addFocusable:function(R,S){var U=this;if(typeof S=='undefined'){S=U._.focusList.length;U._.focusList.push(new t(U,R,S));}else{U._.focusList.splice(S,0,new t(U,R,S));for(var T=S+1;Tac.width-ab.width-W)ah=ac.width-ab.width+(V.lang.dir=='rtl'?0:X[1]);else ah=T.x;if(T.y+X[0]ac.height-ab.height-W)ai=ac.height-ab.height+X[2];else ai=T.y;R.move(ah,ai,1);aa.data.preventDefault();};function Z(aa){a.document.removeListener('mousemove',Y);a.document.removeListener('mouseup',Z);if(b.ie6Compat){var ab=F.getChild(0).getFrameDocument();ab.removeListener('mousemove',Y);ab.removeListener('mouseup',Z);}};R.parts.title.on('mousedown',function(aa){S={x:aa.data.$.screenX,y:aa.data.$.screenY};a.document.on('mousemove',Y);a.document.on('mouseup',Z);T=R.getPosition();if(b.ie6Compat){var ab=F.getChild(0).getFrameDocument();ab.on('mousemove',Y);ab.on('mouseup',Z);}aa.data.preventDefault();},R);};function C(R){var S=R.definition,T=S.resizable;if(T==0)return;var U=R.getParentEditor(),V,W,X,Y,Z,aa,ab=e.addFunction(function(ae){Z=R.getSize();var af=R.parts.contents,ag=af.$.getElementsByTagName('iframe').length;if(ag){aa=h.createFromHtml('

    ');af.append(aa);}W=Z.height-R.parts.contents.getSize('height',!(b.gecko||b.opera||c&&b.quirks));V=Z.width-R.parts.contents.getSize('width',1);Y={x:ae.screenX,y:ae.screenY};X=a.document.getWindow().getViewPaneSize();a.document.on('mousemove',ac);a.document.on('mouseup',ad);if(b.ie6Compat){var ah=F.getChild(0).getFrameDocument();ah.on('mousemove',ac);ah.on('mouseup',ad);}ae.preventDefault&&ae.preventDefault();});R.on('load',function(){var ae='';if(T==1)ae=' cke_resizer_horizontal';else if(T==2)ae=' cke_resizer_vertical';var af=h.createFromHtml('
    '); +R.parts.footer.append(af,1);});U.on('destroy',function(){e.removeFunction(ab);});function ac(ae){var af=U.lang.dir=='rtl',ag=(ae.data.$.screenX-Y.x)*(af?-1:1),ah=ae.data.$.screenY-Y.y,ai=Z.width,aj=Z.height,ak=ai+ag*(R._.moved?1:2),al=aj+ah*(R._.moved?1:2),am=R._.element.getFirst(),an=af&&am.getComputedStyle('right'),ao=R.getPosition();if(ao.y+al>X.height)al=X.height-ao.y;if((af?an:ao.x)+ak>X.width)ak=X.width-(af?an:ao.x);if(T==1||T==3)ai=Math.max(S.minWidth||0,ak-V);if(T==2||T==3)aj=Math.max(S.minHeight||0,al-W);R.resize(ai,aj);if(!R._.moved)R.layout();ae.data.preventDefault();};function ad(){a.document.removeListener('mouseup',ad);a.document.removeListener('mousemove',ac);if(aa){aa.remove();aa=null;}if(b.ie6Compat){var ae=F.getChild(0).getFrameDocument();ae.removeListener('mouseup',ad);ae.removeListener('mousemove',ac);}};};var D,E={},F;function G(R){R.data.preventDefault(1);};function H(R){var S=a.document.getWindow(),T=R.config,U=T.dialog_backgroundCoverColor||'white',V=T.dialog_backgroundCoverOpacity,W=T.baseFloatZIndex,X=e.genKey(U,V,W),Y=E[X];if(!Y){var Z=['
    '];if(b.ie6Compat){var aa=b.isCustomDomain(),ab="";Z.push('');}Z.push('
    ');Y=h.createFromHtml(Z.join(''));Y.setOpacity(V!=undefined?V:0.5);Y.on('keydown',G);Y.on('keypress',G);Y.on('keyup',G);Y.appendTo(a.document.getBody());E[X]=Y;}else Y.show();F=Y;var ac=function(){var af=S.getViewPaneSize();Y.setStyles({width:af.width+'px',height:af.height+'px'});},ad=function(){var af=S.getScrollPosition(),ag=a.dialog._.currentTop;Y.setStyles({left:af.x+'px',top:af.y+'px'});if(ag)do{var ah=ag.getPosition();ag.move(ah.x,ah.y);}while(ag=ag._.parentDialog)};D=ac;S.on('resize',ac);ac();if(!(b.mac&&b.webkit))Y.focus();if(b.ie6Compat){var ae=function(){ad();arguments.callee.prevScrollHandler.apply(this,arguments);};S.$.setTimeout(function(){ae.prevScrollHandler=window.onscroll||(function(){}); +window.onscroll=ae;},0);ad();}};function I(){if(!F)return;var R=a.document.getWindow();F.hide();R.removeListener('resize',D);if(b.ie6Compat)R.$.setTimeout(function(){var S=window.onscroll&&window.onscroll.prevScrollHandler;window.onscroll=S||null;},0);D=null;};function J(){for(var R in E)E[R].remove();E={};};var K={},L=function(R){var S=R.data.$.ctrlKey||R.data.$.metaKey,T=R.data.$.altKey,U=R.data.$.shiftKey,V=String.fromCharCode(R.data.$.keyCode),W=K[(S?'CTRL+':'')+(T?'ALT+':'')+(U?'SHIFT+':'')+V];if(!W||!W.length)return;W=W[W.length-1];W.keydown&&W.keydown.call(W.uiElement,W.dialog,W.key);R.data.preventDefault();},M=function(R){var S=R.data.$.ctrlKey||R.data.$.metaKey,T=R.data.$.altKey,U=R.data.$.shiftKey,V=String.fromCharCode(R.data.$.keyCode),W=K[(S?'CTRL+':'')+(T?'ALT+':'')+(U?'SHIFT+':'')+V];if(!W||!W.length)return;W=W[W.length-1];if(W.keyup){W.keyup.call(W.uiElement,W.dialog,W.key);R.data.preventDefault();}},N=function(R,S,T,U,V){var W=K[T]||(K[T]=[]);W.push({uiElement:R,dialog:S,key:T,keyup:V||R.accessKeyUp,keydown:U||R.accessKeyDown});},O=function(R){for(var S in K){var T=K[S];for(var U=T.length-1;U>=0;U--){if(T[U].dialog==R||T[U].uiElement==R)T.splice(U,1);}if(T.length===0)delete K[S];}},P=function(R,S){if(R._.accessKeyMap[S])R.selectPage(R._.accessKeyMap[S]);},Q=function(R,S){};(function(){k.dialog={uiElement:function(R,S,T,U,V,W,X){if(arguments.length<4)return;var Y=(U.call?U(S):U)||'div',Z=['<',Y,' '],aa=(V&&V.call?V(S):V)||{},ab=(W&&W.call?W(S):W)||{},ac=(X&&X.call?X.call(this,R,S):X)||'',ad=this.domId=ab.id||e.getNextId()+'_uiElement',ae=this.id=S.id,af;ab.id=ad;var ag={};if(S.type)ag['cke_dialog_ui_'+S.type]=1;if(S.className)ag[S.className]=1;if(S.disabled)ag.cke_disabled=1;var ah=ab['class']&&ab['class'].split?ab['class'].split(' '):[];for(af=0;af=0;af--){if(aj[af]==='')aj.splice(af,1);}if(aj.length>0)ab.style=(ab.style?ab.style+'; ':'')+aj.join('; ');for(af in ab)Z.push(af+'="'+e.htmlEncode(ab[af])+'" ');Z.push('>',ac,'');T.push(Z.join(''));(this._||(this._={})).dialog=R;if(typeof S.isChanged=='boolean')this.isChanged=function(){return S.isChanged;};if(typeof S.isChanged=='function')this.isChanged=S.isChanged; +if(typeof S.setValue=='function')this.setValue=e.override(this.setValue,function(am){return function(an){am.call(this,S.setValue.call(this,an));};});if(typeof S.getValue=='function')this.getValue=e.override(this.getValue,function(am){return function(){return S.getValue.call(this,am.call(this));};});a.event.implementOn(this);this.registerEvents(S);if(this.accessKeyUp&&this.accessKeyDown&&S.accessKey)N(this,R,'CTRL+'+S.accessKey);var al=this;R.on('load',function(){var am=al.getInputElement();if(am){var an=al.type in {checkbox:1,ratio:1}&&c&&b.version<8?'cke_dialog_ui_focused':'';am.on('focus',function(){R._.tabBarMode=false;R._.hasFocus=true;al.fire('focus');an&&this.addClass(an);});am.on('blur',function(){al.fire('blur');an&&this.removeClass(an);});}});if(this.keyboardFocusable){this.tabIndex=S.tabIndex||0;this.focusIndex=R._.focusList.push(this)-1;this.on('focus',function(){R._.currentFocusIndex=al.focusIndex;});}e.extend(this,S);},hbox:function(R,S,T,U,V){if(arguments.length<4)return;this._||(this._={});var W=this._.children=S,X=V&&V.widths||null,Y=V&&V.height||null,Z={},aa,ab=function(){var ad=[''];for(aa=0;aa0)ad.push('style="'+af.join('; ')+'" ');ad.push('>',T[aa],'');}ad.push('');return ad.join('');},ac={role:'presentation'};V&&V.align&&(ac.align=V.align);k.dialog.uiElement.call(this,R,V||{type:'hbox'},U,'table',Z,ac,ab);},vbox:function(R,S,T,U,V){if(arguments.length<3)return;this._||(this._={});var W=this._.children=S,X=V&&V.width||null,Y=V&&V.heights||null,Z=function(){var aa=['');for(var ab=0;ab');}aa.push('
    0)aa.push('style="',ac.join('; '),'" ');aa.push(' class="cke_dialog_ui_vbox_child">',T[ab],'
    ');return aa.join('');};k.dialog.uiElement.call(this,R,V||{type:'vbox'},U,'div',null,{role:'presentation'},Z);}};})();k.dialog.uiElement.prototype={getElement:function(){return a.document.getById(this.domId);},getInputElement:function(){return this.getElement();},getDialog:function(){return this._.dialog;},setValue:function(R,S){this.getInputElement().setValue(R);!S&&this.fire('change',{value:R});return this;},getValue:function(){return this.getInputElement().getValue();},isChanged:function(){return false;},selectParentTab:function(){var U=this;var R=U.getInputElement(),S=R,T;while((S=S.getParent())&&S.$.className.search('cke_dialog_page_contents')==-1){}if(!S)return U;T=S.getAttribute('name');if(U._.dialog._.currentTabId!=T)U._.dialog.selectPage(T);return U;},focus:function(){this.selectParentTab().getInputElement().focus();return this;},registerEvents:function(R){var S=/^on([A-Z]\w+)/,T,U=function(W,X,Y,Z){X.on('load',function(){W.getInputElement().on(Y,Z,W);});};for(var V in R){if(!(T=V.match(S)))continue;if(this.eventProcessors[V])this.eventProcessors[V].call(this,this._.dialog,R[V]);else U(this,this._.dialog,T[1].toLowerCase(),R[V]);}return this;},eventProcessors:{onLoad:function(R,S){R.on('load',S,this);},onShow:function(R,S){R.on('show',S,this);},onHide:function(R,S){R.on('hide',S,this);}},accessKeyDown:function(R,S){this.focus();},accessKeyUp:function(R,S){},disable:function(){var R=this.getElement(),S=this.getInputElement();S.setAttribute('disabled','true');R.addClass('cke_disabled');},enable:function(){var R=this.getElement(),S=this.getInputElement();S.removeAttribute('disabled');R.removeClass('cke_disabled');},isEnabled:function(){return!this.getElement().hasClass('cke_disabled');},isVisible:function(){return this.getInputElement().isVisible();},isFocusable:function(){if(!this.isEnabled()||!this.isVisible())return false;return true;}};k.dialog.hbox.prototype=e.extend(new k.dialog.uiElement(),{getChild:function(R){var S=this;if(arguments.length<1)return S._.children.concat();if(!R.splice)R=[R];if(R.length<2)return S._.children[R[0]];else return S._.children[R[0]]&&S._.children[R[0]].getChild?S._.children[R[0]].getChild(R.slice(1,R.length)):null;}},true);k.dialog.vbox.prototype=new k.dialog.hbox(); +(function(){var R={build:function(S,T,U){var V=T.children,W,X=[],Y=[];for(var Z=0;Z',T||U.name,'');return V.join('');}};a.style.getStyleText=function(T){var U=T._ST;if(U)return U;U=T.styles;var V=T.attributes&&T.attributes.style||'',W='';if(V.length)V=V.replace(o,';');for(var X in U){var Y=U[X],Z=(X+':'+Y).replace(o,';');if(Y=='inherit')W+=Z;else V+=Z;}if(V.length)V=P(V);V+=W;return T._ST=V;};function s(T){var U,V;while(T=T.getParent()){if(T.getName()=='body')break;if(T.getAttribute('data-nostyle'))U=T;else if(!V){var W=T.getAttribute('contentEditable');if(W=='false')U=T;else if(W=='true')V=1;}}return U;};function t(T){var ay=this;var U=T.document;if(T.collapsed){var V=J(ay,U);T.insertNode(V);T.moveToPosition(V,2);return;}var W=ay.element,X=ay._.definition,Y,Z=X.ignoreReadonly,aa=Z||X.includeReadonly;if(aa==undefined)aa=U.getCustomData('cke_includeReadonly');var ab=f[W]||(Y=true,f.span);T.enlarge(1,1);T.trim();var ac=T.createBookmark(),ad=ac.startNode,ae=ac.endNode,af=ad,ag;if(!Z){var ah=s(ad),ai=s(ae);if(ah)af=ah.getNextSourceNode(true);if(ai)ae=ai;}if(af.getPosition(ae)==2)af=0;while(af){var aj=false;if(af.equals(ae)){af=null;aj=true;}else{var ak=af.type,al=ak==1?af.getName():null,am=al&&af.getAttribute('contentEditable')=='false',an=al&&af.getAttribute('data-nostyle');if(al&&af.data('cke-bookmark')){af=af.getNextSourceNode(true);continue;}if(!al||ab[al]&&!an&&(!am||aa)&&(af.getPosition(ae)|4|0|8)==4+0+8&&(!X.childRule||X.childRule(af))){var ao=af.getParent(); +if(ao&&((ao.getDtd()||f.span)[W]||Y)&&(!X.parentRule||X.parentRule(ao))){if(!ag&&(!al||!f.$removeEmpty[al]||(af.getPosition(ae)|4|0|8)==4+0+8)){ag=new d.range(U);ag.setStartBefore(af);}if(ak==3||am||ak==1&&!af.getChildCount()){var ap=af,aq;while((aj=!ap.getNext(q))&&(aq=ap.getParent(),ab[aq.getName()])&&(aq.getPosition(ad)|2|0|8)==2+0+8&&(!X.childRule||X.childRule(aq)))ap=aq;ag.setEndAfter(ap);}}else aj=true;}else aj=true;af=af.getNextSourceNode(an||am);}if(aj&&ag&&!ag.collapsed){var ar=J(ay,U),as=ar.hasAttributes(),at=ag.getCommonAncestor(),au={styles:{},attrs:{},blockedStyles:{},blockedAttrs:{}},av,aw,ax;while(ar&&at){if(at.getName()==W){for(av in X.attributes){if(au.blockedAttrs[av]||!(ax=at.getAttribute(aw)))continue;if(ar.getAttribute(av)==ax)au.attrs[av]=1;else au.blockedAttrs[av]=1;}for(aw in X.styles){if(au.blockedStyles[aw]||!(ax=at.getStyle(aw)))continue;if(ar.getStyle(aw)==ax)au.styles[aw]=1;else au.blockedStyles[aw]=1;}}at=at.getParent();}for(av in au.attrs)ar.removeAttribute(av);for(aw in au.styles)ar.removeStyle(aw);if(as&&!ar.hasAttributes())ar=null;if(ar){ag.extractContents().appendTo(ar);G(ay,ar);ag.insertNode(ar);ar.mergeSiblings();if(!c)ar.$.normalize();}else{ar=new h('span');ag.extractContents().appendTo(ar);ag.insertNode(ar);G(ay,ar);ar.remove(true);}ag=null;}}T.moveToBookmark(ac);T.shrink(2);};function u(T){T.enlarge(1,1);var U=T.createBookmark(),V=U.startNode;if(T.collapsed){var W=new d.elementPath(V.getParent()),X;for(var Y=0,Z;Y'+V+'';else T.setHtml(V);U.remove();};function B(T){var U=/(\S\s*)\n(?:\s|(]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi,V=T.getName(),W=C(T.getOuterHtml(),U,function(Y,Z,aa){return Z+''+aa+'
    ';}),X=[];W.replace(/([\s\S]*?)<\/pre>/gi,function(Y,Z){X.push(Z);});return X;};function C(T,U,V){var W='',X='';T=T.replace(/(^]+data-cke-bookmark.*?\/span>)|(]+data-cke-bookmark.*?\/span>$)/gi,function(Y,Z,aa){Z&&(W=Z);aa&&(X=aa);return '';});return W+T.replace(U,V)+X;};function D(T,U){var V;if(T.length>1)V=new d.documentFragment(U.getDocument());for(var W=0;W');X=X.replace(/[ \t]{2,}/g,function(Z){return e.repeat(' ',Z.length-1)+' ';});if(V){var Y=U.clone();Y.setHtml(X);V.append(Y);}else U.setHtml(X);}return V||U;};function E(T,U){var V=T.getBogus();V&&V.remove();var W=T.getHtml();W=C(W,/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g,'');W=W.replace(/[ \t\r\n]*(]*>)[ \t\r\n]*/gi,'$1');W=W.replace(/([ \t\n\r]+| )/g,' ');W=W.replace(/]*>/gi,'\n');if(c){var X=T.getDocument().createElement('div');X.append(U);U.$.outerHTML='
    '+W+'
    ';U.copyAttributes(X.getFirst());U=X.getFirst().remove();}else U.setHtml(W);return U;};function F(T,U){var V=T._.definition,W=V.attributes,X=V.styles,Y=N(T)[U.getName()],Z=e.isEmpty(W)&&e.isEmpty(X);for(var aa in W){if((aa=='class'||T._.definition.fullMatch)&&U.getAttribute(aa)!=O(aa,W[aa]))continue;Z=U.hasAttribute(aa);U.removeAttribute(aa);}for(var ab in X){if(T._.definition.fullMatch&&U.getStyle(ab)!=O(ab,X[ab],true))continue;Z=Z||!!U.getStyle(ab);U.removeStyle(ab);}H(U,Y,m[U.getName()]);if(Z)!f.$block[U.getName()]||T._.enterMode==2&&!U.hasAttributes()?I(U):U.renameNode(T._.enterMode==1?'p':'div');};function G(T,U){var V=T._.definition,W=V.attributes,X=V.styles,Y=N(T),Z=U.getElementsByTag(T.element);for(var aa=Z.count();--aa>=0;)F(T,Z.getItem(aa));for(var ab in Y){if(ab!=T.element){Z=U.getElementsByTag(ab);for(aa=Z.count()-1;aa>=0;aa--){var ac=Z.getItem(aa);H(ac,Y[ab]);}}}};function H(T,U,V){var W=U&&U.attributes;if(W)for(var X=0;X0)H+=(F.$.offsetWidth||0)-(F.$.clientWidth||0)+3;H+=4;F.setStyle('width',H+'px');v.element.addClass('cke_frameLoaded');var I=v.element.$.scrollHeight;if(c&&b.quirks&&I>0)I+=(F.$.offsetHeight||0)-(F.$.clientHeight||0)+3;F.setStyle('height',I+'px');u._.currentBlock.element.setStyle('display','none').removeStyle('display');}else F.removeStyle('height');if(A)B-=w.$.offsetWidth;w.setStyle('left',B+'px');var J=u.element,K=J.getWindow(),L=w.$.getBoundingClientRect(),M=K.getViewPaneSize(),N=L.width||L.right-L.left,O=L.height||L.bottom-L.top,P=A?L.right:M.width-L.left,Q=A?M.width-L.right:L.left;if(A){if(PN)B+=N;else if(M.width>N)B-=L.left;else B=B-L.right+M.width;}else if(PN)B-=N;else if(M.width>N)B=B-L.right+M.width;else B-=L.left; +var R=M.height-L.top,S=L.top;if(RO)C-=O;else if(M.height>O)C=C-L.bottom+M.height;else C-=L.top;if(c){var T=new h(w.$.offsetParent),U=T;if(U.getName()=='html')U=U.getDocument().getBody();if(U.getComputedStyle('direction')=='rtl')if(b.ie8Compat)B-=w.getDocument().getDocumentElement().$.scrollLeft*2;else B-=T.$.scrollWidth-T.$.clientWidth;}var V=w.getFirst(),W;if(W=V.getCustomData('activePanel'))W.onHide&&W.onHide.call(this,1);V.setCustomData('activePanel',this);w.setStyles({top:C+'px',left:B+'px'});w.setOpacity(1);},this);u.isLoaded?E():u.onLoad=E;e.setTimeout(function(){x.$.contentWindow.focus();this.allowBlur(true);},0,this);},b.air?200:0,this);this.visible=1;if(this.onShow)this.onShow.call(this);n=0;},hide:function(p){var r=this;if(r.visible&&(!r.onHide||r.onHide.call(r)!==true)){r.hideChild();b.gecko&&r._.iframe.getFrameDocument().$.activeElement.blur();r.element.setStyle('display','none');r.visible=0;r.element.getFirst().removeCustomData('activePanel');var q=p!==false&&r._.returnFocus;if(q){if(b.webkit&&q.type)q.getWindow().$.focus();q.focus();}}},allowBlur:function(p){var q=this._.panel;if(p!=undefined)q.allowBlur=p;return q.allowBlur;},showAsChild:function(p,q,r,s,t,u){if(this._.activeChild==p&&p._.panel._.offsetParentId==r.getId())return;this.hideChild();p.onHide=e.bind(function(){e.setTimeout(function(){if(!this._.focused)this.hide();},0,this);},this);this._.activeChild=p;this._.focused=false;p.showBlock(q,r,s,t,u);if(b.ie7Compat||b.ie8&&b.ie6Compat)setTimeout(function(){p.element.getChild(0).$.style.cssText+='';},100);},hideChild:function(){var p=this._.activeChild;if(p){delete p.onHide;delete p._.returnFocus;delete this._.activeChild;p.hide();}}}});a.on('instanceDestroyed',function(){var p=e.isEmpty(a.instances);for(var q in m){var r=m[q];if(p)r.destroy();else r.element.hide();}p&&(m={});});})();j.add('menu',{beforeInit:function(m){var n=m.config.menu_groups.split(','),o=m._.menuGroups={},p=m._.menuItems={};for(var q=0;q'],B=r.length,C=B&&r[0].group;for(var D=0;D');C=E.group;}E.render(this,D,A);}A.push('');u.setHtml(A.join(''));k.fire('ready',this);if(this.parent)this.parent._.panel.showAsChild(t,this.id,n,o,p,q);else t.showBlock(this.id,n,o,p,q);s.fire('menuShow',[t]);},addListener:function(n){this._.listeners.push(n);},hide:function(n){var o=this;o._.onHide&&o._.onHide();o._.panel&&o._.panel.hide(n);}}});function m(n){n.sort(function(o,p){if(o.groupp.group)return 1;return o.orderp.order?1:0;});};a.menuItem=e.createClass({$:function(n,o,p){var q=this;e.extend(q,p,{order:0,className:'cke_button_'+o});q.group=n._.menuGroups[q.group];q.editor=n;q.name=o;},proto:{render:function(n,o,p){var w=this;var q=n.id+String(o),r=typeof w.state=='undefined'?2:w.state,s=' cke_'+(r==1?'on':r==0?'disabled':'off'),t=w.label;if(w.className)s+=' '+w.className;var u=w.getItems;p.push(''+''+'');if(u)p.push('','&#',w.editor.lang.dir=='rtl'?'9668':'9658',';','');p.push(t,'');}}});})();i.menu_groups='clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea,div'; +(function(){var m;j.add('editingblock',{init:function(n){if(!n.config.editingBlock)return;n.on('themeSpace',function(o){if(o.data.space=='contents')o.data.html+='
    ';});n.on('themeLoaded',function(){n.fireOnce('editingBlockReady');});n.on('uiReady',function(){n.setMode(n.config.startupMode);});n.on('afterSetData',function(){if(!m){function o(){m=true;n.getMode().loadData(n.getData());m=false;};if(n.mode)o();else n.on('mode',function(){if(n.mode){o();n.removeListener('mode',arguments.callee);}});}});n.on('beforeGetData',function(){if(!m&&n.mode){m=true;n.setData(n.getMode().getData(),null,1);m=false;}});n.on('getSnapshot',function(o){if(n.mode)o.data=n.getMode().getSnapshotData();});n.on('loadSnapshot',function(o){if(n.mode)n.getMode().loadSnapshotData(o.data);});n.on('mode',function(o){o.removeListener();b.webkit&&n.container.on('focus',function(){n.focus();});if(n.config.startupFocus)n.focus();setTimeout(function(){n.fireOnce('instanceReady');a.fire('instanceReady',null,n);},0);});n.on('destroy',function(){var o=this;if(o.mode)o._.modes[o.mode].unload(o.getThemeSpace('contents'));});}});a.editor.prototype.mode='';a.editor.prototype.addMode=function(n,o){o.name=n;(this._.modes||(this._.modes={}))[n]=o;};a.editor.prototype.setMode=function(n){this.fire('beforeSetMode',{newMode:n});var o,p=this.getThemeSpace('contents'),q=this.checkDirty();if(this.mode){if(n==this.mode)return;this._.previousMode=this.mode;this.fire('beforeModeUnload');var r=this.getMode();o=r.getData();r.unload(p);this.mode='';}p.setHtml('');var s=this.getMode(n);if(!s)throw '[CKEDITOR.editor.setMode] Unknown mode "'+n+'".';if(!q)this.on('mode',function(){this.resetDirty();this.removeListener('mode',arguments.callee);});s.load(p,typeof o!='string'?this.getData():o);};a.editor.prototype.getMode=function(n){return this._.modes&&this._.modes[n||this.mode];};a.editor.prototype.focus=function(){this.forceNextSelectionCheck();var n=this.getMode();if(n)n.focus();};})();i.startupMode='wysiwyg';i.editingBlock=true;(function(){function m(){var G=this;try{var D=G.getSelection();if(!D||!D.document.getWindow().$)return;var E=D.getStartElement(),F=new d.elementPath(E);if(!F.compare(G._.selectionPreviousPath)){G._.selectionPreviousPath=F;G.fire('selectionChange',{selection:D,path:F,element:E});}}catch(H){}};var n,o;function p(){o=true;if(n)return;q.call(this);n=e.setTimeout(q,200,this);};function q(){n=null;if(o){e.setTimeout(m,0,this);o=false;}};function r(D){function E(I,J){if(!I||I.type==3)return false; +var K=D.clone();return K['moveToElementEdit'+(J?'End':'Start')](I);};var F=D.startContainer,G=D.getPreviousNode(A,null,F),H=D.getNextNode(A,null,F);if(E(G)||E(H,1))return true;if(!(G||H)&&!(F.type==1&&F.isBlockBoundary()&&F.getBogus()))return true;return false;};var s={modes:{wysiwyg:1,source:1},readOnly:c||b.webkit,exec:function(D){switch(D.mode){case 'wysiwyg':D.document.$.execCommand('SelectAll',false,null);D.forceNextSelectionCheck();D.selectionChange();break;case 'source':var E=D.textarea.$;if(c)E.createTextRange().execCommand('SelectAll');else{E.selectionStart=0;E.selectionEnd=E.value.length;}E.focus();}},canUndo:false};function t(D){w(D);var E=D.createText('​');D.setCustomData('cke-fillingChar',E);return E;};function u(D){return D&&D.getCustomData('cke-fillingChar');};function v(D){var E=D&&u(D);if(E)if(E.getCustomData('ready'))w(D);else E.setCustomData('ready',1);};function w(D){var E=D&&D.removeCustomData('cke-fillingChar');if(E){var F,G=D.getSelection().getNative(),H=G&&G.type!='None'&&G.getRangeAt(0);if(E.getLength()>1&&H&&H.intersectsNode(E.$)){F=[G.anchorOffset,G.focusOffset];var I=G.anchorNode==E.$&&G.anchorOffset>0,J=G.focusNode==E.$&&G.focusOffset>0;I&&F[0]--;J&&F[1]--;x(G)&&F.unshift(F.pop());}E.setText(E.getText().replace(/\u200B/g,''));if(F){var K=G.getRangeAt(0);K.setStart(K.startContainer,F[0]);K.setEnd(K.startContainer,F[1]);G.removeAllRanges();G.addRange(K);}}};function x(D){if(!D.isCollapsed){var E=D.getRangeAt(0);E.setStart(D.anchorNode,D.anchorOffset);E.setEnd(D.focusNode,D.focusOffset);return E.collapsed;}};j.add('selection',{init:function(D){if(b.webkit){D.on('selectionChange',function(){v(D.document);});D.on('beforeSetMode',function(){w(D.document);});var E,F;function G(){var I=D.document,J=u(I);if(J){var K=I.$.defaultView.getSelection();if(K.type=='Caret'&&K.anchorNode==J.$)F=1;E=J.getText();J.setText(E.replace(/\u200B/g,''));}};function H(){var I=D.document,J=u(I);if(J){J.setText(E);if(F){I.$.defaultView.getSelection().setPosition(J.$,J.getLength());F=0;}}};D.on('beforeUndoImage',G);D.on('afterUndoImage',H);D.on('beforeGetData',G,null,null,0);D.on('getData',H);}D.on('contentDom',function(){var I=D.document,J=a.document,K=I.getBody(),L=I.getDocumentElement();if(c){var M,N,O=1;K.on('focusin',function(V){if(V.data.$.srcElement.nodeName!='BODY')return;var W=I.getCustomData('cke_locked_selection');if(W){W.unlock(1);W.lock();}else if(M&&O){try{M.select();}catch(X){}M=null;}});K.on('focus',function(){N=1;U();});K.on('beforedeactivate',function(V){if(V.data.$.toElement)return; +N=0;O=1;});c&&D.on('blur',function(){try{I.$.selection.empty();}catch(V){}});L.on('mousedown',function(){O=0;});L.on('mouseup',function(){O=1;});var P;K.on('mousedown',function(V){if(V.data.$.button==2){var W=D.document.$.selection;if(W.type=='None')P=D.window.getScrollPosition();}T();});K.on('mouseup',function(V){if(V.data.$.button==2&&P){D.document.$.documentElement.scrollLeft=P.x;D.document.$.documentElement.scrollTop=P.y;}P=null;N=1;setTimeout(function(){U(true);},0);});K.on('keydown',T);K.on('keyup',function(){N=1;U();});if(I.$.compatMode!='BackCompat'){if(b.ie7Compat||b.ie6Compat){function Q(V,W,X){try{V.moveToPoint(W,X);}catch(Y){}};L.on('mousedown',function(V){function W(ab){ab=ab.data.$;if(Z){var ac=K.$.createTextRange();Q(ac,ab.x,ab.y);Z.setEndPoint(aa.compareEndPoints('StartToStart',ac)<0?'EndToEnd':'StartToStart',ac);Z.select();}};function X(){J.removeListener('mouseup',Y);L.removeListener('mouseup',Y);};function Y(){L.removeListener('mousemove',W);X();Z.select();};V=V.data;if(V.getTarget().is('html')&&V.$.x0)P=Q-1;else if(R<0)O=Q+1;else if(b.ie9Compat&&L.tagName=='BR'){var U=J.defaultView.getSelection();return{container:U[H?'anchorNode':'focusNode'],offset:U[H?'anchorOffset':'focusOffset']};}else return{container:I,offset:E(L)};}if(Q==-1||Q==K.length-1&&R<0){N.moveToElementText(I);N.setEndPoint('StartToStart',G);S=N.text.replace(/(\r\n|\r)/g,'\n').length;K=I.childNodes;if(!S){L=K[K.length-1];if(L.nodeType!=3)return{container:I,offset:K.length};else return{container:L,offset:L.nodeValue.length};}var V=K.length; +while(S>0&&V>0){M=K[--V];if(M.nodeType==3){T=M;S-=M.nodeValue.length;}}return{container:T,offset:-S};}else{N.collapse(R>0?true:false);N.setEndPoint(R>0?'StartToStart':'EndToStart',G);S=N.text.replace(/(\r\n|\r)/g,'\n').length;if(!S)return{container:I,offset:E(L)+(R>0?0:1)};while(S>0)try{M=L[R>0?'previousSibling':'nextSibling'];if(M.nodeType==3){S-=M.nodeValue.length;T=M;}L=M;}catch(W){return{container:I,offset:E(L)};}return{container:T,offset:R>0?-S:T.nodeValue.length+S};}};return function(){var Q=this;var G=Q.getNative(),H=G&&G.createRange(),I=Q.getType(),J;if(!G)return[];if(I==2){J=new d.range(Q.document);var K=F(H,true);J.setStart(new d.node(K.container),K.offset);K=F(H);J.setEnd(new d.node(K.container),K.offset);if(J.endContainer.getPosition(J.startContainer)&4&&J.endOffset<=J.startContainer.getIndex())J.collapse();return[J];}else if(I==3){var L=[];for(var M=0;M=L.getLength())P.setStartAfter(L);else P.setStartBefore(L);if(M&&M.type==3)if(!O)P.setEndBefore(M);else P.setEndAfter(M);var Q=new d.walker(P);Q.evaluator=function(R){if(R.type==1&&R.isReadOnly()){var S=I.clone();I.setEndBefore(R);if(I.collapsed)G.splice(H--,1);if(!(R.getPosition(P.endContainer)&16)){S.setStartAfter(R);if(!S.collapsed)G.splice(H+1,0,S);}return true;}return false;};Q.next();}}return F.ranges;};})(),getStartElement:function(){var K=this;var D=K._.cache;if(D.startElement!==undefined)return D.startElement; +var E,F=K.getNative();switch(K.getType()){case 3:return K.getSelectedElement();case 2:var G=K.getRanges()[0];if(G){if(!G.collapsed){G.optimize();while(1){var H=G.startContainer,I=G.startOffset;if(I==(H.getChildCount?H.getChildCount():H.getLength())&&!H.isBlockBoundary())G.setStartAfter(H);else break;}E=G.startContainer;if(E.type!=1)return E.getParent();E=E.getChild(G.startOffset);if(!E||E.type!=1)E=G.startContainer;else{var J=E.getFirst();while(J&&J.type==1){E=J;J=J.getFirst();}}}else{E=G.startContainer;if(E.type!=1)E=E.getParent();}E=E.$;}}return D.startElement=E?new h(E):null;},getSelectedElement:function(){var D=this._.cache;if(D.selectedElement!==undefined)return D.selectedElement;var E=this,F=e.tryThese(function(){return E.getNative().createRange().item(0);},function(){var G,H,I=E.getRanges()[0],J=I.getCommonAncestor(1,1),K={table:1,ul:1,ol:1,dl:1};for(var L in K){if(G=J.getAscendant(L,1))break;}if(G){var M=new d.range(this.document);M.setStartAt(G,1);M.setEnd(I.startContainer,I.startOffset);var N=e.extend(K,f.$listItem,f.$tableContent),O=new d.walker(M),P=function(Q,R){return function(S,T){if(S.type==3&&(!e.trim(S.getText())||S.getParent().data('cke-bookmark')))return true;var U;if(S.type==1){U=S.getName();if(U=='br'&&R&&S.equals(S.getParent().getBogus()))return true;if(T&&U in N||U in f.$removeEmpty)return true;}Q.halted=1;return false;};};O.guard=P(O);if(O.checkBackward()&&!O.halted){O=new d.walker(M);M.setStart(I.endContainer,I.endOffset);M.setEndAt(G,2);O.guard=P(O,1);if(O.checkForward()&&!O.halted)H=G.$;}}if(!H)throw 0;return H;},function(){var G=E.getRanges()[0],H,I;for(var J=2;J&&!((H=G.getEnclosedNode())&&H.type==1&&y[H.getName()]&&(I=H));J--)G.shrink(1);return I.$;});return D.selectedElement=F?new h(F):null;},getSelectedText:function(){var D=this._.cache;if(D.selectedText!==undefined)return D.selectedText;var E='',F=this.getNative();if(this.getType()==2)E=c?F.createRange().text:F.toString();return D.selectedText=E;},lock:function(){var D=this;D.getRanges();D.getStartElement();D.getSelectedElement();D.getSelectedText();D._.cache.nativeSel={};D.isLocked=1;D.document.setCustomData('cke_locked_selection',D);},unlock:function(D){var I=this;var E=I.document,F=E.getCustomData('cke_locked_selection');if(F){E.setCustomData('cke_locked_selection',null);if(D){var G=F.getSelectedElement(),H=!G&&F.getRanges();I.isLocked=0;I.reset();if(G)I.selectElement(G);else I.selectRanges(H);}}if(!F||!D){I.isLocked=0;I.reset();}},reset:function(){this._.cache={};},selectElement:function(D){var F=this; +if(F.isLocked){var E=new d.range(F.document);E.setStartBefore(D);E.setEndAfter(D);F._.cache.selectedElement=D;F._.cache.startElement=D;F._.cache.ranges=new d.rangeList(E);F._.cache.type=3;return;}E=new d.range(D.getDocument());E.setStartBefore(D);E.setEndAfter(D);E.select();F.document.fire('selectionchange');F.reset();},selectRanges:function(D){var R=this;if(R.isLocked){R._.cache.selectedElement=null;R._.cache.startElement=D[0]&&D[0].getTouchedStartNode();R._.cache.ranges=new d.rangeList(D);R._.cache.type=2;return;}if(c){if(D.length>1){var E=D[D.length-1];D[0].setEnd(E.endContainer,E.endOffset);D.length=1;}if(D[0])D[0].select();R.reset();}else{var F=R.getNative();if(!F)return;if(D.length){F.removeAllRanges();b.webkit&&w(R.document);}for(var G=0;G=0){M.collapse(1);N.setEnd(M.endContainer.$,M.endOffset);}else throw S;}F.addRange(N);}R.document.fire('selectionchange');R.reset();}},createBookmarks:function(D){return this.getRanges().createBookmarks(D);},createBookmarks2:function(D){return this.getRanges().createBookmarks2(D);},selectBookmarks:function(D){var E=[];for(var F=0;F','','',this.label,'','=10900&&!o.hc?'':" href=\"javascript:void('"+this.label+"')\"",' role="button" aria-labelledby="',p,'_label" aria-describedby="',p,'_text" aria-haspopup="true"'); +if(b.opera||b.gecko&&b.mac)n.push(' onkeypress="return false;"');if(b.gecko)n.push(' onblur="this.style.cssText = this.style.cssText;"');n.push(' onkeydown="CKEDITOR.tools.callFunction( ',t,', event, this );" onfocus="return CKEDITOR.tools.callFunction(',u,', event);" '+(c?'onclick="return false;" onmouseup':'onclick')+'="CKEDITOR.tools.callFunction(',q,', this); return false;">'+this.label+''+''+''+(b.hc?'▼':b.air?' ':'')+''+''+''+'');if(this.onRender)this.onRender();return r;},createPanel:function(m){if(this._.panel)return;var n=this._.panelDefinition,o=this._.panelDefinition.block,p=n.parent||a.document.getBody(),q=new k.floatPanel(m,p,n),r=q.addListBlock(this.id,o),s=this;q.onShow=function(){if(s.className)this.element.getFirst().addClass(s.className+'_panel');s.setState(1);r.focus(!s.multiSelect&&s.getValue());s._.on=1;if(s.onOpen)s.onOpen();};q.onHide=function(t){if(s.className)this.element.getFirst().removeClass(s.className+'_panel');s.setState(s.modes&&s.modes[m.mode]?2:0);s._.on=0;if(!t&&s.onClose)s.onClose();};q.onEscape=function(){q.hide();};r.onClick=function(t,u){s.document.getWindow().focus();if(s.onClick)s.onClick.call(s,t,u);if(u)s.setValue(t,s._.items[t]);else s.setValue('');q.hide(false);};this._.panel=q;this._.list=r;q.getBlock(this.id).onHide=function(){s._.on=0;s.setState(2);};if(this.init)this.init();},setValue:function(m,n){var p=this;p._.value=m;var o=p.document.getById('cke_'+p.id+'_text');if(o){if(!(m||n)){n=p.label;o.addClass('cke_inline_label');}else o.removeClass('cke_inline_label');o.setHtml(typeof n!='undefined'?n:m);}},getValue:function(){return this._.value||'';},unmarkAll:function(){this._.list.unmarkAll();},mark:function(m){this._.list.mark(m);},hideItem:function(m){this._.list.hideItem(m);},hideGroup:function(m){this._.list.hideGroup(m);},showAll:function(){this._.list.showAll();},add:function(m,n,o){this._.items[m]=o||m;this._.list.add(m,n,o);},startGroup:function(m){this._.list.startGroup(m);},commit:function(){var m=this;if(!m._.committed){m._.list.commit();m._.committed=1;k.fire('ready',m);}m._.committed=1;},setState:function(m){var n=this;if(n._.state==m)return;n.document.getById('cke_'+n.id).setState(m);n._.state=m;}}});k.prototype.addRichCombo=function(m,n){this.add(m,'richcombo',n);};j.add('htmlwriter');a.htmlWriter=e.createClass({base:a.htmlParser.basicWriter,$:function(){var o=this; +o.base();o.indentationChars='\t';o.selfClosingEnd=' />';o.lineBreakChars='\n';o.forceSimpleAmpersand=0;o.sortAttributes=1;o._.indent=0;o._.indentation='';o._.inPre=0;o._.rules={};var m=f;for(var n in e.extend({},m.$nonBodyContent,m.$block,m.$listItem,m.$tableContent))o.setRules(n,{indent:1,breakBeforeOpen:1,breakAfterOpen:1,breakBeforeClose:!m[n]['#'],breakAfterClose:1});o.setRules('br',{breakAfterOpen:1});o.setRules('title',{indent:0,breakAfterOpen:0});o.setRules('style',{indent:0,breakBeforeClose:1});o.setRules('pre',{indent:0});},proto:{openTag:function(m,n){var p=this;var o=p._.rules[m];if(p._.indent)p.indentation();else if(o&&o.breakBeforeOpen){p.lineBreak();p.indentation();}p._.output.push('<',m);},openTagClose:function(m,n){var p=this;var o=p._.rules[m];if(n)p._.output.push(p.selfClosingEnd);else{p._.output.push('>');if(o&&o.indent)p._.indentation+=p.indentationChars;}if(o&&o.breakAfterOpen)p.lineBreak();m=='pre'&&(p._.inPre=1);},attribute:function(m,n){if(typeof n=='string'){this.forceSimpleAmpersand&&(n=n.replace(/&/g,'&'));n=e.htmlEncodeAttr(n);}this._.output.push(' ',m,'="',n,'"');},closeTag:function(m){var o=this;var n=o._.rules[m];if(n&&n.indent)o._.indentation=o._.indentation.substr(o.indentationChars.length);if(o._.indent)o.indentation();else if(n&&n.breakBeforeClose){o.lineBreak();o.indentation();}o._.output.push('');m=='pre'&&(o._.inPre=0);if(n&&n.breakAfterClose)o.lineBreak();},text:function(m){var n=this;if(n._.indent){n.indentation();!n._.inPre&&(m=e.ltrim(m));}n._.output.push(m);},comment:function(m){if(this._.indent)this.indentation();this._.output.push('');},lineBreak:function(){var m=this;if(!m._.inPre&&m._.output.length>0)m._.output.push(m.lineBreakChars);m._.indent=1;},indentation:function(){var m=this;if(!m._.inPre)m._.output.push(m._.indentation);m._.indent=0;},setRules:function(m,n){var o=this._.rules[m];if(o)e.extend(o,n,true);else this._.rules[m]=n;}}});j.add('menubutton',{requires:['button','menu'],beforeInit:function(m){m.ui.addHandler('menubutton',k.menuButton.handler);}});a.UI_MENUBUTTON='menubutton';(function(){var m=function(n){var o=this._;if(o.state===0)return;o.previousState=o.state;var p=o.menu;if(!p){p=o.menu=new a.menu(n,{panel:{className:n.skinClass+' cke_contextmenu',attributes:{'aria-label':n.lang.common.options}}});p.onHide=e.bind(function(){this.setState(this.modes&&this.modes[n.mode]?o.previousState:0);},this);if(this.onMenu)p.addListener(this.onMenu);}if(o.on){p.hide();return;}this.setState(1); +p.show(a.document.getById(this._.id),4);};k.menuButton=e.createClass({base:k.button,$:function(n){var o=n.panel;delete n.panel;this.base(n);this.hasArrow=true;this.click=m;},statics:{handler:{create:function(n){return new k.menuButton(n);}}}});})();j.add('dialogui');(function(){var m=function(u){var x=this;x._||(x._={});x._['default']=x._.initValue=u['default']||'';x._.required=u.required||false;var v=[x._];for(var w=1;w',v.label,'','');else{var D={type:'hbox',widths:v.widths,padding:0,children:[{type:'html',html:'